[Phoenix-commits] rev 13653 - public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content

andi at wyona.com andi at wyona.com
Mon May 29 19:29:12 CEST 2006


Author: andi
Date: 2006-05-29 19:29:11 +0200 (Mon, 29 May 2006)
New Revision: 13653

Modified:
   public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/phoenix.js
   public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/phoenix.xul
   public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/view.js
Log:
Added first part of the introspection detection functionality.


Modified: public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/phoenix.js
===================================================================
--- public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/phoenix.js	2006-05-29 16:16:00 UTC (rev 13652)
+++ public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/phoenix.js	2006-05-29 17:29:11 UTC (rev 13653)
@@ -26,31 +26,152 @@
  *
  */
 
-var Phoenix = {
-    createNewEditor: function (aURI) {
-        var phoenixTab = null;
-        var targetURI  = null;
+/* Registers our init code to be run (see
+ * http://developer.mozilla.org/en/docs/Extension_FAQ#Why_doesn.27t_my_script_run_properly.3F) */
+window.addEventListener('load', initPhoenix, false);
 
-        /* DEBUG */ dump("Phoenix:phoenix.js:createNewEditor() invoked\n");
+/**
+ * Event handler for setting up Phoenix for active window.
+ *
+ * @return {Undefined}
+ */
+function initPhoenix() {
+    /* DEBUG */ dump("Phoenix:phoenix.js:initPhoenix() invoked\n");
 
-        try {
-            // construct target URI
-            targetURI = "chrome://phoenix/content/editor.xul" + "?" + document.getElementById("content").currentURI.spec;
+    new Phoenix();
+}
 
-            // getBrowser() (defined in browser.js) returns a reference to the Tabbrowser element
-            phoenixTab = self.getBrowser().addTab(targetURI);
+function createNewEditor(aURI) {
+    var phoenixTab = null;
+    var targetURI  = null;
 
-            // switch ui to newly created tab
-            self.getBrowser().selectedTab = phoenixTab;
-        } catch (exception) {
-            dump("Phoenix:phoenix.js:createNewEditor: failed to open new editor tab: " + exception.toString() + "\n");
-            return;
+    /* DEBUG */ dump("Phoenix:phoenix.js:createNewEditor() invoked\n");
+
+    try {
+        // construct target URI
+        targetURI = "chrome://phoenix/content/editor.xul" + "?" + document.getElementById("content").currentURI.spec;
+
+        // getBrowser() (defined in browser.js) returns a reference to the Tabbrowser element
+        phoenixTab = self.getBrowser().addTab(targetURI);
+
+        // switch ui to newly created tab
+        self.getBrowser().selectedTab = phoenixTab;
+    } catch (exception) {
+        dump("Phoenix:phoenix.js:createNewEditor: failed to open new editor tab: " + exception.toString() + "\n");
+        return;
+    }
+
+    /* DEBUG */ dump("Phoenix:phoenix.js:createNewEditor: new tab created\n");
+}
+
+function Phoenix() {
+    var tabBrowser       = null;
+    var tabSwitchHandler = null;
+
+    /* DEBUG */ dump("Phoenix:phoenix.js:Phoenix() invoked\n");
+
+    this.phoenixEditMenu = document.getElementById("uiPhoenixEditButton");
+
+    // install tab switch listener
+    tabSwitchHandler = new TabSwitchHandler(this);
+
+    tabBrowser = self.getBrowser();
+    tabBrowser.tabContainer.addEventListener("select", tabSwitchHandler, false);
+
+    /* DEBUG */ dump("Phoenix:phoenix.js:Phoenix: initialisation completed\n");
+}
+
+Phoenix.prototype = {
+    currentWebProgressListener: null,
+
+    introspectionDetector: function (aDocument) {
+        /* DEBUG */ dump("Phoenix:phoenix.js:Phoenix.introspectionDetector(\"" + aDocument + "\") invoked\n");
+    },
+
+    getPrefs: function (aPref) {
+        var prefBranch = null;
+
+        /* DEBUG */ dump("Phoenix:phoenix.js:Phoenix.getPrefs() invoked\n");
+
+        prefBranch = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
+        prefBranch = pref.getBranch("extensions.phoenix.");
+
+        return prefBranch.aPref;
+    }
+};
+
+function TabSwitchHandler(aPhoenix) {
+    /* DEBUG */ dump("Phoenix:phoenix.js:Phoenix.TabSwitchHandler() invoked\n");
+
+    this.phoenix = aPhoenix;
+}
+
+TabSwitchHandler.prototype.handleEvent = function (aEvent) {
+    var browser             = null;
+    var webProgressListener = null;
+
+    /* DEBUG */ dump("Phoenix:phoenix.js:Phoenix.TabSwitchHandler.handleEvent() invoked\n");
+
+    browser = self.getBrowser();
+
+    // check if a document is currently loading
+    if (self.getBrowser().webProgress.isLoadingDocument) {
+        // if yes, install a progress listener
+
+        /* DEBUG */ dump("Phoenix:phoenix.js:Phoenix.TabSwitchHandler.handleEvent: install onload handler\n");
+
+        webProgressListener = new WebProgressListener(this.phoenix);
+        self.getBrowser().selectedBrowser.webProgress.addProgressListener(webProgressListener, /*Components.interfaces.nsIWebProgress.NOTIFY_LOCATION |*/ Components.interfaces.nsIWebProgress.NOTIFY_STATE_ALL);
+    } else {
+        // if no, check for introspection link
+        this.phoenix.introspectionDetector(browser.selectedBrowser.contentDocument);
+    }
+
+    // recheck, since we may have missed STATE_STOP during handler installation
+
+    /* DEBUG */ dump("Phoenix:phoenix.js:Phoenix.TabSwitchHandler.handleEvent completed\n");
+};
+
+function WebProgressListener(aPhoenix) {
+    /* DEBUG */ dump("Phoenix:phoenix.js:webProgressListener() invoked\n");
+
+    this.phoenix = aPhoenix;
+}
+
+WebProgressListener.prototype = {
+    QueryInterface: function (aUUID) {
+        if (aUUID.equals(Components.interfaces.nsISupports) ||
+            aUUID.equals(Components.interfaces.nsISupportsWeakReference) ||
+            aUUID.equals(Components.interfaces.nsIWebProgressListener)) {
+            return this;
+        } else {
+            throw Components.results.NS_NOINTERFACE;
         }
+    },
 
-        /* DEBUG */ dump("Phoenix:phoenix.js:createNewEditor: new tab created\n");
+    GetWeakReference: function () {
+        throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
     },
 
-    introspectionDetector: function () {
+    onLocationChange: function (aWebProgress, aRequest, aLocation) {
+        /* DEBUG */ dump("Phoenix:phoenix.js:webProgressListener.onLocationChange(\"" + aWebProgress + "\", \"" + aRequest + "\", \"" + aLocation + "\") invoked\n");
 
+    },
+
+    onStateChange: function (aWebProgress, aRequest, aStateFlags, aStatus) {
+        /* DEBUG */ dump("Phoenix:phoenix.js:webProgressListener.onStateChange(\"" + aWebProgress + "\", \"" + aRequest + "\", \"" + "\"" + aStateFlags + "\", \"" + aStatus + "\") invoked\n");
+
+    },
+
+    onProgressChange: function () {
+        throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
+    },
+
+    onSecurityChange: function () {
+        throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
+    },
+
+    onStatusChange: function () {
+        throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
     }
 }

Modified: public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/phoenix.xul
===================================================================
--- public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/phoenix.xul	2006-05-29 16:16:00 UTC (rev 13652)
+++ public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/phoenix.xul	2006-05-29 17:29:11 UTC (rev 13653)
@@ -40,7 +40,7 @@
             class="chromeclass-toolbar-additional"
             label="&editToolbarbutton.label;"
             tooltiptext="&editToolbarbutton.tooltip;"
-            oncommand="Phoenix.createNewEditor(document.location)"
+            oncommand="createNewEditor(document.location)"
             disabled="false"/>
   </toolbar>
 

Modified: public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/view.js
===================================================================
--- public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/view.js	2006-05-29 16:16:00 UTC (rev 13652)
+++ public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/view.js	2006-05-29 17:29:11 UTC (rev 13653)
@@ -85,6 +85,7 @@
         } catch (exception) {
             dump("EXCEPTION: Phoenix:view.js:View.syncToModel: " + exception + "\n");
             dump("STACKTRACE: " + exception.stack + "\n");
+            Components.utils.reportError(exception);
         }
     } else {
         /* DEBUG */ dump("Phoenix:view.js:View.syncToModel: not syncing (document not modified)\n");
@@ -155,6 +156,7 @@
         } catch (exception) {
             dump("EXCEPTION: Phoenix:view.js:SourceModeView.setUp: " + exception + "\n");
             dump("STACKTRACE: " + exception.stack + "\n");
+            Components.utils.reportError(exception);
             return;
         }
 
@@ -200,6 +202,7 @@
             // cannot handle document content type
             dump("EXCEPTION: Phoenix:view.js:SourceModeView.fillView: " + exception + "\n");
             dump("STACKTRACE: " + exception.stack + "\n");
+            Components.utils.reportError(exception);
             return false;
         }
     }
@@ -263,6 +266,7 @@
         } catch (exception) {
             dump("EXCEPTION: Phoenix:view.js:WYSIWYGModeView.setUp: " + exception + "\n");
             dump("STACKTRACE: " + exception.stack + "\n");
+            Components.utils.reportError(exception);
             return;
         }
 
@@ -304,6 +308,7 @@
             // cannot handle document content type
             dump("EXCEPTION: Phoenix:view.js:WYSIWYGModeView.fillView: " + exception + "\n");
             dump("STACKTRACE: " + exception.stack + "\n");
+            Components.utils.reportError(exception);
             return false;
         }
     }




More information about the Phoenix-commits mailing list