зеркало из https://github.com/mozilla/gecko-dev.git
Bug 769350 - Implement trusted/certified app scheme support [r=vingtetun]
This commit is contained in:
Родитель
994e810626
Коммит
3fe7c66a25
|
@ -473,6 +473,9 @@
|
|||
@BINPATH@/components/SystemMessageManager.js
|
||||
@BINPATH@/components/SystemMessageManager.manifest
|
||||
|
||||
@BINPATH@/components/AppProtocolHandler.js
|
||||
@BINPATH@/components/AppProtocolHandler.manifest
|
||||
|
||||
; Modules
|
||||
@BINPATH@/modules/*
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ let DOMApplicationRegistry = {
|
|||
"Webapps:GetSelf",
|
||||
"Webapps:GetInstalled", "Webapps:GetNotInstalled",
|
||||
"Webapps:Launch", "Webapps:GetAll",
|
||||
"Webapps:InstallPackage"];
|
||||
"Webapps:InstallPackage", "Webapps:GetBasePath"];
|
||||
|
||||
this.messages.forEach((function(msgName) {
|
||||
ppmm.addMessageListener(msgName, this);
|
||||
|
@ -188,6 +188,9 @@ let DOMApplicationRegistry = {
|
|||
case "Webapps:InstallPackage":
|
||||
this.installPackage(msg);
|
||||
break;
|
||||
case "Webapps:GetBasePath":
|
||||
return FileUtils.getFile(DIRECTORY_NAME, ["webapps"], true).path;
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -15,4 +15,9 @@ interface nsIJARChannel : nsIChannel
|
|||
* channel.
|
||||
*/
|
||||
readonly attribute boolean isUnsafe;
|
||||
|
||||
/**
|
||||
* Forces the uri to be a app:// uri.
|
||||
*/
|
||||
void setAppURI(in nsIURI uri);
|
||||
};
|
||||
|
|
|
@ -186,7 +186,8 @@ nsJARInputThunk::IsNonBlocking(bool *nonBlocking)
|
|||
|
||||
|
||||
nsJARChannel::nsJARChannel()
|
||||
: mContentLength(-1)
|
||||
: mAppURI(nsnull)
|
||||
, mContentLength(-1)
|
||||
, mLoadFlags(LOAD_NORMAL)
|
||||
, mStatus(NS_OK)
|
||||
, mIsPending(false)
|
||||
|
@ -476,7 +477,12 @@ nsJARChannel::SetOriginalURI(nsIURI *aURI)
|
|||
NS_IMETHODIMP
|
||||
nsJARChannel::GetURI(nsIURI **aURI)
|
||||
{
|
||||
if (mAppURI) {
|
||||
NS_IF_ADDREF(*aURI = mAppURI);
|
||||
} else {
|
||||
NS_IF_ADDREF(*aURI = mJarURI);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -758,6 +764,20 @@ nsJARChannel::GetIsUnsafe(bool *isUnsafe)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::SetAppURI(nsIURI *aURI) {
|
||||
NS_ENSURE_ARG_POINTER(aURI);
|
||||
|
||||
nsCAutoString scheme;
|
||||
aURI->GetScheme(scheme);
|
||||
if (!scheme.EqualsLiteral("app")) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
mAppURI = aURI;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// nsIDownloadObserver
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
@ -55,6 +55,7 @@ private:
|
|||
|
||||
nsCOMPtr<nsIJARURI> mJarURI;
|
||||
nsCOMPtr<nsIURI> mOriginalURI;
|
||||
nsCOMPtr<nsIURI> mAppURI;
|
||||
nsCOMPtr<nsISupports> mOwner;
|
||||
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
|
||||
nsCOMPtr<nsISupports> mSecurityInfo;
|
||||
|
|
|
@ -12,6 +12,7 @@ include $(DEPTH)/config/autoconf.mk
|
|||
|
||||
PARALLEL_DIRS = \
|
||||
about \
|
||||
app \
|
||||
data \
|
||||
device \
|
||||
file \
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
/* 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";
|
||||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "cpmm", function() {
|
||||
return Cc["@mozilla.org/childprocessmessagemanager;1"]
|
||||
.getService(Ci.nsIFrameMessageManager)
|
||||
.QueryInterface(Ci.nsISyncMessageSender);
|
||||
});
|
||||
|
||||
function AppProtocolHandler() {
|
||||
this._basePath = null;
|
||||
}
|
||||
|
||||
AppProtocolHandler.prototype = {
|
||||
classID: Components.ID("{b7ad6144-d344-4687-b2d0-b6b9dce1f07f}"),
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]),
|
||||
|
||||
scheme: "app",
|
||||
defaultPort: -1,
|
||||
// Using the same flags as the JAR protocol handler.
|
||||
protocolFlags2: Ci.nsIProtocolHandler.URI_NORELATIVE |
|
||||
Ci.nsIProtocolHandler.URI_NOAUTH |
|
||||
Ci.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE,
|
||||
|
||||
get basePath() {
|
||||
if (!this._basePath) {
|
||||
this._basePath = cpmm.sendSyncMessage("Webapps:GetBasePath", { })[0] + "/";
|
||||
}
|
||||
|
||||
return this._basePath;
|
||||
},
|
||||
|
||||
newURI: function app_phNewURI(aSpec, aOriginCharset, aBaseURI) {
|
||||
let uri = Cc["@mozilla.org/network/standard-url;1"]
|
||||
.createInstance(Ci.nsIStandardURL);
|
||||
uri.init(Ci.nsIStandardURL.URLTYPE_STANDARD, -1, aSpec, aOriginCharset,
|
||||
aBaseURI);
|
||||
return uri.QueryInterface(Ci.nsIURI);
|
||||
},
|
||||
|
||||
newChannel: function app_phNewChannel(aURI) {
|
||||
// We map app://ABCDEF/path/to/file.ext to
|
||||
// jar:file:///path/to/profile/webapps/ABCDEF/application.zip!/path/to/file.ext
|
||||
let noScheme = aURI.spec.substring(6);
|
||||
let firstSlash = noScheme.indexOf("/");
|
||||
|
||||
let appId = noScheme;
|
||||
let fileSpec = aURI.path;
|
||||
|
||||
if (firstSlash) {
|
||||
appId = noScheme.substring(0, firstSlash);
|
||||
}
|
||||
|
||||
// Simulates default behavior of http servers:
|
||||
// Adds index.html if the file spec ends in / in /#anchor
|
||||
let lastSlash = fileSpec.lastIndexOf("/");
|
||||
if (lastSlash == fileSpec.length - 1) {
|
||||
fileSpec += "index.html";
|
||||
} else if (fileSpec[lastSlash + 1] == '#') {
|
||||
let anchor = fileSpec.substring(lastSlash + 1);
|
||||
fileSpec = fileSpec.substring(0, lastSlash) + "/index.html" + anchor;
|
||||
}
|
||||
|
||||
// Build a jar channel and masquerade as an app:// URI.
|
||||
let uri = "jar:file://" + this.basePath + appId + "/application.zip!" + fileSpec;
|
||||
let channel = Services.io.newChannel(uri, null, null);
|
||||
channel.QueryInterface(Ci.nsIJARChannel).setAppURI(aURI);
|
||||
channel.QueryInterface(Ci.nsIChannel).originalURI = aURI;
|
||||
|
||||
return channel;
|
||||
},
|
||||
|
||||
allowPort: function app_phAllowPort(aPort, aScheme) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const NSGetFactory = XPCOMUtils.generateNSGetFactory([AppProtocolHandler]);
|
|
@ -0,0 +1,3 @@
|
|||
# AppProtocolHander.js
|
||||
component {b7ad6144-d344-4687-b2d0-b6b9dce1f07f} AppProtocolHandler.js
|
||||
contract @mozilla.org/network/protocol;1?name=app {b7ad6144-d344-4687-b2d0-b6b9dce1f07f}
|
|
@ -0,0 +1,17 @@
|
|||
# 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/.
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
EXTRA_COMPONENTS = \
|
||||
AppProtocolHandler.js \
|
||||
AppProtocolHandler.manifest \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
Загрузка…
Ссылка в новой задаче