Backed out changeset ab088eb19b46 (bug 1258464)
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Wed, 30 Mar 2016 14:02:07 +0200
changeset 290868 791698f3f8cfaa225a00339f8b2b963bca71c407
parent 290867 3df6a745a563855868ce0dfaba1c74f0f263307f
child 290869 d202b268a22881704adae85f42c4473e1b82259c
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1258464
milestone48.0a1
backs outab088eb19b46d9e8dc5551e39aa4a871a4c9ee23
Backed out changeset ab088eb19b46 (bug 1258464)
mobile/android/base/java/org/mozilla/gecko/GeckoView.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoView.java
@@ -1,15 +1,18 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 import java.util.Set;
 
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.mozilla.gecko.annotation.ReflectionTarget;
 import org.mozilla.gecko.annotation.WrapForJNI;
 import org.mozilla.gecko.gfx.GLController;
 import org.mozilla.gecko.gfx.LayerView;
@@ -353,26 +356,90 @@ public class GeckoView extends LayerView
                 mInputConnectionListener.onKeyMultiple(keyCode, repeatCount, event);
     }
 
     /* package */ boolean isIMEEnabled() {
         return mInputConnectionListener != null &&
                 mInputConnectionListener.isIMEEnabled();
     }
 
+    /**
+    * Add a Browser to the GeckoView container.
+    * @param url The URL resource to load into the new Browser.
+    */
+    public Browser addBrowser(String url) {
+        Tab tab = Tabs.getInstance().loadUrl(url, Tabs.LOADURL_NEW_TAB);
+        if (tab != null) {
+            return new Browser(tab.getId());
+        }
+        return null;
+    }
+
+    /**
+    * Remove a Browser from the GeckoView container.
+    * @param browser The Browser to remove.
+    */
+    public void removeBrowser(Browser browser) {
+        Tab tab = Tabs.getInstance().getTab(browser.getId());
+        if (tab != null) {
+            Tabs.getInstance().closeTab(tab);
+        }
+    }
+
+    /**
+    * Set the active/visible Browser.
+    * @param browser The Browser to make selected.
+    */
+    public void setCurrentBrowser(Browser browser) {
+        Tab tab = Tabs.getInstance().getTab(browser.getId());
+        if (tab != null) {
+            Tabs.getInstance().selectTab(tab.getId());
+        }
+    }
+
+    /**
+    * Get the active/visible Browser.
+    * @return The current selected Browser.
+    */
+    public Browser getCurrentBrowser() {
+        Tab tab = Tabs.getInstance().getSelectedTab();
+        if (tab != null) {
+            return new Browser(tab.getId());
+        }
+        return null;
+    }
+
+    /**
+    * Get the list of current Browsers in the GeckoView container.
+    * @return An unmodifiable List of Browser objects.
+    */
+    public List<Browser> getBrowsers() {
+        ArrayList<Browser> browsers = new ArrayList<Browser>();
+        Iterable<Tab> tabs = Tabs.getInstance().getTabsInOrder();
+        for (Tab tab : tabs) {
+            browsers.add(new Browser(tab.getId()));
+        }
+        return Collections.unmodifiableList(browsers);
+    }
+
     public void importScript(final String url) {
         if (url.startsWith("resource://android/assets/")) {
             GeckoAppShell.notifyObservers("GeckoView:ImportScript", url);
             return;
         }
 
         throw new IllegalArgumentException("Must import script from 'resources://android/assets/' location.");
     }
 
     private void connectToGecko() {
+        Tab selectedTab = Tabs.getInstance().getSelectedTab();
+        if (selectedTab != null) {
+            Tabs.getInstance().notifyListeners(selectedTab, Tabs.TabEvents.SELECTED);
+        }
+
         GeckoAppShell.notifyObservers("Viewport:Flush", null);
     }
 
     private void handleReady(final JSONObject message) {
         connectToGecko();
 
         if (mChromeDelegate != null) {
             mChromeDelegate.onReady(this);
@@ -518,16 +585,85 @@ public class GeckoView extends LayerView
                 args.put("parentId", -1);
                 args.put("newTab", false);
                 args.put("tabID", mId);
             } catch (Exception e) {
                 Log.w(LOGTAG, "Error building JSON arguments for loadUrl.", e);
             }
             GeckoAppShell.notifyObservers("Tab:Load", args.toString());
         }
+
+        /**
+        * Reload the current URL resource into the Browser. The URL is force loaded from the
+        * network and is not pulled from cache.
+        */
+        public void reload() {
+            Tab tab = Tabs.getInstance().getTab(mId);
+            if (tab != null) {
+                tab.doReload(true);
+            }
+        }
+
+        /**
+        * Stop the current loading operation.
+        */
+        public void stop() {
+            Tab tab = Tabs.getInstance().getTab(mId);
+            if (tab != null) {
+                tab.doStop();
+            }
+        }
+
+        /**
+        * Check to see if the Browser has session history and can go back to a
+        * previous page.
+        * @return A boolean flag indicating if previous session exists.
+        * This method will likely be removed and replaced by a callback in GeckoViewContent
+        */
+        public boolean canGoBack() {
+            Tab tab = Tabs.getInstance().getTab(mId);
+            if (tab != null) {
+                return tab.canDoBack();
+            }
+            return false;
+        }
+
+        /**
+        * Move backward in the session history, if that's possible.
+        */
+        public void goBack() {
+            Tab tab = Tabs.getInstance().getTab(mId);
+            if (tab != null) {
+                tab.doBack();
+            }
+        }
+
+        /**
+        * Check to see if the Browser has session history and can go forward to a
+        * new page.
+        * @return A boolean flag indicating if forward session exists.
+        * This method will likely be removed and replaced by a callback in GeckoViewContent
+        */
+        public boolean canGoForward() {
+            Tab tab = Tabs.getInstance().getTab(mId);
+            if (tab != null) {
+                return tab.canDoForward();
+            }
+            return false;
+        }
+
+        /**
+        * Move forward in the session history, if that's possible.
+        */
+        public void goForward() {
+            Tab tab = Tabs.getInstance().getTab(mId);
+            if (tab != null) {
+                tab.doForward();
+            }
+        }
     }
 
     /* Provides a means for the client to indicate whether a JavaScript
      * dialog request should proceed. An instance of this class is passed to
      * various GeckoViewChrome callback actions.
      */
     public class PromptResult {
         private final int RESULT_OK = 0;