diff options
author | cindylau@google.com <cindylau@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-02 03:41:14 +0000 |
---|---|---|
committer | cindylau@google.com <cindylau@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-02 03:41:14 +0000 |
commit | 15e123091eaa54a4b20f407a181cdc17532e9364 (patch) | |
tree | e6c3b64d8d7bb122b1127db41095218883a2ff64 /ceee | |
parent | 62c2fc060b6fc3a89eca390cb2d1271ff144922b (diff) | |
download | chromium_src-15e123091eaa54a4b20f407a181cdc17532e9364.zip chromium_src-15e123091eaa54a4b20f407a181cdc17532e9364.tar.gz chromium_src-15e123091eaa54a4b20f407a181cdc17532e9364.tar.bz2 |
Add implementation of tabs.getCurrent() API, and correct implementation of
windows.getCurrent(), to Firefox's CEEE.
Cloned from issue http://codereview.chromium.org/5277004/ by rogerta@chromium.org.
BUG=64979
TEST=see integration tests
Review URL: http://codereview.chromium.org/5512001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67961 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ceee')
-rw-r--r-- | ceee/firefox/content/cf.js | 10 | ||||
-rw-r--r-- | ceee/firefox/content/overlay.js | 4 | ||||
-rw-r--r-- | ceee/firefox/content/tab_api.js | 19 | ||||
-rw-r--r-- | ceee/firefox/content/window_api.js | 7 | ||||
-rw-r--r-- | ceee/firefox/modules/global.js | 25 |
5 files changed, 56 insertions, 9 deletions
diff --git a/ceee/firefox/content/cf.js b/ceee/firefox/content/cf.js index ee23b66..fe4ad91 100644 --- a/ceee/firefox/content/cf.js +++ b/ceee/firefox/content/cf.js @@ -49,12 +49,6 @@ function CfHelper(instance) { this.parent_ = null; } -/** - * Value used for id attribute of the ChromeFrame <embed> element. - * @const - */ -CfHelper.prototype.CHROME_FRAME_ID = 'ceee-browser'; - /** Origin for use with postPrivateMessage. @const */ CfHelper.prototype.ORIGIN_EXTENSION = '__priv_xtapi'; @@ -241,6 +235,10 @@ CfHelper.prototype.onReadyStateChange_ = function() { if (this.cf_.readystate == READY_STATE_UNINITIALIZED) { this.cf_.style.visibility = 'hidden'; } else if (this.cf_.readystate == READY_STATE_COMPLETED) { + this.ceee_.logInfo('CfHelper.readystatechange: window=' + + CEEE_mozilla_windows.getWindowId(window) + + ' cf=' + this.cf_.sessionid); + // Do this before we even load the extension at the other end so // that extension automation is set up before any background pages // in the extension load. diff --git a/ceee/firefox/content/overlay.js b/ceee/firefox/content/overlay.js index bba7a47f..7b94b5e 100644 --- a/ceee/firefox/content/overlay.js +++ b/ceee/firefox/content/overlay.js @@ -297,8 +297,8 @@ CEEE_Class.prototype.createChromeFrame_ = function() { this.cfHelper_ = new CEEE_CfHelper(this); var parent = document.getElementById('ceee-browser-item'); - var cf = this.cfHelper_.create(parent, this.cfHelper_.CHROME_FRAME_ID, - onCfReady, onCfMessage); + var cf = this.cfHelper_.create(parent, CEEE_globals.CHROME_FRAME_ID, + onCfReady, onCfMessage); }; /** Returns a helper object for working with ChromeFrame. */ diff --git a/ceee/firefox/content/tab_api.js b/ceee/firefox/content/tab_api.js index 2f0cb42..6ca5596 100644 --- a/ceee/firefox/content/tab_api.js +++ b/ceee/firefox/content/tab_api.js @@ -258,6 +258,22 @@ CEEE_tabs_internal_.getSelectedTab_ = function(cmd, data) { return this.buildTabValue(mainBrowser, tab); }; +CEEE_tabs_internal_.CMD_GET_CURRENT_TAB = 'tabs.getCurrent'; +CEEE_tabs_internal_.getCurrentTab_ = function(cmd, data) { + // TODO(rogerta@chromium.org): Revisit this implementation. I'm not sure + // it strictly obeys the chrome extension API spec. + var cfTab = data.tab; + if (cfTab) { + var win = CEEE_mozilla_windows.findWindowFromCfSessionId(cfTab.id); + if (win) { + var mainBrowser = win.document.getElementById( + CEEE_globals.MAIN_BROWSER_ID); + var tab = mainBrowser.selectedTab; + return this.buildTabValue(mainBrowser, tab); + } + } +}; + CEEE_tabs_internal_.CMD_GET_ALL_TABS_IN_WINDOW = 'tabs.getAllInWindow'; CEEE_tabs_internal_.getAllTabsInWindow_ = function(cmd, data) { var args = CEEE_json.decode(data.args); @@ -455,6 +471,9 @@ function CEEE_initialize_tabs(ceeeInstance) { ceeeInstance.registerExtensionHandler(tabs.CMD_GET_SELECTED_TAB, tabs, tabs.getSelectedTab_); + ceeeInstance.registerExtensionHandler(tabs.CMD_GET_CURRENT_TAB, + tabs, + tabs.getCurrentTab_); ceeeInstance.registerExtensionHandler(tabs.CMD_GET_ALL_TABS_IN_WINDOW, tabs, tabs.getAllTabsInWindow_); diff --git a/ceee/firefox/content/window_api.js b/ceee/firefox/content/window_api.js index a3909c9..ac13f8b 100644 --- a/ceee/firefox/content/window_api.js +++ b/ceee/firefox/content/window_api.js @@ -143,7 +143,12 @@ CEEE_window_internal_.getWindow_ = function(cmd, data) { CEEE_window_internal_.CMD_GET_CURRENT_WINDOW = 'windows.getCurrent'; CEEE_window_internal_.getCurrentWindow_ = function(cmd, data) { - return this.buildWindowValue(window); + var tab = data.tab; + if (tab) { + var win = CEEE_mozilla_windows.findWindowFromCfSessionId(tab.id); + if (win) + return this.buildWindowValue(win); + } }; CEEE_window_internal_.CMD_GET_LAST_FOCUSED_WINDOW = diff --git a/ceee/firefox/modules/global.js b/ceee/firefox/modules/global.js index 60d79b0..dd0eb28 100644 --- a/ceee/firefox/modules/global.js +++ b/ceee/firefox/modules/global.js @@ -142,6 +142,25 @@ CEEE_mozilla_windows.findWindowFromContentWindow = function(win) { }; /** + * Find the window with the given a Chrome Frame session id. + * + * @param {number} id The Chrome Frame session Id of the window to find. + * @return The window that contains the Chrome Frame instance with the + * specified session Id, or null if no window is found. + * @public + */ +CEEE_mozilla_windows.findWindowFromCfSessionId = function(id) { + var e = this.service.getEnumerator(this.WINDOW_TYPE); + while (e.hasMoreElements()) { + var win = e.getNext(); + var cf = win.document.getElementById(CEEE_globals.CHROME_FRAME_ID); + if (cf.sessionid == id) + return win; + } + return null; +}; + +/** * Global object used as a place-holder for API routines accessing the Mozilla * tabs interface. * @public @@ -377,6 +396,12 @@ var CEEE_globals = CEEE_globals || { /** @const */ MAIN_BROWSER_ID: 'content', /** @const */ ADDON_ID: 'ceee@google.com', + /** + * Value used for id attribute of the ChromeFrame <embed> element. + * @const + */ + CHROME_FRAME_ID: 'ceee-browser', + /** The integer id for the next window. @private */ nextWindowId_: 0, |