Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/child/service_worker/service_worker_dispatcher.h" | 5 #include "content/child/service_worker/service_worker_dispatcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 const GURL& script_url, | 124 const GURL& script_url, |
| 125 std::unique_ptr<WebServiceWorkerRegistrationCallbacks> callbacks) { | 125 std::unique_ptr<WebServiceWorkerRegistrationCallbacks> callbacks) { |
| 126 DCHECK(callbacks); | 126 DCHECK(callbacks); |
| 127 | 127 |
| 128 if (pattern.possibly_invalid_spec().size() > url::kMaxURLChars || | 128 if (pattern.possibly_invalid_spec().size() > url::kMaxURLChars || |
| 129 script_url.possibly_invalid_spec().size() > url::kMaxURLChars) { | 129 script_url.possibly_invalid_spec().size() > url::kMaxURLChars) { |
| 130 std::string error_message(kServiceWorkerRegisterErrorPrefix); | 130 std::string error_message(kServiceWorkerRegisterErrorPrefix); |
| 131 error_message += "The provided scriptURL or scope is too long."; | 131 error_message += "The provided scriptURL or scope is too long."; |
| 132 callbacks->onError( | 132 callbacks->onError( |
| 133 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, | 133 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, |
| 134 blink::WebString::fromUTF8(error_message))); | 134 blink::WebString::fromASCII(error_message))); |
|
falken
2016/12/26 01:26:20
Just to be sure what happens if you pass something
| |
| 135 return; | 135 return; |
| 136 } | 136 } |
| 137 | 137 |
| 138 int request_id = pending_registration_callbacks_.Add(std::move(callbacks)); | 138 int request_id = pending_registration_callbacks_.Add(std::move(callbacks)); |
| 139 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", | 139 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", |
| 140 "ServiceWorkerDispatcher::RegisterServiceWorker", | 140 "ServiceWorkerDispatcher::RegisterServiceWorker", |
| 141 request_id, | 141 request_id, |
| 142 "Scope", pattern.spec(), | 142 "Scope", pattern.spec(), |
| 143 "Script URL", script_url.spec()); | 143 "Script URL", script_url.spec()); |
| 144 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( | 144 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 172 int provider_id, | 172 int provider_id, |
| 173 const GURL& document_url, | 173 const GURL& document_url, |
| 174 std::unique_ptr<WebServiceWorkerGetRegistrationCallbacks> callbacks) { | 174 std::unique_ptr<WebServiceWorkerGetRegistrationCallbacks> callbacks) { |
| 175 DCHECK(callbacks); | 175 DCHECK(callbacks); |
| 176 | 176 |
| 177 if (document_url.possibly_invalid_spec().size() > url::kMaxURLChars) { | 177 if (document_url.possibly_invalid_spec().size() > url::kMaxURLChars) { |
| 178 std::string error_message(kServiceWorkerGetRegistrationErrorPrefix); | 178 std::string error_message(kServiceWorkerGetRegistrationErrorPrefix); |
| 179 error_message += "The provided documentURL is too long."; | 179 error_message += "The provided documentURL is too long."; |
| 180 callbacks->onError( | 180 callbacks->onError( |
| 181 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, | 181 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, |
| 182 blink::WebString::fromUTF8(error_message))); | 182 blink::WebString::fromASCII(error_message))); |
| 183 return; | 183 return; |
| 184 } | 184 } |
| 185 | 185 |
| 186 int request_id = | 186 int request_id = |
| 187 pending_get_registration_callbacks_.Add(std::move(callbacks)); | 187 pending_get_registration_callbacks_.Add(std::move(callbacks)); |
| 188 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 188 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
| 189 "ServiceWorkerDispatcher::GetRegistration", | 189 "ServiceWorkerDispatcher::GetRegistration", |
| 190 request_id, | 190 request_id, |
| 191 "Document URL", document_url.spec()); | 191 "Document URL", document_url.spec()); |
| 192 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration( | 192 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration( |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 610 "OnRegistrationError"); | 610 "OnRegistrationError"); |
| 611 TRACE_EVENT_ASYNC_END0("ServiceWorker", | 611 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| 612 "ServiceWorkerDispatcher::RegisterServiceWorker", | 612 "ServiceWorkerDispatcher::RegisterServiceWorker", |
| 613 request_id); | 613 request_id); |
| 614 WebServiceWorkerRegistrationCallbacks* callbacks = | 614 WebServiceWorkerRegistrationCallbacks* callbacks = |
| 615 pending_registration_callbacks_.Lookup(request_id); | 615 pending_registration_callbacks_.Lookup(request_id); |
| 616 DCHECK(callbacks); | 616 DCHECK(callbacks); |
| 617 if (!callbacks) | 617 if (!callbacks) |
| 618 return; | 618 return; |
| 619 | 619 |
| 620 callbacks->onError(WebServiceWorkerError(error_type, message)); | 620 callbacks->onError( |
| 621 WebServiceWorkerError(error_type, blink::WebString::fromUTF16(message))); | |
| 621 pending_registration_callbacks_.Remove(request_id); | 622 pending_registration_callbacks_.Remove(request_id); |
| 622 } | 623 } |
| 623 | 624 |
| 624 void ServiceWorkerDispatcher::OnUpdateError( | 625 void ServiceWorkerDispatcher::OnUpdateError( |
| 625 int thread_id, | 626 int thread_id, |
| 626 int request_id, | 627 int request_id, |
| 627 WebServiceWorkerError::ErrorType error_type, | 628 WebServiceWorkerError::ErrorType error_type, |
| 628 const base::string16& message) { | 629 const base::string16& message) { |
| 629 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", | 630 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", |
| 630 "ServiceWorkerDispatcher::UpdateServiceWorker", | 631 "ServiceWorkerDispatcher::UpdateServiceWorker", |
| 631 request_id, "OnUpdateError"); | 632 request_id, "OnUpdateError"); |
| 632 TRACE_EVENT_ASYNC_END0("ServiceWorker", | 633 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| 633 "ServiceWorkerDispatcher::UpdateServiceWorker", | 634 "ServiceWorkerDispatcher::UpdateServiceWorker", |
| 634 request_id); | 635 request_id); |
| 635 WebServiceWorkerUpdateCallbacks* callbacks = | 636 WebServiceWorkerUpdateCallbacks* callbacks = |
| 636 pending_update_callbacks_.Lookup(request_id); | 637 pending_update_callbacks_.Lookup(request_id); |
| 637 DCHECK(callbacks); | 638 DCHECK(callbacks); |
| 638 if (!callbacks) | 639 if (!callbacks) |
| 639 return; | 640 return; |
| 640 | 641 |
| 641 callbacks->onError(WebServiceWorkerError(error_type, message)); | 642 callbacks->onError( |
| 643 WebServiceWorkerError(error_type, blink::WebString::fromUTF16(message))); | |
| 642 pending_update_callbacks_.Remove(request_id); | 644 pending_update_callbacks_.Remove(request_id); |
| 643 } | 645 } |
| 644 | 646 |
| 645 void ServiceWorkerDispatcher::OnUnregistrationError( | 647 void ServiceWorkerDispatcher::OnUnregistrationError( |
| 646 int thread_id, | 648 int thread_id, |
| 647 int request_id, | 649 int request_id, |
| 648 WebServiceWorkerError::ErrorType error_type, | 650 WebServiceWorkerError::ErrorType error_type, |
| 649 const base::string16& message) { | 651 const base::string16& message) { |
| 650 TRACE_EVENT_ASYNC_STEP_INTO0( | 652 TRACE_EVENT_ASYNC_STEP_INTO0( |
| 651 "ServiceWorker", | 653 "ServiceWorker", |
| 652 "ServiceWorkerDispatcher::UnregisterServiceWorker", | 654 "ServiceWorkerDispatcher::UnregisterServiceWorker", |
| 653 request_id, | 655 request_id, |
| 654 "OnUnregistrationError"); | 656 "OnUnregistrationError"); |
| 655 TRACE_EVENT_ASYNC_END0("ServiceWorker", | 657 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| 656 "ServiceWorkerDispatcher::UnregisterServiceWorker", | 658 "ServiceWorkerDispatcher::UnregisterServiceWorker", |
| 657 request_id); | 659 request_id); |
| 658 WebServiceWorkerUnregistrationCallbacks* callbacks = | 660 WebServiceWorkerUnregistrationCallbacks* callbacks = |
| 659 pending_unregistration_callbacks_.Lookup(request_id); | 661 pending_unregistration_callbacks_.Lookup(request_id); |
| 660 DCHECK(callbacks); | 662 DCHECK(callbacks); |
| 661 if (!callbacks) | 663 if (!callbacks) |
| 662 return; | 664 return; |
| 663 | 665 |
| 664 callbacks->onError(WebServiceWorkerError(error_type, message)); | 666 callbacks->onError( |
| 667 WebServiceWorkerError(error_type, blink::WebString::fromUTF16(message))); | |
| 665 pending_unregistration_callbacks_.Remove(request_id); | 668 pending_unregistration_callbacks_.Remove(request_id); |
| 666 } | 669 } |
| 667 | 670 |
| 668 void ServiceWorkerDispatcher::OnGetRegistrationError( | 671 void ServiceWorkerDispatcher::OnGetRegistrationError( |
| 669 int thread_id, | 672 int thread_id, |
| 670 int request_id, | 673 int request_id, |
| 671 WebServiceWorkerError::ErrorType error_type, | 674 WebServiceWorkerError::ErrorType error_type, |
| 672 const base::string16& message) { | 675 const base::string16& message) { |
| 673 TRACE_EVENT_ASYNC_STEP_INTO0( | 676 TRACE_EVENT_ASYNC_STEP_INTO0( |
| 674 "ServiceWorker", | 677 "ServiceWorker", |
| 675 "ServiceWorkerDispatcher::GetRegistration", | 678 "ServiceWorkerDispatcher::GetRegistration", |
| 676 request_id, | 679 request_id, |
| 677 "OnGetRegistrationError"); | 680 "OnGetRegistrationError"); |
| 678 TRACE_EVENT_ASYNC_END0("ServiceWorker", | 681 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| 679 "ServiceWorkerDispatcher::GetRegistration", | 682 "ServiceWorkerDispatcher::GetRegistration", |
| 680 request_id); | 683 request_id); |
| 681 WebServiceWorkerGetRegistrationCallbacks* callbacks = | 684 WebServiceWorkerGetRegistrationCallbacks* callbacks = |
| 682 pending_get_registration_callbacks_.Lookup(request_id); | 685 pending_get_registration_callbacks_.Lookup(request_id); |
| 683 DCHECK(callbacks); | 686 DCHECK(callbacks); |
| 684 if (!callbacks) | 687 if (!callbacks) |
| 685 return; | 688 return; |
| 686 | 689 |
| 687 callbacks->onError(WebServiceWorkerError(error_type, message)); | 690 callbacks->onError( |
| 691 WebServiceWorkerError(error_type, blink::WebString::fromUTF16(message))); | |
| 688 pending_get_registration_callbacks_.Remove(request_id); | 692 pending_get_registration_callbacks_.Remove(request_id); |
| 689 } | 693 } |
| 690 | 694 |
| 691 void ServiceWorkerDispatcher::OnGetRegistrationsError( | 695 void ServiceWorkerDispatcher::OnGetRegistrationsError( |
| 692 int thread_id, | 696 int thread_id, |
| 693 int request_id, | 697 int request_id, |
| 694 WebServiceWorkerError::ErrorType error_type, | 698 WebServiceWorkerError::ErrorType error_type, |
| 695 const base::string16& message) { | 699 const base::string16& message) { |
| 696 TRACE_EVENT_ASYNC_STEP_INTO0( | 700 TRACE_EVENT_ASYNC_STEP_INTO0( |
| 697 "ServiceWorker", | 701 "ServiceWorker", |
| 698 "ServiceWorkerDispatcher::GetRegistrations", | 702 "ServiceWorkerDispatcher::GetRegistrations", |
| 699 request_id, | 703 request_id, |
| 700 "OnGetRegistrationsError"); | 704 "OnGetRegistrationsError"); |
| 701 TRACE_EVENT_ASYNC_END0("ServiceWorker", | 705 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| 702 "ServiceWorkerDispatcher::GetRegistrations", | 706 "ServiceWorkerDispatcher::GetRegistrations", |
| 703 request_id); | 707 request_id); |
| 704 WebServiceWorkerGetRegistrationsCallbacks* callbacks = | 708 WebServiceWorkerGetRegistrationsCallbacks* callbacks = |
| 705 pending_get_registrations_callbacks_.Lookup(request_id); | 709 pending_get_registrations_callbacks_.Lookup(request_id); |
| 706 DCHECK(callbacks); | 710 DCHECK(callbacks); |
| 707 if (!callbacks) | 711 if (!callbacks) |
| 708 return; | 712 return; |
| 709 | 713 |
| 710 callbacks->onError(WebServiceWorkerError(error_type, message)); | 714 callbacks->onError( |
| 715 WebServiceWorkerError(error_type, blink::WebString::fromUTF16(message))); | |
| 711 pending_get_registrations_callbacks_.Remove(request_id); | 716 pending_get_registrations_callbacks_.Remove(request_id); |
| 712 } | 717 } |
| 713 | 718 |
| 714 void ServiceWorkerDispatcher::OnEnableNavigationPreloadError( | 719 void ServiceWorkerDispatcher::OnEnableNavigationPreloadError( |
| 715 int thread_id, | 720 int thread_id, |
| 716 int request_id, | 721 int request_id, |
| 717 WebServiceWorkerError::ErrorType error_type, | 722 WebServiceWorkerError::ErrorType error_type, |
| 718 const std::string& message) { | 723 const std::string& message) { |
| 719 WebEnableNavigationPreloadCallbacks* callbacks = | 724 WebEnableNavigationPreloadCallbacks* callbacks = |
| 720 enable_navigation_preload_callbacks_.Lookup(request_id); | 725 enable_navigation_preload_callbacks_.Lookup(request_id); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 859 // client. | 864 // client. |
| 860 return; | 865 return; |
| 861 } | 866 } |
| 862 | 867 |
| 863 blink::WebMessagePortChannelArray ports = | 868 blink::WebMessagePortChannelArray ports = |
| 864 WebMessagePortChannelImpl::CreatePorts( | 869 WebMessagePortChannelImpl::CreatePorts( |
| 865 params.message_ports, params.new_routing_ids, | 870 params.message_ports, params.new_routing_ids, |
| 866 base::ThreadTaskRunnerHandle::Get()); | 871 base::ThreadTaskRunnerHandle::Get()); |
| 867 | 872 |
| 868 found->second->dispatchMessageEvent( | 873 found->second->dispatchMessageEvent( |
| 869 WebServiceWorkerImpl::CreateHandle(worker), params.message, ports); | 874 WebServiceWorkerImpl::CreateHandle(worker), |
| 875 blink::WebString::fromUTF16(params.message), ports); | |
| 870 } | 876 } |
| 871 | 877 |
| 872 void ServiceWorkerDispatcher::AddServiceWorker( | 878 void ServiceWorkerDispatcher::AddServiceWorker( |
| 873 int handle_id, WebServiceWorkerImpl* worker) { | 879 int handle_id, WebServiceWorkerImpl* worker) { |
| 874 DCHECK(!base::ContainsKey(service_workers_, handle_id)); | 880 DCHECK(!base::ContainsKey(service_workers_, handle_id)); |
| 875 service_workers_[handle_id] = worker; | 881 service_workers_[handle_id] = worker; |
| 876 } | 882 } |
| 877 | 883 |
| 878 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { | 884 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { |
| 879 DCHECK(base::ContainsKey(service_workers_, handle_id)); | 885 DCHECK(base::ContainsKey(service_workers_, handle_id)); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 899 return ServiceWorkerRegistrationHandleReference::Adopt( | 905 return ServiceWorkerRegistrationHandleReference::Adopt( |
| 900 info, thread_safe_sender_.get()); | 906 info, thread_safe_sender_.get()); |
| 901 } | 907 } |
| 902 | 908 |
| 903 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( | 909 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( |
| 904 const ServiceWorkerObjectInfo& info) { | 910 const ServiceWorkerObjectInfo& info) { |
| 905 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); | 911 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); |
| 906 } | 912 } |
| 907 | 913 |
| 908 } // namespace content | 914 } // namespace content |
| OLD | NEW |