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

Side by Side Diff: Source/modules/serviceworkers/ServiceWorkerContainerClient.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, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "ServiceWorkerContainerClient.h" 6 #include "ServiceWorkerContainerClient.h"
7 7
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/ExecutionContext.h" 9 #include "core/dom/ExecutionContext.h"
10 #include "core/frame/LocalFrame.h" 10 #include "core/frame/LocalFrame.h"
(...skipping 18 matching lines...) Expand all
29 } 29 }
30 30
31 ServiceWorkerContainerClient* ServiceWorkerContainerClient::from(ExecutionContex t* context) 31 ServiceWorkerContainerClient* ServiceWorkerContainerClient::from(ExecutionContex t* context)
32 { 32 {
33 if (context->isDocument()) { 33 if (context->isDocument()) {
34 Document* document = toDocument(context); 34 Document* document = toDocument(context);
35 ServiceWorkerContainerClient* client = static_cast<ServiceWorkerContaine rClient*>(Supplement<Page>::from(document->page(), supplementName())); 35 ServiceWorkerContainerClient* client = static_cast<ServiceWorkerContaine rClient*>(Supplement<Page>::from(document->page(), supplementName()));
36 if (client) 36 if (client)
37 return client; 37 return client;
38 38
39 // If it's not provided yet create it lazily. 39 if (!document->frame())
40 ASSERT(document->frame()); 40 return 0;
41
42 // If it's not provided yet, create it lazily.
41 document->page()->provideSupplement(ServiceWorkerContainerClient::supple mentName(), ServiceWorkerContainerClient::create(document->frame()->loader().cli ent()->createServiceWorkerProvider())); 43 document->page()->provideSupplement(ServiceWorkerContainerClient::supple mentName(), ServiceWorkerContainerClient::create(document->frame()->loader().cli ent()->createServiceWorkerProvider()));
42 return static_cast<ServiceWorkerContainerClient*>(Supplement<Page>::from (document->page(), supplementName())); 44 return static_cast<ServiceWorkerContainerClient*>(Supplement<Page>::from (document->page(), supplementName()));
43 } 45 }
44 46
45 ASSERT(context->isWorkerGlobalScope()); 47 ASSERT(context->isWorkerGlobalScope());
46 return static_cast<ServiceWorkerContainerClient*>(Supplement<WorkerClients>: :from(toWorkerGlobalScope(context)->clients(), supplementName())); 48 return static_cast<ServiceWorkerContainerClient*>(Supplement<WorkerClients>: :from(toWorkerGlobalScope(context)->clients(), supplementName()));
47 } 49 }
48 50
49 ServiceWorkerContainerClient::ServiceWorkerContainerClient(PassOwnPtr<blink::Web ServiceWorkerProvider> provider) 51 ServiceWorkerContainerClient::ServiceWorkerContainerClient(PassOwnPtr<blink::Web ServiceWorkerProvider> provider)
50 : m_provider(provider) 52 : m_provider(provider)
51 { 53 {
52 } 54 }
53 55
54 void provideServiceWorkerContainerClientToWorker(WorkerClients* clients, PassOwn Ptr<blink::WebServiceWorkerProvider> provider) 56 void provideServiceWorkerContainerClientToWorker(WorkerClients* clients, PassOwn Ptr<blink::WebServiceWorkerProvider> provider)
55 { 57 {
56 clients->provideSupplement(ServiceWorkerContainerClient::supplementName(), S erviceWorkerContainerClient::create(provider)); 58 clients->provideSupplement(ServiceWorkerContainerClient::supplementName(), S erviceWorkerContainerClient::create(provider));
57 } 59 }
58 60
59 } // namespace WebCore 61 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698