Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1382)

Unified Diff: Source/modules/serviceworkers/ServiceWorkerContainer.cpp

Issue 217023003: Add null checks in navigator.serviceWorker access to fix possible crash (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/modules/serviceworkers/ServiceWorkerContainer.cpp
diff --git a/Source/modules/serviceworkers/ServiceWorkerContainer.cpp b/Source/modules/serviceworkers/ServiceWorkerContainer.cpp
index 558f2cd74ea9f6c3f1933d378141bf0b04c0bd5a..f0078f420ffafc2284eee7dbe572c5e8f62a68b9 100644
--- a/Source/modules/serviceworkers/ServiceWorkerContainer.cpp
+++ b/Source/modules/serviceworkers/ServiceWorkerContainer.cpp
@@ -93,11 +93,15 @@ ScriptPromise ServiceWorkerContainer::unregisterServiceWorker(ExecutionContext*
RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(executionContext);
ScriptPromise promise = resolver->promise();
+ if (!m_provider) {
+ resolver->reject(DOMError::create(NotSupportedError, "No provider is available"));
dominicc (has gone to gerrit) 2014/03/31 04:52:09 It would be great to see a W3C-style test for this
kinuko 2014/03/31 12:33:05 Yes, but if we can have a test code that can repro
+ return promise;
+ }
+
RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
KURL patternURL = executionContext->completeURL(pattern);
if (!pattern.isEmpty() && !documentOrigin->canRequest(patternURL)) {
resolver->reject(DOMError::create(SecurityError, "Can only unregister for patterns in the document's origin."));
-
return promise;
}
@@ -106,10 +110,15 @@ ScriptPromise ServiceWorkerContainer::unregisterServiceWorker(ExecutionContext*
}
ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContext)
- : m_provider(ServiceWorkerContainerClient::from(executionContext)->provider())
+ : m_provider(0)
dominicc (has gone to gerrit) 2014/03/31 04:52:09 Why use nullptr sometimes and 0 other times?
kinuko 2014/03/31 12:33:05 Some compilers don't accept assigning nullptr to a
{
ScriptWrappable::init(this);
- m_provider->setClient(this);
+
+ if (ServiceWorkerContainerClient::from(executionContext)) {
dominicc (has gone to gerrit) 2014/03/31 04:52:09 More idiomatic Blink would be something like: if
kinuko 2014/03/31 12:33:05 Done.
+ m_provider = ServiceWorkerContainerClient::from(executionContext)->provider();
+ if (m_provider)
+ m_provider->setClient(this);
+ }
}
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698