Merge m-c to fx-team. a=merge

This commit is contained in:
Ryan VanderMeulen 2015-08-25 16:58:22 -04:00
commit a42c50b92b
268 changed files with 4016 additions and 2127 deletions

View File

@ -32,9 +32,9 @@ let principaluri = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService). getService(Ci.nsIIOService).
newURI(PSEUDOURI, null, null); newURI(PSEUDOURI, null, null);
let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"] let principal = Cc["@mozilla.org/scriptsecuritymanager;1"].
.getService(Ci.nsIScriptSecurityManager); getService(Ci.nsIScriptSecurityManager).
let principal = ssm.createCodebasePrincipal(principaluri, {}); getCodebasePrincipal(principaluri);
function toArray(args) { function toArray(args) {
return Array.prototype.slice.call(args); return Array.prototype.slice.call(args);

View File

@ -154,10 +154,11 @@ this.AboutServiceWorkers = {
return; return;
} }
let principal = Services.scriptSecurityManager.createCodebasePrincipal( let principal = Services.scriptSecurityManager.getAppCodebasePrincipal(
// TODO: Bug 1196652. use originNoSuffix
Services.io.newURI(message.principal.origin, null, null), Services.io.newURI(message.principal.origin, null, null),
message.principal.originAttributes); message.principal.originAttributes.appId,
message.principal.originAttributes.inBrowser
);
if (!message.scope) { if (!message.scope) {
self.sendError(message.id, "MissingScope"); self.sendError(message.id, "MissingScope");

View File

@ -205,9 +205,9 @@ ContentPermissionPrompt.prototype = {
// URL. // URL.
let notDenyAppPrincipal = function(type) { let notDenyAppPrincipal = function(type) {
let url = Services.io.newURI(app.origin, null, null); let url = Services.io.newURI(app.origin, null, null);
let principal = let principal = secMan.getAppCodebasePrincipal(url,
secMan.createCodebasePrincipal(url, request.principal.appId,
{appId: request.principal.appId}); /*mozbrowser*/false);
let result = Services.perms.testExactPermissionFromPrincipal(principal, let result = Services.perms.testExactPermissionFromPrincipal(principal,
type.access); type.access);

View File

@ -55,8 +55,7 @@
// the error message. // the error message.
if (!config.origin) { if (!config.origin) {
let URI = Services.io.newURI(url, null, null); let URI = Services.io.newURI(url, null, null);
config.origin = config.origin = Services.scriptSecurityManager.getNoAppCodebasePrincipal(URI).origin;
Services.scriptSecurityManager.createCodebasePrincipal(URI, {}).origin;
} }
switch (mode) { switch (mode) {

View File

@ -11,7 +11,7 @@ const URL = "http://mochi.test:8888/browser/browser/base/content/test/general/of
registerCleanupFunction(function() { registerCleanupFunction(function() {
// Clean up after ourself // Clean up after ourself
let uri = Services.io.newURI(URL, null, null); let uri = Services.io.newURI(URL, null, null);
let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {}); var principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(uri);
Services.perms.removeFromPrincipal(principal, "offline-app"); Services.perms.removeFromPrincipal(principal, "offline-app");
Services.prefs.clearUserPref("offline-apps.quota.warn"); Services.prefs.clearUserPref("offline-apps.quota.warn");
Services.prefs.clearUserPref("offline-apps.allow_by_default"); Services.prefs.clearUserPref("offline-apps.allow_by_default");

View File

@ -564,7 +564,7 @@ var gAllTests = [
var sm = Cc["@mozilla.org/scriptsecuritymanager;1"] var sm = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager); .getService(Ci.nsIScriptSecurityManager);
var principal = sm.createCodebasePrincipal(URI, {}); var principal = sm.getNoAppCodebasePrincipal(URI);
// Give www.example.com privileges to store offline data // Give www.example.com privileges to store offline data
var pm = Cc["@mozilla.org/permissionmanager;1"] var pm = Cc["@mozilla.org/permissionmanager;1"]
@ -634,7 +634,7 @@ var gAllTests = [
var sm = Cc["@mozilla.org/scriptsecuritymanager;1"] var sm = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager); .getService(Ci.nsIScriptSecurityManager);
var principal = sm.createCodebasePrincipal(URI, {}); var principal = sm.getNoAppCodebasePrincipal(URI);
// Open the dialog // Open the dialog
let wh = new WindowHelper(); let wh = new WindowHelper();

View File

@ -43,10 +43,12 @@ window.addEventListener("message", function(event) {
var uri1 = ioService.newURI(frames.testFrame.location, null, null); var uri1 = ioService.newURI(frames.testFrame.location, null, null);
var uri2 = ioService.newURI(frames.testFrame3.location, null, null); var uri2 = ioService.newURI(frames.testFrame3.location, null, null);
var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"] var principal1 = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(SpecialPowers.Ci.nsIScriptSecurityManager); .getService(SpecialPowers.Ci.nsIScriptSecurityManager)
var principal1 = ssm.createCodebasePrincipal(uri1, {}); .getNoAppCodebasePrincipal(uri1);
var principal2 = ssm.createCodebasePrincipal(uri2, {}); var principal2 = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(SpecialPowers.Ci.nsIScriptSecurityManager)
.getNoAppCodebasePrincipal(uri2);
pm.removeFromPrincipal(principal1, "offline-app"); pm.removeFromPrincipal(principal1, "offline-app");
pm.removeFromPrincipal(principal2, "offline-app"); pm.removeFromPrincipal(principal2, "offline-app");

View File

@ -39,9 +39,9 @@ function finishTest() {
var uri = Cc["@mozilla.org/network/io-service;1"].getService(SpecialPowers.Ci.nsIIOService) var uri = Cc["@mozilla.org/network/io-service;1"].getService(SpecialPowers.Ci.nsIIOService)
.newURI(window.frames[0].location, null, null); .newURI(window.frames[0].location, null, null);
var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"] var principal = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(SpecialPowers.Ci.nsIScriptSecurityManager); .getService(SpecialPowers.Ci.nsIScriptSecurityManager)
var principal = ssm.createCodebasePrincipal(uri, {}); .getNoAppCodebasePrincipal(uri);
pm.removeFromPrincipal(principal, "offline-app"); pm.removeFromPrincipal(principal, "offline-app");

View File

@ -18,7 +18,7 @@ Cu.import("resource://gre/modules/Timer.jsm", tmp);
let {Promise, NewTabUtils, Sanitizer, clearTimeout, setTimeout, DirectoryLinksProvider, PlacesTestUtils} = tmp; let {Promise, NewTabUtils, Sanitizer, clearTimeout, setTimeout, DirectoryLinksProvider, PlacesTestUtils} = tmp;
let uri = Services.io.newURI("about:newtab", null, null); let uri = Services.io.newURI("about:newtab", null, null);
let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {}); let principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(uri);
let isMac = ("nsILocalFileMac" in Ci); let isMac = ("nsILocalFileMac" in Ci);
let isLinux = ("@mozilla.org/gnome-gconf-service;1" in Cc); let isLinux = ("@mozilla.org/gnome-gconf-service;1" in Cc);

View File

@ -254,7 +254,7 @@ FeedConverter.prototype = {
chromeChannel = ios.newChannelFromURIWithLoadInfo(aboutFeedsURI, loadInfo); chromeChannel = ios.newChannelFromURIWithLoadInfo(aboutFeedsURI, loadInfo);
chromeChannel.originalURI = result.uri; chromeChannel.originalURI = result.uri;
chromeChannel.owner = chromeChannel.owner =
Services.scriptSecurityManager.createCodebasePrincipal(aboutFeedsURI, {}); Services.scriptSecurityManager.getNoAppCodebasePrincipal(aboutFeedsURI);
} else { } else {
chromeChannel = ios.newChannelFromURIWithLoadInfo(result.uri, loadInfo); chromeChannel = ios.newChannelFromURIWithLoadInfo(result.uri, loadInfo);
} }

View File

@ -505,7 +505,7 @@ let AboutPermissions = {
while (row = aResults.getNextRow()) { while (row = aResults.getNextRow()) {
let spec = row.getResultByName("url"); let spec = row.getResultByName("url");
let uri = NetUtil.newURI(spec); let uri = NetUtil.newURI(spec);
let principal = gSecMan.createCodebasePrincipal(uri, {}); let principal = gSecMan.getNoAppCodebasePrincipal(uri);
AboutPermissions.addPrincipal(principal); AboutPermissions.addPrincipal(principal);
} }
@ -556,7 +556,7 @@ let AboutPermissions = {
try { try {
// aLogin.hostname is a string in origin URL format (e.g. "http://foo.com") // aLogin.hostname is a string in origin URL format (e.g. "http://foo.com")
let uri = NetUtil.newURI(aLogin.hostname); let uri = NetUtil.newURI(aLogin.hostname);
let principal = gSecMan.createCodebasePrincipal(uri, {}); let principal = gSecMan.getNoAppCodebasePrincipal(uri);
this.addPrincipal(principal); this.addPrincipal(principal);
} catch (e) { } catch (e) {
// newURI will throw for add-ons logins stored in chrome:// URIs // newURI will throw for add-ons logins stored in chrome:// URIs
@ -572,7 +572,7 @@ let AboutPermissions = {
try { try {
// aHostname is a string in origin URL format (e.g. "http://foo.com") // aHostname is a string in origin URL format (e.g. "http://foo.com")
let uri = NetUtil.newURI(aHostname); let uri = NetUtil.newURI(aHostname);
let principal = gSecMan.createCodebasePrincipal(uri, {}); let principal = gSecMan.getNoAppCodebasePrincipal(uri);
this.addPrincipal(principal); this.addPrincipal(principal);
} catch (e) { } catch (e) {
// newURI will throw for add-ons logins stored in chrome:// URIs // newURI will throw for add-ons logins stored in chrome:// URIs

View File

@ -95,12 +95,12 @@ var gPermissionManager = {
let uri; let uri;
try { try {
uri = Services.io.newURI(input_url, null, null); uri = Services.io.newURI(input_url, null, null);
principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {}); principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(uri);
// If we have ended up with an unknown scheme, the following will throw. // If we have ended up with an unknown scheme, the following will throw.
principal.origin; principal.origin;
} catch(ex) { } catch(ex) {
uri = Services.io.newURI("http://" + input_url, null, null); uri = Services.io.newURI("http://" + input_url, null, null);
principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {}); principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(uri);
// If we have ended up with an unknown scheme, the following will throw. // If we have ended up with an unknown scheme, the following will throw.
principal.origin; principal.origin;
} }

View File

@ -8,10 +8,8 @@ const ABOUT_PERMISSIONS_SPEC = "about:permissions";
const TEST_URI_1 = NetUtil.newURI("http://mozilla.com/"); const TEST_URI_1 = NetUtil.newURI("http://mozilla.com/");
const TEST_URI_2 = NetUtil.newURI("http://mozilla.org/"); const TEST_URI_2 = NetUtil.newURI("http://mozilla.org/");
const TEST_PRINCIPAL_1 = const TEST_PRINCIPAL_1 = Services.scriptSecurityManager.getNoAppCodebasePrincipal(TEST_URI_1);
Services.scriptSecurityManager.createCodebasePrincipal(TEST_URI_1, {}); const TEST_PRINCIPAL_2 = Services.scriptSecurityManager.getNoAppCodebasePrincipal(TEST_URI_2);
const TEST_PRINCIPAL_2 =
Services.scriptSecurityManager.createCodebasePrincipal(TEST_URI_2, {});
// values from DefaultPermissions object // values from DefaultPermissions object
const PERM_UNKNOWN = 0; const PERM_UNKNOWN = 0;

View File

@ -116,14 +116,20 @@ support-files =
[browser_dbg_aaa_run_first_leaktest.js] [browser_dbg_aaa_run_first_leaktest.js]
skip-if = e10s && debug skip-if = e10s && debug
[browser_dbg_addonactor.js] [browser_dbg_addonactor.js]
tags = addons
[browser_dbg_addon-sources.js] [browser_dbg_addon-sources.js]
tags = addons
[browser_dbg_addon-modules.js] [browser_dbg_addon-modules.js]
skip-if = e10s # TODO skip-if = e10s # TODO
tags = addons
[browser_dbg_addon-modules-unpacked.js] [browser_dbg_addon-modules-unpacked.js]
skip-if = e10s # TODO skip-if = e10s # TODO
tags = addons
[browser_dbg_addon-panels.js] [browser_dbg_addon-panels.js]
tags = addons
[browser_dbg_addon-console.js] [browser_dbg_addon-console.js]
skip-if = e10s && debug || os == 'win' # bug 1005274 skip-if = e10s && debug || os == 'win' # bug 1005274
tags = addons
[browser_dbg_auto-pretty-print-01.js] [browser_dbg_auto-pretty-print-01.js]
[browser_dbg_auto-pretty-print-02.js] [browser_dbg_auto-pretty-print-02.js]
[browser_dbg_bfcache.js] [browser_dbg_bfcache.js]
@ -256,6 +262,7 @@ skip-if = e10s && debug
skip-if = e10s && debug skip-if = e10s && debug
[browser_dbg_listaddons.js] [browser_dbg_listaddons.js]
skip-if = e10s && debug skip-if = e10s && debug
tags = addons
[browser_dbg_listtabs-01.js] [browser_dbg_listtabs-01.js]
skip-if = e10s # TODO skip-if = e10s # TODO
[browser_dbg_listtabs-02.js] [browser_dbg_listtabs-02.js]

View File

@ -15,9 +15,9 @@ const TEST_URI_XUL = TEST_URL_ROOT + "doc_content_stylesheet.xul";
const XUL_URI = Cc["@mozilla.org/network/io-service;1"] const XUL_URI = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService) .getService(Ci.nsIIOService)
.newURI(TEST_URI_XUL, null, null); .newURI(TEST_URI_XUL, null, null);
let ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"] const XUL_PRINCIPAL = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager); .getService(Ci.nsIScriptSecurityManager)
const XUL_PRINCIPAL = ssm.createCodebasePrincipal(XUL_URI, {}); .getNoAppCodebasePrincipal(XUL_URI);
add_task(function*() { add_task(function*() {
info("Checking stylesheets on HTML document"); info("Checking stylesheets on HTML document");

View File

@ -995,21 +995,14 @@ PdfStreamConverter.prototype = {
// We can use resource principal when data is fetched by the chrome // We can use resource principal when data is fetched by the chrome
// e.g. useful for NoScript // e.g. useful for NoScript
var ssm = Cc['@mozilla.org/scriptsecuritymanager;1'] var securityManager = Cc['@mozilla.org/scriptsecuritymanager;1']
.getService(Ci.nsIScriptSecurityManager); .getService(Ci.nsIScriptSecurityManager);
var uri = NetUtil.newURI(PDF_VIEWER_WEB_PAGE, null, null); var uri = NetUtil.newURI(PDF_VIEWER_WEB_PAGE, null, null);
// FF16 and below had getCodebasePrincipal, it was replaced by // FF16 and below had getCodebasePrincipal, it was replaced by
// getNoAppCodebasePrincipal (bug 758258). // getNoAppCodebasePrincipal (bug 758258).
// FF 43 added createCodebasePrincipal to replace getNoAppCodebasePrincipal var resourcePrincipal = 'getNoAppCodebasePrincipal' in securityManager ?
// (bug 1165272). securityManager.getNoAppCodebasePrincipal(uri) :
var resourcePrincipal securityManager.getCodebasePrincipal(uri);
if ('createCodebasePrincipal' in ssm) {
resourcePrincipal = ssm.createCodebasePrincipal(uri, {});
} else if ('getNoAppCodebasePrincipal' in ssm) {
resourcePrincipal = ssm.getNoAppCodebasePrincipal(uri)
} else {
resourcePrincipal = ssm.getCodebasePrincipal(uri);
}
aRequest.owner = resourcePrincipal; aRequest.owner = resourcePrincipal;
channel.asyncOpen(proxy, aContext); channel.asyncOpen(proxy, aContext);
}, },

View File

@ -22,9 +22,9 @@ var SpecialStorageUtils = {
createWrappedSpecialStorage: function (sandbox, swfUrl, privateBrowsing) { createWrappedSpecialStorage: function (sandbox, swfUrl, privateBrowsing) {
// Creating internal localStorage object based on url and privateBrowsing setting. // Creating internal localStorage object based on url and privateBrowsing setting.
var uri = Services.io.newURI(swfUrl, null, null); var uri = Services.io.newURI(swfUrl, null, null);
var ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"] var principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
.getService(Components.interfaces.nsIScriptSecurityManager); .getService(Components.interfaces.nsIScriptSecurityManager)
var principal = ssm.createCodebasePrincipal(uri, {}); .getNoAppCodebasePrincipal(uri);
var dsm = Components.classes["@mozilla.org/dom/localStorage-manager;1"] var dsm = Components.classes["@mozilla.org/dom/localStorage-manager;1"]
.getService(Components.interfaces.nsIDOMStorageManager); .getService(Components.interfaces.nsIDOMStorageManager);
var storage = dsm.createStorage(null, principal, privateBrowsing); var storage = dsm.createStorage(null, principal, privateBrowsing);

View File

@ -66,8 +66,7 @@ this.Feeds = {
if (aIsFeed) { if (aIsFeed) {
// re-create the principal as it may be a CPOW. // re-create the principal as it may be a CPOW.
let principalURI = BrowserUtils.makeURIFromCPOW(aPrincipal.URI); let principalURI = BrowserUtils.makeURIFromCPOW(aPrincipal.URI);
let principalToCheck = let principalToCheck = Services.scriptSecurityManager.getNoAppCodebasePrincipal(principalURI);
Services.scriptSecurityManager.createCodebasePrincipal(principalURI, {});
try { try {
BrowserUtils.urlSecurityCheck(aLink.href, principalToCheck, BrowserUtils.urlSecurityCheck(aLink.href, principalToCheck,
Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL); Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);

View File

@ -26,7 +26,7 @@ class DomainPolicyClone;
[ptr] native JSObjectPtr(JSObject); [ptr] native JSObjectPtr(JSObject);
[ptr] native DomainPolicyClonePtr(mozilla::dom::DomainPolicyClone); [ptr] native DomainPolicyClonePtr(mozilla::dom::DomainPolicyClone);
[scriptable, uuid(6e8a4d1e-d9c6-4d86-bf53-d73f58f36148)] [scriptable, uuid(9a8f0b70-6b9f-4e19-8885-7cfe24f4a42d)]
interface nsIScriptSecurityManager : nsISupports interface nsIScriptSecurityManager : nsISupports
{ {
/** /**
@ -150,12 +150,10 @@ interface nsIScriptSecurityManager : nsISupports
* @param appId is the app id of the principal. It can't be UNKNOWN_APP_ID. * @param appId is the app id of the principal. It can't be UNKNOWN_APP_ID.
* @param inMozBrowser is true if the principal has to be considered as * @param inMozBrowser is true if the principal has to be considered as
* inside a mozbrowser frame. * inside a mozbrowser frame.
*
* @deprecated use createCodebasePrincipal instead.
*/ */
[deprecated] nsIPrincipal getAppCodebasePrincipal(in nsIURI uri, nsIPrincipal getAppCodebasePrincipal(in nsIURI uri,
in unsigned long appId, in unsigned long appId,
in boolean inMozBrowser); in boolean inMozBrowser);
/** /**
* Returns a principal that has the appId and inMozBrowser of the load * Returns a principal that has the appId and inMozBrowser of the load
@ -177,10 +175,8 @@ interface nsIScriptSecurityManager : nsISupports
* Returns a principal with that has the same origin as uri and is not part * Returns a principal with that has the same origin as uri and is not part
* of an appliction. * of an appliction.
* The returned principal will have appId = NO_APP_ID. * The returned principal will have appId = NO_APP_ID.
*
* @deprecated use createCodebasePrincipal instead.
*/ */
[deprecated] nsIPrincipal getNoAppCodebasePrincipal(in nsIURI uri); nsIPrincipal getNoAppCodebasePrincipal(in nsIURI uri);
/** /**
* Legacy method for getting a principal with no origin attributes. * Legacy method for getting a principal with no origin attributes.

View File

@ -11,7 +11,6 @@
#include "mozilla/ArrayUtils.h" #include "mozilla/ArrayUtils.h"
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
#include "mozilla/AutoRestore.h" #include "mozilla/AutoRestore.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/Casting.h" #include "mozilla/Casting.h"
#include "mozilla/dom/ContentChild.h" #include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/Element.h" #include "mozilla/dom/Element.h"
@ -9361,6 +9360,9 @@ nsDocShell::CreatePrincipalFromReferrer(nsIURI* aReferrer,
nsIPrincipal** aResult) nsIPrincipal** aResult)
{ {
nsresult rv; nsresult rv;
nsCOMPtr<nsIScriptSecurityManager> secMan =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
uint32_t appId; uint32_t appId;
rv = GetAppId(&appId); rv = GetAppId(&appId);
@ -9368,14 +9370,12 @@ nsDocShell::CreatePrincipalFromReferrer(nsIURI* aReferrer,
bool isInBrowserElement; bool isInBrowserElement;
rv = GetIsInBrowserElement(&isInBrowserElement); rv = GetIsInBrowserElement(&isInBrowserElement);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = secMan->GetAppCodebasePrincipal(aReferrer,
// TODO: Bug 1165466 - Pass mOriginAttributes directly. appId,
OriginAttributes attrs(appId, isInBrowserElement); isInBrowserElement,
nsCOMPtr<nsIPrincipal> prin = aResult);
BasePrincipal::CreateCodebasePrincipal(aReferrer, attrs); NS_ENSURE_SUCCESS(rv, rv);
prin.forget(aResult); return NS_OK;
return *aResult ? NS_OK : NS_ERROR_FAILURE;
} }
NS_IMETHODIMP NS_IMETHODIMP

View File

@ -73,9 +73,11 @@ mozIApplication.prototype = {
this._principal = null; this._principal = null;
try { try {
this._principal = Services.scriptSecurityManager.createCodebasePrincipal( this._principal = Services.scriptSecurityManager.getAppCodebasePrincipal(
Services.io.newURI(this.origin, null, null), Services.io.newURI(this.origin, null, null),
{appId: this.localId}); this.localId,
false /* mozbrowser */
);
} catch(e) { } catch(e) {
dump("Could not create app principal " + e + "\n"); dump("Could not create app principal " + e + "\n");
} }

View File

@ -228,8 +228,8 @@ function installCache(app) {
if (!cacheManifest.exists()) if (!cacheManifest.exists())
return; return;
let principal = let principal = Services.scriptSecurityManager.getAppCodebasePrincipal(
Services.scriptSecurityManager.createCodebasePrincipal(app.origin, {appId: aApp.localId}); app.origin, app.localId, false);
// If the build has been correctly configured, this should not happen! // If the build has been correctly configured, this should not happen!
// If we install the cache anyway, it won't be updateable. If we don't install // If we install the cache anyway, it won't be updateable. If we don't install

View File

@ -40,7 +40,7 @@ this.ScriptPreloader = {
let toLoad = aManifest.precompile.length; let toLoad = aManifest.precompile.length;
let principal = let principal =
Services.scriptSecurityManager Services.scriptSecurityManager
.createCodebasePrincipal(origin, {appId: aApp.localId}); .getAppCodebasePrincipal(origin, aApp.localId, false);
aManifest.precompile.forEach((aPath) => { aManifest.precompile.forEach((aPath) => {
let uri = Services.io.newURI(aPath, null, origin); let uri = Services.io.newURI(aPath, null, origin);

View File

@ -820,7 +820,8 @@ this.DOMApplicationRegistry = {
let uri = Services.io.newURI(aOrigin, null, null); let uri = Services.io.newURI(aOrigin, null, null);
let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"] let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager); .getService(Ci.nsIScriptSecurityManager);
let principal = secMan.createCodebasePrincipal(uri, {appId: aId}); let principal = secMan.getAppCodebasePrincipal(uri, aId,
/*mozbrowser*/ false);
if (!dataStoreService.checkPermission(principal)) { if (!dataStoreService.checkPermission(principal)) {
return; return;
} }
@ -3368,9 +3369,8 @@ this.DOMApplicationRegistry = {
let requestChannel; let requestChannel;
let appURI = NetUtil.newURI(aNewApp.origin, null, null); let appURI = NetUtil.newURI(aNewApp.origin, null, null);
let principal = let principal = Services.scriptSecurityManager.getAppCodebasePrincipal(
Services.scriptSecurityManager.createCodebasePrincipal(appURI, appURI, aNewApp.localId, false);
{appId: aNewApp.localId});
if (aIsLocalFileInstall) { if (aIsLocalFileInstall) {
requestChannel = NetUtil.newChannel({ requestChannel = NetUtil.newChannel({

View File

@ -185,6 +185,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGeolocation) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGeolocation)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNotification) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNotification)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBatteryManager) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBatteryManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBatteryPromise)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPowerManager) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPowerManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCellBroadcast) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCellBroadcast)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIccManager) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIccManager)
@ -252,6 +253,8 @@ Navigator::Invalidate()
mBatteryManager = nullptr; mBatteryManager = nullptr;
} }
mBatteryPromise = nullptr;
#ifdef MOZ_B2G_FM #ifdef MOZ_B2G_FM
if (mFMRadio) { if (mFMRadio) {
mFMRadio->Shutdown(); mFMRadio->Shutdown();
@ -1455,8 +1458,37 @@ Navigator::GetMozFMRadio(ErrorResult& aRv)
// Navigator::nsINavigatorBattery // Navigator::nsINavigatorBattery
//***************************************************************************** //*****************************************************************************
battery::BatteryManager* Promise*
Navigator::GetBattery(ErrorResult& aRv) Navigator::GetBattery(ErrorResult& aRv)
{
if (mBatteryPromise) {
return mBatteryPromise;
}
if (!mWindow || !mWindow->GetDocShell()) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(mWindow);
nsRefPtr<Promise> batteryPromise = Promise::Create(go, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
mBatteryPromise = batteryPromise;
if (!mBatteryManager) {
mBatteryManager = new battery::BatteryManager(mWindow);
mBatteryManager->Init();
}
mBatteryPromise->MaybeResolve(mBatteryManager);
return mBatteryPromise;
}
battery::BatteryManager*
Navigator::GetDeprecatedBattery(ErrorResult& aRv)
{ {
if (!mBatteryManager) { if (!mBatteryManager) {
if (!mWindow) { if (!mWindow) {

View File

@ -160,7 +160,8 @@ public:
Permissions* GetPermissions(ErrorResult& aRv); Permissions* GetPermissions(ErrorResult& aRv);
// The XPCOM GetDoNotTrack is ok // The XPCOM GetDoNotTrack is ok
Geolocation* GetGeolocation(ErrorResult& aRv); Geolocation* GetGeolocation(ErrorResult& aRv);
battery::BatteryManager* GetBattery(ErrorResult& aRv); Promise* GetBattery(ErrorResult& aRv);
battery::BatteryManager* GetDeprecatedBattery(ErrorResult& aRv);
static already_AddRefed<Promise> GetDataStores(nsPIDOMWindow* aWindow, static already_AddRefed<Promise> GetDataStores(nsPIDOMWindow* aWindow,
const nsAString& aName, const nsAString& aName,
@ -371,6 +372,7 @@ private:
nsRefPtr<Geolocation> mGeolocation; nsRefPtr<Geolocation> mGeolocation;
nsRefPtr<DesktopNotificationCenter> mNotification; nsRefPtr<DesktopNotificationCenter> mNotification;
nsRefPtr<battery::BatteryManager> mBatteryManager; nsRefPtr<battery::BatteryManager> mBatteryManager;
nsRefPtr<Promise> mBatteryPromise;
#ifdef MOZ_B2G_FM #ifdef MOZ_B2G_FM
nsRefPtr<FMRadio> mFMRadio; nsRefPtr<FMRadio> mFMRadio;
#endif #endif

View File

@ -95,6 +95,7 @@
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "nsILoadContext.h" #include "nsILoadContext.h"
#include "nsIPresShell.h" #include "nsIPresShell.h"
#include "nsIScriptSecurityManager.h"
#include "nsIScrollableFrame.h" #include "nsIScrollableFrame.h"
#include "nsView.h" #include "nsView.h"
#include "nsViewManager.h" #include "nsViewManager.h"
@ -191,7 +192,6 @@
#include "nsRefreshDriver.h" #include "nsRefreshDriver.h"
#include "mozilla/AddonPathService.h" #include "mozilla/AddonPathService.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/Services.h" #include "mozilla/Services.h"
#include "mozilla/Telemetry.h" #include "mozilla/Telemetry.h"
#include "nsLocation.h" #include "nsLocation.h"
@ -256,8 +256,6 @@ static const char kStorageEnabled[] = "dom.storage.enabled";
using namespace mozilla; using namespace mozilla;
using namespace mozilla::dom; using namespace mozilla::dom;
using namespace mozilla::dom::ipc; using namespace mozilla::dom::ipc;
using mozilla::BasePrincipal;
using mozilla::OriginAttributes;
using mozilla::TimeStamp; using mozilla::TimeStamp;
using mozilla::TimeDuration; using mozilla::TimeDuration;
using mozilla::dom::cache::CacheStorage; using mozilla::dom::cache::CacheStorage;
@ -8589,14 +8587,21 @@ nsGlobalWindow::PostMessageMozOuter(JSContext* aCx, JS::Handle<JS::Value> aMessa
return; return;
} }
nsCOMPtr<nsIScriptSecurityManager> ssm =
nsContentUtils::GetSecurityManager();
MOZ_ASSERT(ssm);
nsCOMPtr<nsIPrincipal> principal = nsContentUtils::SubjectPrincipal(); nsCOMPtr<nsIPrincipal> principal = nsContentUtils::SubjectPrincipal();
MOZ_ASSERT(principal); MOZ_ASSERT(principal);
OriginAttributes attrs = BasePrincipal::Cast(principal)->OriginAttributesRef(); uint32_t appId = principal->GetAppId();
bool isInBrowser = principal->GetIsInBrowserElement();
// Create a nsIPrincipal inheriting the app/browser attributes from the // Create a nsIPrincipal inheriting the app/browser attributes from the
// caller. // caller.
providedPrincipal = BasePrincipal::CreateCodebasePrincipal(originURI, attrs); nsresult rv = ssm->GetAppCodebasePrincipal(originURI, appId, isInBrowser,
if (NS_WARN_IF(!providedPrincipal)) { getter_AddRefs(providedPrincipal));
if (NS_WARN_IF(NS_FAILED(rv))) {
return; return;
} }
} }

View File

@ -10,6 +10,7 @@
#include "mozilla/DOMEventTargetHelper.h" #include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/Hal.h" #include "mozilla/Hal.h"
#include "mozilla/dom/BatteryManagerBinding.h" #include "mozilla/dom/BatteryManagerBinding.h"
#include "mozilla/Preferences.h"
#include "nsIDOMClassInfo.h" #include "nsIDOMClassInfo.h"
/** /**
@ -56,10 +57,37 @@ BatteryManager::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
return BatteryManagerBinding::Wrap(aCx, this, aGivenProto); return BatteryManagerBinding::Wrap(aCx, this, aGivenProto);
} }
bool
BatteryManager::Charging() const
{
MOZ_ASSERT(NS_IsMainThread());
// For testing, unable to report the battery status information
if (Preferences::GetBool("dom.battery.test.default", false)) {
return true;
}
if (Preferences::GetBool("dom.battery.test.charging", false)) {
return true;
}
if (Preferences::GetBool("dom.battery.test.discharging", false)) {
return false;
}
return mCharging;
}
double double
BatteryManager::DischargingTime() const BatteryManager::DischargingTime() const
{ {
if (mCharging || mRemainingTime == kUnknownRemainingTime) { MOZ_ASSERT(NS_IsMainThread());
// For testing, unable to report the battery status information
if (Preferences::GetBool("dom.battery.test.default", false)) {
return std::numeric_limits<double>::infinity();
}
if (Preferences::GetBool("dom.battery.test.discharging", false)) {
return 42.0;
}
if (Charging() || mRemainingTime == kUnknownRemainingTime) {
return std::numeric_limits<double>::infinity(); return std::numeric_limits<double>::infinity();
} }
@ -69,13 +97,34 @@ BatteryManager::DischargingTime() const
double double
BatteryManager::ChargingTime() const BatteryManager::ChargingTime() const
{ {
if (!mCharging || mRemainingTime == kUnknownRemainingTime) { MOZ_ASSERT(NS_IsMainThread());
// For testing, unable to report the battery status information
if (Preferences::GetBool("dom.battery.test.default", false)) {
return 0.0;
}
if (Preferences::GetBool("dom.battery.test.charging", false)) {
return 42.0;
}
if (!Charging() || mRemainingTime == kUnknownRemainingTime) {
return std::numeric_limits<double>::infinity(); return std::numeric_limits<double>::infinity();
} }
return mRemainingTime; return mRemainingTime;
} }
double
BatteryManager::Level() const
{
MOZ_ASSERT(NS_IsMainThread());
// For testing, unable to report the battery status information
if (Preferences::GetBool("dom.battery.test.default")) {
return 1.0;
}
return mLevel;
}
void void
BatteryManager::UpdateFromBatteryInfo(const hal::BatteryInformation& aBatteryInfo) BatteryManager::UpdateFromBatteryInfo(const hal::BatteryInformation& aBatteryInfo)
{ {

View File

@ -46,19 +46,13 @@ public:
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
bool Charging() const bool Charging() const;
{
return mCharging;
}
double ChargingTime() const; double ChargingTime() const;
double DischargingTime() const; double DischargingTime() const;
double Level() const double Level() const;
{
return mLevel;
}
IMPL_EVENT_HANDLER(chargingchange) IMPL_EVENT_HANDLER(chargingchange)
IMPL_EVENT_HANDLER(chargingtimechange) IMPL_EVENT_HANDLER(chargingtimechange)

View File

@ -9,3 +9,9 @@ qemu = true
[test_battery_status_full.js] [test_battery_status_full.js]
[test_battery_status_not_charging.js] [test_battery_status_not_charging.js]
[test_battery_status_unknown.js] [test_battery_status_unknown.js]
[test_deprecated_battery_level.js]
[test_deprecated_battery_status_charging.js]
[test_deprecated_battery_status_discharging.js]
[test_deprecated_battery_status_full.js]
[test_deprecated_battery_status_not_charging.js]
[test_deprecated_battery_status_unknown.js]

View File

@ -3,15 +3,18 @@
MARIONETTE_TIMEOUT = 10000; MARIONETTE_TIMEOUT = 10000;
let battery = window.navigator.battery; let battery = null;
function verifyInitialState() { function verifyInitialState() {
ok(battery, "battery"); window.navigator.getBattery().then(function (b) {
is(battery.level, 0.5, "battery.level"); battery = b;
runEmulatorCmd("power display", function (result) { ok(battery, "battery");
is(result.pop(), "OK", "power display successful"); is(battery.level, 0.5, "battery.level");
ok(result.indexOf("capacity: 50") !== -1, "power capacity"); runEmulatorCmd("power display", function (result) {
setUp(); is(result.pop(), "OK", "power display successful");
ok(result.indexOf("capacity: 50") !== -1, "power capacity");
setUp();
});
}); });
} }
@ -29,10 +32,10 @@ function changeCapacity(capacity, changeExpected, nextFunction) {
log("Changing power capacity to " + capacity); log("Changing power capacity to " + capacity);
if (changeExpected) { if (changeExpected) {
battery.onlevelchange = function (event) { battery.onlevelchange = function (event) {
battery.onlevelchange = unexpectedEvent; battery.onlevelchange = unexpectedEvent;
is(event.type, "levelchange", "event.type"); is(event.type, "levelchange", "event.type");
is(battery.level, capacity / 100, "battery.level"); is(battery.level, capacity / 100, "battery.level");
nextFunction(); nextFunction();
}; };
runEmulatorCmd("power capacity " + capacity); runEmulatorCmd("power capacity " + capacity);
} }

View File

@ -3,17 +3,20 @@
MARIONETTE_TIMEOUT = 10000; MARIONETTE_TIMEOUT = 10000;
let battery = window.navigator.battery; let battery = null;
let fromStatus = "charging"; let fromStatus = "charging";
let fromCharging = true; let fromCharging = true;
function verifyInitialState() { function verifyInitialState() {
ok(battery, "battery"); window.navigator.getBattery().then(function (b) {
ok(battery.charging, "battery.charging"); battery = b;
runEmulatorCmd("power display", function (result) { ok(battery, "battery");
is(result.pop(), "OK", "power display successful"); ok(battery.charging, "battery.charging");
ok(result.indexOf("status: Charging") !== -1, "power status charging"); runEmulatorCmd("power display", function (result) {
setUp(); is(result.pop(), "OK", "power display successful");
ok(result.indexOf("status: Charging") !== -1, "power status charging");
setUp();
});
}); });
} }

View File

@ -3,17 +3,20 @@
MARIONETTE_TIMEOUT = 10000; MARIONETTE_TIMEOUT = 10000;
let battery = window.navigator.battery; let battery = null;
let fromStatus = "discharging"; let fromStatus = "discharging";
let fromCharging = false; let fromCharging = false;
function verifyInitialState() { function verifyInitialState() {
ok(battery, "battery"); window.navigator.getBattery().then(function (b) {
ok(battery.charging, "battery.charging"); battery = b;
runEmulatorCmd("power display", function (result) { ok(battery, "battery");
is(result.pop(), "OK", "power display successful"); ok(battery.charging, "battery.charging");
ok(result.indexOf("status: Charging") !== -1, "power status charging"); runEmulatorCmd("power display", function (result) {
setUp(); is(result.pop(), "OK", "power display successful");
ok(result.indexOf("status: Charging") !== -1, "power status charging");
setUp();
});
}); });
} }

View File

@ -8,12 +8,15 @@ let fromStatus = "full";
let fromCharging = true; let fromCharging = true;
function verifyInitialState() { function verifyInitialState() {
ok(battery, "battery"); window.navigator.getBattery().then(function (b) {
ok(battery.charging, "battery.charging"); battery = b;
runEmulatorCmd("power display", function (result) { ok(battery, "battery");
is(result.pop(), "OK", "power display successful"); ok(battery.charging, "battery.charging");
ok(result.indexOf("status: Charging") !== -1, "power status charging"); runEmulatorCmd("power display", function (result) {
setUp(); is(result.pop(), "OK", "power display successful");
ok(result.indexOf("status: Charging") !== -1, "power status charging");
setUp();
});
}); });
} }

View File

@ -8,12 +8,15 @@ let fromStatus = "not-charging";
let fromCharging = false; let fromCharging = false;
function verifyInitialState() { function verifyInitialState() {
ok(battery, "battery"); window.navigator.getBattery().then(function (b) {
ok(battery.charging, "battery.charging"); battery = b;
runEmulatorCmd("power display", function (result) { ok(battery, "battery");
is(result.pop(), "OK", "power display successful"); ok(battery.charging, "battery.charging");
ok(result.indexOf("status: Charging") !== -1, "power status charging"); runEmulatorCmd("power display", function (result) {
setUp(); is(result.pop(), "OK", "power display successful");
ok(result.indexOf("status: Charging") !== -1, "power status charging");
setUp();
});
}); });
} }

View File

@ -8,12 +8,15 @@ let fromStatus = "unknown";
let fromCharging = false; let fromCharging = false;
function verifyInitialState() { function verifyInitialState() {
ok(battery, "battery"); window.navigator.getBattery().then(function (b) {
ok(battery.charging, "battery.charging"); battery = b;
runEmulatorCmd("power display", function (result) { ok(battery, "battery");
is(result.pop(), "OK", "power display successful"); ok(battery.charging, "battery.charging");
ok(result.indexOf("status: Charging") !== -1, "power status charging"); runEmulatorCmd("power display", function (result) {
setUp(); is(result.pop(), "OK", "power display successful");
ok(result.indexOf("status: Charging") !== -1, "power status charging");
setUp();
});
}); });
} }

View File

@ -0,0 +1,68 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 10000;
let battery = window.navigator.battery;
function verifyInitialState() {
ok(battery, "battery");
is(battery.level, 0.5, "battery.level");
runEmulatorCmd("power display", function (result) {
is(result.pop(), "OK", "power display successful");
ok(result.indexOf("capacity: 50") !== -1, "power capacity");
setUp();
});
}
function unexpectedEvent(event) {
ok(false, "Unexpected " + event.type + " event");
}
function setUp() {
battery.onchargingchange = unexpectedEvent;
battery.onlevelchange = unexpectedEvent;
levelUp();
}
function changeCapacity(capacity, changeExpected, nextFunction) {
log("Changing power capacity to " + capacity);
if (changeExpected) {
battery.onlevelchange = function (event) {
battery.onlevelchange = unexpectedEvent;
is(event.type, "levelchange", "event.type");
is(battery.level, capacity / 100, "battery.level");
nextFunction();
};
runEmulatorCmd("power capacity " + capacity);
}
else {
runEmulatorCmd("power capacity " + capacity, function () {
is(battery.level, capacity / 100, "battery.level");
nextFunction();
});
}
}
function levelUp() {
changeCapacity("90", true, levelDown);
}
function levelDown() {
changeCapacity("10", true, levelSame);
}
function levelSame() {
changeCapacity("10", false, cleanUp);
}
function cleanUp() {
battery.onchargingchange = null;
battery.onlevelchange = function () {
battery.onlevelchange = null;
finish();
};
runEmulatorCmd("power capacity 50");
}
verifyInitialState();

View File

@ -0,0 +1,85 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 10000;
let battery = window.navigator.battery;
let fromStatus = "charging";
let fromCharging = true;
function verifyInitialState() {
ok(battery, "battery");
ok(battery.charging, "battery.charging");
runEmulatorCmd("power display", function (result) {
is(result.pop(), "OK", "power display successful");
ok(result.indexOf("status: Charging") !== -1, "power status charging");
setUp();
});
}
function unexpectedEvent(event) {
ok(false, "Unexpected " + event.type + " event");
}
function setUp() {
battery.onchargingchange = unexpectedEvent;
battery.onlevelchange = unexpectedEvent;
toDischarging();
}
function resetStatus(charging, nextFunction) {
log("Resetting power status to " + fromStatus);
if (charging !== fromCharging) {
battery.onchargingchange = function () {
battery.onchargingchange = unexpectedEvent;
nextFunction();
};
runEmulatorCmd("power status " + fromStatus);
}
else {
runEmulatorCmd("power status " + fromStatus, nextFunction);
}
}
function changeStatus(toStatus, toCharging, nextFunction) {
log("Changing power status to " + toStatus);
if (fromCharging !== toCharging) {
battery.onchargingchange = function (event) {
battery.onchargingchange = unexpectedEvent;
is(event.type, "chargingchange", "event type");
is(battery.charging, toCharging, "battery.charging");
resetStatus(toCharging, nextFunction);
};
runEmulatorCmd("power status " + toStatus);
}
else {
runEmulatorCmd("power status " + toStatus, function () {
is(battery.charging, toCharging, "battery.charging");
resetStatus(toCharging, nextFunction);
});
}
}
function toDischarging() {
changeStatus("discharging", false, toFull);
}
function toFull() {
changeStatus("full", true, toNotCharging);
}
function toNotCharging() {
changeStatus("not-charging", false, toUnknown);
}
function toUnknown() {
changeStatus("unknown", false, cleanUp);
}
function cleanUp() {
battery.onchargingchange = null;
battery.onlevelchange = null;
finish();
}
verifyInitialState();

View File

@ -0,0 +1,93 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 10000;
let battery = window.navigator.battery;
let fromStatus = "discharging";
let fromCharging = false;
function verifyInitialState() {
ok(battery, "battery");
ok(battery.charging, "battery.charging");
runEmulatorCmd("power display", function (result) {
is(result.pop(), "OK", "power display successful");
ok(result.indexOf("status: Charging") !== -1, "power status charging");
setUp();
});
}
function unexpectedEvent(event) {
ok(false, "Unexpected " + event.type + " event");
}
function setUp() {
battery.onchargingchange = function () {
battery.onchargingchange = unexpectedEvent;
toCharging();
};
battery.onlevelchange = unexpectedEvent;
log("Changing power status to " + fromStatus);
runEmulatorCmd("power status " + fromStatus);
}
function resetStatus(charging, nextFunction) {
log("Resetting power status to " + fromStatus);
if (charging !== fromCharging) {
battery.onchargingchange = function () {
battery.onchargingchange = unexpectedEvent;
nextFunction();
};
runEmulatorCmd("power status " + fromStatus);
}
else {
runEmulatorCmd("power status " + fromStatus, nextFunction);
}
}
function changeStatus(toStatus, toCharging, nextFunction) {
log("Changing power status to " + toStatus);
if (fromCharging !== toCharging) {
battery.onchargingchange = function (event) {
battery.onchargingchange = unexpectedEvent;
is(event.type, "chargingchange", "event type");
is(battery.charging, toCharging, "battery.charging");
resetStatus(toCharging, nextFunction);
};
runEmulatorCmd("power status " + toStatus);
}
else {
runEmulatorCmd("power status " + toStatus, function () {
is(battery.charging, toCharging, "battery.charging");
resetStatus(toCharging, nextFunction);
});
}
}
function toCharging() {
changeStatus("charging", true, toFull);
}
function toFull() {
changeStatus("full", true, toNotCharging);
}
function toNotCharging() {
changeStatus("not-charging", false, toUnknown);
}
function toUnknown() {
changeStatus("unknown", false, cleanUp);
}
function cleanUp() {
battery.onchargingchange = function () {
battery.onchargingchange = null;
finish();
};
battery.onlevelchange = null;
log("Resetting power status to charging");
runEmulatorCmd("power status charging");
}
verifyInitialState();

View File

@ -0,0 +1,87 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 10000;
let battery = window.navigator.battery;
let fromStatus = "full";
let fromCharging = true;
function verifyInitialState() {
ok(battery, "battery");
ok(battery.charging, "battery.charging");
runEmulatorCmd("power display", function (result) {
is(result.pop(), "OK", "power display successful");
ok(result.indexOf("status: Charging") !== -1, "power status charging");
setUp();
});
}
function unexpectedEvent(event) {
ok(false, "Unexpected " + event.type + " event");
}
function setUp() {
battery.onchargingchange = unexpectedEvent;
battery.onlevelchange = unexpectedEvent;
log("Changing power status to " + fromStatus);
runEmulatorCmd("power status " + fromStatus, toCharging);
}
function resetStatus(charging, nextFunction) {
log("Resetting power status to " + fromStatus);
if (charging !== fromCharging) {
battery.onchargingchange = function () {
battery.onchargingchange = unexpectedEvent;
nextFunction();
};
runEmulatorCmd("power status " + fromStatus);
}
else {
runEmulatorCmd("power status " + fromStatus, nextFunction);
}
}
function changeStatus(toStatus, toCharging, nextFunction) {
log("Changing power status to " + toStatus);
if (fromCharging !== toCharging) {
battery.onchargingchange = function (event) {
battery.onchargingchange = unexpectedEvent;
is(event.type, "chargingchange", "event type");
is(battery.charging, toCharging, "battery.charging");
resetStatus(toCharging, nextFunction);
};
runEmulatorCmd("power status " + toStatus);
}
else {
runEmulatorCmd("power status " + toStatus, function () {
is(battery.charging, toCharging, "battery.charging");
resetStatus(toCharging, nextFunction);
});
}
}
function toCharging() {
changeStatus("charging", true, toDischarging);
}
function toDischarging() {
changeStatus("discharging", false, toNotCharging);
}
function toNotCharging() {
changeStatus("not-charging", false, toUnknown);
}
function toUnknown() {
changeStatus("unknown", false, cleanUp);
}
function cleanUp() {
battery.onchargingchange = null;
battery.onlevelchange = null;
log("Resetting power status to charging");
runEmulatorCmd("power status charging", finish);
}
verifyInitialState();

View File

@ -0,0 +1,93 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 10000;
let battery = window.navigator.battery;
let fromStatus = "not-charging";
let fromCharging = false;
function verifyInitialState() {
ok(battery, "battery");
ok(battery.charging, "battery.charging");
runEmulatorCmd("power display", function (result) {
is(result.pop(), "OK", "power display successful");
ok(result.indexOf("status: Charging") !== -1, "power status charging");
setUp();
});
}
function unexpectedEvent(event) {
ok(false, "Unexpected " + event.type + " event");
}
function setUp() {
battery.onchargingchange = function () {
battery.onchargingchange = unexpectedEvent;
toCharging();
};
battery.onlevelchange = unexpectedEvent;
log("Changing power status to " + fromStatus);
runEmulatorCmd("power status " + fromStatus);
}
function resetStatus(charging, nextFunction) {
log("Resetting power status to " + fromStatus);
if (charging !== fromCharging) {
battery.onchargingchange = function () {
battery.onchargingchange = unexpectedEvent;
nextFunction();
};
runEmulatorCmd("power status " + fromStatus);
}
else {
runEmulatorCmd("power status " + fromStatus, nextFunction);
}
}
function changeStatus(toStatus, toCharging, nextFunction) {
log("Changing power status to " + toStatus);
if (fromCharging !== toCharging) {
battery.onchargingchange = function (event) {
battery.onchargingchange = unexpectedEvent;
is(event.type, "chargingchange", "event type");
is(battery.charging, toCharging, "battery.charging");
resetStatus(toCharging, nextFunction);
};
runEmulatorCmd("power status " + toStatus);
}
else {
runEmulatorCmd("power status " + toStatus, function () {
is(battery.charging, toCharging, "battery.charging");
resetStatus(toCharging, nextFunction);
});
}
}
function toCharging() {
changeStatus("charging", true, toDischarging);
}
function toDischarging() {
changeStatus("discharging", false, toFull);
}
function toFull() {
changeStatus("full", true, toUnknown);
}
function toUnknown() {
changeStatus("unknown", false, cleanUp);
}
function cleanUp() {
battery.onchargingchange = function () {
battery.onchargingchange = null;
finish();
};
battery.onlevelchange = null;
log("Resetting power status to charging");
runEmulatorCmd("power status charging");
}
verifyInitialState();

View File

@ -0,0 +1,93 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 10000;
let battery = window.navigator.battery;
let fromStatus = "unknown";
let fromCharging = false;
function verifyInitialState() {
ok(battery, "battery");
ok(battery.charging, "battery.charging");
runEmulatorCmd("power display", function (result) {
is(result.pop(), "OK", "power display successful");
ok(result.indexOf("status: Charging") !== -1, "power status charging");
setUp();
});
}
function unexpectedEvent(event) {
ok(false, "Unexpected " + event.type + " event");
}
function setUp() {
battery.onchargingchange = function () {
battery.onchargingchange = unexpectedEvent;
toCharging();
};
battery.onlevelchange = unexpectedEvent;
log("Changing power status to " + fromStatus);
runEmulatorCmd("power status " + fromStatus);
}
function resetStatus(charging, nextFunction) {
log("Resetting power status to " + fromStatus);
if (charging !== fromCharging) {
battery.onchargingchange = function () {
battery.onchargingchange = unexpectedEvent;
nextFunction();
};
runEmulatorCmd("power status " + fromStatus);
}
else {
runEmulatorCmd("power status " + fromStatus, nextFunction);
}
}
function changeStatus(toStatus, toCharging, nextFunction) {
log("Changing power status to " + toStatus);
if (fromCharging !== toCharging) {
battery.onchargingchange = function (event) {
battery.onchargingchange = unexpectedEvent;
is(event.type, "chargingchange", "event type");
is(battery.charging, toCharging, "battery.charging");
resetStatus(toCharging, nextFunction);
};
runEmulatorCmd("power status " + toStatus);
}
else {
runEmulatorCmd("power status " + toStatus, function () {
is(battery.charging, toCharging, "battery.charging");
resetStatus(toCharging, nextFunction);
});
}
}
function toCharging() {
changeStatus("charging", true, toDischarging);
}
function toDischarging() {
changeStatus("discharging", false, toFull);
}
function toFull() {
changeStatus("full", true, toNotCharging);
}
function toNotCharging() {
changeStatus("not-charging", false, cleanUp);
}
function cleanUp() {
battery.onchargingchange = function () {
battery.onchargingchange = null;
finish();
};
battery.onlevelchange = null;
log("Resetting power status to charging");
runEmulatorCmd("power status charging");
}
verifyInitialState();

View File

@ -1,2 +1,8 @@
[test_battery_basics.html] [test_battery_basics.html]
skip-if = (buildapp == 'b2g' && (toolkit != 'gonk' || debug)) skip-if = (buildapp == 'b2g' && (toolkit != 'gonk' || debug))
[test_battery_charging.html]
skip-if = (buildapp == 'b2g' && (toolkit != 'gonk' || debug))
[test_battery_discharging.html]
skip-if = (buildapp == 'b2g' && (toolkit != 'gonk' || debug))
[test_deprecated_battery_basics.html]
skip-if = (buildapp == 'b2g' && (toolkit != 'gonk' || debug))

View File

@ -12,20 +12,23 @@
<pre id="test"> <pre id="test">
<script type="application/javascript"> <script type="application/javascript">
SimpleTest.waitForExplicitFinish();
/** Test for Battery API **/ /** Test for Battery API **/
ok("getBattery" in navigator, "navigator.getBattery should exist");
ok('battery' in navigator, "navigator.battery should exist"); navigator.getBattery().then(function (battery) {
ok(battery.level >= 0.0 && battery.level <= 1.0, "Battery level " + battery.level + " should be in the range [0.0, 1.0]");
var battery = navigator.battery; SpecialPowers.pushPrefEnv({"set": [["dom.battery.test.default", true]]}, function () {
ok(battery.level >= 0.0 && battery.level <= 1.0, "Battery level " + battery.level + " should be in the range [0.0, 1.0]"); ok(battery.charging, "Battery should be charging by default");
is(battery.chargingTime, 0, "Battery chargingTime " + battery.chargingTime + " should be zero by default");
is(battery.dischargingTime, Infinity, "Battery dischargingTime should be Infinity by default");
is(battery.level, 1.0, "Battery level " + battery.level + " should be 1.0 by default");
if (battery.charging) { SimpleTest.finish();
ok(battery.chargingTime >= 0, "Battery chargingTime " + battery.chargingTime + " should be nonnegative when charging"); });
is(battery.dischargingTime, Infinity, "Battery dischargingTime should be Infinity when charging"); });
} else {
is(battery.chargingTime, Infinity, "Battery chargingTime should be Infinity when discharging");
ok(battery.dischargingTime > 0, "Battery dischargingTime " + battery.dischargingTime + " should be positive when discharging");
}
</script> </script>
</pre> </pre>

View File

@ -0,0 +1,33 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for Battery API</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
/** Test for Battery API **/
navigator.getBattery().then(function (battery) {
ok(battery.level >= 0.0 && battery.level <= 1.0, "Battery level " + battery.level + " should be in the range [0.0, 1.0]");
SpecialPowers.pushPrefEnv({"set": [["dom.battery.test.charging", true]]}, function () {
is(battery.charging, true, "Battery should be charging");
ok(battery.chargingTime >= 0, "Battery chargingTime " + battery.chargingTime + " should be nonnegative when charging");
is(battery.dischargingTime, Infinity, "Battery dischargingTime should be Infinity when charging");
SimpleTest.finish();
});
});
</script>
</pre>
</body>
</html>

View File

@ -0,0 +1,33 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for Battery API</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
/** Test for Battery API **/
navigator.getBattery().then(function (battery) {
ok(battery.level >= 0.0 && battery.level <= 1.0, "Battery level " + battery.level + " should be in the range [0.0, 1.0]");
SpecialPowers.pushPrefEnv({"set": [["dom.battery.test.discharging", true]]}, function () {
is(battery.charging, false, "Battery should be discharging");
is(battery.chargingTime, Infinity, "Battery chargingTime should be Infinity when discharging");
ok(battery.dischargingTime > 0, "Battery dischargingTime " + battery.dischargingTime + " should be positive when discharging");
SimpleTest.finish();
});
});
</script>
</pre>
</body>
</html>

View File

@ -0,0 +1,32 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for Battery API</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Battery API **/
ok("battery" in navigator, "navigator.battery should exist");
var battery = navigator.battery;
ok(battery.level >= 0.0 && battery.level <= 1.0, "Battery level " + battery.level + " should be in the range [0.0, 1.0]");
if (battery.charging) {
ok(battery.chargingTime >= 0, "Battery chargingTime " + battery.chargingTime + " should be nonnegative when charging");
is(battery.dischargingTime, Infinity, "Battery dischargingTime should be Infinity when charging");
} else {
is(battery.chargingTime, Infinity, "Battery chargingTime should be Infinity when discharging");
ok(battery.dischargingTime > 0, "Battery dischargingTime " + battery.dischargingTime + " should be positive when discharging");
}
</script>
</pre>
</body>
</html>

View File

@ -24,7 +24,8 @@ public:
#define BT_DECL_HFP_MGR_BASE \ #define BT_DECL_HFP_MGR_BASE \
BT_DECL_PROFILE_MGR_BASE \ BT_DECL_PROFILE_MGR_BASE \
virtual bool IsScoConnected() override; virtual bool IsScoConnected() override; \
virtual bool IsNrecEnabled() override;
END_BLUETOOTH_NAMESPACE END_BLUETOOTH_NAMESPACE

View File

@ -105,6 +105,12 @@ BluetoothHfpManager::IsScoConnected()
return false; return false;
} }
bool
BluetoothHfpManager::IsNrecEnabled()
{
return false;
}
/** /**
* Non-inherited functions * Non-inherited functions
*/ */

View File

@ -92,7 +92,6 @@ public:
bool ConnectSco(); bool ConnectSco();
bool DisconnectSco(); bool DisconnectSco();
bool IsNrecEnabled();
/** /**
* @param aSend A boolean indicates whether we need to notify headset or not * @param aSend A boolean indicates whether we need to notify headset or not

View File

@ -103,7 +103,6 @@ public:
*/ */
bool ConnectSco(BluetoothReplyRunnable* aRunnable = nullptr); bool ConnectSco(BluetoothReplyRunnable* aRunnable = nullptr);
bool DisconnectSco(); bool DisconnectSco();
bool IsNrecEnabled();
bool ListenSco(); bool ListenSco();
#ifdef MOZ_B2G_RIL #ifdef MOZ_B2G_RIL

View File

@ -833,16 +833,14 @@ BrowserElementParent.prototype = {
catch(e) { catch(e) {
debug('Malformed referrer -- ' + e); debug('Malformed referrer -- ' + e);
} }
// TODO Bug 1165466: use originAttributes from nsILoadContext.
let attrs = {appId: this._frameLoader.loadContext.appId,
inBrowser: this._frameLoader.loadContext.isInBrowserElement};
// This simply returns null if there is no principal available // This simply returns null if there is no principal available
// for the requested uri. This is an acceptable fallback when // for the requested uri. This is an acceptable fallback when
// calling newChannelFromURI2. // calling newChannelFromURI2.
principal = principal =
Services.scriptSecurityManager.createCodebasePrincipal( Services.scriptSecurityManager.getAppCodebasePrincipal(
referrer, attrs); referrer,
this._frameLoader.loadContext.appId,
this._frameLoader.loadContext.isInBrowserElement);
} }
debug('Using principal? ' + !!principal); debug('Using principal? ' + !!principal);

View File

@ -158,17 +158,15 @@ function testAuthJarNoInterfere(e) {
// Set a bunch of auth data that should not conflict with the correct auth data already // Set a bunch of auth data that should not conflict with the correct auth data already
// stored in the cache. // stored in the cache.
var attrs = {appId: 1}; var principal = secMan.getAppCodebasePrincipal(uri, 1, false);
var principal = secMan.createCodebasePrincipal(uri, attrs);
authMgr.setAuthIdentity('http', 'test', -1, 'basic', 'http_realm', authMgr.setAuthIdentity('http', 'test', -1, 'basic', 'http_realm',
'tests/dom/browser-element/mochitest/file_http_401_response.sjs', 'tests/dom/browser-element/mochitest/file_http_401_response.sjs',
'', 'httpuser', 'wrongpass', false, principal); '', 'httpuser', 'wrongpass', false, principal);
attrs = {appId: 1, inBrowser: true}; principal = secMan.getAppCodebasePrincipal(uri, 1, true);
principal = secMan.createCodebasePrincipal(uri, attrs);
authMgr.setAuthIdentity('http', 'test', -1, 'basic', 'http_realm', authMgr.setAuthIdentity('http', 'test', -1, 'basic', 'http_realm',
'tests/dom/browser-element/mochitest/file_http_401_response.sjs', 'tests/dom/browser-element/mochitest/file_http_401_response.sjs',
'', 'httpuser', 'wrongpass', false, principal); '', 'httpuser', 'wrongpass', false, principal);
principal = secMan.createCodebasePrincipal(uri, {}); principal = secMan.getAppCodebasePrincipal(uri, secMan.NO_APP_ID, false);
authMgr.setAuthIdentity('http', 'test', -1, 'basic', 'http_realm', authMgr.setAuthIdentity('http', 'test', -1, 'basic', 'http_realm',
'tests/dom/browser-element/mochitest/file_http_401_response.sjs', 'tests/dom/browser-element/mochitest/file_http_401_response.sjs',
'', 'httpuser', 'wrongpass', false, principal); '', 'httpuser', 'wrongpass', false, principal);
@ -198,7 +196,7 @@ function testAuthJarInterfere(e) {
var uri = ioService.newURI("http://test/tests/dom/browser-element/mochitest/file_http_401_response.sjs", null, null); var uri = ioService.newURI("http://test/tests/dom/browser-element/mochitest/file_http_401_response.sjs", null, null);
// Set some auth data that should overwrite the successful stored details. // Set some auth data that should overwrite the successful stored details.
var principal = secMan.createCodebasePrincipal(uri, {inBrowser: true}); var principal = secMan.getAppCodebasePrincipal(uri, secMan.NO_APP_ID, true);
authMgr.setAuthIdentity('http', 'test', -1, 'basic', 'http_realm', authMgr.setAuthIdentity('http', 'test', -1, 'basic', 'http_realm',
'tests/dom/browser-element/mochitest/file_http_401_response.sjs', 'tests/dom/browser-element/mochitest/file_http_401_response.sjs',
'', 'httpuser', 'wrongpass', false, principal); '', 'httpuser', 'wrongpass', false, principal);

View File

@ -20,7 +20,7 @@
// attach to a different origin's CacheStorage // attach to a different origin's CacheStorage
var url = 'http://example.com/'; var url = 'http://example.com/';
var uri = Services.io.newURI(url, null, null); var uri = Services.io.newURI(url, null, null);
var principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {}); var principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(uri);
var storage = new CacheStorage('content', principal); var storage = new CacheStorage('content', principal);
// verify we can use the other origin's CacheStorage as normal // verify we can use the other origin's CacheStorage as normal

View File

@ -14,7 +14,6 @@
#include "mozilla/dom/DataStoreImplBinding.h" #include "mozilla/dom/DataStoreImplBinding.h"
#include "nsIDataStore.h" #include "nsIDataStore.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "mozilla/Services.h" #include "mozilla/Services.h"
#include "mozilla/StaticPtr.h" #include "mozilla/StaticPtr.h"
@ -57,9 +56,6 @@
return NS_ERROR_FAILURE; \ return NS_ERROR_FAILURE; \
} }
using mozilla::BasePrincipal;
using mozilla::OriginAttributes;
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
@ -217,10 +213,17 @@ ResetPermission(uint32_t aAppId, const nsAString& aOriginURL,
return rv; return rv;
} }
OriginAttributes attrs(aAppId, false); nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
nsCOMPtr<nsIPrincipal> principal = if (!ssm) {
BasePrincipal::CreateCodebasePrincipal(uri, attrs); return NS_ERROR_FAILURE;
NS_ENSURE_TRUE(principal, NS_ERROR_FAILURE); }
nsCOMPtr<nsIPrincipal> principal;
rv = ssm->GetAppCodebasePrincipal(uri, aAppId, false,
getter_AddRefs(principal));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
nsCOMPtr<nsIPermissionManager> pm = nsCOMPtr<nsIPermissionManager> pm =
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID); do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);

View File

@ -263,37 +263,50 @@ FetchDriver::BasicFetch()
nsAutoCString method; nsAutoCString method;
mRequest->GetMethod(method); mRequest->GetMethod(method);
if (method.LowerCaseEqualsASCII("get")) { if (method.LowerCaseEqualsASCII("get")) {
// Use nsDataHandler directly so that we can extract the content type. nsresult rv;
// XXX(nsm): Is there a way to acquire the charset without such tight nsCOMPtr<nsIProtocolHandler> dataHandler =
// coupling with the DataHandler? nsIProtocolHandler does not provide do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "data", &rv);
// anything similar.
nsAutoCString contentType, contentCharset, dataBuffer, hashRef;
bool isBase64;
rv = nsDataHandler::ParseURI(url,
contentType,
contentCharset,
isBase64,
dataBuffer,
hashRef);
if (NS_SUCCEEDED(rv)) {
ErrorResult result;
nsRefPtr<InternalResponse> response = new InternalResponse(200, NS_LITERAL_CSTRING("OK"));
if (!contentCharset.IsEmpty()) {
contentType.Append(";charset=");
contentType.Append(contentCharset);
}
response->Headers()->Append(NS_LITERAL_CSTRING("Content-Type"), contentType, result); if (NS_WARN_IF(NS_FAILED(rv))) {
if (!result.Failed()) { return FailWithNetworkError();
nsCOMPtr<nsIInputStream> stream;
rv = NS_NewCStringInputStream(getter_AddRefs(stream), dataBuffer);
if (NS_SUCCEEDED(rv)) {
response->SetBody(stream);
BeginResponse(response);
return SucceedWithResponse();
}
}
} }
nsCOMPtr<nsIChannel> channel;
rv = dataHandler->NewChannel(uri, getter_AddRefs(channel));
if (NS_WARN_IF(NS_FAILED(rv))) {
return FailWithNetworkError();
}
nsCOMPtr<nsIInputStream> stream;
rv = channel->Open(getter_AddRefs(stream));
if (NS_WARN_IF(NS_FAILED(rv))) {
return FailWithNetworkError();
}
// nsDataChannel will parse the data URI when it is Open()ed and set the
// correct content type and charset.
nsAutoCString contentType;
if (NS_SUCCEEDED(channel->GetContentType(contentType))) {
nsAutoCString charset;
if (NS_SUCCEEDED(channel->GetContentCharset(charset)) && !charset.IsEmpty()) {
contentType.AppendLiteral(";charset=");
contentType.Append(charset);
}
} else {
NS_WARNING("Could not get content type from data channel");
}
nsRefPtr<InternalResponse> response = new InternalResponse(200, NS_LITERAL_CSTRING("OK"));
ErrorResult result;
response->Headers()->Append(NS_LITERAL_CSTRING("Content-Type"), contentType, result);
if (NS_WARN_IF(result.Failed())) {
FailWithNetworkError();
return result.StealNSResult();
}
response->SetBody(stream);
BeginResponse(response);
return SucceedWithResponse();
} }
return FailWithNetworkError(); return FailWithNetworkError();

View File

@ -18519,6 +18519,12 @@ FactoryOp::CheckAtLeastOneAppHasPermission(ContentParent* aContentParent,
return false; return false;
} }
nsCOMPtr<nsIScriptSecurityManager> secMan =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
if (NS_WARN_IF(!secMan)) {
return false;
}
nsCOMPtr<nsIPermissionManager> permMan = nsCOMPtr<nsIPermissionManager> permMan =
mozilla::services::GetPermissionManager(); mozilla::services::GetPermissionManager();
if (NS_WARN_IF(!permMan)) { if (NS_WARN_IF(!permMan)) {
@ -18542,9 +18548,24 @@ FactoryOp::CheckAtLeastOneAppHasPermission(ContentParent* aContentParent,
return false; return false;
} }
nsString origin;
rv = app->GetOrigin(origin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
nsCOMPtr<nsIURI> uri;
rv = NS_NewURI(getter_AddRefs(uri), origin, nullptr, nullptr, ioService);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
nsCOMPtr<nsIPrincipal> principal; nsCOMPtr<nsIPrincipal> principal;
app->GetPrincipal(getter_AddRefs(principal)); rv = secMan->GetAppCodebasePrincipal(uri, appId, false,
NS_ENSURE_TRUE(principal, false); getter_AddRefs(principal));
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
uint32_t permission; uint32_t permission;
rv = permMan->TestExactPermissionFromPrincipal(principal, rv = permMan->TestExactPermissionFromPrincipal(principal,

View File

@ -116,9 +116,9 @@ function setPermission(url, permission)
let uri = Components.classes["@mozilla.org/network/io-service;1"] let uri = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService) .getService(Components.interfaces.nsIIOService)
.newURI(url, null, null); .newURI(url, null, null);
let ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"] let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager); .getService(Ci.nsIScriptSecurityManager)
let principal = ssm.createCodebasePrincipal(uri, {}); .getNoAppCodebasePrincipal(uri);
Components.classes["@mozilla.org/permissionmanager;1"] Components.classes["@mozilla.org/permissionmanager;1"]
.getService(nsIPermissionManager) .getService(nsIPermissionManager)
@ -131,9 +131,9 @@ function removePermission(url, permission)
let uri = Components.classes["@mozilla.org/network/io-service;1"] let uri = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService) .getService(Components.interfaces.nsIIOService)
.newURI(url, null, null); .newURI(url, null, null);
let ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"] let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager); .getService(Ci.nsIScriptSecurityManager)
let principal = ssm.createCodebasePrincipal(uri, {}); .getNoAppCodebasePrincipal(uri);
Components.classes["@mozilla.org/permissionmanager;1"] Components.classes["@mozilla.org/permissionmanager;1"]
.getService(Components.interfaces.nsIPermissionManager) .getService(Components.interfaces.nsIPermissionManager)
@ -145,9 +145,9 @@ function getPermission(url, permission)
let uri = Components.classes["@mozilla.org/network/io-service;1"] let uri = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService) .getService(Components.interfaces.nsIIOService)
.newURI(url, null, null); .newURI(url, null, null);
let ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"] let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager); .getService(Ci.nsIScriptSecurityManager)
let principal = ssm.createCodebasePrincipal(uri, {}); .getNoAppCodebasePrincipal(uri);
return Components.classes["@mozilla.org/permissionmanager;1"] return Components.classes["@mozilla.org/permissionmanager;1"]
.getService(Components.interfaces.nsIPermissionManager) .getService(Components.interfaces.nsIPermissionManager)

View File

@ -90,10 +90,13 @@ function testSteps()
let request; let request;
if ("url" in params) { if ("url" in params) {
let uri = ios.newURI(params.url, null, null); let uri = ios.newURI(params.url, null, null);
let principal = let principal;
ssm.createCodebasePrincipal(uri, if ("appId" in params) {
{appId: params.appId || ssm.NO_APPID, principal = ssm.getAppCodebasePrincipal(uri, params.appId,
inBrowser: params.inMozBrowser}); params.inMozBrowser);
} else {
principal = ssm.getNoAppCodebasePrincipal(uri);
}
if ("dbVersion" in params) { if ("dbVersion" in params) {
request = indexedDB.openForPrincipal(principal, params.dbName, request = indexedDB.openForPrincipal(principal, params.dbName,
params.dbVersion); params.dbVersion);

View File

@ -10,9 +10,9 @@ function testSteps()
let uri = Cc["@mozilla.org/network/io-service;1"]. let uri = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService). getService(Ci.nsIIOService).
newURI("https://www.example.com", null, null); newURI("https://www.example.com", null, null);
let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"] let principal = Cc["@mozilla.org/scriptsecuritymanager;1"].
.getService(Ci.nsIScriptSecurityManager); getService(Ci.nsIScriptSecurityManager).
let principal = ssm.createCodebasePrincipal(uri, {}); getNoAppCodebasePrincipal(uri);
info("Setting permissions"); info("Setting permissions");

View File

@ -67,7 +67,7 @@ function testSteps()
let request; let request;
if ("url" in params) { if ("url" in params) {
let uri = ios.newURI(params.url, null, null); let uri = ios.newURI(params.url, null, null);
let principal = ssm.createCodebasePrincipal(uri, {}); let principal = ssm.getNoAppCodebasePrincipal(uri);
request = indexedDB.openForPrincipal(principal, params.dbName, request = indexedDB.openForPrincipal(principal, params.dbName,
params.dbOptions); params.dbOptions);
} else { } else {

View File

@ -48,9 +48,9 @@ function testSteps()
let uri = Components.classes["@mozilla.org/network/io-service;1"] let uri = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService) .getService(Components.interfaces.nsIIOService)
.newURI("http://appdata.example.com", null, null); .newURI("http://appdata.example.com", null, null);
let ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"] let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
.getService(Components.interfaces.nsIScriptSecurityManager); .getService(Components.interfaces.nsIScriptSecurityManager)
let principal = ssm.createCodebasePrincipal(uri, {}); .getNoAppCodebasePrincipal(uri);
request = indexedDB.openForPrincipal(principal, name, 1); request = indexedDB.openForPrincipal(principal, name, 1);
request.onerror = errorHandler; request.onerror = errorHandler;

View File

@ -34,9 +34,9 @@ function testSteps()
let uri = Cc["@mozilla.org/network/io-service;1"] let uri = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService) .getService(Ci.nsIIOService)
.newURI(url, null, null); .newURI(url, null, null);
let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"] return Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager); .getService(Ci.nsIScriptSecurityManager)
return ssm.createCodebasePrincipal(uri, {}); .getNoAppCodebasePrincipal(uri);
} }
for (let temporary of [true, false]) { for (let temporary of [true, false]) {

View File

@ -12,6 +12,7 @@
#include "mozilla/hal_sandbox/PHalParent.h" #include "mozilla/hal_sandbox/PHalParent.h"
#include "nsIAppsService.h" #include "nsIAppsService.h"
#include "nsIPrincipal.h" #include "nsIPrincipal.h"
#include "nsIScriptSecurityManager.h"
#include "nsPrintfCString.h" #include "nsPrintfCString.h"
#include "nsIURI.h" #include "nsIURI.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
@ -231,10 +232,21 @@ GetAppPrincipal(uint32_t aAppId)
nsresult rv = appsService->GetAppByLocalId(aAppId, getter_AddRefs(app)); nsresult rv = appsService->GetAppByLocalId(aAppId, getter_AddRefs(app));
NS_ENSURE_SUCCESS(rv, nullptr); NS_ENSURE_SUCCESS(rv, nullptr);
nsCOMPtr<nsIPrincipal> principal; nsString origin;
app->GetPrincipal(getter_AddRefs(principal)); rv = app->GetOrigin(origin);
NS_ENSURE_SUCCESS(rv, nullptr);
return principal.forget(); nsCOMPtr<nsIURI> uri;
NS_NewURI(getter_AddRefs(uri), origin);
nsCOMPtr<nsIScriptSecurityManager> secMan =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
nsCOMPtr<nsIPrincipal> appPrincipal;
rv = secMan->GetAppCodebasePrincipal(uri, aAppId, false,
getter_AddRefs(appPrincipal));
NS_ENSURE_SUCCESS(rv, nullptr);
return appPrincipal.forget();
} }
uint32_t uint32_t

View File

@ -1562,15 +1562,23 @@ TabChild::MaybeRequestPreinitCamera()
return; return;
} }
nsCOMPtr<mozIApplication> app; nsString manifestUrl = EmptyString();
nsresult rv = appsService->GetAppByLocalId(OwnAppId(), getter_AddRefs(app)); appsService->GetManifestURLByLocalId(OwnAppId(), manifestUrl);
nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
if (NS_WARN_IF(!secMan)) {
return;
}
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), manifestUrl);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return; return;
} }
nsCOMPtr<nsIPrincipal> principal; nsCOMPtr<nsIPrincipal> principal;
app->GetPrincipal(getter_AddRefs(principal)); rv = secMan->GetAppCodebasePrincipal(uri, OwnAppId(), false,
if (NS_WARN_IF(!principal)) { getter_AddRefs(principal));
if (NS_WARN_IF(NS_FAILED(rv))) {
return; return;
} }

View File

@ -226,6 +226,7 @@ static const char* const gOmxTypes[] = {
"audio/3gpp", "audio/3gpp",
"audio/flac", "audio/flac",
"video/mp4", "video/mp4",
"video/x-m4v",
"video/3gpp", "video/3gpp",
"video/3gpp2", "video/3gpp2",
"video/quicktime", "video/quicktime",
@ -332,7 +333,7 @@ IsAndroidMediaType(const nsACString& aType)
} }
static const char* supportedTypes[] = { static const char* supportedTypes[] = {
"audio/mpeg", "audio/mp4", "video/mp4", nullptr "audio/mpeg", "audio/mp4", "video/mp4", "video/x-m4v", nullptr
}; };
return CodecListContains(supportedTypes, aType); return CodecListContains(supportedTypes, aType);
} }

View File

@ -147,8 +147,7 @@ MP4Decoder::CanHandleMediaType(const nsACString& aType,
return Preferences::GetBool("media.fragmented-mp4.gonk.enabled", false); return Preferences::GetBool("media.fragmented-mp4.gonk.enabled", false);
} }
#endif #endif
if ((!aType.EqualsASCII("video/mp4") && !aType.EqualsASCII("video/x-m4v")) ||
if (!aType.EqualsASCII("video/mp4") ||
!MP4Decoder::CanCreateH264Decoder()) { !MP4Decoder::CanCreateH264Decoder()) {
return false; return false;
} }

View File

@ -40,8 +40,9 @@ void GStreamerFormatHelper::Shutdown() {
gInstance = nullptr; gInstance = nullptr;
} }
static char const *const sContainers[6][2] = { static char const *const sContainers[][2] = {
{"video/mp4", "video/quicktime"}, {"video/mp4", "video/quicktime"},
{"video/x-m4v", "video/quicktime"},
{"video/quicktime", "video/quicktime"}, {"video/quicktime", "video/quicktime"},
{"audio/mp4", "audio/x-m4a"}, {"audio/mp4", "audio/x-m4a"},
{"audio/x-m4a", "audio/x-m4a"}, {"audio/x-m4a", "audio/x-m4a"},
@ -63,6 +64,7 @@ static char const *const sCodecs[9][2] = {
static char const * const sDefaultCodecCaps[][2] = { static char const * const sDefaultCodecCaps[][2] = {
{"video/mp4", "video/x-h264"}, {"video/mp4", "video/x-h264"},
{"video/x-m4v", "video/x-h264"},
{"video/quicktime", "video/x-h264"}, {"video/quicktime", "video/x-h264"},
{"audio/mp4", "audio/mpeg, mpegversion=(int)4"}, {"audio/mp4", "audio/mpeg, mpegversion=(int)4"},
{"audio/x-m4a", "audio/mpeg, mpegversion=(int)4"}, {"audio/x-m4a", "audio/mpeg, mpegversion=(int)4"},

View File

@ -26,11 +26,13 @@ function check_mp4(v, enabled) {
} }
check("video/mp4", "maybe"); check("video/mp4", "maybe");
check("video/x-m4v", "maybe");
check("audio/mp4", "maybe"); check("audio/mp4", "maybe");
check("audio/x-m4a", "maybe"); check("audio/x-m4a", "maybe");
// Not the MIME type that other browsers respond to, so we won't either. // Not the MIME type that other browsers respond to, so we won't either.
check("audio/m4a", ""); check("audio/m4a", "");
check("video/m4v", "");
// Only Safari responds affirmatively to "audio/aac", // Only Safari responds affirmatively to "audio/aac",
// so we'll let x-m4a cover aac support. // so we'll let x-m4a cover aac support.
check("audio/aac", ""); check("audio/aac", "");

View File

@ -236,9 +236,8 @@ let PaymentManager = {
if (systemAppId != Ci.nsIScriptSecurityManager.NO_APP_ID) { if (systemAppId != Ci.nsIScriptSecurityManager.NO_APP_ID) {
this.LOG("Granting firefox-accounts permission to " + provider.uri); this.LOG("Granting firefox-accounts permission to " + provider.uri);
let uri = Services.io.newURI(provider.uri, null, null); let uri = Services.io.newURI(provider.uri, null, null);
let attrs = {appId: systemAppId, inBrowser: true}; let principal = Services.scriptSecurityManager
let principal = .getAppCodebasePrincipal(uri, systemAppId, true);
Services.scriptSecurityManager.createCodebasePrincipal(uri, attrs);
Services.perms.addFromPrincipal(principal, "firefox-accounts", Services.perms.addFromPrincipal(principal, "firefox-accounts",
Ci.nsIPermissionManager.ALLOW_ACTION, Ci.nsIPermissionManager.ALLOW_ACTION,

View File

@ -35,14 +35,10 @@ XPCOMUtils.defineLazyServiceGetter(this,
PermissionSettings.prototype = { PermissionSettings.prototype = {
get: function get(aPermName, aManifestURL, aOrigin, aBrowserFlag) { get: function get(aPermName, aManifestURL, aOrigin, aBrowserFlag) {
// TODO: Bug 1196644 - Add signPKg parameter into PermissionSettings.js
debug("Get called with: " + aPermName + ", " + aManifestURL + ", " + aOrigin + ", " + aBrowserFlag); debug("Get called with: " + aPermName + ", " + aManifestURL + ", " + aOrigin + ", " + aBrowserFlag);
let uri = Services.io.newURI(aOrigin, null, null); let uri = Services.io.newURI(aOrigin, null, null);
let appID = appsService.getAppLocalIdByManifestURL(aManifestURL); let appID = appsService.getAppLocalIdByManifestURL(aManifestURL);
let principal = let principal = Services.scriptSecurityManager.getAppCodebasePrincipal(uri, appID, aBrowserFlag);
Services.scriptSecurityManager.createCodebasePrincipal(uri,
{appId: appID,
inBrowser: aBrowserFlag});
let result = Services.perms.testExactPermanentPermission(principal, aPermName); let result = Services.perms.testExactPermanentPermission(principal, aPermName);
switch (result) switch (result)
@ -63,12 +59,11 @@ PermissionSettings.prototype = {
isExplicit: function isExplicit(aPermName, aManifestURL, aOrigin, isExplicit: function isExplicit(aPermName, aManifestURL, aOrigin,
aBrowserFlag) { aBrowserFlag) {
// TODO: Bug 1196644 - Add signPKg parameter into PermissionSettings.js
debug("isExplicit: " + aPermName + ", " + aManifestURL + ", " + aOrigin); debug("isExplicit: " + aPermName + ", " + aManifestURL + ", " + aOrigin);
let uri = Services.io.newURI(aOrigin, null, null); let uri = Services.io.newURI(aOrigin, null, null);
let app = appsService.getAppByManifestURL(aManifestURL); let app = appsService.getAppByManifestURL(aManifestURL);
let principal = Services.scriptSecurityManager let principal = Services.scriptSecurityManager
.createCodebasePrincipal(uri, {appId: app.localId, inBrowser: aBrowserFlag}); .getAppCodebasePrincipal(uri, app.localId, aBrowserFlag);
return isExplicitInPermissionsTable(aPermName, return isExplicitInPermissionsTable(aPermName,
principal.appStatus, principal.appStatus,
@ -104,13 +99,9 @@ PermissionSettings.prototype = {
}, },
remove: function remove(aPermName, aManifestURL, aOrigin) { remove: function remove(aPermName, aManifestURL, aOrigin) {
// TODO: Bug 1196644 - Add signPKg parameter into PermissionSettings.js
let uri = Services.io.newURI(aOrigin, null, null); let uri = Services.io.newURI(aOrigin, null, null);
let appID = appsService.getAppLocalIdByManifestURL(aManifestURL); let appID = appsService.getAppLocalIdByManifestURL(aManifestURL);
let principal = let principal = Services.scriptSecurityManager.getAppCodebasePrincipal(uri, appID, true);
Services.scriptSecurityManager.createCodebasePrincipal(uri,
{appId: appID,
inBrowser: true});
if (principal.appStatus !== Ci.nsIPrincipal.APP_STATUS_NOT_INSTALLED) { if (principal.appStatus !== Ci.nsIPrincipal.APP_STATUS_NOT_INSTALLED) {
let errorMsg = "PermissionSettings.js: '" + aOrigin + "'" + let errorMsg = "PermissionSettings.js: '" + aOrigin + "'" +

View File

@ -67,13 +67,9 @@ this.PermissionSettingsModule = {
_internalAddPermission: function _internalAddPermission(aData, aAllowAllChanges, aCallbacks) { _internalAddPermission: function _internalAddPermission(aData, aAllowAllChanges, aCallbacks) {
// TODO: Bug 1196644 - Add signPKg parameter into PermissionSettings.jsm
let uri = Services.io.newURI(aData.origin, null, null); let uri = Services.io.newURI(aData.origin, null, null);
let app = appsService.getAppByManifestURL(aData.manifestURL); let app = appsService.getAppByManifestURL(aData.manifestURL);
let principal = let principal = Services.scriptSecurityManager.getAppCodebasePrincipal(uri, app.localId, aData.browserFlag);
Services.scriptSecurityManager.createCodebasePrincipal(uri,
{appId: app.localId,
inBrowser: aData.browserFlag});
let action; let action;
switch (aData.value) switch (aData.value)
@ -107,14 +103,10 @@ this.PermissionSettingsModule = {
}, },
getPermission: function getPermission(aPermName, aManifestURL, aOrigin, aBrowserFlag) { getPermission: function getPermission(aPermName, aManifestURL, aOrigin, aBrowserFlag) {
// TODO: Bug 1196644 - Add signPKg parameter into PermissionSettings.jsm
debug("getPermission: " + aPermName + ", " + aManifestURL + ", " + aOrigin); debug("getPermission: " + aPermName + ", " + aManifestURL + ", " + aOrigin);
let uri = Services.io.newURI(aOrigin, null, null); let uri = Services.io.newURI(aOrigin, null, null);
let appID = appsService.getAppLocalIdByManifestURL(aManifestURL); let appID = appsService.getAppLocalIdByManifestURL(aManifestURL);
let principal = let principal = Services.scriptSecurityManager.getAppCodebasePrincipal(uri, appID, aBrowserFlag);
Services.scriptSecurityManager.createCodebasePrincipal(uri,
{appId: appID,
inBrowser: aBrowserFlag});
let result = Services.perms.testExactPermissionFromPrincipal(principal, aPermName); let result = Services.perms.testExactPermissionFromPrincipal(principal, aPermName);
switch (result) switch (result)

View File

@ -0,0 +1,6 @@
[DEFAULT]
support-files =
plugin_test.html
[browser_bug1163570.js]
skip-if = (!e10s || os != "win")

View File

@ -0,0 +1,140 @@
let gTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
// Returns the chrome side nsIPluginTag for this plugin
function getTestPlugin(aName) {
let pluginName = aName || "Test Plug-in";
let ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
let tags = ph.getPluginTags();
// Find the test plugin
for (let i = 0; i < tags.length; i++) {
if (tags[i].name == pluginName)
return tags[i];
}
ok(false, "Unable to find plugin");
return null;
}
// Set the test plugin state, disabling features like click-to-play
function setTestPluginEnabledState(newEnabledState, pluginName) {
let name = pluginName || "Test Plug-in";
let plugin = getTestPlugin(name);
plugin.enabledState = newEnabledState;
}
// simple tab load helper, pilfered from browser plugin tests
function promiseTabLoad(tab, url, eventType="load") {
return new Promise((resolve, reject) => {
function handle(event) {
if (event.originalTarget != tab.linkedBrowser.contentDocument ||
event.target.location.href == "about:blank" ||
(url && event.target.location.href != url)) {
return;
}
clearTimeout(timeout);
tab.linkedBrowser.removeEventListener(eventType, handle, true);
resolve(event);
}
let timeout = setTimeout(() => {
tab.linkedBrowser.removeEventListener(eventType, handle, true);
reject(new Error("Timed out while waiting for a '" + eventType + "'' event"));
}, 30000);
tab.linkedBrowser.addEventListener(eventType, handle, true, true);
if (url) {
tab.linkedBrowser.loadURI(url);
}
});
}
// dom event listener helper
function promiseWaitForEvent(object, eventName, capturing = false, chrome = false) {
return new Promise((resolve) => {
function listener(event) {
object.removeEventListener(eventName, listener, capturing, chrome);
resolve(event);
}
object.addEventListener(eventName, listener, capturing, chrome);
});
}
add_task(function* () {
registerCleanupFunction(function () {
Services.prefs.clearUserPref("browser.uiCustomization.disableAnimation");
window.focus();
});
});
add_task(function* () {
Services.prefs.setBoolPref("browser.uiCustomization.disableAnimation", true);
setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, "Test Plug-in");
let pluginTab = gBrowser.selectedTab = gBrowser.addTab();
let customizeTab = gBrowser.addTab();
yield promiseTabLoad(pluginTab, gTestRoot + "plugin_test.html");
yield promiseTabLoad(customizeTab, "about:customizing");
let result = yield ContentTask.spawn(gBrowser.selectedBrowser, null, function*() {
let doc = content.document;
let plugin = doc.getElementById("testplugin");
return !!plugin;
});
is(result, true, "plugin is loaded");
let cpromise = promiseWaitForEvent(window.gNavToolbox, "customizationready");
let ppromise = promiseWaitForEvent(window, "MozAfterPaint");
gBrowser.selectedTab = customizeTab;
yield cpromise;
yield ppromise;
// We're going to switch tabs using actual mouse clicks, which helps
// reproduce this bug.
let tabStripContainer = document.getElementById("tabbrowser-tabs");
// diagnosis if front end layout changes
info("-> " + tabStripContainer.tagName); // tabs
info("-> " + tabStripContainer.firstChild.tagName); // tab
info("-> " + tabStripContainer.childNodes[0].label); // test harness tab
info("-> " + tabStripContainer.childNodes[1].label); // plugin tab
info("-> " + tabStripContainer.childNodes[2].label); // customize tab
for (let iteration = 0; iteration < 5; iteration++) {
cpromise = promiseWaitForEvent(window.gNavToolbox, "aftercustomization");
ppromise = promiseWaitForEvent(window, "MozAfterPaint");
EventUtils.synthesizeMouseAtCenter(tabStripContainer.childNodes[1], {}, window);
yield cpromise;
yield ppromise;
result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
let doc = content.document;
let plugin = doc.getElementById("testplugin");
return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible();
});
is(result, true, "plugin is visible");
cpromise = promiseWaitForEvent(window.gNavToolbox, "customizationready");
ppromise = promiseWaitForEvent(window, "MozAfterPaint");
EventUtils.synthesizeMouseAtCenter(tabStripContainer.childNodes[2], {}, window);
yield cpromise;
yield ppromise;
result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
let doc = content.document;
let plugin = doc.getElementById("testplugin");
return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible();
});
is(result, false, "plugin is hidden");
}
// wait for customize view to shutdown cleanly otherwise we get
// a ton of error spew on shutdown.
cpromise = promiseWaitForEvent(window.gNavToolbox, "aftercustomization");
gBrowser.removeTab(customizeTab);
yield cpromise;
gBrowser.removeTab(pluginTab);
});

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<embed id="testplugin" type="application/x-test" drawmode="solid" color="ff00ff00" wmode="window"
style="position:absolute; top:50px; left:50px; width:500px; height:250px">
</body>
</html>

View File

@ -11,4 +11,5 @@ XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3', 'cocoa', 'windows'): if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3', 'cocoa', 'windows'):
MOCHITEST_MANIFESTS += ['mochitest/mochitest.ini'] MOCHITEST_MANIFESTS += ['mochitest/mochitest.ini']
MOCHITEST_CHROME_MANIFESTS += ['mochitest/chrome.ini'] MOCHITEST_CHROME_MANIFESTS += ['mochitest/chrome.ini']
BROWSER_CHROME_MANIFESTS += ['mochitest/browser.ini']

View File

@ -171,6 +171,7 @@ static bool echoString(NPObject* npobj, const NPVariant* args, uint32_t argCount
static bool startAudioPlayback(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result); static bool startAudioPlayback(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool stopAudioPlayback(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result); static bool stopAudioPlayback(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool getAudioMuted(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result); static bool getAudioMuted(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool nativeWidgetIsVisible(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static const NPUTF8* sPluginMethodIdentifierNames[] = { static const NPUTF8* sPluginMethodIdentifierNames[] = {
"npnEvaluateTest", "npnEvaluateTest",
@ -240,6 +241,7 @@ static const NPUTF8* sPluginMethodIdentifierNames[] = {
"startAudioPlayback", "startAudioPlayback",
"stopAudioPlayback", "stopAudioPlayback",
"audioMuted", "audioMuted",
"nativeWidgetIsVisible",
}; };
static NPIdentifier sPluginMethodIdentifiers[MOZ_ARRAY_LENGTH(sPluginMethodIdentifierNames)]; static NPIdentifier sPluginMethodIdentifiers[MOZ_ARRAY_LENGTH(sPluginMethodIdentifierNames)];
static const ScriptableFunction sPluginMethodFunctions[] = { static const ScriptableFunction sPluginMethodFunctions[] = {
@ -310,6 +312,7 @@ static const ScriptableFunction sPluginMethodFunctions[] = {
startAudioPlayback, startAudioPlayback,
stopAudioPlayback, stopAudioPlayback,
getAudioMuted, getAudioMuted,
nativeWidgetIsVisible,
}; };
static_assert(MOZ_ARRAY_LENGTH(sPluginMethodIdentifierNames) == static_assert(MOZ_ARRAY_LENGTH(sPluginMethodIdentifierNames) ==
@ -3321,6 +3324,27 @@ destroySharedGfxStuff(NPObject* npobj, const NPVariant* args,
} }
#endif #endif
#if defined(XP_WIN)
bool
nativeWidgetIsVisible(NPObject* npobj, const NPVariant* args,
uint32_t argCount, NPVariant* result)
{
NPP npp = static_cast<TestNPObject*>(npobj)->npp;
InstanceData* id = static_cast<InstanceData*>(npp->pdata);
bool visible = pluginNativeWidgetIsVisible(id);
BOOLEAN_TO_NPVARIANT(visible, *result);
return true;
}
#else
bool
nativeWidgetIsVisible(NPObject* npobj, const NPVariant* args,
uint32_t argCount, NPVariant* result)
{
// XXX Not implemented!
return false;
}
#endif
bool bool
callOnDestroy(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result) callOnDestroy(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{ {

View File

@ -145,4 +145,11 @@ bool pluginCrashInNestedLoop(InstanceData* instanceData);
*/ */
bool pluginDestroySharedGfxStuff(InstanceData* instanceData); bool pluginDestroySharedGfxStuff(InstanceData* instanceData);
/**
* Checks to see if the native widget is marked as visible. Works
* in e10s and non-e10s. Useful in testing e10s related compositor
* plugin window functionality. Supported on Windows.
*/
bool pluginNativeWidgetIsVisible(InstanceData* instanceData);
#endif // nptest_platform_h_ #endif // nptest_platform_h_

View File

@ -591,3 +591,15 @@ void pluginDoInternalConsistencyCheck(InstanceData* instanceData, string& error)
checkEquals(childRect.bottom, childRect.top + CHILD_WIDGET_SIZE, "Child widget height", error); checkEquals(childRect.bottom, childRect.top + CHILD_WIDGET_SIZE, "Child widget height", error);
} }
} }
bool pluginNativeWidgetIsVisible(InstanceData* instanceData)
{
HWND hWnd = (HWND)instanceData->window.window;
wchar_t className[60];
if (::GetClassNameW(hWnd, className, sizeof(className) / sizeof(char16_t)) &&
!wcsicmp(className, L"GeckoPluginWindow")) {
return ::IsWindowVisible(hWnd);
}
// something isn't right, fail the check
return false;
}

View File

@ -5288,9 +5288,10 @@ StorageDirectoryHelper::RunOnMainThread()
rv = secMan->GetSimpleCodebasePrincipal(uri, rv = secMan->GetSimpleCodebasePrincipal(uri,
getter_AddRefs(principal)); getter_AddRefs(principal));
} else { } else {
OriginAttributes attrs(originProps.mAppId, originProps.mInMozBrowser); rv = secMan->GetAppCodebasePrincipal(uri,
principal = BasePrincipal::CreateCodebasePrincipal(uri, attrs); originProps.mAppId,
rv = principal ? NS_OK : NS_ERROR_FAILURE; originProps.mInMozBrowser,
getter_AddRefs(principal));
} }
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;

View File

@ -27,9 +27,9 @@ function make_uri(url) {
// Ensure "fullscreen" permissions are not present on the test URI. // Ensure "fullscreen" permissions are not present on the test URI.
var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager); var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
var uri = make_uri("http://mochi.test:8888"); var uri = make_uri("http://mochi.test:8888");
var ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"] var principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager); .getService(Ci.nsIScriptSecurityManager)
var principal = ssm.createCodebasePrincipal(uri, {}); .getNoAppCodebasePrincipal(uri);
pm.removeFromPrincipal(principal, "fullscreen"); pm.removeFromPrincipal(principal, "fullscreen");
SpecialPowers.pushPrefEnv({"set": [ SpecialPowers.pushPrefEnv({"set": [

View File

@ -18,21 +18,33 @@ function testAboutURL() {
} }
function testDataURL() { function testDataURL() {
return fetch("data:text/plain;charset=UTF-8,Hello").then(function(res) { return Promise.all(
ok(true, "Data URL fetch should resolve"); [
if (res.type == "error") { ["data:text/plain;charset=UTF-8,Hello", 'text/plain;charset=UTF-8', 'Hello'],
ok(false, "Data URL fetch should not fail."); ["data:text/plain;charset=utf-8;base64,SGVsbG8=", 'text/plain;charset=utf-8', 'Hello'],
return Promise.reject(); ['data:text/xml,%3Cres%3Ehello%3C/res%3E%0A', 'text/xml', '<res>hello</res>\n'],
} ['data:text/plain,hello%20pass%0A', 'text/plain', 'hello pass\n'],
ok(res instanceof Response, "Fetch should resolve to a Response"); ['data:,foo', 'text/plain;charset=US-ASCII', 'foo'],
is(res.status, 200, "Data URL status should be 200"); ['data:text/plain;base64,Zm9v', 'text/plain', 'foo'],
is(res.statusText, "OK", "Data URL statusText should be OK"); ['data:text/plain,foo#bar', 'text/plain', 'foo'],
ok(res.headers.has("content-type"), "Headers must have Content-Type header"); ['data:text/plain,foo%23bar', 'text/plain', 'foo#bar'],
is(res.headers.get("content-type"), "text/plain;charset=UTF-8", "Content-Type header should match specified value"); ].map(test => {
return res.text().then(function(body) { var uri = test[0], contentType = test[1], expectedBody = test[2];
is(body, "Hello", "Data URL Body should match"); return fetch(uri).then(res => {
}); ok(true, "Data URL fetch should resolve");
}); if (res.type == "error") {
ok(false, "Data URL fetch should not fail.");
return Promise.reject();
}
ok(res instanceof Response, "Fetch should resolve to a Response");
is(res.status, 200, "Data URL status should be 200");
is(res.statusText, "OK", "Data URL statusText should be OK");
ok(res.headers.has("content-type"), "Headers must have Content-Type header");
is(res.headers.get("content-type"), contentType, "Content-Type header should match specified value");
return res.text().then(body => is(body, expectedBody, "Data URL Body should match"));
})
})
);
} }
function testSameOriginBlobURL() { function testSameOriginBlobURL() {

View File

@ -18,7 +18,7 @@ function startTest()
.getService(Components.interfaces.nsIDOMStorageManager); .getService(Components.interfaces.nsIDOMStorageManager);
var uri = ios.newURI(url, "", null); var uri = ios.newURI(url, "", null);
var principal = ssm.createCodebasePrincipal(uri, {}); var principal = ssm.getNoAppCodebasePrincipal(uri);
var storage = dsm.createStorage(window, principal, ""); var storage = dsm.createStorage(window, principal, "");
storage.setItem("chromekey", "chromevalue"); storage.setItem("chromekey", "chromevalue");

View File

@ -125,14 +125,15 @@ interface NavigatorGeolocation {
Navigator implements NavigatorGeolocation; Navigator implements NavigatorGeolocation;
// http://www.w3.org/TR/battery-status/#navigatorbattery-interface // http://www.w3.org/TR/battery-status/#navigatorbattery-interface
[NoInterfaceObject] partial interface Navigator {
interface NavigatorBattery { [Throws, Pref="dom.battery.enabled"]
// XXXbz Per spec this should be non-nullable, but we return null in Promise<BatteryManager> getBattery();
// torn-down windows. See bug 884925. // Deprecated. Use getBattery() instead.
[Throws, Pref="dom.battery.enabled"] // XXXbz Per spec this should be non-nullable, but we return null in
readonly attribute BatteryManager? battery; // torn-down windows. See bug 884925.
[Throws, Pref="dom.battery.enabled", BinaryName="deprecatedBattery"]
readonly attribute BatteryManager? battery;
}; };
Navigator implements NavigatorBattery;
// https://wiki.mozilla.org/WebAPI/DataStore // https://wiki.mozilla.org/WebAPI/DataStore
[NoInterfaceObject, [NoInterfaceObject,

View File

@ -404,10 +404,25 @@ ExtendableEvent::WaitUntil(Promise& aPromise, ErrorResult& aRv)
return; return;
} }
// Only first caller counts. mPromises.AppendElement(&aPromise);
if (EventPhase() == AT_TARGET && !mPromise) { }
mPromise = &aPromise;
already_AddRefed<Promise>
ExtendableEvent::GetPromise()
{
WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(worker);
worker->AssertIsOnWorkerThread();
GlobalObject global(worker->GetJSContext(), worker->GlobalScope()->GetGlobalJSObject());
ErrorResult result;
nsRefPtr<Promise> p = Promise::All(global, Move(mPromises), result);
if (NS_WARN_IF(result.Failed())) {
return nullptr;
} }
return p.forget();
} }
NS_IMPL_ADDREF_INHERITED(ExtendableEvent, Event) NS_IMPL_ADDREF_INHERITED(ExtendableEvent, Event)
@ -416,7 +431,7 @@ NS_IMPL_RELEASE_INHERITED(ExtendableEvent, Event)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ExtendableEvent) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ExtendableEvent)
NS_INTERFACE_MAP_END_INHERITING(Event) NS_INTERFACE_MAP_END_INHERITING(Event)
NS_IMPL_CYCLE_COLLECTION_INHERITED(ExtendableEvent, Event, mPromise) NS_IMPL_CYCLE_COLLECTION_INHERITED(ExtendableEvent, Event, mPromises)
#ifndef MOZ_SIMPLEPUSH #ifndef MOZ_SIMPLEPUSH

View File

@ -102,7 +102,7 @@ public:
class ExtendableEvent : public Event class ExtendableEvent : public Event
{ {
nsRefPtr<Promise> mPromise; nsTArray<nsRefPtr<Promise>> mPromises;
protected: protected:
explicit ExtendableEvent(mozilla::dom::EventTarget* aOwner); explicit ExtendableEvent(mozilla::dom::EventTarget* aOwner);
@ -144,11 +144,7 @@ public:
WaitUntil(Promise& aPromise, ErrorResult& aRv); WaitUntil(Promise& aPromise, ErrorResult& aRv);
already_AddRefed<Promise> already_AddRefed<Promise>
GetPromise() const GetPromise();
{
nsRefPtr<Promise> p = mPromise;
return p.forget();
}
virtual ExtendableEvent* AsExtendableEvent() override virtual ExtendableEvent* AsExtendableEvent() override
{ {

View File

@ -1903,7 +1903,7 @@ LifecycleEventWorkerRunnable::DispatchLifecycleEvent(JSContext* aCx, WorkerPriva
// FIXME(nsm): Bug 982787 pass previous active worker. // FIXME(nsm): Bug 982787 pass previous active worker.
ExtendableEventInit init; ExtendableEventInit init;
init.mBubbles = false; init.mBubbles = false;
init.mCancelable = true; init.mCancelable = false;
event = ExtendableEvent::Constructor(target, mEventName, init); event = ExtendableEvent::Constructor(target, mEventName, init);
} else { } else {
MOZ_CRASH("Unexpected lifecycle event"); MOZ_CRASH("Unexpected lifecycle event");
@ -2304,7 +2304,7 @@ public:
// FIXME(nsm): Bug 1149195. // FIXME(nsm): Bug 1149195.
// pei.mData.Construct(mData); // pei.mData.Construct(mData);
pei.mBubbles = false; pei.mBubbles = false;
pei.mCancelable = true; pei.mCancelable = false;
ErrorResult result; ErrorResult result;
nsRefPtr<PushEvent> event = nsRefPtr<PushEvent> event =
@ -2503,7 +2503,7 @@ public:
NotificationEventInit nei; NotificationEventInit nei;
nei.mNotification = notification; nei.mNotification = notification;
nei.mBubbles = false; nei.mBubbles = false;
nei.mCancelable = true; nei.mCancelable = false;
nsRefPtr<NotificationEvent> event = nsRefPtr<NotificationEvent> event =
NotificationEvent::Constructor(target, NS_LITERAL_STRING("notificationclick"), nei, result); NotificationEvent::Constructor(target, NS_LITERAL_STRING("notificationclick"), nei, result);
@ -2980,14 +2980,10 @@ ServiceWorkerRegistrationInfo::FinishActivate(bool aSuccess)
return; return;
} }
if (aSuccess) { // Activation never fails, so aSuccess is ignored.
mActiveWorker->UpdateState(ServiceWorkerState::Activated); mActiveWorker->UpdateState(ServiceWorkerState::Activated);
nsRefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance(); nsRefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
swm->StoreRegistration(mPrincipal, this); swm->StoreRegistration(mPrincipal, this);
} else {
mActiveWorker->UpdateState(ServiceWorkerState::Redundant);
mActiveWorker = nullptr;
}
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -3822,7 +3818,7 @@ private:
init.mRequest.Construct(); init.mRequest.Construct();
init.mRequest.Value() = request; init.mRequest.Value() = request;
init.mBubbles = false; init.mBubbles = false;
init.mCancelable = true; init.mCancelable = false;
init.mIsReload.Construct(mIsReload); init.mIsReload.Construct(mIsReload);
nsRefPtr<FetchEvent> event = nsRefPtr<FetchEvent> event =
FetchEvent::Constructor(globalObj, NS_LITERAL_STRING("fetch"), init, result); FetchEvent::Constructor(globalObj, NS_LITERAL_STRING("fetch"), init, result);

View File

@ -58,22 +58,40 @@
}); });
} }
function activateError() { function testActive(worker) {
is(worker.state, "activating", "Should be activating");
return new Promise(function(resolve, reject) {
worker.onstatechange = function(e) {
e.target.onstatechange = null;
is(e.target.state, "activated", "Activation of worker with error in activate event handler should still succeed.");
resolve();
}
});
}
function activateErrorShouldSucceed() {
// Silence worker errors so they don't cause the test to fail. // Silence worker errors so they don't cause the test to fail.
window.onerror = function() { } window.onerror = function() { }
return navigator.serviceWorker.register("activate_event_error_worker.js", { scope: "./activate_error" }) return navigator.serviceWorker.register("activate_event_error_worker.js", { scope: "./activate_error" })
.then(function(swr) { .then(function(swr) {
return new Promise(function(resolve, reject) { var p = new Promise(function(resolve, reject) {
ok(swr.installing.state == "installing", "activateError(): Installing worker's state should be 'installing'"); ok(swr.installing.state == "installing", "activateErrorShouldSucceed(): Installing worker's state should be 'installing'");
swr.installing.onstatechange = function(e) { swr.installing.onstatechange = function(e) {
ok(swr.active, "transition to active successfully"); e.target.onstatechange = null;
is(swr.active.state, "activating", "should be activating"); if (swr.waiting) {
swr.active.onstatechange = function(e) { swr.waiting.onstatechange = function(e) {
is(e.target.state, "redundant", "Activation of worker with error in activate event handler should fail."); e.target.onstatechange = null;
resolve(swr); testActive(swr.active).then(resolve, reject);
}
} else {
testActive(swr.active).then(resolve, reject);
} }
} }
}); });
return p.then(function() {
return Promise.resolve(swr);
});
}).then(function(swr) { }).then(function(swr) {
return swr.unregister(); return swr.unregister();
}); });
@ -90,7 +108,7 @@
.then(simpleRegister) .then(simpleRegister)
.then(nextRegister) .then(nextRegister)
.then(installError) .then(installError)
.then(activateError) .then(activateErrorShouldSucceed)
.then(unregister) .then(unregister)
.then(function() { .then(function() {
SimpleTest.finish(); SimpleTest.finish();

View File

@ -7,6 +7,7 @@
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsIClassInfoImpl.h" #include "nsIClassInfoImpl.h"
#include "nsIEffectiveTLDService.h" #include "nsIEffectiveTLDService.h"
#include "nsIScriptSecurityManager.h"
#include "mozilla/BasePrincipal.h" #include "mozilla/BasePrincipal.h"
// nsPermission Implementation // nsPermission Implementation
@ -167,9 +168,12 @@ nsPermission::MatchesURI(nsIURI* aURI, bool aExactHost, bool* aMatches)
{ {
NS_ENSURE_ARG_POINTER(aURI); NS_ENSURE_ARG_POINTER(aURI);
mozilla::OriginAttributes attrs; nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
nsCOMPtr<nsIPrincipal> principal = mozilla::BasePrincipal::CreateCodebasePrincipal(aURI, attrs); NS_ENSURE_TRUE(secMan, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(principal, NS_ERROR_FAILURE);
nsCOMPtr<nsIPrincipal> principal;
nsresult rv = secMan->GetNoAppCodebasePrincipal(aURI, getter_AddRefs(principal));
NS_ENSURE_SUCCESS(rv, rv);
return Matches(principal, aExactHost, aMatches); return Matches(principal, aExactHost, aMatches);
} }

View File

@ -126,24 +126,19 @@ GetPrincipalFromOrigin(const nsACString& aOrigin, nsIPrincipal** aPrincipal)
nsresult nsresult
GetPrincipal(nsIURI* aURI, uint32_t aAppId, bool aIsInBrowserElement, nsIPrincipal** aPrincipal) GetPrincipal(nsIURI* aURI, uint32_t aAppId, bool aIsInBrowserElement, nsIPrincipal** aPrincipal)
{ {
// TODO: Bug 1165267 - Use OriginAttributes for nsCookieService nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
mozilla::OriginAttributes attrs(aAppId, aIsInBrowserElement); NS_ENSURE_TRUE(secMan, NS_ERROR_FAILURE);
nsCOMPtr<nsIPrincipal> principal = mozilla::BasePrincipal::CreateCodebasePrincipal(aURI, attrs);
NS_ENSURE_TRUE(principal, NS_ERROR_FAILURE);
principal.forget(aPrincipal); return secMan->GetAppCodebasePrincipal(aURI, aAppId, aIsInBrowserElement, aPrincipal);
return NS_OK;
} }
nsresult nsresult
GetPrincipal(nsIURI* aURI, nsIPrincipal** aPrincipal) GetPrincipal(nsIURI* aURI, nsIPrincipal** aPrincipal)
{ {
mozilla::OriginAttributes attrs; nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
nsCOMPtr<nsIPrincipal> principal = mozilla::BasePrincipal::CreateCodebasePrincipal(aURI, attrs); NS_ENSURE_TRUE(secMan, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(principal, NS_ERROR_FAILURE);
principal.forget(aPrincipal); return secMan->GetNoAppCodebasePrincipal(aURI, aPrincipal);
return NS_OK;
} }
nsCString nsCString

View File

@ -67,22 +67,19 @@ function onInstall() {
var currentPermissionCount = getPermissionCountForApp(-1); var currentPermissionCount = getPermissionCountForApp(-1);
var attrs = {appId: testAppId}; var principal = secMan.getAppCodebasePrincipal(ioService.newURI("http://www.example.com", null, null),
var principal = secMan.createCodebasePrincipal(ioService.newURI("http://www.example.com", null, null), testAppId, false);
attrs);
permManager.addFromPrincipal(principal, "foobar", Ci.nsIPermissionManager.ALLOW_ACTION); permManager.addFromPrincipal(principal, "foobar", Ci.nsIPermissionManager.ALLOW_ACTION);
permManager.addFromPrincipal(principal, "foo", Ci.nsIPermissionManager.DENY_ACTION); permManager.addFromPrincipal(principal, "foo", Ci.nsIPermissionManager.DENY_ACTION);
permManager.addFromPrincipal(principal, "bar", Ci.nsIPermissionManager.ALLOW_ACTION, Ci.nsIPermissionManager.EXPIRE_SESSION, 0); permManager.addFromPrincipal(principal, "bar", Ci.nsIPermissionManager.ALLOW_ACTION, Ci.nsIPermissionManager.EXPIRE_SESSION, 0);
attrs = {appId: testAppId, inBrowser: true}; principal = secMan.getAppCodebasePrincipal(ioService.newURI("http://www.example.com", null, null),
principal = secMan.createCodebasePrincipal(ioService.newURI("http://www.example.com", null, null), testAppId, true);
attrs);
permManager.addFromPrincipal(principal, "foobar", Ci.nsIPermissionManager.ALLOW_ACTION); permManager.addFromPrincipal(principal, "foobar", Ci.nsIPermissionManager.ALLOW_ACTION);
attrs = {appId: testAppId}; principal = secMan.getAppCodebasePrincipal(ioService.newURI("http://www.example.org", null, null),
principal = secMan.createCodebasePrincipal(ioService.newURI("http://www.example.org", null, null), testAppId, false);
attrs);
permManager.addFromPrincipal(principal, "foobar", Ci.nsIPermissionManager.ALLOW_ACTION); permManager.addFromPrincipal(principal, "foobar", Ci.nsIPermissionManager.ALLOW_ACTION);
is(getPermissionCountForApp(testAppId), 5, "App should have 5 permissions"); is(getPermissionCountForApp(testAppId), 5, "App should have 5 permissions");

View File

@ -6,8 +6,7 @@ let pm;
// Create a principal based on the { origin, appId, browserElement }. // Create a principal based on the { origin, appId, browserElement }.
function createPrincipal(aOrigin, aAppId, aBrowserElement) function createPrincipal(aOrigin, aAppId, aBrowserElement)
{ {
var attrs = {appId: aAppId, inBrowser: aBrowserElement}; return Services.scriptSecurityManager.getAppCodebasePrincipal(NetUtil.newURI(aOrigin), aAppId, aBrowserElement);
return Services.scriptSecurityManager.createCodebasePrincipal(NetUtil.newURI(aOrigin), attrs);
} }
// Return the subject required by 'webapps-clear-data' notification. // Return the subject required by 'webapps-clear-data' notification.

View File

@ -51,14 +51,12 @@ add_task(function* do_test() {
getService(Ci.nsIPermissionManager); getService(Ci.nsIPermissionManager);
// test the default permission was applied. // test the default permission was applied.
let principal = Services.scriptSecurityManager.createCodebasePrincipal(TEST_ORIGIN, {}); let principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(TEST_ORIGIN);
let principalHttps = Services.scriptSecurityManager.createCodebasePrincipal(TEST_ORIGIN_HTTPS, {}); let principalHttps = Services.scriptSecurityManager.getNoAppCodebasePrincipal(TEST_ORIGIN_HTTPS);
let principal2 = Services.scriptSecurityManager.createCodebasePrincipal(TEST_ORIGIN_2, {}); let principal2 = Services.scriptSecurityManager.getNoAppCodebasePrincipal(TEST_ORIGIN_2);
let principal3 = Services.scriptSecurityManager.createCodebasePrincipal(TEST_ORIGIN_3, {}); let principal3 = Services.scriptSecurityManager.getNoAppCodebasePrincipal(TEST_ORIGIN_3);
let principal4 = Services.scriptSecurityManager.getAppCodebasePrincipal(TEST_ORIGIN, 1000, true);
let attrs = {appId: 1000, inBrowser: true}; let principal5 = Services.scriptSecurityManager.getAppCodebasePrincipal(TEST_ORIGIN_3, 1000, true);
let principal4 = Services.scriptSecurityManager.createCodebasePrincipal(TEST_ORIGIN, attrs);
let principal5 = Services.scriptSecurityManager.createCodebasePrincipal(TEST_ORIGIN_3, attrs);
do_check_eq(Ci.nsIPermissionManager.ALLOW_ACTION, do_check_eq(Ci.nsIPermissionManager.ALLOW_ACTION,
pm.testPermissionFromPrincipal(principal, TEST_PERMISSION)); pm.testPermissionFromPrincipal(principal, TEST_PERMISSION));
@ -224,7 +222,7 @@ function checkCapabilityViaDB(expected, origin = TEST_ORIGIN, type = TEST_PERMIS
// value (ie, the "capability" in nsIPermission parlance) or null if it can't // value (ie, the "capability" in nsIPermission parlance) or null if it can't
// be found. // be found.
function findCapabilityViaDB(origin = TEST_ORIGIN, type = TEST_PERMISSION) { function findCapabilityViaDB(origin = TEST_ORIGIN, type = TEST_PERMISSION) {
let principal = Services.scriptSecurityManager.createCodebasePrincipal(origin, {}); let principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(origin);
let originStr = principal.origin; let originStr = principal.origin;
let file = Services.dirsvc.get("ProfD", Ci.nsIFile); let file = Services.dirsvc.get("ProfD", Ci.nsIFile);

View File

@ -21,7 +21,7 @@ function do_run_test() {
let pm = Services.perms; let pm = Services.perms;
let permURI = NetUtil.newURI("http://example.com"); let permURI = NetUtil.newURI("http://example.com");
let principal = Services.scriptSecurityManager.createCodebasePrincipal(permURI, {}); let principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(permURI);
let now = Number(Date.now()); let now = Number(Date.now());

View File

@ -1,11 +1,10 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
function getPrincipalFromURI(aURI) { function getPrincipalFromURI(uri) {
let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"] return Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager); .getService(Ci.nsIScriptSecurityManager)
let uri = NetUtil.newURI(aURI); .getNoAppCodebasePrincipal(NetUtil.newURI(uri));
return ssm.createCodebasePrincipal(uri, {});
} }
function getSystemPrincipal() { function getSystemPrincipal() {

View File

@ -2,10 +2,9 @@
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
function getPrincipalFromDomain(aDomain) { function getPrincipalFromDomain(aDomain) {
let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"] return Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager); .getService(Ci.nsIScriptSecurityManager)
let uri = NetUtil.newURI("http://" + aDomain); .getNoAppCodebasePrincipal(NetUtil.newURI("http://" + aDomain));
return ssm.createCodebasePrincipal(uri, {});
} }
function run_test() { function run_test() {

View File

@ -134,9 +134,8 @@ function run_test() {
do_check_true(numMigrated > 0, "we found at least 1 record that was migrated"); do_check_true(numMigrated > 0, "we found at least 1 record that was migrated");
// This permission should always be there. // This permission should always be there.
let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"] let principal = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager); .getService(Ci.nsIScriptSecurityManager)
let uri = NetUtil.newURI("http://example.org"); .getNoAppCodebasePrincipal(NetUtil.newURI("http://example.org"));
let principal = ssm.createCodebasePrincipal(uri, {});
do_check_eq(pm.testPermissionFromPrincipal(principal, 'test-load-invalid-entries'), Ci.nsIPermissionManager.ALLOW_ACTION); do_check_eq(pm.testPermissionFromPrincipal(principal, 'test-load-invalid-entries'), Ci.nsIPermissionManager.ALLOW_ACTION);
} }

View File

@ -5,8 +5,7 @@
function getPrincipalFromURIString(uriStr) function getPrincipalFromURIString(uriStr)
{ {
let uri = NetUtil.newURI(uriStr); return Services.scriptSecurityManager.getNoAppCodebasePrincipal(NetUtil.newURI(uriStr));
return Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
} }
function run_test() { function run_test() {

View File

@ -38,44 +38,40 @@ function run_test() {
let uri4 = NetUtil.newURI("https://hangouts.google.com/#!/hangout", null, null); let uri4 = NetUtil.newURI("https://hangouts.google.com/#!/hangout", null, null);
let uri5 = NetUtil.newURI("http://google.com:8096/", null, null); let uri5 = NetUtil.newURI("http://google.com:8096/", null, null);
let uri0_n_n = secMan.createCodebasePrincipal(uri0, {}); let uri0_n_n = secMan.getNoAppCodebasePrincipal(uri0);
let uri1_n_n = secMan.createCodebasePrincipal(uri1, {}); let uri1_n_n = secMan.getNoAppCodebasePrincipal(uri1);
let uri2_n_n = secMan.createCodebasePrincipal(uri2, {}); let uri2_n_n = secMan.getNoAppCodebasePrincipal(uri2);
let uri3_n_n = secMan.createCodebasePrincipal(uri3, {}); let uri3_n_n = secMan.getNoAppCodebasePrincipal(uri3);
let uri4_n_n = secMan.createCodebasePrincipal(uri4, {}); let uri4_n_n = secMan.getNoAppCodebasePrincipal(uri4);
let uri5_n_n = secMan.createCodebasePrincipal(uri5, {}); let uri5_n_n = secMan.getNoAppCodebasePrincipal(uri5);
let attrs = {appId: 1000}; let uri0_1000_n = secMan.getAppCodebasePrincipal(uri0, 1000, false);
let uri0_1000_n = secMan.createCodebasePrincipal(uri0, attrs); let uri1_1000_n = secMan.getAppCodebasePrincipal(uri1, 1000, false);
let uri1_1000_n = secMan.createCodebasePrincipal(uri1, attrs); let uri2_1000_n = secMan.getAppCodebasePrincipal(uri2, 1000, false);
let uri2_1000_n = secMan.createCodebasePrincipal(uri2, attrs); let uri3_1000_n = secMan.getAppCodebasePrincipal(uri3, 1000, false);
let uri3_1000_n = secMan.createCodebasePrincipal(uri3, attrs); let uri4_1000_n = secMan.getAppCodebasePrincipal(uri4, 1000, false);
let uri4_1000_n = secMan.createCodebasePrincipal(uri4, attrs); let uri5_1000_n = secMan.getAppCodebasePrincipal(uri5, 1000, false);
let uri5_1000_n = secMan.createCodebasePrincipal(uri5, attrs);
attrs = {appId: 1000, inBrowser: true}; let uri0_1000_y = secMan.getAppCodebasePrincipal(uri0, 1000, true);
let uri0_1000_y = secMan.createCodebasePrincipal(uri0, attrs); let uri1_1000_y = secMan.getAppCodebasePrincipal(uri1, 1000, true);
let uri1_1000_y = secMan.createCodebasePrincipal(uri1, attrs); let uri2_1000_y = secMan.getAppCodebasePrincipal(uri2, 1000, true);
let uri2_1000_y = secMan.createCodebasePrincipal(uri2, attrs); let uri3_1000_y = secMan.getAppCodebasePrincipal(uri3, 1000, true);
let uri3_1000_y = secMan.createCodebasePrincipal(uri3, attrs); let uri4_1000_y = secMan.getAppCodebasePrincipal(uri4, 1000, true);
let uri4_1000_y = secMan.createCodebasePrincipal(uri4, attrs); let uri5_1000_y = secMan.getAppCodebasePrincipal(uri5, 1000, true);
let uri5_1000_y = secMan.createCodebasePrincipal(uri5, attrs);
attrs = {appId: 2000}; let uri0_2000_n = secMan.getAppCodebasePrincipal(uri0, 2000, false);
let uri0_2000_n = secMan.createCodebasePrincipal(uri0, attrs); let uri1_2000_n = secMan.getAppCodebasePrincipal(uri1, 2000, false);
let uri1_2000_n = secMan.createCodebasePrincipal(uri1, attrs); let uri2_2000_n = secMan.getAppCodebasePrincipal(uri2, 2000, false);
let uri2_2000_n = secMan.createCodebasePrincipal(uri2, attrs); let uri3_2000_n = secMan.getAppCodebasePrincipal(uri3, 2000, false);
let uri3_2000_n = secMan.createCodebasePrincipal(uri3, attrs); let uri4_2000_n = secMan.getAppCodebasePrincipal(uri4, 2000, false);
let uri4_2000_n = secMan.createCodebasePrincipal(uri4, attrs); let uri5_2000_n = secMan.getAppCodebasePrincipal(uri5, 2000, false);
let uri5_2000_n = secMan.createCodebasePrincipal(uri5, attrs);
attrs = {appId: 2000, inBrowser: true}; let uri0_2000_y = secMan.getAppCodebasePrincipal(uri0, 2000, true);
let uri0_2000_y = secMan.createCodebasePrincipal(uri0, attrs); let uri1_2000_y = secMan.getAppCodebasePrincipal(uri1, 2000, true);
let uri1_2000_y = secMan.createCodebasePrincipal(uri1, attrs); let uri2_2000_y = secMan.getAppCodebasePrincipal(uri2, 2000, true);
let uri2_2000_y = secMan.createCodebasePrincipal(uri2, attrs); let uri3_2000_y = secMan.getAppCodebasePrincipal(uri3, 2000, true);
let uri3_2000_y = secMan.createCodebasePrincipal(uri3, attrs); let uri4_2000_y = secMan.getAppCodebasePrincipal(uri4, 2000, true);
let uri4_2000_y = secMan.createCodebasePrincipal(uri4, attrs); let uri5_2000_y = secMan.getAppCodebasePrincipal(uri5, 2000, true);
let uri5_2000_y = secMan.createCodebasePrincipal(uri5, attrs);
pm.addFromPrincipal(uri0_n_n, "test/matches", pm.ALLOW_ACTION); pm.addFromPrincipal(uri0_n_n, "test/matches", pm.ALLOW_ACTION);
let perm_n_n = pm.getPermissionObject(uri0_n_n, "test/matches", true); let perm_n_n = pm.getPermissionObject(uri0_n_n, "test/matches", true);

View File

@ -30,9 +30,9 @@ function mk_permission(uri, isAppPermission = false) {
.getService(Ci.nsIScriptSecurityManager); .getService(Ci.nsIScriptSecurityManager);
// Get the permission from the principal! // Get the permission from the principal!
let attrs = {appId: 1000}; let principal = isAppPermission ?
let principal = secMan.getAppCodebasePrincipal(uri, 1000, false) :
secMan.createCodebasePrincipal(uri, isAppPermission ? attrs : {}); secMan.getNoAppCodebasePrincipal(uri);
pm.addFromPrincipal(principal, "test/matchesuri", pm.ALLOW_ACTION); pm.addFromPrincipal(principal, "test/matchesuri", pm.ALLOW_ACTION);
let permission = pm.getPermissionObject(principal, "test/matchesuri", true); let permission = pm.getPermissionObject(principal, "test/matchesuri", true);

Some files were not shown because too many files have changed in this diff Show More