Bug 1533089 - HTTP Referer not set when clicking articles r=k88hudson
authorEd Lee <edilee@mozilla.com>
Wed, 06 Mar 2019 20:54:42 +0000
changeset 520584 61f7f4614016337030ac0f1047f0df641aaa37bd
parent 520583 d34db0a033145601b8ec344c9debd10799c2fdae
child 520585 79cc37f5c16dbbd88a92d3c240c4a17d593cee39
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersk88hudson
bugs1533089
milestone67.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 1533089 - HTTP Referer not set when clicking articles r=k88hudson Differential Revision: https://phabricator.services.mozilla.com/D22375
browser/components/newtab/content-src/components/DiscoveryStreamComponents/DSCard/DSCard.jsx
browser/components/newtab/content-src/components/DiscoveryStreamComponents/Hero/Hero.jsx
browser/components/newtab/content-src/components/DiscoveryStreamComponents/List/List.jsx
browser/components/newtab/content-src/components/DiscoveryStreamComponents/SafeAnchor/SafeAnchor.jsx
browser/components/newtab/data/content/activity-stream.bundle.js
--- a/browser/components/newtab/content-src/components/DiscoveryStreamComponents/DSCard/DSCard.jsx
+++ b/browser/components/newtab/content-src/components/DiscoveryStreamComponents/DSCard/DSCard.jsx
@@ -23,17 +23,21 @@ export class DSCard extends React.PureCo
         click: 0,
         tiles: [{id: this.props.id, pos: this.props.pos}],
       }));
     }
   }
 
   render() {
     return (
-      <SafeAnchor url={this.props.url} className="ds-card" onLinkClick={this.onLinkClick}>
+      <SafeAnchor
+        className="ds-card"
+        dispatch={this.props.dispatch}
+        onLinkClick={this.onLinkClick}
+        url={this.props.url}>
         <div className="img-wrapper">
           <div className="img" style={{backgroundImage: `url(${this.props.image_src}`}} />
         </div>
         <div className="meta">
           <div className="info-wrap">
             <header className="title">{this.props.title}</header>
             {this.props.excerpt && <p className="excerpt">{this.props.excerpt}</p>}
           </div>
--- a/browser/components/newtab/content-src/components/DiscoveryStreamComponents/Hero/Hero.jsx
+++ b/browser/components/newtab/content-src/components/DiscoveryStreamComponents/Hero/Hero.jsx
@@ -64,17 +64,21 @@ export class Hero extends React.PureComp
         items={this.props.items - 1}
         type={`Hero`} />
     );
 
     return (
       <div>
         <div className="ds-header">{this.props.title}</div>
         <div className={`ds-hero ds-hero-${this.props.border}`}>
-          <SafeAnchor url={heroRec.url} className="wrapper" onLinkClick={this.onLinkClick}>
+          <SafeAnchor
+            className="wrapper"
+            dispatch={this.props.dispatch}
+            onLinkClick={this.onLinkClick}
+            url={heroRec.url}>
             <div className="img-wrapper">
               <div className="img" style={{backgroundImage: `url(${heroRec.image_src})`}} />
             </div>
             <div className="meta">
               <div className="header-and-excerpt">
                 <header>{heroRec.title}</header>
                 <p className="excerpt">{heroRec.excerpt}</p>
               </div>
--- a/browser/components/newtab/content-src/components/DiscoveryStreamComponents/List/List.jsx
+++ b/browser/components/newtab/content-src/components/DiscoveryStreamComponents/List/List.jsx
@@ -29,17 +29,21 @@ export class ListItem extends React.Pure
         tiles: [{id: this.props.id, pos: this.props.pos}],
       }));
     }
   }
 
   render() {
     return (
       <li className="ds-list-item">
-        <SafeAnchor url={this.props.url} className="ds-list-item-link" onLinkClick={this.onLinkClick}>
+        <SafeAnchor
+          className="ds-list-item-link"
+          dispatch={this.props.dispatch}
+          onLinkClick={this.onLinkClick}
+          url={this.props.url}>
           <div className="ds-list-item-text">
             <div>
               <div className="ds-list-item-title">{this.props.title}</div>
               {this.props.excerpt && <div className="ds-list-item-excerpt">{this.props.excerpt}</div>}
             </div>
             <p>
               {this.props.context && (
                 <span>
--- a/browser/components/newtab/content-src/components/DiscoveryStreamComponents/SafeAnchor/SafeAnchor.jsx
+++ b/browser/components/newtab/content-src/components/DiscoveryStreamComponents/SafeAnchor/SafeAnchor.jsx
@@ -1,11 +1,39 @@
+import {actionCreators as ac, actionTypes as at} from "common/Actions.jsm";
 import React from "react";
 
 export class SafeAnchor extends React.PureComponent {
+  constructor(props) {
+    super(props);
+    this.onClick = this.onClick.bind(this);
+  }
+
+  onClick(event) {
+    // Use dispatch instead of normal link click behavior to include referrer
+    if (this.props.dispatch) {
+      event.preventDefault();
+      const {altKey, button, ctrlKey, metaKey, shiftKey} = event;
+      this.props.dispatch(ac.OnlyToMain({
+        type: at.OPEN_LINK,
+        data: {
+          event: {altKey, button, ctrlKey, metaKey, shiftKey},
+          referrer: "https://getpocket.com/recommendations",
+          // Use the anchor's url, which could have been cleaned up
+          url: event.currentTarget.href,
+        },
+      }));
+    }
+
+    // Propagate event if there's a handler
+    if (this.props.onLinkClick) {
+      this.props.onLinkClick(event);
+    }
+  }
+
   safeURI(url) {
     let protocol = null;
     try {
       protocol = new URL(url).protocol;
     } catch (e) { return ""; }
 
     const isAllowed = [
       "http:",
@@ -14,16 +42,16 @@ export class SafeAnchor extends React.Pu
     if (!isAllowed) {
       console.warn(`${url} is not allowed for anchor targets.`); // eslint-disable-line no-console
       return "";
     }
     return url;
   }
 
   render() {
-    const {url, className, onLinkClick} = this.props;
+    const {url, className} = this.props;
     return (
-      <a href={this.safeURI(url)} className={className} onClick={onLinkClick}>
+      <a href={this.safeURI(url)} className={className} onClick={this.onClick}>
         {this.props.children}
       </a>
     );
   }
 }
--- a/browser/components/newtab/data/content/activity-stream.bundle.js
+++ b/browser/components/newtab/data/content/activity-stream.bundle.js
@@ -7250,17 +7250,45 @@ var ImpressionStats = __webpack_require_
 
 // EXTERNAL MODULE: external "React"
 var external_React_ = __webpack_require__(10);
 var external_React_default = /*#__PURE__*/__webpack_require__.n(external_React_);
 
 // CONCATENATED MODULE: ./content-src/components/DiscoveryStreamComponents/SafeAnchor/SafeAnchor.jsx
 
 
+
 class SafeAnchor_SafeAnchor extends external_React_default.a.PureComponent {
+  constructor(props) {
+    super(props);
+    this.onClick = this.onClick.bind(this);
+  }
+
+  onClick(event) {
+    // Use dispatch instead of normal link click behavior to include referrer
+    if (this.props.dispatch) {
+      event.preventDefault();
+      const { altKey, button, ctrlKey, metaKey, shiftKey } = event;
+      this.props.dispatch(Actions["actionCreators"].OnlyToMain({
+        type: Actions["actionTypes"].OPEN_LINK,
+        data: {
+          event: { altKey, button, ctrlKey, metaKey, shiftKey },
+          referrer: "https://getpocket.com/recommendations",
+          // Use the anchor's url, which could have been cleaned up
+          url: event.currentTarget.href
+        }
+      }));
+    }
+
+    // Propagate event if there's a handler
+    if (this.props.onLinkClick) {
+      this.props.onLinkClick(event);
+    }
+  }
+
   safeURI(url) {
     let protocol = null;
     try {
       protocol = new URL(url).protocol;
     } catch (e) {
       return "";
     }
 
@@ -7268,20 +7296,20 @@ class SafeAnchor_SafeAnchor extends exte
     if (!isAllowed) {
       console.warn(`${url} is not allowed for anchor targets.`); // eslint-disable-line no-console
       return "";
     }
     return url;
   }
 
   render() {
-    const { url, className, onLinkClick } = this.props;
+    const { url, className } = this.props;
     return external_React_default.a.createElement(
       "a",
-      { href: this.safeURI(url), className: className, onClick: onLinkClick },
+      { href: this.safeURI(url), className: className, onClick: this.onClick },
       this.props.children
     );
   }
 }
 // CONCATENATED MODULE: ./content-src/components/DiscoveryStreamComponents/DSCard/DSCard.jsx
 
 
 
@@ -7308,17 +7336,21 @@ class DSCard_DSCard extends external_Rea
         tiles: [{ id: this.props.id, pos: this.props.pos }]
       }));
     }
   }
 
   render() {
     return external_React_default.a.createElement(
       SafeAnchor_SafeAnchor,
-      { url: this.props.url, className: "ds-card", onLinkClick: this.onLinkClick },
+      {
+        className: "ds-card",
+        dispatch: this.props.dispatch,
+        onLinkClick: this.onLinkClick,
+        url: this.props.url },
       external_React_default.a.createElement(
         "div",
         { className: "img-wrapper" },
         external_React_default.a.createElement("div", { className: "img", style: { backgroundImage: `url(${this.props.image_src}` } })
       ),
       external_React_default.a.createElement(
         "div",
         { className: "meta" },
@@ -7485,17 +7517,21 @@ class List_ListItem extends external_Rea
   }
 
   render() {
     return external_React_default.a.createElement(
       "li",
       { className: "ds-list-item" },
       external_React_default.a.createElement(
         SafeAnchor_SafeAnchor,
-        { url: this.props.url, className: "ds-list-item-link", onLinkClick: this.onLinkClick },
+        {
+          className: "ds-list-item-link",
+          dispatch: this.props.dispatch,
+          onLinkClick: this.onLinkClick,
+          url: this.props.url },
         external_React_default.a.createElement(
           "div",
           { className: "ds-list-item-text" },
           external_React_default.a.createElement(
             "div",
             null,
             external_React_default.a.createElement(
               "div",
@@ -7657,17 +7693,21 @@ class Hero_Hero extends external_React_d
         { className: "ds-header" },
         this.props.title
       ),
       external_React_default.a.createElement(
         "div",
         { className: `ds-hero ds-hero-${this.props.border}` },
         external_React_default.a.createElement(
           SafeAnchor_SafeAnchor,
-          { url: heroRec.url, className: "wrapper", onLinkClick: this.onLinkClick },
+          {
+            className: "wrapper",
+            dispatch: this.props.dispatch,
+            onLinkClick: this.onLinkClick,
+            url: heroRec.url },
           external_React_default.a.createElement(
             "div",
             { className: "img-wrapper" },
             external_React_default.a.createElement("div", { className: "img", style: { backgroundImage: `url(${heroRec.image_src})` } })
           ),
           external_React_default.a.createElement(
             "div",
             { className: "meta" },