mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
4270b0ce16
- Bug 1265133 - Adds s-expr comments support for wasmTextToBinary. r=sunfish (85ff83eb37)
- Bug 1263203: Ensure we don't have Phi values in wasm; r=luke (165667b0b2)
- Bug 676828 - Initialize AudioSession on xpcshell. r=jmathies (684b071278)
- Bug 676828 - Use RAII for AudioSession instead. r=bholley (d17dc48e35)
- Bug 1256992: Initialize Windows sandbox BrokerServices before any child processes are created. r=aklotz, r=bholley (145949d5ea)
- Bug 1255934 - Start collecting telemetry data on the usage of remote JAR protocol in the wild; r=mcmanus (d2f43908e0)
- Bug 1237198 - Block SWFs on the content blocking list hosted on the Shavar service. r=francois (cb2d850412)
- Bug 1242644 - HTML swapFrameLoaders. r=bz (1d899b3e19)
- Bug 1259877 - Remove the unused JSObject::callMethod. r=jorendorff (624bb62f38)
- Bug 1259877 - Remove jsarray.cpp's now-unused SortComparatorFunction. r=mrrrgn (66c84d0d64)
- Bug 1259877 - Update function-calling JSAPI methods to use js::Call. r=sfink (a9fe2995ae)
- Bug 1259877 - Update Reflect.parse callback code to work with InvokeArgs and js::Call. r=arai (d4acd08f45)
- Bug 1259877 - Rename FastInvokeGuard to FastCallGuard and make it not depend on CallArgs::set{Callee,This}, and remove js::Invoke. r=shu (adb4f46944)
- Bug 1259877 - Adjust Promise code to use Call instead of Invoke. r=till (161a451182)
- Bug 1259877 - Update ScriptedDirectProxyHandler code to use js::Call and FixedInvokeArgs. r=evilpie (bd20c77152)
- Bug 1259877 - Update various builtins to use js::Call, not js::Invoke. r=efaust (1a49365f0a)
- Bug 1246091 - patch 1/7 - Add some NS_WARN_IF in Console.cpp, r=ejpbruel (1d5db4511c)
- Bug 1246091 - patch 2/7 - Propagate initialization error in Console.cpp, r=ejpbruel (ea081b0835)
- Bug 1246091 - patch 3/7 - Console API should store ConsoleCallData internally, r=ejpbruel (c9a5e71c0b)
- Bug 1246091 - patch 4/7 - Expose ConsoleCallData to WorkerDebuggerGlobalScope, r=ejpbruel (0209ec651e)
- Bug 1246091 - patch 5/7 - Remove data when memory pressure notification is received, r=ejpbruel (8d07cc4755)
- Bug 1246091 - patch 6/7 - Tests, r=ejpbruel (7e8e20083e)
- Bug 1246091 - patch 7/7 - Correct use of JSCompartment in Console.cpp, r=bz (fcac2da17e)
- Followup for bug 1246091 to fix the naming for PopulateConsoleNotificationInTheTargetScope, r=me (dd942dde21)
- Followup for bug 1246091 to fix the rooting hazard, get us closer to reopening the CLOSED TREE, and reduce philor's blood pressure. (6ef49eaf20)
- Bug 1247953 - Increase the number of stored ConsoleEvent objects, r=bgrinstead (139304e4c6)
- Bug 1211665 - Save originAttributes in the console event messages. r=baku (068697a29f)
- Bug 1263392 - Console should reset the state of ConsoleCallData if the worker runnables are not correctly dispatched, r=smaug (04c3a73423)
- Bug 1246153 part 1. Restrict initialization of dictionaries from JSON to dictionaries that can actually be represented in JSON. r=bholley (2b9c4b98d9)
- Bug 1260414 - WorkerDebuggerGlobalScope.setConsoleEventHandler should be able to receive a null param, r=bz (0b91b09796)
- Bug 1259338 P1 Ensure that AllowWindowInteractionHandler is released on worker thread. r=khuey (28e058999a)
- Bug 1258034 - Fix ServiceWorkerPrivate.cpp build error on b2g r=khuey (1ba0edcc64)
- Bug 1260439 - workerdebuggersandbox_moved needs to update the wrappercache;r=bz (be656ef346)
- Bug 1253777 P1 Ensure buffered copying when reading body in service worker respondWith(). r=jdm (fe61b4f1b3)
- Bug 1253777 P2 Test passing a file-backed blob to FetchEvent.respondWith(). r=jdm (930bf780b0)
- Bug 1226384 - Reject the promise returned from ServiceWorkerRegistration.update() if the registration is being uninstalled; r=bkelly (209e034384)
- Bug 1230030 Don't replace active worker unnecessarly after saving registration in e10s mode. r=ehsan (5582d7ea04)
- Bug 1229795 - P1. Remove scriptSpec from registration data. r=baku, bkelly (f83b7862ec)
- Bug 1229795 - P2. Remove waitingCacheName from registartion data. r=baku (f9279c4ded)
- Bug 1229795 - P3. Migrate service worker registrar data between version 2 and version 3. r=baku (27a53f3d96)
- bit of Bug 1237831 (4b21cec952)
- Bug 1256411 Simplify and cleanup ServiceWorkerInfo. r=ehsan (947166b5e2)
- Bug 1240013 - Crash in nsNavBookmarks::OnVisit by setting long locatiÂĤon.hash. r=Yoric (e9f722434d)
- Bug 1250363 - Speed up history removals through a simulated per-statement trigger. r=yoric (f57235e806)
- Bug 1259294: Part 2 - Use MOZ_ALWAYS_SUCCEEDS. r=froydnj (7624e0a821)
- Bug 548685 - Avoid null pointer deref in nsURIHashKey r=mcmanus (913c7bf0b9)
- Bug 1246153 part 2. Create a way to ask for a clean new global that works on both mainthread and workers. r=bholley (35532ec302)
- Bug 1246153 part 3. Use the new clean global setup for doing from-JSON creation of dictionaries. r=bholley (0cf844641c)
- Bug 1242482 - Propagate Service worker unregistration to the parent process. r=bkelly (b7f44defbe)
- Bug 1247436 Ensure service worker registration is persisted if its resurrected from a pending uninstall. r=baku (d74fc996f1)
- Bug 1242482 P2 Don't SendUnregister() if registration is already removed. r=baku (a0768d2a1c)
- Bug 1242482 P3 Don't send unregister messages when triggered from a PropagateUnregister(). r=baku (b12a3b7ad5)
- Bug 1242482 P4 Don't call SendUnregister() a second time when SW registration is finally removed. r=baku (b0249dd442)
- Bug 1253738 P1 Require an explicit principal when looking up a service worker registration. r=baku (cdb980236a)
- Bug 1253738 P2 Consistently use "scope key" terminology in ServiceWorkerManager. r=baku (e8ae328a83)
- Bug 1253738 P3 Use origin the ServiceWorkerManager scope key. r=baku (e555aba315)
- Bug 1252290 - load xpcom services registered with the category manager as being able to handle push notifications before delivering them. r=kitcambridge (3ade504ad7)
- Bug 1246341 - Report push event errors and rejections to the Push service. r=baku (436943501c)
- Bug 1251113 - Change PushService state to PUSH_SERVICE_UNINIT in the state change process queue. r=dragana (1bacbbb72b)
- Bug 1263311: Part 1 - Change the nsICancelableRunnable interface. r=froydnj (599db8f7d0)
- Bug 1263311: Part 2 - Remove a non-existent CancelableRunnable. r=froydnj (a077efc319)
- Bug 1165052 - Part 8: Use ArraySpeciesCreate in Array.prototype.concat. r=efaust (c421e8e87c)
- Bug 1120715 - Part 3: Connect the Necko level cache mode parameter with the Request cache mode variable; r=bkelly (9a813c0e04)
954 lines
26 KiB
C++
954 lines
26 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* 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/. */
|
|
|
|
#include "IDBFactory.h"
|
|
|
|
#include "BackgroundChildImpl.h"
|
|
#include "IDBRequest.h"
|
|
#include "IndexedDatabaseManager.h"
|
|
#include "mozilla/ErrorResult.h"
|
|
#include "mozilla/Preferences.h"
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
|
#include "mozilla/dom/IDBFactoryBinding.h"
|
|
#include "mozilla/dom/TabChild.h"
|
|
#include "mozilla/ipc/BackgroundChild.h"
|
|
#include "mozilla/ipc/BackgroundUtils.h"
|
|
#include "mozilla/ipc/PBackground.h"
|
|
#include "mozilla/ipc/PBackgroundChild.h"
|
|
#include "mozIThirdPartyUtil.h"
|
|
#include "nsAboutProtocolUtils.h"
|
|
#include "nsContentUtils.h"
|
|
#include "nsGlobalWindow.h"
|
|
#include "nsIAboutModule.h"
|
|
#include "nsIIPCBackgroundChildCreateCallback.h"
|
|
#include "nsILoadContext.h"
|
|
#include "nsIPrincipal.h"
|
|
#include "nsIURI.h"
|
|
#include "nsIUUIDGenerator.h"
|
|
#include "nsIWebNavigation.h"
|
|
#include "nsSandboxFlags.h"
|
|
#include "nsServiceManagerUtils.h"
|
|
#include "ProfilerHelpers.h"
|
|
#include "ReportInternalError.h"
|
|
|
|
// Include this last to avoid path problems on Windows.
|
|
#include "ActorsChild.h"
|
|
|
|
#ifdef DEBUG
|
|
#include "nsContentUtils.h" // For assertions.
|
|
#endif
|
|
|
|
namespace mozilla {
|
|
namespace dom {
|
|
|
|
using namespace mozilla::dom::quota;
|
|
using namespace mozilla::ipc;
|
|
|
|
namespace {
|
|
|
|
const char kPrefIndexedDBEnabled[] = "dom.indexedDB.enabled";
|
|
|
|
} // namespace
|
|
|
|
class IDBFactory::BackgroundCreateCallback final
|
|
: public nsIIPCBackgroundChildCreateCallback
|
|
{
|
|
RefPtr<IDBFactory> mFactory;
|
|
LoggingInfo mLoggingInfo;
|
|
|
|
public:
|
|
explicit
|
|
BackgroundCreateCallback(IDBFactory* aFactory,
|
|
const LoggingInfo& aLoggingInfo)
|
|
: mFactory(aFactory)
|
|
, mLoggingInfo(aLoggingInfo)
|
|
{
|
|
MOZ_ASSERT(aFactory);
|
|
}
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
private:
|
|
~BackgroundCreateCallback()
|
|
{ }
|
|
|
|
NS_DECL_NSIIPCBACKGROUNDCHILDCREATECALLBACK
|
|
};
|
|
|
|
struct IDBFactory::PendingRequestInfo
|
|
{
|
|
RefPtr<IDBOpenDBRequest> mRequest;
|
|
FactoryRequestParams mParams;
|
|
|
|
PendingRequestInfo(IDBOpenDBRequest* aRequest,
|
|
const FactoryRequestParams& aParams)
|
|
: mRequest(aRequest), mParams(aParams)
|
|
{
|
|
MOZ_ASSERT(aRequest);
|
|
MOZ_ASSERT(aParams.type() != FactoryRequestParams::T__None);
|
|
}
|
|
};
|
|
|
|
IDBFactory::IDBFactory()
|
|
: mOwningObject(nullptr)
|
|
, mBackgroundActor(nullptr)
|
|
, mInnerWindowID(0)
|
|
, mBackgroundActorFailed(false)
|
|
, mPrivateBrowsingMode(false)
|
|
{
|
|
#ifdef DEBUG
|
|
mOwningThread = PR_GetCurrentThread();
|
|
#endif
|
|
AssertIsOnOwningThread();
|
|
}
|
|
|
|
IDBFactory::~IDBFactory()
|
|
{
|
|
MOZ_ASSERT_IF(mBackgroundActorFailed, !mBackgroundActor);
|
|
|
|
mOwningObject = nullptr;
|
|
mozilla::DropJSObjects(this);
|
|
|
|
if (mBackgroundActor) {
|
|
mBackgroundActor->SendDeleteMeInternal();
|
|
MOZ_ASSERT(!mBackgroundActor, "SendDeleteMeInternal should have cleared!");
|
|
}
|
|
}
|
|
|
|
// static
|
|
nsresult
|
|
IDBFactory::CreateForWindow(nsPIDOMWindow* aWindow,
|
|
IDBFactory** aFactory)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
MOZ_ASSERT(aWindow);
|
|
MOZ_ASSERT(aWindow->IsInnerWindow());
|
|
MOZ_ASSERT(aFactory);
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
nsresult rv = AllowedForWindowInternal(aWindow, getter_AddRefs(principal));
|
|
|
|
if (!(NS_SUCCEEDED(rv) && nsContentUtils::IsSystemPrincipal(principal)) &&
|
|
NS_WARN_IF(!Preferences::GetBool(kPrefIndexedDBEnabled, false))) {
|
|
*aFactory = nullptr;
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
|
}
|
|
|
|
if (rv == NS_ERROR_DOM_NOT_SUPPORTED_ERR) {
|
|
NS_WARNING("IndexedDB is not permitted in a third-party window.");
|
|
*aFactory = nullptr;
|
|
return NS_OK;
|
|
}
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
if (rv == NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR) {
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
MOZ_ASSERT(principal);
|
|
|
|
nsAutoPtr<PrincipalInfo> principalInfo(new PrincipalInfo());
|
|
rv = PrincipalToPrincipalInfo(principal, principalInfo);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
}
|
|
|
|
MOZ_ASSERT(principalInfo->type() == PrincipalInfo::TContentPrincipalInfo ||
|
|
principalInfo->type() == PrincipalInfo::TSystemPrincipalInfo);
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(aWindow);
|
|
nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(webNav);
|
|
|
|
RefPtr<IDBFactory> factory = new IDBFactory();
|
|
factory->mPrincipalInfo = Move(principalInfo);
|
|
factory->mWindow = aWindow;
|
|
factory->mTabChild = TabChild::GetFrom(aWindow);
|
|
factory->mInnerWindowID = aWindow->WindowID();
|
|
factory->mPrivateBrowsingMode =
|
|
loadContext && loadContext->UsePrivateBrowsing();
|
|
|
|
factory.forget(aFactory);
|
|
return NS_OK;
|
|
}
|
|
|
|
// static
|
|
nsresult
|
|
IDBFactory::CreateForMainThreadJS(JSContext* aCx,
|
|
JS::Handle<JSObject*> aOwningObject,
|
|
IDBFactory** aFactory)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
nsAutoPtr<PrincipalInfo> principalInfo(new PrincipalInfo());
|
|
nsIPrincipal* principal = nsContentUtils::ObjectPrincipal(aOwningObject);
|
|
MOZ_ASSERT(principal);
|
|
bool isSystem;
|
|
if (!AllowedForPrincipal(principal, &isSystem)) {
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
}
|
|
|
|
nsresult rv = PrincipalToPrincipalInfo(principal, principalInfo);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
return rv;
|
|
}
|
|
|
|
rv = CreateForMainThreadJSInternal(aCx, aOwningObject, principalInfo, aFactory);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
return rv;
|
|
}
|
|
|
|
MOZ_ASSERT(!principalInfo);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
// static
|
|
nsresult
|
|
IDBFactory::CreateForDatastore(JSContext* aCx,
|
|
JS::Handle<JSObject*> aOwningObject,
|
|
IDBFactory** aFactory)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
// There should be a null principal pushed here, but it's still chrome...
|
|
MOZ_ASSERT(!nsContentUtils::IsCallerChrome());
|
|
|
|
nsAutoPtr<PrincipalInfo> principalInfo(
|
|
new PrincipalInfo(SystemPrincipalInfo()));
|
|
|
|
nsresult rv =
|
|
CreateForMainThreadJSInternal(aCx, aOwningObject, principalInfo, aFactory);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
return rv;
|
|
}
|
|
|
|
MOZ_ASSERT(!principalInfo);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
// static
|
|
nsresult
|
|
IDBFactory::CreateForWorker(JSContext* aCx,
|
|
JS::Handle<JSObject*> aOwningObject,
|
|
const PrincipalInfo& aPrincipalInfo,
|
|
uint64_t aInnerWindowID,
|
|
IDBFactory** aFactory)
|
|
{
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
MOZ_ASSERT(aPrincipalInfo.type() != PrincipalInfo::T__None);
|
|
|
|
nsAutoPtr<PrincipalInfo> principalInfo(new PrincipalInfo(aPrincipalInfo));
|
|
|
|
nsresult rv =
|
|
CreateForJSInternal(aCx,
|
|
aOwningObject,
|
|
principalInfo,
|
|
aInnerWindowID,
|
|
aFactory);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
return rv;
|
|
}
|
|
|
|
MOZ_ASSERT(!principalInfo);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
// static
|
|
nsresult
|
|
IDBFactory::CreateForMainThreadJSInternal(
|
|
JSContext* aCx,
|
|
JS::Handle<JSObject*> aOwningObject,
|
|
nsAutoPtr<PrincipalInfo>& aPrincipalInfo,
|
|
IDBFactory** aFactory)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
MOZ_ASSERT(aPrincipalInfo);
|
|
|
|
if (aPrincipalInfo->type() != PrincipalInfo::TSystemPrincipalInfo &&
|
|
NS_WARN_IF(!Preferences::GetBool(kPrefIndexedDBEnabled, false))) {
|
|
*aFactory = nullptr;
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
|
}
|
|
|
|
IndexedDatabaseManager* mgr = IndexedDatabaseManager::GetOrCreate();
|
|
if (NS_WARN_IF(!mgr)) {
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
}
|
|
|
|
nsresult rv =
|
|
CreateForJSInternal(aCx,
|
|
aOwningObject,
|
|
aPrincipalInfo,
|
|
/* aInnerWindowID */ 0,
|
|
aFactory);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
return rv;
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
// static
|
|
nsresult
|
|
IDBFactory::CreateForJSInternal(JSContext* aCx,
|
|
JS::Handle<JSObject*> aOwningObject,
|
|
nsAutoPtr<PrincipalInfo>& aPrincipalInfo,
|
|
uint64_t aInnerWindowID,
|
|
IDBFactory** aFactory)
|
|
{
|
|
MOZ_ASSERT(aCx);
|
|
MOZ_ASSERT(aOwningObject);
|
|
MOZ_ASSERT(aPrincipalInfo);
|
|
MOZ_ASSERT(aPrincipalInfo->type() != PrincipalInfo::T__None);
|
|
MOZ_ASSERT(aFactory);
|
|
MOZ_ASSERT(JS_GetGlobalForObject(aCx, aOwningObject) == aOwningObject,
|
|
"Not a global object!");
|
|
|
|
if (aPrincipalInfo->type() != PrincipalInfo::TContentPrincipalInfo &&
|
|
aPrincipalInfo->type() != PrincipalInfo::TSystemPrincipalInfo) {
|
|
NS_WARNING("IndexedDB not allowed for this principal!");
|
|
aPrincipalInfo = nullptr;
|
|
*aFactory = nullptr;
|
|
return NS_OK;
|
|
}
|
|
|
|
RefPtr<IDBFactory> factory = new IDBFactory();
|
|
factory->mPrincipalInfo = aPrincipalInfo.forget();
|
|
factory->mOwningObject = aOwningObject;
|
|
mozilla::HoldJSObjects(factory.get());
|
|
factory->mInnerWindowID = aInnerWindowID;
|
|
|
|
factory.forget(aFactory);
|
|
return NS_OK;
|
|
}
|
|
|
|
// static
|
|
bool
|
|
IDBFactory::AllowedForWindow(nsPIDOMWindow* aWindow)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
MOZ_ASSERT(aWindow);
|
|
MOZ_ASSERT(aWindow->IsInnerWindow());
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
nsresult rv = AllowedForWindowInternal(aWindow, getter_AddRefs(principal));
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// static
|
|
nsresult
|
|
IDBFactory::AllowedForWindowInternal(nsPIDOMWindow* aWindow,
|
|
nsIPrincipal** aPrincipal)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
MOZ_ASSERT(aWindow);
|
|
MOZ_ASSERT(aWindow->IsInnerWindow());
|
|
|
|
if (NS_WARN_IF(!IndexedDatabaseManager::GetOrCreate())) {
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
}
|
|
|
|
nsContentUtils::StorageAccess access =
|
|
nsContentUtils::StorageAllowedForWindow(aWindow);
|
|
|
|
// the factory callsite records whether the browser is in private browsing.
|
|
// and thus we don't have to respect that setting here. IndexedDB has no
|
|
// concept of session-local storage, and thus ignores it.
|
|
if (access == nsContentUtils::StorageAccess::eDeny) {
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
}
|
|
|
|
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(aWindow);
|
|
MOZ_ASSERT(sop);
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = sop->GetPrincipal();
|
|
if (NS_WARN_IF(!principal)) {
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
if (nsContentUtils::IsSystemPrincipal(principal)) {
|
|
principal.forget(aPrincipal);
|
|
return NS_OK;
|
|
}
|
|
|
|
// About URIs shouldn't be able to access IndexedDB unless they have the
|
|
// nsIAboutModule::ENABLE_INDEXED_DB flag set on them.
|
|
nsCOMPtr<nsIURI> uri;
|
|
MOZ_ALWAYS_SUCCEEDS(principal->GetURI(getter_AddRefs(uri)));
|
|
MOZ_ASSERT(uri);
|
|
|
|
bool isAbout = false;
|
|
MOZ_ALWAYS_SUCCEEDS(uri->SchemeIs("about", &isAbout));
|
|
|
|
if (isAbout) {
|
|
nsCOMPtr<nsIAboutModule> module;
|
|
if (NS_SUCCEEDED(NS_GetAboutModule(uri, getter_AddRefs(module)))) {
|
|
uint32_t flags;
|
|
if (NS_SUCCEEDED(module->GetURIFlags(uri, &flags))) {
|
|
if (!(flags & nsIAboutModule::ENABLE_INDEXED_DB)) {
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
|
}
|
|
} else {
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
|
}
|
|
} else {
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
|
}
|
|
}
|
|
|
|
principal.forget(aPrincipal);
|
|
return NS_OK;
|
|
}
|
|
|
|
// static
|
|
bool
|
|
IDBFactory::AllowedForPrincipal(nsIPrincipal* aPrincipal,
|
|
bool* aIsSystemPrincipal)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
MOZ_ASSERT(aPrincipal);
|
|
|
|
if (NS_WARN_IF(!IndexedDatabaseManager::GetOrCreate())) {
|
|
return false;
|
|
}
|
|
|
|
if (nsContentUtils::IsSystemPrincipal(aPrincipal)) {
|
|
if (aIsSystemPrincipal) {
|
|
*aIsSystemPrincipal = true;
|
|
}
|
|
return true;
|
|
} else if (aIsSystemPrincipal) {
|
|
*aIsSystemPrincipal = false;
|
|
}
|
|
|
|
bool isNullPrincipal;
|
|
if (NS_WARN_IF(NS_FAILED(aPrincipal->GetIsNullPrincipal(&isNullPrincipal))) ||
|
|
isNullPrincipal) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
IDBFactory::AssertIsOnOwningThread() const
|
|
{
|
|
MOZ_ASSERT(mOwningThread);
|
|
MOZ_ASSERT(PR_GetCurrentThread() == mOwningThread);
|
|
}
|
|
|
|
PRThread*
|
|
IDBFactory::OwningThread() const
|
|
{
|
|
MOZ_ASSERT(mOwningThread);
|
|
return mOwningThread;
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
bool
|
|
IDBFactory::IsChrome() const
|
|
{
|
|
AssertIsOnOwningThread();
|
|
MOZ_ASSERT(mPrincipalInfo);
|
|
|
|
return mPrincipalInfo->type() == PrincipalInfo::TSystemPrincipalInfo;
|
|
}
|
|
|
|
void
|
|
IDBFactory::IncrementParentLoggingRequestSerialNumber()
|
|
{
|
|
AssertIsOnOwningThread();
|
|
MOZ_ASSERT(mBackgroundActor);
|
|
|
|
mBackgroundActor->SendIncrementLoggingRequestSerialNumber();
|
|
}
|
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
|
IDBFactory::Open(const nsAString& aName,
|
|
uint64_t aVersion,
|
|
ErrorResult& aRv)
|
|
{
|
|
return OpenInternal(/* aPrincipal */ nullptr,
|
|
aName,
|
|
Optional<uint64_t>(aVersion),
|
|
Optional<StorageType>(),
|
|
/* aDeleting */ false,
|
|
aRv);
|
|
}
|
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
|
IDBFactory::Open(const nsAString& aName,
|
|
const IDBOpenDBOptions& aOptions,
|
|
ErrorResult& aRv)
|
|
{
|
|
return OpenInternal(/* aPrincipal */ nullptr,
|
|
aName,
|
|
aOptions.mVersion,
|
|
aOptions.mStorage,
|
|
/* aDeleting */ false,
|
|
aRv);
|
|
}
|
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
|
IDBFactory::DeleteDatabase(const nsAString& aName,
|
|
const IDBOpenDBOptions& aOptions,
|
|
ErrorResult& aRv)
|
|
{
|
|
return OpenInternal(/* aPrincipal */ nullptr,
|
|
aName,
|
|
Optional<uint64_t>(),
|
|
aOptions.mStorage,
|
|
/* aDeleting */ true,
|
|
aRv);
|
|
}
|
|
|
|
int16_t
|
|
IDBFactory::Cmp(JSContext* aCx, JS::Handle<JS::Value> aFirst,
|
|
JS::Handle<JS::Value> aSecond, ErrorResult& aRv)
|
|
{
|
|
Key first, second;
|
|
nsresult rv = first.SetFromJSVal(aCx, aFirst);
|
|
if (NS_FAILED(rv)) {
|
|
aRv.Throw(rv);
|
|
return 0;
|
|
}
|
|
|
|
rv = second.SetFromJSVal(aCx, aSecond);
|
|
if (NS_FAILED(rv)) {
|
|
aRv.Throw(rv);
|
|
return 0;
|
|
}
|
|
|
|
if (first.IsUnset() || second.IsUnset()) {
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
return 0;
|
|
}
|
|
|
|
return Key::CompareKeys(first, second);
|
|
}
|
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
|
IDBFactory::OpenForPrincipal(nsIPrincipal* aPrincipal,
|
|
const nsAString& aName,
|
|
uint64_t aVersion,
|
|
ErrorResult& aRv)
|
|
{
|
|
MOZ_ASSERT(aPrincipal);
|
|
if (!NS_IsMainThread()) {
|
|
MOZ_CRASH("Figure out security checks for workers!");
|
|
}
|
|
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
|
|
|
|
return OpenInternal(aPrincipal,
|
|
aName,
|
|
Optional<uint64_t>(aVersion),
|
|
Optional<StorageType>(),
|
|
/* aDeleting */ false,
|
|
aRv);
|
|
}
|
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
|
IDBFactory::OpenForPrincipal(nsIPrincipal* aPrincipal,
|
|
const nsAString& aName,
|
|
const IDBOpenDBOptions& aOptions,
|
|
ErrorResult& aRv)
|
|
{
|
|
MOZ_ASSERT(aPrincipal);
|
|
if (!NS_IsMainThread()) {
|
|
MOZ_CRASH("Figure out security checks for workers!");
|
|
}
|
|
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
|
|
|
|
return OpenInternal(aPrincipal,
|
|
aName,
|
|
aOptions.mVersion,
|
|
aOptions.mStorage,
|
|
/* aDeleting */ false,
|
|
aRv);
|
|
}
|
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
|
IDBFactory::DeleteForPrincipal(nsIPrincipal* aPrincipal,
|
|
const nsAString& aName,
|
|
const IDBOpenDBOptions& aOptions,
|
|
ErrorResult& aRv)
|
|
{
|
|
MOZ_ASSERT(aPrincipal);
|
|
if (!NS_IsMainThread()) {
|
|
MOZ_CRASH("Figure out security checks for workers!");
|
|
}
|
|
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
|
|
|
|
return OpenInternal(aPrincipal,
|
|
aName,
|
|
Optional<uint64_t>(),
|
|
aOptions.mStorage,
|
|
/* aDeleting */ true,
|
|
aRv);
|
|
}
|
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
|
IDBFactory::OpenInternal(nsIPrincipal* aPrincipal,
|
|
const nsAString& aName,
|
|
const Optional<uint64_t>& aVersion,
|
|
const Optional<StorageType>& aStorageType,
|
|
bool aDeleting,
|
|
ErrorResult& aRv)
|
|
{
|
|
MOZ_ASSERT(mWindow || mOwningObject);
|
|
MOZ_ASSERT_IF(!mWindow, !mPrivateBrowsingMode);
|
|
|
|
CommonFactoryRequestParams commonParams;
|
|
commonParams.privateBrowsingMode() = mPrivateBrowsingMode;
|
|
|
|
PrincipalInfo& principalInfo = commonParams.principalInfo();
|
|
|
|
if (aPrincipal) {
|
|
if (!NS_IsMainThread()) {
|
|
MOZ_CRASH("Figure out security checks for workers!");
|
|
}
|
|
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
|
|
|
|
if (NS_WARN_IF(NS_FAILED(PrincipalToPrincipalInfo(aPrincipal,
|
|
&principalInfo)))) {
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
return nullptr;
|
|
}
|
|
|
|
if (principalInfo.type() != PrincipalInfo::TContentPrincipalInfo &&
|
|
principalInfo.type() != PrincipalInfo::TSystemPrincipalInfo) {
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
return nullptr;
|
|
}
|
|
} else {
|
|
principalInfo = *mPrincipalInfo;
|
|
}
|
|
|
|
uint64_t version = 0;
|
|
if (!aDeleting && aVersion.WasPassed()) {
|
|
if (aVersion.Value() < 1) {
|
|
aRv.ThrowTypeError<MSG_INVALID_VERSION>();
|
|
return nullptr;
|
|
}
|
|
version = aVersion.Value();
|
|
}
|
|
|
|
// Nothing can be done here if we have previously failed to create a
|
|
// background actor.
|
|
if (mBackgroundActorFailed) {
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
return nullptr;
|
|
}
|
|
|
|
PersistenceType persistenceType;
|
|
|
|
if (principalInfo.type() == PrincipalInfo::TSystemPrincipalInfo) {
|
|
// Chrome privilege always gets persistent storage.
|
|
persistenceType = PERSISTENCE_TYPE_PERSISTENT;
|
|
} else {
|
|
persistenceType = PersistenceTypeFromStorage(aStorageType);
|
|
}
|
|
|
|
DatabaseMetadata& metadata = commonParams.metadata();
|
|
metadata.name() = aName;
|
|
metadata.persistenceType() = persistenceType;
|
|
|
|
FactoryRequestParams params;
|
|
if (aDeleting) {
|
|
metadata.version() = 0;
|
|
params = DeleteDatabaseRequestParams(commonParams);
|
|
} else {
|
|
metadata.version() = version;
|
|
params = OpenDatabaseRequestParams(commonParams);
|
|
}
|
|
|
|
if (!mBackgroundActor && mPendingRequests.IsEmpty()) {
|
|
BackgroundChildImpl::ThreadLocal* threadLocal =
|
|
BackgroundChildImpl::GetThreadLocalForCurrentThread();
|
|
|
|
nsAutoPtr<ThreadLocal> newIDBThreadLocal;
|
|
ThreadLocal* idbThreadLocal;
|
|
|
|
if (threadLocal && threadLocal->mIndexedDBThreadLocal) {
|
|
idbThreadLocal = threadLocal->mIndexedDBThreadLocal;
|
|
} else {
|
|
nsCOMPtr<nsIUUIDGenerator> uuidGen =
|
|
do_GetService("@mozilla.org/uuid-generator;1");
|
|
MOZ_ASSERT(uuidGen);
|
|
|
|
nsID id;
|
|
MOZ_ALWAYS_SUCCEEDS(uuidGen->GenerateUUIDInPlace(&id));
|
|
|
|
newIDBThreadLocal = idbThreadLocal = new ThreadLocal(id);
|
|
}
|
|
|
|
if (PBackgroundChild* actor = BackgroundChild::GetForCurrentThread()) {
|
|
BackgroundActorCreated(actor, idbThreadLocal->GetLoggingInfo());
|
|
} else {
|
|
// We need to start the sequence to create a background actor for this
|
|
// thread.
|
|
RefPtr<BackgroundCreateCallback> cb =
|
|
new BackgroundCreateCallback(this, idbThreadLocal->GetLoggingInfo());
|
|
if (NS_WARN_IF(!BackgroundChild::GetOrCreateForCurrentThread(cb))) {
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
if (newIDBThreadLocal) {
|
|
if (!threadLocal) {
|
|
threadLocal = BackgroundChildImpl::GetThreadLocalForCurrentThread();
|
|
}
|
|
MOZ_ASSERT(threadLocal);
|
|
MOZ_ASSERT(!threadLocal->mIndexedDBThreadLocal);
|
|
|
|
threadLocal->mIndexedDBThreadLocal = newIDBThreadLocal.forget();
|
|
}
|
|
}
|
|
|
|
RefPtr<IDBOpenDBRequest> request;
|
|
|
|
if (mWindow) {
|
|
JS::Rooted<JSObject*> scriptOwner(nsContentUtils::RootingCxForThread(),
|
|
nsGlobalWindow::Cast(mWindow.get())->FastGetGlobalJSObject());
|
|
MOZ_ASSERT(scriptOwner);
|
|
|
|
request = IDBOpenDBRequest::CreateForWindow(this, mWindow, scriptOwner);
|
|
} else {
|
|
JS::Rooted<JSObject*> scriptOwner(nsContentUtils::RootingCxForThread(),
|
|
mOwningObject);
|
|
|
|
request = IDBOpenDBRequest::CreateForJS(this, scriptOwner);
|
|
if (!request) {
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
aRv.ThrowUncatchableException();
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
MOZ_ASSERT(request);
|
|
|
|
if (aDeleting) {
|
|
IDB_LOG_MARK("IndexedDB %s: Child Request[%llu]: "
|
|
"indexedDB.deleteDatabase(\"%s\")",
|
|
"IndexedDB %s: C R[%llu]: IDBFactory.deleteDatabase()",
|
|
IDB_LOG_ID_STRING(),
|
|
request->LoggingSerialNumber(),
|
|
NS_ConvertUTF16toUTF8(aName).get());
|
|
} else {
|
|
IDB_LOG_MARK("IndexedDB %s: Child Request[%llu]: "
|
|
"indexedDB.open(\"%s\", %s)",
|
|
"IndexedDB %s: C R[%llu]: IDBFactory.open()",
|
|
IDB_LOG_ID_STRING(),
|
|
request->LoggingSerialNumber(),
|
|
NS_ConvertUTF16toUTF8(aName).get(),
|
|
IDB_LOG_STRINGIFY(aVersion));
|
|
}
|
|
|
|
// If we already have a background actor then we can start this request now.
|
|
if (mBackgroundActor) {
|
|
nsresult rv = InitiateRequest(request, params);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
return nullptr;
|
|
}
|
|
} else {
|
|
mPendingRequests.AppendElement(new PendingRequestInfo(request, params));
|
|
}
|
|
|
|
return request.forget();
|
|
}
|
|
|
|
nsresult
|
|
IDBFactory::BackgroundActorCreated(PBackgroundChild* aBackgroundActor,
|
|
const LoggingInfo& aLoggingInfo)
|
|
{
|
|
MOZ_ASSERT(aBackgroundActor);
|
|
MOZ_ASSERT(!mBackgroundActor);
|
|
MOZ_ASSERT(!mBackgroundActorFailed);
|
|
|
|
{
|
|
BackgroundFactoryChild* actor = new BackgroundFactoryChild(this);
|
|
|
|
mBackgroundActor =
|
|
static_cast<BackgroundFactoryChild*>(
|
|
aBackgroundActor->SendPBackgroundIDBFactoryConstructor(actor,
|
|
aLoggingInfo));
|
|
}
|
|
|
|
if (NS_WARN_IF(!mBackgroundActor)) {
|
|
BackgroundActorFailed();
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
}
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
for (uint32_t index = 0, count = mPendingRequests.Length();
|
|
index < count;
|
|
index++) {
|
|
nsAutoPtr<PendingRequestInfo> info(mPendingRequests[index].forget());
|
|
|
|
nsresult rv2 = InitiateRequest(info->mRequest, info->mParams);
|
|
|
|
// Warn for every failure, but just return the first failure if there are
|
|
// multiple failures.
|
|
if (NS_WARN_IF(NS_FAILED(rv2)) && NS_SUCCEEDED(rv)) {
|
|
rv = rv2;
|
|
}
|
|
}
|
|
|
|
mPendingRequests.Clear();
|
|
|
|
return rv;
|
|
}
|
|
|
|
void
|
|
IDBFactory::BackgroundActorFailed()
|
|
{
|
|
MOZ_ASSERT(!mPendingRequests.IsEmpty());
|
|
MOZ_ASSERT(!mBackgroundActor);
|
|
MOZ_ASSERT(!mBackgroundActorFailed);
|
|
|
|
mBackgroundActorFailed = true;
|
|
|
|
for (uint32_t index = 0, count = mPendingRequests.Length();
|
|
index < count;
|
|
index++) {
|
|
nsAutoPtr<PendingRequestInfo> info(mPendingRequests[index].forget());
|
|
info->mRequest->
|
|
DispatchNonTransactionError(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
}
|
|
|
|
mPendingRequests.Clear();
|
|
}
|
|
|
|
nsresult
|
|
IDBFactory::InitiateRequest(IDBOpenDBRequest* aRequest,
|
|
const FactoryRequestParams& aParams)
|
|
{
|
|
MOZ_ASSERT(aRequest);
|
|
MOZ_ASSERT(mBackgroundActor);
|
|
MOZ_ASSERT(!mBackgroundActorFailed);
|
|
|
|
bool deleting;
|
|
uint64_t requestedVersion;
|
|
|
|
switch (aParams.type()) {
|
|
case FactoryRequestParams::TDeleteDatabaseRequestParams: {
|
|
const DatabaseMetadata& metadata =
|
|
aParams.get_DeleteDatabaseRequestParams().commonParams().metadata();
|
|
deleting = true;
|
|
requestedVersion = metadata.version();
|
|
break;
|
|
}
|
|
|
|
case FactoryRequestParams::TOpenDatabaseRequestParams: {
|
|
const DatabaseMetadata& metadata =
|
|
aParams.get_OpenDatabaseRequestParams().commonParams().metadata();
|
|
deleting = false;
|
|
requestedVersion = metadata.version();
|
|
break;
|
|
}
|
|
|
|
default:
|
|
MOZ_CRASH("Should never get here!");
|
|
}
|
|
|
|
auto actor =
|
|
new BackgroundFactoryRequestChild(this,
|
|
aRequest,
|
|
deleting,
|
|
requestedVersion);
|
|
|
|
if (!mBackgroundActor->SendPBackgroundIDBFactoryRequestConstructor(actor,
|
|
aParams)) {
|
|
aRequest->DispatchNonTransactionError(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(IDBFactory)
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(IDBFactory)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBFactory)
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
NS_INTERFACE_MAP_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBFactory)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(IDBFactory)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBFactory)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
tmp->mOwningObject = nullptr;
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBFactory)
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mOwningObject)
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
JSObject*
|
|
IDBFactory::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
|
{
|
|
return IDBFactoryBinding::Wrap(aCx, this, aGivenProto);
|
|
}
|
|
|
|
NS_IMPL_ISUPPORTS(IDBFactory::BackgroundCreateCallback,
|
|
nsIIPCBackgroundChildCreateCallback)
|
|
|
|
void
|
|
IDBFactory::BackgroundCreateCallback::ActorCreated(PBackgroundChild* aActor)
|
|
{
|
|
MOZ_ASSERT(aActor);
|
|
MOZ_ASSERT(mFactory);
|
|
|
|
RefPtr<IDBFactory> factory;
|
|
mFactory.swap(factory);
|
|
|
|
factory->BackgroundActorCreated(aActor, mLoggingInfo);
|
|
}
|
|
|
|
void
|
|
IDBFactory::BackgroundCreateCallback::ActorFailed()
|
|
{
|
|
MOZ_ASSERT(mFactory);
|
|
|
|
RefPtr<IDBFactory> factory;
|
|
mFactory.swap(factory);
|
|
|
|
factory->BackgroundActorFailed();
|
|
}
|
|
|
|
} // namespace dom
|
|
} // namespace mozilla
|