Esempio n. 1
0
// 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;
}
Esempio n. 2
0
// 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;
}
Esempio n. 3
0
nsresult
FetchDriver::Fetch(AbortSignal* aSignal, FetchDriverObserver* aObserver)
{
  AssertIsOnMainThread();
#ifdef DEBUG
  MOZ_ASSERT(!mFetchCalled);
  mFetchCalled = true;
#endif

  mObserver = aObserver;

  Telemetry::Accumulate(Telemetry::SERVICE_WORKER_REQUEST_PASSTHROUGH,
                        mRequest->WasCreatedByFetchEvent());

  // FIXME(nsm): Deal with HSTS.

  MOZ_RELEASE_ASSERT(!mRequest->IsSynchronous(),
                     "Synchronous fetch not supported");


  UniquePtr<mozilla::ipc::PrincipalInfo> principalInfo(new mozilla::ipc::PrincipalInfo());
  nsresult rv = PrincipalToPrincipalInfo(mPrincipal, principalInfo.get());
  if (NS_WARN_IF(NS_FAILED(rv))) {
    return rv;
  }

  mRequest->SetPrincipalInfo(std::move(principalInfo));

  // If the signal is aborted, it's time to inform the observer and terminate
  // the operation.
  if (aSignal) {
    if (aSignal->Aborted()) {
      Abort();
      return NS_OK;
    }

    Follow(aSignal);
  }

  rv = HttpFetch(mRequest->GetPreferredAlternativeDataType());
  if (NS_FAILED(rv)) {
    FailWithNetworkError(rv);
  }

  // Any failure is handled by FailWithNetworkError notifying the aObserver.
  return NS_OK;
}
Esempio n. 4
0
// 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;
}