Skip to content

Commit

Permalink
Bug 1776609: Record source and triggeringPlaceId for sponsored tile o…
Browse files Browse the repository at this point in the history
…n newtab. r=mak,geckoview-reviewers,m_kato

Differential Revision: https://phabricator.services.mozilla.com/D150729
  • Loading branch information
Daisuke Akatsuka committed Jul 29, 2022
1 parent d23c50f commit 7c02dae
Show file tree
Hide file tree
Showing 27 changed files with 727 additions and 32 deletions.
6 changes: 6 additions & 0 deletions browser/actors/ClickHandlerParent.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ class ClickHandlerParent extends JSWindowActorParent {
openerBrowser: browser,
// The child ensures that untrusted events have a valid user activation.
hasValidUserGestureActivation: true,
globalHistoryOptions: {
triggeringSponsoredURL: browser.getAttribute("triggeringSponsoredURL"),
triggeringSponsoredURLVisitTimeMS: browser.getAttribute(
"triggeringSponsoredURLVisitTimeMS"
),
},
};

// The new tab/window must use the same userContextId.
Expand Down
12 changes: 12 additions & 0 deletions browser/base/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,7 @@ function _loadURI(browser, uri, params = {}) {
csp,
remoteTypeOverride,
hasValidUserGestureActivation,
globalHistoryOptions,
} = params || {};
let loadFlags =
params.loadFlags || params.flags || Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
Expand Down Expand Up @@ -1509,6 +1510,17 @@ function _loadURI(browser, uri, params = {}) {

// XXX(nika): Is `browser.isNavigating` necessary anymore?
browser.isNavigating = true;

if (globalHistoryOptions?.triggeringSponsoredURL) {
browser.setAttribute(
"triggeringSponsoredURL",
globalHistoryOptions.triggeringSponsoredURL
);
const time =
globalHistoryOptions.triggeringSponsoredURLVisitTimeMS || Date.now();
browser.setAttribute("triggeringSponsoredURLVisitTimeMS", time);
}

let loadURIOptions = {
triggeringPrincipal,
csp,
Expand Down
8 changes: 8 additions & 0 deletions browser/base/content/nsContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,14 @@ class nsContextMenu {
openLinkInTab(event) {
let params = {
userContextId: parseInt(event.target.getAttribute("data-usercontextid")),
globalHistoryOptions: {
triggeringSponsoredURL: this.browser.getAttribute(
"triggeringSponsoredURL"
),
triggeringSponsoredURLVisitTimeMS: this.browser.getAttribute(
"triggeringSponsoredURLVisitTimeMS"
),
},
};

openLinkIn(this.linkURL, "tab", this._openLinkInParameters(params));
Expand Down
5 changes: 5 additions & 0 deletions browser/base/content/tabbrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,7 @@
var aName;
var aCsp;
var aSkipLoad;
var aGlobalHistoryOptions;
if (
arguments.length == 2 &&
typeof arguments[1] == "object" &&
Expand Down Expand Up @@ -1689,6 +1690,7 @@
aName = params.name;
aCsp = params.csp;
aSkipLoad = params.skipLoad;
aGlobalHistoryOptions = params.globalHistoryOptions;
}

// all callers of loadOneTab need to pass a valid triggeringPrincipal.
Expand Down Expand Up @@ -1728,6 +1730,7 @@
name: aName,
csp: aCsp,
skipLoad: aSkipLoad,
globalHistoryOptions: aGlobalHistoryOptions,
});
if (!bgLoad) {
this.selectedTab = tab;
Expand Down Expand Up @@ -2585,6 +2588,7 @@
csp,
skipLoad,
batchInsertingTabs,
globalHistoryOptions,
} = {}
) {
// all callers of addTab that pass a params object need to pass
Expand Down Expand Up @@ -2916,6 +2920,7 @@
charset,
postData,
csp,
globalHistoryOptions,
});
} catch (ex) {
Cu.reportError(ex);
Expand Down
3 changes: 3 additions & 0 deletions browser/base/content/utilityOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ function openLinkIn(url, where, params) {
var aResolveOnNewTabCreated = params.resolveOnNewTabCreated;
// This callback will be called with the content browser once it's created.
var aResolveOnContentBrowserReady = params.resolveOnContentBrowserCreated;
var aGlobalHistoryOptions = params.globalHistoryOptions;

if (!aTriggeringPrincipal) {
throw new Error("Must load with a triggering Principal");
Expand Down Expand Up @@ -608,6 +609,7 @@ function openLinkIn(url, where, params) {
postData: aPostData,
userContextId: aUserContextId,
hasValidUserGestureActivation: params.hasValidUserGestureActivation,
globalHistoryOptions: aGlobalHistoryOptions,
});
if (aResolveOnContentBrowserReady) {
aResolveOnContentBrowserReady(targetBrowser);
Expand Down Expand Up @@ -645,6 +647,7 @@ function openLinkIn(url, where, params) {
focusUrlBar,
openerBrowser: params.openerBrowser,
fromExternal: params.fromExternal,
globalHistoryOptions: aGlobalHistoryOptions,
});
targetBrowser = tabUsedForLoad.linkedBrowser;

Expand Down
5 changes: 5 additions & 0 deletions browser/components/newtab/lib/PlacesFeed.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ class PlacesFeed {
private: isPrivate,
targetBrowser: action._target.browser,
fromChrome: false, // This ensure we maintain user preference for how to open new tabs.
globalHistoryOptions: {
triggeringSponsoredURL: action.data.sponsored_tile_id
? action.data.url
: undefined,
},
};

// Always include the referrer (even for http links) if we have one
Expand Down
2 changes: 2 additions & 0 deletions browser/components/newtab/test/browser/annotation_first.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
first
<a href="annotation_second.html">goto second</a>
2 changes: 2 additions & 0 deletions browser/components/newtab/test/browser/annotation_second.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
second
<a href="https://www.example.com/browser/browser/components/newtab/test/browser/annotation_third.html">goto third</a>
2 changes: 2 additions & 0 deletions browser/components/newtab/test/browser/annotation_third.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
thrid
<a href="https://example.org/">goto outside</a>
5 changes: 5 additions & 0 deletions browser/components/newtab/test/browser/browser.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
support-files =
blue_page.html
red_page.html
annotation_first.html
annotation_second.html
annotation_third.html
head.js
redirect_to.sjs
snippet.json
snippet_below_search_test.json
snippet_simple_test.json
Expand Down Expand Up @@ -62,6 +66,7 @@ support-files=
[browser_open_tab_focus.js]
skip-if = (os == "linux") # Test setup only implemented for OSX and Windows
[browser_remote_l10n.js]
[browser_topsites_annotation.js]
[browser_topsites_contextMenu_options.js]
[browser_topsites_section.js]
skip-if =
Expand Down
Loading

0 comments on commit 7c02dae

Please sign in to comment.