Bug 800199 - Stub initial tab before Gecko starts. r=mfinkle

This commit is contained in:
Brian Nicholson 2012-10-15 10:40:16 -07:00
parent c61c599711
commit 4a55193d26
6 changed files with 51 additions and 50 deletions

View File

@ -261,12 +261,15 @@ abstract public class BrowserApp extends GeckoApp
super.finishProfileMigration();
}
// We don't want to call super.initializeChrome in here because we don't
// want to create two DoorHangerPopup instances.
@Override void initializeChrome(String uri, Boolean isExternalURL) {
@Override
protected void initializeChrome(String uri, Boolean isExternalURL) {
super.initializeChrome(uri, isExternalURL);
mBrowserToolbar.updateBackButton(false);
mBrowserToolbar.updateForwardButton(false);
mDoorHangerPopup.setAnchor(mBrowserToolbar.mFavicon);
Intent intent = getIntent();
String action = intent.getAction();
String args = intent.getStringExtra("args");
@ -278,23 +281,17 @@ abstract public class BrowserApp extends GeckoApp
}
}
if (uri != null && uri.length() > 0) {
mBrowserToolbar.setTitle(uri);
}
if (!isExternalURL) {
// show about:home if we aren't restoring previous session
if (mRestoreMode == GeckoAppShell.RESTORE_NONE) {
mBrowserToolbar.updateTabCount(1);
Tab tab = Tabs.getInstance().loadUrl("about:home", Tabs.LOADURL_NEW_TAB);
tab.updateTitle(null);
showAboutHome();
}
} else {
mBrowserToolbar.updateTabCount(1);
hideAboutHome();
Tabs.getInstance().loadUrl(uri, Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_USER_ENTERED);
}
mBrowserToolbar.setProgressVisibility(isExternalURL || (mRestoreMode != GeckoAppShell.RESTORE_NONE));
mDoorHangerPopup = new DoorHangerPopup(this, mBrowserToolbar.mFavicon);
}
void toggleChrome(final boolean aShow) {

View File

@ -635,11 +635,6 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
public void setTitle(CharSequence title) {
Tab tab = Tabs.getInstance().getSelectedTab();
// We use about:empty as a placeholder for an external page load and
// we don't want to change the title
if (tab != null && "about:empty".equals(tab.getURL()))
return;
// Keep the title unchanged if the tab is entering reader mode
if (tab != null && tab.isEnteringReaderMode())
return;

View File

@ -1555,7 +1555,7 @@ abstract public class GeckoApp
});
}
void initializeChrome(String uri, Boolean isExternalURL) {
protected void initializeChrome(String uri, Boolean isExternalURL) {
mDoorHangerPopup = new DoorHangerPopup(this, null);
}
@ -1610,8 +1610,6 @@ abstract public class GeckoApp
}
boolean isExternalURL = passedUri != null && !passedUri.equals("about:home");
initializeChrome(uri, isExternalURL);
StartupAction startupAction;
if (isExternalURL) {
startupAction = StartupAction.URL;
@ -1635,13 +1633,20 @@ abstract public class GeckoApp
// loading it twice
intent.setAction(Intent.ACTION_MAIN);
intent.setData(null);
passedUri = "about:empty";
passedUri = null;
} else {
startupAction = StartupAction.PREFETCH;
GeckoAppShell.getHandler().post(new PrefetchRunnable(copy));
}
}
initializeChrome(passedUri, isExternalURL);
if (mRestoreMode == GeckoAppShell.RESTORE_NONE) {
// show telemetry door hanger if we aren't restoring a session
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Telemetry:Prompt", null));
}
Telemetry.HistogramAdd("FENNEC_STARTUP_GECKOAPP_ACTION", startupAction.ordinal());
if (!mIsRestoringActivity) {

View File

@ -38,6 +38,7 @@ public class Tabs implements GeckoEventListener {
public static final int LOADURL_NEW_TAB = 1;
public static final int LOADURL_USER_ENTERED = 2;
public static final int LOADURL_PRIVATE = 4;
public static final int LOADURL_PINNED = 8;
private static final int SCORE_INCREMENT_TAB_LOCATION_CHANGE = 5;
private static final int SCORE_INCREMENT_TAB_SELECTED = 10;
@ -460,9 +461,11 @@ public class Tabs implements GeckoEventListener {
*
* @param url URL of page to load, or search term used if searchEngine is given
* @param flags flags used to load tab
*
* @return the Tab if a new one was created; null otherwise
*/
public void loadUrl(String url, int flags) {
loadUrl(url, null, -1, flags);
public Tab loadUrl(String url, int flags) {
return loadUrl(url, null, -1, flags);
}
/**
@ -473,25 +476,30 @@ public class Tabs implements GeckoEventListener {
* to search for the url string; if null, the URL is loaded directly
* @param parentId ID of this tab's parent, or -1 if it has no parent
* @param flags flags used to load tab
*
* @return the Tab if a new one was created; null otherwise
*/
public void loadUrl(String url, String searchEngine, int parentId, int flags) {
public Tab loadUrl(String url, String searchEngine, int parentId, int flags) {
JSONObject args = new JSONObject();
int tabId = -1;
Tab added = null;
try {
boolean isPrivate = (flags & LOADURL_PRIVATE) != 0;
boolean userEntered = (flags & LOADURL_USER_ENTERED) != 0;
args.put("url", url);
args.put("engine", searchEngine);
args.put("parentId", parentId);
args.put("userEntered", (flags & LOADURL_USER_ENTERED) != 0);
args.put("userEntered", userEntered);
args.put("newTab", (flags & LOADURL_NEW_TAB) != 0);
args.put("isPrivate", isPrivate);
args.put("pinned", (flags & LOADURL_PINNED) != 0);
if ((flags & LOADURL_NEW_TAB) != 0) {
tabId = getNextTabId();
args.put("tabID", tabId);
addTab(tabId, null, false, parentId, url, isPrivate);
added = addTab(tabId, (userEntered ? null : url), false, parentId, url, isPrivate);
}
} catch (Exception e) {
Log.e(LOGTAG, "error building JSON arguments");
@ -503,6 +511,8 @@ public class Tabs implements GeckoEventListener {
if (tabId != -1) {
selectTab(tabId);
}
return added;
}
/**

View File

@ -88,6 +88,12 @@ public class WebApp extends GeckoApp {
}
}
@Override
protected void initializeChrome(String uri, Boolean isExternalURL) {
super.initializeChrome(uri, isExternalURL);
Tabs.getInstance().loadUrl(uri, Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_USER_ENTERED | Tabs.LOADURL_PINNED);
}
private void showSplash() {
mSplashscreen = (RelativeLayout) findViewById(R.id.splashscreen);

View File

@ -245,8 +245,7 @@ var BrowserApp = {
// Init FormHistory
Cc["@mozilla.org/satchel/form-history;1"].getService(Ci.nsIFormHistory2);
let loadParams = {};
let url = "about:home";
let url = null;
let restoreMode = 0;
let pinned = false;
if ("arguments" in window) {
@ -270,9 +269,6 @@ var BrowserApp = {
this.initContextMenu();
}
if (url == "about:empty")
loadParams.flags = Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_HISTORY;
// XXX maybe we don't do this if the launch was kicked off from external
Services.io.offline = false;
@ -296,12 +292,8 @@ var BrowserApp = {
}
});
// Open any commandline URLs, except the homepage
if (url && url != "about:home") {
loadParams.pinned = pinned;
this.addTab(url, loadParams);
} else {
// Let the session make a restored tab active
// Make the restored tab active if we aren't loading an external URL
if (url == null) {
restoreToFront = true;
}
@ -327,15 +319,6 @@ var BrowserApp = {
// Start the restore
ss.restoreLastSession(restoreToFront, restoreMode == 1);
} else {
loadParams.showProgress = shouldShowProgress(url);
loadParams.pinned = pinned;
this.addTab(url, loadParams);
// show telemetry door hanger if we aren't restoring a session
#ifdef MOZ_TELEMETRY_REPORTING
Telemetry.prompt();
#endif
}
if (updated)
@ -1067,8 +1050,6 @@ var BrowserApp = {
observe: function(aSubject, aTopic, aData) {
let browser = this.selectedBrowser;
if (!browser)
return;
if (aTopic == "Session:Back") {
browser.goBack();
@ -1092,7 +1073,8 @@ var BrowserApp = {
parentId: ("parentId" in data) ? data.parentId : -1,
flags: flags,
tabID: data.tabID,
isPrivate: data.isPrivate
isPrivate: data.isPrivate,
pinned: data.pinned
};
let url = data.url;
@ -6815,11 +6797,13 @@ var Telemetry = {
init: function init() {
Services.obs.addObserver(this, "Preferences:Set", false);
Services.obs.addObserver(this, "Telemetry:Add", false);
Services.obs.addObserver(this, "Telemetry:Prompt", false);
},
uninit: function uninit() {
Services.obs.removeObserver(this, "Preferences:Set");
Services.obs.removeObserver(this, "Telemetry:Add");
Services.obs.removeObserver(this, "Telemetry:Prompt");
},
observe: function observe(aSubject, aTopic, aData) {
@ -6833,6 +6817,10 @@ var Telemetry = {
var telemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry);
let histogram = telemetry.getHistogramById(json.name);
histogram.add(json.value);
} else if (aTopic == "Telemetry:Prompt") {
#ifdef MOZ_TELEMETRY_REPORTING
this.prompt();
#endif
}
},