1 /* -*- mode: js; indent-tabs-mode: nil; js-indent-level: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 var EXPORTED_SYMBOLS = [ "ContentClick" ];
10 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
12 ChromeUtils.defineModuleGetter(this, "PlacesUIUtils",
13 "resource:///modules/PlacesUIUtils.jsm");
14 ChromeUtils.defineModuleGetter(this, "PrivateBrowsingUtils",
15 "resource://gre/modules/PrivateBrowsingUtils.jsm");
18 // Listeners are added in nsBrowserGlue.js
19 receiveMessage(message) {
20 switch (message.name) {
22 this.contentAreaClick(message.json, message.target);
28 * Handles clicks in the content area.
30 * @param json {Object} JSON object that looks like an Event
31 * @param browser {Element<browser>}
33 contentAreaClick(json, browser) {
34 // This is heavily based on contentAreaClick from browser.js (Bug 903016)
35 // The json is set up in a way to look like an Event.
36 let window = browser.ownerGlobal;
39 // Might be middle mouse navigation.
40 if (Services.prefs.getBoolPref("middlemouse.contentLoadURL") &&
41 !Services.prefs.getBoolPref("general.autoScroll")) {
42 window.middleMousePaste(json);
47 // If the browser is not in a place where we can open links, bail out.
48 // This can happen in osx sheets, dialogs, etc. that are not browser
49 // windows. Specifically the payments UI is in an osx sheet.
50 if (window.openLinkIn === undefined) {
54 // Mark the page as a user followed link. This is done so that history can
55 // distinguish automatic embed visits from user activated ones. For example
56 // pages loaded in frames are embed visits and lost with the session, while
57 // visits across frames should be preserved.
59 if (!PrivateBrowsingUtils.isWindowPrivate(window))
60 PlacesUIUtils.markPageAsFollowedLink(json.href);
61 } catch (ex) { /* Skip invalid URIs. */ }
63 // This part is based on handleLinkClick.
64 var where = window.whereToOpenLink(json);
65 if (where == "current")
68 // Todo(903022): code for where == save
71 charset: browser.characterSet,
72 referrerURI: browser.documentURI,
73 referrerPolicy: json.referrerPolicy,
74 noReferrer: json.noReferrer,
75 allowMixedContent: json.allowMixedContent,
76 isContentWindowPrivate: json.isContentWindowPrivate,
77 originPrincipal: json.originPrincipal,
78 triggeringPrincipal: json.triggeringPrincipal,
79 frameOuterWindowID: json.frameOuterWindowID,
82 // The new tab/window must use the same userContextId.
83 if (json.originAttributes.userContextId) {
84 params.userContextId = json.originAttributes.userContextId;
87 params.allowInheritPrincipal = true;
89 window.openLinkIn(json.href, where, params);