Bug 1198093 - Part 1: Expose indexedDB to System with [Exposed=System]. r=khuey

This commit is contained in:
Bevis Tseng 2016-03-30 11:22:14 +08:00
Родитель 5672f5992c
Коммит 47e9ad43d3
20 изменённых файлов: 94 добавлений и 28 удалений

Просмотреть файл

@ -553,8 +553,8 @@ IndexedDatabaseManager::CommonPostHandleEvent(EventChainPostVisitor& aVisitor,
// static
bool
IndexedDatabaseManager::DefineIndexedDB(JSContext* aCx,
JS::Handle<JSObject*> aGlobal)
IndexedDatabaseManager::ResolveSandboxBinding(JSContext* aCx,
JS::Handle<JSObject*> aGlobal)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(js::GetObjectClass(aGlobal)->flags & JSCLASS_DOM_GLOBAL,
@ -583,6 +583,18 @@ IndexedDatabaseManager::DefineIndexedDB(JSContext* aCx,
return false;
}
return true;
}
// static
bool
IndexedDatabaseManager::DefineIndexedDB(JSContext* aCx,
JS::Handle<JSObject*> aGlobal)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(js::GetObjectClass(aGlobal)->flags & JSCLASS_DOM_GLOBAL,
"Passed object is not a global object!");
RefPtr<IDBFactory> factory;
if (NS_FAILED(IDBFactory::CreateForMainThreadJS(aCx,
aGlobal,
@ -691,6 +703,30 @@ IndexedDatabaseManager::ExperimentalFeaturesEnabled()
return gExperimentalFeaturesEnabled;
}
// static
bool
IndexedDatabaseManager::ExperimentalFeaturesEnabled(JSContext* aCx, JSObject* aGlobal)
{
// If, in the child process, properties of the global object are enumerated
// before the chrome registry (and thus the value of |intl.accept_languages|)
// is ready, calling IndexedDatabaseManager::Init will permanently break
// that preference. We can retrieve gExperimentalFeaturesEnabled without
// actually going through IndexedDatabaseManager.
// See Bug 1198093 comment 14 for detailed explanation.
if (IsNonExposedGlobal(aCx, js::GetGlobalForObjectCrossCompartment(aGlobal),
GlobalNames::BackstagePass)) {
MOZ_ASSERT(NS_IsMainThread());
static bool featureRetrieved = false;
if (!featureRetrieved) {
gExperimentalFeaturesEnabled = Preferences::GetBool(kPrefExperimental);
featureRetrieved = true;
}
return gExperimentalFeaturesEnabled;
}
return ExperimentalFeaturesEnabled();
}
// static
bool
IndexedDatabaseManager::IsFileHandleEnabled()

Просмотреть файл

@ -119,10 +119,7 @@ public:
ExperimentalFeaturesEnabled();
static bool
ExperimentalFeaturesEnabled(JSContext* /* aCx */, JSObject* /* aGlobal */)
{
return ExperimentalFeaturesEnabled();
}
ExperimentalFeaturesEnabled(JSContext* aCx, JSObject* aGlobal);
static bool
IsFileHandleEnabled();
@ -190,6 +187,9 @@ public:
static nsresult
CommonPostHandleEvent(EventChainPostVisitor& aVisitor, IDBFactory* aFactory);
static bool
ResolveSandboxBinding(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
static bool
DefineIndexedDB(JSContext* aCx, JS::Handle<JSObject*> aGlobal);

Просмотреть файл

@ -5,7 +5,7 @@
enum DOMRequestReadyState { "pending", "done" };
[Exposed=(Window,Worker), NoInterfaceObject]
[Exposed=(Window,Worker,System), NoInterfaceObject]
interface DOMRequestShared {
readonly attribute DOMRequestReadyState readyState;
@ -16,7 +16,7 @@ interface DOMRequestShared {
attribute EventHandler onerror;
};
[Exposed=(Window,Worker)]
[Exposed=(Window,Worker,System)]
interface DOMRequest : EventTarget {
// The [TreatNonCallableAsNull] annotation is required since then() should do
// nothing instead of throwing errors when non-callable arguments are passed.

Просмотреть файл

@ -10,7 +10,7 @@
* liability, trademark and document use rules apply.
*/
[Exposed=(Window,Worker)]
[Exposed=(Window,Worker,System)]
interface DOMStringList {
readonly attribute unsigned long length;
getter DOMString? item(unsigned long index);

Просмотреть файл

@ -14,7 +14,7 @@ enum IDBCursorDirection {
"prevunique"
};
[Exposed=(Window,Worker)]
[Exposed=(Window,Worker,System)]
interface IDBCursor {
readonly attribute (IDBObjectStore or IDBIndex) source;
@ -39,7 +39,7 @@ interface IDBCursor {
IDBRequest delete ();
};
[Exposed=(Window,Worker)]
[Exposed=(Window,Worker,System)]
interface IDBCursorWithValue : IDBCursor {
[Throws]
readonly attribute any value;

Просмотреть файл

@ -10,7 +10,7 @@
* liability, trademark and document use rules apply.
*/
[Exposed=(Window,Worker)]
[Exposed=(Window,Worker,System)]
interface IDBDatabase : EventTarget {
readonly attribute DOMString name;
readonly attribute unsigned long long version;

Просмотреть файл

@ -23,7 +23,7 @@ dictionary IDBOpenDBOptions
* http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl-def-IDBFactory
* for more information.
*/
[Exposed=(Window,Worker)]
[Exposed=(Window,Worker,System)]
interface IDBFactory {
[Throws]
IDBOpenDBRequest

Просмотреть файл

@ -8,6 +8,7 @@ dictionary IDBFileMetadataParameters
boolean lastModified = true;
};
[Exposed=(Window,System)]
interface IDBFileHandle : EventTarget
{
readonly attribute IDBMutableFile? mutableFile;

Просмотреть файл

@ -4,6 +4,7 @@
* 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/. */
[Exposed=(Window,System)]
interface IDBFileRequest : DOMRequest {
readonly attribute IDBFileHandle? fileHandle;
// this is deprecated due to renaming in the spec

Просмотреть файл

@ -18,7 +18,7 @@ dictionary IDBIndexParameters {
DOMString? locale = null;
};
[Exposed=(Window,Worker)]
[Exposed=(Window,Worker,System)]
interface IDBIndex {
readonly attribute DOMString name;
readonly attribute IDBObjectStore objectStore;

Просмотреть файл

@ -9,7 +9,7 @@
* liability, trademark and document use rules apply.
*/
[Exposed=(Window,Worker)]
[Exposed=(Window,Worker,System)]
interface IDBKeyRange {
[Throws]
readonly attribute any lower;
@ -33,7 +33,7 @@ interface IDBKeyRange {
static IDBKeyRange bound (any lower, any upper, optional boolean lowerOpen = false, optional boolean upperOpen = false);
};
[Exposed=(Window,Worker),
[Exposed=(Window,Worker,System),
Func="mozilla::dom::IndexedDatabaseManager::ExperimentalFeaturesEnabled"]
interface IDBLocaleAwareKeyRange : IDBKeyRange {
[NewObject, Throws]

Просмотреть файл

@ -3,6 +3,7 @@
* 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/. */
[Exposed=(Window,System)]
interface IDBMutableFile : EventTarget {
readonly attribute DOMString name;
readonly attribute DOMString type;

Просмотреть файл

@ -12,7 +12,7 @@ dictionary IDBObjectStoreParameters {
boolean autoIncrement = false;
};
[Exposed=(Window,Worker)]
[Exposed=(Window,Worker,System)]
interface IDBObjectStore {
readonly attribute DOMString name;

Просмотреть файл

@ -7,7 +7,7 @@
* https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl-def-IDBOpenDBRequest
*/
[Exposed=(Window,Worker)]
[Exposed=(Window,Worker,System)]
interface IDBOpenDBRequest : IDBRequest {
attribute EventHandler onblocked;

Просмотреть файл

@ -13,7 +13,7 @@ enum IDBRequestReadyState {
"done"
};
[Exposed=(Window,Worker)]
[Exposed=(Window,Worker,System)]
interface IDBRequest : EventTarget {
[Throws]
readonly attribute any result;

Просмотреть файл

@ -19,7 +19,7 @@ enum IDBTransactionMode {
"versionchange"
};
[Exposed=(Window,Worker)]
[Exposed=(Window,Worker,System)]
interface IDBTransaction : EventTarget {
[Throws]
readonly attribute IDBTransactionMode mode;

Просмотреть файл

@ -16,7 +16,7 @@ dictionary IDBVersionChangeEventInit : EventInit {
};
[Constructor(DOMString type, optional IDBVersionChangeEventInit eventInitDict),
Exposed=(Window,Worker)]
Exposed=(Window,Worker,System)]
interface IDBVersionChangeEvent : Event {
readonly attribute unsigned long long oldVersion;
readonly attribute unsigned long long? newVersion;

Просмотреть файл

@ -941,13 +941,14 @@ xpc::GlobalProperties::Parse(JSContext* cx, JS::HandleObject obj)
bool
xpc::GlobalProperties::Define(JSContext* cx, JS::HandleObject obj)
{
// Properties will be exposed to System automatically but not to Sandboxes
// if |[Exposed=System]| is specified.
// This function holds common properties not exposed automatically but able
// to be requested either in |Cu.importGlobalProperties| or
// |wantGlobalProperties| of a sandbox.
if (CSS && !dom::CSSBinding::GetConstructorObject(cx, obj))
return false;
if (indexedDB &&
!IndexedDatabaseManager::DefineIndexedDB(cx, obj))
return false;
if (XMLHttpRequest &&
!dom::XMLHttpRequestBinding::GetConstructorObject(cx, obj))
return false;
@ -1004,6 +1005,29 @@ xpc::GlobalProperties::Define(JSContext* cx, JS::HandleObject obj)
return true;
}
bool
xpc::GlobalProperties::DefineInXPCComponents(JSContext* cx, JS::HandleObject obj)
{
if (indexedDB &&
!IndexedDatabaseManager::DefineIndexedDB(cx, obj))
return false;
return Define(cx, obj);
}
bool
xpc::GlobalProperties::DefineInSandbox(JSContext* cx, JS::HandleObject obj)
{
MOZ_ASSERT(IsSandbox(obj));
if (indexedDB &&
!(IndexedDatabaseManager::ResolveSandboxBinding(cx, obj) &&
IndexedDatabaseManager::DefineIndexedDB(cx, obj)))
return false;
return Define(cx, obj);
}
nsresult
xpc::CreateSandboxObject(JSContext* cx, MutableHandleValue vp, nsISupports* prinOrSop,
SandboxOptions& options)
@ -1170,7 +1194,7 @@ xpc::CreateSandboxObject(JSContext* cx, MutableHandleValue vp, nsISupports* prin
!JS_DefineFunction(cx, sandbox, "isProxy", SandboxIsProxy, 1, 0)))
return NS_ERROR_XPC_UNEXPECTED;
if (!options.globalProperties.Define(cx, sandbox))
if (!options.globalProperties.DefineInSandbox(cx, sandbox))
return NS_ERROR_XPC_UNEXPECTED;
#ifndef SPIDERMONKEY_PROMISE

Просмотреть файл

@ -2548,7 +2548,7 @@ nsXPCComponents_Utils::ImportGlobalProperties(HandleValue aPropertyList,
}
if (!options.Parse(cx, propertyList) ||
!options.Define(cx, global))
!options.DefineInXPCComponents(cx, global))
{
return NS_ERROR_FAILURE;
}

Просмотреть файл

@ -3359,7 +3359,8 @@ struct GlobalProperties {
}
bool Parse(JSContext* cx, JS::HandleObject obj);
bool Define(JSContext* cx, JS::HandleObject obj);
bool DefineInXPCComponents(JSContext* cx, JS::HandleObject obj);
bool DefineInSandbox(JSContext* cx, JS::HandleObject obj);
bool CSS : 1;
bool indexedDB : 1;
bool XMLHttpRequest : 1;
@ -3376,6 +3377,8 @@ struct GlobalProperties {
bool fetch : 1;
bool caches : 1;
bool fileReader: 1;
private:
bool Define(JSContext* cx, JS::HandleObject obj);
};
// Infallible.