diff options
Diffstat (limited to 'chromium/content/common/service_worker')
7 files changed, 531 insertions, 0 deletions
diff --git a/chromium/content/common/service_worker/OWNERS b/chromium/content/common/service_worker/OWNERS new file mode 100644 index 00000000000..98927dc929d --- /dev/null +++ b/chromium/content/common/service_worker/OWNERS @@ -0,0 +1,18 @@ +michaeln@chromium.org +falken@chromium.org + +# may not be available +kinuko@chromium.org + +# Changes to IPC messages require a security review to avoid introducing +# new sandbox escapes. +per-file *_messages*.h=set noparent +per-file *_messages*.h=cevans@chromium.org +per-file *_messages*.h=dcheng@chromium.org +per-file *_messages*.h=inferno@chromium.org +per-file *_messages*.h=jln@chromium.org +per-file *_messages*.h=jschuh@chromium.org +per-file *_messages*.h=kenrb@chromium.org +per-file *_messages*.h=nasko@chromium.org +per-file *_messages*.h=palmer@chromium.org +per-file *_messages*.h=tsepez@chromium.org diff --git a/chromium/content/common/service_worker/embedded_worker_messages.h b/chromium/content/common/service_worker/embedded_worker_messages.h new file mode 100644 index 00000000000..df5cf6914a3 --- /dev/null +++ b/chromium/content/common/service_worker/embedded_worker_messages.h @@ -0,0 +1,93 @@ +// Copyright 2014 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. + +// Message definition file, included multiple times, hence no include guard. + +#include <string> + +#include "ipc/ipc_message.h" +#include "ipc/ipc_message_macros.h" +#include "ipc/ipc_param_traits.h" +#include "url/gurl.h" + +#undef IPC_MESSAGE_EXPORT +#define IPC_MESSAGE_EXPORT CONTENT_EXPORT + +#define IPC_MESSAGE_START EmbeddedWorkerMsgStart + +// Parameters structure for EmbeddedWorkerMsg_StartWorker. +IPC_STRUCT_BEGIN(EmbeddedWorkerMsg_StartWorker_Params) + IPC_STRUCT_MEMBER(int, embedded_worker_id) + IPC_STRUCT_MEMBER(int64, service_worker_version_id) + IPC_STRUCT_MEMBER(GURL, scope) + IPC_STRUCT_MEMBER(GURL, script_url) + IPC_STRUCT_MEMBER(int, worker_devtools_agent_route_id) + IPC_STRUCT_MEMBER(bool, pause_on_start) +IPC_STRUCT_END() + +// Parameters structure for EmbeddedWorkerHostMsg_ReportConsoleMessage. +// The data members directly correspond to parameters of +// WorkerMessagingProxy::reportConsoleMessage() +IPC_STRUCT_BEGIN(EmbeddedWorkerHostMsg_ReportConsoleMessage_Params) + IPC_STRUCT_MEMBER(int, source_identifier) + IPC_STRUCT_MEMBER(int, message_level) + IPC_STRUCT_MEMBER(base::string16, message) + IPC_STRUCT_MEMBER(int, line_number) + IPC_STRUCT_MEMBER(GURL, source_url) +IPC_STRUCT_END() + +// Browser -> Renderer message to create a new embedded worker context. +IPC_MESSAGE_CONTROL1(EmbeddedWorkerMsg_StartWorker, + EmbeddedWorkerMsg_StartWorker_Params /* params */) + +// Browser -> Renderer message to stop (terminate) the embedded worker. +IPC_MESSAGE_CONTROL1(EmbeddedWorkerMsg_StopWorker, + int /* embedded_worker_id */) + +// Renderer -> Browser message to indicate that the worker has loadedd the +// script. +IPC_MESSAGE_CONTROL1(EmbeddedWorkerHostMsg_WorkerScriptLoaded, + int /* embedded_worker_id */) + +// Renderer -> Browser message to indicate that the worker has failed to load +// the script. +IPC_MESSAGE_CONTROL1(EmbeddedWorkerHostMsg_WorkerScriptLoadFailed, + int /* embedded_worker_id */) + +// Renderer -> Browser message to indicate that the worker is started. +IPC_MESSAGE_CONTROL2(EmbeddedWorkerHostMsg_WorkerStarted, + int /* thread_id */, + int /* embedded_worker_id */) + +// Renderer -> Browser message to indicate that the worker is stopped. +IPC_MESSAGE_CONTROL1(EmbeddedWorkerHostMsg_WorkerStopped, + int /* embedded_worker_id */) + +// Renderer -> Browser message to report an exception. +IPC_MESSAGE_CONTROL5(EmbeddedWorkerHostMsg_ReportException, + int /* embedded_worker_id */, + base::string16 /* error_message */, + int /* line_number */, + int /* column_number */, + GURL /* source_url */) + +// Renderer -> Browser message to report console message. +IPC_MESSAGE_CONTROL2( + EmbeddedWorkerHostMsg_ReportConsoleMessage, + int /* embedded_worker_id */, + EmbeddedWorkerHostMsg_ReportConsoleMessage_Params /* params */) + +// --------------------------------------------------------------------------- +// For EmbeddedWorkerContext related messages, which are directly sent from +// browser to the worker thread in the child process. We use a new message class +// for this for easier cross-thread message dispatching. + +#undef IPC_MESSAGE_START +#define IPC_MESSAGE_START EmbeddedWorkerContextMsgStart + +// Browser -> Renderer message to send message. +IPC_MESSAGE_CONTROL3(EmbeddedWorkerContextMsg_MessageToWorker, + int /* thread_id */, + int /* embedded_worker_id */, + IPC::Message /* message */) diff --git a/chromium/content/common/service_worker/service_worker_messages.h b/chromium/content/common/service_worker/service_worker_messages.h new file mode 100644 index 00000000000..0b0cb4ea821 --- /dev/null +++ b/chromium/content/common/service_worker/service_worker_messages.h @@ -0,0 +1,204 @@ +// Copyright 2014 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. + +// Message definition file, included multiple times, hence no include guard. + +#include "base/strings/string16.h" +#include "content/common/service_worker/service_worker_status_code.h" +#include "content/common/service_worker/service_worker_types.h" +#include "ipc/ipc_message_macros.h" +#include "ipc/ipc_param_traits.h" +#include "third_party/WebKit/public/platform/WebServiceWorkerError.h" +#include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h" +#include "url/gurl.h" + +#undef IPC_MESSAGE_EXPORT +#define IPC_MESSAGE_EXPORT CONTENT_EXPORT + +#define IPC_MESSAGE_START ServiceWorkerMsgStart + +IPC_ENUM_TRAITS_MAX_VALUE(blink::WebServiceWorkerError::ErrorType, + blink::WebServiceWorkerError::ErrorTypeLast) + +IPC_ENUM_TRAITS_MAX_VALUE(blink::WebServiceWorkerEventResult, + blink::WebServiceWorkerEventResultLast) + +IPC_ENUM_TRAITS_MAX_VALUE(blink::WebServiceWorkerState, + blink::WebServiceWorkerStateLast) + +IPC_STRUCT_TRAITS_BEGIN(content::ServiceWorkerFetchRequest) + IPC_STRUCT_TRAITS_MEMBER(url) + IPC_STRUCT_TRAITS_MEMBER(method) + IPC_STRUCT_TRAITS_MEMBER(headers) +IPC_STRUCT_TRAITS_END() + +IPC_ENUM_TRAITS_MAX_VALUE(content::ServiceWorkerFetchEventResult, + content::SERVICE_WORKER_FETCH_EVENT_LAST) + +IPC_STRUCT_TRAITS_BEGIN(content::ServiceWorkerResponse) + IPC_STRUCT_TRAITS_MEMBER(status_code) + IPC_STRUCT_TRAITS_MEMBER(status_text) + IPC_STRUCT_TRAITS_MEMBER(headers) + IPC_STRUCT_TRAITS_MEMBER(blob_uuid) +IPC_STRUCT_TRAITS_END() + +IPC_STRUCT_TRAITS_BEGIN(content::ServiceWorkerObjectInfo) + IPC_STRUCT_TRAITS_MEMBER(handle_id) + IPC_STRUCT_TRAITS_MEMBER(scope) + IPC_STRUCT_TRAITS_MEMBER(url) + IPC_STRUCT_TRAITS_MEMBER(state) +IPC_STRUCT_TRAITS_END() + +//--------------------------------------------------------------------------- +// Messages sent from the child process to the browser. + +IPC_MESSAGE_CONTROL5(ServiceWorkerHostMsg_RegisterServiceWorker, + int /* thread_id */, + int /* request_id */, + int /* provider_id */, + GURL /* scope */, + GURL /* script_url */) + +IPC_MESSAGE_CONTROL4(ServiceWorkerHostMsg_UnregisterServiceWorker, + int /* thread_id */, + int /* request_id */, + int /* provider_id */, + GURL /* scope (url pattern) */) + +// Sends a 'message' event to a service worker (renderer->browser). +IPC_MESSAGE_CONTROL3(ServiceWorkerHostMsg_PostMessageToWorker, + int /* handle_id */, + base::string16 /* message */, + std::vector<int> /* sent_message_port_ids */) + +// Informs the browser of a new ServiceWorkerProvider in the child process, +// |provider_id| is unique within its child process. +IPC_MESSAGE_CONTROL1(ServiceWorkerHostMsg_ProviderCreated, + int /* provider_id */) + +// Informs the browser of a ServiceWorkerProvider being destroyed. +IPC_MESSAGE_CONTROL1(ServiceWorkerHostMsg_ProviderDestroyed, + int /* provider_id */) + +// Increments and decrements the ServiceWorker object's reference +// counting in the browser side. The ServiceWorker object is created +// with ref-count==1 initially. +IPC_MESSAGE_CONTROL1(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount, + int /* handle_id */) +IPC_MESSAGE_CONTROL1(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount, + int /* handle_id */) + +// Informs the browser that |provider_id| is associated +// with a service worker script running context and +// |version_id| identifies which ServcieWorkerVersion. +IPC_MESSAGE_CONTROL2(ServiceWorkerHostMsg_SetVersionId, + int /* provider_id */, + int64 /* version_id */) + +// Informs the browser that event handling has finished. +// Routed to the target ServiceWorkerVersion. +IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_InstallEventFinished, + int /* request_id */, + blink::WebServiceWorkerEventResult) +IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_ActivateEventFinished, + int /* request_id */, + blink::WebServiceWorkerEventResult); +IPC_MESSAGE_ROUTED3(ServiceWorkerHostMsg_FetchEventFinished, + int /* request_id */, + content::ServiceWorkerFetchEventResult, + content::ServiceWorkerResponse) +IPC_MESSAGE_ROUTED1(ServiceWorkerHostMsg_SyncEventFinished, + int /* request_id */) +IPC_MESSAGE_ROUTED1(ServiceWorkerHostMsg_PushEventFinished, + int /* request_id */) + +// Asks the browser to retrieve documents controlled by the sender +// ServiceWorker. +IPC_MESSAGE_ROUTED1(ServiceWorkerHostMsg_GetClientDocuments, + int /* request_id */) + +// Sends a 'message' event to a client document (renderer->browser). +IPC_MESSAGE_ROUTED3(ServiceWorkerHostMsg_PostMessageToDocument, + int /* client_id */, + base::string16 /* message */, + std::vector<int> /* sent_message_port_ids */) + +//--------------------------------------------------------------------------- +// Messages sent from the browser to the child process. +// +// NOTE: All ServiceWorkerMsg messages not sent via EmbeddedWorker must have +// a thread_id as their first field so that ServiceWorkerMessageFilter can +// extract it and dispatch the message to the correct ServiceWorkerDispatcher +// on the correct thread. + +// Response to ServiceWorkerMsg_RegisterServiceWorker. +IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_ServiceWorkerRegistered, + int /* thread_id */, + int /* request_id */, + content::ServiceWorkerObjectInfo) + +// Response to ServiceWorkerMsg_UnregisterServiceWorker. +IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_ServiceWorkerUnregistered, + int /* thread_id */, + int /* request_id */) + +// Sent when any kind of registration error occurs during a +// RegisterServiceWorker / UnregisterServiceWorker handler above. +IPC_MESSAGE_CONTROL4(ServiceWorkerMsg_ServiceWorkerRegistrationError, + int /* thread_id */, + int /* request_id */, + blink::WebServiceWorkerError::ErrorType /* code */, + base::string16 /* message */) + +// Informs the child process that the ServiceWorker's state has changed. +IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_ServiceWorkerStateChanged, + int /* thread_id */, + int /* handle_id */, + blink::WebServiceWorkerState) + +// Tells the child process to set the waiting ServiceWorker for the given +// provider. +IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_SetWaitingServiceWorker, + int /* thread_id */, + int /* provider_id */, + content::ServiceWorkerObjectInfo) + +// Tells the child process to set the current ServiceWorker for the given +// provider. +IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_SetCurrentServiceWorker, + int /* thread_id */, + int /* provider_id */, + content::ServiceWorkerObjectInfo) + +// Sends a 'message' event to a client document (browser->renderer). +IPC_MESSAGE_CONTROL5(ServiceWorkerMsg_MessageToDocument, + int /* thread_id */, + int /* provider_id */, + base::string16 /* message */, + std::vector<int> /* sent_message_port_ids */, + std::vector<int> /* new_routing_ids */) + +// Sent via EmbeddedWorker to dispatch events. +IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_InstallEvent, + int /* request_id */, + int /* active_version_id */) +IPC_MESSAGE_CONTROL1(ServiceWorkerMsg_ActivateEvent, + int /* request_id */) +IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_FetchEvent, + int /* request_id */, + content::ServiceWorkerFetchRequest) +IPC_MESSAGE_CONTROL1(ServiceWorkerMsg_SyncEvent, + int /* request_id */) +IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_PushEvent, + int /* request_id */, + std::string /* data */) +IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_MessageToWorker, + base::string16 /* message */, + std::vector<int> /* sent_message_port_ids */, + std::vector<int> /* new_routing_ids */) + +// Sent via EmbeddedWorker as a response of GetClientDocuments. +IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_DidGetClientDocuments, + int /* request_id */, + std::vector<int> /* client_ids */) diff --git a/chromium/content/common/service_worker/service_worker_status_code.cc b/chromium/content/common/service_worker/service_worker_status_code.cc new file mode 100644 index 00000000000..bdf28a94f67 --- /dev/null +++ b/chromium/content/common/service_worker/service_worker_status_code.cc @@ -0,0 +1,38 @@ +// Copyright 2014 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_status_code.h" + +#include "base/logging.h" + +namespace content { + +const char* ServiceWorkerStatusToString(ServiceWorkerStatusCode status) { + switch (status) { + case SERVICE_WORKER_OK: + return "Operation has succeeded"; + case SERVICE_WORKER_ERROR_FAILED: + return "Operation has failed (unknown reason)"; + case SERVICE_WORKER_ERROR_ABORT: + return "Operation has been aborted"; + case SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND: + return "Could not find a renderer process to run a service worker"; + case SERVICE_WORKER_ERROR_NOT_FOUND: + return "Not found"; + case SERVICE_WORKER_ERROR_EXISTS: + return "Already exists"; + case SERVICE_WORKER_ERROR_START_WORKER_FAILED: + return "ServiceWorker cannot be started"; + case SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED: + return "ServiceWorker failed to install"; + case SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED: + return "ServiceWorker failed to activate"; + case SERVICE_WORKER_ERROR_IPC_FAILED: + return "IPC connection was closed or IPC error has occured"; + } + NOTREACHED(); + return ""; +} + +} // namespace content diff --git a/chromium/content/common/service_worker/service_worker_status_code.h b/chromium/content/common/service_worker/service_worker_status_code.h new file mode 100644 index 00000000000..a0245e48e10 --- /dev/null +++ b/chromium/content/common/service_worker/service_worker_status_code.h @@ -0,0 +1,52 @@ +// Copyright 2014 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_STATUS_CODE_H_ +#define CONTENT_COMMON_SERVICE_WORKER_SERVICE_WORKER_STATUS_CODE_H_ + +#include "content/common/content_export.h" + +namespace content { + +// Generic service worker operation statuses. +enum ServiceWorkerStatusCode { + // Operation succeeded. + SERVICE_WORKER_OK, + + // Generic operation error (more specific error code should be used in + // general). + SERVICE_WORKER_ERROR_FAILED, + + // Operation was aborted (e.g. due to context or child process shutdown). + SERVICE_WORKER_ERROR_ABORT, + + // Starting a new service worker script context failed. + SERVICE_WORKER_ERROR_START_WORKER_FAILED, + + // Could not find a renderer process to run a service worker. + SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND, + + // Generic error code to indicate the specified item is not found. + SERVICE_WORKER_ERROR_NOT_FOUND, + + // Generic error code to indicate the specified item already exists. + SERVICE_WORKER_ERROR_EXISTS, + + // Install event handling failed. + SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED, + + // Activate event handling failed. + SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED, + + // Sending an IPC to the worker failed (often due to child process is + // terminated). + SERVICE_WORKER_ERROR_IPC_FAILED, +}; + +CONTENT_EXPORT const char* ServiceWorkerStatusToString( + ServiceWorkerStatusCode code); + +} // namespace content + +#endif // CONTENT_COMMON_SERVICE_WORKER_SERVICE_WORKER_STATUS_CODE_H_ diff --git a/chromium/content/common/service_worker/service_worker_types.cc b/chromium/content/common/service_worker/service_worker_types.cc new file mode 100644 index 00000000000..ce5cd7aee07 --- /dev/null +++ b/chromium/content/common/service_worker/service_worker_types.cc @@ -0,0 +1,41 @@ +// Copyright 2014 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_types.h" + +namespace content { + +ServiceWorkerFetchRequest::ServiceWorkerFetchRequest() {} + +ServiceWorkerFetchRequest::ServiceWorkerFetchRequest( + const GURL& url, + const std::string& method, + const std::map<std::string, std::string>& headers) + : url(url), + method(method), + headers(headers) { +} + +ServiceWorkerFetchRequest::~ServiceWorkerFetchRequest() {} + +ServiceWorkerResponse::ServiceWorkerResponse() : status_code(0) {} + +ServiceWorkerResponse::ServiceWorkerResponse( + int status_code, + const std::string& status_text, + const std::map<std::string, std::string>& headers, + const std::string& blob_uuid) + : status_code(status_code), + status_text(status_text), + headers(headers), + blob_uuid(blob_uuid) { +} + +ServiceWorkerResponse::~ServiceWorkerResponse() {} + +ServiceWorkerObjectInfo::ServiceWorkerObjectInfo() + : handle_id(kInvalidServiceWorkerHandleId), + state(blink::WebServiceWorkerStateUnknown) {} + +} // namespace content diff --git a/chromium/content/common/service_worker/service_worker_types.h b/chromium/content/common/service_worker/service_worker_types.h new file mode 100644 index 00000000000..8f49f9a5635 --- /dev/null +++ b/chromium/content/common/service_worker/service_worker_types.h @@ -0,0 +1,85 @@ +// Copyright 2014 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_TYPES_H_ +#define CONTENT_COMMON_SERVICE_WORKER_SERVICE_WORKER_TYPES_H_ + +#include <map> +#include <string> + +#include "base/basictypes.h" +#include "content/common/content_export.h" +#include "third_party/WebKit/public/platform/WebServiceWorkerState.h" +#include "url/gurl.h" + +// This file is to have common definitions that are to be shared by +// browser and child process. + +namespace content { + +// Indicates invalid request ID (i.e. the sender does not expect it gets +// response for the message) for messaging between browser process +// and embedded worker. +const static int kInvalidServiceWorkerRequestId = -1; + +// Constants for invalid identifiers. +const static int kInvalidServiceWorkerHandleId = -1; +const static int kInvalidServiceWorkerProviderId = -1; +const static int64 kInvalidServiceWorkerRegistrationId = -1; +const static int64 kInvalidServiceWorkerVersionId = -1; +const static int64 kInvalidServiceWorkerResourceId = -1; +const static int64 kInvalidServiceWorkerResponseId = -1; + +// To dispatch fetch request from browser to child process. +// TODO(kinuko): This struct will definitely need more fields and +// we'll probably want to have response struct/class too. +struct CONTENT_EXPORT ServiceWorkerFetchRequest { + ServiceWorkerFetchRequest(); + ServiceWorkerFetchRequest( + const GURL& url, + const std::string& method, + const std::map<std::string, std::string>& headers); + ~ServiceWorkerFetchRequest(); + + GURL url; + std::string method; + std::map<std::string, std::string> headers; +}; + +// Indicates how the service worker handled a fetch event. +enum ServiceWorkerFetchEventResult { + // Browser should fallback to native fetch. + SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, + // Service worker provided a ServiceWorkerResponse. + SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, + SERVICE_WORKER_FETCH_EVENT_LAST = SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE +}; + +// Represents a response to a fetch. +struct CONTENT_EXPORT ServiceWorkerResponse { + ServiceWorkerResponse(); + ServiceWorkerResponse(int status_code, + const std::string& status_text, + const std::map<std::string, std::string>& headers, + const std::string& blob_uuid); + ~ServiceWorkerResponse(); + + int status_code; + std::string status_text; + std::map<std::string, std::string> headers; + std::string blob_uuid; +}; + +// Represents initialization info for a WebServiceWorker object. +struct CONTENT_EXPORT ServiceWorkerObjectInfo { + ServiceWorkerObjectInfo(); + int handle_id; + GURL scope; + GURL url; + blink::WebServiceWorkerState state; +}; + +} // namespace content + +#endif // CONTENT_COMMON_SERVICE_WORKER_SERVICE_WORKER_TYPES_H_ |