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

Unified Diff: content/browser/service_worker/service_worker_version.cc

Issue 1439333002: Service Worker: Add Clients.get(id) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add layout test Created 4 years, 12 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_version.cc
diff --git a/content/browser/service_worker/service_worker_version.cc b/content/browser/service_worker/service_worker_version.cc
index 2635365b2c8421f4c3eef89a9941d8c0fbb062a5..aed3a6b28f06eb5655fc8d9277fd799188d0355f 100644
--- a/content/browser/service_worker/service_worker_version.cc
+++ b/content/browser/service_worker/service_worker_version.cc
@@ -21,6 +21,8 @@
#include "base/time/time.h"
#include "content/browser/bad_message.h"
#include "content/browser/child_process_security_policy_impl.h"
+#include "content/browser/frame_host/frame_tree_node.h"
+#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/message_port_message_filter.h"
#include "content/browser/message_port_service.h"
#include "content/browser/service_worker/embedded_worker_instance.h"
@@ -50,6 +52,8 @@ namespace content {
using StatusCallback = ServiceWorkerVersion::StatusCallback;
using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>;
+using GetClientCallback =
zino 2016/01/04 09:05:27 This was already defined in provider host[1] as we
+ base::Callback<void(scoped_ptr<ServiceWorkerClientInfo>)>;
using GetClientsCallback =
base::Callback<void(scoped_ptr<ServiceWorkerClients>)>;
@@ -1101,6 +1105,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_ActivateEventFinished,
@@ -1175,6 +1180,29 @@ void ServiceWorkerVersion::DispatchActivateEventAfterStartWorker(
}
}
+void ServiceWorkerVersion::OnGetClient(int request_id, const std::string& id) {
+ TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", "ServiceWorkerVersion::OnGetClient",
+ request_id, "id", id);
+
+ ServiceWorkerClientInfo client;
+
+ GetClient(request_id, id, &client);
zino 2016/01/04 09:05:27 IMHO, Many functions are defined duplicately. What
+ OnGetClientFinished(request_id, &client);
+}
+
+void ServiceWorkerVersion::OnGetClientFinished(
+ int request_id,
+ ServiceWorkerClientInfo* client) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ TRACE_EVENT_ASYNC_END1("ServiceWorker", "ServiceWorkerVersion::OnGetClients",
+ request_id, "The retrieved client", client);
+
+ if (running_status() != RUNNING)
+ return;
+ embedded_worker_->SendMessage(
+ ServiceWorkerMsg_DidGetClient(request_id, *client));
+}
+
void ServiceWorkerVersion::OnGetClients(
int request_id,
const ServiceWorkerClientQueryOptions& options) {
@@ -1766,6 +1794,44 @@ void ServiceWorkerVersion::StartWorkerInternal() {
}
}
+void ServiceWorkerVersion::GetClient(int request_id,
+ std::string id,
+ ServiceWorkerClientInfo* client_info) {
+ ServiceWorkerProviderHost* provider_host =
+ context_->GetProviderHostByClientID(id);
+ if (!provider_host) {
+ // The client may already have been closed, just ignore.
+ return;
+ }
+
+ client_info->client_uuid = provider_host->client_uuid();
+
+ if (provider_host->client_type() == blink::WebServiceWorkerClientTypeWindow) {
zino 2016/01/04 09:05:27 I think you can reuse the provider_host->GetWindow
+ RenderFrameHostImpl* render_frame_host = RenderFrameHostImpl::FromID(
+ provider_host->process_id(), provider_host->frame_id());
+ if (!render_frame_host)
+ return;
+
+ client_info->url = render_frame_host->GetLastCommittedURL();
+ client_info->page_visibility_state =
+ render_frame_host->GetVisibilityState();
+ client_info->is_focused = render_frame_host->IsFocused();
+ client_info->frame_type = render_frame_host->GetParent()
+ ? REQUEST_CONTEXT_FRAME_TYPE_NESTED
+ : REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL;
+ client_info->client_type = blink::WebServiceWorkerClientTypeWindow;
+ client_info->last_focus_time =
+ render_frame_host->frame_tree_node()->last_focus_time();
+ } else {
+ client_info->url = provider_host->document_url();
+ client_info->page_visibility_state = blink::WebPageVisibilityStateHidden;
+ client_info->is_focused = false;
+ client_info->frame_type = REQUEST_CONTEXT_FRAME_TYPE_NONE;
+ client_info->client_type = provider_host->client_type();
+ client_info->last_focus_time = base::TimeTicks();
+ }
+}
+
void ServiceWorkerVersion::GetWindowClients(
int request_id,
const ServiceWorkerClientQueryOptions& options) {

Powered by Google App Engine
This is Rietveld 408576698