summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
Diffstat (limited to 'content')
-rw-r--r--content/browser/service_worker/service_worker_provider_host.cc37
-rw-r--r--content/browser/service_worker/service_worker_provider_host.h6
-rw-r--r--content/browser/service_worker/service_worker_version.cc67
-rw-r--r--content/browser/service_worker/service_worker_version.h13
-rw-r--r--content/child/service_worker/service_worker_dispatcher.cc26
-rw-r--r--content/child/service_worker/service_worker_dispatcher.h4
-rw-r--r--content/common/service_worker/service_worker_client_info.cc42
-rw-r--r--content/common/service_worker/service_worker_client_info.h42
-rw-r--r--content/common/service_worker/service_worker_messages.h17
-rw-r--r--content/common/service_worker/service_worker_types.h9
-rw-r--r--content/content_common.gypi2
-rw-r--r--content/renderer/service_worker/service_worker_script_context.cc25
-rw-r--r--content/renderer/service_worker/service_worker_script_context.h1
13 files changed, 169 insertions, 122 deletions
diff --git a/content/browser/service_worker/service_worker_provider_host.cc b/content/browser/service_worker/service_worker_provider_host.cc
index 46f9074..7adeb88 100644
--- a/content/browser/service_worker/service_worker_provider_host.cc
+++ b/content/browser/service_worker/service_worker_provider_host.cc
@@ -5,6 +5,7 @@
#include "content/browser/service_worker/service_worker_provider_host.h"
#include "base/stl_util.h"
+#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/message_port_message_filter.h"
#include "content/browser/service_worker/service_worker_context_core.h"
#include "content/browser/service_worker/service_worker_context_request_handler.h"
@@ -43,6 +44,32 @@ void FocusOnUIThread(int render_process_id,
base::Bind(callback, result));
}
+void GetClientInfoOnUIThread(
+ int render_process_id,
+ int render_frame_id,
+ const ServiceWorkerProviderHost::GetClientInfoCallback& callback) {
+ RenderFrameHostImpl* render_frame_host =
+ RenderFrameHostImpl::FromID(render_process_id, render_frame_id);
+ if (!render_frame_host) {
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(callback, ServiceWorkerClientInfo()));
+ return;
+ }
+
+ // TODO(mlamouri,michaeln): it is possible to end up collecting information
+ // for a frame that is actually being navigated and isn't exactly what we are
+ // expecting.
+ ServiceWorkerClientInfo client_info(
+ 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);
+
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(callback, client_info));
+}
+
} // anonymous namespace
ServiceWorkerProviderHost::ServiceWorkerProviderHost(
@@ -268,10 +295,12 @@ void ServiceWorkerProviderHost::Focus(const FocusCallback& callback) {
}
void ServiceWorkerProviderHost::GetClientInfo(
- int embedded_worker_id,
- int request_id) {
- Send(new ServiceWorkerMsg_GetClientInfo(
- kDocumentMainThreadId, embedded_worker_id, request_id, provider_id()));
+ const GetClientInfoCallback& callback) {
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(&GetClientInfoOnUIThread,
+ render_process_id_,
+ render_frame_id_,
+ callback));
}
void ServiceWorkerProviderHost::AddScopedProcessReferenceToPattern(
diff --git a/content/browser/service_worker/service_worker_provider_host.h b/content/browser/service_worker/service_worker_provider_host.h
index b3e60c1..4cfca4e 100644
--- a/content/browser/service_worker/service_worker_provider_host.h
+++ b/content/browser/service_worker/service_worker_provider_host.h
@@ -45,7 +45,9 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
: public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener),
public base::SupportsWeakPtr<ServiceWorkerProviderHost> {
public:
- typedef base::Callback<void(bool)> FocusCallback;
+ using FocusCallback = base::Callback<void(bool)>;
+ using GetClientInfoCallback =
+ base::Callback<void(const ServiceWorkerClientInfo&)>;
// If |render_frame_id| is MSG_ROUTING_NONE, this provider host works for the
// worker context.
@@ -146,7 +148,7 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
void Focus(const FocusCallback& callback);
// Asks the renderer to send back the document information.
- void GetClientInfo(int embedded_worker_id, int request_id);
+ void GetClientInfo(const GetClientInfoCallback& callback);
// 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 8776f0e..47545e0 100644
--- a/content/browser/service_worker/service_worker_version.cc
+++ b/content/browser/service_worker/service_worker_version.cc
@@ -45,6 +45,8 @@ class ServiceWorkerVersion::GetClientDocumentsCallback
friend class base::RefCounted<GetClientDocumentsCallback>;
virtual ~GetClientDocumentsCallback() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
if (version_->running_status() == RUNNING) {
version_->embedded_worker_->SendMessage(
ServiceWorkerMsg_DidGetClientDocuments(request_id_, clients_));
@@ -53,9 +55,7 @@ class ServiceWorkerVersion::GetClientDocumentsCallback
std::vector<ServiceWorkerClientInfo> clients_;
int request_id_;
-
- // |version_| must outlive this callback.
- ServiceWorkerVersion* version_;
+ scoped_refptr<ServiceWorkerVersion> version_;
DISALLOW_COPY_AND_ASSIGN(GetClientDocumentsCallback);
};
@@ -614,6 +614,8 @@ void ServiceWorkerVersion::AddControllee(
ServiceWorkerProviderHost* provider_host) {
DCHECK(!ContainsKey(controllee_map_, provider_host));
int controllee_id = controllee_by_id_.Add(provider_host);
+ // IDMap<>'s last index is kInvalidServiceWorkerClientId.
+ CHECK(controllee_id != kInvalidServiceWorkerClientId);
controllee_map_[provider_host] = controllee_id;
// Reset the timer if it's running (so that it's kept alive a bit longer
// right after a new controllee is added).
@@ -734,9 +736,6 @@ void ServiceWorkerVersion::OnStopped(
SERVICE_WORKER_ERROR_FAILED);
RunIDMapCallbacks(&geofencing_callbacks_,
SERVICE_WORKER_ERROR_FAILED);
- RunIDMapCallbacks(&get_client_info_callbacks_,
- SERVICE_WORKER_ERROR_FAILED,
- ServiceWorkerClientInfo());
RunIDMapCallbacks(&cross_origin_connect_callbacks_,
SERVICE_WORKER_ERROR_FAILED,
false);
@@ -812,10 +811,6 @@ bool ServiceWorkerVersion::OnMessageReceived(const IPC::Message& message) {
OnPostMessageToDocument)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FocusClient,
OnFocusClient)
- IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClientInfoSuccess,
- OnGetClientInfoSuccess)
- IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClientInfoError,
- OnGetClientInfoError)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SkipWaiting,
OnSkipWaiting)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClaimClients,
@@ -875,40 +870,14 @@ void ServiceWorkerVersion::OnGetClientDocuments(int request_id) {
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerVersion::OnGetClientDocuments");
while (!it.IsAtEnd()) {
- int client_request_id = get_client_info_callbacks_.Add(
- new GetClientInfoCallback(base::Bind(
- &ServiceWorkerVersion::DidGetClientInfo,
- weak_factory_.GetWeakPtr(), it.GetCurrentKey(), callback)));
- it.GetCurrentValue()->GetClientInfo(embedded_worker_->embedded_worker_id(),
- client_request_id);
+ // TODO(mlamouri): we could coalesce those requests into one.
+ it.GetCurrentValue()->GetClientInfo(
+ base::Bind(&ServiceWorkerVersion::DidGetClientInfo,
+ weak_factory_.GetWeakPtr(), it.GetCurrentKey(), callback));
it.Advance();
}
}
-void ServiceWorkerVersion::OnGetClientInfoSuccess(
- int request_id,
- const ServiceWorkerClientInfo& info) {
- GetClientInfoCallback* callback =
- get_client_info_callbacks_.Lookup(request_id);
- if (!callback) {
- // The callback may already have been cleared by OnStopped, just ignore.
- return;
- }
- callback->Run(SERVICE_WORKER_OK, info);
- RemoveCallbackAndStopIfDoomed(&get_client_info_callbacks_, request_id);
-}
-
-void ServiceWorkerVersion::OnGetClientInfoError(int request_id) {
- GetClientInfoCallback* callback =
- get_client_info_callbacks_.Lookup(request_id);
- if (!callback) {
- // The callback may already have been cleared by OnStopped, just ignore.
- return;
- }
- callback->Run(SERVICE_WORKER_ERROR_FAILED, ServiceWorkerClientInfo());
- RemoveCallbackAndStopIfDoomed(&get_client_info_callbacks_, request_id);
-}
-
void ServiceWorkerVersion::OnActivateEventFinished(
int request_id,
blink::WebServiceWorkerEventResult result) {
@@ -1167,10 +1136,21 @@ void ServiceWorkerVersion::DidClaimClients(
void ServiceWorkerVersion::DidGetClientInfo(
int client_id,
scoped_refptr<GetClientDocumentsCallback> callback,
- ServiceWorkerStatusCode status,
const ServiceWorkerClientInfo& info) {
- if (status == SERVICE_WORKER_OK)
- callback->AddClientInfo(client_id, info);
+ // If the request to the provider_host returned an empty
+ // ServiceWorkerClientInfo, that means that it wasn't possible to associate
+ // it with a valid RenderFrameHost. It might be because the frame was killed
+ // or navigated in between.
+ if (info.IsEmpty())
+ return;
+
+ // We can get info for a frame that was navigating end ended up with a
+ // different URL than expected. In such case, we should make sure to not
+ // expose cross-origin WindowClient.
+ if (info.url.GetOrigin() != script_url_.GetOrigin())
+ return;
+
+ callback->AddClientInfo(client_id, info);
}
void ServiceWorkerVersion::ScheduleStopWorker() {
@@ -1208,7 +1188,6 @@ bool ServiceWorkerVersion::HasInflightRequests() const {
!notification_click_callbacks_.IsEmpty() ||
!push_callbacks_.IsEmpty() ||
!geofencing_callbacks_.IsEmpty() ||
- !get_client_info_callbacks_.IsEmpty() ||
!cross_origin_connect_callbacks_.IsEmpty() ||
!streaming_url_request_jobs_.empty();
}
diff --git a/content/browser/service_worker/service_worker_version.h b/content/browser/service_worker/service_worker_version.h
index 015fc9d..b07503d 100644
--- a/content/browser/service_worker/service_worker_version.h
+++ b/content/browser/service_worker/service_worker_version.h
@@ -40,13 +40,14 @@ class HttpResponseInfo;
namespace content {
class EmbeddedWorkerRegistry;
-struct NavigatorConnectClient;
-struct PlatformNotificationData;
class ServiceWorkerContextCore;
class ServiceWorkerProviderHost;
class ServiceWorkerRegistration;
class ServiceWorkerURLRequestJob;
class ServiceWorkerVersionInfo;
+struct NavigatorConnectClient;
+struct PlatformNotificationData;
+struct ServiceWorkerClientInfo;
// This class corresponds to a specific version of a ServiceWorker
// script for a given pattern. When a script is upgraded, there may be
@@ -63,9 +64,6 @@ class CONTENT_EXPORT ServiceWorkerVersion
typedef base::Callback<void(ServiceWorkerStatusCode,
ServiceWorkerFetchEventResult,
const ServiceWorkerResponse&)> FetchCallback;
- typedef base::Callback<void(ServiceWorkerStatusCode,
- const ServiceWorkerClientInfo&)>
- GetClientInfoCallback;
typedef base::Callback<void(ServiceWorkerStatusCode, bool)>
CrossOriginConnectCallback;
@@ -346,9 +344,6 @@ class CONTENT_EXPORT ServiceWorkerVersion
// Message handlers.
void OnGetClientDocuments(int request_id);
- void OnGetClientInfoSuccess(int request_id,
- const ServiceWorkerClientInfo& info);
- void OnGetClientInfoError(int request_id);
void OnActivateEventFinished(int request_id,
blink::WebServiceWorkerEventResult result);
void OnInstallEventFinished(int request_id,
@@ -375,7 +370,6 @@ class CONTENT_EXPORT ServiceWorkerVersion
void DidClaimClients(int request_id, ServiceWorkerStatusCode status);
void DidGetClientInfo(int client_id,
scoped_refptr<GetClientDocumentsCallback> callback,
- ServiceWorkerStatusCode status,
const ServiceWorkerClientInfo& info);
void ScheduleStopWorker();
void StopWorkerIfIdle();
@@ -406,7 +400,6 @@ class CONTENT_EXPORT ServiceWorkerVersion
IDMap<StatusCallback, IDMapOwnPointer> notification_click_callbacks_;
IDMap<StatusCallback, IDMapOwnPointer> push_callbacks_;
IDMap<StatusCallback, IDMapOwnPointer> geofencing_callbacks_;
- IDMap<GetClientInfoCallback, IDMapOwnPointer> get_client_info_callbacks_;
IDMap<CrossOriginConnectCallback, IDMapOwnPointer>
cross_origin_connect_callbacks_;
diff --git a/content/child/service_worker/service_worker_dispatcher.cc b/content/child/service_worker/service_worker_dispatcher.cc
index 73b9a29..2a713bc 100644
--- a/content/child/service_worker/service_worker_dispatcher.cc
+++ b/content/child/service_worker/service_worker_dispatcher.cc
@@ -84,8 +84,6 @@ void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) {
OnSetControllerServiceWorker)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument,
OnPostMessage)
- IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GetClientInfo,
- OnGetClientInfo)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
DCHECK(handled) << "Unhandled message:" << msg.type();
@@ -663,30 +661,6 @@ void ServiceWorkerDispatcher::OnPostMessage(
found->second->dispatchMessageEvent(message, ports);
}
-void ServiceWorkerDispatcher::OnGetClientInfo(int thread_id,
- int embedded_worker_id,
- int request_id,
- int provider_id) {
- blink::WebServiceWorkerClientInfo info;
- ProviderClientMap::iterator found = provider_clients_.find(provider_id);
- // TODO(ksakamoto): Could we track these values in the browser side? Except
- // for |isFocused|, it would be pretty easy.
- if (found != provider_clients_.end() && found->second->getClientInfo(&info)) {
- ServiceWorkerClientInfo result;
- result.client_id = info.clientID;
- result.page_visibility_state = info.pageVisibilityState;
- result.is_focused = info.isFocused;
- result.url = info.url;
- result.frame_type = static_cast<RequestContextFrameType>(info.frameType);
-
- thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetClientInfoSuccess(
- embedded_worker_id, request_id, result));
- } else {
- thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetClientInfoError(
- embedded_worker_id, request_id));
- }
-}
-
void ServiceWorkerDispatcher::AddServiceWorker(
int handle_id, WebServiceWorkerImpl* worker) {
DCHECK(!ContainsKey(service_workers_, handle_id));
diff --git a/content/child/service_worker/service_worker_dispatcher.h b/content/child/service_worker/service_worker_dispatcher.h
index 3f1deff..9ef86cc 100644
--- a/content/child/service_worker/service_worker_dispatcher.h
+++ b/content/child/service_worker/service_worker_dispatcher.h
@@ -205,10 +205,6 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer {
const base::string16& message,
const std::vector<int>& sent_message_port_ids,
const std::vector<int>& new_routing_ids);
- void OnGetClientInfo(int thread_id,
- int embedded_worker_id,
- int request_id,
- int provider_id);
void SetReadyRegistration(
int provider_id,
diff --git a/content/common/service_worker/service_worker_client_info.cc b/content/common/service_worker/service_worker_client_info.cc
new file mode 100644
index 0000000..5662818
--- /dev/null
+++ b/content/common/service_worker/service_worker_client_info.cc
@@ -0,0 +1,42 @@
+// 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/common/service_worker/service_worker_client_info.h"
+
+#include "base/logging.h"
+#include "content/common/service_worker/service_worker_types.h"
+
+namespace content {
+
+ServiceWorkerClientInfo::ServiceWorkerClientInfo()
+ : client_id(kInvalidServiceWorkerClientId),
+ page_visibility_state(blink::WebPageVisibilityStateLast),
+ is_focused(false),
+ frame_type(REQUEST_CONTEXT_FRAME_TYPE_LAST) {
+}
+
+ServiceWorkerClientInfo::ServiceWorkerClientInfo(
+ blink::WebPageVisibilityState page_visibility_state,
+ bool is_focused,
+ const GURL& url,
+ RequestContextFrameType frame_type)
+ : client_id(kInvalidServiceWorkerClientId),
+ page_visibility_state(page_visibility_state),
+ is_focused(is_focused),
+ url(url),
+ frame_type(frame_type) {
+}
+
+bool ServiceWorkerClientInfo::IsEmpty() const {
+ return page_visibility_state == blink::WebPageVisibilityStateLast &&
+ is_focused == false &&
+ url.is_empty() &&
+ frame_type == REQUEST_CONTEXT_FRAME_TYPE_LAST;
+}
+
+bool ServiceWorkerClientInfo::IsValid() const {
+ return !IsEmpty() && client_id != kInvalidServiceWorkerClientId;
+}
+
+} // namespace content
diff --git a/content/common/service_worker/service_worker_client_info.h b/content/common/service_worker/service_worker_client_info.h
new file mode 100644
index 0000000..c90ba69
--- /dev/null
+++ b/content/common/service_worker/service_worker_client_info.h
@@ -0,0 +1,42 @@
+// 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_COMMON_SERVICE_WORKER_SERVICE_WORKER_INFO_CLIENT_H_
+#define CONTENT_COMMON_SERVICE_WORKER_SERVICE_WORKER_INFO_CLIENT_H_
+
+#include "content/public/common/request_context_frame_type.h"
+#include "third_party/WebKit/public/platform/WebPageVisibilityState.h"
+#include "url/gurl.h"
+
+namespace content {
+
+// This class holds the information related to a service worker window client.
+// It is the content/ equivalent of Blink's WebServiceWorkerClientInfo.
+// An instance can be created empty or can be filed with the expected
+// properties. Except for the client_id, it is preferred to use the constructor
+// to fill the properties.
+struct ServiceWorkerClientInfo {
+ ServiceWorkerClientInfo();
+ ServiceWorkerClientInfo(blink::WebPageVisibilityState page_visibility_state,
+ bool is_focused,
+ const GURL& url,
+ RequestContextFrameType frame_type);
+
+ // Returns whether the instance is empty.
+ bool IsEmpty() const;
+
+ // Returns whether the instance is valid. A valid instance is not empty and
+ // has a valid client_id.
+ bool IsValid() const;
+
+ int client_id;
+ blink::WebPageVisibilityState page_visibility_state;
+ bool is_focused;
+ GURL url;
+ RequestContextFrameType frame_type;
+};
+
+} // namespace content
+
+#endif // CONTENT_COMMON_SERVICE_WORKER_SERVICE_WORKER_INFO_CLIENT_H_
diff --git a/content/common/service_worker/service_worker_messages.h b/content/common/service_worker/service_worker_messages.h
index 5aee688..17f109d 100644
--- a/content/common/service_worker/service_worker_messages.h
+++ b/content/common/service_worker/service_worker_messages.h
@@ -8,6 +8,7 @@
#include <vector>
#include "base/strings/string16.h"
+#include "content/common/service_worker/service_worker_client_info.h"
#include "content/common/service_worker/service_worker_status_code.h"
#include "content/common/service_worker/service_worker_types.h"
#include "content/public/common/navigator_connect_client.h"
@@ -227,15 +228,6 @@ IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_FocusClient,
int /* request_id */,
int /* client_id */)
-// Response to ServiceWorkerMsg_GetClientInfo.
-IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_GetClientInfoSuccess,
- int /* request_id */,
- content::ServiceWorkerClientInfo)
-
-// Response to ServiceWorkerMsg_GetClientInfo.
-IPC_MESSAGE_ROUTED1(ServiceWorkerHostMsg_GetClientInfoError,
- int /* request_id */)
-
// Asks the browser to force this worker to become activated.
IPC_MESSAGE_ROUTED1(ServiceWorkerHostMsg_SkipWaiting,
int /* request_id */)
@@ -403,13 +395,6 @@ IPC_MESSAGE_CONTROL5(ServiceWorkerMsg_MessageToDocument,
std::vector<int> /* sent_message_port_ids */,
std::vector<int> /* new_routing_ids */)
-// Sent to client documents to request document properties.
-IPC_MESSAGE_CONTROL4(ServiceWorkerMsg_GetClientInfo,
- int /* thread_id */,
- int /* embedded_worker_id */,
- int /* request_id */,
- int /* provider_id */)
-
// Sent via EmbeddedWorker to dispatch events.
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_InstallEvent,
int /* request_id */,
diff --git a/content/common/service_worker/service_worker_types.h b/content/common/service_worker/service_worker_types.h
index 6191a47..8d3dc29 100644
--- a/content/common/service_worker/service_worker_types.h
+++ b/content/common/service_worker/service_worker_types.h
@@ -48,6 +48,7 @@ static const int64 kInvalidServiceWorkerVersionId = -1;
static const int64 kInvalidServiceWorkerResourceId = -1;
static const int64 kInvalidServiceWorkerResponseId = -1;
static const int kInvalidEmbeddedWorkerThreadId = -1;
+static const int kInvalidServiceWorkerClientId = 0;
enum FetchRequestMode {
FETCH_REQUEST_MODE_SAME_ORIGIN,
@@ -204,14 +205,6 @@ class ChangedVersionAttributesMask {
int changed_;
};
-struct ServiceWorkerClientInfo {
- int client_id;
- blink::WebPageVisibilityState page_visibility_state;
- bool is_focused;
- GURL url;
- RequestContextFrameType frame_type;
-};
-
} // namespace content
#endif // CONTENT_COMMON_SERVICE_WORKER_SERVICE_WORKER_TYPES_H_
diff --git a/content/content_common.gypi b/content/content_common.gypi
index 31f3ea7..5e4940c 100644
--- a/content/content_common.gypi
+++ b/content/content_common.gypi
@@ -491,6 +491,8 @@
'common/screen_orientation_messages.h',
'common/send_zygote_child_ping_linux.cc',
'common/service_worker/embedded_worker_messages.h',
+ 'common/service_worker/service_worker_client_info.cc',
+ 'common/service_worker/service_worker_client_info.h',
'common/service_worker/service_worker_messages.h',
'common/service_worker/service_worker_status_code.cc',
'common/service_worker/service_worker_status_code.h',
diff --git a/content/renderer/service_worker/service_worker_script_context.cc b/content/renderer/service_worker/service_worker_script_context.cc
index f68a0053..f0fde5a 100644
--- a/content/renderer/service_worker/service_worker_script_context.cc
+++ b/content/renderer/service_worker/service_worker_script_context.cc
@@ -72,6 +72,21 @@ blink::WebURLRequest::FrameType GetBlinkFrameType(
return static_cast<blink::WebURLRequest::FrameType>(frame_type);
}
+blink::WebServiceWorkerClientInfo
+ToWebServiceWorkerClientInfo(const ServiceWorkerClientInfo& client_info) {
+ DCHECK(client_info.IsValid());
+
+ blink::WebServiceWorkerClientInfo web_client_info;
+
+ web_client_info.clientID = client_info.client_id;
+ web_client_info.pageVisibilityState = client_info.page_visibility_state;
+ web_client_info.isFocused = client_info.is_focused;
+ web_client_info.url = client_info.url;
+ web_client_info.frameType = GetBlinkFrameType(client_info.frame_type);
+
+ return web_client_info;
+}
+
} // namespace
ServiceWorkerScriptContext::ServiceWorkerScriptContext(
@@ -429,14 +444,8 @@ void ServiceWorkerScriptContext::OnDidGetClientDocuments(
new blink::WebServiceWorkerClientsInfo);
blink::WebVector<blink::WebServiceWorkerClientInfo> convertedClients(
clients.size());
- for (size_t i = 0; i < clients.size(); ++i) {
- convertedClients[i].clientID = clients[i].client_id;
- convertedClients[i].pageVisibilityState = clients[i].page_visibility_state;
- convertedClients[i].isFocused = clients[i].is_focused;
- convertedClients[i].url = clients[i].url;
- convertedClients[i].frameType =
- static_cast<blink::WebURLRequest::FrameType>(clients[i].frame_type);
- }
+ for (size_t i = 0; i < clients.size(); ++i)
+ convertedClients[i] = ToWebServiceWorkerClientInfo(clients[i]);
info->clients.swap(convertedClients);
callbacks->onSuccess(info.release());
pending_clients_callbacks_.Remove(request_id);
diff --git a/content/renderer/service_worker/service_worker_script_context.h b/content/renderer/service_worker/service_worker_script_context.h
index 3259a4f..a6d53ad 100644
--- a/content/renderer/service_worker/service_worker_script_context.h
+++ b/content/renderer/service_worker/service_worker_script_context.h
@@ -42,6 +42,7 @@ class EmbeddedWorkerContextClient;
class WebServiceWorkerRegistrationImpl;
struct NavigatorConnectClient;
struct PlatformNotificationData;
+struct ServiceWorkerClientInfo;
// TODO(kinuko): This should implement WebServiceWorkerContextClient
// rather than having EmbeddedWorkerContextClient implement it.