Home | History | Annotate | Download | only in common
      1 // Copyright (c) 2012 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 // Defines messages between the browser and worker process, as well as between
      6 // the renderer and worker process.
      7 
      8 // Multiply-included message file, hence no include guard.
      9 
     10 #include <string>
     11 #include <utility>
     12 #include <vector>
     13 
     14 #include "base/basictypes.h"
     15 #include "base/strings/string16.h"
     16 #include "content/common/content_export.h"
     17 #include "ipc/ipc_message_macros.h"
     18 #include "ipc/ipc_message_utils.h"
     19 #include "third_party/WebKit/public/web/WebContentSecurityPolicy.h"
     20 #include "url/gurl.h"
     21 
     22 // Singly-included section, not converted.
     23 #ifndef CONTENT_COMMON_WORKER_MESSAGES_H_
     24 #define CONTENT_COMMON_WORKER_MESSAGES_H_
     25 
     26 typedef std::pair<string16, std::vector<int> > QueuedMessage;
     27 
     28 #endif  // CONTENT_COMMON_WORKER_MESSAGES_H_
     29 
     30 #undef IPC_MESSAGE_EXPORT
     31 #define IPC_MESSAGE_EXPORT CONTENT_EXPORT
     32 #define IPC_MESSAGE_START WorkerMsgStart
     33 
     34 // Parameters structure for WorkerHostMsg_PostConsoleMessageToWorkerObject,
     35 // which has too many data parameters to be reasonably put in a predefined
     36 // IPC message. The data members directly correspond to parameters of
     37 // WebWorkerClient::postConsoleMessageToWorkerObject()
     38 IPC_STRUCT_BEGIN(WorkerHostMsg_PostConsoleMessageToWorkerObject_Params)
     39   IPC_STRUCT_MEMBER(int, source_identifier)
     40   IPC_STRUCT_MEMBER(int, message_type)
     41   IPC_STRUCT_MEMBER(int, message_level)
     42   IPC_STRUCT_MEMBER(string16, message)
     43   IPC_STRUCT_MEMBER(int, line_number)
     44   IPC_STRUCT_MEMBER(string16, source_url)
     45 IPC_STRUCT_END()
     46 
     47 // Parameter structure for WorkerProcessMsg_CreateWorker.
     48 IPC_STRUCT_BEGIN(WorkerProcessMsg_CreateWorker_Params)
     49   IPC_STRUCT_MEMBER(GURL, url)
     50   IPC_STRUCT_MEMBER(string16, name)
     51   IPC_STRUCT_MEMBER(int, route_id)
     52   IPC_STRUCT_MEMBER(int, creator_process_id)
     53   IPC_STRUCT_MEMBER(int64, shared_worker_appcache_id)
     54 IPC_STRUCT_END()
     55 
     56 IPC_ENUM_TRAITS(WebKit::WebContentSecurityPolicyType)
     57 
     58 //-----------------------------------------------------------------------------
     59 // WorkerProcess messages
     60 // These are messages sent from the browser to the worker process.
     61 IPC_MESSAGE_CONTROL1(WorkerProcessMsg_CreateWorker,
     62                      WorkerProcessMsg_CreateWorker_Params)
     63 
     64 // Note: these Message Port related messages can also be sent to the
     65 // renderer process.  Putting them here since we don't have a shared place
     66 // like common_messages_internal.h
     67 IPC_MESSAGE_ROUTED3(WorkerProcessMsg_Message,
     68                     string16 /* message */,
     69                     std::vector<int> /* sent_message_port_ids */,
     70                     std::vector<int> /* new_routing_ids */)
     71 
     72 // Tells the Message Port Channel object that there are no more in-flight
     73 // messages arriving.
     74 IPC_MESSAGE_ROUTED0(WorkerProcessMsg_MessagesQueued)
     75 
     76 
     77 //-----------------------------------------------------------------------------
     78 // WorkerProcessHost messages
     79 // These are messages sent from the worker process to the browser process.
     80 
     81 // Note: these Message Port related messages can also be sent out from the
     82 // renderer process.  Putting them here since we don't have a shared place
     83 // like common_messages_internal.h
     84 
     85 // Creates a new Message Port Channel object.  The first paramaeter is the
     86 // message port channel's routing id in this process.  The second parameter
     87 // is the process-wide-unique identifier for that port.
     88 IPC_SYNC_MESSAGE_CONTROL0_2(WorkerProcessHostMsg_CreateMessagePort,
     89                             int /* route_id */,
     90                             int /* message_port_id */)
     91 
     92 // Sent when a Message Port Channel object is destroyed.
     93 IPC_MESSAGE_CONTROL1(WorkerProcessHostMsg_DestroyMessagePort,
     94                      int /* message_port_id */)
     95 
     96 // Sends a message to a message port.  Optionally sends a message port as
     97 // as well if sent_message_port_id != MSG_ROUTING_NONE.
     98 IPC_MESSAGE_CONTROL3(WorkerProcessHostMsg_PostMessage,
     99                      int /* sender_message_port_id */,
    100                      string16 /* message */,
    101                      std::vector<int> /* sent_message_port_ids */)
    102 
    103 // Causes messages sent to the remote port to be delivered to this local port.
    104 IPC_MESSAGE_CONTROL2(WorkerProcessHostMsg_Entangle,
    105                      int /* local_message_port_id */,
    106                      int /* remote_message_port_id */)
    107 
    108 // Causes the browser to queue messages sent to this port until the the port
    109 // has made sure that all in-flight messages were routed to the new
    110 // destination.
    111 IPC_MESSAGE_CONTROL1(WorkerProcessHostMsg_QueueMessages,
    112                      int /* message_port_id */)
    113 
    114 // Sends the browser all the queued messages that arrived at this message port
    115 // after it was sent in a postMessage call.
    116 // NOTE: MSVS can't compile the macro if std::vector<std::pair<string16, int> >
    117 // is used, so we typedef it in worker_messages.h.
    118 IPC_MESSAGE_CONTROL2(WorkerProcessHostMsg_SendQueuedMessages,
    119                      int /* message_port_id */,
    120                      std::vector<QueuedMessage> /* queued_messages */)
    121 
    122 // Sent by the worker process to check whether access to web databases is
    123 // allowed.
    124 IPC_SYNC_MESSAGE_CONTROL5_1(WorkerProcessHostMsg_AllowDatabase,
    125                             int /* worker_route_id */,
    126                             GURL /* origin url */,
    127                             string16 /* database name */,
    128                             string16 /* database display name */,
    129                             unsigned long /* estimated size */,
    130                             bool /* result */)
    131 
    132 // Sent by the worker process to check whether access to file system is allowed.
    133 IPC_SYNC_MESSAGE_CONTROL2_1(WorkerProcessHostMsg_AllowFileSystem,
    134                             int /* worker_route_id */,
    135                             GURL /* origin url */,
    136                             bool /* result */)
    137 
    138 // Sent by the worker process to check whether access to IndexedDB is allowed.
    139 IPC_SYNC_MESSAGE_CONTROL3_1(WorkerProcessHostMsg_AllowIndexedDB,
    140                             int /* worker_route_id */,
    141                             GURL /* origin url */,
    142                             string16 /* database name */,
    143                             bool /* result */)
    144 
    145 //-----------------------------------------------------------------------------
    146 // Worker messages
    147 // These are messages sent from the renderer process to the worker process.
    148 IPC_MESSAGE_ROUTED5(WorkerMsg_StartWorkerContext,
    149                     GURL /* url */,
    150                     string16  /* user_agent */,
    151                     string16  /* source_code */,
    152                     string16  /* content_security_policy */,
    153                     WebKit::WebContentSecurityPolicyType)
    154 
    155 IPC_MESSAGE_ROUTED0(WorkerMsg_TerminateWorkerContext)
    156 
    157 IPC_MESSAGE_ROUTED3(WorkerMsg_PostMessage,
    158                     string16  /* message */,
    159                     std::vector<int>  /* sent_message_port_ids */,
    160                     std::vector<int>  /* new_routing_ids */)
    161 
    162 IPC_MESSAGE_ROUTED2(WorkerMsg_Connect,
    163                     int /* sent_message_port_id */,
    164                     int /* routing_id */)
    165 
    166 IPC_MESSAGE_ROUTED0(WorkerMsg_WorkerObjectDestroyed)
    167 
    168 
    169 //-----------------------------------------------------------------------------
    170 // WorkerHost messages
    171 // These are messages sent from the worker process to the renderer process.
    172 // WorkerMsg_PostMessage is also sent here.
    173 IPC_MESSAGE_ROUTED3(WorkerHostMsg_PostExceptionToWorkerObject,
    174                     string16  /* error_message */,
    175                     int  /* line_number */,
    176                     string16  /* source_url*/)
    177 
    178 IPC_MESSAGE_ROUTED1(WorkerHostMsg_PostConsoleMessageToWorkerObject,
    179                     WorkerHostMsg_PostConsoleMessageToWorkerObject_Params)
    180 
    181 IPC_MESSAGE_ROUTED1(WorkerHostMsg_ConfirmMessageFromWorkerObject,
    182                     bool /* bool has_pending_activity */)
    183 
    184 IPC_MESSAGE_ROUTED1(WorkerHostMsg_ReportPendingActivity,
    185                     bool /* bool has_pending_activity */)
    186 
    187 IPC_MESSAGE_CONTROL1(WorkerHostMsg_WorkerContextClosed,
    188                      int /* worker_route_id */)
    189 IPC_MESSAGE_ROUTED0(WorkerHostMsg_WorkerContextDestroyed)
    190