Home | History | Annotate | Download | only in service_worker
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Message definition file, included multiple times, hence no include guard.
      6 
      7 #include "base/strings/string16.h"
      8 #include "content/common/service_worker/service_worker_status_code.h"
      9 #include "content/common/service_worker/service_worker_types.h"
     10 #include "ipc/ipc_message_macros.h"
     11 #include "ipc/ipc_param_traits.h"
     12 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h"
     13 #include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h"
     14 #include "url/gurl.h"
     15 
     16 #undef IPC_MESSAGE_EXPORT
     17 #define IPC_MESSAGE_EXPORT CONTENT_EXPORT
     18 
     19 #define IPC_MESSAGE_START ServiceWorkerMsgStart
     20 
     21 IPC_ENUM_TRAITS_MAX_VALUE(blink::WebServiceWorkerError::ErrorType,
     22                           blink::WebServiceWorkerError::ErrorTypeLast)
     23 
     24 IPC_ENUM_TRAITS_MAX_VALUE(blink::WebServiceWorkerEventResult,
     25                           blink::WebServiceWorkerEventResultLast)
     26 
     27 IPC_ENUM_TRAITS_MAX_VALUE(blink::WebServiceWorkerState,
     28                           blink::WebServiceWorkerStateLast)
     29 
     30 IPC_STRUCT_TRAITS_BEGIN(content::ServiceWorkerFetchRequest)
     31   IPC_STRUCT_TRAITS_MEMBER(url)
     32   IPC_STRUCT_TRAITS_MEMBER(method)
     33   IPC_STRUCT_TRAITS_MEMBER(headers)
     34 IPC_STRUCT_TRAITS_END()
     35 
     36 IPC_ENUM_TRAITS_MAX_VALUE(content::ServiceWorkerFetchEventResult,
     37                           content::SERVICE_WORKER_FETCH_EVENT_LAST)
     38 
     39 IPC_STRUCT_TRAITS_BEGIN(content::ServiceWorkerResponse)
     40   IPC_STRUCT_TRAITS_MEMBER(status_code)
     41   IPC_STRUCT_TRAITS_MEMBER(status_text)
     42   IPC_STRUCT_TRAITS_MEMBER(headers)
     43   IPC_STRUCT_TRAITS_MEMBER(blob_uuid)
     44 IPC_STRUCT_TRAITS_END()
     45 
     46 IPC_STRUCT_TRAITS_BEGIN(content::ServiceWorkerObjectInfo)
     47   IPC_STRUCT_TRAITS_MEMBER(handle_id)
     48   IPC_STRUCT_TRAITS_MEMBER(scope)
     49   IPC_STRUCT_TRAITS_MEMBER(url)
     50   IPC_STRUCT_TRAITS_MEMBER(state)
     51 IPC_STRUCT_TRAITS_END()
     52 
     53 //---------------------------------------------------------------------------
     54 // Messages sent from the child process to the browser.
     55 
     56 IPC_MESSAGE_CONTROL5(ServiceWorkerHostMsg_RegisterServiceWorker,
     57                      int /* thread_id */,
     58                      int /* request_id */,
     59                      int /* provider_id */,
     60                      GURL /* scope */,
     61                      GURL /* script_url */)
     62 
     63 IPC_MESSAGE_CONTROL4(ServiceWorkerHostMsg_UnregisterServiceWorker,
     64                      int /* thread_id */,
     65                      int /* request_id */,
     66                      int /* provider_id */,
     67                      GURL /* scope (url pattern) */)
     68 
     69 // Sends a 'message' event to a service worker (renderer->browser).
     70 IPC_MESSAGE_CONTROL3(ServiceWorkerHostMsg_PostMessageToWorker,
     71                      int /* handle_id */,
     72                      base::string16 /* message */,
     73                      std::vector<int> /* sent_message_port_ids */)
     74 
     75 // Informs the browser of a new ServiceWorkerProvider in the child process,
     76 // |provider_id| is unique within its child process.
     77 IPC_MESSAGE_CONTROL1(ServiceWorkerHostMsg_ProviderCreated,
     78                      int /* provider_id */)
     79 
     80 // Informs the browser of a ServiceWorkerProvider being destroyed.
     81 IPC_MESSAGE_CONTROL1(ServiceWorkerHostMsg_ProviderDestroyed,
     82                      int /* provider_id */)
     83 
     84 // Increments and decrements the ServiceWorker object's reference
     85 // counting in the browser side. The ServiceWorker object is created
     86 // with ref-count==1 initially.
     87 IPC_MESSAGE_CONTROL1(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount,
     88                      int /* handle_id */)
     89 IPC_MESSAGE_CONTROL1(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount,
     90                      int /* handle_id */)
     91 
     92 // Informs the browser that |provider_id| is associated
     93 // with a service worker script running context and
     94 // |version_id| identifies which ServcieWorkerVersion.
     95 IPC_MESSAGE_CONTROL2(ServiceWorkerHostMsg_SetVersionId,
     96                      int /* provider_id */,
     97                      int64 /* version_id */)
     98 
     99 // Informs the browser that event handling has finished.
    100 // Routed to the target ServiceWorkerVersion.
    101 IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_InstallEventFinished,
    102                     int /* request_id */,
    103                     blink::WebServiceWorkerEventResult)
    104 IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_ActivateEventFinished,
    105                     int /* request_id */,
    106                     blink::WebServiceWorkerEventResult);
    107 IPC_MESSAGE_ROUTED3(ServiceWorkerHostMsg_FetchEventFinished,
    108                     int /* request_id */,
    109                     content::ServiceWorkerFetchEventResult,
    110                     content::ServiceWorkerResponse)
    111 IPC_MESSAGE_ROUTED1(ServiceWorkerHostMsg_SyncEventFinished,
    112                     int /* request_id */)
    113 IPC_MESSAGE_ROUTED1(ServiceWorkerHostMsg_PushEventFinished,
    114                     int /* request_id */)
    115 
    116 // Asks the browser to retrieve documents controlled by the sender
    117 // ServiceWorker.
    118 IPC_MESSAGE_ROUTED1(ServiceWorkerHostMsg_GetClientDocuments,
    119                     int /* request_id */)
    120 
    121 // Sends a 'message' event to a client document (renderer->browser).
    122 IPC_MESSAGE_ROUTED3(ServiceWorkerHostMsg_PostMessageToDocument,
    123                     int /* client_id */,
    124                     base::string16 /* message */,
    125                     std::vector<int> /* sent_message_port_ids */)
    126 
    127 //---------------------------------------------------------------------------
    128 // Messages sent from the browser to the child process.
    129 //
    130 // NOTE: All ServiceWorkerMsg messages not sent via EmbeddedWorker must have
    131 // a thread_id as their first field so that ServiceWorkerMessageFilter can
    132 // extract it and dispatch the message to the correct ServiceWorkerDispatcher
    133 // on the correct thread.
    134 
    135 // Response to ServiceWorkerMsg_RegisterServiceWorker.
    136 IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_ServiceWorkerRegistered,
    137                      int /* thread_id */,
    138                      int /* request_id */,
    139                      content::ServiceWorkerObjectInfo)
    140 
    141 // Response to ServiceWorkerMsg_UnregisterServiceWorker.
    142 IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_ServiceWorkerUnregistered,
    143                      int /* thread_id */,
    144                      int /* request_id */)
    145 
    146 // Sent when any kind of registration error occurs during a
    147 // RegisterServiceWorker / UnregisterServiceWorker handler above.
    148 IPC_MESSAGE_CONTROL4(ServiceWorkerMsg_ServiceWorkerRegistrationError,
    149                      int /* thread_id */,
    150                      int /* request_id */,
    151                      blink::WebServiceWorkerError::ErrorType /* code */,
    152                      base::string16 /* message */)
    153 
    154 // Informs the child process that the ServiceWorker's state has changed.
    155 IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_ServiceWorkerStateChanged,
    156                      int /* thread_id */,
    157                      int /* handle_id */,
    158                      blink::WebServiceWorkerState)
    159 
    160 // Tells the child process to set the waiting ServiceWorker for the given
    161 // provider.
    162 IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_SetWaitingServiceWorker,
    163                      int /* thread_id */,
    164                      int /* provider_id */,
    165                      content::ServiceWorkerObjectInfo)
    166 
    167 // Tells the child process to set the current ServiceWorker for the given
    168 // provider.
    169 IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_SetCurrentServiceWorker,
    170                      int /* thread_id */,
    171                      int /* provider_id */,
    172                      content::ServiceWorkerObjectInfo)
    173 
    174 // Sends a 'message' event to a client document (browser->renderer).
    175 IPC_MESSAGE_CONTROL5(ServiceWorkerMsg_MessageToDocument,
    176                      int /* thread_id */,
    177                      int /* provider_id */,
    178                      base::string16 /* message */,
    179                      std::vector<int> /* sent_message_port_ids */,
    180                      std::vector<int> /* new_routing_ids */)
    181 
    182 // Sent via EmbeddedWorker to dispatch events.
    183 IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_InstallEvent,
    184                      int /* request_id */,
    185                      int /* active_version_id */)
    186 IPC_MESSAGE_CONTROL1(ServiceWorkerMsg_ActivateEvent,
    187                      int /* request_id */)
    188 IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_FetchEvent,
    189                      int /* request_id */,
    190                      content::ServiceWorkerFetchRequest)
    191 IPC_MESSAGE_CONTROL1(ServiceWorkerMsg_SyncEvent,
    192                      int /* request_id */)
    193 IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_PushEvent,
    194                      int /* request_id */,
    195                      std::string /* data */)
    196 IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_MessageToWorker,
    197                      base::string16 /* message */,
    198                      std::vector<int> /* sent_message_port_ids */,
    199                      std::vector<int> /* new_routing_ids */)
    200 
    201 // Sent via EmbeddedWorker as a response of GetClientDocuments.
    202 IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_DidGetClientDocuments,
    203                      int /* request_id */,
    204                      std::vector<int> /* client_ids */)
    205