Backout e7208eeb05da for Android failures
authorBrian Nicholson <bnicholson@mozilla.com>
Mon, 15 Oct 2012 13:16:06 -0700
changeset 110458 3ff5410852cc65d582e1ae4eed6e18c6a2f36fcc
parent 110457 66c3714ea45fdd00b1688ba1ba7f84ba8594a6e4
child 110459 40204318c5b71f00cd183e540d1e009b6cfcbeeb
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
milestone19.0a1
backs oute7208eeb05dacbba00bdf8e7631c7c0c5e8438a1
Backout e7208eeb05da for Android failures
mobile/android/base/BrowserApp.java
mobile/android/base/BrowserToolbar.java
mobile/android/base/GeckoApp.java
mobile/android/base/Tabs.java
mobile/android/base/WebApp.java.in
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -258,44 +258,47 @@ abstract public class BrowserApp extends
         // Update about:home with the new information.
         updateAboutHomeTopSites();
 
         super.finishProfileMigration();
     }
 
     // We don't want to call super.initializeChrome in here because we don't
     // want to create two DoorHangerPopup instances.
-    @Override
-    protected void initializeChrome(String uri, Boolean isExternalURL) {
+    @Override void initializeChrome(String uri, Boolean isExternalURL) {
         mBrowserToolbar.updateBackButton(false);
         mBrowserToolbar.updateForwardButton(false);
 
         Intent intent = getIntent();
         String action = intent.getAction();
         String args = intent.getStringExtra("args");
         if (args != null && args.contains("-profile")) {
             Pattern p = Pattern.compile("(?:-profile\\s*)(\\w*)(\\s*)");
             Matcher m = p.matcher(args);
             if (m.find()) {
                 mBrowserToolbar.setTitle(null);
             }
         }
 
+        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) {
-                Tab tab = Tabs.getInstance().loadUrl("about:home", Tabs.LOADURL_NEW_TAB);
-                tab.updateTitle(null);
+                mBrowserToolbar.updateTabCount(1);
                 showAboutHome();
             }
         } else {
-            hideAboutHome();
-            Tabs.getInstance().loadUrl(uri, Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_USER_ENTERED);
+            mBrowserToolbar.updateTabCount(1);
         }
 
+        mBrowserToolbar.setProgressVisibility(isExternalURL || (mRestoreMode != GeckoAppShell.RESTORE_NONE));
+
         mDoorHangerPopup = new DoorHangerPopup(this, mBrowserToolbar.mFavicon);
     }
 
     void toggleChrome(final boolean aShow) {
         mMainHandler.post(new Runnable() {
             public void run() {
                 if (aShow) {
                     mBrowserToolbar.show();
--- a/mobile/android/base/BrowserToolbar.java
+++ b/mobile/android/base/BrowserToolbar.java
@@ -630,16 +630,21 @@ public class BrowserToolbar implements V
 
     public void setShadowVisibility(boolean visible) {
         mShadow.setVisibility(visible ? View.VISIBLE : View.GONE);
     }
 
     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;
 
         // Setting a null title for about:home will ensure we just see
         // the "Enter Search or Address" placeholder text
         if (tab != null && "about:home".equals(tab.getURL()))
             title = null;
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -1550,17 +1550,17 @@ abstract public class GeckoApp
                 // put a flag to check if we got a normal onSaveInstaceState
                 // on exit, or if we were suddenly killed (crash or native OOM)
                 editor.putBoolean(GeckoApp.PREFS_WAS_STOPPED, false);
                 editor.commit();
             }
         });
     }
 
-    protected void initializeChrome(String uri, Boolean isExternalURL) {
+    void initializeChrome(String uri, Boolean isExternalURL) {
         mDoorHangerPopup = new DoorHangerPopup(this, null);
     }
 
     private void initialize() {
         mInitialized = true;
 
         invalidateOptionsMenu();
 
@@ -1605,16 +1605,18 @@ abstract public class GeckoApp
         }
 
         if (mRestoreMode == GeckoAppShell.RESTORE_NONE && getProfile().shouldRestoreSession()) {
             Log.i(LOGTAG, "Restoring crash");
             mRestoreMode = GeckoAppShell.RESTORE_CRASH;
         }
 
         boolean isExternalURL = passedUri != null && !passedUri.equals("about:home");
+        initializeChrome(uri, isExternalURL);
+
         StartupAction startupAction;
         if (isExternalURL) {
             startupAction = StartupAction.URL;
         } else {
             startupAction = StartupAction.NORMAL;
         }
 
         // Start migrating as early as possible, can do this in
@@ -1628,25 +1630,23 @@ abstract public class GeckoApp
             if (isHostOnRedirectWhitelist(data.getHost())) {
                 startupAction = StartupAction.REDIRECTOR;
                 GeckoAppShell.getHandler().post(new RedirectorRunnable(copy));
                 // We're going to handle this uri with the redirector, so setting
                 // the action to MAIN and clearing the uri data prevents us from
                 // loading it twice
                 intent.setAction(Intent.ACTION_MAIN);
                 intent.setData(null);
-                passedUri = null;
+                passedUri = "about:empty";
             } else {
                 startupAction = StartupAction.PREFETCH;
                 GeckoAppShell.getHandler().post(new PrefetchRunnable(copy));
             }
         }
 
-        initializeChrome(passedUri, isExternalURL);
-
         Telemetry.HistogramAdd("FENNEC_STARTUP_GECKOAPP_ACTION", startupAction.ordinal());
 
         if (!mIsRestoringActivity) {
             sGeckoThread = new GeckoThread(intent, passedUri, mRestoreMode);
         }
         if (!ACTION_DEBUG.equals(action) &&
             checkAndSetLaunchState(LaunchState.Launching, LaunchState.Launched)) {
             sGeckoThread.start();
--- a/mobile/android/base/Tabs.java
+++ b/mobile/android/base/Tabs.java
@@ -33,17 +33,16 @@ public class Tabs implements GeckoEventL
 
     // Keeps track of how much has happened since we last updated our persistent tab store.
     private volatile int mScore = 0;
 
     public static final int LOADURL_NONE = 0;
     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;
     private static final int SCORE_THRESHOLD = 30;
 
     private static AtomicInteger sTabId = new AtomicInteger(0);
 
     private GeckoApp mActivity;
@@ -456,68 +455,59 @@ public class Tabs implements GeckoEventL
         loadUrl(url, LOADURL_NONE);
     }
 
     /**
      * Loads a tab with the given URL.
      *
      * @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 Tab loadUrl(String url, int flags) {
-        return loadUrl(url, null, -1, flags);
+    public void loadUrl(String url, int flags) {
+        loadUrl(url, null, -1, flags);
     }
 
     /**
      * Loads a tab with the given URL.
      *
      * @param url          URL of page to load, or search term used if searchEngine is given
      * @param searchEngine if given, the search engine with this name is used
      *                     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 Tab loadUrl(String url, String searchEngine, int parentId, int flags) {
+    public void 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", userEntered);
+            args.put("userEntered", (flags & LOADURL_USER_ENTERED) != 0);
             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);
-                added = addTab(tabId, (userEntered ? null : url), false, parentId, url, isPrivate);
+                addTab(tabId, null, false, parentId, url, isPrivate);
             }
         } catch (Exception e) {
             Log.e(LOGTAG, "error building JSON arguments");
         }
 
         Log.d(LOGTAG, "Sending message to Gecko: " + SystemClock.uptimeMillis() + " - Tab:Load");
         GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tab:Load", args.toString()));
 
         if (tabId != -1) {
             selectTab(tabId);
         }
-
-        return added;
     }
 
     /**
      * Open the url as a new tab, and mark the selected tab as its "parent".
      *
      * If the url is already open in a tab, the existing tab is selected.
      * Use this for tabs opened by the browser chrome, so users can press the
      * "Back" button to return to the previous tab.
--- a/mobile/android/base/WebApp.java.in
+++ b/mobile/android/base/WebApp.java.in
@@ -83,22 +83,16 @@ public class WebApp extends GeckoApp {
             try {
                 mOrigin = new URL(getIntent().getData().toString());
             } catch (java.net.MalformedURLException ex2) {
                 Log.e(LOGTAG, "Unable to parse intent url: ", ex);
             }
         }
     }
 
-    @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);
 
         SharedPreferences prefs = getSharedPreferences("webapps", Context.MODE_PRIVATE | Context.MODE_MULTI_PROCESS);
 
         // get the favicon dominant color, stored when the app was installed
         int[] colors = new int[2];
         int dominantColor = prefs.getInt(WebAppAllocator.iconKey(getIndex()), -1);
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -240,17 +240,18 @@ var BrowserApp = {
     AccessFu.attach(window);
 #endif
 
     // Init LoginManager
     Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
     // Init FormHistory
     Cc["@mozilla.org/satchel/form-history;1"].getService(Ci.nsIFormHistory2);
 
-    let url = null;
+    let loadParams = {};
+    let url = "about:home";
     let restoreMode = 0;
     let pinned = false;
     if ("arguments" in window) {
       if (window.arguments[0])
         url = window.arguments[0];
       if (window.arguments[1])
         restoreMode = window.arguments[1];
       if (window.arguments[2])
@@ -264,16 +265,19 @@ var BrowserApp = {
     let updated = this.isAppUpdated();
     if (pinned) {
       WebAppRT.init(updated, url);
     } else {
       SearchEngines.init();
       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;
 
     // Broadcast a UIReady message so add-ons know we are finished with startup
     let event = document.createEvent("Events");
     event.initEvent("UIReady", true, false);
     window.dispatchEvent(event);
 
@@ -287,18 +291,22 @@ var BrowserApp = {
       let restoreToFront = false;
 
       sendMessageToJava({
         gecko: {
           type: "Session:RestoreBegin"
         }
       });
 
-      // Make the restored tab active if we aren't loading an external URL
-      if (url == null) {
+      // 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
         restoreToFront = true;
       }
 
       // Be ready to handle any restore failures by making sure we have a valid tab opened
       let restoreCleanup = {
         observe: function(aSubject, aTopic, aData) {
           Services.obs.removeObserver(restoreCleanup, "sessionstore-windows-restored");
           if (aData == "fail") {
@@ -315,16 +323,20 @@ var BrowserApp = {
           });
         }
       };
       Services.obs.addObserver(restoreCleanup, "sessionstore-windows-restored", false);
 
       // 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)
       this.onAppUpdated();
@@ -1050,16 +1062,18 @@ var BrowserApp = {
 
       // finally, let java know where we ended up
       tab.sendViewportUpdate();
     }
   },
 
   observe: function(aSubject, aTopic, aData) {
     let browser = this.selectedBrowser;
+    if (!browser)
+      return;
 
     if (aTopic == "Session:Back") {
       browser.goBack();
     } else if (aTopic == "Session:Forward") {
       browser.goForward();
     } else if (aTopic == "Session:Reload") {
       browser.reload();
     } else if (aTopic == "Session:Stop") {
@@ -1073,18 +1087,17 @@ var BrowserApp = {
       if (data.userEntered)
         flags |= Ci.nsIWebNavigation.LOAD_FLAGS_DISALLOW_INHERIT_OWNER;
 
       let params = {
         selected: true,
         parentId: ("parentId" in data) ? data.parentId : -1,
         flags: flags,
         tabID: data.tabID,
-        isPrivate: data.isPrivate,
-        pinned: data.pinned
+        isPrivate: data.isPrivate
       };
 
       let url = data.url;
       if (data.engine) {
         let engine = Services.search.getEngineByName(data.engine);
         if (engine) {
           let submission = engine.getSubmission(url);
           url = submission.uri.spec;