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