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

Side by Side Diff: third_party/WebKit/Source/web/WebSharedWorkerImpl.cpp

Issue 2423213002: Remove a bunch of pointless null checks in FrameLoaderClientImpl.
Patch Set: Fix formatting. Created 4 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 m_mainFrame(nullptr), 86 m_mainFrame(nullptr),
87 m_askedToTerminate(false), 87 m_askedToTerminate(false),
88 m_workerInspectorProxy(WorkerInspectorProxy::create()), 88 m_workerInspectorProxy(WorkerInspectorProxy::create()),
89 m_client(client), 89 m_client(client),
90 m_pauseWorkerContextOnStart(false), 90 m_pauseWorkerContextOnStart(false),
91 m_isPausedOnStart(false), 91 m_isPausedOnStart(false),
92 m_creationAddressSpace(WebAddressSpacePublic) {} 92 m_creationAddressSpace(WebAddressSpacePublic) {}
93 93
94 WebSharedWorkerImpl::~WebSharedWorkerImpl() { 94 WebSharedWorkerImpl::~WebSharedWorkerImpl() {
95 DCHECK(m_webView); 95 DCHECK(m_webView);
96 // Detach the client before closing the view to avoid getting called back.
97 m_mainFrame->setClient(0);
98 96
99 m_webView->close(); 97 m_webView->close();
100 m_mainFrame->close(); 98
101 if (m_loaderProxy) 99 if (m_loaderProxy)
102 m_loaderProxy->detachProvider(this); 100 m_loaderProxy->detachProvider(this);
103 } 101 }
104 102
105 void WebSharedWorkerImpl::terminateWorkerThread() { 103 void WebSharedWorkerImpl::terminateWorkerThread() {
106 if (m_askedToTerminate) 104 if (m_askedToTerminate)
107 return; 105 return;
108 m_askedToTerminate = true; 106 m_askedToTerminate = true;
109 if (m_mainScriptLoader) { 107 if (m_mainScriptLoader) {
110 m_mainScriptLoader->cancel(); 108 m_mainScriptLoader->cancel();
(...skipping 29 matching lines...) Expand all
140 m_client->workerReadyForInspection(); 138 m_client->workerReadyForInspection();
141 if (m_pauseWorkerContextOnStart) { 139 if (m_pauseWorkerContextOnStart) {
142 m_isPausedOnStart = true; 140 m_isPausedOnStart = true;
143 return; 141 return;
144 } 142 }
145 loadShadowPage(); 143 loadShadowPage();
146 } 144 }
147 145
148 WebApplicationCacheHost* WebSharedWorkerImpl::createApplicationCacheHost( 146 WebApplicationCacheHost* WebSharedWorkerImpl::createApplicationCacheHost(
149 WebApplicationCacheHostClient* appcacheHostClient) { 147 WebApplicationCacheHostClient* appcacheHostClient) {
148 if (m_askedToTerminate)
149 return nullptr;
150 return m_client->createApplicationCacheHost(appcacheHostClient); 150 return m_client->createApplicationCacheHost(appcacheHostClient);
151 } 151 }
152 152
153 void WebSharedWorkerImpl::loadShadowPage() { 153 void WebSharedWorkerImpl::loadShadowPage() {
154 // Construct substitute data source for the 'shadow page'. We only need it 154 // Construct substitute data source for the 'shadow page'. We only need it
155 // to have same origin as the worker so the loading checks work correctly. 155 // to have same origin as the worker so the loading checks work correctly.
156 CString content(""); 156 CString content("");
157 RefPtr<SharedBuffer> buffer( 157 RefPtr<SharedBuffer> buffer(
158 SharedBuffer::create(content.data(), content.length())); 158 SharedBuffer::create(content.data(), content.length()));
159 m_mainFrame->frame()->loader().load( 159 m_mainFrame->frame()->loader().load(
160 FrameLoadRequest(0, ResourceRequest(m_url), 160 FrameLoadRequest(0, ResourceRequest(m_url),
161 SubstituteData(buffer, "text/html", "UTF-8", KURL()))); 161 SubstituteData(buffer, "text/html", "UTF-8", KURL())));
162 } 162 }
163 163
164 void WebSharedWorkerImpl::willSendRequest(WebLocalFrame* frame, 164 void WebSharedWorkerImpl::willSendRequest(WebLocalFrame* frame,
165 WebURLRequest& request) { 165 WebURLRequest& request) {
166 if (m_askedToTerminate)
167 return;
168
166 if (m_networkProvider) 169 if (m_networkProvider)
167 m_networkProvider->willSendRequest(frame->dataSource(), request); 170 m_networkProvider->willSendRequest(frame->dataSource(), request);
168 } 171 }
169 172
170 void WebSharedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame) { 173 void WebSharedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame) {
174 if (m_askedToTerminate)
dcheng 2016/10/17 22:33:29 Similarly, I've added early returns. It feels a bi
175 return;
176
171 DCHECK(!m_loadingDocument); 177 DCHECK(!m_loadingDocument);
172 DCHECK(!m_mainScriptLoader); 178 DCHECK(!m_mainScriptLoader);
173 m_networkProvider = wrapUnique( 179 m_networkProvider = wrapUnique(
174 m_client->createServiceWorkerNetworkProvider(frame->dataSource())); 180 m_client->createServiceWorkerNetworkProvider(frame->dataSource()));
175 m_mainScriptLoader = WorkerScriptLoader::create(); 181 m_mainScriptLoader = WorkerScriptLoader::create();
176 m_mainScriptLoader->setRequestContext( 182 m_mainScriptLoader->setRequestContext(
177 WebURLRequest::RequestContextSharedWorker); 183 WebURLRequest::RequestContextSharedWorker);
178 m_loadingDocument = toWebLocalFrameImpl(frame)->frame()->document(); 184 m_loadingDocument = toWebLocalFrameImpl(frame)->frame()->document();
179 m_mainScriptLoader->loadAsynchronously( 185 m_mainScriptLoader->loadAsynchronously(
180 *m_loadingDocument.get(), m_url, DenyCrossOriginRequests, 186 *m_loadingDocument.get(), m_url, DenyCrossOriginRequests,
181 m_creationAddressSpace, 187 m_creationAddressSpace,
182 bind(&WebSharedWorkerImpl::didReceiveScriptLoaderResponse, 188 bind(&WebSharedWorkerImpl::didReceiveScriptLoaderResponse,
183 WTF::unretained(this)), 189 WTF::unretained(this)),
184 bind(&WebSharedWorkerImpl::onScriptLoaderFinished, 190 bind(&WebSharedWorkerImpl::onScriptLoaderFinished,
185 WTF::unretained(this))); 191 WTF::unretained(this)));
dcheng 2016/10/17 22:33:29 Same question here: why does onScriptLoaderFinishe
nhiroki 2016/10/20 05:57:12 ditto(https://codereview.chromium.org/451603002)
186 // Do nothing here since onScriptLoaderFinished() might have been already 192 // Do nothing here since onScriptLoaderFinished() might have been already
187 // invoked and |this| might have been deleted at this point. 193 // invoked and |this| might have been deleted at this point.
188 } 194 }
189 195
190 bool WebSharedWorkerImpl::isControlledByServiceWorker( 196 bool WebSharedWorkerImpl::isControlledByServiceWorker(
191 WebDataSource& dataSource) { 197 WebDataSource& dataSource) {
198 if (m_askedToTerminate)
esprehn 2016/10/24 21:27:07 should m_networkProvider be nulled out once this i
199 return false;
200
192 return m_networkProvider && 201 return m_networkProvider &&
193 m_networkProvider->isControlledByServiceWorker(dataSource); 202 m_networkProvider->isControlledByServiceWorker(dataSource);
194 } 203 }
195 204
196 int64_t WebSharedWorkerImpl::serviceWorkerID(WebDataSource& dataSource) { 205 int64_t WebSharedWorkerImpl::serviceWorkerID(WebDataSource& dataSource) {
197 if (!m_networkProvider) 206 if (m_askedToTerminate || !m_networkProvider)
198 return -1; 207 return -1;
199 return m_networkProvider->serviceWorkerID(dataSource); 208 return m_networkProvider->serviceWorkerID(dataSource);
esprehn 2016/10/24 21:27:07 ditto?
200 } 209 }
201 210
202 InterfaceProvider* WebSharedWorkerImpl::interfaceProvider() { 211 InterfaceProvider* WebSharedWorkerImpl::interfaceProvider() {
212 if (m_askedToTerminate)
213 return nullptr;
esprehn 2016/10/24 21:27:07 Can we return getEmptyInterfaceProvider() instead?
203 return Platform::current()->interfaceProvider(); 214 return Platform::current()->interfaceProvider();
204 } 215 }
205 216
206 void WebSharedWorkerImpl::sendProtocolMessage(int sessionId, 217 void WebSharedWorkerImpl::sendProtocolMessage(int sessionId,
207 int callId, 218 int callId,
208 const WebString& message, 219 const WebString& message,
209 const WebString& state) { 220 const WebString& state) {
210 m_client->sendDevToolsMessage(sessionId, callId, message, state); 221 m_client->sendDevToolsMessage(sessionId, callId, message, state);
211 } 222 }
212 223
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 if (devtoolsAgent) 447 if (devtoolsAgent)
437 devtoolsAgent->dispatchOnInspectorBackend(sessionId, callId, method, 448 devtoolsAgent->dispatchOnInspectorBackend(sessionId, callId, method,
438 message); 449 message);
439 } 450 }
440 451
441 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) { 452 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) {
442 return new WebSharedWorkerImpl(client); 453 return new WebSharedWorkerImpl(client);
443 } 454 }
444 455
445 } // namespace blink 456 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698