Detect targets for API calls about tab relations based on "browser" element, instead of "Window" objects

This commit is contained in:
YUKI Hiroshi 2014-10-29 20:36:12 +09:00
parent b871d1ab4e
commit 12cdd76f7e
3 changed files with 59 additions and 63 deletions

View File

@ -1109,6 +1109,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
return null; return null;
}, },
// this is used only for obsolete API call on non-E10S windows
getTabFromFrame : function TSTBase_getTabFromFrame(aFrame, aTabBrowser) getTabFromFrame : function TSTBase_getTabFromFrame(aFrame, aTabBrowser)
{ {
var b = aTabBrowser || this.browser; var b = aTabBrowser || this.browser;
@ -1259,27 +1260,27 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
this.browser ; this.browser ;
}, },
getFrameFromTabBrowserElements : function TSTBase_getFrameFromTabBrowserElements(aFrameOrTabBrowser) getBrowserFromTabBrowserElements : function TSTBase_getBrowserFromTabBrowserElements(aTarget)
{ {
var frame = aFrameOrTabBrowser; if (aTarget == '[object XULElement]') {
if (frame == '[object XULElement]') { if (aTarget.localName == 'tab')
if (frame.localName == 'tab') { return aTarget.linkedBrowser;
frame = frame.linkedBrowser.contentWindow;
}
else if (frame.localName == 'browser') {
frame = frame.contentWindow;
}
else {
frame = this.getTabBrowserFromChild(frame);
if (!frame)
return null;
frame = frame.contentWindow;
}
}
if (!frame)
frame = this.browser.contentWindow;
return frame; if (aTarget.localName == 'browser')
return aTarget;
aTarget = this.getTabBrowserFromChild(aTarget);
if (aTarget)
return aTarget.selectedTab.linkedBrowser;
else
return null;
}
if (aTarget == '[object Window]' || aTarget == '[object ChromeWindow]') {
let tab = this.getTabFromFrame(aTarget, this.getTabBrowserFromFrame(aTarget));
if (tab)
return tab.linkedBrowser;
}
return this.browser.selectedTab.linkedBrowser;
}, },
/* get tab(s) */ /* get tab(s) */
@ -1538,18 +1539,18 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
/* notify "ready to open child tab(s)" */ /* notify "ready to open child tab(s)" */
readyToOpenChildTab : function TSTBase_readyToOpenChildTab(aFrameOrTabBrowser, aMultiple, aInsertBefore) /* PUBLIC API */ readyToOpenChildTab : function TSTBase_readyToOpenChildTab(aTabOrSomething, aMultiple, aInsertBefore) /* PUBLIC API */
{ {
if (!utils.getTreePref('autoAttach')) if (!utils.getTreePref('autoAttach'))
return false; return false;
var frame = this.getFrameFromTabBrowserElements(aFrameOrTabBrowser); var browser = this.getBrowserFromTabBrowserElements(aTabOrSomething);
if (!frame) if (!browser)
return false; return false;
var ownerBrowser = this.getTabBrowserFromFrame(frame); var ownerBrowser = this.getTabBrowserFromFrame(browser);
var parentTab = this.getTabFromFrame(frame, ownerBrowser); var parentTab = this.getTabFromBrowser(browser, ownerBrowser);
if (!parentTab || parentTab.getAttribute('pinned') == 'true') if (!parentTab || parentTab.getAttribute('pinned') == 'true')
return false; return false;
@ -1593,15 +1594,15 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
return false; return false;
}, },
readyToOpenNextSiblingTab : function TSTBase_readyToOpenNextSiblingTab(aFrameOrTabBrowser) /* PUBLIC API */ readyToOpenNextSiblingTab : function TSTBase_readyToOpenNextSiblingTab(aTabOrSomething) /* PUBLIC API */
{ {
var frame = this.getFrameFromTabBrowserElements(aFrameOrTabBrowser); var browser = this.getBrowserFromTabBrowserElements(aTabOrSomething);
if (!frame) if (!browser)
return false; return false;
var ownerBrowser = this.getTabBrowserFromFrame(frame); var ownerBrowser = this.getTabBrowserFromChild(browser);
var tab = this.getTabFromFrame(frame, ownerBrowser); var tab = this.getTabFromBrowser(browser, ownerBrowser);
if (!tab || tab.getAttribute('pinned') == 'true') if (!tab || tab.getAttribute('pinned') == 'true')
return false; return false;
@ -1654,13 +1655,13 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
if (!utils.getTreePref('autoAttach')) if (!utils.getTreePref('autoAttach'))
return false; return false;
var frame = this.getFrameFromTabBrowserElements(aFrameOrTabBrowser); var browser = this.getBrowserFromTabBrowserElements(aTabOrSomething);
if (!frame) if (!browser)
return false; return false;
this.stopToOpenChildTab(frame); this.stopToOpenChildTab(browser);
var ownerBrowser = this.getTabBrowserFromFrame(frame); var ownerBrowser = this.getTabBrowserFromFrame(browser);
ownerBrowser.treeStyleTab.readiedToAttachNewTabGroup = true; ownerBrowser.treeStyleTab.readiedToAttachNewTabGroup = true;
ownerBrowser.treeStyleTab.readiedToAttachMultiple = true; ownerBrowser.treeStyleTab.readiedToAttachMultiple = true;
ownerBrowser.treeStyleTab.multipleCount = 0; ownerBrowser.treeStyleTab.multipleCount = 0;
@ -1691,13 +1692,13 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
return false; return false;
}, },
stopToOpenChildTab : function TSTBase_stopToOpenChildTab(aFrameOrTabBrowser) /* PUBLIC API */ stopToOpenChildTab : function TSTBase_stopToOpenChildTab(aTabOrSomething) /* PUBLIC API */
{ {
var frame = this.getFrameFromTabBrowserElements(aFrameOrTabBrowser); var browser = this.getBrowserFromTabBrowserElements(aTabOrSomething);
if (!frame) if (!browser)
return false; return false;
var ownerBrowser = this.getTabBrowserFromFrame(frame); var ownerBrowser = this.getTabBrowserFromChild(browser);
ownerBrowser.treeStyleTab.readiedToAttachNewTab = false; ownerBrowser.treeStyleTab.readiedToAttachNewTab = false;
ownerBrowser.treeStyleTab.readiedToAttachNewTabGroup = false; ownerBrowser.treeStyleTab.readiedToAttachNewTabGroup = false;
ownerBrowser.treeStyleTab.readiedToAttachMultiple = false; ownerBrowser.treeStyleTab.readiedToAttachMultiple = false;
@ -1710,13 +1711,13 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
return true; return true;
}, },
checkToOpenChildTab : function TSTBase_checkToOpenChildTab(aFrameOrTabBrowser) /* PUBLIC API */ checkToOpenChildTab : function TSTBase_checkToOpenChildTab(aTabOrSomething) /* PUBLIC API */
{ {
var frame = this.getFrameFromTabBrowserElements(aFrameOrTabBrowser); var browser = this.getBrowserFromTabBrowserElements(aTabOrSomething);
if (!frame) if (!browser)
return false; return false;
var ownerBrowser = this.getTabBrowserFromFrame(frame); var ownerBrowser = this.getTabBrowserFromChild(browser);
return !!(ownerBrowser.treeStyleTab.readiedToAttachNewTab || ownerBrowser.treeStyleTab.readiedToAttachNewTabGroup); return !!(ownerBrowser.treeStyleTab.readiedToAttachNewTab || ownerBrowser.treeStyleTab.readiedToAttachNewTabGroup);
}, },
@ -1727,11 +1728,11 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
kNEWTAB_OPEN_AS_NEXT_SIBLING : 3, kNEWTAB_OPEN_AS_NEXT_SIBLING : 3,
readyToOpenRelatedTabAs : function TSTBase_readyToOpenRelatedTabAs(aBaseTab, aBehavior) readyToOpenRelatedTabAs : function TSTBase_readyToOpenRelatedTabAs(aBaseTab, aBehavior)
{ {
var frame = this.getFrameFromTabBrowserElements(aBaseTab); var browser = this.getBrowserFromTabBrowserElements(aBaseTab);
if (!frame) if (!browser)
return; return;
aBaseTab = this.getTabFromFrame(frame, this.getTabBrowserFromFrame(frame)); aBaseTab = this.getTabFromBrowser(browser, this.getTabBrowserFromChild(browser));
switch (aBehavior) switch (aBehavior)
{ {

View File

@ -3764,6 +3764,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
if (!tab.selected && if (!tab.selected &&
this.mTabBrowser.currentURI.spec == 'about:sessionrestore') { this.mTabBrowser.currentURI.spec == 'about:sessionrestore') {
// because this is a chrome document, E10S is not applied.
let frame = this.mTabBrowser.contentWindow; let frame = this.mTabBrowser.contentWindow;
frame = frame.wrappedJSObject || frame; frame = frame.wrappedJSObject || frame;
let tree = frame.document.getElementById('tabList'); let tree = frame.document.getElementById('tabList');

View File

@ -79,33 +79,27 @@ function test_getTabBrowserFromFrame()
assertTabBrowserFrame(gBrowser, null); assertTabBrowserFrame(gBrowser, null);
} }
function test_getFrameFromTabBrowserElements() function test_getBrowserFromTabBrowserElements()
{ {
function assertFrameTabBrowser(aExpected, aArgument) function assertBrowser(aExpected, aArgument)
{ {
assert.equals(aExpected, sv.getFrameFromTabBrowserElements(aArgument)); assert.equals(aExpected, sv.getBrowserFromTabBrowserElements(aArgument));
} }
var tab, frame; var tab, browser;
tab = gBrowser.selectedTab; tab = gBrowser.selectedTab;
frame = gBrowser.contentWindow; browser = tab.linkedBrowser;
assertFrameTabBrowser(frame, frame); assertBrowser(browser, browser);
assertFrameTabBrowser(frame, tab); assertBrowser(browser, tab);
assertFrameTabBrowser(frame, tab.linkedBrowser); assertBrowser(browser, tab.linkedBrowser);
assertFrameTabBrowser(frame, tab.ownerDocument.getAnonymousNodes(tab)[0]); assertBrowser(browser, tab.ownerDocument.getAnonymousNodes(tab)[0]);
assertFrameTabBrowser(tabs[2].linkedBrowser.contentWindow, tabs[2]); assertBrowser(tabs[2].linkedBrowser, tabs[2]);
frame = tabs[2].linkedBrowser.contentWindow.frames[1];
assertFrameTabBrowser(frame, frame);
assertFrameTabBrowser(tabs[3].linkedBrowser.contentWindow, tabs[3]); assertBrowser(browser, null);
frame = tabs[3].linkedBrowser.contentWindow.frames[0]; assertBrowser(browser, gBrowser);
assertFrameTabBrowser(frame, frame); assert.isNull(sv.getBrowserFromTabBrowserElements(gBrowser.parentNode));
assertFrameTabBrowser(gBrowser.contentWindow, null);
assertFrameTabBrowser(gBrowser.contentWindow, gBrowser);
assert.isNull(sv.getFrameFromTabBrowserElements(gBrowser.parentNode));
} }
function test_tabID() function test_tabID()