summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormek <mek@chromium.org>2015-07-17 15:45:07 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-17 22:45:39 +0000
commitef0b94c53140a46f65c8233c7833b0bacd789792 (patch)
tree1919dee72a4194c9cb0ed7b7b3203fc0d478a99c
parent673add86a33e1cd0c753030f9ff5faa5b11a39bc (diff)
downloadchromium_src-ef0b94c53140a46f65c8233c7833b0bacd789792.zip
chromium_src-ef0b94c53140a46f65c8233c7833b0bacd789792.tar.gz
chromium_src-ef0b94c53140a46f65c8233c7833b0bacd789792.tar.bz2
Update navigator.services API to use the new services.onconnect event [2/3].
This is part of a series of patches to change the service side API from a global oncrossoriginconnect event to a new navigator.services.onconnect event. This patch builds on https://codereview.chromium.org/1221503003 to setup a mojo service in the worker thread in the renderer which is used to dispatch the new event to blink. [1/3] https://codereview.chromium.org/1210633002 Adds new event to blink. [2/3] This patch [3/3] https://codereview.chromium.org/1205783004 Removes old event from blink and adds some tests specific to the new event. BUG=426458 Review URL: https://codereview.chromium.org/1210643002 Cr-Commit-Position: refs/heads/master@{#339347}
-rw-r--r--content/browser/navigator_connect/navigator_connect_service_worker_service_factory.cc16
-rw-r--r--content/browser/navigator_connect/navigator_connect_service_worker_service_factory.h7
-rw-r--r--content/browser/service_worker/service_worker_version.cc88
-rw-r--r--content/browser/service_worker/service_worker_version.h37
-rw-r--r--content/child/navigator_connect/service_port_dispatcher_impl.cc78
-rw-r--r--content/child/navigator_connect/service_port_dispatcher_impl.h55
-rw-r--r--content/common/service_port_service.mojom5
-rw-r--r--content/common/service_worker/service_worker_messages.h6
-rw-r--r--content/content_child.gypi2
-rw-r--r--content/renderer/service_worker/service_worker_context_client.cc30
-rw-r--r--content/renderer/service_worker/service_worker_context_client.h4
11 files changed, 245 insertions, 83 deletions
diff --git a/content/browser/navigator_connect/navigator_connect_service_worker_service_factory.cc b/content/browser/navigator_connect/navigator_connect_service_worker_service_factory.cc
index 17ee080..36f4ed4 100644
--- a/content/browser/navigator_connect/navigator_connect_service_worker_service_factory.cc
+++ b/content/browser/navigator_connect/navigator_connect_service_worker_service_factory.cc
@@ -156,24 +156,25 @@ void NavigatorConnectServiceWorkerServiceFactory::GotServiceWorkerRegistration(
ServiceWorkerStatusCode status,
const scoped_refptr<ServiceWorkerRegistration>& registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
-
if (status != SERVICE_WORKER_OK) {
// No service worker found, reject connection attempt.
- OnConnectResult(callback, client, registration, status, false);
+ OnConnectResult(callback, client, registration, status, false,
+ base::string16(), base::string16());
return;
}
ServiceWorkerVersion* active_version = registration->active_version();
if (!active_version) {
// No active version, reject connection attempt.
- OnConnectResult(callback, client, registration, status, false);
+ OnConnectResult(callback, client, registration, status, false,
+ base::string16(), base::string16());
return;
}
- active_version->DispatchCrossOriginConnectEvent(
+ active_version->DispatchServicePortConnectEvent(
base::Bind(&NavigatorConnectServiceWorkerServiceFactory::OnConnectResult,
weak_factory_.GetWeakPtr(), callback, client, registration),
- client);
+ client.target_url, client.origin, client.message_port_id);
}
void NavigatorConnectServiceWorkerServiceFactory::OnConnectResult(
@@ -181,7 +182,9 @@ void NavigatorConnectServiceWorkerServiceFactory::OnConnectResult(
const NavigatorConnectClient& client,
const scoped_refptr<ServiceWorkerRegistration>& service_worker_registration,
ServiceWorkerStatusCode status,
- bool accept_connection) {
+ bool accept_connection,
+ const base::string16& name,
+ const base::string16& data) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (status != SERVICE_WORKER_OK || !accept_connection) {
@@ -189,6 +192,7 @@ void NavigatorConnectServiceWorkerServiceFactory::OnConnectResult(
return;
}
+ // TODO(mek): Keep track of name and data for this port.
// TODO(mek): http://crbug.com/462744 Keep track of these
// NavigatorConnectServiceWorkerService instances and clean them up when a
// service worker registration is deleted.
diff --git a/content/browser/navigator_connect/navigator_connect_service_worker_service_factory.h b/content/browser/navigator_connect/navigator_connect_service_worker_service_factory.h
index 4e0239f..cd935fb 100644
--- a/content/browser/navigator_connect/navigator_connect_service_worker_service_factory.h
+++ b/content/browser/navigator_connect/navigator_connect_service_worker_service_factory.h
@@ -8,6 +8,7 @@
#include <map>
#include "base/memory/weak_ptr.h"
+#include "base/strings/string16.h"
#include "content/common/service_worker/service_worker_status_code.h"
#include "content/public/browser/navigator_connect_service_factory.h"
@@ -42,14 +43,16 @@ class NavigatorConnectServiceWorkerServiceFactory
ServiceWorkerStatusCode status,
const scoped_refptr<ServiceWorkerRegistration>& registration);
- // Callback called when the service worker finished handling the cross origin
+ // Callback called when the service worker finished handling the service port
// connection event.
void OnConnectResult(
const ConnectCallback& callback,
const NavigatorConnectClient& client,
const scoped_refptr<ServiceWorkerRegistration>& registration,
ServiceWorkerStatusCode status,
- bool accept_connection);
+ bool accept_connection,
+ const base::string16& name,
+ const base::string16& data);
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
base::WeakPtrFactory<NavigatorConnectServiceWorkerServiceFactory>
diff --git a/content/browser/service_worker/service_worker_version.cc b/content/browser/service_worker/service_worker_version.cc
index f225a9b..4b24f21 100644
--- a/content/browser/service_worker/service_worker_version.cc
+++ b/content/browser/service_worker/service_worker_version.cc
@@ -42,6 +42,8 @@
#include "content/public/common/content_client.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/result_codes.h"
+#include "mojo/common/common_type_converters.h"
+#include "mojo/common/url_type_converters.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_response_info.h"
@@ -165,10 +167,11 @@ void RunErrorMessageCallback(
callback.Run(status);
}
-void RunErrorCrossOriginConnectCallback(
- const ServiceWorkerVersion::CrossOriginConnectCallback& callback,
+void RunErrorServicePortConnectCallback(
+ const ServiceWorkerVersion::ServicePortConnectCallback& callback,
ServiceWorkerStatusCode status) {
- callback.Run(status, false /* accept_connection */);
+ callback.Run(status, false /* accept_connection */, base::string16(),
+ base::string16());
}
void RunErrorSendStashedPortsCallback(
@@ -894,14 +897,17 @@ void ServiceWorkerVersion::DispatchGeofencingEvent(
}
}
-void ServiceWorkerVersion::DispatchCrossOriginConnectEvent(
- const CrossOriginConnectCallback& callback,
- const NavigatorConnectClient& client) {
+void ServiceWorkerVersion::DispatchServicePortConnectEvent(
+ const ServicePortConnectCallback& callback,
+ const GURL& target_url,
+ const GURL& origin,
+ int port_id) {
DCHECK_EQ(ACTIVATED, status()) << status();
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableExperimentalWebPlatformFeatures)) {
- callback.Run(SERVICE_WORKER_ERROR_ABORT, false);
+ callback.Run(SERVICE_WORKER_ERROR_ABORT, false, base::string16(),
+ base::string16());
return;
}
@@ -909,20 +915,26 @@ void ServiceWorkerVersion::DispatchCrossOriginConnectEvent(
// Schedule calling this method after starting the worker.
StartWorker(
base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(),
- base::Bind(&RunErrorCrossOriginConnectCallback, callback),
- base::Bind(&self::DispatchCrossOriginConnectEvent,
- weak_factory_.GetWeakPtr(), callback, client)));
+ base::Bind(&RunErrorServicePortConnectCallback, callback),
+ base::Bind(&self::DispatchServicePortConnectEvent,
+ weak_factory_.GetWeakPtr(), callback, target_url,
+ origin, port_id)));
return;
}
- int request_id = AddRequest(callback, &cross_origin_connect_requests_,
- REQUEST_CROSS_ORIGIN_CONNECT);
- ServiceWorkerStatusCode status = embedded_worker_->SendMessage(
- ServiceWorkerMsg_CrossOriginConnectEvent(request_id, client));
- if (status != SERVICE_WORKER_OK) {
- cross_origin_connect_requests_.Remove(request_id);
- RunSoon(base::Bind(callback, status, false));
+ int request_id = AddRequest(callback, &service_port_connect_requests_,
+ REQUEST_SERVICE_PORT_CONNECT);
+ if (!service_port_dispatcher_) {
+ embedded_worker_->GetServiceRegistry()->ConnectToRemoteService(
+ mojo::GetProxy(&service_port_dispatcher_));
+ service_port_dispatcher_.set_connection_error_handler(base::Bind(
+ &ServiceWorkerVersion::OnServicePortDispatcherConnectionError,
+ weak_factory_.GetWeakPtr()));
}
+ service_port_dispatcher_->Connect(
+ mojo::String::From(target_url), mojo::String::From(origin), port_id,
+ base::Bind(&ServiceWorkerVersion::OnServicePortConnectEventFinished,
+ weak_factory_.GetWeakPtr(), request_id));
}
void ServiceWorkerVersion::DispatchCrossOriginMessageEvent(
@@ -1203,8 +1215,6 @@ bool ServiceWorkerVersion::OnMessageReceived(const IPC::Message& message) {
OnPushEventFinished)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GeofencingEventFinished,
OnGeofencingEventFinished)
- IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CrossOriginConnectEventFinished,
- OnCrossOriginConnectEventFinished)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow,
OnOpenWindow)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetCachedMetadata,
@@ -1462,22 +1472,26 @@ void ServiceWorkerVersion::OnGeofencingEventFinished(int request_id) {
RemoveCallbackAndStopIfRedundant(&geofencing_requests_, request_id);
}
-void ServiceWorkerVersion::OnCrossOriginConnectEventFinished(
+void ServiceWorkerVersion::OnServicePortConnectEventFinished(
int request_id,
- bool accept_connection) {
+ ServicePortConnectResult result,
+ const mojo::String& name,
+ const mojo::String& data) {
TRACE_EVENT1("ServiceWorker",
- "ServiceWorkerVersion::OnCrossOriginConnectEventFinished",
+ "ServiceWorkerVersion::OnServicePortConnectEventFinished",
"Request id", request_id);
- PendingRequest<CrossOriginConnectCallback>* request =
- cross_origin_connect_requests_.Lookup(request_id);
+ PendingRequest<ServicePortConnectCallback>* request =
+ service_port_connect_requests_.Lookup(request_id);
if (!request) {
NOTREACHED() << "Got unexpected message: " << request_id;
return;
}
scoped_refptr<ServiceWorkerVersion> protect(this);
- request->callback.Run(SERVICE_WORKER_OK, accept_connection);
- RemoveCallbackAndStopIfRedundant(&cross_origin_connect_requests_, request_id);
+ request->callback.Run(SERVICE_WORKER_OK,
+ result == SERVICE_PORT_CONNECT_RESULT_ACCEPT,
+ name.To<base::string16>(), data.To<base::string16>());
+ RemoveCallbackAndStopIfRedundant(&service_port_connect_requests_, request_id);
}
void ServiceWorkerVersion::OnOpenWindow(int request_id, GURL url) {
@@ -1980,7 +1994,7 @@ bool ServiceWorkerVersion::HasInflightRequests() const {
!fetch_requests_.IsEmpty() || !sync_requests_.IsEmpty() ||
!notification_click_requests_.IsEmpty() || !push_requests_.IsEmpty() ||
!geofencing_requests_.IsEmpty() ||
- !cross_origin_connect_requests_.IsEmpty() ||
+ !service_port_connect_requests_.IsEmpty() ||
!streaming_url_request_jobs_.empty();
}
@@ -2071,10 +2085,11 @@ bool ServiceWorkerVersion::OnRequestTimeout(const RequestInfo& info) {
case REQUEST_GEOFENCING:
return RunIDMapCallback(&geofencing_requests_, info.id,
SERVICE_WORKER_ERROR_TIMEOUT);
- case REQUEST_CROSS_ORIGIN_CONNECT:
- return RunIDMapCallback(&cross_origin_connect_requests_, info.id,
+ case REQUEST_SERVICE_PORT_CONNECT:
+ return RunIDMapCallback(&service_port_connect_requests_, info.id,
SERVICE_WORKER_ERROR_TIMEOUT,
- false /* accept_connection */);
+ false /* accept_connection */, base::string16(),
+ base::string16());
}
NOTREACHED() << "Got unexpected request type: " << info.type;
return false;
@@ -2191,8 +2206,10 @@ void ServiceWorkerVersion::OnStoppedInternal(
RunIDMapCallbacks(&notification_click_requests_, SERVICE_WORKER_ERROR_FAILED);
RunIDMapCallbacks(&push_requests_, SERVICE_WORKER_ERROR_FAILED);
RunIDMapCallbacks(&geofencing_requests_, SERVICE_WORKER_ERROR_FAILED);
- RunIDMapCallbacks(&cross_origin_connect_requests_,
- SERVICE_WORKER_ERROR_FAILED, false);
+
+ // Close all mojo services. This will also fire and clear all callbacks
+ // for messages that are still outstanding for those services.
+ OnServicePortDispatcherConnectionError();
streaming_url_request_jobs_.clear();
@@ -2202,4 +2219,11 @@ void ServiceWorkerVersion::OnStoppedInternal(
StartWorkerInternal();
}
+void ServiceWorkerVersion::OnServicePortDispatcherConnectionError() {
+ RunIDMapCallbacks(&service_port_connect_requests_,
+ SERVICE_WORKER_ERROR_FAILED, false, base::string16(),
+ base::string16());
+ service_port_dispatcher_.reset();
+}
+
} // namespace content
diff --git a/content/browser/service_worker/service_worker_version.h b/content/browser/service_worker/service_worker_version.h
index deb22aa..47114dc 100644
--- a/content/browser/service_worker/service_worker_version.h
+++ b/content/browser/service_worker/service_worker_version.h
@@ -22,8 +22,10 @@
#include "content/browser/service_worker/embedded_worker_instance.h"
#include "content/browser/service_worker/service_worker_script_cache_map.h"
#include "content/common/content_export.h"
+#include "content/common/service_port_service.mojom.h"
#include "content/common/service_worker/service_worker_status_code.h"
#include "content/common/service_worker/service_worker_types.h"
+#include "content/public/common/service_registry.h"
#include "third_party/WebKit/public/platform/WebGeofencingEventType.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h"
@@ -69,8 +71,10 @@ class CONTENT_EXPORT ServiceWorkerVersion
ServiceWorkerFetchEventResult,
const ServiceWorkerResponse&)> FetchCallback;
typedef base::Callback<void(ServiceWorkerStatusCode,
- bool /* accept_connction */)>
- CrossOriginConnectCallback;
+ bool /* accept_connction */,
+ const base::string16& /* name */,
+ const base::string16& /* data */)>
+ ServicePortConnectCallback;
typedef base::Callback<void(ServiceWorkerStatusCode, const std::vector<int>&)>
SendStashedPortsCallback;
@@ -237,13 +241,15 @@ class CONTENT_EXPORT ServiceWorkerVersion
const std::string& region_id,
const blink::WebCircularGeofencingRegion& region);
- // Sends a cross origin connect event to the associated embedded worker and
+ // Sends a ServicePort connect event to the associated embedded worker and
// asynchronously calls |callback| with the response from the worker.
//
// This must be called when the status() is ACTIVATED.
- void DispatchCrossOriginConnectEvent(
- const CrossOriginConnectCallback& callback,
- const NavigatorConnectClient& client);
+ void DispatchServicePortConnectEvent(
+ const ServicePortConnectCallback& callback,
+ const GURL& target_url,
+ const GURL& origin,
+ int port_id);
// Sends a cross origin message event to the associated embedded worker and
// asynchronously calls |callback| when the message was sent (or failed to
@@ -364,7 +370,7 @@ class CONTENT_EXPORT ServiceWorkerVersion
REQUEST_NOTIFICATION_CLICK,
REQUEST_PUSH,
REQUEST_GEOFENCING,
- REQUEST_CROSS_ORIGIN_CONNECT
+ REQUEST_SERVICE_PORT_CONNECT
};
struct RequestInfo {
@@ -438,8 +444,10 @@ class CONTENT_EXPORT ServiceWorkerVersion
void OnPushEventFinished(int request_id,
blink::WebServiceWorkerEventResult result);
void OnGeofencingEventFinished(int request_id);
- void OnCrossOriginConnectEventFinished(int request_id,
- bool accept_connection);
+ void OnServicePortConnectEventFinished(int request_id,
+ ServicePortConnectResult result,
+ const mojo::String& name,
+ const mojo::String& data);
void OnOpenWindow(int request_id, GURL url);
void DidOpenWindow(int request_id,
int render_process_id,
@@ -533,6 +541,11 @@ class CONTENT_EXPORT ServiceWorkerVersion
void OnStoppedInternal(EmbeddedWorkerInstance::Status old_status);
+ // Called when the connection to a ServicePortDispatcher drops or fails.
+ // Calls callbacks for any outstanding requests to the dispatcher as well
+ // as cleans up the dispatcher.
+ void OnServicePortDispatcherConnectionError();
+
const int64 version_id_;
const int64 registration_id_;
const GURL script_url_;
@@ -554,8 +567,10 @@ class CONTENT_EXPORT ServiceWorkerVersion
notification_click_requests_;
IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> push_requests_;
IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> geofencing_requests_;
- IDMap<PendingRequest<CrossOriginConnectCallback>, IDMapOwnPointer>
- cross_origin_connect_requests_;
+ IDMap<PendingRequest<ServicePortConnectCallback>, IDMapOwnPointer>
+ service_port_connect_requests_;
+
+ ServicePortDispatcherPtr service_port_dispatcher_;
std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_;
diff --git a/content/child/navigator_connect/service_port_dispatcher_impl.cc b/content/child/navigator_connect/service_port_dispatcher_impl.cc
new file mode 100644
index 0000000..adb2981
--- /dev/null
+++ b/content/child/navigator_connect/service_port_dispatcher_impl.cc
@@ -0,0 +1,78 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/child/navigator_connect/service_port_dispatcher_impl.h"
+
+#include "base/trace_event/trace_event.h"
+#include "mojo/common/common_type_converters.h"
+#include "mojo/common/url_type_converters.h"
+#include "third_party/WebKit/public/web/WebServiceWorkerContextProxy.h"
+
+namespace content {
+
+namespace {
+
+class WebConnectCallbacksImpl
+ : public blink::WebServicePortConnectEventCallbacks {
+ public:
+ WebConnectCallbacksImpl(
+ const ServicePortDispatcher::ConnectCallback& callback)
+ : callback_(callback) {}
+
+ ~WebConnectCallbacksImpl() override {}
+
+ void onSuccess(blink::WebServicePort* port) override {
+ callback_.Run(SERVICE_PORT_CONNECT_RESULT_ACCEPT,
+ mojo::String::From<base::string16>(port->name),
+ mojo::String::From<base::string16>(port->data));
+ }
+
+ void onError() override {
+ callback_.Run(SERVICE_PORT_CONNECT_RESULT_REJECT, mojo::String(""),
+ mojo::String(""));
+ }
+
+ private:
+ ServicePortDispatcher::ConnectCallback callback_;
+};
+
+} // namespace
+
+void ServicePortDispatcherImpl::Create(
+ base::WeakPtr<blink::WebServiceWorkerContextProxy> proxy,
+ mojo::InterfaceRequest<ServicePortDispatcher> request) {
+ new ServicePortDispatcherImpl(proxy, request.Pass());
+}
+
+ServicePortDispatcherImpl::~ServicePortDispatcherImpl() {
+ WorkerTaskRunner::Instance()->RemoveStopObserver(this);
+}
+
+ServicePortDispatcherImpl::ServicePortDispatcherImpl(
+ base::WeakPtr<blink::WebServiceWorkerContextProxy> proxy,
+ mojo::InterfaceRequest<ServicePortDispatcher> request)
+ : binding_(this, request.Pass()), proxy_(proxy) {
+ WorkerTaskRunner::Instance()->AddStopObserver(this);
+}
+
+void ServicePortDispatcherImpl::OnWorkerRunLoopStopped() {
+ delete this;
+}
+
+void ServicePortDispatcherImpl::Connect(const mojo::String& target_url,
+ const mojo::String& origin,
+ int32_t port_id,
+ const ConnectCallback& callback) {
+ if (!proxy_) {
+ callback.Run(SERVICE_PORT_CONNECT_RESULT_REJECT, mojo::String(""),
+ mojo::String(""));
+ return;
+ }
+ TRACE_EVENT0("ServiceWorker", "ServicePortDispatcherImpl::Connect");
+ proxy_->dispatchServicePortConnectEvent(new WebConnectCallbacksImpl(callback),
+ target_url.To<GURL>(),
+ origin.To<base::string16>(), port_id);
+}
+
+} // namespace content
diff --git a/content/child/navigator_connect/service_port_dispatcher_impl.h b/content/child/navigator_connect/service_port_dispatcher_impl.h
new file mode 100644
index 0000000..079e077
--- /dev/null
+++ b/content/child/navigator_connect/service_port_dispatcher_impl.h
@@ -0,0 +1,55 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_CHILD_NAVIGATOR_CONNECT_SERVICE_PORT_DISPATCHER_IMPL_H_
+#define CONTENT_CHILD_NAVIGATOR_CONNECT_SERVICE_PORT_DISPATCHER_IMPL_H_
+
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "content/child/worker_task_runner.h"
+#include "content/common/service_port_service.mojom.h"
+#include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
+
+namespace blink {
+class WebServiceWorkerContextProxy;
+}
+
+namespace content {
+
+// Mojo service that dispatches ServicePort related events to a service worker.
+// Instances are always created on a worker thread, and all methods are only
+// called on that same thread. Lifetime of this class is tied to both the mojo
+// channel and the lifetime of the worker thread. If either the channel is
+// disconnected or the worker thread stops the instance deletes itself.
+class ServicePortDispatcherImpl : public ServicePortDispatcher,
+ public WorkerTaskRunner::Observer {
+ public:
+ static void Create(base::WeakPtr<blink::WebServiceWorkerContextProxy> proxy,
+ mojo::InterfaceRequest<ServicePortDispatcher> request);
+
+ ~ServicePortDispatcherImpl() override;
+
+ private:
+ ServicePortDispatcherImpl(
+ base::WeakPtr<blink::WebServiceWorkerContextProxy> proxy,
+ mojo::InterfaceRequest<ServicePortDispatcher> request);
+
+ // WorkerTaskRunner::Observer implementation.
+ void OnWorkerRunLoopStopped() override;
+
+ // ServicePortDispatcher implementation.
+ void Connect(const mojo::String& target_url,
+ const mojo::String& origin,
+ int32_t port_id,
+ const ConnectCallback& callback) override;
+
+ mojo::StrongBinding<ServicePortDispatcher> binding_;
+ base::WeakPtr<blink::WebServiceWorkerContextProxy> proxy_;
+
+ DISALLOW_COPY_AND_ASSIGN(ServicePortDispatcherImpl);
+};
+
+} // namespace content
+
+#endif // CONTENT_CHILD_NAVIGATOR_CONNECT_SERVICE_PORT_DISPATCHER_IMPL_H_
diff --git a/content/common/service_port_service.mojom b/content/common/service_port_service.mojom
index 116194d..41cee6a 100644
--- a/content/common/service_port_service.mojom
+++ b/content/common/service_port_service.mojom
@@ -30,3 +30,8 @@ interface ServicePortServiceClient {
array<MojoTransferredMessagePort> ports,
array<int32> new_routing_ids);
};
+
+interface ServicePortDispatcher {
+ Connect(string target_url, string origin, int32 port_id)
+ => (ServicePortConnectResult result, string name, string data);
+};
diff --git a/content/common/service_worker/service_worker_messages.h b/content/common/service_worker/service_worker_messages.h
index ad15ed1..571536b 100644
--- a/content/common/service_worker/service_worker_messages.h
+++ b/content/common/service_worker/service_worker_messages.h
@@ -238,9 +238,6 @@ IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_PushEventFinished,
blink::WebServiceWorkerEventResult)
IPC_MESSAGE_ROUTED1(ServiceWorkerHostMsg_GeofencingEventFinished,
int /* request_id */)
-IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_CrossOriginConnectEventFinished,
- int /* request_id */,
- bool /* accept_connection */)
// Responds to a Ping from the browser.
// Routed to the target ServiceWorkerVersion.
@@ -439,9 +436,6 @@ IPC_MESSAGE_CONTROL4(ServiceWorkerMsg_GeofencingEvent,
blink::WebGeofencingEventType /* event_type */,
std::string /* region_id */,
blink::WebCircularGeofencingRegion /* region */)
-IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CrossOriginConnectEvent,
- int /* request_id */,
- content::NavigatorConnectClient /* client */)
IPC_MESSAGE_CONTROL3(
ServiceWorkerMsg_MessageToWorker,
base::string16 /* message */,
diff --git a/content/content_child.gypi b/content/content_child.gypi
index b5a7e38..0f6b009 100644
--- a/content/content_child.gypi
+++ b/content/content_child.gypi
@@ -122,6 +122,8 @@
'child/mojo/mojo_application.h',
'child/multipart_response_delegate.cc',
'child/multipart_response_delegate.h',
+ 'child/navigator_connect/service_port_dispatcher_impl.cc',
+ 'child/navigator_connect/service_port_dispatcher_impl.h',
'child/navigator_connect/service_port_provider.cc',
'child/navigator_connect/service_port_provider.h',
'child/notifications/notification_data_conversions.cc',
diff --git a/content/renderer/service_worker/service_worker_context_client.cc b/content/renderer/service_worker/service_worker_context_client.cc
index 85b79ac..1b65fe1 100644
--- a/content/renderer/service_worker/service_worker_context_client.cc
+++ b/content/renderer/service_worker/service_worker_context_client.cc
@@ -12,6 +12,7 @@
#include "base/threading/thread_checker.h"
#include "base/threading/thread_local.h"
#include "base/trace_event/trace_event.h"
+#include "content/child/navigator_connect/service_port_dispatcher_impl.h"
#include "content/child/notifications/notification_data_conversions.h"
#include "content/child/request_extra_data.h"
#include "content/child/service_worker/service_worker_dispatcher.h"
@@ -181,7 +182,7 @@ struct ServiceWorkerContextClient::WorkerContextData {
IDMap<blink::WebServiceWorkerSkipWaitingCallbacks, IDMapOwnPointer>;
explicit WorkerContextData(ServiceWorkerContextClient* owner)
- : weak_factory(owner) {}
+ : weak_factory(owner), proxy_weak_factory(owner->proxy_) {}
~WorkerContextData() {
DCHECK(thread_checker.CalledOnValidThread());
@@ -203,6 +204,7 @@ struct ServiceWorkerContextClient::WorkerContextData {
base::ThreadChecker thread_checker;
base::WeakPtrFactory<ServiceWorkerContextClient> weak_factory;
+ base::WeakPtrFactory<blink::WebServiceWorkerContextProxy> proxy_weak_factory;
};
ServiceWorkerContextClient*
@@ -251,8 +253,6 @@ void ServiceWorkerContextClient::OnMessageReceived(
OnNotificationClickEvent)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent)
- IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginConnectEvent,
- OnCrossOriginConnectEvent)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker,
OnCrossOriginMessageToWorker)
@@ -349,6 +349,11 @@ void ServiceWorkerContextClient::workerContextStarted(
// willDestroyWorkerContext.
context_.reset(new WorkerContextData(this));
+ // Register Mojo services.
+ context_->service_registry.ServiceRegistry::AddService(
+ base::Bind(&ServicePortDispatcherImpl::Create,
+ context_->proxy_weak_factory.GetWeakPtr()));
+
SetRegistrationInServiceWorkerGlobalScope();
Send(new EmbeddedWorkerHostMsg_WorkerScriptLoaded(
@@ -497,13 +502,6 @@ void ServiceWorkerContextClient::didHandleSyncEvent(
result));
}
-void ServiceWorkerContextClient::didHandleCrossOriginConnectEvent(
- int request_id,
- bool accept_connection) {
- Send(new ServiceWorkerHostMsg_CrossOriginConnectEventFinished(
- GetRoutingID(), request_id, accept_connection));
-}
-
blink::WebServiceWorkerNetworkProvider*
ServiceWorkerContextClient::createServiceWorkerNetworkProvider(
blink::WebDataSource* data_source) {
@@ -736,18 +734,6 @@ void ServiceWorkerContextClient::OnGeofencingEvent(
request_id));
}
-void ServiceWorkerContextClient::OnCrossOriginConnectEvent(
- int request_id,
- const NavigatorConnectClient& client) {
- TRACE_EVENT0("ServiceWorker",
- "ServiceWorkerContextClient::OnCrossOriginConnectEvent");
- blink::WebCrossOriginServiceWorkerClient web_client;
- web_client.origin = client.origin;
- web_client.targetURL = client.target_url;
- web_client.clientID = client.message_port_id;
- proxy_->dispatchCrossOriginConnectEvent(request_id, web_client);
-}
-
void ServiceWorkerContextClient::OnPostMessage(
const base::string16& message,
const std::vector<TransferredMessagePort>& sent_message_ports,
diff --git a/content/renderer/service_worker/service_worker_context_client.h b/content/renderer/service_worker/service_worker_context_client.h
index 970480d..f78758b 100644
--- a/content/renderer/service_worker/service_worker_context_client.h
+++ b/content/renderer/service_worker/service_worker_context_client.h
@@ -125,8 +125,6 @@ class ServiceWorkerContextClient
blink::WebServiceWorkerEventResult result);
virtual void didHandleSyncEvent(int request_id,
blink::WebServiceWorkerEventResult result);
- virtual void didHandleCrossOriginConnectEvent(int request_id,
- bool accept_connection);
// Called on the main thread.
virtual blink::WebServiceWorkerNetworkProvider*
@@ -173,8 +171,6 @@ class ServiceWorkerContextClient
blink::WebGeofencingEventType event_type,
const std::string& region_id,
const blink::WebCircularGeofencingRegion& region);
- void OnCrossOriginConnectEvent(int request_id,
- const NavigatorConnectClient& client);
void OnPostMessage(
const base::string16& message,
const std::vector<TransferredMessagePort>& sent_message_ports,