Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 let Cc = Components.classes;
8 let Ci = Components.interfaces;
9 let Cu = Components.utils;
11 this.EXPORTED_SYMBOLS = [ "ContentClick" ];
13 Cu.import("resource:///modules/PlacesUIUtils.jsm");
14 Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
15 Cu.import("resource://gre/modules/Services.jsm");
17 let ContentClick = {
18 init: function() {
19 let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
20 mm.addMessageListener("Content:Click", this);
21 },
23 receiveMessage: function (message) {
24 switch (message.name) {
25 case "Content:Click":
26 this.contentAreaClick(message.json, message.target)
27 break;
28 }
29 },
31 contentAreaClick: function (json, browser) {
32 // This is heavily based on contentAreaClick from browser.js (Bug 903016)
33 // The json is set up in a way to look like an Event.
34 let window = browser.ownerDocument.defaultView;
36 if (!json.href) {
37 // Might be middle mouse navigation.
38 if (Services.prefs.getBoolPref("middlemouse.contentLoadURL") &&
39 !Services.prefs.getBoolPref("general.autoScroll")) {
40 window.middleMousePaste(json);
41 }
42 return;
43 }
45 if (json.bookmark) {
46 // This is the Opera convention for a special link that, when clicked,
47 // allows to add a sidebar panel. The link's title attribute contains
48 // the title that should be used for the sidebar panel.
49 PlacesUIUtils.showBookmarkDialog({ action: "add"
50 , type: "bookmark"
51 , uri: Services.io.newURI(json.href, null, null)
52 , title: json.title
53 , loadBookmarkInSidebar: true
54 , hiddenRows: [ "description"
55 , "location"
56 , "keyword" ]
57 }, window);
58 return;
59 }
61 // Note: We don't need the sidebar code here.
63 // This part is based on handleLinkClick.
64 var where = window.whereToOpenLink(json);
65 if (where == "current")
66 return false;
68 // Todo(903022): code for where == save
70 window.openLinkIn(json.href, where, { referrerURI: browser.documentURI,
71 charset: browser.characterSet });
73 // Mark the page as a user followed link. This is done so that history can
74 // distinguish automatic embed visits from user activated ones. For example
75 // pages loaded in frames are embed visits and lost with the session, while
76 // visits across frames should be preserved.
77 try {
78 if (!PrivateBrowsingUtils.isWindowPrivate(window))
79 PlacesUIUtils.markPageAsFollowedLink(href);
80 } catch (ex) { /* Skip invalid URIs. */ }
81 }
82 };