mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 23:35:34 +00:00
Bug 653833 - Show a doorhanger allowing users to open a page in helper apps. r=mfinkle
This commit is contained in:
parent
034ffa003d
commit
e4ad9c5094
60
mobile/android/chrome/content/HelperApps.js
Normal file
60
mobile/android/chrome/content/HelperApps.js
Normal file
@ -0,0 +1,60 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
"use strict";
|
||||
|
||||
|
||||
var HelperApps = {
|
||||
get defaultHttpHandlers() {
|
||||
let protoHandlers = this.getAppsForProtocol("http");
|
||||
|
||||
var results = {};
|
||||
for (var i = 0; i < protoHandlers.length; i++) {
|
||||
try {
|
||||
let protoApp = protoHandlers.queryElementAt(i, Ci.nsIHandlerApp);
|
||||
results[protoApp.name] = protoApp;
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
delete this.defaultHttpHandlers;
|
||||
return this.defaultHttpHandlers = results;
|
||||
},
|
||||
|
||||
get protoSvc() {
|
||||
delete this.protoSvc;
|
||||
return this.protoSvc = Cc["@mozilla.org/uriloader/external-protocol-service;1"].getService(Ci.nsIExternalProtocolService);
|
||||
},
|
||||
|
||||
get urlHandlerService() {
|
||||
delete this.urlHandlerService;
|
||||
return this.urlHandlerService = Cc["@mozilla.org/uriloader/external-url-handler-service;1"].getService(Ci.nsIExternalURLHandlerService);
|
||||
},
|
||||
|
||||
getAppsForProtocol: function getAppsForProtocol(uri) {
|
||||
let handlerInfoProto = this.protoSvc.getProtocolHandlerInfoFromOS(uri, {});
|
||||
return handlerInfoProto.possibleApplicationHandlers;
|
||||
},
|
||||
|
||||
getAppsForUri: function getAppsFor(uri) {
|
||||
let found = [];
|
||||
let handlerInfoProto = this.urlHandlerService.getURLHandlerInfoFromOS(uri, {});
|
||||
let urlHandlers = handlerInfoProto.possibleApplicationHandlers;
|
||||
for (var i = 0; i < urlHandlers.length; i++) {
|
||||
let urlApp = urlHandlers.queryElementAt(i, Ci.nsIHandlerApp);
|
||||
if (!this.defaultHttpHandlers[urlApp.name]) {
|
||||
found.push(urlApp);
|
||||
}
|
||||
}
|
||||
return found;
|
||||
},
|
||||
|
||||
openUriInApp: function openUriInApp(uri) {
|
||||
var possibleHandlers = this.getAppsForUri(uri);
|
||||
if (possibleHandlers.length == 1) {
|
||||
possibleHandlers[0].launchWithURI(uri);
|
||||
} else if (possibleHandlers.length > 0) {
|
||||
let handlerInfoProto = this.urlHandlerService.getURLHandlerInfoFromOS(uri, {});
|
||||
handlerInfoProto.preferredApplicationHandler.launchWithURI(uri);
|
||||
}
|
||||
}
|
||||
};
|
@ -29,6 +29,7 @@ XPCOMUtils.defineLazyGetter(this, "DebuggerServer", function() {
|
||||
|
||||
// Lazily-loaded browser scripts:
|
||||
[
|
||||
["HelperApps", "chrome://browser/content/HelperApps.js"],
|
||||
["SelectHelper", "chrome://browser/content/SelectHelper.js"],
|
||||
["Readability", "chrome://browser/content/Readability.js"],
|
||||
].forEach(function (aScript) {
|
||||
@ -1825,19 +1826,26 @@ var UserAgent = {
|
||||
if (tab == null)
|
||||
break;
|
||||
|
||||
// Send XUL UA to YouTube; temporary hack to make videos play
|
||||
if (channel.URI.host.indexOf("youtube") != -1) {
|
||||
let ua = Cc["@mozilla.org/network/protocol;1?name=http"].getService(Ci.nsIHttpProtocolHandler).userAgent;
|
||||
#expand let version = "__MOZ_APP_VERSION__";
|
||||
ua += " Fennec/" + version;
|
||||
channel.setRequestHeader("User-Agent", ua, false);
|
||||
}
|
||||
|
||||
// Send desktop UA if "Request Desktop Site" is enabled
|
||||
if (tab.desktopMode && (channel.loadFlags & Ci.nsIChannel.LOAD_DOCUMENT_URI))
|
||||
channel.setRequestHeader("User-Agent", this.DESKTOP_UA, false);
|
||||
|
||||
break;
|
||||
let apps = HelperApps.getAppsForUri(channel.URI);
|
||||
if (apps.length > 0) {
|
||||
let message = apps.length == 1 ? Strings.browser.formatStringFromName("helperapps.openWithApp", [apps[0].name], 1) :
|
||||
Strings.browser.GetStringFromName("helperapps.openWithList");
|
||||
let buttons = [{
|
||||
label: Strings.browser.GetStringFromName("helperapps.open"),
|
||||
callback: function() {
|
||||
aSubject.QueryInterface(Ci.nsIRequest).cancel(Components.results.NS_ERROR_ABORT);
|
||||
HelperApps.openUriInApp(channel.URI);
|
||||
}
|
||||
},
|
||||
{
|
||||
label: Strings.browser.GetStringFromName("helperapps.cancel"),
|
||||
callback: function() { }
|
||||
}];
|
||||
// Persist this over page loads. Pages that expect to open in helper apps often redirect
|
||||
// Youtube redirects twice, so I've forced this to two for now
|
||||
let options = { persistence: 2 };
|
||||
let name = "helperapps-" + (apps.length > 1 ? "list" : apps[0].name);
|
||||
NativeWindow.doorhanger.show(message, name, buttons, self.id, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5043,7 +5051,7 @@ var PermissionsHelper = {
|
||||
// If we implement a two-line UI, we will need to pass the label and
|
||||
// value individually and let java handle the formatting
|
||||
let setting = Strings.browser.formatStringFromName("siteSettings.labelToValue",
|
||||
[ label, valueString ], 2)
|
||||
[ label, valueString ], 2);
|
||||
permissions.push({
|
||||
type: type,
|
||||
setting: setting
|
||||
|
@ -36,6 +36,7 @@ chrome.jar:
|
||||
* content/downloads.js (content/downloads.js)
|
||||
content/netError.xhtml (content/netError.xhtml)
|
||||
content/SelectHelper.js (content/SelectHelper.js)
|
||||
content/HelperApps.js (content/HelperApps.js)
|
||||
content/dbg-browser-actors.js (content/dbg-browser-actors.js)
|
||||
|
||||
% override chrome://global/content/config.xul chrome://browser/content/config.xhtml
|
||||
|
@ -264,3 +264,9 @@ remoteIncomingPromptTitle=Incoming Connection
|
||||
# dialog that prompts the user to allow the incoming connection.
|
||||
remoteIncomingPromptMessage=An incoming request to permit remote debugging connection was detected. A remote client can take complete control over your browser! Allow connection?
|
||||
remoteIncomingPromptDisable=Disable
|
||||
|
||||
# Helper apps
|
||||
helperapps.openWithApp=The %S App can open this link.
|
||||
helperapps.openWithList=You have apps installed that can open this link.
|
||||
helperapps.open=Open with App
|
||||
helperapps.cancel=Cancel
|
||||
|
Loading…
Reference in New Issue
Block a user