WorkerDebuggerManager::WorkerDebuggerManager() : mMutex("WorkerDebuggerManager::mMutex") { AssertIsOnMainThread(); }
WorkerDebuggerManager::~WorkerDebuggerManager() { AssertIsOnMainThread(); }
ServiceWorkerInfo* ServiceWorkerRegistrationInfo::GetActive() const { AssertIsOnMainThread(); return mActiveWorker; }
DOMBindingBase::~DOMBindingBase() { if (!mJSContext) { AssertIsOnMainThread(); } }
ServiceWorkerInfo* ServiceWorkerRegistrationInfo::GetWaiting() const { AssertIsOnMainThread(); return mWaitingWorker; }
void ServiceWorkerRegistrationInfo::RefreshLastUpdateCheckTime() { AssertIsOnMainThread(); mLastUpdateCheckTime = PR_IntervalNow() / PR_MSEC_PER_SEC; }
explicit FailConsumeBodyWorkerRunnable(FetchBody<Derived>* aBody) : MainThreadWorkerControlRunnable(aBody->mWorkerPrivate) , mBody(aBody) { AssertIsOnMainThread(); }
void ServiceWorkerUpdateJob::ComparisonResult(nsresult aStatus, bool aInCacheAndEqual, const nsAString& aNewCacheName, const nsACString& aMaxScope) { AssertIsOnMainThread(); if (NS_WARN_IF(Canceled())) { FailUpdateJob(NS_ERROR_DOM_ABORT_ERR); return; } // Handle failure of the download or comparison. This is part of Update // step 5 as "If the algorithm asynchronously completes with null, then:". if (NS_WARN_IF(NS_FAILED(aStatus))) { FailUpdateJob(aStatus); return; } // The spec validates the response before performing the byte-for-byte check. // Here we perform the comparison in another module and then validate the // script URL and scope. Make sure to do this validation before accepting // an byte-for-byte match since the service-worker-allowed header might have // changed since the last time it was installed. // This is step 2 the "validate response" section of Update algorithm step 5. // Step 1 is performed in the serviceWorkerScriptCache code. nsCOMPtr<nsIURI> scriptURI; nsresult rv = NS_NewURI(getter_AddRefs(scriptURI), mScriptSpec); if (NS_WARN_IF(NS_FAILED(rv))) { FailUpdateJob(NS_ERROR_DOM_SECURITY_ERR); return; } nsCOMPtr<nsIURI> maxScopeURI; if (!aMaxScope.IsEmpty()) { rv = NS_NewURI(getter_AddRefs(maxScopeURI), aMaxScope, nullptr, scriptURI); if (NS_WARN_IF(NS_FAILED(rv))) { FailUpdateJob(NS_ERROR_DOM_SECURITY_ERR); return; } } nsAutoCString defaultAllowedPrefix; rv = GetRequiredScopeStringPrefix(scriptURI, defaultAllowedPrefix, eUseDirectory); if (NS_WARN_IF(NS_FAILED(rv))) { FailUpdateJob(NS_ERROR_DOM_SECURITY_ERR); return; } nsAutoCString maxPrefix(defaultAllowedPrefix); if (maxScopeURI) { rv = GetRequiredScopeStringPrefix(maxScopeURI, maxPrefix, eUsePath); if (NS_WARN_IF(NS_FAILED(rv))) { FailUpdateJob(NS_ERROR_DOM_SECURITY_ERR); return; } } if (!StringBeginsWith(mRegistration->mScope, maxPrefix)) { nsXPIDLString message; NS_ConvertUTF8toUTF16 reportScope(mRegistration->mScope); NS_ConvertUTF8toUTF16 reportMaxPrefix(maxPrefix); const char16_t* params[] = { reportScope.get(), reportMaxPrefix.get() }; rv = nsContentUtils::FormatLocalizedString(nsContentUtils::eDOM_PROPERTIES, "ServiceWorkerScopePathMismatch", params, message); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to format localized string"); RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance(); swm->ReportToAllClients(mScope, message, EmptyString(), EmptyString(), 0, 0, nsIScriptError::errorFlag); FailUpdateJob(NS_ERROR_DOM_SECURITY_ERR); return; } // The response has been validated, so now we can consider if its a // byte-for-byte match. This is step 6 of the Update algorithm. if (aInCacheAndEqual) { Finish(NS_OK); return; } Telemetry::Accumulate(Telemetry::SERVICE_WORKER_UPDATED, 1); // Begin step 7 of the Update algorithm to evaluate the new script. RefPtr<ServiceWorkerInfo> sw = new ServiceWorkerInfo(mRegistration->mPrincipal, mRegistration->mScope, mScriptSpec, aNewCacheName); mRegistration->SetEvaluating(sw); nsMainThreadPtrHandle<ServiceWorkerUpdateJob> handle( new nsMainThreadPtrHolder<ServiceWorkerUpdateJob>(this)); RefPtr<LifeCycleEventCallback> callback = new ContinueUpdateRunnable(handle); ServiceWorkerPrivate* workerPrivate = sw->WorkerPrivate(); MOZ_ASSERT(workerPrivate); rv = workerPrivate->CheckScriptEvaluation(callback); if (NS_WARN_IF(NS_FAILED(rv))) { FailUpdateJob(NS_ERROR_DOM_ABORT_ERR); return; } }
NS_IMETHOD Run() override { AssertIsOnMainThread(); nsCOMPtr<nsIPrincipal> principal; { // Bug 1228723: If permission is revoked or an error occurs, the // subscription callback will be called synchronously. This causes // `GetSubscriptionCallback::OnPushSubscription` to deadlock when // it tries to acquire the lock. MutexAutoLock lock(mProxy->Lock()); if (mProxy->CleanedUp()) { return NS_OK; } principal = mProxy->GetWorkerPrivate()->GetPrincipal(); } MOZ_ASSERT(principal); RefPtr<GetSubscriptionCallback> callback = new GetSubscriptionCallback(mProxy, mScope); PushPermissionState state; nsresult rv = GetPermissionState(principal, state); if (NS_FAILED(rv)) { callback->OnPushSubscriptionError(NS_ERROR_FAILURE); return NS_OK; } if (state != PushPermissionState::Granted) { if (mAction == PushManager::GetSubscriptionAction) { callback->OnPushSubscriptionError(NS_OK); return NS_OK; } callback->OnPushSubscriptionError(NS_ERROR_DOM_PUSH_DENIED_ERR); return NS_OK; } nsCOMPtr<nsIPushService> service = do_GetService("@mozilla.org/push/Service;1"); if (NS_WARN_IF(!service)) { callback->OnPushSubscriptionError(NS_ERROR_FAILURE); return NS_OK; } if (mAction == PushManager::SubscribeAction) { if (mAppServerKey.IsEmpty()) { rv = service->Subscribe(mScope, principal, callback); } else { rv = service->SubscribeWithKey(mScope, principal, mAppServerKey.Length(), mAppServerKey.Elements(), callback); } } else { MOZ_ASSERT(mAction == PushManager::GetSubscriptionAction); rv = service->GetSubscription(mScope, principal, callback); } if (NS_WARN_IF(NS_FAILED(rv))) { callback->OnPushSubscriptionError(NS_ERROR_FAILURE); return NS_OK; } return NS_OK; }