Bug 582244 - Part 1: Bare bones PB implementation. r=mfinkle
authorBrian Nicholson <bnicholson@mozilla.com>
Tue, 09 Oct 2012 11:26:33 -0700
changeset 109771 093b6818007cc43fd416c6ddf06f7fa637da582b
parent 109770 b4989f34fdf7c09237e0ce05f1875f79d5bc6672
child 109772 e937f574fb4dd97c1cd4a89234c8bc2fa9a51454
push id23652
push userryanvm@gmail.com
push dateWed, 10 Oct 2012 01:10:20 +0000
treeherdermozilla-central@5cca0408a73f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs582244
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 582244 - Part 1: Bare bones PB implementation. r=mfinkle
mobile/android/base/BrowserApp.java
mobile/android/base/Tabs.java
mobile/android/base/locales/en-US/android_strings.dtd
mobile/android/base/resources/menu-large-v11/browser_app_menu.xml.in
mobile/android/base/resources/menu-v11/browser_app_menu.xml.in
mobile/android/base/resources/menu-xlarge-v11/browser_app_menu.xml.in
mobile/android/base/resources/menu/browser_app_menu.xml.in
mobile/android/base/strings.xml.in
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -890,16 +890,19 @@ abstract public class BrowserApp extends
                 try {
                     args.put("desktopMode", !item.isChecked());
                     args.put("tabId", selectedTab.getId());
                 } catch (JSONException e) {
                     Log.e(LOGTAG, "error building json arguments");
                 }
                 GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("DesktopMode:Change", args.toString()));
                 return true;
+            case R.id.private_browsing:
+                Tabs.getInstance().loadUrl("about:home", Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_PRIVATE);
+                return true;
             default:
                 return super.onOptionsItemSelected(item);
         }
     }
 
     /*
      * If the app has been launched a certain number of times, and we haven't asked for feedback before,
      * open a new tab with about:feedback when launching the app from the icon shortcut.
--- a/mobile/android/base/Tabs.java
+++ b/mobile/android/base/Tabs.java
@@ -32,16 +32,17 @@ public class Tabs implements GeckoEventL
     private boolean mRestoringSession;
 
     // 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;
 
     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;
@@ -450,21 +451,24 @@ public class Tabs implements GeckoEventL
      * @param parentId     ID of this tab's parent, or -1 if it has no parent
      * @param flags        flags used to load tab
      */
     public void loadUrl(String url, String searchEngine, int parentId, int flags) {
         JSONObject args = new JSONObject();
         int tabId = -1;
 
         try {
+            boolean isPrivate = (flags & LOADURL_PRIVATE) != 0;
+
             args.put("url", url);
             args.put("engine", searchEngine);
             args.put("parentId", parentId);
             args.put("userEntered", (flags & LOADURL_USER_ENTERED) != 0);
             args.put("newTab", (flags & LOADURL_NEW_TAB) != 0);
+            args.put("isPrivate", isPrivate);
 
             if ((flags & LOADURL_NEW_TAB) != 0) {
                 tabId = getNextTabId();
                 args.put("tabID", tabId);
                 addTab(tabId, null, false, parentId, url);
             }
         } catch (Exception e) {
             Log.e(LOGTAG, "error building JSON arguments");
--- a/mobile/android/base/locales/en-US/android_strings.dtd
+++ b/mobile/android/base/locales/en-US/android_strings.dtd
@@ -121,16 +121,17 @@ size. -->
 
 <!ENTITY share "Share">
 <!ENTITY share_title "Share via">
 <!ENTITY share_image_failed "Unable to share this image">
 <!ENTITY save_as_pdf "Save as PDF">
 <!ENTITY find_in_page "Find in Page">
 <!ENTITY desktop_mode "Request Desktop Site">
 <!ENTITY tools "Tools">
+<!ENTITY new_pb_tab "New Private Browsing Tab">
 
 <!-- Localization note (find_text, find_prev, find_next, find_close) : These strings are used
      as alternate text for accessibility. They are not visible in the UI. -->
 <!ENTITY find_text "Find in Page">
 <!ENTITY find_prev "Previous">
 <!ENTITY find_next "Next">
 <!ENTITY find_close "Close">
 
--- a/mobile/android/base/resources/menu-large-v11/browser_app_menu.xml.in
+++ b/mobile/android/base/resources/menu-large-v11/browser_app_menu.xml.in
@@ -27,16 +27,19 @@
           android:icon="@drawable/ic_menu_find_in_page"
           android:title="@string/find_in_page" />
 
     <item android:id="@+id/desktop_mode"
           android:icon="@drawable/ic_menu_desktop_mode_off"
           android:title="@string/desktop_mode"
           android:checkable="true" />
 
+    <item android:id="@+id/private_browsing"
+          android:title="@string/new_pb_tab"/>
+
     <item android:title="@string/tools"
           android:icon="@drawable/ic_menu_tools">
 
         <menu>
 
             <item android:id="@+id/save_as_pdf"
                   android:icon="@drawable/ic_menu_save_as_pdf"
                   android:title="@string/save_as_pdf" />
--- a/mobile/android/base/resources/menu-v11/browser_app_menu.xml.in
+++ b/mobile/android/base/resources/menu-v11/browser_app_menu.xml.in
@@ -28,16 +28,19 @@
           android:icon="@drawable/ic_menu_find_in_page"
           android:title="@string/find_in_page" />
 
     <item android:id="@+id/desktop_mode"
           android:icon="@drawable/ic_menu_desktop_mode_off"
           android:title="@string/desktop_mode"
           android:checkable="true" />
 
+    <item android:id="@+id/private_browsing"
+          android:title="@string/new_pb_tab"/>
+
     <item android:title="@string/tools"
           android:icon="@drawable/ic_menu_tools">
 
         <menu>
 
             <item android:id="@+id/save_as_pdf"
                   android:icon="@drawable/ic_menu_save_as_pdf"
                   android:title="@string/save_as_pdf" />
--- a/mobile/android/base/resources/menu-xlarge-v11/browser_app_menu.xml.in
+++ b/mobile/android/base/resources/menu-xlarge-v11/browser_app_menu.xml.in
@@ -28,16 +28,19 @@
           android:icon="@drawable/ic_menu_find_in_page"
           android:title="@string/find_in_page" />
 
     <item android:id="@+id/desktop_mode"
           android:icon="@drawable/ic_menu_desktop_mode_off"
           android:title="@string/desktop_mode"
           android:checkable="true" />
 
+    <item android:id="@+id/private_browsing"
+          android:title="@string/new_pb_tab"/>
+
     <item android:title="@string/tools"
           android:icon="@drawable/ic_menu_tools">
 
         <menu>
 
             <item android:id="@+id/save_as_pdf"
                   android:icon="@drawable/ic_menu_save_as_pdf"
                   android:title="@string/save_as_pdf" />
--- a/mobile/android/base/resources/menu/browser_app_menu.xml.in
+++ b/mobile/android/base/resources/menu/browser_app_menu.xml.in
@@ -27,16 +27,19 @@
 
     <item android:id="@+id/find_in_page"
           android:title="@string/find_in_page" />
 
     <item android:id="@+id/desktop_mode"
           android:title="@string/desktop_mode"
           android:checkable="true" />
 
+    <item android:id="@+id/private_browsing"
+          android:title="@string/new_pb_tab"/>
+
     <item android:id="@+id/addons"
           android:title="@string/addons"/>
 
     <item android:id="@+id/downloads"
           android:title="@string/downloads"/>
 
 #if MOZ_UPDATE_CHANNEL != beta
 #if MOZ_UPDATE_CHANNEL != release
--- a/mobile/android/base/strings.xml.in
+++ b/mobile/android/base/strings.xml.in
@@ -120,16 +120,17 @@
   <string name="new_tab">&new_tab;</string>
   <string name="new_tab_opened">&new_tab_opened;</string>
   <string name="one_tab">&one_tab;</string>
   <string name="num_tabs">&num_tabs;</string>
   <string name="addons">&addons;</string>
   <string name="downloads">&downloads;</string>
   <string name="apps">&apps;</string>
   <string name="char_encoding">&char_encoding;</string>
+  <string name="new_pb_tab">&new_pb_tab;</string>
   <!-- This string only appears in developer builds, which
        is why it is not localizable. -->
   <string name="toggle_profiling">Toggle Profiling</string>
 
   <string name="site_settings_title">&site_settings_title2;</string>
   <string name="site_settings_cancel">&site_settings_cancel;</string>
   <string name="site_settings_clear">&site_settings_clear;</string>
   <string name="site_settings_no_settings">&site_settings_no_settings;</string>
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -1084,17 +1084,18 @@ var BrowserApp = {
       let flags = Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
       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
+        tabID: data.tabID,
+        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;
@@ -2277,16 +2278,21 @@ Tab.prototype = {
     // not stable when panels are added.
     let selectedPanel = BrowserApp.deck.selectedPanel;
     BrowserApp.deck.insertBefore(this.browser, aParams.sibling || null);
     BrowserApp.deck.selectedPanel = selectedPanel;
 
     // Must be called after appendChild so the docshell has been created.
     this.setActive(false);
 
+    let isPrivate = ("isPrivate" in aParams) && aParams.isPrivate;
+    if (isPrivate) {
+      this.browser.docShell.QueryInterface(Ci.nsILoadContext).usePrivateBrowsing = true;
+    }
+
     this.browser.stop();
 
     let frameLoader = this.browser.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader;
     frameLoader.renderMode = Ci.nsIFrameLoader.RENDER_MODE_ASYNC_SCROLL;
 
     // only set tab uri if uri is valid
     let uri = null;
     try {
@@ -2311,17 +2317,18 @@ Tab.prototype = {
           type: "Tab:Added",
           tabID: this.id,
           uri: uri,
           parentId: ("parentId" in aParams) ? aParams.parentId : -1,
           external: ("external" in aParams) ? aParams.external : false,
           selected: ("selected" in aParams) ? aParams.selected : true,
           title: aParams.title || aURL,
           delayLoad: aParams.delayLoad || false,
-          desktopMode: this.desktopMode
+          desktopMode: this.desktopMode,
+          isPrivate: isPrivate
         }
       };
       sendMessageToJava(message);
 
       this.overscrollController = new OverscrollController(this);
     }
 
     this.browser.contentWindow.controllers.insertControllerAt(0, this.overscrollController);