michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: let Cc = Components.classes; michael@0: let Ci = Components.interfaces; michael@0: let Cu = Components.utils; michael@0: michael@0: this.EXPORTED_SYMBOLS = [ "ContentClick" ]; michael@0: michael@0: Cu.import("resource:///modules/PlacesUIUtils.jsm"); michael@0: Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm"); michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: let ContentClick = { michael@0: init: function() { michael@0: let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager); michael@0: mm.addMessageListener("Content:Click", this); michael@0: }, michael@0: michael@0: receiveMessage: function (message) { michael@0: switch (message.name) { michael@0: case "Content:Click": michael@0: this.contentAreaClick(message.json, message.target) michael@0: break; michael@0: } michael@0: }, michael@0: michael@0: contentAreaClick: function (json, browser) { michael@0: // This is heavily based on contentAreaClick from browser.js (Bug 903016) michael@0: // The json is set up in a way to look like an Event. michael@0: let window = browser.ownerDocument.defaultView; michael@0: michael@0: if (!json.href) { michael@0: // Might be middle mouse navigation. michael@0: if (Services.prefs.getBoolPref("middlemouse.contentLoadURL") && michael@0: !Services.prefs.getBoolPref("general.autoScroll")) { michael@0: window.middleMousePaste(json); michael@0: } michael@0: return; michael@0: } michael@0: michael@0: if (json.bookmark) { michael@0: // This is the Opera convention for a special link that, when clicked, michael@0: // allows to add a sidebar panel. The link's title attribute contains michael@0: // the title that should be used for the sidebar panel. michael@0: PlacesUIUtils.showBookmarkDialog({ action: "add" michael@0: , type: "bookmark" michael@0: , uri: Services.io.newURI(json.href, null, null) michael@0: , title: json.title michael@0: , loadBookmarkInSidebar: true michael@0: , hiddenRows: [ "description" michael@0: , "location" michael@0: , "keyword" ] michael@0: }, window); michael@0: return; michael@0: } michael@0: michael@0: // Note: We don't need the sidebar code here. michael@0: michael@0: // This part is based on handleLinkClick. michael@0: var where = window.whereToOpenLink(json); michael@0: if (where == "current") michael@0: return false; michael@0: michael@0: // Todo(903022): code for where == save michael@0: michael@0: window.openLinkIn(json.href, where, { referrerURI: browser.documentURI, michael@0: charset: browser.characterSet }); michael@0: michael@0: // Mark the page as a user followed link. This is done so that history can michael@0: // distinguish automatic embed visits from user activated ones. For example michael@0: // pages loaded in frames are embed visits and lost with the session, while michael@0: // visits across frames should be preserved. michael@0: try { michael@0: if (!PrivateBrowsingUtils.isWindowPrivate(window)) michael@0: PlacesUIUtils.markPageAsFollowedLink(href); michael@0: } catch (ex) { /* Skip invalid URIs. */ } michael@0: } michael@0: };