2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-10-06 18:51:03 +04:00
|
|
|
/* This code is loaded in every child process that is started by mochitest in
|
|
|
|
* order to be used as a replacement for UniversalXPConnect
|
|
|
|
*/
|
|
|
|
|
2014-05-22 23:53:22 +04:00
|
|
|
"use strict";
|
|
|
|
|
2011-10-06 18:51:03 +04:00
|
|
|
var Ci = Components.interfaces;
|
|
|
|
var Cc = Components.classes;
|
2012-08-18 02:13:23 +04:00
|
|
|
var Cu = Components.utils;
|
2011-10-06 18:51:03 +04:00
|
|
|
|
2012-11-17 06:53:32 +04:00
|
|
|
Cu.import("resource://specialpowers/MockFilePicker.jsm");
|
2013-07-08 23:11:36 +04:00
|
|
|
Cu.import("resource://specialpowers/MockColorPicker.jsm");
|
2012-11-17 06:53:32 +04:00
|
|
|
Cu.import("resource://specialpowers/MockPermissionPrompt.jsm");
|
2015-01-19 16:50:32 +03:00
|
|
|
Cu.import("resource://specialpowers/MockPaymentsUIGlue.jsm");
|
2012-11-17 06:53:32 +04:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2011-10-22 03:39:30 +04:00
|
|
|
|
2015-03-04 05:01:58 +03:00
|
|
|
if (!this.File) {
|
|
|
|
Cu.importGlobalProperties(["File"]);
|
|
|
|
}
|
2014-10-21 04:49:00 +04:00
|
|
|
|
2014-07-18 08:34:48 +04:00
|
|
|
// Allow stuff from this scope to be accessed from non-privileged scopes. This
|
|
|
|
// would crash if used outside of automation.
|
|
|
|
Cu.forcePermissiveCOWs();
|
|
|
|
|
2012-11-17 06:53:32 +04:00
|
|
|
function SpecialPowersAPI() {
|
2011-10-06 18:51:03 +04:00
|
|
|
this._consoleListeners = [];
|
|
|
|
this._encounteredCrashDumpFiles = [];
|
|
|
|
this._unexpectedCrashDumpFiles = { };
|
|
|
|
this._crashDumpDir = null;
|
|
|
|
this._mfl = null;
|
2011-10-06 18:51:03 +04:00
|
|
|
this._prefEnvUndoStack = [];
|
|
|
|
this._pendingPrefs = [];
|
|
|
|
this._applyingPrefs = false;
|
2013-03-29 16:43:27 +04:00
|
|
|
this._permissionsUndoStack = [];
|
|
|
|
this._pendingPermissions = [];
|
|
|
|
this._applyingPermissions = false;
|
2011-10-06 18:51:03 +04:00
|
|
|
this._fm = null;
|
2011-10-14 15:52:02 +04:00
|
|
|
this._cb = null;
|
2014-09-27 03:21:57 +04:00
|
|
|
this._quotaManagerCallbackInfos = null;
|
2011-10-06 18:51:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function bindDOMWindowUtils(aWindow) {
|
|
|
|
if (!aWindow)
|
|
|
|
return
|
|
|
|
|
2013-02-23 02:18:38 +04:00
|
|
|
var util = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
return wrapPrivileged(util);
|
2011-10-06 18:51:03 +04:00
|
|
|
}
|
|
|
|
|
2012-09-24 16:46:27 +04:00
|
|
|
function getRawComponents(aWindow) {
|
2014-01-15 06:49:29 +04:00
|
|
|
// If we're running in automation that supports enablePrivilege, then we also
|
|
|
|
// provided access to the privileged Components.
|
|
|
|
try {
|
|
|
|
let win = Cu.waiveXrays(aWindow);
|
|
|
|
if (typeof win.netscape.security.PrivilegeManager == 'object')
|
|
|
|
Cu.forcePrivilegedComponentsForScope(aWindow);
|
|
|
|
} catch (e) {}
|
2012-09-24 16:46:27 +04:00
|
|
|
return Cu.getComponentsForScope(aWindow);
|
|
|
|
}
|
|
|
|
|
2012-01-19 07:10:04 +04:00
|
|
|
function isWrappable(x) {
|
|
|
|
if (typeof x === "object")
|
|
|
|
return x !== null;
|
|
|
|
return typeof x === "function";
|
|
|
|
};
|
|
|
|
|
|
|
|
function isWrapper(x) {
|
|
|
|
return isWrappable(x) && (typeof x.SpecialPowers_wrappedObject !== "undefined");
|
|
|
|
};
|
|
|
|
|
|
|
|
function unwrapIfWrapped(x) {
|
|
|
|
return isWrapper(x) ? unwrapPrivileged(x) : x;
|
|
|
|
};
|
|
|
|
|
2013-06-05 06:56:41 +04:00
|
|
|
function wrapIfUnwrapped(x) {
|
|
|
|
return isWrapper(x) ? x : wrapPrivileged(x);
|
|
|
|
}
|
|
|
|
|
2014-06-12 02:16:06 +04:00
|
|
|
function isObjectOrArray(obj) {
|
|
|
|
if (Object(obj) !== obj)
|
|
|
|
return false;
|
2014-07-10 02:23:53 +04:00
|
|
|
let arrayClasses = ['Object', 'Array', 'Int8Array', 'Uint8Array',
|
|
|
|
'Int16Array', 'Uint16Array', 'Int32Array',
|
|
|
|
'Uint32Array', 'Float32Array', 'Float64Array',
|
|
|
|
'Uint8ClampedArray'];
|
2014-06-12 02:16:06 +04:00
|
|
|
let className = Cu.getClassName(obj, true);
|
2014-07-10 02:23:53 +04:00
|
|
|
return arrayClasses.indexOf(className) != -1;
|
2014-06-12 02:16:06 +04:00
|
|
|
}
|
|
|
|
|
2014-07-10 02:23:53 +04:00
|
|
|
// In general, we want Xray wrappers for content DOM objects, because waiving
|
|
|
|
// Xray gives us Xray waiver wrappers that clamp the principal when we cross
|
|
|
|
// compartment boundaries. However, there are some exceptions where we want
|
|
|
|
// to use a waiver:
|
|
|
|
//
|
|
|
|
// * Xray adds some gunk to toString(), which has the potential to confuse
|
|
|
|
// consumers that aren't expecting Xray wrappers. Since toString() is a
|
|
|
|
// non-privileged method that returns only strings, we can just waive Xray
|
|
|
|
// for that case.
|
|
|
|
//
|
|
|
|
// * We implement Xrays to pure JS [[Object]] and [[Array]] instances that
|
|
|
|
// filter out tricky things like callables. This is the right thing for
|
|
|
|
// security in general, but tends to break tests that try to pass object
|
|
|
|
// literals into SpecialPowers. So we waive [[Object]] and [[Array]]
|
|
|
|
// instances before inspecting properties.
|
2014-07-14 21:09:06 +04:00
|
|
|
//
|
|
|
|
// * When we don't have meaningful Xray semantics, we create an Opaque
|
|
|
|
// XrayWrapper for security reasons. For test code, we generally want to see
|
|
|
|
// through that sort of thing.
|
2014-07-10 02:23:53 +04:00
|
|
|
function waiveXraysIfAppropriate(obj, propName) {
|
2014-07-14 21:09:06 +04:00
|
|
|
if (propName == 'toString' || isObjectOrArray(obj) ||
|
|
|
|
/Opaque/.test(Object.prototype.toString.call(obj)))
|
|
|
|
{
|
2014-07-10 02:23:53 +04:00
|
|
|
return XPCNativeWrapper.unwrap(obj);
|
2014-07-14 21:09:06 +04:00
|
|
|
}
|
2014-07-10 02:23:53 +04:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2012-06-18 17:43:00 +04:00
|
|
|
function callGetOwnPropertyDescriptor(obj, name) {
|
2014-07-10 02:23:53 +04:00
|
|
|
obj = waiveXraysIfAppropriate(obj, name);
|
|
|
|
|
2012-06-18 17:43:00 +04:00
|
|
|
// Quickstubbed getters and setters are propertyOps, and don't get reified
|
|
|
|
// until someone calls __lookupGetter__ or __lookupSetter__ on them (note
|
|
|
|
// that there are special version of those functions for quickstubs, so
|
|
|
|
// apply()ing Object.prototype.__lookupGetter__ isn't good enough). Try to
|
|
|
|
// trigger reification before calling Object.getOwnPropertyDescriptor.
|
|
|
|
//
|
|
|
|
// See bug 764315.
|
|
|
|
try {
|
|
|
|
obj.__lookupGetter__(name);
|
|
|
|
obj.__lookupSetter__(name);
|
|
|
|
} catch(e) { }
|
|
|
|
return Object.getOwnPropertyDescriptor(obj, name);
|
|
|
|
}
|
|
|
|
|
2012-01-19 07:10:04 +04:00
|
|
|
// We can't call apply() directy on Xray-wrapped functions, so we have to be
|
|
|
|
// clever.
|
|
|
|
function doApply(fun, invocant, args) {
|
2014-05-28 22:14:27 +04:00
|
|
|
// We implement Xrays to pure JS [[Object]] instances that filter out tricky
|
|
|
|
// things like callables. This is the right thing for security in general,
|
|
|
|
// but tends to break tests that try to pass object literals into
|
|
|
|
// SpecialPowers. So we waive [[Object]] instances when they're passed to a
|
|
|
|
// SpecialPowers-wrapped callable.
|
|
|
|
//
|
|
|
|
// Note that the transitive nature of Xray waivers means that any property
|
|
|
|
// pulled off such an object will also be waived, and so we'll get principal
|
|
|
|
// clamping for Xrayed DOM objects reached from literals, so passing things
|
|
|
|
// like {l : xoWin.location} won't work. Hopefully the rabbit hole doesn't
|
|
|
|
// go that deep.
|
2014-06-12 02:16:06 +04:00
|
|
|
args = args.map(x => isObjectOrArray(x) ? Cu.waiveXrays(x) : x);
|
2012-01-19 07:10:04 +04:00
|
|
|
return Function.prototype.apply.call(fun, invocant, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
function wrapPrivileged(obj) {
|
|
|
|
|
|
|
|
// Primitives pass straight through.
|
|
|
|
if (!isWrappable(obj))
|
|
|
|
return obj;
|
|
|
|
|
|
|
|
// No double wrapping.
|
|
|
|
if (isWrapper(obj))
|
|
|
|
throw "Trying to double-wrap object!";
|
|
|
|
|
|
|
|
// Make our core wrapper object.
|
|
|
|
var handler = new SpecialPowersHandler(obj);
|
|
|
|
|
|
|
|
// If the object is callable, make a function proxy.
|
|
|
|
if (typeof obj === "function") {
|
|
|
|
var callTrap = function() {
|
|
|
|
// The invocant and arguments may or may not be wrappers. Unwrap them if necessary.
|
|
|
|
var invocant = unwrapIfWrapped(this);
|
|
|
|
var unwrappedArgs = Array.prototype.slice.call(arguments).map(unwrapIfWrapped);
|
|
|
|
|
2014-02-20 20:57:20 +04:00
|
|
|
try {
|
|
|
|
return wrapPrivileged(doApply(obj, invocant, unwrappedArgs));
|
|
|
|
} catch (e) {
|
|
|
|
// Wrap exceptions and re-throw them.
|
|
|
|
throw wrapIfUnwrapped(e);
|
|
|
|
}
|
2012-01-19 07:10:04 +04:00
|
|
|
};
|
|
|
|
var constructTrap = function() {
|
|
|
|
// The arguments may or may not be wrappers. Unwrap them if necessary.
|
|
|
|
var unwrappedArgs = Array.prototype.slice.call(arguments).map(unwrapIfWrapped);
|
|
|
|
|
2014-03-11 01:38:14 +04:00
|
|
|
// We want to invoke "obj" as a constructor, but using unwrappedArgs as
|
|
|
|
// the arguments. Make sure to wrap and re-throw exceptions!
|
|
|
|
try {
|
|
|
|
return wrapPrivileged(new obj(...unwrappedArgs));
|
|
|
|
} catch (e) {
|
|
|
|
throw wrapIfUnwrapped(e);
|
|
|
|
}
|
2012-01-19 07:10:04 +04:00
|
|
|
};
|
|
|
|
|
2012-03-06 23:05:29 +04:00
|
|
|
return Proxy.createFunction(handler, callTrap, constructTrap);
|
2012-02-20 03:47:12 +04:00
|
|
|
}
|
|
|
|
|
2012-03-06 23:05:29 +04:00
|
|
|
// Otherwise, just make a regular object proxy.
|
|
|
|
return Proxy.create(handler);
|
2012-01-19 07:10:04 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
function unwrapPrivileged(x) {
|
|
|
|
|
|
|
|
// We don't wrap primitives, so sometimes we have a primitive where we'd
|
|
|
|
// expect to have a wrapper. The proxy pretends to be the type that it's
|
|
|
|
// emulating, so we can just as easily check isWrappable() on a proxy as
|
|
|
|
// we can on an unwrapped object.
|
|
|
|
if (!isWrappable(x))
|
|
|
|
return x;
|
|
|
|
|
|
|
|
// If we have a wrappable type, make sure it's wrapped.
|
|
|
|
if (!isWrapper(x))
|
|
|
|
throw "Trying to unwrap a non-wrapped object!";
|
|
|
|
|
2015-01-13 04:07:00 +03:00
|
|
|
var obj = x.SpecialPowers_wrappedObject;
|
|
|
|
// unwrapped.
|
|
|
|
return obj;
|
2012-01-19 07:10:04 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
function crawlProtoChain(obj, fn) {
|
|
|
|
var rv = fn(obj);
|
|
|
|
if (rv !== undefined)
|
|
|
|
return rv;
|
2014-07-10 02:23:53 +04:00
|
|
|
// Follow the prototype chain of the underlying object in cases where it differs
|
|
|
|
// from the Xray prototype chain. This is important for things like Opaque Xray
|
|
|
|
// Wrappers, which always get Object.prototype as their proto.
|
|
|
|
let proto = Cu.unwaiveXrays(Object.getPrototypeOf(Cu.waiveXrays(obj)));
|
|
|
|
if (proto)
|
|
|
|
return crawlProtoChain(proto, fn);
|
|
|
|
return undefined;
|
2012-01-19 07:10:04 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
function SpecialPowersHandler(obj) {
|
|
|
|
this.wrappedObject = obj;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Allow us to transitively maintain the membrane by wrapping descriptors
|
|
|
|
// we return.
|
|
|
|
SpecialPowersHandler.prototype.doGetPropertyDescriptor = function(name, own) {
|
|
|
|
|
|
|
|
// Handle our special API.
|
|
|
|
if (name == "SpecialPowers_wrappedObject")
|
|
|
|
return { value: this.wrappedObject, writeable: false, configurable: false, enumerable: false };
|
|
|
|
|
|
|
|
//
|
|
|
|
// Call through to the wrapped object.
|
|
|
|
//
|
|
|
|
// Note that we have several cases here, each of which requires special handling.
|
|
|
|
//
|
|
|
|
var desc;
|
2014-07-10 02:23:53 +04:00
|
|
|
var obj = this.wrappedObject;
|
2014-07-10 02:23:53 +04:00
|
|
|
function isWrappedNativeXray(o) {
|
|
|
|
if (!Cu.isXrayWrapper(o))
|
|
|
|
return false;
|
|
|
|
var proto = Object.getPrototypeOf(o);
|
|
|
|
return /XPC_WN/.test(Cu.getClassName(o, /* unwrap = */ true)) ||
|
|
|
|
(proto && /XPC_WN/.test(Cu.getClassName(proto, /* unwrap = */ true)));
|
|
|
|
}
|
2012-01-19 07:10:04 +04:00
|
|
|
|
|
|
|
// Case 1: Own Properties.
|
|
|
|
//
|
|
|
|
// This one is easy, thanks to Object.getOwnPropertyDescriptor().
|
|
|
|
if (own)
|
2012-06-18 17:43:00 +04:00
|
|
|
desc = callGetOwnPropertyDescriptor(obj, name);
|
2012-01-19 07:10:04 +04:00
|
|
|
|
2014-07-10 02:23:53 +04:00
|
|
|
// Case 2: Not own, meaningful prototype.
|
2012-01-19 07:10:04 +04:00
|
|
|
//
|
|
|
|
// Here, we can just crawl the prototype chain, calling
|
|
|
|
// Object.getOwnPropertyDescriptor until we find what we want.
|
|
|
|
//
|
|
|
|
// NB: Make sure to check this.wrappedObject here, rather than obj, because
|
|
|
|
// we may have waived Xray on obj above.
|
2014-07-10 02:23:53 +04:00
|
|
|
else if (!isWrappedNativeXray(this.wrappedObject))
|
2012-06-18 17:43:00 +04:00
|
|
|
desc = crawlProtoChain(obj, function(o) {return callGetOwnPropertyDescriptor(o, name);});
|
2012-01-19 07:10:04 +04:00
|
|
|
|
2014-07-10 02:23:53 +04:00
|
|
|
// Case 3: Not own, no meaningful prototype. This corresponds to old-style
|
|
|
|
// XPCWrappedNative XrayWrappers.
|
2012-01-19 07:10:04 +04:00
|
|
|
//
|
2014-07-10 02:23:53 +04:00
|
|
|
// This one is harder, because we these XrayWrappers are flattened and don't have
|
|
|
|
// a prototype.
|
2012-01-19 07:10:04 +04:00
|
|
|
//
|
|
|
|
// So we first try with a call to getOwnPropertyDescriptor(). If that fails,
|
|
|
|
// we make up a descriptor, using some assumptions about what kinds of things
|
|
|
|
// tend to live on the prototypes of Xray-wrapped objects.
|
|
|
|
else {
|
2014-07-10 02:23:53 +04:00
|
|
|
obj = waiveXraysIfAppropriate(obj, name);
|
2012-01-19 07:10:04 +04:00
|
|
|
desc = Object.getOwnPropertyDescriptor(obj, name);
|
|
|
|
if (!desc) {
|
|
|
|
var getter = Object.prototype.__lookupGetter__.call(obj, name);
|
|
|
|
var setter = Object.prototype.__lookupSetter__.call(obj, name);
|
|
|
|
if (getter || setter)
|
|
|
|
desc = {get: getter, set: setter, configurable: true, enumerable: true};
|
|
|
|
else if (name in obj)
|
|
|
|
desc = {value: obj[name], writable: false, configurable: true, enumerable: true};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bail if we've got nothing.
|
|
|
|
if (typeof desc === 'undefined')
|
|
|
|
return undefined;
|
|
|
|
|
2015-01-30 22:56:15 +03:00
|
|
|
// When accessors are implemented as JSGetterOp/JSSetterOps rather than
|
|
|
|
// JSNatives (ie, QuickStubs), the js engine does the wrong thing and treats
|
|
|
|
// it as a value descriptor rather than an accessor descriptor. Jorendorff
|
|
|
|
// suggested this little hack to work around it. See bug 520882.
|
2012-01-19 07:10:04 +04:00
|
|
|
if (desc && 'value' in desc && desc.value === undefined)
|
|
|
|
desc.value = obj[name];
|
|
|
|
|
|
|
|
// A trapping proxy's properties must always be configurable, but sometimes
|
|
|
|
// this we get non-configurable properties from Object.getOwnPropertyDescriptor().
|
|
|
|
// Tell a white lie.
|
|
|
|
desc.configurable = true;
|
|
|
|
|
|
|
|
// Transitively maintain the wrapper membrane.
|
|
|
|
function wrapIfExists(key) { if (key in desc) desc[key] = wrapPrivileged(desc[key]); };
|
|
|
|
wrapIfExists('value');
|
|
|
|
wrapIfExists('get');
|
|
|
|
wrapIfExists('set');
|
|
|
|
|
|
|
|
return desc;
|
|
|
|
};
|
|
|
|
|
|
|
|
SpecialPowersHandler.prototype.getOwnPropertyDescriptor = function(name) {
|
|
|
|
return this.doGetPropertyDescriptor(name, true);
|
|
|
|
};
|
|
|
|
|
|
|
|
SpecialPowersHandler.prototype.getPropertyDescriptor = function(name) {
|
|
|
|
return this.doGetPropertyDescriptor(name, false);
|
|
|
|
};
|
|
|
|
|
|
|
|
function doGetOwnPropertyNames(obj, props) {
|
|
|
|
|
|
|
|
// Insert our special API. It's not enumerable, but getPropertyNames()
|
|
|
|
// includes non-enumerable properties.
|
|
|
|
var specialAPI = 'SpecialPowers_wrappedObject';
|
|
|
|
if (props.indexOf(specialAPI) == -1)
|
|
|
|
props.push(specialAPI);
|
|
|
|
|
|
|
|
// Do the normal thing.
|
|
|
|
var flt = function(a) { return props.indexOf(a) == -1; };
|
|
|
|
props = props.concat(Object.getOwnPropertyNames(obj).filter(flt));
|
|
|
|
|
|
|
|
// If we've got an Xray wrapper, include the expandos as well.
|
|
|
|
if ('wrappedJSObject' in obj)
|
|
|
|
props = props.concat(Object.getOwnPropertyNames(obj.wrappedJSObject)
|
|
|
|
.filter(flt));
|
|
|
|
|
|
|
|
return props;
|
|
|
|
}
|
|
|
|
|
|
|
|
SpecialPowersHandler.prototype.getOwnPropertyNames = function() {
|
|
|
|
return doGetOwnPropertyNames(this.wrappedObject, []);
|
|
|
|
};
|
|
|
|
|
|
|
|
SpecialPowersHandler.prototype.getPropertyNames = function() {
|
|
|
|
|
|
|
|
// Manually walk the prototype chain, making sure to add only property names
|
|
|
|
// that haven't been overridden.
|
|
|
|
//
|
|
|
|
// There's some trickiness here with Xray wrappers. Xray wrappers don't have
|
|
|
|
// a prototype, so we need to unwrap them if we want to get all of the names
|
|
|
|
// with Object.getOwnPropertyNames(). But we don't really want to unwrap the
|
|
|
|
// base object, because that will include expandos that are inaccessible via
|
|
|
|
// our implementation of get{,Own}PropertyDescriptor(). So we unwrap just
|
|
|
|
// before accessing the prototype. This ensures that we get Xray vision on
|
|
|
|
// the base object, and no Xray vision for the rest of the way up.
|
|
|
|
var obj = this.wrappedObject;
|
|
|
|
var props = [];
|
|
|
|
while (obj) {
|
|
|
|
props = doGetOwnPropertyNames(obj, props);
|
|
|
|
obj = Object.getPrototypeOf(XPCNativeWrapper.unwrap(obj));
|
|
|
|
}
|
|
|
|
return props;
|
|
|
|
};
|
|
|
|
|
|
|
|
SpecialPowersHandler.prototype.defineProperty = function(name, desc) {
|
|
|
|
return Object.defineProperty(this.wrappedObject, name, desc);
|
|
|
|
};
|
|
|
|
|
|
|
|
SpecialPowersHandler.prototype.delete = function(name) {
|
|
|
|
return delete this.wrappedObject[name];
|
|
|
|
};
|
|
|
|
|
|
|
|
SpecialPowersHandler.prototype.fix = function() { return undefined; /* Throws a TypeError. */ };
|
|
|
|
|
|
|
|
// Per the ES5 spec this is a derived trap, but it's fundamental in spidermonkey
|
|
|
|
// for some reason. See bug 665198.
|
|
|
|
SpecialPowersHandler.prototype.enumerate = function() {
|
|
|
|
var t = this;
|
|
|
|
var filt = function(name) { return t.getPropertyDescriptor(name).enumerable; };
|
|
|
|
return this.getPropertyNames().filter(filt);
|
|
|
|
};
|
|
|
|
|
2012-11-17 06:53:32 +04:00
|
|
|
// SPConsoleListener reflects nsIConsoleMessage objects into JS in a
|
|
|
|
// tidy, XPCOM-hiding way. Messages that are nsIScriptError objects
|
|
|
|
// have their properties exposed in detail. It also auto-unregisters
|
|
|
|
// itself when it receives a "sentinel" message.
|
|
|
|
function SPConsoleListener(callback) {
|
|
|
|
this.callback = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
SPConsoleListener.prototype = {
|
|
|
|
observe: function(msg) {
|
|
|
|
let m = { message: msg.message,
|
|
|
|
errorMessage: null,
|
|
|
|
sourceName: null,
|
|
|
|
sourceLine: null,
|
|
|
|
lineNumber: null,
|
|
|
|
columnNumber: null,
|
|
|
|
category: null,
|
|
|
|
windowID: null,
|
|
|
|
isScriptError: false,
|
|
|
|
isWarning: false,
|
|
|
|
isException: false,
|
|
|
|
isStrict: false };
|
|
|
|
if (msg instanceof Ci.nsIScriptError) {
|
|
|
|
m.errorMessage = msg.errorMessage;
|
|
|
|
m.sourceName = msg.sourceName;
|
|
|
|
m.sourceLine = msg.sourceLine;
|
|
|
|
m.lineNumber = msg.lineNumber;
|
|
|
|
m.columnNumber = msg.columnNumber;
|
|
|
|
m.category = msg.category;
|
|
|
|
m.windowID = msg.outerWindowID;
|
|
|
|
m.isScriptError = true;
|
|
|
|
m.isWarning = ((msg.flags & Ci.nsIScriptError.warningFlag) === 1);
|
|
|
|
m.isException = ((msg.flags & Ci.nsIScriptError.exceptionFlag) === 1);
|
|
|
|
m.isStrict = ((msg.flags & Ci.nsIScriptError.strictFlag) === 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Object.freeze(m);
|
|
|
|
|
|
|
|
this.callback.call(undefined, m);
|
|
|
|
|
|
|
|
if (!m.isScriptError && m.message === "SENTINEL")
|
|
|
|
Services.console.unregisterListener(this);
|
|
|
|
},
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIConsoleListener])
|
|
|
|
};
|
|
|
|
|
2013-06-05 06:56:41 +04:00
|
|
|
function wrapCallback(cb) {
|
|
|
|
return function SpecialPowersCallbackWrapper() {
|
2014-05-22 23:53:22 +04:00
|
|
|
var args = Array.prototype.map.call(arguments, wrapIfUnwrapped);
|
2013-06-05 06:56:41 +04:00
|
|
|
return cb.apply(this, args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function wrapCallbackObject(obj) {
|
2014-05-28 22:14:27 +04:00
|
|
|
obj = Cu.waiveXrays(obj);
|
2014-07-18 08:34:48 +04:00
|
|
|
var wrapper = {};
|
2013-06-05 06:56:41 +04:00
|
|
|
for (var i in obj) {
|
|
|
|
if (typeof obj[i] == 'function')
|
|
|
|
wrapper[i] = wrapCallback(obj[i]);
|
|
|
|
else
|
|
|
|
wrapper[i] = obj[i];
|
|
|
|
}
|
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
|
2011-10-06 18:51:03 +04:00
|
|
|
SpecialPowersAPI.prototype = {
|
|
|
|
|
2012-01-19 07:10:04 +04:00
|
|
|
/*
|
|
|
|
* Privileged object wrapping API
|
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
* var wrapper = SpecialPowers.wrap(obj);
|
|
|
|
* wrapper.privilegedMethod(); wrapper.privilegedProperty;
|
|
|
|
* obj === SpecialPowers.unwrap(wrapper);
|
|
|
|
*
|
|
|
|
* These functions provide transparent access to privileged objects using
|
|
|
|
* various pieces of deep SpiderMagic. Conceptually, a wrapper is just an
|
|
|
|
* object containing a reference to the underlying object, where all method
|
|
|
|
* calls and property accesses are transparently performed with the System
|
|
|
|
* Principal. Moreover, objects obtained from the wrapper (including properties
|
|
|
|
* and method return values) are wrapped automatically. Thus, after a single
|
|
|
|
* call to SpecialPowers.wrap(), the wrapper layer is transitively maintained.
|
|
|
|
*
|
|
|
|
* Known Issues:
|
|
|
|
*
|
2012-03-06 23:05:29 +04:00
|
|
|
* - The wrapping function does not preserve identity, so
|
|
|
|
* SpecialPowers.wrap(foo) !== SpecialPowers.wrap(foo). See bug 718543.
|
|
|
|
*
|
2012-01-19 07:10:04 +04:00
|
|
|
* - The wrapper cannot see expando properties on unprivileged DOM objects.
|
|
|
|
* That is to say, the wrapper uses Xray delegation.
|
|
|
|
*
|
|
|
|
* - The wrapper sometimes guesses certain ES5 attributes for returned
|
|
|
|
* properties. This is explained in a comment in the wrapper code above,
|
|
|
|
* and shouldn't be a problem.
|
|
|
|
*/
|
2013-06-05 06:56:41 +04:00
|
|
|
wrap: wrapIfUnwrapped,
|
2012-05-24 15:04:57 +04:00
|
|
|
unwrap: unwrapIfWrapped,
|
|
|
|
isWrapper: isWrapper,
|
2012-01-19 07:10:04 +04:00
|
|
|
|
2013-06-05 06:56:41 +04:00
|
|
|
/*
|
|
|
|
* When content needs to pass a callback or a callback object to an API
|
|
|
|
* accessed over SpecialPowers, that API may sometimes receive arguments for
|
|
|
|
* whom it is forbidden to create a wrapper in content scopes. As such, we
|
|
|
|
* need a layer to wrap the values in SpecialPowers wrappers before they ever
|
|
|
|
* reach content.
|
|
|
|
*/
|
|
|
|
wrapCallback: wrapCallback,
|
|
|
|
wrapCallbackObject: wrapCallbackObject,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create blank privileged objects to use as out-params for privileged functions.
|
|
|
|
*/
|
|
|
|
createBlankObject: function () {
|
2014-07-18 08:34:48 +04:00
|
|
|
return new Object;
|
2013-06-05 06:56:41 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Because SpecialPowers wrappers don't preserve identity, comparing with ==
|
|
|
|
* can be hazardous. Sometimes we can just unwrap to compare, but sometimes
|
|
|
|
* wrapping the underlying object into a content scope is forbidden. This
|
|
|
|
* function strips any wrappers if they exist and compare the underlying
|
|
|
|
* values.
|
|
|
|
*/
|
|
|
|
compare: function(a, b) {
|
|
|
|
return unwrapIfWrapped(a) === unwrapIfWrapped(b);
|
|
|
|
},
|
|
|
|
|
2011-10-22 03:39:30 +04:00
|
|
|
get MockFilePicker() {
|
2015-01-19 16:50:32 +03:00
|
|
|
return MockFilePicker;
|
2011-10-22 03:39:30 +04:00
|
|
|
},
|
|
|
|
|
2013-07-08 23:11:36 +04:00
|
|
|
get MockColorPicker() {
|
2015-01-19 16:50:32 +03:00
|
|
|
return MockColorPicker;
|
2013-07-08 23:11:36 +04:00
|
|
|
},
|
|
|
|
|
2012-10-31 21:06:51 +04:00
|
|
|
get MockPermissionPrompt() {
|
2015-01-19 16:50:32 +03:00
|
|
|
return MockPermissionPrompt;
|
|
|
|
},
|
|
|
|
|
|
|
|
get MockPaymentsUIGlue() {
|
|
|
|
return MockPaymentsUIGlue;
|
2012-10-31 21:06:51 +04:00
|
|
|
},
|
|
|
|
|
2013-09-15 06:09:13 +04:00
|
|
|
loadChromeScript: function (url) {
|
|
|
|
// Create a unique id for this chrome script
|
|
|
|
let uuidGenerator = Cc["@mozilla.org/uuid-generator;1"]
|
|
|
|
.getService(Ci.nsIUUIDGenerator);
|
|
|
|
let id = uuidGenerator.generateUUID().toString();
|
|
|
|
|
|
|
|
// Tells chrome code to evaluate this chrome script
|
|
|
|
this._sendSyncMessage("SPLoadChromeScript",
|
|
|
|
{ url: url, id: id });
|
|
|
|
|
|
|
|
// Returns a MessageManager like API in order to be
|
|
|
|
// able to communicate with this chrome script
|
|
|
|
let listeners = [];
|
|
|
|
let chromeScript = {
|
|
|
|
addMessageListener: (name, listener) => {
|
|
|
|
listeners.push({ name: name, listener: listener });
|
|
|
|
},
|
|
|
|
|
|
|
|
removeMessageListener: (name, listener) => {
|
|
|
|
listeners = listeners.filter(
|
|
|
|
o => (o.name != name || o.listener != listener)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
sendAsyncMessage: (name, message) => {
|
|
|
|
this._sendSyncMessage("SPChromeScriptMessage",
|
|
|
|
{ id: id, name: name, message: message });
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: () => {
|
|
|
|
listeners = [];
|
|
|
|
this._removeMessageListener("SPChromeScriptMessage", chromeScript);
|
2014-03-25 20:03:21 +04:00
|
|
|
this._removeMessageListener("SPChromeScriptAssert", chromeScript);
|
2013-09-15 06:09:13 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: (aMessage) => {
|
|
|
|
let messageId = aMessage.json.id;
|
|
|
|
let name = aMessage.json.name;
|
|
|
|
let message = aMessage.json.message;
|
|
|
|
// Ignore message from other chrome script
|
|
|
|
if (messageId != id)
|
|
|
|
return;
|
|
|
|
|
2014-03-25 20:03:21 +04:00
|
|
|
if (aMessage.name == "SPChromeScriptMessage") {
|
|
|
|
listeners.filter(o => (o.name == name))
|
2015-01-17 00:40:46 +03:00
|
|
|
.forEach(o => o.listener(message));
|
2014-03-25 20:03:21 +04:00
|
|
|
} else if (aMessage.name == "SPChromeScriptAssert") {
|
|
|
|
assert(aMessage.json);
|
|
|
|
}
|
2013-09-15 06:09:13 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
this._addMessageListener("SPChromeScriptMessage", chromeScript);
|
2014-03-25 20:03:21 +04:00
|
|
|
this._addMessageListener("SPChromeScriptAssert", chromeScript);
|
|
|
|
|
|
|
|
let assert = json => {
|
|
|
|
// An assertion has been done in a mochitest chrome script
|
|
|
|
let {url, err, message, stack} = json;
|
|
|
|
|
|
|
|
// Try to fetch a test runner from the mochitest
|
|
|
|
// in order to properly log these assertions and notify
|
|
|
|
// all usefull log observers
|
|
|
|
let window = this.window.get();
|
|
|
|
let parentRunner, repr = function (o) o;
|
|
|
|
if (window) {
|
|
|
|
window = window.wrappedJSObject;
|
|
|
|
parentRunner = window.TestRunner;
|
|
|
|
if (window.repr) {
|
|
|
|
repr = window.repr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Craft a mochitest-like report string
|
|
|
|
var resultString = err ? "TEST-UNEXPECTED-FAIL" : "TEST-PASS";
|
|
|
|
var diagnostic =
|
|
|
|
message ? message :
|
|
|
|
("assertion @ " + stack.filename + ":" + stack.lineNumber);
|
|
|
|
if (err) {
|
|
|
|
diagnostic +=
|
|
|
|
" - got " + repr(err.actual) +
|
|
|
|
", expected " + repr(err.expected) +
|
|
|
|
" (operator " + err.operator + ")";
|
|
|
|
}
|
|
|
|
var msg = [resultString, url, diagnostic].join(" | ");
|
|
|
|
if (parentRunner) {
|
|
|
|
if (err) {
|
|
|
|
parentRunner.addFailedTest(url);
|
|
|
|
parentRunner.error(msg);
|
|
|
|
} else {
|
|
|
|
parentRunner.log(msg);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// When we are running only a single mochitest, there is no test runner
|
|
|
|
dump(msg + "\n");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-15 06:09:13 +04:00
|
|
|
return this.wrap(chromeScript);
|
|
|
|
},
|
|
|
|
|
2012-08-04 00:19:54 +04:00
|
|
|
get Services() {
|
|
|
|
return wrapPrivileged(Services);
|
|
|
|
},
|
|
|
|
|
2014-01-15 06:49:29 +04:00
|
|
|
/*
|
|
|
|
* In general, any Components object created for unprivileged scopes is
|
|
|
|
* neutered (it implements nsIXPCComponentsBase, but not nsIXPCComponents).
|
|
|
|
* We override this in certain legacy automation configurations (see the
|
|
|
|
* implementation of getRawComponents() above), but don't want to support
|
|
|
|
* it in cases where it isn't already required.
|
|
|
|
*
|
|
|
|
* In scopes with neutered Components, we don't have a natural referent for
|
|
|
|
* things like SpecialPowers.Cc. So in those cases, we fall back to the
|
|
|
|
* Components object from the SpecialPowers scope. This doesn't quite behave
|
|
|
|
* the same way (in particular, SpecialPowers.Cc[foo].createInstance() will
|
|
|
|
* create an instance in the SpecialPowers scope), but SpecialPowers wrapping
|
|
|
|
* is already a YMMV / Whatever-It-Takes-To-Get-TBPL-Green sort of thing.
|
|
|
|
*
|
|
|
|
* It probably wouldn't be too much work to just make SpecialPowers.Components
|
|
|
|
* unconditionally point to the Components object in the SpecialPowers scope.
|
|
|
|
* Try will tell what needs to be fixed up.
|
|
|
|
*/
|
|
|
|
getFullComponents: function() {
|
|
|
|
return typeof this.Components.classes == 'object' ? this.Components
|
|
|
|
: Components;
|
|
|
|
},
|
|
|
|
|
2012-09-24 16:46:27 +04:00
|
|
|
/*
|
|
|
|
* Convenient shortcuts to the standard Components abbreviations. Note that
|
|
|
|
* we don't SpecialPowers-wrap Components.interfaces, because it's available
|
|
|
|
* to untrusted content, and wrapping it confuses QI and identity checks.
|
|
|
|
*/
|
2015-01-13 04:07:00 +03:00
|
|
|
get Cc() { return wrapPrivileged(this.getFullComponents().classes); },
|
2012-09-24 16:46:27 +04:00
|
|
|
get Ci() { return this.Components.interfaces; },
|
2015-01-13 04:07:00 +03:00
|
|
|
get Cu() { return wrapPrivileged(this.getFullComponents().utils); },
|
|
|
|
get Cr() { return wrapPrivileged(this.Components.results); },
|
2012-09-24 16:46:27 +04:00
|
|
|
|
|
|
|
/*
|
2014-01-15 06:49:29 +04:00
|
|
|
* SpecialPowers.getRawComponents() allows content to get a reference to a
|
|
|
|
* naked (and, in certain automation configurations, privileged) Components
|
|
|
|
* object for its scope.
|
2012-09-24 16:46:27 +04:00
|
|
|
*
|
|
|
|
* SpecialPowers.getRawComponents(window) is defined as the global property
|
|
|
|
* window.SpecialPowers.Components for convenience.
|
|
|
|
*/
|
|
|
|
getRawComponents: getRawComponents,
|
|
|
|
|
2011-10-06 18:51:03 +04:00
|
|
|
getDOMWindowUtils: function(aWindow) {
|
2012-04-02 06:23:51 +04:00
|
|
|
if (aWindow == this.window.get() && this.DOMWindowUtils != null)
|
2011-10-06 18:51:03 +04:00
|
|
|
return this.DOMWindowUtils;
|
|
|
|
|
|
|
|
return bindDOMWindowUtils(aWindow);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeExpectedCrashDumpFiles: function(aExpectingProcessCrash) {
|
|
|
|
var success = true;
|
|
|
|
if (aExpectingProcessCrash) {
|
|
|
|
var message = {
|
|
|
|
op: "delete-crash-dump-files",
|
2013-02-09 00:25:37 +04:00
|
|
|
filenames: this._encounteredCrashDumpFiles
|
2011-10-06 18:51:03 +04:00
|
|
|
};
|
|
|
|
if (!this._sendSyncMessage("SPProcessCrashService", message)[0]) {
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._encounteredCrashDumpFiles.length = 0;
|
|
|
|
return success;
|
|
|
|
},
|
|
|
|
|
|
|
|
findUnexpectedCrashDumpFiles: function() {
|
|
|
|
var self = this;
|
|
|
|
var message = {
|
|
|
|
op: "find-crash-dump-files",
|
|
|
|
crashDumpFilesToIgnore: this._unexpectedCrashDumpFiles
|
|
|
|
};
|
|
|
|
var crashDumpFiles = this._sendSyncMessage("SPProcessCrashService", message)[0];
|
|
|
|
crashDumpFiles.forEach(function(aFilename) {
|
|
|
|
self._unexpectedCrashDumpFiles[aFilename] = true;
|
|
|
|
});
|
|
|
|
return crashDumpFiles;
|
|
|
|
},
|
|
|
|
|
2014-07-13 19:00:26 +04:00
|
|
|
_setTimeout: function(callback) {
|
|
|
|
// for mochitest-browser
|
|
|
|
if (typeof window != 'undefined')
|
|
|
|
setTimeout(callback, 0);
|
|
|
|
// for mochitest-plain
|
|
|
|
else
|
|
|
|
content.window.setTimeout(callback, 0);
|
|
|
|
},
|
|
|
|
|
2014-01-16 18:35:38 +04:00
|
|
|
_delayCallbackTwice: function(callback) {
|
2014-07-13 19:00:26 +04:00
|
|
|
function delayedCallback() {
|
|
|
|
function delayAgain(aCallback) {
|
|
|
|
// Using this._setTimeout doesn't work here
|
|
|
|
// It causes failures in mochtests that use
|
|
|
|
// multiple pushPrefEnv calls
|
|
|
|
// For chrome/browser-chrome mochitests
|
|
|
|
if (typeof window != 'undefined')
|
|
|
|
setTimeout(aCallback, 0);
|
|
|
|
// For mochitest-plain
|
|
|
|
else
|
|
|
|
content.window.setTimeout(aCallback, 0);
|
|
|
|
}
|
|
|
|
delayAgain(delayAgain(callback));
|
|
|
|
}
|
|
|
|
return delayedCallback;
|
2014-01-16 18:35:38 +04:00
|
|
|
},
|
|
|
|
|
2013-03-29 16:43:27 +04:00
|
|
|
/* apply permissions to the system and when the test case is finished (SimpleTest.finish())
|
|
|
|
we will revert the permission back to the original.
|
|
|
|
|
|
|
|
inPermissions is an array of objects where each object has a type, action, context, ex:
|
|
|
|
[{'type': 'SystemXHR', 'allow': 1, 'context': document},
|
2013-05-17 12:46:36 +04:00
|
|
|
{'type': 'SystemXHR', 'allow': Ci.nsIPermissionManager.PROMPT_ACTION, 'context': document}]
|
2013-03-29 16:43:27 +04:00
|
|
|
|
2013-08-26 22:05:20 +04:00
|
|
|
Allow can be a boolean value of true/false or ALLOW_ACTION/DENY_ACTION/PROMPT_ACTION/UNKNOWN_ACTION
|
2013-03-29 16:43:27 +04:00
|
|
|
*/
|
|
|
|
pushPermissions: function(inPermissions, callback) {
|
2014-05-28 22:14:27 +04:00
|
|
|
inPermissions = Cu.waiveXrays(inPermissions);
|
2013-03-29 16:43:27 +04:00
|
|
|
var pendingPermissions = [];
|
|
|
|
var cleanupPermissions = [];
|
|
|
|
|
|
|
|
for (var p in inPermissions) {
|
|
|
|
var permission = inPermissions[p];
|
|
|
|
var originalValue = Ci.nsIPermissionManager.UNKNOWN_ACTION;
|
2014-05-28 22:14:27 +04:00
|
|
|
var context = Cu.unwaiveXrays(permission.context); // Sometimes |context| is a DOM object on which we expect
|
|
|
|
// to be able to access .nodePrincipal, so we need to unwaive.
|
|
|
|
if (this.testPermission(permission.type, Ci.nsIPermissionManager.ALLOW_ACTION, context)) {
|
2013-03-29 16:43:27 +04:00
|
|
|
originalValue = Ci.nsIPermissionManager.ALLOW_ACTION;
|
2014-05-28 22:14:27 +04:00
|
|
|
} else if (this.testPermission(permission.type, Ci.nsIPermissionManager.DENY_ACTION, context)) {
|
2013-03-29 16:43:27 +04:00
|
|
|
originalValue = Ci.nsIPermissionManager.DENY_ACTION;
|
2014-05-28 22:14:27 +04:00
|
|
|
} else if (this.testPermission(permission.type, Ci.nsIPermissionManager.PROMPT_ACTION, context)) {
|
2013-05-17 12:46:36 +04:00
|
|
|
originalValue = Ci.nsIPermissionManager.PROMPT_ACTION;
|
2014-05-28 22:14:27 +04:00
|
|
|
} else if (this.testPermission(permission.type, Ci.nsICookiePermission.ACCESS_SESSION, context)) {
|
2013-09-16 19:15:22 +04:00
|
|
|
originalValue = Ci.nsICookiePermission.ACCESS_SESSION;
|
2014-05-28 22:14:27 +04:00
|
|
|
} else if (this.testPermission(permission.type, Ci.nsICookiePermission.ACCESS_ALLOW_FIRST_PARTY_ONLY, context)) {
|
2013-09-16 19:15:22 +04:00
|
|
|
originalValue = Ci.nsICookiePermission.ACCESS_ALLOW_FIRST_PARTY_ONLY;
|
2014-05-28 22:14:27 +04:00
|
|
|
} else if (this.testPermission(permission.type, Ci.nsICookiePermission.ACCESS_LIMIT_THIRD_PARTY, context)) {
|
2013-09-16 19:15:22 +04:00
|
|
|
originalValue = Ci.nsICookiePermission.ACCESS_LIMIT_THIRD_PARTY;
|
2013-03-29 16:43:27 +04:00
|
|
|
}
|
|
|
|
|
2014-07-29 03:17:50 +04:00
|
|
|
let [url, appId, isInBrowserElement, isSystem] = this._getInfoFromPermissionArg(context);
|
|
|
|
if (isSystem) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-29 16:43:27 +04:00
|
|
|
|
2013-05-17 12:46:36 +04:00
|
|
|
let perm;
|
|
|
|
if (typeof permission.allow !== 'boolean') {
|
|
|
|
perm = permission.allow;
|
|
|
|
} else {
|
|
|
|
perm = permission.allow ? Ci.nsIPermissionManager.ALLOW_ACTION
|
|
|
|
: Ci.nsIPermissionManager.DENY_ACTION;
|
|
|
|
}
|
2013-03-29 16:43:27 +04:00
|
|
|
|
2013-08-30 01:12:15 +04:00
|
|
|
if (permission.remove == true)
|
|
|
|
perm = Ci.nsIPermissionManager.UNKNOWN_ACTION;
|
|
|
|
|
2013-03-29 16:43:27 +04:00
|
|
|
if (originalValue == perm) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-08-26 22:05:20 +04:00
|
|
|
|
|
|
|
var todo = {'op': 'add', 'type': permission.type, 'permission': perm, 'value': perm, 'url': url, 'appId': appId, 'isInBrowserElement': isInBrowserElement};
|
|
|
|
if (permission.remove == true)
|
|
|
|
todo.op = 'remove';
|
|
|
|
|
|
|
|
pendingPermissions.push(todo);
|
2013-03-29 16:43:27 +04:00
|
|
|
|
|
|
|
/* Push original permissions value or clear into cleanup array */
|
|
|
|
var cleanupTodo = {'op': 'add', 'type': permission.type, 'permission': perm, 'value': perm, 'url': url, 'appId': appId, 'isInBrowserElement': isInBrowserElement};
|
|
|
|
if (originalValue == Ci.nsIPermissionManager.UNKNOWN_ACTION) {
|
|
|
|
cleanupTodo.op = 'remove';
|
|
|
|
} else {
|
2013-05-17 12:46:36 +04:00
|
|
|
cleanupTodo.value = originalValue;
|
|
|
|
cleanupTodo.permission = originalValue;
|
2013-03-29 16:43:27 +04:00
|
|
|
}
|
|
|
|
cleanupPermissions.push(cleanupTodo);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pendingPermissions.length > 0) {
|
|
|
|
// The callback needs to be delayed twice. One delay is because the pref
|
|
|
|
// service doesn't guarantee the order it calls its observers in, so it
|
|
|
|
// may notify the observer holding the callback before the other
|
|
|
|
// observers have been notified and given a chance to make the changes
|
|
|
|
// that the callback checks for. The second delay is because pref
|
|
|
|
// observers often defer making their changes by posting an event to the
|
|
|
|
// event loop.
|
|
|
|
this._permissionsUndoStack.push(cleanupPermissions);
|
2014-01-16 18:35:38 +04:00
|
|
|
this._pendingPermissions.push([pendingPermissions,
|
|
|
|
this._delayCallbackTwice(callback)]);
|
2013-03-29 16:43:27 +04:00
|
|
|
this._applyPermissions();
|
|
|
|
} else {
|
2014-07-13 19:00:26 +04:00
|
|
|
this._setTimeout(callback);
|
2013-03-29 16:43:27 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
popPermissions: function(callback) {
|
|
|
|
if (this._permissionsUndoStack.length > 0) {
|
|
|
|
// See pushPermissions comment regarding delay.
|
2014-01-16 18:35:38 +04:00
|
|
|
let cb = callback ? this._delayCallbackTwice(callback) : null;
|
2013-03-29 16:43:27 +04:00
|
|
|
/* Each pop from the stack will yield an object {op/type/permission/value/url/appid/isInBrowserElement} or null */
|
|
|
|
this._pendingPermissions.push([this._permissionsUndoStack.pop(), cb]);
|
|
|
|
this._applyPermissions();
|
|
|
|
} else {
|
2014-07-13 19:00:26 +04:00
|
|
|
this._setTimeout(callback);
|
2013-03-29 16:43:27 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
flushPermissions: function(callback) {
|
|
|
|
while (this._permissionsUndoStack.length > 1)
|
|
|
|
this.popPermissions(null);
|
|
|
|
|
|
|
|
this.popPermissions(callback);
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2014-10-29 18:04:51 +03:00
|
|
|
setTestPluginEnabledState: function(newEnabledState, pluginName) {
|
|
|
|
return this._sendSyncMessage("SPSetTestPluginEnabledState",
|
|
|
|
{ newEnabledState: newEnabledState, pluginName: pluginName })[0];
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2013-03-29 16:43:27 +04:00
|
|
|
_permissionObserver: {
|
2014-07-13 19:00:26 +04:00
|
|
|
_self: null,
|
2013-03-29 16:43:27 +04:00
|
|
|
_lastPermission: {},
|
|
|
|
_callBack: null,
|
|
|
|
_nextCallback: null,
|
|
|
|
|
|
|
|
observe: function (aSubject, aTopic, aData)
|
|
|
|
{
|
|
|
|
if (aTopic == "perm-changed") {
|
|
|
|
var permission = aSubject.QueryInterface(Ci.nsIPermission);
|
|
|
|
if (permission.type == this._lastPermission.type) {
|
2014-04-29 19:31:12 +04:00
|
|
|
Services.obs.removeObserver(this, "perm-changed");
|
2014-07-13 19:00:26 +04:00
|
|
|
this._self._setTimeout(this._callback);
|
|
|
|
this._self._setTimeout(this._nextCallback);
|
2013-03-29 16:43:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
Iterate through one atomic set of permissions actions and perform allow/deny as appropriate.
|
|
|
|
All actions performed must modify the relevant permission.
|
|
|
|
*/
|
|
|
|
_applyPermissions: function() {
|
|
|
|
if (this._applyingPermissions || this._pendingPermissions.length <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set lock and get prefs from the _pendingPrefs queue */
|
|
|
|
this._applyingPermissions = true;
|
|
|
|
var transaction = this._pendingPermissions.shift();
|
|
|
|
var pendingActions = transaction[0];
|
|
|
|
var callback = transaction[1];
|
2014-02-12 09:36:23 +04:00
|
|
|
var lastPermission = pendingActions[pendingActions.length-1];
|
2013-03-29 16:43:27 +04:00
|
|
|
|
|
|
|
var self = this;
|
2014-07-13 19:00:26 +04:00
|
|
|
this._permissionObserver._self = self;
|
2013-03-29 16:43:27 +04:00
|
|
|
this._permissionObserver._lastPermission = lastPermission;
|
|
|
|
this._permissionObserver._callback = callback;
|
|
|
|
this._permissionObserver._nextCallback = function () {
|
|
|
|
self._applyingPermissions = false;
|
|
|
|
// Now apply any permissions that may have been queued while we were applying
|
|
|
|
self._applyPermissions();
|
|
|
|
}
|
|
|
|
|
2014-04-29 19:31:12 +04:00
|
|
|
Services.obs.addObserver(this._permissionObserver, "perm-changed", false);
|
2013-03-29 16:43:27 +04:00
|
|
|
|
|
|
|
for (var idx in pendingActions) {
|
|
|
|
var perm = pendingActions[idx];
|
|
|
|
this._sendSyncMessage('SPPermissionManager', perm)[0];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-10-06 18:51:03 +04:00
|
|
|
/*
|
2012-10-02 20:04:24 +04:00
|
|
|
* Take in a list of pref changes to make, and invoke |callback| once those
|
|
|
|
* changes have taken effect. When the test finishes, these changes are
|
|
|
|
* reverted.
|
2011-10-06 18:51:03 +04:00
|
|
|
*
|
2012-10-02 20:04:24 +04:00
|
|
|
* |inPrefs| must be an object with up to two properties: "set" and "clear".
|
|
|
|
* pushPrefEnv will set prefs as indicated in |inPrefs.set| and will unset
|
|
|
|
* the prefs indicated in |inPrefs.clear|.
|
2011-10-06 18:51:03 +04:00
|
|
|
*
|
2012-10-02 20:04:24 +04:00
|
|
|
* For example, you might pass |inPrefs| as:
|
2011-10-06 18:51:03 +04:00
|
|
|
*
|
2012-10-02 20:04:24 +04:00
|
|
|
* inPrefs = {'set': [['foo.bar', 2], ['magic.pref', 'baz']],
|
|
|
|
* 'clear': [['clear.this'], ['also.this']] };
|
|
|
|
*
|
|
|
|
* Notice that |set| and |clear| are both an array of arrays. In |set|, each
|
|
|
|
* of the inner arrays must have the form [pref_name, value] or [pref_name,
|
|
|
|
* value, iid]. (The latter form is used for prefs with "complex" values.)
|
|
|
|
*
|
|
|
|
* In |clear|, each inner array should have the form [pref_name].
|
|
|
|
*
|
|
|
|
* If you set the same pref more than once (or both set and clear a pref),
|
|
|
|
* the behavior of this method is undefined.
|
|
|
|
*
|
|
|
|
* (Implementation note: _prefEnvUndoStack is a stack of values to revert to,
|
|
|
|
* not values which have been set!)
|
2011-10-06 18:51:03 +04:00
|
|
|
*
|
|
|
|
* TODO: complex values for original cleanup?
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
pushPrefEnv: function(inPrefs, callback) {
|
2014-04-29 19:31:12 +04:00
|
|
|
var prefs = Services.prefs;
|
2011-10-06 18:51:03 +04:00
|
|
|
|
|
|
|
var pref_string = [];
|
|
|
|
pref_string[prefs.PREF_INT] = "INT";
|
|
|
|
pref_string[prefs.PREF_BOOL] = "BOOL";
|
2012-10-18 16:03:31 +04:00
|
|
|
pref_string[prefs.PREF_STRING] = "CHAR";
|
2011-10-06 18:51:03 +04:00
|
|
|
|
|
|
|
var pendingActions = [];
|
|
|
|
var cleanupActions = [];
|
|
|
|
|
|
|
|
for (var action in inPrefs) { /* set|clear */
|
|
|
|
for (var idx in inPrefs[action]) {
|
|
|
|
var aPref = inPrefs[action][idx];
|
|
|
|
var prefName = aPref[0];
|
|
|
|
var prefValue = null;
|
|
|
|
var prefIid = null;
|
|
|
|
var prefType = prefs.PREF_INVALID;
|
|
|
|
var originalValue = null;
|
|
|
|
|
|
|
|
if (aPref.length == 3) {
|
|
|
|
prefValue = aPref[1];
|
|
|
|
prefIid = aPref[2];
|
|
|
|
} else if (aPref.length == 2) {
|
|
|
|
prefValue = aPref[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If pref is not found or invalid it doesn't exist. */
|
|
|
|
if (prefs.getPrefType(prefName) != prefs.PREF_INVALID) {
|
|
|
|
prefType = pref_string[prefs.getPrefType(prefName)];
|
|
|
|
if ((prefs.prefHasUserValue(prefName) && action == 'clear') ||
|
|
|
|
(action == 'set'))
|
|
|
|
originalValue = this._getPref(prefName, prefType);
|
|
|
|
} else if (action == 'set') {
|
|
|
|
/* prefName doesn't exist, so 'clear' is pointless */
|
|
|
|
if (aPref.length == 3) {
|
|
|
|
prefType = "COMPLEX";
|
|
|
|
} else if (aPref.length == 2) {
|
2013-02-09 00:25:37 +04:00
|
|
|
if (typeof(prefValue) == "boolean")
|
2011-10-06 18:51:03 +04:00
|
|
|
prefType = "BOOL";
|
|
|
|
else if (typeof(prefValue) == "number")
|
|
|
|
prefType = "INT";
|
|
|
|
else if (typeof(prefValue) == "string")
|
|
|
|
prefType = "CHAR";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PREF_INVALID: A non existing pref which we are clearing or invalid values for a set */
|
|
|
|
if (prefType == prefs.PREF_INVALID)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* We are not going to set a pref if the value is the same */
|
|
|
|
if (originalValue == prefValue)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pendingActions.push({'action': action, 'type': prefType, 'name': prefName, 'value': prefValue, 'Iid': prefIid});
|
|
|
|
|
|
|
|
/* Push original preference value or clear into cleanup array */
|
|
|
|
var cleanupTodo = {'action': action, 'type': prefType, 'name': prefName, 'value': originalValue, 'Iid': prefIid};
|
|
|
|
if (originalValue == null) {
|
|
|
|
cleanupTodo.action = 'clear';
|
|
|
|
} else {
|
|
|
|
cleanupTodo.action = 'set';
|
|
|
|
}
|
|
|
|
cleanupActions.push(cleanupTodo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pendingActions.length > 0) {
|
2012-01-28 02:16:44 +04:00
|
|
|
// The callback needs to be delayed twice. One delay is because the pref
|
|
|
|
// service doesn't guarantee the order it calls its observers in, so it
|
|
|
|
// may notify the observer holding the callback before the other
|
|
|
|
// observers have been notified and given a chance to make the changes
|
|
|
|
// that the callback checks for. The second delay is because pref
|
|
|
|
// observers often defer making their changes by posting an event to the
|
|
|
|
// event loop.
|
2011-10-06 18:51:03 +04:00
|
|
|
this._prefEnvUndoStack.push(cleanupActions);
|
2014-01-16 18:35:38 +04:00
|
|
|
this._pendingPrefs.push([pendingActions,
|
|
|
|
this._delayCallbackTwice(callback)]);
|
2011-10-06 18:51:03 +04:00
|
|
|
this._applyPrefs();
|
|
|
|
} else {
|
2014-07-13 19:00:26 +04:00
|
|
|
this._setTimeout(callback);
|
2011-10-06 18:51:03 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
popPrefEnv: function(callback) {
|
|
|
|
if (this._prefEnvUndoStack.length > 0) {
|
2012-01-28 02:16:44 +04:00
|
|
|
// See pushPrefEnv comment regarding delay.
|
2014-01-16 18:35:38 +04:00
|
|
|
let cb = callback ? this._delayCallbackTwice(callback) : null;
|
2011-10-06 18:51:03 +04:00
|
|
|
/* Each pop will have a valid block of preferences */
|
2012-01-28 02:16:44 +04:00
|
|
|
this._pendingPrefs.push([this._prefEnvUndoStack.pop(), cb]);
|
2011-10-06 18:51:03 +04:00
|
|
|
this._applyPrefs();
|
|
|
|
} else {
|
2014-07-13 19:00:26 +04:00
|
|
|
this._setTimeout(callback);
|
2011-10-06 18:51:03 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
flushPrefEnv: function(callback) {
|
|
|
|
while (this._prefEnvUndoStack.length > 1)
|
|
|
|
this.popPrefEnv(null);
|
|
|
|
|
|
|
|
this.popPrefEnv(callback);
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
2013-02-09 00:25:37 +04:00
|
|
|
Iterate through one atomic set of pref actions and perform sets/clears as appropriate.
|
2011-10-06 18:51:03 +04:00
|
|
|
All actions performed must modify the relevant pref.
|
|
|
|
*/
|
|
|
|
_applyPrefs: function() {
|
|
|
|
if (this._applyingPrefs || this._pendingPrefs.length <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set lock and get prefs from the _pendingPrefs queue */
|
|
|
|
this._applyingPrefs = true;
|
|
|
|
var transaction = this._pendingPrefs.shift();
|
|
|
|
var pendingActions = transaction[0];
|
|
|
|
var callback = transaction[1];
|
|
|
|
|
|
|
|
var lastPref = pendingActions[pendingActions.length-1];
|
2012-02-19 05:33:18 +04:00
|
|
|
|
2014-04-29 19:31:12 +04:00
|
|
|
var pb = Services.prefs;
|
2012-02-19 05:33:18 +04:00
|
|
|
var self = this;
|
|
|
|
pb.addObserver(lastPref.name, function prefObs(subject, topic, data) {
|
|
|
|
pb.removeObserver(lastPref.name, prefObs);
|
|
|
|
|
2014-07-13 19:00:26 +04:00
|
|
|
self._setTimeout(callback);
|
|
|
|
self._setTimeout(function () {
|
2012-02-19 05:33:18 +04:00
|
|
|
self._applyingPrefs = false;
|
|
|
|
// Now apply any prefs that may have been queued while we were applying
|
|
|
|
self._applyPrefs();
|
2014-07-13 19:00:26 +04:00
|
|
|
});
|
2012-02-19 05:33:18 +04:00
|
|
|
}, false);
|
2011-10-06 18:51:03 +04:00
|
|
|
|
|
|
|
for (var idx in pendingActions) {
|
|
|
|
var pref = pendingActions[idx];
|
|
|
|
if (pref.action == 'set') {
|
|
|
|
this._setPref(pref.name, pref.type, pref.value, pref.Iid);
|
|
|
|
} else if (pref.action == 'clear') {
|
|
|
|
this.clearUserPref(pref.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-01-04 22:21:31 +04:00
|
|
|
// Disables the app install prompt for the duration of this test. There is
|
|
|
|
// no need to re-enable the prompt at the end of the test.
|
|
|
|
//
|
|
|
|
// The provided callback is invoked once the prompt is disabled.
|
|
|
|
autoConfirmAppInstall: function(cb) {
|
|
|
|
this.pushPrefEnv({set: [['dom.mozApps.auto_confirm_install', true]]}, cb);
|
|
|
|
},
|
|
|
|
|
2014-06-12 01:37:03 +04:00
|
|
|
autoConfirmAppUninstall: function(cb) {
|
|
|
|
this.pushPrefEnv({set: [['dom.mozApps.auto_confirm_uninstall', true]]}, cb);
|
|
|
|
},
|
|
|
|
|
2013-04-05 04:58:44 +04:00
|
|
|
// Allow tests to disable the per platform app validity checks so we can
|
|
|
|
// test higher level WebApp functionality without full platform support.
|
|
|
|
setAllAppsLaunchable: function(launchable) {
|
2014-04-18 00:43:04 +04:00
|
|
|
this._sendSyncMessage("SPWebAppService", {
|
2013-04-05 04:58:44 +04:00
|
|
|
op: "set-launchable",
|
|
|
|
launchable: launchable
|
2014-04-18 00:43:04 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-12-17 02:32:28 +03:00
|
|
|
// Allow tests to install addons without signing the package, for convenience.
|
|
|
|
allowUnsignedAddons: function() {
|
|
|
|
this._sendSyncMessage("SPWebAppService", {
|
|
|
|
op: "allow-unsigned-addons"
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-01-17 01:16:03 +03:00
|
|
|
// Turn on debug information from UserCustomizations.jsm
|
|
|
|
debugUserCustomizations: function(value) {
|
|
|
|
this._sendSyncMessage("SPWebAppService", {
|
|
|
|
op: "debug-customizations",
|
|
|
|
value: value
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-04-18 00:43:04 +04:00
|
|
|
// Restore the launchable property to its default value.
|
|
|
|
flushAllAppsLaunchable: function() {
|
|
|
|
this._sendSyncMessage("SPWebAppService", {
|
|
|
|
op: "set-launchable",
|
|
|
|
launchable: false
|
|
|
|
});
|
2013-04-05 04:58:44 +04:00
|
|
|
},
|
|
|
|
|
2013-12-12 04:57:19 +04:00
|
|
|
_proxiedObservers: {
|
|
|
|
"specialpowers-http-notify-request": function(aMessage) {
|
|
|
|
let uri = aMessage.json.uri;
|
|
|
|
Services.obs.notifyObservers(null, "specialpowers-http-notify-request", uri);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
_addObserverProxy: function(notification) {
|
|
|
|
if (notification in this._proxiedObservers) {
|
|
|
|
this._addMessageListener(notification, this._proxiedObservers[notification]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_removeObserverProxy: function(notification) {
|
|
|
|
if (notification in this._proxiedObservers) {
|
|
|
|
this._removeMessageListener(notification, this._proxiedObservers[notification]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-10-14 22:24:10 +04:00
|
|
|
addObserver: function(obs, notification, weak) {
|
2013-12-12 04:57:19 +04:00
|
|
|
this._addObserverProxy(notification);
|
2014-05-28 22:14:27 +04:00
|
|
|
obs = Cu.waiveXrays(obs);
|
2013-06-05 06:56:42 +04:00
|
|
|
if (typeof obs == 'object' && obs.observe.name != 'SpecialPowersCallbackWrapper')
|
|
|
|
obs.observe = wrapCallback(obs.observe);
|
2014-04-29 19:31:12 +04:00
|
|
|
Services.obs.addObserver(obs, notification, weak);
|
2011-10-14 22:24:10 +04:00
|
|
|
},
|
|
|
|
removeObserver: function(obs, notification) {
|
2013-12-12 04:57:19 +04:00
|
|
|
this._removeObserverProxy(notification);
|
2014-05-28 22:14:27 +04:00
|
|
|
Services.obs.removeObserver(Cu.waiveXrays(obs), notification);
|
2011-10-14 22:24:10 +04:00
|
|
|
},
|
2013-05-11 01:22:01 +04:00
|
|
|
notifyObservers: function(subject, topic, data) {
|
2014-04-29 19:31:12 +04:00
|
|
|
Services.obs.notifyObservers(subject, topic, data);
|
2013-05-11 01:22:01 +04:00
|
|
|
},
|
2013-02-09 00:25:37 +04:00
|
|
|
|
2011-10-14 22:24:10 +04:00
|
|
|
can_QI: function(obj) {
|
|
|
|
return obj.QueryInterface !== undefined;
|
|
|
|
},
|
|
|
|
do_QueryInterface: function(obj, iface) {
|
2013-02-09 00:25:37 +04:00
|
|
|
return obj.QueryInterface(Ci[iface]);
|
2011-10-14 22:24:10 +04:00
|
|
|
},
|
|
|
|
|
2012-08-09 00:08:42 +04:00
|
|
|
call_Instanceof: function (obj1, obj2) {
|
|
|
|
obj1=unwrapIfWrapped(obj1);
|
|
|
|
obj2=unwrapIfWrapped(obj2);
|
|
|
|
return obj1 instanceof obj2;
|
|
|
|
},
|
|
|
|
|
2013-03-08 04:10:54 +04:00
|
|
|
// Returns a privileged getter from an object. GetOwnPropertyDescriptor does
|
|
|
|
// not work here because xray wrappers don't properly implement it.
|
|
|
|
//
|
2014-10-25 21:25:22 +04:00
|
|
|
// This terribleness is used by dom/base/test/test_object.html because
|
2013-03-08 04:10:54 +04:00
|
|
|
// <object> and <embed> tags will spawn plugins if their prototype is touched,
|
|
|
|
// so we need to get and cache the getter of |hasRunningPlugin| if we want to
|
|
|
|
// call it without paradoxically spawning the plugin.
|
|
|
|
do_lookupGetter: function(obj, name) {
|
|
|
|
return Object.prototype.__lookupGetter__.call(obj, name);
|
|
|
|
},
|
|
|
|
|
2011-10-06 18:51:03 +04:00
|
|
|
// Mimic the get*Pref API
|
|
|
|
getBoolPref: function(aPrefName) {
|
|
|
|
return (this._getPref(aPrefName, 'BOOL'));
|
|
|
|
},
|
|
|
|
getIntPref: function(aPrefName) {
|
|
|
|
return (this._getPref(aPrefName, 'INT'));
|
|
|
|
},
|
|
|
|
getCharPref: function(aPrefName) {
|
|
|
|
return (this._getPref(aPrefName, 'CHAR'));
|
|
|
|
},
|
|
|
|
getComplexValue: function(aPrefName, aIid) {
|
|
|
|
return (this._getPref(aPrefName, 'COMPLEX', aIid));
|
|
|
|
},
|
|
|
|
|
|
|
|
// Mimic the set*Pref API
|
|
|
|
setBoolPref: function(aPrefName, aValue) {
|
|
|
|
return (this._setPref(aPrefName, 'BOOL', aValue));
|
|
|
|
},
|
|
|
|
setIntPref: function(aPrefName, aValue) {
|
|
|
|
return (this._setPref(aPrefName, 'INT', aValue));
|
|
|
|
},
|
|
|
|
setCharPref: function(aPrefName, aValue) {
|
|
|
|
return (this._setPref(aPrefName, 'CHAR', aValue));
|
|
|
|
},
|
|
|
|
setComplexValue: function(aPrefName, aIid, aValue) {
|
|
|
|
return (this._setPref(aPrefName, 'COMPLEX', aValue, aIid));
|
|
|
|
},
|
|
|
|
|
|
|
|
// Mimic the clearUserPref API
|
|
|
|
clearUserPref: function(aPrefName) {
|
|
|
|
var msg = {'op':'clear', 'prefName': aPrefName, 'prefType': ""};
|
|
|
|
this._sendSyncMessage('SPPrefService', msg);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Private pref functions to communicate to chrome
|
|
|
|
_getPref: function(aPrefName, aPrefType, aIid) {
|
|
|
|
var msg = {};
|
|
|
|
if (aIid) {
|
|
|
|
// Overloading prefValue to handle complex prefs
|
|
|
|
msg = {'op':'get', 'prefName': aPrefName, 'prefType':aPrefType, 'prefValue':[aIid]};
|
|
|
|
} else {
|
|
|
|
msg = {'op':'get', 'prefName': aPrefName,'prefType': aPrefType};
|
|
|
|
}
|
|
|
|
var val = this._sendSyncMessage('SPPrefService', msg);
|
|
|
|
|
|
|
|
if (val == null || val[0] == null)
|
|
|
|
throw "Error getting pref";
|
|
|
|
return val[0];
|
|
|
|
},
|
|
|
|
_setPref: function(aPrefName, aPrefType, aValue, aIid) {
|
|
|
|
var msg = {};
|
|
|
|
if (aIid) {
|
|
|
|
msg = {'op':'set','prefName':aPrefName, 'prefType': aPrefType, 'prefValue': [aIid,aValue]};
|
|
|
|
} else {
|
|
|
|
msg = {'op':'set', 'prefName': aPrefName, 'prefType': aPrefType, 'prefValue': aValue};
|
|
|
|
}
|
|
|
|
return(this._sendSyncMessage('SPPrefService', msg)[0]);
|
|
|
|
},
|
|
|
|
|
2012-11-17 06:53:32 +04:00
|
|
|
_getDocShell: function(window) {
|
|
|
|
return window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShell);
|
|
|
|
},
|
|
|
|
_getMUDV: function(window) {
|
2014-07-10 01:27:49 +04:00
|
|
|
return this._getDocShell(window).contentViewer;
|
2012-11-17 06:53:32 +04:00
|
|
|
},
|
2011-10-06 18:51:03 +04:00
|
|
|
//XXX: these APIs really ought to be removed, they're not e10s-safe.
|
|
|
|
// (also they're pretty Firefox-specific)
|
|
|
|
_getTopChromeWindow: function(window) {
|
|
|
|
return window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShellTreeItem)
|
|
|
|
.rootTreeItem
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindow)
|
|
|
|
.QueryInterface(Ci.nsIDOMChromeWindow);
|
|
|
|
},
|
|
|
|
_getAutoCompletePopup: function(window) {
|
|
|
|
return this._getTopChromeWindow(window).document
|
|
|
|
.getElementById("PopupAutoComplete");
|
|
|
|
},
|
2013-04-20 02:21:30 +04:00
|
|
|
addAutoCompletePopupEventListener: function(window, eventname, listener) {
|
|
|
|
this._getAutoCompletePopup(window).addEventListener(eventname,
|
2011-10-06 18:51:03 +04:00
|
|
|
listener,
|
|
|
|
false);
|
|
|
|
},
|
2013-04-20 02:21:30 +04:00
|
|
|
removeAutoCompletePopupEventListener: function(window, eventname, listener) {
|
|
|
|
this._getAutoCompletePopup(window).removeEventListener(eventname,
|
2011-10-06 18:51:03 +04:00
|
|
|
listener,
|
|
|
|
false);
|
|
|
|
},
|
2013-04-20 02:21:30 +04:00
|
|
|
get formHistory() {
|
|
|
|
let tmp = {};
|
|
|
|
Cu.import("resource://gre/modules/FormHistory.jsm", tmp);
|
|
|
|
return wrapPrivileged(tmp.FormHistory);
|
|
|
|
},
|
2012-03-27 18:22:56 +04:00
|
|
|
getFormFillController: function(window) {
|
|
|
|
return Components.classes["@mozilla.org/satchel/form-fill-controller;1"]
|
|
|
|
.getService(Components.interfaces.nsIFormFillController);
|
|
|
|
},
|
|
|
|
attachFormFillControllerTo: function(window) {
|
|
|
|
this.getFormFillController()
|
|
|
|
.attachToBrowser(this._getDocShell(window),
|
|
|
|
this._getAutoCompletePopup(window));
|
|
|
|
},
|
|
|
|
detachFormFillControllerFrom: function(window) {
|
|
|
|
this.getFormFillController().detachFromBrowser(this._getDocShell(window));
|
|
|
|
},
|
2011-10-06 18:51:03 +04:00
|
|
|
isBackButtonEnabled: function(window) {
|
|
|
|
return !this._getTopChromeWindow(window).document
|
|
|
|
.getElementById("Browser:Back")
|
|
|
|
.hasAttribute("disabled");
|
|
|
|
},
|
2012-11-17 06:53:32 +04:00
|
|
|
//XXX end of problematic APIs
|
2011-10-06 18:51:03 +04:00
|
|
|
|
|
|
|
addChromeEventListener: function(type, listener, capture, allowUntrusted) {
|
|
|
|
addEventListener(type, listener, capture, allowUntrusted);
|
|
|
|
},
|
|
|
|
removeChromeEventListener: function(type, listener, capture) {
|
|
|
|
removeEventListener(type, listener, capture);
|
|
|
|
},
|
|
|
|
|
2012-11-17 06:53:32 +04:00
|
|
|
// Note: each call to registerConsoleListener MUST be paired with a
|
|
|
|
// call to postConsoleSentinel; when the callback receives the
|
|
|
|
// sentinel it will unregister itself (_after_ calling the
|
|
|
|
// callback). SimpleTest.expectConsoleMessages does this for you.
|
|
|
|
// If you register more than one console listener, a call to
|
|
|
|
// postConsoleSentinel will zap all of them.
|
|
|
|
registerConsoleListener: function(callback) {
|
|
|
|
let listener = new SPConsoleListener(callback);
|
|
|
|
Services.console.registerListener(listener);
|
2012-11-17 00:29:21 +04:00
|
|
|
},
|
2012-11-17 06:53:32 +04:00
|
|
|
postConsoleSentinel: function() {
|
|
|
|
Services.console.logStringMessage("SENTINEL");
|
|
|
|
},
|
|
|
|
resetConsole: function() {
|
|
|
|
Services.console.reset();
|
2011-10-06 18:51:03 +04:00
|
|
|
},
|
|
|
|
|
2012-09-06 01:39:34 +04:00
|
|
|
getMaxLineBoxWidth: function(window) {
|
|
|
|
return this._getMUDV(window).maxLineBoxWidth;
|
|
|
|
},
|
|
|
|
|
|
|
|
setMaxLineBoxWidth: function(window, width) {
|
|
|
|
this._getMUDV(window).changeMaxLineBoxWidth(width);
|
|
|
|
},
|
|
|
|
|
2011-10-06 18:51:03 +04:00
|
|
|
getFullZoom: function(window) {
|
|
|
|
return this._getMUDV(window).fullZoom;
|
|
|
|
},
|
|
|
|
setFullZoom: function(window, zoom) {
|
|
|
|
this._getMUDV(window).fullZoom = zoom;
|
|
|
|
},
|
|
|
|
getTextZoom: function(window) {
|
|
|
|
return this._getMUDV(window).textZoom;
|
|
|
|
},
|
|
|
|
setTextZoom: function(window, zoom) {
|
|
|
|
this._getMUDV(window).textZoom = zoom;
|
|
|
|
},
|
|
|
|
|
2013-07-17 19:39:19 +04:00
|
|
|
emulateMedium: function(window, mediaType) {
|
|
|
|
this._getMUDV(window).emulateMedium(mediaType);
|
|
|
|
},
|
|
|
|
stopEmulatingMedium: function(window) {
|
|
|
|
this._getMUDV(window).stopEmulatingMedium();
|
|
|
|
},
|
|
|
|
|
2013-06-25 10:01:38 +04:00
|
|
|
snapshotWindowWithOptions: function (win, rect, bgcolor, options) {
|
2012-04-02 06:23:51 +04:00
|
|
|
var el = this.window.get().document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
|
2013-06-25 10:01:38 +04:00
|
|
|
if (rect === undefined) {
|
2012-09-07 09:29:47 +04:00
|
|
|
rect = { top: win.scrollY, left: win.scrollX,
|
|
|
|
width: win.innerWidth, height: win.innerHeight };
|
|
|
|
}
|
2013-06-25 10:01:38 +04:00
|
|
|
if (bgcolor === undefined) {
|
2012-09-07 09:29:47 +04:00
|
|
|
bgcolor = "rgb(255,255,255)";
|
|
|
|
}
|
2013-06-25 10:01:38 +04:00
|
|
|
if (options === undefined) {
|
|
|
|
options = { };
|
|
|
|
}
|
2012-09-07 09:29:47 +04:00
|
|
|
|
|
|
|
el.width = rect.width;
|
|
|
|
el.height = rect.height;
|
2011-10-06 18:51:03 +04:00
|
|
|
var ctx = el.getContext("2d");
|
|
|
|
var flags = 0;
|
|
|
|
|
2013-06-25 10:01:38 +04:00
|
|
|
for (var option in options) {
|
|
|
|
flags |= options[option] && ctx[option];
|
|
|
|
}
|
|
|
|
|
2012-09-07 09:29:47 +04:00
|
|
|
ctx.drawWindow(win,
|
|
|
|
rect.left, rect.top, rect.width, rect.height,
|
|
|
|
bgcolor,
|
2013-06-25 10:01:38 +04:00
|
|
|
flags);
|
2011-10-06 18:51:03 +04:00
|
|
|
return el;
|
|
|
|
},
|
|
|
|
|
2013-06-25 10:01:38 +04:00
|
|
|
snapshotWindow: function (win, withCaret, rect, bgcolor) {
|
|
|
|
return this.snapshotWindowWithOptions(win, rect, bgcolor,
|
|
|
|
{ DRAWWINDOW_DRAW_CARET: withCaret });
|
|
|
|
},
|
|
|
|
|
2012-09-07 09:29:47 +04:00
|
|
|
snapshotRect: function (win, rect, bgcolor) {
|
2013-06-25 10:01:38 +04:00
|
|
|
return this.snapshotWindowWithOptions(win, rect, bgcolor);
|
2012-09-07 09:29:47 +04:00
|
|
|
},
|
|
|
|
|
2011-10-06 18:51:03 +04:00
|
|
|
gc: function() {
|
|
|
|
this.DOMWindowUtils.garbageCollect();
|
|
|
|
},
|
|
|
|
|
|
|
|
forceGC: function() {
|
2012-11-17 06:53:32 +04:00
|
|
|
Cu.forceGC();
|
2011-10-06 18:51:03 +04:00
|
|
|
},
|
|
|
|
|
2012-08-10 20:15:02 +04:00
|
|
|
forceCC: function() {
|
2012-11-17 06:53:32 +04:00
|
|
|
Cu.forceCC();
|
2012-08-10 20:15:02 +04:00
|
|
|
},
|
|
|
|
|
2014-05-07 04:25:26 +04:00
|
|
|
finishCC: function() {
|
|
|
|
Cu.finishCC();
|
|
|
|
},
|
|
|
|
|
|
|
|
ccSlice: function(budget) {
|
|
|
|
Cu.ccSlice(budget);
|
|
|
|
},
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
// Due to various dependencies between JS objects and C++ objects, an ordinary
|
|
|
|
// forceGC doesn't necessarily clear all unused objects, thus the GC and CC
|
|
|
|
// needs to run several times and when no other JS is running.
|
|
|
|
// The current number of iterations has been determined according to massive
|
|
|
|
// cross platform testing.
|
2011-12-16 11:34:24 +04:00
|
|
|
exactGC: function(win, callback) {
|
|
|
|
var self = this;
|
|
|
|
let count = 0;
|
|
|
|
|
2014-10-27 03:31:00 +03:00
|
|
|
function genGCCallback(cb) {
|
|
|
|
return function() {
|
2011-12-16 11:34:24 +04:00
|
|
|
self.getDOMWindowUtils(win).cycleCollect();
|
|
|
|
if (++count < 2) {
|
2014-10-27 03:31:00 +03:00
|
|
|
Cu.schedulePreciseGC(genGCCallback(cb));
|
2014-12-15 20:56:47 +03:00
|
|
|
} else if (cb) {
|
2014-10-27 03:31:00 +03:00
|
|
|
cb();
|
2011-12-16 11:34:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-27 03:31:00 +03:00
|
|
|
Cu.schedulePreciseGC(genGCCallback(callback));
|
2011-12-16 11:34:24 +04:00
|
|
|
},
|
|
|
|
|
2012-09-20 17:06:50 +04:00
|
|
|
setGCZeal: function(zeal) {
|
2012-11-17 06:53:32 +04:00
|
|
|
Cu.setGCZeal(zeal);
|
2012-09-20 17:06:50 +04:00
|
|
|
},
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
isMainProcess: function() {
|
2011-10-06 18:51:03 +04:00
|
|
|
try {
|
2012-06-01 21:21:12 +04:00
|
|
|
return Cc["@mozilla.org/xre/app-info;1"].
|
|
|
|
getService(Ci.nsIXULRuntime).
|
|
|
|
processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
|
|
|
} catch (e) { }
|
|
|
|
return true;
|
2011-10-06 18:51:03 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_xpcomabi: null,
|
|
|
|
|
|
|
|
get XPCOMABI() {
|
|
|
|
if (this._xpcomabi != null)
|
|
|
|
return this._xpcomabi;
|
|
|
|
|
|
|
|
var xulRuntime = Cc["@mozilla.org/xre/app-info;1"]
|
|
|
|
.getService(Components.interfaces.nsIXULAppInfo)
|
|
|
|
.QueryInterface(Components.interfaces.nsIXULRuntime);
|
|
|
|
|
|
|
|
this._xpcomabi = xulRuntime.XPCOMABI;
|
|
|
|
return this._xpcomabi;
|
|
|
|
},
|
|
|
|
|
2012-08-18 02:13:23 +04:00
|
|
|
// The optional aWin parameter allows the caller to specify a given window in
|
|
|
|
// whose scope the runnable should be dispatched. If aFun throws, the
|
|
|
|
// exception will be reported to aWin.
|
|
|
|
executeSoon: function(aFun, aWin) {
|
|
|
|
// Create the runnable in the scope of aWin to avoid running into COWs.
|
|
|
|
var runnable = {};
|
|
|
|
if (aWin)
|
|
|
|
runnable = Cu.createObjectIn(aWin);
|
|
|
|
runnable.run = aFun;
|
|
|
|
Cu.dispatch(runnable, aWin);
|
2011-10-06 18:51:03 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_os: null,
|
|
|
|
|
|
|
|
get OS() {
|
|
|
|
if (this._os != null)
|
|
|
|
return this._os;
|
|
|
|
|
|
|
|
var xulRuntime = Cc["@mozilla.org/xre/app-info;1"]
|
|
|
|
.getService(Components.interfaces.nsIXULAppInfo)
|
|
|
|
.QueryInterface(Components.interfaces.nsIXULRuntime);
|
|
|
|
|
|
|
|
this._os = xulRuntime.OS;
|
|
|
|
return this._os;
|
|
|
|
},
|
|
|
|
|
2015-02-08 12:09:00 +03:00
|
|
|
get isB2G() {
|
|
|
|
#ifdef MOZ_B2G
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
},
|
|
|
|
|
2011-10-06 18:51:03 +04:00
|
|
|
addSystemEventListener: function(target, type, listener, useCapture) {
|
|
|
|
Cc["@mozilla.org/eventlistenerservice;1"].
|
|
|
|
getService(Ci.nsIEventListenerService).
|
|
|
|
addSystemEventListener(target, type, listener, useCapture);
|
|
|
|
},
|
|
|
|
removeSystemEventListener: function(target, type, listener, useCapture) {
|
|
|
|
Cc["@mozilla.org/eventlistenerservice;1"].
|
|
|
|
getService(Ci.nsIEventListenerService).
|
|
|
|
removeSystemEventListener(target, type, listener, useCapture);
|
|
|
|
},
|
|
|
|
|
2012-02-24 17:19:49 +04:00
|
|
|
getDOMRequestService: function() {
|
2014-04-29 19:31:12 +04:00
|
|
|
var serv = Services.DOMRequest;
|
2014-07-18 08:34:48 +04:00
|
|
|
var res = {};
|
2013-06-28 06:53:44 +04:00
|
|
|
var props = ["createRequest", "createCursor", "fireError", "fireSuccess",
|
|
|
|
"fireDone", "fireDetailedError"];
|
2014-06-13 21:56:38 +04:00
|
|
|
for (var i in props) {
|
2012-02-24 17:19:49 +04:00
|
|
|
let prop = props[i];
|
|
|
|
res[prop] = function() { return serv[prop].apply(serv, arguments) };
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
},
|
|
|
|
|
2011-10-06 18:51:03 +04:00
|
|
|
setLogFile: function(path) {
|
|
|
|
this._mfl = new MozillaFileLogger(path);
|
|
|
|
},
|
|
|
|
|
|
|
|
log: function(data) {
|
|
|
|
this._mfl.log(data);
|
|
|
|
},
|
|
|
|
|
|
|
|
closeLogFile: function() {
|
|
|
|
this._mfl.close();
|
|
|
|
},
|
|
|
|
|
|
|
|
addCategoryEntry: function(category, entry, value, persists, replace) {
|
|
|
|
Components.classes["@mozilla.org/categorymanager;1"].
|
|
|
|
getService(Components.interfaces.nsICategoryManager).
|
|
|
|
addCategoryEntry(category, entry, value, persists, replace);
|
|
|
|
},
|
|
|
|
|
2013-08-22 17:44:19 +04:00
|
|
|
deleteCategoryEntry: function(category, entry, persists) {
|
|
|
|
Components.classes["@mozilla.org/categorymanager;1"].
|
|
|
|
getService(Components.interfaces.nsICategoryManager).
|
|
|
|
deleteCategoryEntry(category, entry, persists);
|
|
|
|
},
|
|
|
|
|
2012-04-17 06:14:01 +04:00
|
|
|
copyString: function(str, doc) {
|
2011-10-06 18:51:03 +04:00
|
|
|
Components.classes["@mozilla.org/widget/clipboardhelper;1"].
|
|
|
|
getService(Components.interfaces.nsIClipboardHelper).
|
2012-04-17 06:14:01 +04:00
|
|
|
copyString(str, doc);
|
2011-10-06 18:51:03 +04:00
|
|
|
},
|
2011-10-06 18:51:03 +04:00
|
|
|
|
2011-12-30 21:35:39 +04:00
|
|
|
openDialog: function(win, args) {
|
|
|
|
return win.openDialog.apply(win, args);
|
|
|
|
},
|
|
|
|
|
2011-10-06 18:51:03 +04:00
|
|
|
// :jdm gets credit for this. ex: getPrivilegedProps(window, 'location.href');
|
|
|
|
getPrivilegedProps: function(obj, props) {
|
2012-01-20 19:21:46 +04:00
|
|
|
var parts = props.split('.');
|
2011-10-06 18:51:03 +04:00
|
|
|
|
|
|
|
for (var i = 0; i < parts.length; i++) {
|
|
|
|
var p = parts[i];
|
|
|
|
if (obj[p]) {
|
|
|
|
obj = obj[p];
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
},
|
|
|
|
|
|
|
|
get focusManager() {
|
|
|
|
if (this._fm != null)
|
|
|
|
return this._fm;
|
|
|
|
|
|
|
|
this._fm = Components.classes["@mozilla.org/focus-manager;1"].
|
|
|
|
getService(Components.interfaces.nsIFocusManager);
|
|
|
|
|
|
|
|
return this._fm;
|
|
|
|
},
|
|
|
|
|
2014-05-28 22:14:27 +04:00
|
|
|
getFocusedElementForWindow: function(targetWindow, aDeep) {
|
|
|
|
var outParam = {};
|
|
|
|
this.focusManager.getFocusedElementForWindow(targetWindow, aDeep, outParam);
|
|
|
|
return outParam.value;
|
2011-10-06 18:51:03 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
activeWindow: function() {
|
|
|
|
return this.focusManager.activeWindow;
|
|
|
|
},
|
|
|
|
|
|
|
|
focusedWindow: function() {
|
|
|
|
return this.focusManager.focusedWindow;
|
|
|
|
},
|
|
|
|
|
2013-05-03 20:29:55 +04:00
|
|
|
focus: function(aWindow) {
|
|
|
|
// This is called inside TestRunner._makeIframe without aWindow, because of assertions in oop mochitests
|
|
|
|
// With aWindow, it is called in SimpleTest.waitForFocus to allow popup window opener focus switching
|
|
|
|
if (aWindow)
|
|
|
|
aWindow.focus();
|
|
|
|
sendAsyncMessage("SpecialPowers.Focus", {});
|
2011-10-06 18:51:03 +04:00
|
|
|
},
|
2013-02-09 00:25:37 +04:00
|
|
|
|
2013-08-07 22:52:38 +04:00
|
|
|
getClipboardData: function(flavor, whichClipboard) {
|
2011-10-14 15:52:02 +04:00
|
|
|
if (this._cb == null)
|
|
|
|
this._cb = Components.classes["@mozilla.org/widget/clipboard;1"].
|
|
|
|
getService(Components.interfaces.nsIClipboard);
|
2013-08-07 22:52:38 +04:00
|
|
|
if (whichClipboard === undefined)
|
|
|
|
whichClipboard = this._cb.kGlobalClipboard;
|
2011-10-14 15:52:02 +04:00
|
|
|
|
|
|
|
var xferable = Components.classes["@mozilla.org/widget/transferable;1"].
|
|
|
|
createInstance(Components.interfaces.nsITransferable);
|
2015-01-29 22:28:01 +03:00
|
|
|
// in e10s b-c tests |content.window| is a CPOW whereas |window| works fine.
|
2014-09-26 08:03:41 +04:00
|
|
|
// for some non-e10s mochi tests, |window| is null whereas |content.window|
|
|
|
|
// works fine. So we take whatever is non-null!
|
2015-01-29 22:28:01 +03:00
|
|
|
xferable.init(this._getDocShell(typeof(window) == "undefined" ? content.window : window)
|
2012-04-17 06:14:01 +04:00
|
|
|
.QueryInterface(Components.interfaces.nsILoadContext));
|
2011-10-14 15:52:02 +04:00
|
|
|
xferable.addDataFlavor(flavor);
|
2013-08-07 22:52:38 +04:00
|
|
|
this._cb.getData(xferable, whichClipboard);
|
2011-10-14 15:52:02 +04:00
|
|
|
var data = {};
|
|
|
|
try {
|
|
|
|
xferable.getTransferData(flavor, data, {});
|
|
|
|
} catch (e) {}
|
|
|
|
data = data.value || null;
|
|
|
|
if (data == null)
|
|
|
|
return "";
|
2013-02-09 00:25:37 +04:00
|
|
|
|
2011-10-14 15:52:02 +04:00
|
|
|
return data.QueryInterface(Components.interfaces.nsISupportsString).data;
|
|
|
|
},
|
|
|
|
|
2012-04-17 06:14:01 +04:00
|
|
|
clipboardCopyString: function(preExpectedVal, doc) {
|
2011-10-14 15:52:02 +04:00
|
|
|
var cbHelperSvc = Components.classes["@mozilla.org/widget/clipboardhelper;1"].
|
|
|
|
getService(Components.interfaces.nsIClipboardHelper);
|
2012-04-17 06:14:01 +04:00
|
|
|
cbHelperSvc.copyString(preExpectedVal, doc);
|
2011-10-14 15:52:02 +04:00
|
|
|
},
|
2011-10-14 15:52:02 +04:00
|
|
|
|
2011-11-30 06:57:41 +04:00
|
|
|
supportsSelectionClipboard: function() {
|
|
|
|
if (this._cb == null) {
|
|
|
|
this._cb = Components.classes["@mozilla.org/widget/clipboard;1"].
|
|
|
|
getService(Components.interfaces.nsIClipboard);
|
|
|
|
}
|
|
|
|
return this._cb.supportsSelectionClipboard();
|
|
|
|
},
|
|
|
|
|
2013-02-09 00:25:37 +04:00
|
|
|
swapFactoryRegistration: function(cid, contractID, newFactory, oldFactory) {
|
2014-05-28 22:14:27 +04:00
|
|
|
newFactory = Cu.waiveXrays(newFactory);
|
|
|
|
oldFactory = Cu.waiveXrays(oldFactory);
|
|
|
|
|
2011-10-14 15:52:02 +04:00
|
|
|
var componentRegistrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
|
|
|
|
|
|
|
var unregisterFactory = newFactory;
|
|
|
|
var registerFactory = oldFactory;
|
2013-02-09 00:25:37 +04:00
|
|
|
|
2011-10-14 15:52:02 +04:00
|
|
|
if (cid == null) {
|
|
|
|
if (contractID != null) {
|
|
|
|
cid = componentRegistrar.contractIDToCID(contractID);
|
|
|
|
oldFactory = Components.manager.getClassObject(Components.classes[contractID],
|
|
|
|
Components.interfaces.nsIFactory);
|
|
|
|
} else {
|
|
|
|
return {'error': "trying to register a new contract ID: Missing contractID"};
|
|
|
|
}
|
|
|
|
|
|
|
|
unregisterFactory = oldFactory;
|
|
|
|
registerFactory = newFactory;
|
|
|
|
}
|
|
|
|
componentRegistrar.unregisterFactory(cid,
|
|
|
|
unregisterFactory);
|
|
|
|
|
|
|
|
// Restore the original factory.
|
|
|
|
componentRegistrar.registerFactory(cid,
|
|
|
|
"",
|
|
|
|
contractID,
|
|
|
|
registerFactory);
|
|
|
|
return {'cid':cid, 'originalFactory':oldFactory};
|
|
|
|
},
|
2013-02-09 00:25:37 +04:00
|
|
|
|
2011-10-19 13:35:05 +04:00
|
|
|
_getElement: function(aWindow, id) {
|
|
|
|
return ((typeof(id) == "string") ?
|
2013-02-09 00:25:37 +04:00
|
|
|
aWindow.document.getElementById(id) : id);
|
2011-10-19 13:35:05 +04:00
|
|
|
},
|
2013-02-09 00:25:37 +04:00
|
|
|
|
2011-10-19 13:35:05 +04:00
|
|
|
dispatchEvent: function(aWindow, target, event) {
|
|
|
|
var el = this._getElement(aWindow, target);
|
|
|
|
return el.dispatchEvent(event);
|
|
|
|
},
|
2012-03-30 01:08:43 +04:00
|
|
|
|
|
|
|
get isDebugBuild() {
|
2014-05-22 23:53:22 +04:00
|
|
|
delete SpecialPowersAPI.prototype.isDebugBuild;
|
|
|
|
|
2012-03-30 01:08:43 +04:00
|
|
|
var debug = Cc["@mozilla.org/xpcom/debug;1"].getService(Ci.nsIDebug2);
|
2014-05-22 23:53:22 +04:00
|
|
|
return SpecialPowersAPI.prototype.isDebugBuild = debug.isDebugBuild;
|
2012-05-08 20:20:35 +04:00
|
|
|
},
|
2013-02-25 11:42:38 +04:00
|
|
|
assertionCount: function() {
|
|
|
|
var debugsvc = Cc['@mozilla.org/xpcom/debug;1'].getService(Ci.nsIDebug2);
|
|
|
|
return debugsvc.assertionCount;
|
|
|
|
},
|
2012-05-08 20:20:35 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the message manager associated with an <iframe mozbrowser>.
|
|
|
|
*/
|
|
|
|
getBrowserFrameMessageManager: function(aFrameElement) {
|
|
|
|
return this.wrap(aFrameElement.QueryInterface(Ci.nsIFrameLoaderOwner)
|
|
|
|
.frameLoader
|
|
|
|
.messageManager);
|
|
|
|
},
|
2013-02-09 00:25:37 +04:00
|
|
|
|
2012-05-09 01:48:27 +04:00
|
|
|
setFullscreenAllowed: function(document) {
|
2014-04-29 19:31:12 +04:00
|
|
|
Services.perms.addFromPrincipal(document.nodePrincipal, "fullscreen",
|
|
|
|
Ci.nsIPermissionManager.ALLOW_ACTION);
|
|
|
|
Services.obs.notifyObservers(document, "fullscreen-approved", null);
|
2012-05-09 01:48:27 +04:00
|
|
|
},
|
2013-02-09 00:25:37 +04:00
|
|
|
|
2012-05-09 01:48:27 +04:00
|
|
|
removeFullscreenAllowed: function(document) {
|
2014-04-29 19:31:12 +04:00
|
|
|
Services.perms.removeFromPrincipal(document.nodePrincipal, "fullscreen");
|
2012-06-01 21:21:12 +04:00
|
|
|
},
|
|
|
|
|
2012-08-23 22:23:48 +04:00
|
|
|
_getInfoFromPermissionArg: function(arg) {
|
|
|
|
let url = "";
|
|
|
|
let appId = Ci.nsIScriptSecurityManager.NO_APP_ID;
|
|
|
|
let isInBrowserElement = false;
|
2014-07-29 03:17:50 +04:00
|
|
|
let isSystem = false;
|
2012-08-23 22:23:48 +04:00
|
|
|
|
|
|
|
if (typeof(arg) == "string") {
|
|
|
|
// It's an URL.
|
|
|
|
url = Cc["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Ci.nsIIOService)
|
|
|
|
.newURI(arg, null, null)
|
|
|
|
.spec;
|
2012-10-23 20:31:19 +04:00
|
|
|
} else if (arg.manifestURL) {
|
|
|
|
// It's a thing representing an app.
|
2012-11-30 22:52:40 +04:00
|
|
|
let appsSvc = Cc["@mozilla.org/AppsService;1"]
|
|
|
|
.getService(Ci.nsIAppsService)
|
2013-02-09 00:25:37 +04:00
|
|
|
let app = appsSvc.getAppByManifestURL(arg.manifestURL);
|
2012-10-23 20:31:19 +04:00
|
|
|
|
|
|
|
if (!app) {
|
|
|
|
throw "No app for this manifest!";
|
|
|
|
}
|
|
|
|
|
2012-11-30 22:52:40 +04:00
|
|
|
appId = appsSvc.getAppLocalIdByManifestURL(arg.manifestURL);
|
2012-10-23 20:31:19 +04:00
|
|
|
url = app.origin;
|
|
|
|
isInBrowserElement = arg.isInBrowserElement || false;
|
2012-08-23 22:23:48 +04:00
|
|
|
} else if (arg.nodePrincipal) {
|
|
|
|
// It's a document.
|
2014-07-29 03:17:50 +04:00
|
|
|
isSystem = (arg.nodePrincipal instanceof Ci.nsIPrincipal) &&
|
|
|
|
Cc["@mozilla.org/scriptsecuritymanager;1"].
|
|
|
|
getService(Ci.nsIScriptSecurityManager).
|
|
|
|
isSystemPrincipal(arg.nodePrincipal);
|
|
|
|
if (!isSystem) {
|
|
|
|
// System principals don't have a URL associated with them, and they
|
|
|
|
// don't really need any permissions to be registered with the
|
|
|
|
// permission manager anyway.
|
|
|
|
url = arg.nodePrincipal.URI.spec;
|
|
|
|
appId = arg.nodePrincipal.appId;
|
|
|
|
isInBrowserElement = arg.nodePrincipal.isInBrowserElement;
|
|
|
|
}
|
2012-08-23 22:23:48 +04:00
|
|
|
} else {
|
|
|
|
url = arg.url;
|
|
|
|
appId = arg.appId;
|
|
|
|
isInBrowserElement = arg.isInBrowserElement;
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
2012-08-23 22:23:48 +04:00
|
|
|
|
2014-07-29 03:17:50 +04:00
|
|
|
return [ url, appId, isInBrowserElement, isSystem ];
|
2012-06-01 21:21:12 +04:00
|
|
|
},
|
|
|
|
|
2012-08-23 22:23:48 +04:00
|
|
|
addPermission: function(type, allow, arg) {
|
2014-07-29 03:17:50 +04:00
|
|
|
let [url, appId, isInBrowserElement, isSystem] = this._getInfoFromPermissionArg(arg);
|
|
|
|
if (isSystem) {
|
|
|
|
return; // nothing to do
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2013-05-17 12:46:36 +04:00
|
|
|
let permission;
|
|
|
|
if (typeof allow !== 'boolean') {
|
|
|
|
permission = allow;
|
|
|
|
} else {
|
|
|
|
permission = allow ? Ci.nsIPermissionManager.ALLOW_ACTION
|
|
|
|
: Ci.nsIPermissionManager.DENY_ACTION;
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
|
|
|
var msg = {
|
2013-03-05 05:17:24 +04:00
|
|
|
'op': 'add',
|
2012-06-01 21:21:12 +04:00
|
|
|
'type': type,
|
2012-08-23 22:23:48 +04:00
|
|
|
'permission': permission,
|
|
|
|
'url': url,
|
|
|
|
'appId': appId,
|
|
|
|
'isInBrowserElement': isInBrowserElement
|
2012-06-01 21:21:12 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
this._sendSyncMessage('SPPermissionManager', msg);
|
|
|
|
},
|
|
|
|
|
2012-08-23 22:23:48 +04:00
|
|
|
removePermission: function(type, arg) {
|
2014-07-29 03:17:50 +04:00
|
|
|
let [url, appId, isInBrowserElement, isSystem] = this._getInfoFromPermissionArg(arg);
|
|
|
|
if (isSystem) {
|
|
|
|
return; // nothing to do
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
|
|
|
var msg = {
|
2013-03-05 05:17:24 +04:00
|
|
|
'op': 'remove',
|
2012-06-01 21:21:12 +04:00
|
|
|
'type': type,
|
2012-08-23 22:23:48 +04:00
|
|
|
'url': url,
|
|
|
|
'appId': appId,
|
|
|
|
'isInBrowserElement': isInBrowserElement
|
2012-06-01 21:21:12 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
this._sendSyncMessage('SPPermissionManager', msg);
|
2012-06-18 21:09:26 +04:00
|
|
|
},
|
|
|
|
|
2013-03-05 05:17:24 +04:00
|
|
|
hasPermission: function (type, arg) {
|
2014-07-29 03:17:50 +04:00
|
|
|
let [url, appId, isInBrowserElement, isSystem] = this._getInfoFromPermissionArg(arg);
|
|
|
|
if (isSystem) {
|
|
|
|
return true; // system principals have all permissions
|
|
|
|
}
|
2013-03-05 05:17:24 +04:00
|
|
|
|
|
|
|
var msg = {
|
|
|
|
'op': 'has',
|
|
|
|
'type': type,
|
|
|
|
'url': url,
|
|
|
|
'appId': appId,
|
|
|
|
'isInBrowserElement': isInBrowserElement
|
|
|
|
};
|
|
|
|
|
|
|
|
return this._sendSyncMessage('SPPermissionManager', msg)[0];
|
|
|
|
},
|
|
|
|
testPermission: function (type, value, arg) {
|
2014-07-29 03:17:50 +04:00
|
|
|
let [url, appId, isInBrowserElement, isSystem] = this._getInfoFromPermissionArg(arg);
|
|
|
|
if (isSystem) {
|
|
|
|
return true; // system principals have all permissions
|
|
|
|
}
|
2013-03-05 05:17:24 +04:00
|
|
|
|
|
|
|
var msg = {
|
|
|
|
'op': 'test',
|
|
|
|
'type': type,
|
|
|
|
'value': value,
|
|
|
|
'url': url,
|
|
|
|
'appId': appId,
|
|
|
|
'isInBrowserElement': isInBrowserElement
|
|
|
|
};
|
|
|
|
return this._sendSyncMessage('SPPermissionManager', msg)[0];
|
|
|
|
},
|
|
|
|
|
2014-09-24 02:48:52 +04:00
|
|
|
isContentWindowPrivate: function(win) {
|
|
|
|
return PrivateBrowsingUtils.isContentWindowPrivate(win);
|
2012-10-07 23:04:39 +04:00
|
|
|
},
|
2013-05-13 08:10:58 +04:00
|
|
|
|
|
|
|
notifyObserversInParentProcess: function(subject, topic, data) {
|
|
|
|
if (subject) {
|
|
|
|
throw new Error("Can't send subject to another process!");
|
|
|
|
}
|
|
|
|
if (this.isMainProcess()) {
|
2014-01-16 18:36:14 +04:00
|
|
|
this.notifyObservers(subject, topic, data);
|
|
|
|
return;
|
2013-05-13 08:10:58 +04:00
|
|
|
}
|
|
|
|
var msg = {
|
|
|
|
'op': 'notify',
|
|
|
|
'observerTopic': topic,
|
|
|
|
'observerData': data
|
|
|
|
};
|
|
|
|
this._sendSyncMessage('SPObserverService', msg);
|
|
|
|
},
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
clearStorageForURI: function(uri, callback, appId, inBrowser) {
|
|
|
|
this._quotaManagerRequest('clear', uri, appId, inBrowser, callback);
|
|
|
|
},
|
|
|
|
|
|
|
|
getStorageUsageForURI: function(uri, callback, appId, inBrowser) {
|
|
|
|
this._quotaManagerRequest('getUsage', uri, appId, inBrowser, callback);
|
|
|
|
},
|
|
|
|
|
|
|
|
_quotaManagerRequest: function(op, uri, appId, inBrowser, callback) {
|
|
|
|
const messageTopic = "SPQuotaManager";
|
|
|
|
|
|
|
|
if (uri instanceof Ci.nsIURI) {
|
|
|
|
uri = uri.spec;
|
|
|
|
}
|
|
|
|
|
|
|
|
const id = Cc["@mozilla.org/uuid-generator;1"]
|
|
|
|
.getService(Ci.nsIUUIDGenerator)
|
|
|
|
.generateUUID()
|
|
|
|
.toString();
|
|
|
|
|
|
|
|
let callbackInfo = { id: id, callback: callback };
|
|
|
|
|
|
|
|
if (this._quotaManagerCallbackInfos) {
|
|
|
|
callbackInfo.listener = this._quotaManagerCallbackInfos[0].listener;
|
|
|
|
this._quotaManagerCallbackInfos.push(callbackInfo)
|
|
|
|
} else {
|
|
|
|
callbackInfo.listener = function(msg) {
|
|
|
|
msg = msg.data;
|
|
|
|
for (let index in this._quotaManagerCallbackInfos) {
|
|
|
|
let callbackInfo = this._quotaManagerCallbackInfos[index];
|
|
|
|
if (callbackInfo.id == msg.id) {
|
|
|
|
if (this._quotaManagerCallbackInfos.length > 1) {
|
|
|
|
this._quotaManagerCallbackInfos.splice(index, 1);
|
|
|
|
} else {
|
|
|
|
this._quotaManagerCallbackInfos = null;
|
|
|
|
this._removeMessageListener(messageTopic, callbackInfo.listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('usage' in msg) {
|
|
|
|
callbackInfo.callback(msg.usage, msg.fileUsage);
|
|
|
|
} else {
|
|
|
|
callbackInfo.callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
this._addMessageListener(messageTopic, callbackInfo.listener);
|
|
|
|
this._quotaManagerCallbackInfos = [ callbackInfo ];
|
|
|
|
}
|
|
|
|
|
|
|
|
let msg = { op: op, uri: uri, appId: appId, inBrowser: inBrowser, id: id };
|
|
|
|
this._sendAsyncMessage(messageTopic, msg);
|
|
|
|
},
|
2014-10-21 04:49:00 +04:00
|
|
|
|
|
|
|
createDOMFile: function(path, options) {
|
|
|
|
return new File(path, options);
|
|
|
|
},
|
2011-10-06 18:51:03 +04:00
|
|
|
};
|
2013-11-24 09:32:27 +04:00
|
|
|
|
|
|
|
this.SpecialPowersAPI = SpecialPowersAPI;
|
|
|
|
this.bindDOMWindowUtils = bindDOMWindowUtils;
|
|
|
|
this.getRawComponents = getRawComponents;
|