1// Copyright (c) 2011 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// IPC messages for extensions. 6// Multiply-included message file, hence no include guard. 7 8#include "base/shared_memory.h" 9#include "base/values.h" 10#include "chrome/common/extensions/extension.h" 11#include "chrome/common/extensions/extension_extent.h" 12#include "chrome/common/extensions/url_pattern.h" 13#include "chrome/common/web_apps.h" 14#include "ipc/ipc_message_macros.h" 15 16#define IPC_MESSAGE_START ExtensionMsgStart 17 18// Parameters structure for ExtensionHostMsg_Request. 19IPC_STRUCT_BEGIN(ExtensionHostMsg_DomMessage_Params) 20 // Message name. 21 IPC_STRUCT_MEMBER(std::string, name) 22 23 // List of message arguments. 24 IPC_STRUCT_MEMBER(ListValue, arguments) 25 26 // URL of the frame request was sent from. 27 IPC_STRUCT_MEMBER(GURL, source_url) 28 29 // Unique request id to match requests and responses. 30 IPC_STRUCT_MEMBER(int, request_id) 31 32 // True if request has a callback specified. 33 IPC_STRUCT_MEMBER(bool, has_callback) 34 35 // True if request is executed in response to an explicit user gesture. 36 IPC_STRUCT_MEMBER(bool, user_gesture) 37IPC_STRUCT_END() 38 39// Allows an extension to execute code in a tab. 40IPC_STRUCT_BEGIN(ExtensionMsg_ExecuteCode_Params) 41 // The extension API request id, for responding. 42 IPC_STRUCT_MEMBER(int, request_id) 43 44 // The ID of the requesting extension. To know which isolated world to 45 // execute the code inside of. 46 IPC_STRUCT_MEMBER(std::string, extension_id) 47 48 // Whether the code is JavaScript or CSS. 49 IPC_STRUCT_MEMBER(bool, is_javascript) 50 51 // String of code to execute. 52 IPC_STRUCT_MEMBER(std::string, code) 53 54 // Whether to inject into all frames, or only the root frame. 55 IPC_STRUCT_MEMBER(bool, all_frames) 56 57 // Whether to execute code in the main world (as opposed to an isolated 58 // world). 59 IPC_STRUCT_MEMBER(bool, in_main_world) 60IPC_STRUCT_END() 61 62IPC_STRUCT_TRAITS_BEGIN(WebApplicationInfo::IconInfo) 63 IPC_STRUCT_TRAITS_MEMBER(url) 64 IPC_STRUCT_TRAITS_MEMBER(width) 65 IPC_STRUCT_TRAITS_MEMBER(height) 66 IPC_STRUCT_TRAITS_MEMBER(data) 67IPC_STRUCT_TRAITS_END() 68 69IPC_STRUCT_TRAITS_BEGIN(WebApplicationInfo) 70 IPC_STRUCT_TRAITS_MEMBER(title) 71 IPC_STRUCT_TRAITS_MEMBER(description) 72 IPC_STRUCT_TRAITS_MEMBER(app_url) 73 IPC_STRUCT_TRAITS_MEMBER(icons) 74 IPC_STRUCT_TRAITS_MEMBER(permissions) 75 IPC_STRUCT_TRAITS_MEMBER(launch_container) 76IPC_STRUCT_TRAITS_END() 77 78// Singly-included section for custom IPC traits. 79#ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGES_H_ 80#define CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGES_H_ 81 82// IPC_MESSAGE macros choke on extra , in the std::map, when expanding. We need 83// to typedef it to avoid that. 84// Substitution map for l10n messages. 85typedef std::map<std::string, std::string> SubstitutionMap; 86 87struct ExtensionMsg_Loaded_Params { 88 ExtensionMsg_Loaded_Params(); 89 ~ExtensionMsg_Loaded_Params(); 90 explicit ExtensionMsg_Loaded_Params(const Extension* extension); 91 92 // A copy constructor is needed because this structure can end up getting 93 // copied inside the IPC machinery on gcc <= 4.2. 94 ExtensionMsg_Loaded_Params(const ExtensionMsg_Loaded_Params& other); 95 96 // Creates a new extension from the data in this object. 97 scoped_refptr<Extension> ConvertToExtension() const; 98 99 // The subset of the extension manifest data we send to renderers. 100 scoped_ptr<DictionaryValue> manifest; 101 102 // The location the extension was installed from. 103 Extension::Location location; 104 105 // The path the extension was loaded from. This is used in the renderer only 106 // to generate the extension ID for extensions that are loaded unpacked. 107 FilePath path; 108 109 // We keep this separate so that it can be used in logging. 110 std::string id; 111}; 112 113namespace IPC { 114 115template <> 116struct ParamTraits<URLPattern> { 117 typedef URLPattern param_type; 118 static void Write(Message* m, const param_type& p); 119 static bool Read(const Message* m, void** iter, param_type* p); 120 static void Log(const param_type& p, std::string* l); 121}; 122 123template <> 124struct ParamTraits<ExtensionExtent> { 125 typedef ExtensionExtent param_type; 126 static void Write(Message* m, const param_type& p); 127 static bool Read(const Message* m, void** iter, param_type* p); 128 static void Log(const param_type& p, std::string* l); 129}; 130 131template <> 132struct ParamTraits<ExtensionMsg_Loaded_Params> { 133 typedef ExtensionMsg_Loaded_Params param_type; 134 static void Write(Message* m, const param_type& p); 135 static bool Read(const Message* m, void** iter, param_type* p); 136 static void Log(const param_type& p, std::string* l); 137}; 138 139} // namespace IPC 140 141#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGES_H_ 142 143// Messages sent from the browser to the renderer. 144 145// The browser sends this message in response to all extension api calls. 146IPC_MESSAGE_ROUTED4(ExtensionMsg_Response, 147 int /* request_id */, 148 bool /* success */, 149 std::string /* response */, 150 std::string /* error */) 151 152// This message is optionally routed. If used as a control message, it 153// will call a javascript function in every registered context in the 154// target process. If routed, it will be restricted to the contexts that 155// are part of the target RenderView. 156// If |extension_id| is non-empty, the function will be invoked only in 157// contexts owned by the extension. |args| is a list of primitive Value types 158// that are passed to the function. 159IPC_MESSAGE_ROUTED4(ExtensionMsg_MessageInvoke, 160 std::string /* extension_id */, 161 std::string /* function_name */, 162 ListValue /* args */, 163 GURL /* event URL */) 164 165// Tell the renderer process all known extension function names. 166IPC_MESSAGE_CONTROL1(ExtensionMsg_SetFunctionNames, 167 std::vector<std::string>) 168 169// TODO(aa): SetAPIPermissions, SetHostPermissions, and possibly 170// UpdatePageActions should be replaced with just sending additional data in 171// ExtensionLoaded. See: crbug.com/70516. 172 173// Tell the renderer process which permissions the given extension has. See 174// Extension::Permissions for which elements correspond to which permissions. 175IPC_MESSAGE_CONTROL2(ExtensionMsg_SetAPIPermissions, 176 std::string /* extension_id */, 177 std::set<std::string> /* permissions */) 178 179// Tell the renderer process which host permissions the given extension has. 180IPC_MESSAGE_CONTROL2(ExtensionMsg_SetHostPermissions, 181 GURL /* source extension's origin */, 182 /* URLPatterns the extension can access */ 183 std::vector<URLPattern>) 184 185// Tell the renderer process all known page action ids for a particular 186// extension. 187IPC_MESSAGE_CONTROL2(ExtensionMsg_UpdatePageActions, 188 std::string /* extension_id */, 189 std::vector<std::string> /* page_action_ids */) 190 191// Notifies the renderer that an extension was loaded in the browser. 192IPC_MESSAGE_CONTROL1(ExtensionMsg_Loaded, 193 ExtensionMsg_Loaded_Params) 194 195// Notifies the renderer that an extension was unloaded in the browser. 196IPC_MESSAGE_CONTROL1(ExtensionMsg_Unloaded, 197 std::string) 198 199// Updates the scripting whitelist for extensions in the render process. This is 200// only used for testing. 201IPC_MESSAGE_CONTROL1(ExtensionMsg_SetScriptingWhitelist, 202 Extension::ScriptingWhitelist /* extenison ids */) 203 204// Notification that renderer should run some JavaScript code. 205IPC_MESSAGE_ROUTED1(ExtensionMsg_ExecuteCode, 206 ExtensionMsg_ExecuteCode_Params) 207 208// Notification that the user scripts have been updated. It has one 209// SharedMemoryHandle argument consisting of the pickled script data. This 210// handle is valid in the context of the renderer. 211IPC_MESSAGE_CONTROL1(ExtensionMsg_UpdateUserScripts, 212 base::SharedMemoryHandle) 213 214// Requests application info for the page. The renderer responds back with 215// ExtensionHostMsg_DidGetApplicationInfo. 216IPC_MESSAGE_ROUTED1(ExtensionMsg_GetApplicationInfo, 217 int32 /*page_id*/) 218 219// Messages sent from the renderer to the browser. 220 221// A renderer sends this message when an extension process starts an API 222// request. The browser will always respond with a ExtensionMsg_Response. 223IPC_MESSAGE_ROUTED1(ExtensionHostMsg_Request, 224 ExtensionHostMsg_DomMessage_Params) 225 226// Notify the browser that the given extension added a listener to an event. 227IPC_MESSAGE_CONTROL2(ExtensionHostMsg_AddListener, 228 std::string /* extension_id */, 229 std::string /* name */) 230 231// Notify the browser that the given extension removed a listener from an 232// event. 233IPC_MESSAGE_CONTROL2(ExtensionHostMsg_RemoveListener, 234 std::string /* extension_id */, 235 std::string /* name */) 236 237// Open a channel to all listening contexts owned by the extension with 238// the given ID. This always returns a valid port ID which can be used for 239// sending messages. If an error occurred, the opener will be notified 240// asynchronously. 241IPC_SYNC_MESSAGE_CONTROL4_1(ExtensionHostMsg_OpenChannelToExtension, 242 int /* routing_id */, 243 std::string /* source_extension_id */, 244 std::string /* target_extension_id */, 245 std::string /* channel_name */, 246 int /* port_id */) 247 248// Get a port handle to the given tab. The handle can be used for sending 249// messages to the extension. 250IPC_SYNC_MESSAGE_CONTROL4_1(ExtensionHostMsg_OpenChannelToTab, 251 int /* routing_id */, 252 int /* tab_id */, 253 std::string /* extension_id */, 254 std::string /* channel_name */, 255 int /* port_id */) 256 257// Send a message to an extension process. The handle is the value returned 258// by ViewHostMsg_OpenChannelTo*. 259IPC_MESSAGE_ROUTED2(ExtensionHostMsg_PostMessage, 260 int /* port_id */, 261 std::string /* message */) 262 263// Send a message to an extension process. The handle is the value returned 264// by ViewHostMsg_OpenChannelTo*. 265IPC_MESSAGE_CONTROL1(ExtensionHostMsg_CloseChannel, 266 int /* port_id */) 267 268// Used to get the extension message bundle. 269IPC_SYNC_MESSAGE_CONTROL1_1(ExtensionHostMsg_GetMessageBundle, 270 std::string /* extension id */, 271 SubstitutionMap /* message bundle */) 272 273// Send from the renderer to the browser to return the script running result. 274IPC_MESSAGE_ROUTED3(ExtensionHostMsg_ExecuteCodeFinished, 275 int /* request id */, 276 bool /* whether the script ran successfully */, 277 std::string /* error message */) 278 279IPC_MESSAGE_ROUTED2(ExtensionHostMsg_DidGetApplicationInfo, 280 int32 /* page_id */, 281 WebApplicationInfo) 282 283// Sent by the renderer to implement chrome.app.installApplication(). 284IPC_MESSAGE_ROUTED1(ExtensionHostMsg_InstallApplication, 285 WebApplicationInfo) 286