示例#1
0
already_AddRefed<SharedThreadPool> GetMediaThreadPool(MediaThreadType aType) {
  const char* name;
  switch (aType) {
    case MediaThreadType::PLATFORM_DECODER:
      name = "MediaPDecoder";
      break;
    case MediaThreadType::MSG_CONTROL:
      name = "MSGControl";
      break;
    case MediaThreadType::WEBRTC_DECODER:
      name = "WebRTCPD";
      break;
    default:
      MOZ_FALLTHROUGH_ASSERT("Unexpected MediaThreadType");
    case MediaThreadType::PLAYBACK:
      name = "MediaPlayback";
      break;
  }

  static const uint32_t kMediaThreadPoolDefaultCount = 4;
  RefPtr<SharedThreadPool> pool = SharedThreadPool::Get(
      nsDependentCString(name), kMediaThreadPoolDefaultCount);

  // Ensure a larger stack for platform decoder threads
  if (aType == MediaThreadType::PLATFORM_DECODER) {
    const uint32_t minStackSize = 512 * 1024;
    uint32_t stackSize;
    MOZ_ALWAYS_SUCCEEDS(pool->GetThreadStackSize(&stackSize));
    if (stackSize < minStackSize) {
      MOZ_ALWAYS_SUCCEEDS(pool->SetThreadStackSize(minStackSize));
    }
  }

  return pool.forget();
}
示例#2
0
// static
nsresult IDBFactory::AllowedForWindowInternal(nsPIDOMWindowInner* aWindow,
                                              nsIPrincipal** aPrincipal) {
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(aWindow);

  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;
}
示例#3
0
mozilla::ipc::IProtocol*
NuwaParent::CloneProtocol(Channel* aChannel,
                          ProtocolCloneContext* aCtx)
{
  MOZ_ASSERT(NS_IsMainThread());
  RefPtr<NuwaParent> self = this;

  MonitorAutoLock lock(mMonitor);

  // Alloc NuwaParent on the worker thread.
  nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([self] () -> void
  {
    MonitorAutoLock lock(self->mMonitor);
    // XXX Calling NuwaParent::Alloc() leads to a compilation error. Use
    // self->Alloc() as a workaround.
    self->mClonedActor = self->Alloc();
    lock.Notify();
  });
  MOZ_ASSERT(runnable);
  MOZ_ALWAYS_SUCCEEDS(mWorkerThread->Dispatch(runnable, NS_DISPATCH_NORMAL));

  while (!mClonedActor) {
    lock.Wait();
  }
  RefPtr<NuwaParent> actor = mClonedActor;
  mClonedActor = nullptr;

  // mManager of the cloned actor is assigned after returning from this method.
  // We can't call ActorConstructed() right after Alloc() in the above runnable.
  // To be safe we dispatch a runnable to the current thread to do it.
  runnable = NS_NewRunnableFunction([actor] () -> void
  {
    MOZ_ASSERT(NS_IsMainThread());

    nsCOMPtr<nsIRunnable> nested = NS_NewRunnableFunction([actor] () -> void
    {
      AssertIsOnBackgroundThread();

      // Call NuwaParent::ActorConstructed() on the worker thread.
      actor->ActorConstructed();

      // The actor can finally be deleted after fully constructed.
      mozilla::Unused << actor->Send__delete__(actor);
    });
    MOZ_ASSERT(nested);
    MOZ_ALWAYS_SUCCEEDS(actor->mWorkerThread->Dispatch(nested, NS_DISPATCH_NORMAL));
  });

  MOZ_ASSERT(runnable);
  MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable));

  return actor;
}
示例#4
0
// static
RequestMode
InternalRequest::MapChannelToRequestMode(nsIChannel* aChannel)
{
  MOZ_ASSERT(aChannel);

  nsCOMPtr<nsILoadInfo> loadInfo;
  MOZ_ALWAYS_SUCCEEDS(aChannel->GetLoadInfo(getter_AddRefs(loadInfo)));

  nsContentPolicyType contentPolicy = loadInfo->InternalContentPolicyType();
  if (IsNavigationContentPolicy(contentPolicy)) {
    return RequestMode::Navigate;
  }

  // TODO: remove the worker override once securityMode is fully implemented (bug 1189945)
  if (IsWorkerContentPolicy(contentPolicy)) {
    return RequestMode::Same_origin;
  }

  uint32_t securityMode;
  MOZ_ALWAYS_SUCCEEDS(loadInfo->GetSecurityMode(&securityMode));

  switch(securityMode) {
    case nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS:
    case nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED:
      return RequestMode::Same_origin;
    case nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS:
    case nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL:
      return RequestMode::No_cors;
    case nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS:
      // TODO: Check additional flag force-preflight after bug 1199693 (bug 1189945)
      return RequestMode::Cors;
    default:
      // TODO: assert never reached after CorsMode flag removed (bug 1189945)
      MOZ_ASSERT(securityMode == nsILoadInfo::SEC_NORMAL);
      break;
  }

  // TODO: remove following code once securityMode is fully implemented (bug 1189945)

  nsCOMPtr<nsIHttpChannelInternal> httpChannel = do_QueryInterface(aChannel);

  uint32_t corsMode;
  MOZ_ALWAYS_SUCCEEDS(httpChannel->GetCorsMode(&corsMode));
  MOZ_ASSERT(corsMode != nsIHttpChannelInternal::CORS_MODE_NAVIGATE);

  // This cast is valid due to static asserts in ServiceWorkerManager.cpp.
  return static_cast<RequestMode>(corsMode);
}
示例#5
0
already_AddRefed<Promise>
ServiceWorkerGlobalScope::SkipWaiting(ErrorResult& aRv)
{
  mWorkerPrivate->AssertIsOnWorkerThread();
  MOZ_ASSERT(mWorkerPrivate->IsServiceWorker());

  RefPtr<Promise> promise = Promise::Create(this, aRv);
  if (NS_WARN_IF(aRv.Failed())) {
    return nullptr;
  }

  RefPtr<PromiseWorkerProxy> promiseProxy =
    PromiseWorkerProxy::Create(mWorkerPrivate, promise);
  if (!promiseProxy) {
    promise->MaybeResolveWithUndefined();
    return promise.forget();
  }

  RefPtr<WorkerScopeSkipWaitingRunnable> runnable =
    new WorkerScopeSkipWaitingRunnable(promiseProxy,
                                       NS_ConvertUTF16toUTF8(mScope));

  MOZ_ALWAYS_SUCCEEDS(mWorkerPrivate->DispatchToMainThread(runnable.forget()));
  return promise.forget();
}
already_AddRefed<Promise>
PushSubscription::UnsubscribeFromWorker(ErrorResult& aRv)
{
  WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
  MOZ_ASSERT(worker);
  worker->AssertIsOnWorkerThread();

  nsCOMPtr<nsIGlobalObject> global = worker->GlobalScope();
  RefPtr<Promise> p = Promise::Create(global, aRv);
  if (NS_WARN_IF(aRv.Failed())) {
    return nullptr;
  }

  RefPtr<PromiseWorkerProxy> proxy = PromiseWorkerProxy::Create(worker, p);
  if (!proxy) {
    p->MaybeReject(NS_ERROR_DOM_PUSH_SERVICE_UNREACHABLE);
    return p.forget();
  }

  RefPtr<UnsubscribeRunnable> r =
    new UnsubscribeRunnable(proxy, mScope);
  MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r));

  return p.forget();
}
bool
ServiceWorkerManagerParent::RecvUnregister(const PrincipalInfo& aPrincipalInfo,
                                           const nsString& aScope)
{
  AssertIsInMainProcess();
  AssertIsOnBackgroundThread();

  // Basic validation.
  if (aScope.IsEmpty() ||
      aPrincipalInfo.type() == PrincipalInfo::TNullPrincipalInfo ||
      aPrincipalInfo.type() == PrincipalInfo::TSystemPrincipalInfo) {
    return false;
  }

  RefPtr<UnregisterServiceWorkerCallback> callback =
    new UnregisterServiceWorkerCallback(aPrincipalInfo, aScope, mID);

  RefPtr<ContentParent> parent =
    BackgroundParent::GetContentParent(Manager());

  // If the ContentParent is null we are dealing with a same-process actor.
  if (!parent) {
    callback->Run();
    return true;
  }

  RefPtr<CheckPrincipalWithCallbackRunnable> runnable =
    new CheckPrincipalWithCallbackRunnable(parent.forget(), aPrincipalInfo,
                                           callback);
  MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable));

  return true;
}
示例#8
0
void
IDBDatabase::CloseInternal()
{
  AssertIsOnOwningThread();

  if (!mClosed) {
    mClosed = true;

    ExpireFileActors(/* aExpireAll */ true);

    if (mObserver) {
      mObserver->Revoke();

      nsCOMPtr<nsIObserverService> obsSvc = GetObserverService();
      if (obsSvc) {
        // These might not have been registered.
        obsSvc->RemoveObserver(mObserver, kCycleCollectionObserverTopic);
        obsSvc->RemoveObserver(mObserver, kMemoryPressureObserverTopic);

        MOZ_ALWAYS_SUCCEEDS(
          obsSvc->RemoveObserver(mObserver, kWindowObserverTopic));
      }

      mObserver = nullptr;
    }

    if (mBackgroundActor && !mInvalidated) {
      mBackgroundActor->SendClose();
    }
  }
}
示例#9
0
NS_IMETHODIMP
FetchDriver::AsyncOnChannelRedirect(nsIChannel* aOldChannel,
                                    nsIChannel* aNewChannel,
                                    uint32_t aFlags,
                                    nsIAsyncVerifyRedirectCallback *aCallback)
{
  nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aNewChannel);
  if (httpChannel) {
    SetRequestHeaders(httpChannel);
  }

  // "HTTP-redirect fetch": step 14 "Append locationURL to request's URL list."
  nsCOMPtr<nsIURI> uri;
  MOZ_ALWAYS_SUCCEEDS(aNewChannel->GetURI(getter_AddRefs(uri)));

  nsCOMPtr<nsIURI> uriClone;
  nsresult rv = uri->CloneIgnoringRef(getter_AddRefs(uriClone));
  if(NS_WARN_IF(NS_FAILED(rv))){
    return rv;
  }

  nsCString spec;
  rv = uriClone->GetSpec(spec);
  if(NS_WARN_IF(NS_FAILED(rv))){
    return rv;
  }

  mRequest->AddURL(spec);

  aCallback->OnRedirectVerifyCallback(NS_OK);
  return NS_OK;
}
示例#10
0
void
ServiceWorkerInfo::UpdateState(ServiceWorkerState aState)
{
  AssertIsOnMainThread();
#ifdef DEBUG
  // Any state can directly transition to redundant, but everything else is
  // ordered.
  if (aState != ServiceWorkerState::Redundant) {
    MOZ_ASSERT_IF(mState == ServiceWorkerState::EndGuard_, aState == ServiceWorkerState::Installing);
    MOZ_ASSERT_IF(mState == ServiceWorkerState::Installing, aState == ServiceWorkerState::Installed);
    MOZ_ASSERT_IF(mState == ServiceWorkerState::Installed, aState == ServiceWorkerState::Activating);
    MOZ_ASSERT_IF(mState == ServiceWorkerState::Activating, aState == ServiceWorkerState::Activated);
  }
  // Activated can only go to redundant.
  MOZ_ASSERT_IF(mState == ServiceWorkerState::Activated, aState == ServiceWorkerState::Redundant);
#endif
  // Flush any pending functional events to the worker when it transitions to the
  // activated state.
  // TODO: Do we care that these events will race with the propagation of the
  //       state change?
  if (aState == ServiceWorkerState::Activated && mState != aState) {
    mServiceWorkerPrivate->Activated();
  }
  mState = aState;
  nsCOMPtr<nsIRunnable> r = new ChangeStateUpdater(mInstances, mState);
  MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r.forget()));
  if (mState == ServiceWorkerState::Redundant) {
    serviceWorkerScriptCache::PurgeCache(mPrincipal, mCacheName);
  }
}
示例#11
0
AudioOffloadPlayer::AudioOffloadPlayer(MediaOmxCommonDecoder* aObserver) :
  mStarted(false),
  mPlaying(false),
  mReachedEOS(false),
  mIsElementVisible(true),
  mSampleRate(0),
  mStartPosUs(0),
  mPositionTimeMediaUs(-1),
  mInputBuffer(nullptr)
{
  MOZ_ASSERT(NS_IsMainThread());

  CHECK(aObserver);
#if ANDROID_VERSION >= 21
  mSessionId = AudioSystem::newAudioUniqueId();
  AudioSystem::acquireAudioSessionId(mSessionId, -1);
#else
  mSessionId = AudioSystem::newAudioSessionId();
  AudioSystem::acquireAudioSessionId(mSessionId);
#endif
  mAudioSink = new AudioOutput(mSessionId,
      IPCThreadState::self()->getCallingUid());

  nsCOMPtr<nsIThread> thread;
  MOZ_ALWAYS_SUCCEEDS(NS_GetMainThread(getter_AddRefs(thread)));
  mPositionChanged = mOnPositionChanged.Connect(
    thread, aObserver, &MediaOmxCommonDecoder::NotifyOffloadPlayerPositionChanged);
  mPlaybackEnded = mOnPlaybackEnded.Connect(
    thread, aObserver, &MediaDecoder::PlaybackEnded);
  mPlayerTearDown = mOnPlayerTearDown.Connect(
    thread, aObserver, &MediaOmxCommonDecoder::AudioOffloadTearDown);
  mSeekingStarted = mOnSeekingStarted.Connect(
    thread, aObserver, &MediaDecoder::SeekingStarted);
}
示例#12
0
// static
RequestMode InternalRequest::MapChannelToRequestMode(nsIChannel* aChannel) {
  MOZ_ASSERT(aChannel);

  nsCOMPtr<nsILoadInfo> loadInfo;
  MOZ_ALWAYS_SUCCEEDS(aChannel->GetLoadInfo(getter_AddRefs(loadInfo)));

  nsContentPolicyType contentPolicy = loadInfo->InternalContentPolicyType();
  if (IsNavigationContentPolicy(contentPolicy)) {
    return RequestMode::Navigate;
  }

  // TODO: remove the worker override once securityMode is fully implemented
  // (bug 1189945)
  if (IsWorkerContentPolicy(contentPolicy)) {
    return RequestMode::Same_origin;
  }

  uint32_t securityMode = loadInfo->GetSecurityMode();

  switch (securityMode) {
    case nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS:
    case nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED:
      return RequestMode::Same_origin;
    case nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS:
    case nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL:
      return RequestMode::No_cors;
    case nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS:
      // TODO: Check additional flag force-preflight after bug 1199693 (bug
      // 1189945)
      return RequestMode::Cors;
    default:
      MOZ_ASSERT_UNREACHABLE("Unexpected security mode!");
      return RequestMode::Same_origin;
  }
}
示例#13
0
already_AddRefed<Promise>
PushManager::PerformSubscriptionActionFromWorker(
  SubscriptionAction aAction, ErrorResult& aRv)
{
  WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
  MOZ_ASSERT(worker);
  worker->AssertIsOnWorkerThread();

  nsCOMPtr<nsIGlobalObject> global = worker->GlobalScope();
  RefPtr<Promise> p = Promise::Create(global, aRv);
  if (NS_WARN_IF(aRv.Failed())) {
    return nullptr;
  }

  RefPtr<PromiseWorkerProxy> proxy = PromiseWorkerProxy::Create(worker, p);
  if (!proxy) {
    p->MaybeReject(NS_ERROR_DOM_PUSH_ABORT_ERR);
    return p.forget();
  }

  RefPtr<GetSubscriptionRunnable> r =
    new GetSubscriptionRunnable(proxy, mScope, aAction);
  MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r));

  return p.forget();
}
void
ServiceWorkerRegistrationInfo::TryToActivateAsync()
{
  MOZ_ALWAYS_SUCCEEDS(
    NS_DispatchToMainThread(NewRunnableMethod(this,
                                              &ServiceWorkerRegistrationInfo::TryToActivate)));
}
示例#15
0
bool
NuwaParent::RecvAddNewProcess(const uint32_t& aPid,
                              nsTArray<ProtocolFdMapping>&& aFds)
{
#ifdef MOZ_NUWA_PROCESS
  if (!mContentParent || !mContentParent->IsNuwaProcess()) {
    NS_ERROR("Received AddNewProcess() message from a non-Nuwa process.");
    return false;
  }

  mNewProcessPid = aPid;
  mNewProcessFds->SwapElements(aFds);
  MonitorAutoLock lock(mMonitor);
  if (mBlocked) {
    // Unblock ForkNewProcess().
    mMonitor.Notify();
    mBlocked = false;
  } else {
    nsCOMPtr<nsIRunnable> runnable =
      NS_NewNonOwningRunnableMethodWithArgs<
        uint32_t,
        UniquePtr<nsTArray<ProtocolFdMapping>>&& >(
          mContentParent.get(),
          &ContentParent::OnNewProcessCreated,
          mNewProcessPid,
          Move(mNewProcessFds));
    MOZ_ASSERT(runnable);
    MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable));
  }
  return true;
#else
  NS_ERROR("NuwaParent::RecvAddNewProcess() not implemented!");
  return false;
#endif
}
示例#16
0
void
DeleteFilesRunnable::Dispatch()
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(mState == State_Initial);

  MOZ_ALWAYS_SUCCEEDS(mBackgroundThread->Dispatch(this, NS_DISPATCH_NORMAL));
}
示例#17
0
void
WorkerThread::SetWorker(const WorkerThreadFriendKey& /* aKey */,
                        WorkerPrivate* aWorkerPrivate)
{
  MOZ_ASSERT(PR_GetCurrentThread() == mThread);

  if (aWorkerPrivate) {
    {
      MutexAutoLock lock(mLock);

      MOZ_ASSERT(!mWorkerPrivate);
      MOZ_ASSERT(mAcceptingNonWorkerRunnables);

      mWorkerPrivate = aWorkerPrivate;
#ifdef DEBUG
      mAcceptingNonWorkerRunnables = false;
#endif
    }

    mObserver = new Observer(aWorkerPrivate);
    MOZ_ALWAYS_SUCCEEDS(AddObserver(mObserver));
  } else {
    MOZ_ALWAYS_SUCCEEDS(RemoveObserver(mObserver));
    mObserver = nullptr;

    {
      MutexAutoLock lock(mLock);

      MOZ_ASSERT(mWorkerPrivate);
      MOZ_ASSERT(!mAcceptingNonWorkerRunnables);
      MOZ_ASSERT(!mOtherThreadsDispatchingViaEventTarget,
                 "XPCOM Dispatch hapenning at the same time our thread is "
                 "being unset! This should not be possible!");

      while (mOtherThreadsDispatchingViaEventTarget) {
        mWorkerPrivateCondVar.Wait();
      }

#ifdef DEBUG
      mAcceptingNonWorkerRunnables = true;
#endif
      mWorkerPrivate = nullptr;
    }
  }
}
示例#18
0
void
DeleteFilesRunnable::Finish()
{
  // Must set mState before dispatching otherwise we will race with the main
  // thread.
  mState = State_UnblockingOpen;

  MOZ_ALWAYS_SUCCEEDS(mBackgroundThread->Dispatch(this, NS_DISPATCH_NORMAL));
}
示例#19
0
// static
RequestCredentials
InternalRequest::MapChannelToRequestCredentials(nsIChannel* aChannel)
{
  MOZ_ASSERT(aChannel);

  nsCOMPtr<nsILoadInfo> loadInfo;
  MOZ_ALWAYS_SUCCEEDS(aChannel->GetLoadInfo(getter_AddRefs(loadInfo)));

  uint32_t securityMode;
  MOZ_ALWAYS_SUCCEEDS(loadInfo->GetSecurityMode(&securityMode));

  // TODO: Remove following code after stylesheet and image support cookie policy
  if (securityMode == nsILoadInfo::SEC_NORMAL) {
    uint32_t loadFlags;
    aChannel->GetLoadFlags(&loadFlags);

    if (loadFlags & nsIRequest::LOAD_ANONYMOUS) {
      return RequestCredentials::Omit;
    } else {
      bool includeCrossOrigin;
      nsCOMPtr<nsIHttpChannelInternal> internalChannel = do_QueryInterface(aChannel);

      internalChannel->GetCorsIncludeCredentials(&includeCrossOrigin);
      if (includeCrossOrigin) {
        return RequestCredentials::Include;
      }
    }
    return RequestCredentials::Same_origin;
  }

  uint32_t cookiePolicy = loadInfo->GetCookiePolicy();

  if (cookiePolicy == nsILoadInfo::SEC_COOKIES_INCLUDE) {
    return RequestCredentials::Include;
  } else if (cookiePolicy == nsILoadInfo::SEC_COOKIES_OMIT) {
    return RequestCredentials::Omit;
  } else if (cookiePolicy == nsILoadInfo::SEC_COOKIES_SAME_ORIGIN) {
    return RequestCredentials::Same_origin;
  }

  MOZ_ASSERT_UNREACHABLE("Unexpected cookie policy!");
  return RequestCredentials::Same_origin;
}
示例#20
0
LoadContext::LoadContext(nsIPrincipal* aPrincipal,
                         nsILoadContext* aOptionalBase)
  : mTopFrameElement(nullptr)
  , mNestedFrameId(0)
  , mIsContent(true)
  , mUseRemoteTabs(false)
#ifdef DEBUG
  , mIsNotNull(true)
#endif
{
  PrincipalOriginAttributes poa = BasePrincipal::Cast(aPrincipal)->OriginAttributesRef();
  mOriginAttributes.InheritFromDocToChildDocShell(poa);
  if (!aOptionalBase) {
    return;
  }

  MOZ_ALWAYS_SUCCEEDS(aOptionalBase->GetIsContent(&mIsContent));
  MOZ_ALWAYS_SUCCEEDS(aOptionalBase->GetUseRemoteTabs(&mUseRemoteTabs));
}
示例#21
0
LoadContext::LoadContext(nsIPrincipal* aPrincipal,
                         nsILoadContext* aOptionalBase)
  : mTopFrameElement(nullptr)
  , mNestedFrameId(0)
  , mIsContent(true)
  , mUseRemoteTabs(false)
  , mUseTrackingProtection(false)
#ifdef DEBUG
  , mIsNotNull(true)
#endif
{
  mOriginAttributes = aPrincipal->OriginAttributesRef();
  if (!aOptionalBase) {
    return;
  }

  MOZ_ALWAYS_SUCCEEDS(aOptionalBase->GetIsContent(&mIsContent));
  MOZ_ALWAYS_SUCCEEDS(aOptionalBase->GetUseRemoteTabs(&mUseRemoteTabs));
  MOZ_ALWAYS_SUCCEEDS(aOptionalBase->GetUseTrackingProtection(&mUseTrackingProtection));
}
示例#22
0
bool
VsyncParent::NotifyVsync(TimeStamp aTimeStamp)
{
  // Called on hardware vsync thread. We should post to current ipc thread.
  MOZ_ASSERT(!IsOnBackgroundThread());
  nsCOMPtr<nsIRunnable> vsyncEvent =
    NewRunnableMethod<TimeStamp>(this,
                                 &VsyncParent::DispatchVsyncEvent,
                                 aTimeStamp);
  MOZ_ALWAYS_SUCCEEDS(mBackgroundThread->Dispatch(vsyncEvent, NS_DISPATCH_NORMAL));
  return true;
}
示例#23
0
/* static */ bool
DecoderDoctorLogger::EnsureLogIsEnabled()
{
  for (;;) {
    LogState state = static_cast<LogState>(sLogState);
    switch (state) {
      case scDisabled:
        // Currently disabled, try to be the one to enable.
        if (sLogState.compareExchange(scDisabled, scEnabling)) {
          // We are the one to enable logging, state won't change (except for
          // possible shutdown.)
          // Create DDMediaLogs singleton, which will process the message queue.
          DDMediaLogs::ConstructionResult mediaLogsConstruction =
            DDMediaLogs::New();
          if (NS_FAILED(mediaLogsConstruction.mRv)) {
            PanicInternal("Failed to enable logging", /* aDontBlock */ true);
            return false;
          }
          MOZ_ASSERT(mediaLogsConstruction.mMediaLogs);
          sMediaLogs = mediaLogsConstruction.mMediaLogs;
          // Setup shutdown-time clean-up.
          MOZ_ALWAYS_SUCCEEDS(SystemGroup::Dispatch(
            TaskCategory::Other,
            NS_NewRunnableFunction("DDLogger shutdown setup", [] {
              sDDLogShutdowner = MakeUnique<DDLogShutdowner>();
              ClearOnShutdown(&sDDLogShutdowner, ShutdownPhase::Shutdown);
              sDDLogDeleter = MakeUnique<DDLogDeleter>();
              ClearOnShutdown(&sDDLogDeleter, ShutdownPhase::ShutdownThreads);
            })));

          // Nobody else should change the state when *we* are enabling logging.
          MOZ_ASSERT(sLogState == scEnabling);
          sLogState = scEnabled;
          DDL_INFO("Logging enabled");
          return true;
        }
        // Someone else changed the state before our compareExchange, just loop
        // around to examine the new situation.
        break;
      case scEnabled:
        return true;
      case scEnabling:
        // Someone else is currently enabling logging, actively wait by just
        // looping, until the state changes.
        break;
      case scShutdown:
        // Shutdown is non-recoverable, we cannot enable logging again.
        return false;
    }
    // Not returned yet, loop around to examine the new situation.
  }
}
示例#24
0
nsresult
GeckoMediaPluginService::Init()
{
  MOZ_ASSERT(NS_IsMainThread());

  nsCOMPtr<nsIObserverService> obsService = mozilla::services::GetObserverService();
  MOZ_ASSERT(obsService);
  MOZ_ALWAYS_SUCCEEDS(obsService->AddObserver(this, NS_XPCOM_SHUTDOWN_THREADS_OBSERVER_ID, false));

  // Kick off scanning for plugins
  nsCOMPtr<nsIThread> thread;
  return GetThread(getter_AddRefs(thread));
}
void
ServiceWorkerRegistrationInfo::UpdateRegistrationStateProperties(WhichServiceWorker aWorker,
                                                                 TransitionType aTransition)
{
  AssertIsOnMainThread();

  nsCOMPtr<nsIRunnable> runnable = NewRunnableMethod<WhichServiceWorker, TransitionType>(
         this,
         &ServiceWorkerRegistrationInfo::AsyncUpdateRegistrationStateProperties, aWorker, aTransition);
  MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable.forget()));

  NotifyChromeRegistrationListeners();
}
示例#26
0
void
U2FTokenManager::RunSendPromptNotification(nsString aJSON)
{
  MOZ_ASSERT(NS_IsMainThread());

  nsCOMPtr<nsIObserverService> os = services::GetObserverService();
  if (NS_WARN_IF(!os)) {
    return;
  }

  nsCOMPtr<nsIU2FTokenManager> self = this;
  MOZ_ALWAYS_SUCCEEDS(os->NotifyObservers(self, "webauthn-prompt", aJSON.get()));
}
void
ServiceWorkerManagerService::PropagateSoftUpdate(
                                      uint64_t aParentID,
                                      const PrincipalOriginAttributes& aOriginAttributes,
                                      const nsAString& aScope)
{
  AssertIsOnBackgroundThread();

  nsAutoPtr<nsTArray<NotifySoftUpdateData>> notifySoftUpdateDataArray(
      new nsTArray<NotifySoftUpdateData>());
  DebugOnly<bool> parentFound = false;
  for (auto iter = mAgents.Iter(); !iter.Done(); iter.Next()) {
    RefPtr<ServiceWorkerManagerParent> parent = iter.Get()->GetKey();
    MOZ_ASSERT(parent);

#ifdef DEBUG
    if (parent->ID() == aParentID) {
      parentFound = true;
    }
#endif

    RefPtr<ContentParent> contentParent = parent->GetContentParent();

    // If the ContentParent is null we are dealing with a same-process actor.
    if (!contentParent) {
      Unused << parent->SendNotifySoftUpdate(aOriginAttributes,
                                             nsString(aScope));
      continue;
    }

    NotifySoftUpdateData* data = notifySoftUpdateDataArray->AppendElement();
    data->mContentParent.swap(contentParent);
    data->mParent.swap(parent);
  }

  if (notifySoftUpdateDataArray->IsEmpty()) {
    return;
  }

  RefPtr<NotifySoftUpdateIfPrincipalOkRunnable> runnable =
    new NotifySoftUpdateIfPrincipalOkRunnable(notifySoftUpdateDataArray,
                                              aOriginAttributes, aScope);
  MOZ_ASSERT(!notifySoftUpdateDataArray);
  MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable));

#ifdef DEBUG
  MOZ_ASSERT(parentFound);
#endif
}
void
WorkerDebuggerManager::UnregisterDebugger(WorkerPrivate* aWorkerPrivate)
{
  aWorkerPrivate->AssertIsOnParentThread();

  if (NS_IsMainThread()) {
    UnregisterDebuggerMainThread(aWorkerPrivate);
  } else {
    nsCOMPtr<nsIRunnable> runnable =
      new UnregisterDebuggerMainThreadRunnable(aWorkerPrivate);
    MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable, NS_DISPATCH_NORMAL));

    aWorkerPrivate->WaitForIsDebuggerRegistered(false);
  }
}
示例#29
0
NS_IMETHODIMP
PSMContentStreamListener::OnStopRequest(nsIRequest* request,
                                        nsISupports* context,
                                        nsresult aStatus)
{
  MOZ_LOG(gPIPNSSLog, LogLevel::Debug, ("CertDownloader::OnStopRequest\n"));

  // Because importing the cert can spin the event loop (via alerts), we can't
  // do it here. Do it off the event loop instead.
  nsCOMPtr<nsIRunnable> r =
    NewRunnableMethod(this, &PSMContentStreamListener::ImportCertificate);
  MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r));

  return NS_OK;
}
示例#30
0
template<typename ...T> void
U2FTokenManager::SendPromptNotification(const char16_t* aFormat, T... aArgs)
{
  mozilla::ipc::AssertIsOnBackgroundThread();

  nsAutoString json;
  nsTextFormatter::ssprintf(json, aFormat, aArgs...);

  nsCOMPtr<nsIRunnable> r(NewRunnableMethod<nsString>(
      "U2FTokenManager::RunSendPromptNotification", this,
      &U2FTokenManager::RunSendPromptNotification, json));

  MOZ_ALWAYS_SUCCEEDS(
    GetMainThreadEventTarget()->Dispatch(r.forget(), NS_DISPATCH_NORMAL));
}