| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 #include "modules/serviceworkers/ExtendableMessageEvent.h" | 65 #include "modules/serviceworkers/ExtendableMessageEvent.h" |
| 66 #include "modules/serviceworkers/FetchEvent.h" | 66 #include "modules/serviceworkers/FetchEvent.h" |
| 67 #include "modules/serviceworkers/ForeignFetchEvent.h" | 67 #include "modules/serviceworkers/ForeignFetchEvent.h" |
| 68 #include "modules/serviceworkers/InstallEvent.h" | 68 #include "modules/serviceworkers/InstallEvent.h" |
| 69 #include "modules/serviceworkers/ServiceWorkerClient.h" | 69 #include "modules/serviceworkers/ServiceWorkerClient.h" |
| 70 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h" | 70 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h" |
| 71 #include "modules/serviceworkers/ServiceWorkerWindowClient.h" | 71 #include "modules/serviceworkers/ServiceWorkerWindowClient.h" |
| 72 #include "modules/serviceworkers/WaitUntilObserver.h" | 72 #include "modules/serviceworkers/WaitUntilObserver.h" |
| 73 #include "platform/CrossThreadFunctional.h" | 73 #include "platform/CrossThreadFunctional.h" |
| 74 #include "platform/RuntimeEnabledFeatures.h" | 74 #include "platform/RuntimeEnabledFeatures.h" |
| 75 #include "platform/loader/fetch/ResourceResponse.h" |
| 75 #include "platform/wtf/Assertions.h" | 76 #include "platform/wtf/Assertions.h" |
| 76 #include "platform/wtf/Functional.h" | 77 #include "platform/wtf/Functional.h" |
| 77 #include "platform/wtf/PtrUtil.h" | 78 #include "platform/wtf/PtrUtil.h" |
| 78 #include "public/platform/modules/notifications/WebNotificationData.h" | 79 #include "public/platform/modules/notifications/WebNotificationData.h" |
| 79 #include "public/platform/modules/serviceworker/WebServiceWorkerEventResult.h" | 80 #include "public/platform/modules/serviceworker/WebServiceWorkerEventResult.h" |
| 80 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h" | 81 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h" |
| 81 #include "public/web/WebSerializedScriptValue.h" | 82 #include "public/web/WebSerializedScriptValue.h" |
| 82 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h" | 83 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h" |
| 83 #include "web/WebEmbeddedWorkerImpl.h" | 84 #include "web/WebEmbeddedWorkerImpl.h" |
| 84 | 85 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 event_init.setRequest(request); | 272 event_init.setRequest(request); |
| 272 event_init.setClientId( | 273 event_init.setClientId( |
| 273 web_request.IsMainResourceLoad() ? WebString() : web_request.ClientId()); | 274 web_request.IsMainResourceLoad() ? WebString() : web_request.ClientId()); |
| 274 event_init.setIsReload(web_request.IsReload()); | 275 event_init.setIsReload(web_request.IsReload()); |
| 275 ScriptState* script_state = | 276 ScriptState* script_state = |
| 276 WorkerGlobalScope()->ScriptController()->GetScriptState(); | 277 WorkerGlobalScope()->ScriptController()->GetScriptState(); |
| 277 FetchEvent* fetch_event = FetchEvent::Create( | 278 FetchEvent* fetch_event = FetchEvent::Create( |
| 278 script_state, EventTypeNames::fetch, event_init, respond_with_observer, | 279 script_state, EventTypeNames::fetch, event_init, respond_with_observer, |
| 279 wait_until_observer, navigation_preload_sent); | 280 wait_until_observer, navigation_preload_sent); |
| 280 if (navigation_preload_sent) { | 281 if (navigation_preload_sent) { |
| 281 // Keep |fetchEvent| until onNavigationPreloadResponse() or | 282 // Keep |fetchEvent| until OnNavigationPreloadComplete() or |
| 282 // onNavigationPreloadError() will be called. | 283 // onNavigationPreloadError() will be called. |
| 283 pending_preload_fetch_events_.insert(fetch_event_id, fetch_event); | 284 pending_preload_fetch_events_.insert(fetch_event_id, fetch_event); |
| 284 } | 285 } |
| 285 wait_until_observer->WillDispatchEvent(); | 286 wait_until_observer->WillDispatchEvent(); |
| 286 respond_with_observer->WillDispatchEvent(); | 287 respond_with_observer->WillDispatchEvent(); |
| 287 DispatchEventResult dispatch_result = | 288 DispatchEventResult dispatch_result = |
| 288 WorkerGlobalScope()->DispatchEvent(fetch_event); | 289 WorkerGlobalScope()->DispatchEvent(fetch_event); |
| 289 respond_with_observer->DidDispatchEvent(dispatch_result); | 290 respond_with_observer->DidDispatchEvent(dispatch_result); |
| 290 // false is okay because waitUntil for fetch event doesn't care about the | 291 // false is okay because waitUntil for fetch event doesn't care about the |
| 291 // promise rejection or an uncaught runtime script error. | 292 // promise rejection or an uncaught runtime script error. |
| 292 wait_until_observer->DidDispatchEvent(false /* errorOccurred */); | 293 wait_until_observer->DidDispatchEvent(false /* errorOccurred */); |
| 293 } | 294 } |
| 294 | 295 |
| 295 void ServiceWorkerGlobalScopeProxy::OnNavigationPreloadResponse( | 296 void ServiceWorkerGlobalScopeProxy::OnNavigationPreloadResponse( |
| 296 int fetch_event_id, | 297 int fetch_event_id, |
| 297 std::unique_ptr<WebURLResponse> response, | 298 std::unique_ptr<WebURLResponse> response, |
| 298 std::unique_ptr<WebDataConsumerHandle> data_consume_handle) { | 299 std::unique_ptr<WebDataConsumerHandle> data_consume_handle) { |
| 299 FetchEvent* fetch_event = pending_preload_fetch_events_.Take(fetch_event_id); | 300 auto it = pending_preload_fetch_events_.find(fetch_event_id); |
| 301 DCHECK(it != pending_preload_fetch_events_.end()); |
| 302 FetchEvent* fetch_event = it->value.Get(); |
| 300 DCHECK(fetch_event); | 303 DCHECK(fetch_event); |
| 301 fetch_event->OnNavigationPreloadResponse( | 304 fetch_event->OnNavigationPreloadResponse( |
| 302 WorkerGlobalScope()->ScriptController()->GetScriptState(), | 305 WorkerGlobalScope()->ScriptController()->GetScriptState(), |
| 303 std::move(response), std::move(data_consume_handle)); | 306 std::move(response), std::move(data_consume_handle)); |
| 304 } | 307 } |
| 305 | 308 |
| 306 void ServiceWorkerGlobalScopeProxy::OnNavigationPreloadError( | 309 void ServiceWorkerGlobalScopeProxy::OnNavigationPreloadError( |
| 307 int fetch_event_id, | 310 int fetch_event_id, |
| 308 std::unique_ptr<WebServiceWorkerError> error) { | 311 std::unique_ptr<WebServiceWorkerError> error) { |
| 309 FetchEvent* fetch_event = pending_preload_fetch_events_.Take(fetch_event_id); | 312 FetchEvent* fetch_event = pending_preload_fetch_events_.Take(fetch_event_id); |
| 310 // This method may be called after onNavigationPreloadResponse() was called. | 313 DCHECK(fetch_event); |
| 311 if (!fetch_event) | |
| 312 return; | |
| 313 // Display an unsanitized console message. | 314 // Display an unsanitized console message. |
| 314 if (!error->unsanitized_message.IsEmpty()) { | 315 if (!error->unsanitized_message.IsEmpty()) { |
| 315 WorkerGlobalScope()->AddConsoleMessage(ConsoleMessage::Create( | 316 WorkerGlobalScope()->AddConsoleMessage(ConsoleMessage::Create( |
| 316 kWorkerMessageSource, blink::MessageLevel::kErrorMessageLevel, | 317 kWorkerMessageSource, blink::MessageLevel::kErrorMessageLevel, |
| 317 error->unsanitized_message)); | 318 error->unsanitized_message)); |
| 318 } | 319 } |
| 319 // Reject the preloadResponse promise. | 320 // Reject the preloadResponse promise. |
| 320 fetch_event->OnNavigationPreloadError( | 321 fetch_event->OnNavigationPreloadError( |
| 321 WorkerGlobalScope()->ScriptController()->GetScriptState(), | 322 WorkerGlobalScope()->ScriptController()->GetScriptState(), |
| 322 std::move(error)); | 323 std::move(error)); |
| 323 } | 324 } |
| 324 | 325 |
| 326 void ServiceWorkerGlobalScopeProxy::OnNavigationPreloadComplete( |
| 327 int fetch_event_id, |
| 328 double completion_time, |
| 329 int64_t encoded_data_length, |
| 330 int64_t encoded_body_length, |
| 331 int64_t decoded_body_length) { |
| 332 FetchEvent* fetch_event = pending_preload_fetch_events_.Take(fetch_event_id); |
| 333 DCHECK(fetch_event); |
| 334 fetch_event->OnNavigationPreloadComplete( |
| 335 WorkerGlobalScope(), completion_time, encoded_data_length, |
| 336 encoded_body_length, decoded_body_length); |
| 337 } |
| 338 |
| 325 void ServiceWorkerGlobalScopeProxy::DispatchForeignFetchEvent( | 339 void ServiceWorkerGlobalScopeProxy::DispatchForeignFetchEvent( |
| 326 int fetch_event_id, | 340 int fetch_event_id, |
| 327 const WebServiceWorkerRequest& web_request) { | 341 const WebServiceWorkerRequest& web_request) { |
| 328 if (!OriginTrials::foreignFetchEnabled(WorkerGlobalScope())) { | 342 if (!OriginTrials::foreignFetchEnabled(WorkerGlobalScope())) { |
| 329 // If origin trial tokens have expired, or are otherwise no longer valid | 343 // If origin trial tokens have expired, or are otherwise no longer valid |
| 330 // no events should be dispatched. | 344 // no events should be dispatched. |
| 331 // TODO(mek): Ideally the browser wouldn't even start the service worker | 345 // TODO(mek): Ideally the browser wouldn't even start the service worker |
| 332 // if its tokens have expired. | 346 // if its tokens have expired. |
| 333 ServiceWorkerGlobalScopeClient::From(WorkerGlobalScope()) | 347 ServiceWorkerGlobalScopeClient::From(WorkerGlobalScope()) |
| 334 ->RespondToFetchEventWithNoResponse(fetch_event_id, WTF::CurrentTime()); | 348 ->RespondToFetchEventWithNoResponse(fetch_event_id, WTF::CurrentTime()); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 return *document_; | 612 return *document_; |
| 599 } | 613 } |
| 600 | 614 |
| 601 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::WorkerGlobalScope() | 615 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::WorkerGlobalScope() |
| 602 const { | 616 const { |
| 603 DCHECK(worker_global_scope_); | 617 DCHECK(worker_global_scope_); |
| 604 return worker_global_scope_; | 618 return worker_global_scope_; |
| 605 } | 619 } |
| 606 | 620 |
| 607 } // namespace blink | 621 } // namespace blink |
| OLD | NEW |