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