Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed bug 1215025 #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions 1215025.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# HG changeset patch
# User ShiHan Wan <[email protected]>

fixed bug 1215025

---
browser/components/extensions/ext-utils.js | 60 ++++++++++++++++++++++++++++--
1 file changed, 57 insertions(+), 3 deletions(-)

diff --git a/browser/components/extensions/ext-utils.js b/browser/components/extensions/ext-utils.js
index 8b2374e..473539e 100644
--- a/browser/components/extensions/ext-utils.js
+++ b/browser/components/extensions/ext-utils.js
@@ -158,6 +158,7 @@ class BasePopup {
this.browser.removeEventListener("load", this, true);
this.browser.removeEventListener("DOMTitleChanged", this, true);
this.browser.removeEventListener("DOMWindowClose", this, true);
+ this.browser.removeEventListener("MozScrolledAreaChanged", this, true);

this.viewNode.removeEventListener(this.DESTROY_EVENT, this);

@@ -204,6 +205,9 @@ class BasePopup {
// dynamically, probably in response to MozScrolledAreaChanged events.
this.window.setTimeout(() => this.resizeBrowser(), 0);
break;
+
+ case "MozScrolledAreaChanged":
+ this.resizeBrowser();
}
}

@@ -235,7 +239,7 @@ class BasePopup {
};
this.browser.addEventListener("load", loadListener, true);
}).then(() => {
- let { contentWindow } = this.browser;
+ let {contentWindow} = this.browser;

contentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
@@ -254,6 +258,7 @@ class BasePopup {
this.browser.addEventListener("load", this, true);
this.browser.addEventListener("DOMTitleChanged", this, true);
this.browser.addEventListener("DOMWindowClose", this, true);
+ this.browser.addEventListener("MozScrolledAreaChanged", this, true);
});
}

@@ -423,7 +428,7 @@ ExtensionTabManager.prototype = {
convert(tab) {
let window = tab.ownerDocument.defaultView;

- let mutedInfo = { muted: tab.muted };
+ let mutedInfo = {muted: tab.muted};
if (tab.muteReason === null) {
mutedInfo.reason = "user";
} else if (tab.muteReason) {
@@ -471,11 +476,60 @@ ExtensionTabManager.prototype = {
global.TabManager = {
_tabs: new WeakMap(),
_nextId: 1,
+ _initialized: false,
+
+ // We begin listening for TabOpen and TabClose events once we've started
+ // assigning IDs to tabs, so that we can remap the IDs of tabs which are moved
+ // between windows.
+ initListener() {
+ if (this._initialized) {
+ return;
+ }
+
+ AllWindowEvents.addListener("TabOpen", this);
+ AllWindowEvents.addListener("TabClose", this);
+ WindowListManager.addOpenListener(this.handleWindowOpen.bind(this));
+
+ this._initialized = true;
+ },
+
+ handleEvent(event) {
+ if (event.type == "TabOpen") {
+ let {adoptedTab} = event.detail;
+ if (adoptedTab) {
+ // This tab is being created to adopt a tab from a different window.
+ // Copy the ID from the old tab to the new.
+ this._tabs.set(event.target, this.getId(adoptedTab));
+ }
+ } else if (event.type == "TabClose") {
+ let {adoptedBy} = event.detail;
+ if (adoptedBy) {
+ // This tab is being closed because it was adopted by a new window.
+ // Copy its ID to the new tab, in case it was created as the first tab
+ // of a new window, and did not have an `adoptedTab` detail when it was
+ // opened.
+ this._tabs.set(adoptedBy, this.getId(event.target));
+ }
+ }
+ },
+
+ handleWindowOpen(window) {
+ if (window.arguments[0] instanceof window.XULElement) {
+ // If the first window argument is a XUL element, it means the
+ // window is about to adopt a tab from another window to replace its
+ // initial tab.
+ let adoptedTab = window.arguments[0];
+
+ this._tabs.set(window.gBrowser.tabs[0], this.getId(adoptedTab));
+ }
+ },

getId(tab) {
if (this._tabs.has(tab)) {
return this._tabs.get(tab);
}
+ this.initListener();
+
let id = this._nextId++;
this._tabs.set(tab, id);
return id;
@@ -583,7 +637,7 @@ global.WindowManager = {
convert(extension, window, getInfo) {
let result = {
id: this.getId(window),
- focused: window == WindowManager.topWindow,
+ focused: window.document.hasFocus(),
top: window.screenY,
left: window.screenX,
width: window.outerWidth,

60 changes: 57 additions & 3 deletions browser/components/extensions/ext-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class BasePopup {
this.browser.removeEventListener("load", this, true);
this.browser.removeEventListener("DOMTitleChanged", this, true);
this.browser.removeEventListener("DOMWindowClose", this, true);
this.browser.removeEventListener("MozScrolledAreaChanged", this, true);

this.viewNode.removeEventListener(this.DESTROY_EVENT, this);

Expand Down Expand Up @@ -204,6 +205,9 @@ class BasePopup {
// dynamically, probably in response to MozScrolledAreaChanged events.
this.window.setTimeout(() => this.resizeBrowser(), 0);
break;

case "MozScrolledAreaChanged":
this.resizeBrowser();
}
}

Expand Down Expand Up @@ -235,7 +239,7 @@ class BasePopup {
};
this.browser.addEventListener("load", loadListener, true);
}).then(() => {
let { contentWindow } = this.browser;
let {contentWindow} = this.browser;

contentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
Expand All @@ -254,6 +258,7 @@ class BasePopup {
this.browser.addEventListener("load", this, true);
this.browser.addEventListener("DOMTitleChanged", this, true);
this.browser.addEventListener("DOMWindowClose", this, true);
this.browser.addEventListener("MozScrolledAreaChanged", this, true);
});
}

Expand Down Expand Up @@ -423,7 +428,7 @@ ExtensionTabManager.prototype = {
convert(tab) {
let window = tab.ownerDocument.defaultView;

let mutedInfo = { muted: tab.muted };
let mutedInfo = {muted: tab.muted};
if (tab.muteReason === null) {
mutedInfo.reason = "user";
} else if (tab.muteReason) {
Expand Down Expand Up @@ -471,11 +476,60 @@ ExtensionTabManager.prototype = {
global.TabManager = {
_tabs: new WeakMap(),
_nextId: 1,
_initialized: false,

// We begin listening for TabOpen and TabClose events once we've started
// assigning IDs to tabs, so that we can remap the IDs of tabs which are moved
// between windows.
initListener() {
if (this._initialized) {
return;
}

AllWindowEvents.addListener("TabOpen", this);
AllWindowEvents.addListener("TabClose", this);
WindowListManager.addOpenListener(this.handleWindowOpen.bind(this));

this._initialized = true;
},

handleEvent(event) {
if (event.type == "TabOpen") {
let {adoptedTab} = event.detail;
if (adoptedTab) {
// This tab is being created to adopt a tab from a different window.
// Copy the ID from the old tab to the new.
this._tabs.set(event.target, this.getId(adoptedTab));
}
} else if (event.type == "TabClose") {
let {adoptedBy} = event.detail;
if (adoptedBy) {
// This tab is being closed because it was adopted by a new window.
// Copy its ID to the new tab, in case it was created as the first tab
// of a new window, and did not have an `adoptedTab` detail when it was
// opened.
this._tabs.set(adoptedBy, this.getId(event.target));
}
}
},

handleWindowOpen(window) {
if (window.arguments[0] instanceof window.XULElement) {
// If the first window argument is a XUL element, it means the
// window is about to adopt a tab from another window to replace its
// initial tab.
let adoptedTab = window.arguments[0];

this._tabs.set(window.gBrowser.tabs[0], this.getId(adoptedTab));
}
},

getId(tab) {
if (this._tabs.has(tab)) {
return this._tabs.get(tab);
}
this.initListener();

let id = this._nextId++;
this._tabs.set(tab, id);
return id;
Expand Down Expand Up @@ -583,7 +637,7 @@ global.WindowManager = {
convert(extension, window, getInfo) {
let result = {
id: this.getId(window),
focused: window == WindowManager.topWindow,
focused: window.document.hasFocus(),
top: window.screenY,
left: window.screenX,
width: window.outerWidth,
Expand Down