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

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: fix crash 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 19 matching lines...) Expand all
30 30
31 #include "web/ServiceWorkerGlobalScopeProxy.h" 31 #include "web/ServiceWorkerGlobalScopeProxy.h"
32 32
33 #include "bindings/core/v8/SourceLocation.h" 33 #include "bindings/core/v8/SourceLocation.h"
34 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" 34 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
35 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
36 #include "core/dom/ExecutionContext.h" 36 #include "core/dom/ExecutionContext.h"
37 #include "core/dom/ExecutionContextTask.h" 37 #include "core/dom/ExecutionContextTask.h"
38 #include "core/dom/MessagePort.h" 38 #include "core/dom/MessagePort.h"
39 #include "core/inspector/ConsoleMessage.h" 39 #include "core/inspector/ConsoleMessage.h"
40 #include "core/inspector/InspectorInstrumentation.h"
40 #include "core/origin_trials/OriginTrials.h" 41 #include "core/origin_trials/OriginTrials.h"
41 #include "core/workers/ParentFrameTaskRunners.h" 42 #include "core/workers/ParentFrameTaskRunners.h"
42 #include "core/workers/WorkerGlobalScope.h" 43 #include "core/workers/WorkerGlobalScope.h"
43 #include "core/workers/WorkerThread.h" 44 #include "core/workers/WorkerThread.h"
44 #include "modules/background_sync/SyncEvent.h" 45 #include "modules/background_sync/SyncEvent.h"
45 #include "modules/fetch/Headers.h" 46 #include "modules/fetch/Headers.h"
46 #include "modules/notifications/Notification.h" 47 #include "modules/notifications/Notification.h"
47 #include "modules/notifications/NotificationEvent.h" 48 #include "modules/notifications/NotificationEvent.h"
48 #include "modules/notifications/NotificationEventInit.h" 49 #include "modules/notifications/NotificationEventInit.h"
49 #include "modules/payments/PaymentAppRequestData.h" 50 #include "modules/payments/PaymentAppRequestData.h"
50 #include "modules/payments/PaymentAppRequestDataConversion.h" 51 #include "modules/payments/PaymentAppRequestDataConversion.h"
51 #include "modules/payments/PaymentRequestEvent.h" 52 #include "modules/payments/PaymentRequestEvent.h"
52 #include "modules/push_messaging/PushEvent.h" 53 #include "modules/push_messaging/PushEvent.h"
53 #include "modules/push_messaging/PushMessageData.h" 54 #include "modules/push_messaging/PushMessageData.h"
54 #include "modules/serviceworkers/ExtendableEvent.h" 55 #include "modules/serviceworkers/ExtendableEvent.h"
55 #include "modules/serviceworkers/ExtendableMessageEvent.h" 56 #include "modules/serviceworkers/ExtendableMessageEvent.h"
56 #include "modules/serviceworkers/FetchEvent.h" 57 #include "modules/serviceworkers/FetchEvent.h"
57 #include "modules/serviceworkers/ForeignFetchEvent.h" 58 #include "modules/serviceworkers/ForeignFetchEvent.h"
58 #include "modules/serviceworkers/InstallEvent.h" 59 #include "modules/serviceworkers/InstallEvent.h"
59 #include "modules/serviceworkers/ServiceWorkerClient.h" 60 #include "modules/serviceworkers/ServiceWorkerClient.h"
60 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h" 61 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h"
61 #include "modules/serviceworkers/ServiceWorkerWindowClient.h" 62 #include "modules/serviceworkers/ServiceWorkerWindowClient.h"
62 #include "modules/serviceworkers/WaitUntilObserver.h" 63 #include "modules/serviceworkers/WaitUntilObserver.h"
63 #include "platform/RuntimeEnabledFeatures.h" 64 #include "platform/RuntimeEnabledFeatures.h"
65 #include "platform/network/ResourceError.h"
64 #include "public/platform/modules/notifications/WebNotificationData.h" 66 #include "public/platform/modules/notifications/WebNotificationData.h"
65 #include "public/platform/modules/serviceworker/WebServiceWorkerEventResult.h" 67 #include "public/platform/modules/serviceworker/WebServiceWorkerEventResult.h"
66 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h" 68 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h"
67 #include "public/web/WebSerializedScriptValue.h" 69 #include "public/web/WebSerializedScriptValue.h"
68 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h" 70 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h"
69 #include "web/WebEmbeddedWorkerImpl.h" 71 #include "web/WebEmbeddedWorkerImpl.h"
70 #include "wtf/Assertions.h" 72 #include "wtf/Assertions.h"
73 #include "wtf/CurrentTime.h"
71 #include "wtf/Functional.h" 74 #include "wtf/Functional.h"
72 #include "wtf/PtrUtil.h" 75 #include "wtf/PtrUtil.h"
73 #include <memory> 76 #include <memory>
74 #include <utility> 77 #include <utility>
75 78
76 namespace blink { 79 namespace blink {
77 80
78 ServiceWorkerGlobalScopeProxy* ServiceWorkerGlobalScopeProxy::create( 81 ServiceWorkerGlobalScopeProxy* ServiceWorkerGlobalScopeProxy::create(
79 WebEmbeddedWorkerImpl& embeddedWorker, 82 WebEmbeddedWorkerImpl& embeddedWorker,
80 Document& document, 83 Document& document,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 waitUntilObserver->willDispatchEvent(); 193 waitUntilObserver->willDispatchEvent();
191 respondWithObserver->willDispatchEvent(); 194 respondWithObserver->willDispatchEvent();
192 DispatchEventResult dispatchResult = 195 DispatchEventResult dispatchResult =
193 workerGlobalScope()->dispatchEvent(fetchEvent); 196 workerGlobalScope()->dispatchEvent(fetchEvent);
194 respondWithObserver->didDispatchEvent(dispatchResult); 197 respondWithObserver->didDispatchEvent(dispatchResult);
195 // false is okay because waitUntil for fetch event doesn't care about the 198 // false is okay because waitUntil for fetch event doesn't care about the
196 // promise rejection or an uncaught runtime script error. 199 // promise rejection or an uncaught runtime script error.
197 waitUntilObserver->didDispatchEvent(false /* errorOccurred */); 200 waitUntilObserver->didDispatchEvent(false /* errorOccurred */);
198 } 201 }
199 202
203 void ServiceWorkerGlobalScopeProxy::onNavigationPreloadSent(int fetchEventID,
204 const WebURL& url) {
205 FetchInitiatorInfo info;
206 ResourceRequest request(url);
207 InspectorInstrumentation::willSendRequest(workerGlobalScope(), fetchEventID,
208 nullptr, request,
209 ResourceResponse(), info);
210 }
211
200 void ServiceWorkerGlobalScopeProxy::onNavigationPreloadResponse( 212 void ServiceWorkerGlobalScopeProxy::onNavigationPreloadResponse(
201 int fetchEventID, 213 int fetchEventID,
202 std::unique_ptr<WebURLResponse> response, 214 std::unique_ptr<WebURLResponse> response,
203 std::unique_ptr<WebDataConsumerHandle> dataConsumeHandle) { 215 std::unique_ptr<WebDataConsumerHandle> dataConsumeHandle) {
216 InspectorInstrumentation::didReceiveResourceResponse(
217 workerGlobalScope(), fetchEventID, nullptr,
218 response->toResourceResponse(), nullptr);
204 FetchEvent* fetchEvent = m_pendingPreloadFetchEvents.take(fetchEventID); 219 FetchEvent* fetchEvent = m_pendingPreloadFetchEvents.take(fetchEventID);
205 DCHECK(fetchEvent); 220 DCHECK(fetchEvent);
206 fetchEvent->onNavigationPreloadResponse( 221 fetchEvent->onNavigationPreloadResponse(
207 workerGlobalScope()->scriptController()->getScriptState(), 222 workerGlobalScope()->scriptController()->getScriptState(),
208 std::move(response), std::move(dataConsumeHandle)); 223 std::move(response), std::move(dataConsumeHandle));
209 } 224 }
210 225
211 void ServiceWorkerGlobalScopeProxy::onNavigationPreloadError( 226 void ServiceWorkerGlobalScopeProxy::onNavigationPreloadError(
212 int fetchEventID, 227 int fetchEventID,
213 std::unique_ptr<WebServiceWorkerError> error) { 228 std::unique_ptr<WebServiceWorkerError> error) {
229 InspectorInstrumentation::didFailLoading(
230 workerGlobalScope(), fetchEventID,
231 ResourceError(errorDomainBlinkInternal, 0, "", error->message));
232
214 FetchEvent* fetchEvent = m_pendingPreloadFetchEvents.take(fetchEventID); 233 FetchEvent* fetchEvent = m_pendingPreloadFetchEvents.take(fetchEventID);
215 // This method may be called after onNavigationPreloadResponse() was called. 234 // This method may be called after onNavigationPreloadResponse() was called.
216 if (!fetchEvent) 235 if (!fetchEvent)
217 return; 236 return;
218 fetchEvent->onNavigationPreloadError( 237 fetchEvent->onNavigationPreloadError(
219 workerGlobalScope()->scriptController()->getScriptState(), 238 workerGlobalScope()->scriptController()->getScriptState(),
220 std::move(error)); 239 std::move(error));
221 } 240 }
222 241
242 void ServiceWorkerGlobalScopeProxy::onNavigationPreloadCompleted(
243 int fetchEventID,
244 int64_t encodedDataLength) {
245 InspectorInstrumentation::didFinishLoading(workerGlobalScope(), fetchEventID,
246 monotonicallyIncreasingTime(),
247 encodedDataLength);
248 }
249
223 void ServiceWorkerGlobalScopeProxy::dispatchForeignFetchEvent( 250 void ServiceWorkerGlobalScopeProxy::dispatchForeignFetchEvent(
224 int fetchEventID, 251 int fetchEventID,
225 const WebServiceWorkerRequest& webRequest) { 252 const WebServiceWorkerRequest& webRequest) {
226 if (!OriginTrials::foreignFetchEnabled(workerGlobalScope())) { 253 if (!OriginTrials::foreignFetchEnabled(workerGlobalScope())) {
227 // If origin trial tokens have expired, or are otherwise no longer valid 254 // If origin trial tokens have expired, or are otherwise no longer valid
228 // no events should be dispatched. 255 // no events should be dispatched.
229 // TODO(mek): Ideally the browser wouldn't even start the service worker 256 // TODO(mek): Ideally the browser wouldn't even start the service worker
230 // if its tokens have expired. 257 // if its tokens have expired.
231 ServiceWorkerGlobalScopeClient::from(workerGlobalScope()) 258 ServiceWorkerGlobalScopeClient::from(workerGlobalScope())
232 ->respondToFetchEvent(fetchEventID, WTF::currentTime()); 259 ->respondToFetchEvent(fetchEventID, WTF::currentTime());
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 return *m_document; 509 return *m_document;
483 } 510 }
484 511
485 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope() 512 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope()
486 const { 513 const {
487 DCHECK(m_workerGlobalScope); 514 DCHECK(m_workerGlobalScope);
488 return m_workerGlobalScope; 515 return m_workerGlobalScope;
489 } 516 }
490 517
491 } // namespace blink 518 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.h ('k') | third_party/WebKit/Source/web/WebEmbeddedWorkerImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698