| 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 12 matching lines...) Expand all Loading... |
| 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" |
| 50 #include "modules/payments/PaymentAppRequestDataConversion.h" | 52 #include "modules/payments/PaymentAppRequestDataConversion.h" |
| 51 #include "modules/payments/PaymentRequestEvent.h" | 53 #include "modules/payments/PaymentRequestEvent.h" |
| 52 #include "modules/push_messaging/PushEvent.h" | 54 #include "modules/push_messaging/PushEvent.h" |
| 53 #include "modules/push_messaging/PushMessageData.h" | 55 #include "modules/push_messaging/PushMessageData.h" |
| 54 #include "modules/serviceworkers/ExtendableEvent.h" | 56 #include "modules/serviceworkers/ExtendableEvent.h" |
| 55 #include "modules/serviceworkers/ExtendableMessageEvent.h" | 57 #include "modules/serviceworkers/ExtendableMessageEvent.h" |
| 56 #include "modules/serviceworkers/FetchEvent.h" | 58 #include "modules/serviceworkers/FetchEvent.h" |
| 57 #include "modules/serviceworkers/ForeignFetchEvent.h" | 59 #include "modules/serviceworkers/ForeignFetchEvent.h" |
| 58 #include "modules/serviceworkers/InstallEvent.h" | 60 #include "modules/serviceworkers/InstallEvent.h" |
| 59 #include "modules/serviceworkers/ServiceWorkerClient.h" | 61 #include "modules/serviceworkers/ServiceWorkerClient.h" |
| 60 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h" | 62 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h" |
| 61 #include "modules/serviceworkers/ServiceWorkerWindowClient.h" | 63 #include "modules/serviceworkers/ServiceWorkerWindowClient.h" |
| 62 #include "modules/serviceworkers/WaitUntilObserver.h" | 64 #include "modules/serviceworkers/WaitUntilObserver.h" |
| 63 #include "platform/RuntimeEnabledFeatures.h" | 65 #include "platform/RuntimeEnabledFeatures.h" |
| 66 #include "platform/network/ResourceError.h" |
| 64 #include "public/platform/modules/notifications/WebNotificationData.h" | 67 #include "public/platform/modules/notifications/WebNotificationData.h" |
| 65 #include "public/platform/modules/serviceworker/WebServiceWorkerEventResult.h" | 68 #include "public/platform/modules/serviceworker/WebServiceWorkerEventResult.h" |
| 66 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h" | 69 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h" |
| 67 #include "public/web/WebSerializedScriptValue.h" | 70 #include "public/web/WebSerializedScriptValue.h" |
| 68 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h" | 71 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h" |
| 69 #include "web/WebEmbeddedWorkerImpl.h" | 72 #include "web/WebEmbeddedWorkerImpl.h" |
| 70 #include "wtf/Assertions.h" | 73 #include "wtf/Assertions.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> |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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( |
| 204 int fetchEventID, |
| 205 const WebURL& url, |
| 206 base::TimeTicks sentTimestamp, |
| 207 base::Time sentWallTime) { |
| 208 FetchInitiatorInfo info; |
| 209 ResourceRequest request(url); |
| 210 InspectorInstrumentation::willSendRequest( |
| 211 workerGlobalScope(), fetchEventID, nullptr, request, ResourceResponse(), |
| 212 info, sentTimestamp.ToInternalValue() / |
| 213 static_cast<double>(base::Time::kMicrosecondsPerSecond), |
| 214 sentWallTime.ToDoubleT()); |
| 215 } |
| 216 |
| 200 void ServiceWorkerGlobalScopeProxy::onNavigationPreloadResponse( | 217 void ServiceWorkerGlobalScopeProxy::onNavigationPreloadResponse( |
| 201 int fetchEventID, | 218 int fetchEventID, |
| 202 std::unique_ptr<WebURLResponse> response, | 219 std::unique_ptr<WebURLResponse> response, |
| 203 std::unique_ptr<WebDataConsumerHandle> dataConsumeHandle) { | 220 std::unique_ptr<WebDataConsumerHandle> dataConsumeHandle) { |
| 221 InspectorInstrumentation::didReceiveResourceResponse( |
| 222 workerGlobalScope(), fetchEventID, nullptr, |
| 223 response->toResourceResponse(), nullptr); |
| 204 FetchEvent* fetchEvent = m_pendingPreloadFetchEvents.take(fetchEventID); | 224 FetchEvent* fetchEvent = m_pendingPreloadFetchEvents.take(fetchEventID); |
| 205 DCHECK(fetchEvent); | 225 DCHECK(fetchEvent); |
| 206 fetchEvent->onNavigationPreloadResponse( | 226 fetchEvent->onNavigationPreloadResponse( |
| 207 workerGlobalScope()->scriptController()->getScriptState(), | 227 workerGlobalScope()->scriptController()->getScriptState(), |
| 208 std::move(response), std::move(dataConsumeHandle)); | 228 std::move(response), std::move(dataConsumeHandle)); |
| 209 } | 229 } |
| 210 | 230 |
| 211 void ServiceWorkerGlobalScopeProxy::onNavigationPreloadError( | 231 void ServiceWorkerGlobalScopeProxy::onNavigationPreloadError( |
| 212 int fetchEventID, | 232 int fetchEventID, |
| 213 std::unique_ptr<WebServiceWorkerError> error) { | 233 std::unique_ptr<WebServiceWorkerError> error) { |
| 234 InspectorInstrumentation::didFailLoading( |
| 235 workerGlobalScope(), fetchEventID, |
| 236 ResourceError(errorDomainBlinkInternal, 0, "", error->message)); |
| 237 |
| 214 FetchEvent* fetchEvent = m_pendingPreloadFetchEvents.take(fetchEventID); | 238 FetchEvent* fetchEvent = m_pendingPreloadFetchEvents.take(fetchEventID); |
| 215 // This method may be called after onNavigationPreloadResponse() was called. | 239 // This method may be called after onNavigationPreloadResponse() was called. |
| 216 if (!fetchEvent) | 240 if (!fetchEvent) |
| 217 return; | 241 return; |
| 218 fetchEvent->onNavigationPreloadError( | 242 fetchEvent->onNavigationPreloadError( |
| 219 workerGlobalScope()->scriptController()->getScriptState(), | 243 workerGlobalScope()->scriptController()->getScriptState(), |
| 220 std::move(error)); | 244 std::move(error)); |
| 221 } | 245 } |
| 222 | 246 |
| 247 void ServiceWorkerGlobalScopeProxy::onNavigationPreloadCompleted( |
| 248 int fetchEventID, |
| 249 int64_t encodedDataLength) { |
| 250 InspectorInstrumentation::didFinishLoading(workerGlobalScope(), fetchEventID, |
| 251 monotonicallyIncreasingTime(), |
| 252 encodedDataLength); |
| 253 } |
| 254 |
| 223 void ServiceWorkerGlobalScopeProxy::dispatchForeignFetchEvent( | 255 void ServiceWorkerGlobalScopeProxy::dispatchForeignFetchEvent( |
| 224 int fetchEventID, | 256 int fetchEventID, |
| 225 const WebServiceWorkerRequest& webRequest) { | 257 const WebServiceWorkerRequest& webRequest) { |
| 226 if (!OriginTrials::foreignFetchEnabled(workerGlobalScope())) { | 258 if (!OriginTrials::foreignFetchEnabled(workerGlobalScope())) { |
| 227 // If origin trial tokens have expired, or are otherwise no longer valid | 259 // If origin trial tokens have expired, or are otherwise no longer valid |
| 228 // no events should be dispatched. | 260 // no events should be dispatched. |
| 229 // TODO(mek): Ideally the browser wouldn't even start the service worker | 261 // TODO(mek): Ideally the browser wouldn't even start the service worker |
| 230 // if its tokens have expired. | 262 // if its tokens have expired. |
| 231 ServiceWorkerGlobalScopeClient::from(workerGlobalScope()) | 263 ServiceWorkerGlobalScopeClient::from(workerGlobalScope()) |
| 232 ->respondToFetchEvent(fetchEventID, WTF::currentTime()); | 264 ->respondToFetchEvent(fetchEventID, WTF::currentTime()); |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 return *m_document; | 520 return *m_document; |
| 489 } | 521 } |
| 490 | 522 |
| 491 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope() | 523 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope() |
| 492 const { | 524 const { |
| 493 DCHECK(m_workerGlobalScope); | 525 DCHECK(m_workerGlobalScope); |
| 494 return m_workerGlobalScope; | 526 return m_workerGlobalScope; |
| 495 } | 527 } |
| 496 | 528 |
| 497 } // namespace blink | 529 } // namespace blink |
| OLD | NEW |