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

Side by Side Diff: third_party/WebKit/Source/web/WebEmbeddedWorkerImpl.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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // Prevent onScriptLoaderFinished from deleting 'this'. 108 // Prevent onScriptLoaderFinished from deleting 'this'.
109 m_askedToTerminate = true; 109 m_askedToTerminate = true;
110 110
111 if (m_workerThread) 111 if (m_workerThread)
112 m_workerThread->terminateAndWait(); 112 m_workerThread->terminateAndWait();
113 113
114 DCHECK(runningWorkerInstances().contains(this)); 114 DCHECK(runningWorkerInstances().contains(this));
115 runningWorkerInstances().remove(this); 115 runningWorkerInstances().remove(this);
116 DCHECK(m_webView); 116 DCHECK(m_webView);
117 117
118 // Detach the client before closing the view to avoid getting called back.
119 m_mainFrame->setClient(0);
dcheng 2016/10/17 22:33:29 This breaks the invariant. For now, I've added ear
120
121 if (m_workerGlobalScopeProxy) { 118 if (m_workerGlobalScopeProxy) {
122 m_workerGlobalScopeProxy->detach(); 119 m_workerGlobalScopeProxy->detach();
123 m_workerGlobalScopeProxy.clear(); 120 m_workerGlobalScopeProxy.clear();
124 } 121 }
125 122
126 m_webView->close(); 123 m_webView->close();
127 m_mainFrame->close();
dcheng 2016/10/17 22:33:29 The default WebFrameClient implementation already
128 if (m_loaderProxy) 124 if (m_loaderProxy)
129 m_loaderProxy->detachProvider(this); 125 m_loaderProxy->detachProvider(this);
130 } 126 }
131 127
132 void WebEmbeddedWorkerImpl::startWorkerContext( 128 void WebEmbeddedWorkerImpl::startWorkerContext(
133 const WebEmbeddedWorkerStartData& data) { 129 const WebEmbeddedWorkerStartData& data) {
134 DCHECK(!m_askedToTerminate); 130 DCHECK(!m_askedToTerminate);
135 DCHECK(!m_mainScriptLoader); 131 DCHECK(!m_mainScriptLoader);
136 DCHECK_EQ(m_pauseAfterDownloadState, DontPauseAfterDownload); 132 DCHECK_EQ(m_pauseAfterDownloadState, DontPauseAfterDownload);
137 m_workerStartData = data; 133 m_workerStartData = data;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 RefPtr<SharedBuffer> buffer( 315 RefPtr<SharedBuffer> buffer(
320 SharedBuffer::create(content.data(), content.length())); 316 SharedBuffer::create(content.data(), content.length()));
321 m_loadingShadowPage = true; 317 m_loadingShadowPage = true;
322 m_mainFrame->frame()->loader().load( 318 m_mainFrame->frame()->loader().load(
323 FrameLoadRequest(0, ResourceRequest(m_workerStartData.scriptURL), 319 FrameLoadRequest(0, ResourceRequest(m_workerStartData.scriptURL),
324 SubstituteData(buffer, "text/html", "UTF-8", KURL()))); 320 SubstituteData(buffer, "text/html", "UTF-8", KURL())));
325 } 321 }
326 322
327 void WebEmbeddedWorkerImpl::willSendRequest(WebLocalFrame* frame, 323 void WebEmbeddedWorkerImpl::willSendRequest(WebLocalFrame* frame,
328 WebURLRequest& request) { 324 WebURLRequest& request) {
325 // TODO(dcheng): Investigate not plumbing through load notifications when a
326 // frame is detached.
327 if (m_askedToTerminate)
328 return;
329
329 if (m_networkProvider) 330 if (m_networkProvider)
330 m_networkProvider->willSendRequest(frame->dataSource(), request); 331 m_networkProvider->willSendRequest(frame->dataSource(), request);
331 } 332 }
332 333
333 void WebEmbeddedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame) { 334 void WebEmbeddedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame) {
335 // TODO(dcheng): Investigate not plumbing through load notifications when a
336 // frame is detached.
337 if (m_askedToTerminate)
338 return;
339
334 DCHECK(!m_mainScriptLoader); 340 DCHECK(!m_mainScriptLoader);
335 DCHECK(!m_networkProvider); 341 DCHECK(!m_networkProvider);
336 DCHECK(m_mainFrame); 342 DCHECK(m_mainFrame);
337 DCHECK(m_workerContextClient); 343 DCHECK(m_workerContextClient);
338 DCHECK(m_loadingShadowPage); 344 DCHECK(m_loadingShadowPage);
339 DCHECK(!m_askedToTerminate);
340 m_loadingShadowPage = false; 345 m_loadingShadowPage = false;
341 m_networkProvider = 346 m_networkProvider =
342 wrapUnique(m_workerContextClient->createServiceWorkerNetworkProvider( 347 wrapUnique(m_workerContextClient->createServiceWorkerNetworkProvider(
343 frame->dataSource())); 348 frame->dataSource()));
344 m_mainScriptLoader = WorkerScriptLoader::create(); 349 m_mainScriptLoader = WorkerScriptLoader::create();
345 m_mainScriptLoader->setRequestContext( 350 m_mainScriptLoader->setRequestContext(
346 WebURLRequest::RequestContextServiceWorker); 351 WebURLRequest::RequestContextServiceWorker);
347 m_mainScriptLoader->loadAsynchronously( 352 m_mainScriptLoader->loadAsynchronously(
348 *m_mainFrame->frame()->document(), m_workerStartData.scriptURL, 353 *m_mainFrame->frame()->document(), m_workerStartData.scriptURL,
349 DenyCrossOriginRequests, m_workerStartData.addressSpace, nullptr, 354 DenyCrossOriginRequests, m_workerStartData.addressSpace, nullptr,
350 bind(&WebEmbeddedWorkerImpl::onScriptLoaderFinished, 355 bind(&WebEmbeddedWorkerImpl::onScriptLoaderFinished,
351 WTF::unretained(this))); 356 WTF::unretained(this)));
dcheng 2016/10/17 22:33:29 It's unclear to me why onScriptLoaderFinished also
nhiroki 2016/10/20 05:57:12 Good point. Yeah, that guard looks strange. Accord
kinuko 2016/10/20 13:01:54 WebViewImpl::close in this class's dtor could sync
352 // Do nothing here since onScriptLoaderFinished() might have been already 357 // Do nothing here since onScriptLoaderFinished() might have been already
353 // invoked and |this| might have been deleted at this point. 358 // invoked and |this| might have been deleted at this point.
354 } 359 }
355 360
356 void WebEmbeddedWorkerImpl::sendProtocolMessage(int sessionId, 361 void WebEmbeddedWorkerImpl::sendProtocolMessage(int sessionId,
357 int callId, 362 int callId,
358 const WebString& message, 363 const WebString& message,
359 const WebString& state) { 364 const WebString& state) {
360 m_workerContextClient->sendDevToolsMessage(sessionId, callId, message, state); 365 m_workerContextClient->sendDevToolsMessage(sessionId, callId, message, state);
361 } 366 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 *this, *document, *m_workerContextClient); 470 *this, *document, *m_workerContextClient);
466 m_loaderProxy = WorkerLoaderProxy::create(this); 471 m_loaderProxy = WorkerLoaderProxy::create(this);
467 m_workerThread = 472 m_workerThread =
468 ServiceWorkerThread::create(m_loaderProxy, *m_workerGlobalScopeProxy); 473 ServiceWorkerThread::create(m_loaderProxy, *m_workerGlobalScopeProxy);
469 m_workerThread->start(std::move(startupData)); 474 m_workerThread->start(std::move(startupData));
470 m_workerInspectorProxy->workerThreadCreated(document, m_workerThread.get(), 475 m_workerInspectorProxy->workerThreadCreated(document, m_workerThread.get(),
471 scriptURL); 476 scriptURL);
472 } 477 }
473 478
474 } // namespace blink 479 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698