Bug 1348686 - WIP , just a begining of the type change process
MozReview-Commit-ID: FyxT6Cm0Fyc
--- a/mobile/android/base/java/org/mozilla/gecko/Tab.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tab.java
@@ -765,16 +765,26 @@ public class Tab {
public boolean isPrivate() {
return false;
}
public TabType getType() {
return mType;
}
+ public void setType(TabType type) {
+ if (mType != type) {
+ mType = type;
+ final GeckoBundle data = new GeckoBundle(1);
+ data.putInt("id", mId);
+ // TODO: 3/31/17 Not sure what to send here. If it's Tab:Load then we should make the data
+ // more complete
+ EventDispatcher.getInstance().dispatch("Tab:Load", data);
+ }
+ }
public enum TabType {
BROWSING,
CUSTOMTAB,
WEBAPP
}
/**
--- a/mobile/android/base/java/org/mozilla/gecko/Tabs.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tabs.java
@@ -134,16 +134,17 @@ public class Tabs implements BundleEvent
"Link:Touchicon",
"Tab:Added",
"Tab:AudioPlayingChange",
"Tab:Close",
"Tab:MediaPlaybackChange",
"Tab:RecordingChange",
"Tab:Select",
"Tab:SetParentId",
+ "Tab:TypeChanged",
null);
EventDispatcher.getInstance().registerBackgroundThreadListener(this,
// BrowserApp already wants this on the background thread.
"Sanitize:ClearHistory",
null);
mPrivateClearColor = Color.RED;
@@ -671,17 +672,25 @@ public class Tabs implements BundleEvent
notifyListeners(tab, TabEvents.MEDIA_PLAYING_RESUME);
} else {
tab.setIsMediaPlaying(status.equals("start"));
notifyListeners(tab, TabEvents.MEDIA_PLAYING_CHANGE);
}
} else if ("Tab:SetParentId".equals(event)) {
tab.setParentId(message.getInt("parentID", -1));
+ } else if ("Tab:TypeChanged".equals(event)) {
+ final String tabType = message.getString("tabType");
+ try {
+ tab.setType(TabType.valueOf(tabType));
+ } catch (IllegalArgumentException e) {
+ tab.setType(TabType.BROWSING);
+ }
}
+
}
public void refreshThumbnails() {
final BrowserDB db = BrowserDB.from(mAppContext);
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
for (final Tab tab : mOrder) {
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -3451,16 +3451,17 @@ nsBrowserAccess.prototype = {
};
function Tab(aURL, aParams) {
this.filter = null;
this.browser = null;
this.id = 0;
this._parentId = -1;
+ this._type = null;
this.lastTouchedAt = Date.now();
this.contentDocumentIsDisplayed = true;
this.pluginDoorhangerTimeout = null;
this.shouldShowPluginDoorhanger = true;
this.clickToPlayPluginsActivated = false;
this.desktopMode = false;
this.originalURI = null;
this.hasTouchListener = false;
@@ -3559,17 +3560,17 @@ Tab.prototype = {
// When the tab is stubbed from Java, there's a window between the stub
// creation and the tab creation in Gecko where the stub could be removed
// or the selected tab can change (which is easiest to hit during startup).
// To prevent these races, we need to differentiate between tab stubs from
// Java and new tabs from Gecko.
let stub = false;
// The authoritative list of possible tab types is the TabType enum in Tab.java.
- this.type = "tabType" in aParams ? aParams.tabType : "BROWSING";
+ this._type = "tabType" in aParams ? aParams.tabType : "BROWSING";
if (!aParams.zombifying) {
if ("tabID" in aParams) {
this.id = aParams.tabID;
stub = true;
} else {
let jenv = JNI.GetForThread();
let jTabs = JNI.LoadClass(jenv, "org.mozilla.gecko.Tabs", {
@@ -3996,16 +3997,30 @@ Tab.prototype = {
this._parentId = newParentId;
GlobalEventDispatcher.sendRequest({
type: "Tab:SetParentId",
tabID: this.id,
parentID: newParentId
});
},
+ get type() {
+ return this._type;
+ },
+
+ set type(aType) {
+ // The tab type setter doesn't update the internal tab type property in Gecko,
+ // but only sends a message with the new tab type to Java
+ GlobalEventDispatcher.sendRequest({
+ type: "Tab:TypeChanged",
+ tabID: this.id,
+ tabType: aType
+ });
+ },
+
get currentURI() {
if (!this.browser.__SS_restore) {
return this.browser.currentURI;
} else {
// For zombie tabs we need to fall back to the session store data.
let data = this.browser.__SS_data;
let url = data.entries[data.index - 1].url;
return Services.io.newURI(url);