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

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

Issue 2620463002: Show service worker navigation preload requests in DevTools Network tab (Closed)
Patch Set: rebase and include time.h in ServiceWorkerGlobalScopeProxy.* Created 3 years, 11 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 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "web/ServiceWorkerGlobalScopeProxy.h" 31 #include "web/ServiceWorkerGlobalScopeProxy.h"
32 32
33 #include "base/time/time.h"
33 #include "bindings/core/v8/SourceLocation.h" 34 #include "bindings/core/v8/SourceLocation.h"
34 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" 35 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
35 #include "core/dom/Document.h" 36 #include "core/dom/Document.h"
36 #include "core/dom/ExecutionContext.h" 37 #include "core/dom/ExecutionContext.h"
37 #include "core/dom/ExecutionContextTask.h" 38 #include "core/dom/ExecutionContextTask.h"
38 #include "core/dom/MessagePort.h" 39 #include "core/dom/MessagePort.h"
39 #include "core/inspector/ConsoleMessage.h" 40 #include "core/inspector/ConsoleMessage.h"
41 #include "core/inspector/InspectorInstrumentation.h"
40 #include "core/origin_trials/OriginTrials.h" 42 #include "core/origin_trials/OriginTrials.h"
41 #include "core/workers/ParentFrameTaskRunners.h" 43 #include "core/workers/ParentFrameTaskRunners.h"
42 #include "core/workers/WorkerGlobalScope.h" 44 #include "core/workers/WorkerGlobalScope.h"
43 #include "core/workers/WorkerThread.h" 45 #include "core/workers/WorkerThread.h"
44 #include "modules/background_sync/SyncEvent.h" 46 #include "modules/background_sync/SyncEvent.h"
45 #include "modules/fetch/Headers.h" 47 #include "modules/fetch/Headers.h"
46 #include "modules/notifications/Notification.h" 48 #include "modules/notifications/Notification.h"
47 #include "modules/notifications/NotificationEvent.h" 49 #include "modules/notifications/NotificationEvent.h"
48 #include "modules/notifications/NotificationEventInit.h" 50 #include "modules/notifications/NotificationEventInit.h"
49 #include "modules/payments/PaymentAppRequestData.h" 51 #include "modules/payments/PaymentAppRequestData.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 waitUntilObserver->willDispatchEvent(); 192 waitUntilObserver->willDispatchEvent();
191 respondWithObserver->willDispatchEvent(); 193 respondWithObserver->willDispatchEvent();
192 DispatchEventResult dispatchResult = 194 DispatchEventResult dispatchResult =
193 workerGlobalScope()->dispatchEvent(fetchEvent); 195 workerGlobalScope()->dispatchEvent(fetchEvent);
194 respondWithObserver->didDispatchEvent(dispatchResult); 196 respondWithObserver->didDispatchEvent(dispatchResult);
195 // false is okay because waitUntil for fetch event doesn't care about the 197 // false is okay because waitUntil for fetch event doesn't care about the
196 // promise rejection or an uncaught runtime script error. 198 // promise rejection or an uncaught runtime script error.
197 waitUntilObserver->didDispatchEvent(false /* errorOccurred */); 199 waitUntilObserver->didDispatchEvent(false /* errorOccurred */);
198 } 200 }
199 201
202 void ServiceWorkerGlobalScopeProxy::onNavigationPreloadSent(
203 int fetchEventID,
204 const WebURL& url,
205 base::TimeTicks sentTimestamp,
206 base::Time sentWallTime) {
207 InspectorInstrumentation::didSendNavigationPreload(
208 workerGlobalScope(), fetchEventID, url,
209 sentTimestamp.ToInternalValue() /
210 static_cast<double>(base::Time::kMicrosecondsPerSecond),
211 sentWallTime.ToDoubleT());
212 }
213
200 void ServiceWorkerGlobalScopeProxy::onNavigationPreloadResponse( 214 void ServiceWorkerGlobalScopeProxy::onNavigationPreloadResponse(
201 int fetchEventID, 215 int fetchEventID,
202 std::unique_ptr<WebURLResponse> response, 216 std::unique_ptr<WebURLResponse> response,
203 std::unique_ptr<WebDataConsumerHandle> dataConsumeHandle) { 217 std::unique_ptr<WebDataConsumerHandle> dataConsumeHandle) {
218 InspectorInstrumentation::didReceiveNavigationPreloadResponse(
219 workerGlobalScope(), fetchEventID, response->toResourceResponse());
204 FetchEvent* fetchEvent = m_pendingPreloadFetchEvents.take(fetchEventID); 220 FetchEvent* fetchEvent = m_pendingPreloadFetchEvents.take(fetchEventID);
205 DCHECK(fetchEvent); 221 DCHECK(fetchEvent);
206 fetchEvent->onNavigationPreloadResponse( 222 fetchEvent->onNavigationPreloadResponse(
207 workerGlobalScope()->scriptController()->getScriptState(), 223 workerGlobalScope()->scriptController()->getScriptState(),
208 std::move(response), std::move(dataConsumeHandle)); 224 std::move(response), std::move(dataConsumeHandle));
209 } 225 }
210 226
211 void ServiceWorkerGlobalScopeProxy::onNavigationPreloadError( 227 void ServiceWorkerGlobalScopeProxy::onNavigationPreloadError(
212 int fetchEventID, 228 int fetchEventID,
213 std::unique_ptr<WebServiceWorkerError> error) { 229 std::unique_ptr<WebServiceWorkerError> error) {
230 InspectorInstrumentation::didReceiveNavigationPreloadError(
231 workerGlobalScope(), fetchEventID, error->message);
214 FetchEvent* fetchEvent = m_pendingPreloadFetchEvents.take(fetchEventID); 232 FetchEvent* fetchEvent = m_pendingPreloadFetchEvents.take(fetchEventID);
215 // This method may be called after onNavigationPreloadResponse() was called. 233 // This method may be called after onNavigationPreloadResponse() was called.
216 if (!fetchEvent) 234 if (!fetchEvent)
217 return; 235 return;
218 fetchEvent->onNavigationPreloadError( 236 fetchEvent->onNavigationPreloadError(
219 workerGlobalScope()->scriptController()->getScriptState(), 237 workerGlobalScope()->scriptController()->getScriptState(),
220 std::move(error)); 238 std::move(error));
221 } 239 }
222 240
241 void ServiceWorkerGlobalScopeProxy::onNavigationPreloadCompleted(
242 int fetchEventID) {
243 InspectorInstrumentation::didCompleteNavigationPreload(workerGlobalScope(),
244 fetchEventID);
245 }
246
223 void ServiceWorkerGlobalScopeProxy::dispatchForeignFetchEvent( 247 void ServiceWorkerGlobalScopeProxy::dispatchForeignFetchEvent(
224 int fetchEventID, 248 int fetchEventID,
225 const WebServiceWorkerRequest& webRequest) { 249 const WebServiceWorkerRequest& webRequest) {
226 if (!OriginTrials::foreignFetchEnabled(workerGlobalScope())) { 250 if (!OriginTrials::foreignFetchEnabled(workerGlobalScope())) {
227 // If origin trial tokens have expired, or are otherwise no longer valid 251 // If origin trial tokens have expired, or are otherwise no longer valid
228 // no events should be dispatched. 252 // no events should be dispatched.
229 // TODO(mek): Ideally the browser wouldn't even start the service worker 253 // TODO(mek): Ideally the browser wouldn't even start the service worker
230 // if its tokens have expired. 254 // if its tokens have expired.
231 ServiceWorkerGlobalScopeClient::from(workerGlobalScope()) 255 ServiceWorkerGlobalScopeClient::from(workerGlobalScope())
232 ->respondToFetchEvent(fetchEventID, WTF::currentTime()); 256 ->respondToFetchEvent(fetchEventID, WTF::currentTime());
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 return *m_document; 512 return *m_document;
489 } 513 }
490 514
491 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope() 515 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope()
492 const { 516 const {
493 DCHECK(m_workerGlobalScope); 517 DCHECK(m_workerGlobalScope);
494 return m_workerGlobalScope; 518 return m_workerGlobalScope;
495 } 519 }
496 520
497 } // namespace blink 521 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698