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

Side by Side Diff: content/renderer/service_worker/service_worker_script_context.cc

Issue 296463005: Push API: fire push event from chrome://serviceworker-internals/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 6 years, 6 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
« no previous file with comments | « content/renderer/service_worker/service_worker_script_context.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/renderer/service_worker/service_worker_script_context.h" 5 #include "content/renderer/service_worker/service_worker_script_context.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/child/thread_safe_sender.h" 8 #include "content/child/thread_safe_sender.h"
9 #include "content/child/webmessageportchannel_impl.h" 9 #include "content/child/webmessageportchannel_impl.h"
10 #include "content/common/service_worker/service_worker_messages.h" 10 #include "content/common/service_worker/service_worker_messages.h"
11 #include "content/renderer/service_worker/embedded_worker_context_client.h" 11 #include "content/renderer/service_worker/embedded_worker_context_client.h"
12 #include "ipc/ipc_message.h" 12 #include "ipc/ipc_message.h"
13 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" 13 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h"
14 #include "third_party/WebKit/public/platform/WebString.h"
14 #include "third_party/WebKit/public/platform/WebURL.h" 15 #include "third_party/WebKit/public/platform/WebURL.h"
15 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h" 16 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h"
16 #include "third_party/WebKit/public/web/WebServiceWorkerContextProxy.h" 17 #include "third_party/WebKit/public/web/WebServiceWorkerContextProxy.h"
17 18
18 namespace content { 19 namespace content {
19 20
20 namespace { 21 namespace {
21 22
22 void SendPostMessageToDocumentOnMainThread( 23 void SendPostMessageToDocumentOnMainThread(
23 ThreadSafeSender* sender, 24 ThreadSafeSender* sender,
(...skipping 18 matching lines...) Expand all
42 ServiceWorkerScriptContext::~ServiceWorkerScriptContext() {} 43 ServiceWorkerScriptContext::~ServiceWorkerScriptContext() {}
43 44
44 void ServiceWorkerScriptContext::OnMessageReceived( 45 void ServiceWorkerScriptContext::OnMessageReceived(
45 const IPC::Message& message) { 46 const IPC::Message& message) {
46 bool handled = true; 47 bool handled = true;
47 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext, message) 48 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext, message)
48 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent) 49 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent)
49 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent, OnFetchEvent) 50 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent, OnFetchEvent)
50 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) 51 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent)
51 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SyncEvent, OnSyncEvent) 52 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SyncEvent, OnSyncEvent)
53 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent)
52 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage) 54 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage)
53 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClientDocuments, 55 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClientDocuments,
54 OnDidGetClientDocuments) 56 OnDidGetClientDocuments)
55 IPC_MESSAGE_UNHANDLED(handled = false) 57 IPC_MESSAGE_UNHANDLED(handled = false)
56 IPC_END_MESSAGE_MAP() 58 IPC_END_MESSAGE_MAP()
57 DCHECK(handled); 59 DCHECK(handled);
58 } 60 }
59 61
60 void ServiceWorkerScriptContext::DidHandleActivateEvent( 62 void ServiceWorkerScriptContext::DidHandleActivateEvent(
61 int request_id, 63 int request_id,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 webRequest.setHeader(blink::WebString::fromUTF8(it->first), 135 webRequest.setHeader(blink::WebString::fromUTF8(it->first),
134 blink::WebString::fromUTF8(it->second)); 136 blink::WebString::fromUTF8(it->second));
135 } 137 }
136 proxy_->dispatchFetchEvent(request_id, webRequest); 138 proxy_->dispatchFetchEvent(request_id, webRequest);
137 } 139 }
138 140
139 void ServiceWorkerScriptContext::OnSyncEvent(int request_id) { 141 void ServiceWorkerScriptContext::OnSyncEvent(int request_id) {
140 proxy_->dispatchSyncEvent(request_id); 142 proxy_->dispatchSyncEvent(request_id);
141 } 143 }
142 144
145 void ServiceWorkerScriptContext::OnPushEvent(int request_id,
146 const std::string& data) {
147 proxy_->dispatchPushEvent(request_id, blink::WebString::fromUTF8(data));
148 Send(new ServiceWorkerHostMsg_PushEventFinished(
149 GetRoutingID(), request_id));
150 }
151
143 void ServiceWorkerScriptContext::OnPostMessage( 152 void ServiceWorkerScriptContext::OnPostMessage(
144 const base::string16& message, 153 const base::string16& message,
145 const std::vector<int>& sent_message_port_ids, 154 const std::vector<int>& sent_message_port_ids,
146 const std::vector<int>& new_routing_ids) { 155 const std::vector<int>& new_routing_ids) {
147 std::vector<WebMessagePortChannelImpl*> ports; 156 std::vector<WebMessagePortChannelImpl*> ports;
148 if (!sent_message_port_ids.empty()) { 157 if (!sent_message_port_ids.empty()) {
149 base::MessageLoopProxy* loop_proxy = embedded_context_->main_thread_proxy(); 158 base::MessageLoopProxy* loop_proxy = embedded_context_->main_thread_proxy();
150 ports.resize(sent_message_port_ids.size()); 159 ports.resize(sent_message_port_ids.size());
151 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { 160 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) {
152 ports[i] = new WebMessagePortChannelImpl( 161 ports[i] = new WebMessagePortChannelImpl(
(...skipping 17 matching lines...) Expand all
170 info->clientIDs = client_ids; 179 info->clientIDs = client_ids;
171 callbacks->onSuccess(info.release()); 180 callbacks->onSuccess(info.release());
172 pending_clients_callbacks_.Remove(request_id); 181 pending_clients_callbacks_.Remove(request_id);
173 } 182 }
174 183
175 int ServiceWorkerScriptContext::GetRoutingID() const { 184 int ServiceWorkerScriptContext::GetRoutingID() const {
176 return embedded_context_->embedded_worker_id(); 185 return embedded_context_->embedded_worker_id();
177 } 186 }
178 187
179 } // namespace content 188 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/service_worker/service_worker_script_context.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698