Bug 1338899 - Part 1 - Use getter/setter for accessing/modifying a tab's parent ID in Gecko. r?sebastian
This should be more foolproof than having to remember to use the dedicated setParentId() function when writing to that variable from outside of the tab constructor.
MozReview-Commit-ID: 1KlXf60VsoF
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -3423,16 +3423,17 @@ nsBrowserAccess.prototype = {
},
};
function Tab(aURL, aParams) {
this.filter = null;
this.browser = null;
this.id = 0;
+ this._parentId = -1;
this.lastTouchedAt = Date.now();
this._zoom = 1.0;
this._drawZoom = 1.0;
this._restoreZoom = false;
this.userScrollPos = { x: 0, y: 0 };
this.contentDocumentIsDisplayed = true;
this.pluginDoorhangerTimeout = null;
this.shouldShowPluginDoorhanger = true;
@@ -3550,17 +3551,17 @@ Tab.prototype = {
{ name: "getNextTabId", sig: "()I" }
],
});
this.id = jTabs.getNextTabId();
JNI.UnloadClasses(jenv);
}
this.desktopMode = ("desktopMode" in aParams) ? aParams.desktopMode : false;
- this.parentId = ("parentId" in aParams && typeof aParams.parentId == "number")
+ this._parentId = ("parentId" in aParams && typeof aParams.parentId == "number")
? aParams.parentId : -1;
let message = {
type: "Tab:Added",
tabID: this.id,
uri: truncate(uri, MAX_URI_LENGTH),
parentId: this.parentId,
tabIndex: ("tabIndex" in aParams) ? aParams.tabIndex : -1,
@@ -3954,19 +3955,23 @@ Tab.prototype = {
type: "Link:OpenSearch",
tabID: this.id,
visible: true
});
});
}
},
- setParentId: function(aParentId) {
+ get parentId() {
+ return this._parentId;
+ },
+
+ set parentId(aParentId) {
let newParentId = (typeof aParentId == "number") ? aParentId : -1;
- this.parentId = newParentId;
+ this._parentId = newParentId;
GlobalEventDispatcher.sendRequest({
type: "Tab:SetParentId",
tabID: this.id,
parentID: newParentId
});
},
handleEvent: function(aEvent) {
--- a/mobile/android/components/SessionStore.js
+++ b/mobile/android/components/SessionStore.js
@@ -1643,17 +1643,17 @@ SessionStore.prototype = {
// Don't restore tab if user has already closed it
if (tab == null) {
delete tabData.tabId;
continue;
}
let parentId = tabData.parentId;
if (parentId > -1) {
- tab.setParentId(parentId);
+ tab.parentId = parentId;
}
tab.browser.__SS_data = tabData;
tab.browser.__SS_extdata = tabData.extData;
if (window.BrowserApp.selectedTab == tab) {
this._restoreTab(tabData, tab.browser);