| 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/web_service_worker_impl.h" | 5 #include "content/child/service_worker/web_service_worker_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "content/child/service_worker/service_worker_dispatcher.h" | 10 #include "content/child/service_worker/service_worker_dispatcher.h" |
| 11 #include "content/child/service_worker/service_worker_handle_reference.h" | 11 #include "content/child/service_worker/service_worker_handle_reference.h" |
| 12 #include "content/child/thread_safe_sender.h" | 12 #include "content/child/thread_safe_sender.h" |
| 13 #include "content/child/webmessageportchannel_impl.h" | 13 #include "content/child/webmessageportchannel_impl.h" |
| 14 #include "content/common/service_worker/service_worker_messages.h" | 14 #include "content/common/service_worker/service_worker_messages.h" |
| 15 #include "third_party/WebKit/public/platform/WebString.h" | 15 #include "third_party/WebKit/public/platform/WebString.h" |
| 16 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerProxy.h" | 16 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerProxy.h" |
| 17 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 17 | 18 |
| 18 using blink::WebMessagePortChannel; | 19 using blink::WebMessagePortChannel; |
| 19 using blink::WebMessagePortChannelArray; | 20 using blink::WebMessagePortChannelArray; |
| 20 using blink::WebMessagePortChannelClient; | 21 using blink::WebMessagePortChannelClient; |
| 22 using blink::WebRuntimeFeatures; |
| 21 using blink::WebString; | 23 using blink::WebString; |
| 22 | 24 |
| 23 namespace content { | 25 namespace content { |
| 24 | 26 |
| 25 namespace { | 27 namespace { |
| 26 | 28 |
| 27 class HandleImpl : public blink::WebServiceWorker::Handle { | 29 class HandleImpl : public blink::WebServiceWorker::Handle { |
| 28 public: | 30 public: |
| 29 explicit HandleImpl(const scoped_refptr<WebServiceWorkerImpl>& worker) | 31 explicit HandleImpl(const scoped_refptr<WebServiceWorkerImpl>& worker) |
| 30 : worker_(worker) {} | 32 : worker_(worker) {} |
| 31 ~HandleImpl() override {} | 33 ~HandleImpl() override {} |
| 32 | 34 |
| 33 blink::WebServiceWorker* serviceWorker() override { return worker_.get(); } | 35 blink::WebServiceWorker* serviceWorker() override { return worker_.get(); } |
| 34 | 36 |
| 35 private: | 37 private: |
| 36 scoped_refptr<WebServiceWorkerImpl> worker_; | 38 scoped_refptr<WebServiceWorkerImpl> worker_; |
| 37 | 39 |
| 38 DISALLOW_COPY_AND_ASSIGN(HandleImpl); | 40 DISALLOW_COPY_AND_ASSIGN(HandleImpl); |
| 39 }; | 41 }; |
| 40 | 42 |
| 41 void SendPostMessageToWorkerOnMainThread( | 43 void SendPostMessageToWorkerOnMainThread( |
| 42 ThreadSafeSender* thread_safe_sender, | 44 ThreadSafeSender* thread_safe_sender, |
| 43 int handle_id, | 45 int handle_id, |
| 44 const base::string16& message, | 46 const base::string16& message, |
| 45 scoped_ptr<WebMessagePortChannelArray> channels) { | 47 scoped_ptr<WebMessagePortChannelArray> channels) { |
| 46 // TODO(nhiroki): Switch to PostMessageToClient message after | 48 if (WebRuntimeFeatures::isServiceWorkerExtendableMessageEventEnabled()) { |
| 47 // ExtendableMessageEvent is implemented (crbug.com/543198). | 49 thread_safe_sender->Send(new ServiceWorkerHostMsg_PostMessageToWorker( |
| 48 thread_safe_sender->Send( | 50 handle_id, message, |
| 49 new ServiceWorkerHostMsg_DeprecatedPostMessageToWorker( | 51 WebMessagePortChannelImpl::ExtractMessagePortIDs(std::move(channels)))); |
| 50 handle_id, message, WebMessagePortChannelImpl::ExtractMessagePortIDs( | 52 } else { |
| 51 std::move(channels)))); | 53 thread_safe_sender->Send( |
| 54 new ServiceWorkerHostMsg_DeprecatedPostMessageToWorker( |
| 55 handle_id, message, |
| 56 WebMessagePortChannelImpl::ExtractMessagePortIDs( |
| 57 std::move(channels)))); |
| 58 } |
| 52 } | 59 } |
| 53 | 60 |
| 54 } // namespace | 61 } // namespace |
| 55 | 62 |
| 56 WebServiceWorkerImpl::WebServiceWorkerImpl( | 63 WebServiceWorkerImpl::WebServiceWorkerImpl( |
| 57 scoped_ptr<ServiceWorkerHandleReference> handle_ref, | 64 scoped_ptr<ServiceWorkerHandleReference> handle_ref, |
| 58 ThreadSafeSender* thread_safe_sender) | 65 ThreadSafeSender* thread_safe_sender) |
| 59 : handle_ref_(std::move(handle_ref)), | 66 : handle_ref_(std::move(handle_ref)), |
| 60 state_(handle_ref_->state()), | 67 state_(handle_ref_->state()), |
| 61 thread_safe_sender_(thread_safe_sender), | 68 thread_safe_sender_(thread_safe_sender), |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 } | 134 } |
| 128 | 135 |
| 129 WebServiceWorkerImpl::~WebServiceWorkerImpl() { | 136 WebServiceWorkerImpl::~WebServiceWorkerImpl() { |
| 130 ServiceWorkerDispatcher* dispatcher = | 137 ServiceWorkerDispatcher* dispatcher = |
| 131 ServiceWorkerDispatcher::GetThreadSpecificInstance(); | 138 ServiceWorkerDispatcher::GetThreadSpecificInstance(); |
| 132 if (dispatcher) | 139 if (dispatcher) |
| 133 dispatcher->RemoveServiceWorker(handle_ref_->handle_id()); | 140 dispatcher->RemoveServiceWorker(handle_ref_->handle_id()); |
| 134 } | 141 } |
| 135 | 142 |
| 136 } // namespace content | 143 } // namespace content |
| OLD | NEW |