Bug 1132547 - Move reader.has_used_toolbar logic to Android's Reader.js. r=bnicholson
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Thu, 12 Feb 2015 15:23:26 -0800
changeset 229481 a288bf86a785ac92b0527ab3f2379a12af8cfa12
parent 229480 3fe14625f9543330393d8b91628e5d9d1c9e776f
child 229482 15edc0cdbae7f203c0919736922ddd9c6746520f
push id11357
push usermleibovic@mozilla.com
push dateWed, 18 Feb 2015 00:06:50 +0000
treeherderfx-team@15edc0cdbae7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson
bugs1132547
milestone38.0a1
Bug 1132547 - Move reader.has_used_toolbar logic to Android's Reader.js. r=bnicholson
browser/modules/ReaderParent.jsm
mobile/android/base/BrowserApp.java
mobile/android/chrome/content/Reader.js
mobile/android/chrome/content/browser.js
mobile/android/locales/en-US/chrome/browser.properties
toolkit/components/reader/AboutReader.jsm
toolkit/locales/en-US/chrome/global/aboutReader.properties
--- a/browser/modules/ReaderParent.jsm
+++ b/browser/modules/ReaderParent.jsm
@@ -21,18 +21,16 @@ let ReaderParent = {
 
   MESSAGES: [
     "Reader:AddToList",
     "Reader:ArticleGet",
     "Reader:FaviconRequest",
     "Reader:ListStatusRequest",
     "Reader:RemoveFromList",
     "Reader:Share",
-    "Reader:ShowToast",
-    "Reader:ToolbarVisibility",
     "Reader:SystemUIVisibility",
     "Reader:UpdateReaderButton",
   ],
 
   init: function() {
     let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
     for (let msg of this.MESSAGES) {
       mm.addMessageListener(msg, this);
@@ -65,28 +63,20 @@ let ReaderParent = {
       case "Reader:RemoveFromList":
         // XXX: To implement.
         break;
 
       case "Reader:Share":
         // XXX: To implement.
         break;
 
-      case "Reader:ShowToast":
-        // XXX: To implement.
-        break;
-
       case "Reader:SystemUIVisibility":
         // XXX: To implement.
         break;
 
-      case "Reader:ToolbarVisibility":
-        // XXX: To implement.
-        break;
-
       case "Reader:UpdateReaderButton": {
         let browser = message.target;
         if (message.data && message.data.isArticle !== undefined) {
           browser.isArticle = message.data.isArticle;
         }
         this.updateReaderButton(browser);
         break;
       }
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -769,18 +769,17 @@ public class BrowserApp extends GeckoApp
             "Feedback:LastUrl",
             "Feedback:MaybeLater",
             "Feedback:OpenPlayStore",
             "Menu:Add",
             "Menu:Remove",
             "Reader:Share",
             "Settings:Show",
             "Telemetry:Gather",
-            "Updater:Launch",
-            "BrowserToolbar:Visibility");
+            "Updater:Launch");
 
         Distribution distribution = Distribution.init(this);
 
         // Init suggested sites engine in BrowserDB.
         final SuggestedSites suggestedSites = new SuggestedSites(appContext, distribution);
         final BrowserDB db = getProfile().getDB();
         db.setSuggestedSites(suggestedSites);
 
@@ -1312,18 +1311,17 @@ public class BrowserApp extends GeckoApp
             "Feedback:LastUrl",
             "Feedback:MaybeLater",
             "Feedback:OpenPlayStore",
             "Menu:Add",
             "Menu:Remove",
             "Reader:Share",
             "Settings:Show",
             "Telemetry:Gather",
-            "Updater:Launch",
-            "BrowserToolbar:Visibility");
+            "Updater:Launch");
 
         if (AppConstants.MOZ_ANDROID_BEAM) {
             NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
             if (nfc != null) {
                 // null this out even though the docs say it's not needed,
                 // because the source code looks like it will only do this
                 // automatically on API 14+
                 nfc.setNdefPushMessageCallback(null, this);
@@ -1529,27 +1527,16 @@ public class BrowserApp extends GeckoApp
         mBrowserToolbar.refresh();
     }
 
     @Override
     public boolean hasTabsSideBar() {
         return (mTabsPanel != null && mTabsPanel.isSideBar());
     }
 
-    private void setBrowserToolbarVisible(final boolean visible) {
-        ThreadUtils.postToUiThread(new Runnable() {
-            @Override
-            public void run() {
-                if (mDynamicToolbar.isEnabled()) {
-                    mDynamicToolbar.setVisible(visible, VisibilityTransition.IMMEDIATE);
-                }
-            }
-        });
-    }
-
     private boolean isSideBar() {
         return (HardwareUtils.isTablet() && getOrientation() == Configuration.ORIENTATION_LANDSCAPE);
     }
 
     private void updateSideBarState() {
         if (NewTabletUI.isEnabled(this)) {
             return;
         }
@@ -1700,20 +1687,16 @@ public class BrowserApp extends GeckoApp
             Telemetry.addToHistogram("FENNEC_THUMBNAILS_COUNT", db.getCount(cr, "thumbnails"));
             Telemetry.addToHistogram("FENNEC_READING_LIST_COUNT", db.getReadingListAccessor().getCount(cr));
             Telemetry.addToHistogram("BROWSER_IS_USER_DEFAULT", (isDefaultBrowser(Intent.ACTION_VIEW) ? 1 : 0));
             if (Versions.feature16Plus) {
                 Telemetry.addToHistogram("BROWSER_IS_ASSIST_DEFAULT", (isDefaultBrowser(Intent.ACTION_ASSIST) ? 1 : 0));
             }
         } else if ("Updater:Launch".equals(event)) {
             handleUpdaterLaunch();
-
-        } else if ("BrowserToolbar:Visibility".equals(event)) {
-            setBrowserToolbarVisible(message.getBoolean("visible"));
-
         } else {
             super.handleMessage(event, message, callback);
         }
     }
 
     /**
      * Use a dummy Intent to do a default browser check.
      *
--- a/mobile/android/chrome/content/Reader.js
+++ b/mobile/android/chrome/content/Reader.js
@@ -10,16 +10,21 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 let Reader = {
   // These values should match those defined in BrowserContract.java.
   STATUS_UNFETCHED: 0,
   STATUS_FETCH_FAILED_TEMPORARY: 1,
   STATUS_FETCH_FAILED_PERMANENT: 2,
   STATUS_FETCH_FAILED_UNSUPPORTED_FORMAT: 3,
   STATUS_FETCHED_ARTICLE: 4,
 
+  get _hasUsedToolbar() {
+    delete this._hasUsedToolbar;
+    return this._hasUsedToolbar = Services.prefs.getBoolPref("reader.has_used_toolbar");
+  },
+
   observe: function Reader_observe(aMessage, aTopic, aData) {
     switch (aTopic) {
       case "Reader:FetchContent": {
         let data = JSON.parse(aData);
         this._fetchContent(data.url, data.id);
         break;
       }
       case "Reader:Removed": {
@@ -98,32 +103,29 @@ let Reader = {
       case "Reader:Share":
         Messaging.sendRequest({
           type: "Reader:Share",
           url: message.data.url,
           title: message.data.title
         });
         break;
 
-      case "Reader:ShowToast":
-        NativeWindow.toast.show(message.data.toast, "short");
-        break;
-
       case "Reader:SystemUIVisibility":
         Messaging.sendRequest({
           type: "SystemUI:Visibility",
           visible: message.data.visible
         });
         break;
 
-      case "Reader:ToolbarVisibility":
-        Messaging.sendRequest({
-          type: "BrowserToolbar:Visibility",
-          visible: message.data.visible
-        });
+      case "Reader:ToolbarHidden":
+        if (!this._hasUsedToolbar) {
+          NativeWindow.toast.show(Strings.browser.GetStringFromName("readerMode.toolbarTip"), "short");
+          Services.prefs.setBoolPref("reader.has_used_toolbar", true);
+          this._hasUsedToolbar = true;
+        }
         break;
 
       case "Reader:UpdateReaderButton": {
         let tab = BrowserApp.getTabForBrowser(message.target);
         tab.browser.isArticle = message.data.isArticle;
         this.updatePageAction(tab);
         break;
       }
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -174,18 +174,17 @@ lazilyLoadedObserverScripts.forEach(func
 [
   ["Reader", [
     "Reader:AddToList",
     "Reader:ArticleGet",
     "Reader:FaviconRequest",
     "Reader:ListStatusRequest",
     "Reader:RemoveFromList",
     "Reader:Share",
-    "Reader:ShowToast",
-    "Reader:ToolbarVisibility",
+    "Reader:ToolbarHidden",
     "Reader:SystemUIVisibility",
     "Reader:UpdateReaderButton",
   ], "chrome://browser/content/Reader.js"],
 ].forEach(aScript => {
   let [name, messages, script] = aScript;
   XPCOMUtils.defineLazyGetter(window, name, function() {
     let sandbox = {};
     Services.scriptloader.loadSubScript(script, sandbox);
--- a/mobile/android/locales/en-US/chrome/browser.properties
+++ b/mobile/android/locales/en-US/chrome/browser.properties
@@ -360,16 +360,20 @@ getUserMedia.audioDevice.prompt = Microp
 getUserMedia.sharingCamera.message2 = Camera is on
 getUserMedia.sharingMicrophone.message2 = Microphone is on
 getUserMedia.sharingCameraAndMicrophone.message2 = Camera and microphone are on
 
 #Reader mode
 readerMode.enter = Enter Reader Mode
 readerMode.exit = Exit Reader Mode
 
+# LOCALIZATION NOTE (readerMode.toolbarTip):
+# Tip shown to users the first time we hide the reader mode toolbar.
+readerMode.toolbarTip=Tap the screen to show reader options
+
 #Open in App
 openInApp.pageAction = Open in App
 openInApp.ok = OK
 openInApp.cancel = Cancel
 
 #Tab sharing
 tabshare.title = "Choose a tab to stream"
 #Tabs in context menus
--- a/toolkit/components/reader/AboutReader.jsm
+++ b/toolkit/components/reader/AboutReader.jsm
@@ -415,34 +415,25 @@ AboutReader.prototype = {
       return;
 
     if (this._getToolbarVisibility() === visible)
       return;
 
     this._toolbarElement.classList.toggle("toolbar-hidden");
     this._setSystemUIVisibility(visible);
 
-    if (!visible && !this._hasUsedToolbar) {
-      this._hasUsedToolbar = Services.prefs.getBoolPref("reader.has_used_toolbar");
-      if (!this._hasUsedToolbar) {
-        this._mm.sendAsyncMessage("Reader:ShowToast", { toast: gStrings.GetStringFromName("aboutReader.toolbarTip") });
-        Services.prefs.setBoolPref("reader.has_used_toolbar", true);
-        this._hasUsedToolbar = true;
-      }
+    if (!visible) {
+      this._mm.sendAsyncMessage("Reader:ToolbarHidden");
     }
   },
 
   _toggleToolbarVisibility: function Reader_toggleToolbarVisibility() {
     this._setToolbarVisibility(!this._getToolbarVisibility());
   },
 
-  _setBrowserToolbarVisiblity: function Reader_setBrowserToolbarVisiblity(visible) {
-    this._mm.sendAsyncMessage("Reader:ToolbarVisibility", { visible: visible });
-  },
-
   _setSystemUIVisibility: function Reader_setSystemUIVisibility(visible) {
     this._mm.sendAsyncMessage("Reader:SystemUIVisibility", { visible: visible });
   },
 
   _loadArticle: Task.async(function* () {
     let url = this._getOriginalUrl();
     this._showProgressDelayed();
 
--- a/toolkit/locales/en-US/chrome/global/aboutReader.properties
+++ b/toolkit/locales/en-US/chrome/global/aboutReader.properties
@@ -21,10 +21,8 @@ aboutReader.fontType.charis-sil=Charis S
 aboutReader.fontType.clear-sans=Clear Sans
 
 # LOCALIZATION NOTE (aboutReader.fontTypeSample): String used to sample font types.
 aboutReader.fontTypeSample=Aa
 
 # LOCALIZATION NOTE (aboutReader.fontSizeSample): String used to sample a relative font size
 # for the font size setting. Tapping different samples will change the font size.
 aboutReader.fontSizeSample=A
-
-aboutReader.toolbarTip=Tap the screen to show reader options