summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
Diffstat (limited to 'content')
-rw-r--r--content/browser/service_worker/service_worker_client_utils.cc70
-rw-r--r--content/browser/service_worker/service_worker_client_utils.h10
-rw-r--r--content/browser/service_worker/service_worker_provider_host.cc19
-rw-r--r--content/browser/service_worker/service_worker_provider_host.h6
-rw-r--r--content/browser/service_worker/service_worker_version.cc64
-rw-r--r--content/browser/service_worker/service_worker_version.h13
-rw-r--r--content/common/service_worker/service_worker_client_info.cc20
-rw-r--r--content/common/service_worker/service_worker_client_info.h5
-rw-r--r--content/common/service_worker/service_worker_messages.h10
-rw-r--r--content/renderer/service_worker/service_worker_context_client.cc36
-rw-r--r--content/renderer/service_worker/service_worker_context_client.h3
11 files changed, 181 insertions, 75 deletions
diff --git a/content/browser/service_worker/service_worker_client_utils.cc b/content/browser/service_worker/service_worker_client_utils.cc
index 26ef4d3..a7eb04f 100644
--- a/content/browser/service_worker/service_worker_client_utils.cc
+++ b/content/browser/service_worker/service_worker_client_utils.cc
@@ -176,15 +176,13 @@ void DidNavigate(const base::WeakPtr<ServiceWorkerContextCore>& context,
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!context) {
- callback.Run(SERVICE_WORKER_ERROR_ABORT, std::string(),
- ServiceWorkerClientInfo());
+ callback.Run(SERVICE_WORKER_ERROR_ABORT, ServiceWorkerClientInfo());
return;
}
if (render_process_id == ChildProcessHost::kInvalidUniqueID &&
render_frame_id == MSG_ROUTING_NONE) {
- callback.Run(SERVICE_WORKER_ERROR_FAILED, std::string(),
- ServiceWorkerClientInfo());
+ callback.Run(SERVICE_WORKER_ERROR_FAILED, ServiceWorkerClientInfo());
return;
}
@@ -196,14 +194,13 @@ void DidNavigate(const base::WeakPtr<ServiceWorkerContextCore>& context,
provider_host->frame_id() != render_frame_id) {
continue;
}
- provider_host->GetWindowClientInfo(
- base::Bind(callback, SERVICE_WORKER_OK, provider_host->client_uuid()));
+ provider_host->GetWindowClientInfo(base::Bind(callback, SERVICE_WORKER_OK));
return;
}
// If here, it means that no provider_host was found, in which case, the
// renderer should still be informed that the window was opened.
- callback.Run(SERVICE_WORKER_OK, std::string(), ServiceWorkerClientInfo());
+ callback.Run(SERVICE_WORKER_OK, ServiceWorkerClientInfo());
}
void AddWindowClient(
@@ -225,12 +222,11 @@ void AddNonWindowClient(ServiceWorkerProviderHost* host,
options.client_type != host_client_type)
return;
- ServiceWorkerClientInfo client_info(blink::WebPageVisibilityStateHidden,
- false, // is_focused
- host->document_url(),
- REQUEST_CONTEXT_FRAME_TYPE_NONE,
- base::TimeTicks(), host_client_type);
- client_info.client_uuid = host->client_uuid();
+ ServiceWorkerClientInfo client_info(
+ host->client_uuid(), blink::WebPageVisibilityStateHidden,
+ false, // is_focused
+ host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE, base::TimeTicks(),
+ host_client_type);
clients->push_back(client_info);
}
@@ -243,8 +239,8 @@ void OnGetWindowClientsOnUI(
for (const auto& it : clients_info) {
ServiceWorkerClientInfo info =
- ServiceWorkerProviderHost::GetWindowClientInfoOnUI(base::get<0>(it),
- base::get<1>(it));
+ ServiceWorkerProviderHost::GetWindowClientInfoOnUI(
+ base::get<0>(it), base::get<1>(it), base::get<2>(it));
// If the request to the provider_host returned an empty
// ServiceWorkerClientInfo, that means that it wasn't possible to associate
@@ -259,7 +255,6 @@ void OnGetWindowClientsOnUI(
if (info.url.GetOrigin() != script_url.GetOrigin())
continue;
- info.client_uuid = base::get<2>(it);
clients->push_back(info);
}
@@ -371,6 +366,49 @@ void NavigateClient(const GURL& url,
base::Bind(&DidNavigate, context, script_url.GetOrigin(), callback)));
}
+void GetClient(
+ const base::WeakPtr<ServiceWorkerVersion>& controller,
+ const std::string& client_uuid,
+ const base::WeakPtr<ServiceWorkerContextCore>& context,
+ const ServiceWorkerProviderHost::GetClientInfoCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ ServiceWorkerProviderHost* provider_host =
+ context->GetProviderHostByClientID(client_uuid);
+
+ if (!provider_host) {
+ // The client may already have been closed, just ignore.
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(callback, ServiceWorkerClientInfo()));
+ return;
+ }
+
+ if (provider_host->document_url().GetOrigin() !=
+ controller->script_url().GetOrigin()) {
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(callback, ServiceWorkerClientInfo()));
+ return;
+ }
+
+ if (provider_host->client_type() == blink::WebServiceWorkerClientTypeWindow) {
+ provider_host->GetWindowClientInfo(callback);
+ return;
+ }
+
+ DCHECK(provider_host->client_type() ==
+ blink::WebServiceWorkerClientTypeWorker ||
+ provider_host->client_type() ==
+ blink::WebServiceWorkerClientTypeSharedWorker);
+
+ ServiceWorkerClientInfo client_info(
+ provider_host->client_uuid(), blink::WebPageVisibilityStateHidden,
+ false, // is_focused
+ provider_host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE,
+ base::TimeTicks(), provider_host->client_type());
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(callback, client_info));
+}
+
void GetClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
const ServiceWorkerClientQueryOptions& options,
const ClientsCallback& callback) {
diff --git a/content/browser/service_worker/service_worker_client_utils.h b/content/browser/service_worker/service_worker_client_utils.h
index 258268e..c4bf312 100644
--- a/content/browser/service_worker/service_worker_client_utils.h
+++ b/content/browser/service_worker/service_worker_client_utils.h
@@ -10,6 +10,7 @@
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
+#include "content/browser/service_worker/service_worker_provider_host.h"
#include "content/common/service_worker/service_worker_status_code.h"
class GURL;
@@ -25,7 +26,6 @@ namespace service_worker_client_utils {
using NavigationCallback =
base::Callback<void(ServiceWorkerStatusCode status,
- const std::string& client_uuid,
const ServiceWorkerClientInfo& client_info)>;
using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>;
using ClientsCallback = base::Callback<void(ServiceWorkerClients* clients)>;
@@ -47,6 +47,14 @@ void NavigateClient(const GURL& url,
const base::WeakPtr<ServiceWorkerContextCore>& context,
const NavigationCallback& callback);
+// Gets a client matched by |client_uuid|. |callback| is called with the client
+// information on completion.
+void GetClient(
+ const base::WeakPtr<ServiceWorkerVersion>& controller,
+ const std::string& client_uuid,
+ const base::WeakPtr<ServiceWorkerContextCore>& context,
+ const ServiceWorkerProviderHost::GetClientInfoCallback& callback);
+
// Collects clients matched with |options|. |callback| is called with the client
// information sorted in MRU order (most recently focused order) on completion.
void GetClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
diff --git a/content/browser/service_worker/service_worker_provider_host.cc b/content/browser/service_worker/service_worker_provider_host.cc
index 1d79f52..639b442 100644
--- a/content/browser/service_worker/service_worker_provider_host.cc
+++ b/content/browser/service_worker/service_worker_provider_host.cc
@@ -36,7 +36,8 @@ namespace content {
namespace {
ServiceWorkerClientInfo FocusOnUIThread(int render_process_id,
- int render_frame_id) {
+ int render_frame_id,
+ const std::string& client_uuid) {
RenderFrameHostImpl* render_frame_host =
RenderFrameHostImpl::FromID(render_process_id, render_frame_id);
WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
@@ -57,8 +58,8 @@ ServiceWorkerClientInfo FocusOnUIThread(int render_process_id,
// Move the web contents to the foreground.
web_contents->Activate();
- return ServiceWorkerProviderHost::GetWindowClientInfoOnUI(render_process_id,
- render_frame_id);
+ return ServiceWorkerProviderHost::GetWindowClientInfoOnUI(
+ render_process_id, render_frame_id, client_uuid);
}
// PlzNavigate
@@ -440,7 +441,8 @@ void ServiceWorkerProviderHost::Focus(const GetClientInfoCallback& callback) {
}
BrowserThread::PostTaskAndReplyWithResult(
BrowserThread::UI, FROM_HERE,
- base::Bind(&FocusOnUIThread, render_process_id_, route_id_), callback);
+ base::Bind(&FocusOnUIThread, render_process_id_, route_id_, client_uuid_),
+ callback);
}
void ServiceWorkerProviderHost::GetWindowClientInfo(
@@ -452,14 +454,15 @@ void ServiceWorkerProviderHost::GetWindowClientInfo(
BrowserThread::PostTaskAndReplyWithResult(
BrowserThread::UI, FROM_HERE,
base::Bind(&ServiceWorkerProviderHost::GetWindowClientInfoOnUI,
- render_process_id_, route_id_),
+ render_process_id_, route_id_, client_uuid_),
callback);
}
// static
ServiceWorkerClientInfo ServiceWorkerProviderHost::GetWindowClientInfoOnUI(
int render_process_id,
- int render_frame_id) {
+ int render_frame_id,
+ const std::string& client_uuid) {
RenderFrameHostImpl* render_frame_host =
RenderFrameHostImpl::FromID(render_process_id, render_frame_id);
if (!render_frame_host)
@@ -469,8 +472,8 @@ ServiceWorkerClientInfo ServiceWorkerProviderHost::GetWindowClientInfoOnUI(
// for a frame that is actually being navigated and isn't exactly what we are
// expecting.
return ServiceWorkerClientInfo(
- render_frame_host->GetVisibilityState(), render_frame_host->IsFocused(),
- render_frame_host->GetLastCommittedURL(),
+ client_uuid, render_frame_host->GetVisibilityState(),
+ render_frame_host->IsFocused(), render_frame_host->GetLastCommittedURL(),
render_frame_host->GetParent() ? REQUEST_CONTEXT_FRAME_TYPE_NESTED
: REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL,
render_frame_host->frame_tree_node()->last_focus_time(),
diff --git a/content/browser/service_worker/service_worker_provider_host.h b/content/browser/service_worker/service_worker_provider_host.h
index a40ffc2..59c243f 100644
--- a/content/browser/service_worker/service_worker_provider_host.h
+++ b/content/browser/service_worker/service_worker_provider_host.h
@@ -186,8 +186,10 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
// Same as above but has to be called from the UI thread.
// It is taking the process and frame ids in parameter because |this| is meant
// to live on the IO thread.
- static ServiceWorkerClientInfo GetWindowClientInfoOnUI(int render_process_id,
- int render_frame_id);
+ static ServiceWorkerClientInfo GetWindowClientInfoOnUI(
+ int render_process_id,
+ int render_frame_id,
+ const std::string& client_uuid);
// Adds reference of this host's process to the |pattern|, the reference will
// be removed in destructor.
diff --git a/content/browser/service_worker/service_worker_version.cc b/content/browser/service_worker/service_worker_version.cc
index fe5ec41..105f168 100644
--- a/content/browser/service_worker/service_worker_version.cc
+++ b/content/browser/service_worker/service_worker_version.cc
@@ -892,6 +892,7 @@ void ServiceWorkerVersion::OnReportConsoleMessage(int source_identifier,
bool ServiceWorkerVersion::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ServiceWorkerVersion, message)
+ IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClient, OnGetClient)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients,
OnGetClients)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow,
@@ -944,6 +945,32 @@ void ServiceWorkerVersion::DispatchExtendableMessageEventAfterStartWorker(
request_id, message, sent_message_ports, new_routing_ids));
}
+void ServiceWorkerVersion::OnGetClient(int request_id,
+ const std::string& client_uuid) {
+ TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", "ServiceWorkerVersion::OnGetClient",
+ request_id, "client_uuid", client_uuid);
+ service_worker_client_utils::GetClient(
+ weak_factory_.GetWeakPtr(), client_uuid, context_,
+ base::Bind(&ServiceWorkerVersion::OnGetClientFinished,
+ weak_factory_.GetWeakPtr(), request_id));
+}
+
+void ServiceWorkerVersion::OnGetClientFinished(
+ int request_id,
+ const ServiceWorkerClientInfo& client_info) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ TRACE_EVENT_ASYNC_END1("ServiceWorker", "ServiceWorkerVersion::OnGetClient",
+ request_id, "client_type", client_info.client_type);
+
+ // When Clients.get() is called on the script evaluation phase, the running
+ // status can be STARTING here.
+ if (running_status() != STARTING && running_status() != RUNNING)
+ return;
+
+ embedded_worker_->SendMessage(
+ ServiceWorkerMsg_DidGetClient(request_id, client_info));
+}
+
void ServiceWorkerVersion::OnGetClients(
int request_id,
const ServiceWorkerClientQueryOptions& options) {
@@ -1028,7 +1055,6 @@ void ServiceWorkerVersion::OnOpenWindow(int request_id, GURL url) {
void ServiceWorkerVersion::OnOpenWindowFinished(
int request_id,
ServiceWorkerStatusCode status,
- const std::string& client_uuid,
const ServiceWorkerClientInfo& client_info) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -1041,16 +1067,8 @@ void ServiceWorkerVersion::OnOpenWindowFinished(
return;
}
- ServiceWorkerClientInfo client(client_info);
-
- // If the |client_info| is empty, it means that the opened window wasn't
- // controlled but the action still succeeded. The renderer process is
- // expecting an empty client in such case.
- if (!client.IsEmpty())
- client.client_uuid = client_uuid;
-
- embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowResponse(
- request_id, client));
+ embedded_worker_->SendMessage(
+ ServiceWorkerMsg_OpenWindowResponse(request_id, client_info));
}
void ServiceWorkerVersion::OnSetCachedMetadata(const GURL& url,
@@ -1133,24 +1151,19 @@ void ServiceWorkerVersion::OnFocusClient(int request_id,
return;
}
provider_host->Focus(base::Bind(&ServiceWorkerVersion::OnFocusClientFinished,
- weak_factory_.GetWeakPtr(), request_id,
- client_uuid));
+ weak_factory_.GetWeakPtr(), request_id));
}
void ServiceWorkerVersion::OnFocusClientFinished(
int request_id,
- const std::string& client_uuid,
- const ServiceWorkerClientInfo& client) {
+ const ServiceWorkerClientInfo& client_info) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (running_status() != RUNNING)
return;
- ServiceWorkerClientInfo client_info(client);
- client_info.client_uuid = client_uuid;
-
- embedded_worker_->SendMessage(ServiceWorkerMsg_FocusClientResponse(
- request_id, client_info));
+ embedded_worker_->SendMessage(
+ ServiceWorkerMsg_FocusClientResponse(request_id, client_info));
}
void ServiceWorkerVersion::OnNavigateClient(int request_id,
@@ -1199,7 +1212,6 @@ void ServiceWorkerVersion::OnNavigateClient(int request_id,
void ServiceWorkerVersion::OnNavigateClientFinished(
int request_id,
ServiceWorkerStatusCode status,
- const std::string& client_uuid,
const ServiceWorkerClientInfo& client_info) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -1212,16 +1224,8 @@ void ServiceWorkerVersion::OnNavigateClientFinished(
return;
}
- ServiceWorkerClientInfo client(client_info);
-
- // If the |client_info| is empty, it means that the navigated client wasn't
- // controlled but the action still succeeded. The renderer process is
- // expecting an empty client in such case.
- if (!client.IsEmpty())
- client.client_uuid = client_uuid;
-
embedded_worker_->SendMessage(
- ServiceWorkerMsg_NavigateClientResponse(request_id, client));
+ ServiceWorkerMsg_NavigateClientResponse(request_id, client_info));
}
void ServiceWorkerVersion::OnSkipWaiting(int request_id) {
diff --git a/content/browser/service_worker/service_worker_version.h b/content/browser/service_worker/service_worker_version.h
index fcc86a4..95109ba 100644
--- a/content/browser/service_worker/service_worker_version.h
+++ b/content/browser/service_worker/service_worker_version.h
@@ -535,6 +535,9 @@ class CONTENT_EXPORT ServiceWorkerVersion
// Message handlers.
+ // This corresponds to the spec's get(id) steps.
+ void OnGetClient(int request_id, const std::string& client_uuid);
+
// This corresponds to the spec's matchAll(options) steps.
void OnGetClients(int request_id,
const ServiceWorkerClientQueryOptions& options);
@@ -544,7 +547,6 @@ class CONTENT_EXPORT ServiceWorkerVersion
void OnOpenWindow(int request_id, GURL url);
void OnOpenWindowFinished(int request_id,
ServiceWorkerStatusCode status,
- const std::string& client_uuid,
const ServiceWorkerClientInfo& client_info);
void OnSetCachedMetadata(const GURL& url, const std::vector<char>& data);
@@ -562,15 +564,13 @@ class CONTENT_EXPORT ServiceWorkerVersion
const GURL& url);
void OnNavigateClientFinished(int request_id,
ServiceWorkerStatusCode status,
- const std::string& client_uuid,
- const ServiceWorkerClientInfo& client);
+ const ServiceWorkerClientInfo& client_info);
void OnSkipWaiting(int request_id);
void OnClaimClients(int request_id);
void OnPongFromWorker();
void OnFocusClientFinished(int request_id,
- const std::string& client_uuid,
- const ServiceWorkerClientInfo& client);
+ const ServiceWorkerClientInfo& client_info);
void OnRegisterForeignFetchScopes(const std::vector<GURL>& sub_scopes,
const std::vector<url::Origin>& origins);
@@ -583,6 +583,9 @@ class CONTENT_EXPORT ServiceWorkerVersion
void DidSkipWaiting(int request_id);
+ void OnGetClientFinished(int request_id,
+ const ServiceWorkerClientInfo& client_info);
+
void OnGetClientsFinished(int request_id, ServiceWorkerClients* clients);
// The timeout timer periodically calls OnTimeoutTimer, which stops the worker
diff --git a/content/common/service_worker/service_worker_client_info.cc b/content/common/service_worker/service_worker_client_info.cc
index c864369..5019575 100644
--- a/content/common/service_worker/service_worker_client_info.cc
+++ b/content/common/service_worker/service_worker_client_info.cc
@@ -10,25 +10,29 @@
namespace content {
ServiceWorkerClientInfo::ServiceWorkerClientInfo()
- : page_visibility_state(blink::WebPageVisibilityStateLast),
- is_focused(false),
- frame_type(REQUEST_CONTEXT_FRAME_TYPE_LAST),
- client_type(blink::WebServiceWorkerClientTypeLast),
- last_focus_time(base::TimeTicks()) {}
+ : ServiceWorkerClientInfo(std::string(),
+ blink::WebPageVisibilityStateLast,
+ false,
+ GURL(),
+ REQUEST_CONTEXT_FRAME_TYPE_LAST,
+ base::TimeTicks(),
+ blink::WebServiceWorkerClientTypeLast) {}
ServiceWorkerClientInfo::ServiceWorkerClientInfo(
+ const std::string& client_uuid,
blink::WebPageVisibilityState page_visibility_state,
bool is_focused,
const GURL& url,
RequestContextFrameType frame_type,
base::TimeTicks last_focus_time,
blink::WebServiceWorkerClientType client_type)
- : page_visibility_state(page_visibility_state),
+ : client_uuid(client_uuid),
+ page_visibility_state(page_visibility_state),
is_focused(is_focused),
url(url),
frame_type(frame_type),
- client_type(client_type),
- last_focus_time(last_focus_time) {}
+ last_focus_time(last_focus_time),
+ client_type(client_type) {}
bool ServiceWorkerClientInfo::IsEmpty() const {
return page_visibility_state == blink::WebPageVisibilityStateLast &&
diff --git a/content/common/service_worker/service_worker_client_info.h b/content/common/service_worker/service_worker_client_info.h
index 1c81fe3..c4b6c34 100644
--- a/content/common/service_worker/service_worker_client_info.h
+++ b/content/common/service_worker/service_worker_client_info.h
@@ -20,7 +20,8 @@ namespace content {
// constructor to fill the properties.
struct ServiceWorkerClientInfo {
ServiceWorkerClientInfo();
- ServiceWorkerClientInfo(blink::WebPageVisibilityState page_visibility_state,
+ ServiceWorkerClientInfo(const std::string& client_uuid,
+ blink::WebPageVisibilityState page_visibility_state,
bool is_focused,
const GURL& url,
RequestContextFrameType frame_type,
@@ -39,8 +40,8 @@ struct ServiceWorkerClientInfo {
bool is_focused;
GURL url;
RequestContextFrameType frame_type;
- blink::WebServiceWorkerClientType client_type;
base::TimeTicks last_focus_time;
+ blink::WebServiceWorkerClientType client_type;
};
} // namespace content
diff --git a/content/common/service_worker/service_worker_messages.h b/content/common/service_worker/service_worker_messages.h
index 6174cc5..2bd68cd 100644
--- a/content/common/service_worker/service_worker_messages.h
+++ b/content/common/service_worker/service_worker_messages.h
@@ -275,6 +275,11 @@ IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_GeofencingEventFinished,
// Routed to the target ServiceWorkerVersion.
IPC_MESSAGE_ROUTED0(ServiceWorkerHostMsg_Pong)
+// Asks the browser to retrieve client of the sender ServiceWorker.
+IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_GetClient,
+ int /* request_id */,
+ std::string /* client_uuid */)
+
// Asks the browser to retrieve clients of the sender ServiceWorker.
IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_GetClients,
int /* request_id */,
@@ -515,6 +520,11 @@ IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_ClaimClientsError,
// Sent via EmbeddedWorker to Ping the worker, expecting a Pong in response.
IPC_MESSAGE_CONTROL0(ServiceWorkerMsg_Ping)
+// Sent via EmbeddedWorker as a response of GetClient.
+IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_DidGetClient,
+ int /* request_id */,
+ content::ServiceWorkerClientInfo)
+
// Sent via EmbeddedWorker as a response of GetClients.
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_DidGetClients,
int /* request_id */,
diff --git a/content/renderer/service_worker/service_worker_context_client.cc b/content/renderer/service_worker/service_worker_context_client.cc
index 34e20a7..ba47847 100644
--- a/content/renderer/service_worker/service_worker_context_client.cc
+++ b/content/renderer/service_worker/service_worker_context_client.cc
@@ -267,6 +267,7 @@ void ServiceWorkerContextClient::OnMessageReceived(
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker,
OnCrossOriginMessageToWorker)
+ IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse,
OnOpenWindowResponse)
@@ -299,6 +300,15 @@ blink::WebURL ServiceWorkerContextClient::scope() const {
return service_worker_scope_;
}
+void ServiceWorkerContextClient::getClient(
+ const blink::WebString& id,
+ blink::WebServiceWorkerClientCallbacks* callbacks) {
+ DCHECK(callbacks);
+ int request_id = context_->client_callbacks.Add(callbacks);
+ Send(new ServiceWorkerHostMsg_GetClient(
+ GetRoutingID(), request_id, base::UTF16ToUTF8(base::StringPiece16(id))));
+}
+
void ServiceWorkerContextClient::getClients(
const blink::WebServiceWorkerClientQueryOptions& weboptions,
blink::WebServiceWorkerClientsCallbacks* callbacks) {
@@ -873,6 +883,26 @@ void ServiceWorkerContextClient::OnCrossOriginMessageToWorker(
proxy_->dispatchCrossOriginMessageEvent(web_client, message, ports);
}
+void ServiceWorkerContextClient::OnDidGetClient(
+ int request_id,
+ const ServiceWorkerClientInfo& client) {
+ TRACE_EVENT0("ServiceWorker", "ServiceWorkerContextClient::OnDidGetClient");
+ blink::WebServiceWorkerClientCallbacks* callbacks =
+ context_->client_callbacks.Lookup(request_id);
+ if (!callbacks) {
+ NOTREACHED() << "Got stray response: " << request_id;
+ return;
+ }
+ scoped_ptr<blink::WebServiceWorkerClientInfo> web_client;
+ if (!client.IsEmpty()) {
+ DCHECK(client.IsValid());
+ web_client.reset(new blink::WebServiceWorkerClientInfo(
+ ToWebServiceWorkerClientInfo(client)));
+ }
+ callbacks->onSuccess(blink::adoptWebPtr(web_client.release()));
+ context_->client_callbacks.Remove(request_id);
+}
+
void ServiceWorkerContextClient::OnDidGetClients(
int request_id, const std::vector<ServiceWorkerClientInfo>& clients) {
TRACE_EVENT0("ServiceWorker",
@@ -910,7 +940,7 @@ void ServiceWorkerContextClient::OnOpenWindowResponse(
web_client.reset(new blink::WebServiceWorkerClientInfo(
ToWebServiceWorkerClientInfo(client)));
}
- callbacks->onSuccess(adoptWebPtr(web_client.release()));
+ callbacks->onSuccess(blink::adoptWebPtr(web_client.release()));
context_->client_callbacks.Remove(request_id);
}
@@ -946,7 +976,7 @@ void ServiceWorkerContextClient::OnFocusClientResponse(
scoped_ptr<blink::WebServiceWorkerClientInfo> web_client (
new blink::WebServiceWorkerClientInfo(
ToWebServiceWorkerClientInfo(client)));
- callback->onSuccess(adoptWebPtr(web_client.release()));
+ callback->onSuccess(blink::adoptWebPtr(web_client.release()));
} else {
callback->onError(blink::WebServiceWorkerError(
blink::WebServiceWorkerError::ErrorTypeNotFound,
@@ -973,7 +1003,7 @@ void ServiceWorkerContextClient::OnNavigateClientResponse(
web_client.reset(new blink::WebServiceWorkerClientInfo(
ToWebServiceWorkerClientInfo(client)));
}
- callbacks->onSuccess(adoptWebPtr(web_client.release()));
+ callbacks->onSuccess(blink::adoptWebPtr(web_client.release()));
context_->client_callbacks.Remove(request_id);
}
diff --git a/content/renderer/service_worker/service_worker_context_client.h b/content/renderer/service_worker/service_worker_context_client.h
index aed6ce5..9b7bbad 100644
--- a/content/renderer/service_worker/service_worker_context_client.h
+++ b/content/renderer/service_worker/service_worker_context_client.h
@@ -92,6 +92,8 @@ class ServiceWorkerContextClient
// WebServiceWorkerContextClient overrides.
blink::WebURL scope() const override;
+ void getClient(const blink::WebString&,
+ blink::WebServiceWorkerClientCallbacks*) override;
void getClients(const blink::WebServiceWorkerClientQueryOptions&,
blink::WebServiceWorkerClientsCallbacks*) override;
void openWindow(const blink::WebURL&,
@@ -227,6 +229,7 @@ class ServiceWorkerContextClient
const base::string16& message,
const std::vector<TransferredMessagePort>& sent_message_ports,
const std::vector<int>& new_routing_ids);
+ void OnDidGetClient(int request_id, const ServiceWorkerClientInfo& client);
void OnDidGetClients(
int request_id, const std::vector<ServiceWorkerClientInfo>& clients);
void OnOpenWindowResponse(int request_id,