Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: content/child/service_worker/web_service_worker_impl.cc

Issue 1701843002: ServiceWorker: Implement 'source' and 'origin' attributes of ExtendableMessageEvent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_focus_into_utils
Patch Set: fix oilpan build Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/service_worker/web_service_worker_provider_impl.h"
12 #include "content/child/thread_safe_sender.h" 13 #include "content/child/thread_safe_sender.h"
13 #include "content/child/webmessageportchannel_impl.h" 14 #include "content/child/webmessageportchannel_impl.h"
14 #include "content/common/service_worker/service_worker_messages.h" 15 #include "content/common/service_worker/service_worker_messages.h"
15 #include "third_party/WebKit/public/platform/WebString.h" 16 #include "third_party/WebKit/public/platform/WebString.h"
16 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerProxy.h" 17 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerProxy.h"
17 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 18 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
18 19
19 using blink::WebMessagePortChannel; 20 using blink::WebMessagePortChannel;
20 using blink::WebMessagePortChannelArray; 21 using blink::WebMessagePortChannelArray;
21 using blink::WebMessagePortChannelClient; 22 using blink::WebMessagePortChannelClient;
(...skipping 14 matching lines...) Expand all
36 37
37 private: 38 private:
38 scoped_refptr<WebServiceWorkerImpl> worker_; 39 scoped_refptr<WebServiceWorkerImpl> worker_;
39 40
40 DISALLOW_COPY_AND_ASSIGN(HandleImpl); 41 DISALLOW_COPY_AND_ASSIGN(HandleImpl);
41 }; 42 };
42 43
43 void SendPostMessageToWorkerOnMainThread( 44 void SendPostMessageToWorkerOnMainThread(
44 ThreadSafeSender* thread_safe_sender, 45 ThreadSafeSender* thread_safe_sender,
45 int handle_id, 46 int handle_id,
47 int provider_id,
46 const base::string16& message, 48 const base::string16& message,
47 scoped_ptr<WebMessagePortChannelArray> channels) { 49 scoped_ptr<WebMessagePortChannelArray> channels) {
48 if (WebRuntimeFeatures::isServiceWorkerExtendableMessageEventEnabled()) { 50 if (WebRuntimeFeatures::isServiceWorkerExtendableMessageEventEnabled()) {
49 thread_safe_sender->Send(new ServiceWorkerHostMsg_PostMessageToWorker( 51 thread_safe_sender->Send(new ServiceWorkerHostMsg_PostMessageToWorker(
50 handle_id, message, 52 handle_id, provider_id, message,
51 WebMessagePortChannelImpl::ExtractMessagePortIDs(std::move(channels)))); 53 WebMessagePortChannelImpl::ExtractMessagePortIDs(std::move(channels))));
52 } else { 54 } else {
53 thread_safe_sender->Send( 55 thread_safe_sender->Send(
54 new ServiceWorkerHostMsg_DeprecatedPostMessageToWorker( 56 new ServiceWorkerHostMsg_DeprecatedPostMessageToWorker(
55 handle_id, message, 57 handle_id, message,
56 WebMessagePortChannelImpl::ExtractMessagePortIDs( 58 WebMessagePortChannelImpl::ExtractMessagePortIDs(
57 std::move(channels)))); 59 std::move(channels))));
58 } 60 }
59 } 61 }
60 62
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 95 }
94 96
95 blink::WebURL WebServiceWorkerImpl::url() const { 97 blink::WebURL WebServiceWorkerImpl::url() const {
96 return handle_ref_->url(); 98 return handle_ref_->url();
97 } 99 }
98 100
99 blink::WebServiceWorkerState WebServiceWorkerImpl::state() const { 101 blink::WebServiceWorkerState WebServiceWorkerImpl::state() const {
100 return state_; 102 return state_;
101 } 103 }
102 104
103 void WebServiceWorkerImpl::postMessage(const WebString& message, 105 void WebServiceWorkerImpl::postMessage(
104 WebMessagePortChannelArray* channels) { 106 blink::WebServiceWorkerProvider* provider,
107 const WebString& message,
108 WebMessagePortChannelArray* channels) {
109 WebServiceWorkerProviderImpl* provider_impl =
110 static_cast<WebServiceWorkerProviderImpl*>(provider);
105 ServiceWorkerDispatcher* dispatcher = 111 ServiceWorkerDispatcher* dispatcher =
106 ServiceWorkerDispatcher::GetThreadSpecificInstance(); 112 ServiceWorkerDispatcher::GetThreadSpecificInstance();
107 DCHECK(dispatcher); 113 DCHECK(dispatcher);
108 114
109 // This may send channels for MessagePorts, and all internal book-keeping 115 // This may send channels for MessagePorts, and all internal book-keeping
110 // messages for MessagePort (e.g. QueueMessages) are sent from main thread 116 // messages for MessagePort (e.g. QueueMessages) are sent from main thread
111 // (with thread hopping), so we need to do the same thread hopping here not 117 // (with thread hopping), so we need to do the same thread hopping here not
112 // to overtake those messages. 118 // to overtake those messages.
113 dispatcher->main_thread_task_runner()->PostTask( 119 dispatcher->main_thread_task_runner()->PostTask(
114 FROM_HERE, base::Bind(&SendPostMessageToWorkerOnMainThread, 120 FROM_HERE,
115 thread_safe_sender_, handle_ref_->handle_id(), 121 base::Bind(&SendPostMessageToWorkerOnMainThread, thread_safe_sender_,
116 // We cast WebString to string16 before crossing 122 handle_ref_->handle_id(), provider_impl->provider_id(),
117 // threads for thread-safety. 123 // We cast WebString to string16 before crossing
118 static_cast<base::string16>(message), 124 // threads for thread-safety.
119 base::Passed(make_scoped_ptr(channels)))); 125 static_cast<base::string16>(message),
126 base::Passed(make_scoped_ptr(channels))));
120 } 127 }
121 128
122 void WebServiceWorkerImpl::terminate() { 129 void WebServiceWorkerImpl::terminate() {
123 thread_safe_sender_->Send( 130 thread_safe_sender_->Send(
124 new ServiceWorkerHostMsg_TerminateWorker(handle_ref_->handle_id())); 131 new ServiceWorkerHostMsg_TerminateWorker(handle_ref_->handle_id()));
125 } 132 }
126 133
127 // static 134 // static
128 blink::WebPassOwnPtr<blink::WebServiceWorker::Handle> 135 blink::WebPassOwnPtr<blink::WebServiceWorker::Handle>
129 WebServiceWorkerImpl::CreateHandle( 136 WebServiceWorkerImpl::CreateHandle(
130 const scoped_refptr<WebServiceWorkerImpl>& worker) { 137 const scoped_refptr<WebServiceWorkerImpl>& worker) {
131 if (!worker) 138 if (!worker)
132 return nullptr; 139 return nullptr;
133 return blink::adoptWebPtr(new HandleImpl(worker)); 140 return blink::adoptWebPtr(new HandleImpl(worker));
134 } 141 }
135 142
136 WebServiceWorkerImpl::~WebServiceWorkerImpl() { 143 WebServiceWorkerImpl::~WebServiceWorkerImpl() {
137 ServiceWorkerDispatcher* dispatcher = 144 ServiceWorkerDispatcher* dispatcher =
138 ServiceWorkerDispatcher::GetThreadSpecificInstance(); 145 ServiceWorkerDispatcher::GetThreadSpecificInstance();
139 if (dispatcher) 146 if (dispatcher)
140 dispatcher->RemoveServiceWorker(handle_ref_->handle_id()); 147 dispatcher->RemoveServiceWorker(handle_ref_->handle_id());
141 } 148 }
142 149
143 } // namespace content 150 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698