// 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 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; }