1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/modules/ContentClick.jsm Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +let Cc = Components.classes; 1.11 +let Ci = Components.interfaces; 1.12 +let Cu = Components.utils; 1.13 + 1.14 +this.EXPORTED_SYMBOLS = [ "ContentClick" ]; 1.15 + 1.16 +Cu.import("resource:///modules/PlacesUIUtils.jsm"); 1.17 +Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm"); 1.18 +Cu.import("resource://gre/modules/Services.jsm"); 1.19 + 1.20 +let ContentClick = { 1.21 + init: function() { 1.22 + let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager); 1.23 + mm.addMessageListener("Content:Click", this); 1.24 + }, 1.25 + 1.26 + receiveMessage: function (message) { 1.27 + switch (message.name) { 1.28 + case "Content:Click": 1.29 + this.contentAreaClick(message.json, message.target) 1.30 + break; 1.31 + } 1.32 + }, 1.33 + 1.34 + contentAreaClick: function (json, browser) { 1.35 + // This is heavily based on contentAreaClick from browser.js (Bug 903016) 1.36 + // The json is set up in a way to look like an Event. 1.37 + let window = browser.ownerDocument.defaultView; 1.38 + 1.39 + if (!json.href) { 1.40 + // Might be middle mouse navigation. 1.41 + if (Services.prefs.getBoolPref("middlemouse.contentLoadURL") && 1.42 + !Services.prefs.getBoolPref("general.autoScroll")) { 1.43 + window.middleMousePaste(json); 1.44 + } 1.45 + return; 1.46 + } 1.47 + 1.48 + if (json.bookmark) { 1.49 + // This is the Opera convention for a special link that, when clicked, 1.50 + // allows to add a sidebar panel. The link's title attribute contains 1.51 + // the title that should be used for the sidebar panel. 1.52 + PlacesUIUtils.showBookmarkDialog({ action: "add" 1.53 + , type: "bookmark" 1.54 + , uri: Services.io.newURI(json.href, null, null) 1.55 + , title: json.title 1.56 + , loadBookmarkInSidebar: true 1.57 + , hiddenRows: [ "description" 1.58 + , "location" 1.59 + , "keyword" ] 1.60 + }, window); 1.61 + return; 1.62 + } 1.63 + 1.64 + // Note: We don't need the sidebar code here. 1.65 + 1.66 + // This part is based on handleLinkClick. 1.67 + var where = window.whereToOpenLink(json); 1.68 + if (where == "current") 1.69 + return false; 1.70 + 1.71 + // Todo(903022): code for where == save 1.72 + 1.73 + window.openLinkIn(json.href, where, { referrerURI: browser.documentURI, 1.74 + charset: browser.characterSet }); 1.75 + 1.76 + // Mark the page as a user followed link. This is done so that history can 1.77 + // distinguish automatic embed visits from user activated ones. For example 1.78 + // pages loaded in frames are embed visits and lost with the session, while 1.79 + // visits across frames should be preserved. 1.80 + try { 1.81 + if (!PrivateBrowsingUtils.isWindowPrivate(window)) 1.82 + PlacesUIUtils.markPageAsFollowedLink(href); 1.83 + } catch (ex) { /* Skip invalid URIs. */ } 1.84 + } 1.85 +};