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

Side by Side Diff: content/browser/navigator_connect/navigator_connect_dispatcher_host.cc

Issue 785133006: Enable messaging over a navigator.connect initiated channel. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@navigator-connect_serviceside
Patch Set: comments Created 6 years 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 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/browser/navigator_connect/navigator_connect_dispatcher_host.h" 5 #include "content/browser/navigator_connect/navigator_connect_dispatcher_host.h"
6 6
7 #include "content/browser/message_port_service.h" 7 #include "content/browser/message_port_service.h"
8 #include "content/browser/navigator_connect/navigator_connect_context.h"
8 #include "content/browser/service_worker/service_worker_context_wrapper.h" 9 #include "content/browser/service_worker/service_worker_context_wrapper.h"
9 #include "content/common/navigator_connect_messages.h" 10 #include "content/common/navigator_connect_messages.h"
10 #include "content/common/navigator_connect_types.h" 11 #include "content/common/navigator_connect_types.h"
11 12
12 namespace content { 13 namespace content {
13 14
14 NavigatorConnectDispatcherHost::NavigatorConnectDispatcherHost( 15 NavigatorConnectDispatcherHost::NavigatorConnectDispatcherHost(
15 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) 16 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context,
17 const scoped_refptr<NavigatorConnectContext>& navigator_connect_context)
16 : BrowserMessageFilter(NavigatorConnectMsgStart), 18 : BrowserMessageFilter(NavigatorConnectMsgStart),
17 service_worker_context_(service_worker_context) { 19 service_worker_context_(service_worker_context),
20 navigator_connect_context_(navigator_connect_context) {
18 } 21 }
19 22
20 NavigatorConnectDispatcherHost::~NavigatorConnectDispatcherHost() { 23 NavigatorConnectDispatcherHost::~NavigatorConnectDispatcherHost() {
21 } 24 }
22 25
23 bool NavigatorConnectDispatcherHost::OnMessageReceived( 26 bool NavigatorConnectDispatcherHost::OnMessageReceived(
24 const IPC::Message& message) { 27 const IPC::Message& message) {
25 bool handled = true; 28 bool handled = true;
26 IPC_BEGIN_MESSAGE_MAP(NavigatorConnectDispatcherHost, message) 29 IPC_BEGIN_MESSAGE_MAP(NavigatorConnectDispatcherHost, message)
27 IPC_MESSAGE_HANDLER(NavigatorConnectHostMsg_Connect, OnConnect) 30 IPC_MESSAGE_HANDLER(NavigatorConnectHostMsg_Connect, OnConnect)
28 IPC_MESSAGE_UNHANDLED(handled = false) 31 IPC_MESSAGE_UNHANDLED(handled = false)
29 IPC_END_MESSAGE_MAP() 32 IPC_END_MESSAGE_MAP()
30 return handled; 33 return handled;
31 } 34 }
32 35
33 void NavigatorConnectDispatcherHost::OnConnect( 36 void NavigatorConnectDispatcherHost::OnConnect(
34 int thread_id, 37 int thread_id,
35 int request_id, 38 int request_id,
36 const CrossOriginServiceWorkerClient& client) { 39 const CrossOriginServiceWorkerClient& client) {
37 DCHECK_CURRENTLY_ON(BrowserThread::IO); 40 DCHECK_CURRENTLY_ON(BrowserThread::IO);
38 41
39 // Hold messages for port while setting up connection. 42 // Hold messages for port while setting up connection.
40 MessagePortService::GetInstance()->HoldMessages(client.message_port_id); 43 MessagePortService::GetInstance()->HoldMessages(client.message_port_id);
scheib 2014/12/18 00:24:10 What sanitizing / protection from a rogue Renderer
Marijn Kruisselbrink 2014/12/19 00:09:21 There are much easier ways a compromised renderer
41 44
42 // Find the right service worker to service this connection. 45 // Find the right service worker to service this connection.
43 service_worker_context_->context()->storage()->FindRegistrationForDocument( 46 service_worker_context_->context()->storage()->FindRegistrationForDocument(
44 client.target_url, 47 client.target_url,
45 base::Bind(&NavigatorConnectDispatcherHost::GotServiceWorkerRegistration, 48 base::Bind(&NavigatorConnectDispatcherHost::GotServiceWorkerRegistration,
46 this, thread_id, request_id, client)); 49 this, thread_id, request_id, client));
47 } 50 }
48 51
49 void NavigatorConnectDispatcherHost::GotServiceWorkerRegistration( 52 void NavigatorConnectDispatcherHost::GotServiceWorkerRegistration(
50 int thread_id, 53 int thread_id,
(...skipping 28 matching lines...) Expand all
79 const CrossOriginServiceWorkerClient& client, 82 const CrossOriginServiceWorkerClient& client,
80 const scoped_refptr<ServiceWorkerRegistration>& registration, 83 const scoped_refptr<ServiceWorkerRegistration>& registration,
81 ServiceWorkerStatusCode status, 84 ServiceWorkerStatusCode status,
82 bool accept_connection) { 85 bool accept_connection) {
83 DCHECK_CURRENTLY_ON(BrowserThread::IO); 86 DCHECK_CURRENTLY_ON(BrowserThread::IO);
84 87
85 if (status != SERVICE_WORKER_OK || !accept_connection) { 88 if (status != SERVICE_WORKER_OK || !accept_connection) {
86 // Close port since connection failed. 89 // Close port since connection failed.
87 MessagePortService::GetInstance()->ClosePort(client.message_port_id); 90 MessagePortService::GetInstance()->ClosePort(client.message_port_id);
88 Send(new NavigatorConnectMsg_ConnectResult(thread_id, request_id, false)); 91 Send(new NavigatorConnectMsg_ConnectResult(thread_id, request_id, false));
89 } else { 92 return;
90 // TODO(mek): Update MessagePortService to make communication between client
91 // and service possible.
92 Send(new NavigatorConnectMsg_ConnectResult(thread_id, request_id, true));
93 } 93 }
94
95 // Register connection and post back result.
96 navigator_connect_context_->RegisterConnection(client, registration);
97 Send(new NavigatorConnectMsg_ConnectResult(thread_id, request_id, true));
94 } 98 }
95 99
96 } // namespace content 100 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698