browser/modules/ContentClick.jsm

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial