diff --git a/mobile/chrome/content/Util.js b/mobile/chrome/content/Util.js index 3752fe7a2ccd..46408f3a9b7c 100644 --- a/mobile/chrome/content/Util.js +++ b/mobile/chrome/content/Util.js @@ -114,9 +114,9 @@ let Util = { let link = null; while (target) { - if (target instanceof HTMLAnchorElement || - target instanceof HTMLAreaElement || - target instanceof HTMLLinkElement) { + if (target instanceof Ci.nsIDOMHTMLAnchorElement || + target instanceof Ci.nsIDOMHTMLAreaElement || + target instanceof Ci.nsIDOMHTMLLinkElement) { if (target.hasAttribute("href")) link = target; } @@ -129,9 +129,13 @@ let Util = { return null; }, + makeURI: function makeURI(aURL, aOriginCharset, aBaseURI) { + return gIOService.newURI(aURL, aOriginCharset, aBaseURI); + }, + makeURLAbsolute: function makeURLAbsolute(base, url) { // Note: makeURI() will throw if url is not a valid URI - return makeURI(url, null, makeURI(base)).spec; + return this.makeURI(url, null, this.makeURI(base)).spec; }, clamp: function(num, min, max) { diff --git a/mobile/chrome/content/browser-ui.js b/mobile/chrome/content/browser-ui.js index 82f6b7b28bb5..192aceb41023 100644 --- a/mobile/chrome/content/browser-ui.js +++ b/mobile/chrome/content/browser-ui.js @@ -388,9 +388,10 @@ var BrowserUI = { messageManager.addMessageListener("DOMWillOpenModalDialog", this); messageManager.addMessageListener("DOMWindowClose", this); - // listen returns messages from content - messageManager.addMessageListener("Browser:SaveAs:Return", this); messageManager.addMessageListener("Browser:Highlight", this); + messageManager.addMessageListener("Browser:OpenURI", this); + messageManager.addMessageListener("Browser:ContextMenu", ContextHelper); + messageManager.addMessageListener("Browser:SaveAs:Return", this); // listening mousedown for automatically dismiss some popups (e.g. larry) window.addEventListener("mousedown", this, true); @@ -818,6 +819,9 @@ var BrowserUI = { } TapHighlightHelper.show(rects); break; + + case "Browser:OpenURI": + Browser.addTab(json.uri, false, Browser.selectedTab); } return {}; @@ -2006,135 +2010,40 @@ var SelectHelper = { const kXLinkNamespace = "http://www.w3.org/1999/xlink"; var ContextHelper = { - popupNode: null, - onLink: false, - onSaveableLink: false, - onVoiceLink: false, - onImage: false, - onLoadedImage: false, - linkURL: "", - linkProtocol: null, - mediaURL: "", + popupState: null, - _clearState: function ch_clearState() { - this.popupNode = null; - this.onLink = false; - this.onSaveableLink = false; - this.onVoiceLink = false; - this.onImage = false; - this.onLoadedImage = false; - this.linkURL = ""; - this.linkProtocol = null; - this.mediaURL = ""; - }, + receiveMessage: function ch_receiveMessage(aMessage) { + this.popupState = aMessage.json; + this.popupState.browser = aMessage.target; - _getLinkURL: function ch_getLinkURL(aLink) { - let href = aLink.href; - if (href) - return href; - - href = aLink.getAttributeNS(kXLinkNamespace, "href"); - if (!href || !href.match(/\S/)) { - // Without this we try to save as the current doc, - // for example, HTML case also throws if empty - throw "Empty href"; - } - - return Util.makeURLAbsolute(aLink.baseURI, href); - }, - - _getURI: function ch_getURI(aURL) { - try { - return makeURI(aURL); - } catch (ex) { } - - return null; - }, - - _getProtocol: function ch_getProtocol(aURI) { - if (aURI) - return aURI.scheme; - return null; - }, - - _isSaveable: function ch_isSaveable(aProtocol) { - // We don't do the Right Thing for news/snews yet, so turn them off until we do - return aProtocol && !(aProtocol == "mailto" || aProtocol == "javascript" || aProtocol == "news" || aProtocol == "snews"); - }, - - _isVoice: function ch_isVoice(aProtocol) { - // Collection of protocols related to voice or data links - return aProtocol && (aProtocol == "tel" || aProtocol == "callto" || aProtocol == "sip" || aProtocol == "voipto"); - }, - - handleEvent: function ch_handleEvent(aEvent) { - this._clearState(); - - let [elementX, elementY] = Browser.transformClientToBrowser(aEvent.clientX, aEvent.clientY); - this.popupNode = Browser.elementFromPoint(elementX, elementY); - - // Do checks for nodes that never have children. - if (this.popupNode.nodeType == Node.ELEMENT_NODE) { - // See if the user clicked on an image. - if (this.popupNode instanceof Ci.nsIImageLoadingContent && this.popupNode.currentURI) { - this.onImage = true; - this.mediaURL = this.popupNode.currentURI.spec; - - let request = this.popupNode.getRequest(Ci.nsIImageLoadingContent.CURRENT_REQUEST); - if (request && (request.imageStatus & request.STATUS_SIZE_AVAILABLE)) - this.onLoadedImage = true; - } - } - - let elem = this.popupNode; - while (elem) { - if (elem.nodeType == Node.ELEMENT_NODE) { - // Link? - if (!this.onLink && - ((elem instanceof HTMLAnchorElement && elem.href) || - (elem instanceof HTMLAreaElement && elem.href) || - elem instanceof HTMLLinkElement || - elem.getAttributeNS(kXLinkNamespace, "type") == "simple")) { - - // Target is a link or a descendant of a link. - this.linkURL = this._getLinkURL(elem); - this.linkProtocol = this._getProtocol(this._getURI(this.linkURL)); - this.onLink = true; - this.onSaveableLink = this._isSaveable(this.linkProtocol); - this.onVoiceLink = this._isVoice(this.linkProtocol); - } - } - - elem = elem.parentNode; - } - - let first = last = null; + let first = null; + let last = null; let commands = document.getElementById("context-commands"); for (let i=0; i