Bug 1393699: Add referrerURI to Tabs.loadUrl flows. r=liuche
authorMichael Comella <michael.l.comella@gmail.com>
Wed, 30 Aug 2017 15:26:03 -0700
changeset 378091 f9bcc1e12a01d0c9da68a76feba749afb5a7ae44
parent 378090 4eb5a8e5cb5d31bdbdcd8c254288cee44baa2149
child 378092 8a87c00279d724ac69415ee05ea92178c5eeb617
push id94412
push userarchaeopteryx@coole-files.de
push dateFri, 01 Sep 2017 08:46:09 +0000
treeherdermozilla-inbound@d56571d7f1be [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche
bugs1393699
milestone57.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 1393699: Add referrerURI to Tabs.loadUrl flows. r=liuche This will allow us to call Tabs.loadUrl with a referrer URI from the Pocket top stories. MozReview-Commit-ID: IGdoTo80SGG
mobile/android/base/java/org/mozilla/gecko/Tabs.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/java/org/mozilla/gecko/Tabs.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tabs.java
@@ -905,50 +905,51 @@ public class Tabs implements BundleEvent
      *
      * @param url   URL of page to load
      * @param flags flags used to load tab
      *
      * @return      the Tab if a new one was created; null otherwise
      */
     @RobocopTarget
     public Tab loadUrl(String url, int flags) {
-        return loadUrl(url, null, INVALID_TAB_ID, null, flags);
+        return loadUrl(url, null, null, INVALID_TAB_ID, null, flags);
     }
 
     public Tab loadUrlWithIntentExtras(final String url, final SafeIntent intent, final int flags) {
         // We can't directly create a listener to tell when the user taps on the "What's new"
         // notification, so we use this intent handling as a signal that they tapped the notification.
         if (intent.getBooleanExtra(WhatsNewReceiver.EXTRA_WHATSNEW_NOTIFICATION, false)) {
             Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.NOTIFICATION,
                     WhatsNewReceiver.EXTRA_WHATSNEW_NOTIFICATION);
         }
 
         // Note: we don't get the URL from the intent so the calling
         // method has the opportunity to change the URL if applicable.
-        return loadUrl(url, null, INVALID_TAB_ID, intent, flags);
+        return loadUrl(url, null, null, INVALID_TAB_ID, intent, flags);
     }
 
     public Tab loadUrl(final String url, final String searchEngine, final int parentId, final int flags) {
-        return loadUrl(url, searchEngine, parentId, null, flags);
+        return loadUrl(url, searchEngine, null, parentId, null, 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 referrerUri  the URI which referred this page load, or null if there is none.
      * @param parentId     ID of this tab's parent, or INVALID_TAB_ID (-1) if it has no parent
      * @param intent       an intent whose extras are used to modify the request
      * @param flags        flags used to load tab
      *
      * @return             the Tab if a new one was created; null otherwise
      */
-    public Tab loadUrl(final String url, final String searchEngine, final int parentId,
-                   final SafeIntent intent, final int flags) {
+    public Tab loadUrl(final String url, final String searchEngine, @Nullable final String referrerUri,
+            final int parentId, @Nullable final SafeIntent intent, final int flags) {
         final GeckoBundle data = new GeckoBundle();
         Tab tabToSelect = null;
         boolean delayLoad = (flags & LOADURL_DELAY_LOAD) != 0;
 
         // delayLoad implies background tab
         boolean background = delayLoad || (flags & LOADURL_BACKGROUND) != 0;
 
         boolean isPrivate = (flags & LOADURL_PRIVATE) != 0 || (intent != null && intent.getBooleanExtra(PRIVATE_TAB_INTENT_EXTRA, false));
@@ -959,16 +960,17 @@ public class Tabs implements BundleEvent
 
         data.putString("url", url);
         data.putString("engine", searchEngine);
         data.putInt("parentId", parentId);
         data.putBoolean("userEntered", userEntered);
         data.putBoolean("isPrivate", isPrivate);
         data.putBoolean("pinned", (flags & LOADURL_PINNED) != 0);
         data.putBoolean("desktopMode", desktopMode);
+        data.putString("referrerURI", referrerUri);
 
         final boolean needsNewTab;
         final String applicationId = (intent == null) ? null :
                 intent.getStringExtra(Browser.EXTRA_APPLICATION_ID);
         if (applicationId == null) {
             needsNewTab = (flags & LOADURL_NEW_TAB) != 0;
         } else {
             // If you modify this code, be careful that intent != null.
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -1892,16 +1892,25 @@ var BrowserApp = {
           isPrivate: (data.isPrivate === true),
           pinned: (data.pinned === true),
           delayLoad: (delayLoad === true),
           desktopMode: (data.desktopMode === true)
         };
 
         params.userRequested = url;
 
+        if (data.referrerURI) {
+          try {
+            params.referrerURI = Services.io.newURI(data.referrerURI);
+          } catch (e) {
+            console.warn("Tab:Load referrerURI is invalid - ignoring."); // don't log exception to avoid leaking urls.
+            params.referrerURI = null;
+          }
+        }
+
         if (data.engine) {
           let engine = Services.search.getEngineByName(data.engine);
           if (engine) {
             let submission = engine.getSubmission(url);
             url = submission.uri.spec;
             params.postData = submission.postData;
             params.isSearch = true;
           }