Extract SIGPIPE ignoring code to a common place.
[chromium-blink-merge.git] / chrome / common / extensions / extension_messages.h
bloba28b152e65a5472e1034cb988a24b821f53631da
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.
5 // IPC messages for extensions.
6 // Multiply-included message file, hence no include guard.
8 #include "base/shared_memory.h"
9 #include "base/values.h"
10 #include "chrome/common/extensions/draggable_region.h"
11 #include "chrome/common/extensions/extension.h"
12 #include "chrome/common/extensions/permissions/permission_set.h"
13 #include "chrome/common/extensions/permissions/socket_permission_data.h"
14 #include "chrome/common/extensions/url_pattern_set.h"
15 #include "chrome/common/view_type.h"
16 #include "chrome/common/web_apps.h"
17 #include "content/public/common/common_param_traits.h"
18 #include "extensions/common/url_pattern.h"
19 #include "googleurl/src/gurl.h"
20 #include "ipc/ipc_message_macros.h"
22 #define IPC_MESSAGE_START ExtensionMsgStart
24 IPC_ENUM_TRAITS(chrome::ViewType)
26 // Parameters structure for ExtensionHostMsg_Request.
27 IPC_STRUCT_BEGIN(ExtensionHostMsg_Request_Params)
28 // Message name.
29 IPC_STRUCT_MEMBER(std::string, name)
31 // List of message arguments.
32 IPC_STRUCT_MEMBER(ListValue, arguments)
34 // Extension ID this request was sent from. This can be empty, in the case
35 // where we expose APIs to normal web pages using the extension function
36 // system.
37 IPC_STRUCT_MEMBER(std::string, extension_id)
39 // URL of the frame the request was sent from. This isn't necessarily an
40 // extension url. Extension requests can also originate from content scripts,
41 // in which case extension_id will indicate the ID of the associated
42 // extension. Or, they can originate from hosted apps or normal web pages.
43 IPC_STRUCT_MEMBER(GURL, source_url)
45 // Web security origin of the frame the request was sent from.
46 IPC_STRUCT_MEMBER(string16, source_origin)
48 // Unique request id to match requests and responses.
49 IPC_STRUCT_MEMBER(int, request_id)
51 // True if request has a callback specified.
52 IPC_STRUCT_MEMBER(bool, has_callback)
54 // True if request is executed in response to an explicit user gesture.
55 IPC_STRUCT_MEMBER(bool, user_gesture)
56 IPC_STRUCT_END()
58 // Allows an extension to execute code in a tab.
59 IPC_STRUCT_BEGIN(ExtensionMsg_ExecuteCode_Params)
60 // The extension API request id, for responding.
61 IPC_STRUCT_MEMBER(int, request_id)
63 // The ID of the requesting extension. To know which isolated world to
64 // execute the code inside of.
65 IPC_STRUCT_MEMBER(std::string, extension_id)
67 // Whether the code is JavaScript or CSS.
68 IPC_STRUCT_MEMBER(bool, is_javascript)
70 // String of code to execute.
71 IPC_STRUCT_MEMBER(std::string, code)
73 // Whether to inject into all frames, or only the root frame.
74 IPC_STRUCT_MEMBER(bool, all_frames)
76 // When to inject the code.
77 IPC_STRUCT_MEMBER(int, run_at)
79 // Whether to execute code in the main world (as opposed to an isolated
80 // world).
81 IPC_STRUCT_MEMBER(bool, in_main_world)
82 IPC_STRUCT_END()
84 IPC_STRUCT_TRAITS_BEGIN(WebApplicationInfo::IconInfo)
85 IPC_STRUCT_TRAITS_MEMBER(url)
86 IPC_STRUCT_TRAITS_MEMBER(width)
87 IPC_STRUCT_TRAITS_MEMBER(height)
88 IPC_STRUCT_TRAITS_MEMBER(data)
89 IPC_STRUCT_TRAITS_END()
91 IPC_STRUCT_TRAITS_BEGIN(WebApplicationInfo)
92 IPC_STRUCT_TRAITS_MEMBER(title)
93 IPC_STRUCT_TRAITS_MEMBER(description)
94 IPC_STRUCT_TRAITS_MEMBER(app_url)
95 IPC_STRUCT_TRAITS_MEMBER(icons)
96 IPC_STRUCT_TRAITS_MEMBER(permissions)
97 IPC_STRUCT_TRAITS_MEMBER(launch_container)
98 IPC_STRUCT_TRAITS_MEMBER(is_offline_enabled)
99 IPC_STRUCT_TRAITS_END()
101 IPC_STRUCT_TRAITS_BEGIN(extensions::DraggableRegion)
102 IPC_STRUCT_TRAITS_MEMBER(draggable)
103 IPC_STRUCT_TRAITS_MEMBER(bounds)
104 IPC_STRUCT_TRAITS_END()
106 // Singly-included section for custom IPC traits.
107 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGES_H_
108 #define CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGES_H_
110 // IPC_MESSAGE macros choke on extra , in the std::map, when expanding. We need
111 // to typedef it to avoid that.
112 // Substitution map for l10n messages.
113 typedef std::map<std::string, std::string> SubstitutionMap;
115 // Map of extensions IDs to the executing script paths.
116 typedef std::map<std::string, std::set<std::string> > ExecutingScriptsMap;
118 struct ExtensionMsg_Loaded_Params {
119 ExtensionMsg_Loaded_Params();
120 ~ExtensionMsg_Loaded_Params();
121 explicit ExtensionMsg_Loaded_Params(const extensions::Extension* extension);
123 // Creates a new extension from the data in this object.
124 scoped_refptr<extensions::Extension> ConvertToExtension() const;
126 // The subset of the extension manifest data we send to renderers.
127 linked_ptr<DictionaryValue> manifest;
129 // The location the extension was installed from.
130 extensions::Extension::Location location;
132 // The path the extension was loaded from. This is used in the renderer only
133 // to generate the extension ID for extensions that are loaded unpacked.
134 FilePath path;
136 // The extension's active permissions.
137 extensions::APIPermissionSet apis;
138 URLPatternSet explicit_hosts;
139 URLPatternSet scriptable_hosts;
141 // We keep this separate so that it can be used in logging.
142 std::string id;
144 // Send creation flags so extension is initialized identically.
145 int creation_flags;
148 namespace IPC {
150 template <>
151 struct ParamTraits<URLPattern> {
152 typedef URLPattern param_type;
153 static void Write(Message* m, const param_type& p);
154 static bool Read(const Message* m, PickleIterator* iter, param_type* p);
155 static void Log(const param_type& p, std::string* l);
158 template <>
159 struct ParamTraits<URLPatternSet> {
160 typedef URLPatternSet param_type;
161 static void Write(Message* m, const param_type& p);
162 static bool Read(const Message* m, PickleIterator* iter, param_type* p);
163 static void Log(const param_type& p, std::string* l);
166 template <>
167 struct ParamTraits<extensions::APIPermission::ID> {
168 typedef extensions::APIPermission::ID param_type;
169 static void Write(Message* m, const param_type& p);
170 static bool Read(const Message* m, PickleIterator* iter, param_type* p);
171 static void Log(const param_type& p, std::string* l);
174 template <>
175 struct ParamTraits<extensions::APIPermission*> {
176 typedef extensions::APIPermission* param_type;
177 static void Log(const param_type& p, std::string* l);
180 template <>
181 struct ParamTraits<extensions::APIPermissionSet> {
182 typedef extensions::APIPermissionSet param_type;
183 static void Write(Message* m, const param_type& p);
184 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
185 static void Log(const param_type& p, std::string* l);
188 template <>
189 struct ParamTraits<extensions::SocketPermissionData> {
190 typedef extensions::SocketPermissionData param_type;
191 static void Write(Message* m, const param_type& p);
192 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
193 static void Log(const param_type& p, std::string* l);
196 template <>
197 struct ParamTraits<ExtensionMsg_Loaded_Params> {
198 typedef ExtensionMsg_Loaded_Params param_type;
199 static void Write(Message* m, const param_type& p);
200 static bool Read(const Message* m, PickleIterator* iter, param_type* p);
201 static void Log(const param_type& p, std::string* l);
204 } // namespace IPC
206 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGES_H_
208 // Messages sent from the browser to the renderer.
210 // The browser sends this message in response to all extension api calls. The
211 // response data (if any) is one of the base::Value subclasses, wrapped as the
212 // first element in a ListValue.
213 IPC_MESSAGE_ROUTED4(ExtensionMsg_Response,
214 int /* request_id */,
215 bool /* success */,
216 ListValue /* response wrapper (see comment above) */,
217 std::string /* error */)
219 // This message is optionally routed. If used as a control message, it
220 // will call a javascript function in every registered context in the
221 // target process. If routed, it will be restricted to the contexts that
222 // are part of the target RenderView.
223 // If |extension_id| is non-empty, the function will be invoked only in
224 // contexts owned by the extension. |args| is a list of primitive Value types
225 // that are passed to the function.
226 IPC_MESSAGE_ROUTED5(ExtensionMsg_MessageInvoke,
227 std::string /* extension_id */,
228 std::string /* function_name */,
229 ListValue /* args */,
230 GURL /* event URL */,
231 bool /* delivered as part of a user gesture */)
233 // Tell the renderer process all known extension function names.
234 IPC_MESSAGE_CONTROL1(ExtensionMsg_SetFunctionNames,
235 std::vector<std::string>)
237 // Marks an extension as 'active' in an extension process. 'Active' extensions
238 // have more privileges than other extension content that might end up running
239 // in the process (e.g. because of iframes or content scripts).
240 IPC_MESSAGE_CONTROL1(ExtensionMsg_ActivateExtension,
241 std::string /* extension_id */)
243 // Notifies the renderer that extensions were loaded in the browser.
244 IPC_MESSAGE_CONTROL1(ExtensionMsg_Loaded,
245 std::vector<ExtensionMsg_Loaded_Params>)
247 // Notifies the renderer that an extension was unloaded in the browser.
248 IPC_MESSAGE_CONTROL1(ExtensionMsg_Unloaded,
249 std::string)
251 // Updates the scripting whitelist for extensions in the render process. This is
252 // only used for testing.
253 IPC_MESSAGE_CONTROL1(ExtensionMsg_SetScriptingWhitelist,
254 // extension ids
255 extensions::Extension::ScriptingWhitelist)
257 // Notification that renderer should run some JavaScript code.
258 IPC_MESSAGE_ROUTED1(ExtensionMsg_ExecuteCode,
259 ExtensionMsg_ExecuteCode_Params)
261 // Notification that the user scripts have been updated. It has one
262 // SharedMemoryHandle argument consisting of the pickled script data. This
263 // handle is valid in the context of the renderer.
264 IPC_MESSAGE_CONTROL1(ExtensionMsg_UpdateUserScripts,
265 base::SharedMemoryHandle)
267 // Requests application info for the page. The renderer responds back with
268 // ExtensionHostMsg_DidGetApplicationInfo.
269 IPC_MESSAGE_ROUTED1(ExtensionMsg_GetApplicationInfo,
270 int32 /*page_id*/)
272 // Tell the render view which browser window it's being attached to.
273 IPC_MESSAGE_ROUTED1(ExtensionMsg_UpdateBrowserWindowId,
274 int /* id of browser window */)
276 // Tell the render view what its tab ID is.
277 IPC_MESSAGE_ROUTED1(ExtensionMsg_SetTabId,
278 int /* id of tab */)
280 // Tell the renderer to update an extension's permission set.
281 IPC_MESSAGE_CONTROL5(ExtensionMsg_UpdatePermissions,
282 int /* UpdateExtensionPermissionsInfo::REASON */,
283 std::string /* extension_id */,
284 extensions::APIPermissionSet /* permissions */,
285 URLPatternSet /* explicit_hosts */,
286 URLPatternSet /* scriptable_hosts */)
288 // Tell the renderer about new tab-specific permissions for an extension.
289 IPC_MESSAGE_CONTROL4(ExtensionMsg_UpdateTabSpecificPermissions,
290 int32 /* page_id (only relevant for the target tab) */,
291 int /* tab_id */,
292 std::string /* extension_id */,
293 URLPatternSet /* hosts */)
295 // Tell the renderer to clear tab-specific permissions for some extensions.
296 IPC_MESSAGE_CONTROL2(ExtensionMsg_ClearTabSpecificPermissions,
297 int /* tab_id */,
298 std::vector<std::string> /* extension_ids */)
300 // Tell the renderer which type this view is.
301 IPC_MESSAGE_ROUTED1(ExtensionMsg_NotifyRenderViewType,
302 chrome::ViewType /* view_type */)
304 // Deliver a message sent with ExtensionHostMsg_PostMessage.
305 IPC_MESSAGE_CONTROL3(ExtensionMsg_UsingWebRequestAPI,
306 bool /* adblock */,
307 bool /* adblock_plus */,
308 bool /* other_webrequest */)
310 // Ask the lazy background page if it is ready to unload. This is sent when the
311 // page is considered idle. The renderer will reply with the same sequence_id
312 // so that we can tell which message it is responding to.
313 IPC_MESSAGE_CONTROL2(ExtensionMsg_ShouldUnload,
314 std::string /* extension_id */,
315 int /* sequence_id */)
317 // If we complete a round of ShouldUnload->ShouldUnloadAck messages without the
318 // lazy background page becoming active again, we are ready to unload. This
319 // message tells the page to dispatch the unload event.
320 IPC_MESSAGE_CONTROL1(ExtensionMsg_Unload,
321 std::string /* extension_id */)
323 // The browser changed its mind about unloading this extension.
324 IPC_MESSAGE_CONTROL1(ExtensionMsg_CancelUnload,
325 std::string /* extension_id */)
327 // Send to renderer once the installation mentioned on
328 // ExtensionHostMsg_InlineWebstoreInstall is complete.
329 IPC_MESSAGE_ROUTED3(ExtensionMsg_InlineWebstoreInstallResponse,
330 int32 /* install id */,
331 bool /* whether the install was successful */,
332 std::string /* error */)
334 // Response to the renderer for ExtensionHostMsg_GetAppNotifyChannel.
335 IPC_MESSAGE_ROUTED3(ExtensionMsg_GetAppNotifyChannelResponse,
336 std::string /* channel_id */,
337 std::string /* error */,
338 int32 /* callback_id */)
340 // Response to the renderer for ExtensionHostMsg_GetAppInstallState.
341 IPC_MESSAGE_ROUTED2(ExtensionMsg_GetAppInstallStateResponse,
342 std::string /* state */,
343 int32 /* callback_id */)
345 // Dispatch the Port.onConnect event for message channels.
346 IPC_MESSAGE_ROUTED5(ExtensionMsg_DispatchOnConnect,
347 int /* target_port_id */,
348 std::string /* channel_name */,
349 std::string /* tab_json */,
350 std::string /* source_extension_id */,
351 std::string /* target_extension_id */)
353 // Deliver a message sent with ExtensionHostMsg_PostMessage.
354 IPC_MESSAGE_ROUTED2(ExtensionMsg_DeliverMessage,
355 int /* target_port_id */,
356 std::string /* message */)
358 // Dispatch the Port.onDisconnect event for message channels.
359 IPC_MESSAGE_ROUTED2(ExtensionMsg_DispatchOnDisconnect,
360 int /* port_id */,
361 bool /* connection_error */)
363 // Informs the renderer what channel (dev, beta, stable, etc) is running.
364 IPC_MESSAGE_CONTROL1(ExtensionMsg_SetChannel,
365 int /* channel */)
367 // Adds a logging message to the renderer's root frame DevTools console.
368 IPC_MESSAGE_ROUTED2(ExtensionMsg_AddMessageToConsole,
369 content::ConsoleMessageLevel /* level */,
370 std::string /* message */)
372 // Notify the renderer that its window has closed.
373 IPC_MESSAGE_ROUTED0(ExtensionMsg_AppWindowClosed)
375 // Messages sent from the renderer to the browser.
377 // A renderer sends this message when an extension process starts an API
378 // request. The browser will always respond with a ExtensionMsg_Response.
379 IPC_MESSAGE_ROUTED1(ExtensionHostMsg_Request,
380 ExtensionHostMsg_Request_Params)
382 // A renderer sends this message when an extension process starts an API
383 // request. The browser will always respond with a ExtensionMsg_Response.
384 IPC_MESSAGE_CONTROL2(ExtensionHostMsg_RequestForIOThread,
385 int /* routing_id */,
386 ExtensionHostMsg_Request_Params)
388 // Notify the browser that the given extension added a listener to an event.
389 IPC_MESSAGE_CONTROL2(ExtensionHostMsg_AddListener,
390 std::string /* extension_id */,
391 std::string /* name */)
393 // Notify the browser that the given extension removed a listener from an
394 // event.
395 IPC_MESSAGE_CONTROL2(ExtensionHostMsg_RemoveListener,
396 std::string /* extension_id */,
397 std::string /* name */)
399 // Notify the browser that the given extension added a listener to an event from
400 // a lazy background page.
401 IPC_MESSAGE_CONTROL2(ExtensionHostMsg_AddLazyListener,
402 std::string /* extension_id */,
403 std::string /* name */)
405 // Notify the browser that the given extension is no longer interested in
406 // receiving the given event from a lazy background page.
407 IPC_MESSAGE_CONTROL2(ExtensionHostMsg_RemoveLazyListener,
408 std::string /* extension_id */,
409 std::string /* name */)
411 // Notify the browser that the given extension added a listener to instances of
412 // the named event that satisfy the filter.
413 IPC_MESSAGE_CONTROL4(ExtensionHostMsg_AddFilteredListener,
414 std::string /* extension_id */,
415 std::string /* name */,
416 DictionaryValue /* filter */,
417 bool /* lazy */)
419 // Notify the browser that the given extension is no longer interested in
420 // instances of the named event that satisfy the filter.
421 IPC_MESSAGE_CONTROL4(ExtensionHostMsg_RemoveFilteredListener,
422 std::string /* extension_id */,
423 std::string /* name */,
424 DictionaryValue /* filter */,
425 bool /* lazy */)
427 // Notify the browser that an event has finished being dispatched.
428 IPC_MESSAGE_ROUTED0(ExtensionHostMsg_EventAck)
430 // Open a channel to all listening contexts owned by the extension with
431 // the given ID. This always returns a valid port ID which can be used for
432 // sending messages. If an error occurred, the opener will be notified
433 // asynchronously.
434 IPC_SYNC_MESSAGE_CONTROL4_1(ExtensionHostMsg_OpenChannelToExtension,
435 int /* routing_id */,
436 std::string /* source_extension_id */,
437 std::string /* target_extension_id */,
438 std::string /* channel_name */,
439 int /* port_id */)
441 IPC_SYNC_MESSAGE_CONTROL5_1(ExtensionHostMsg_OpenChannelToNativeApp,
442 int /* routing_id */,
443 std::string /* source_extension_id */,
444 std::string /* native_app_name */,
445 std::string /* channel_name */,
446 std::string /* connection_message */,
447 int /* port_id */)
449 // Get a port handle to the given tab. The handle can be used for sending
450 // messages to the extension.
451 IPC_SYNC_MESSAGE_CONTROL4_1(ExtensionHostMsg_OpenChannelToTab,
452 int /* routing_id */,
453 int /* tab_id */,
454 std::string /* extension_id */,
455 std::string /* channel_name */,
456 int /* port_id */)
458 // Send a message to an extension process. The handle is the value returned
459 // by ViewHostMsg_OpenChannelTo*.
460 IPC_MESSAGE_ROUTED2(ExtensionHostMsg_PostMessage,
461 int /* port_id */,
462 std::string /* message */)
464 // Send a message to an extension process. The handle is the value returned
465 // by ViewHostMsg_OpenChannelTo*.
466 IPC_MESSAGE_CONTROL2(ExtensionHostMsg_CloseChannel,
467 int /* port_id */,
468 bool /* connection_error */)
470 // Used to get the extension message bundle.
471 IPC_SYNC_MESSAGE_CONTROL1_1(ExtensionHostMsg_GetMessageBundle,
472 std::string /* extension id */,
473 SubstitutionMap /* message bundle */)
475 // Sent from the renderer to the browser to return the script running result.
476 IPC_MESSAGE_ROUTED5(ExtensionHostMsg_ExecuteCodeFinished,
477 int /* request id */,
478 std::string /* error; empty implies success */,
479 int32 /* page_id the code executed on.
480 May be -1 if unsuccessful */,
481 GURL /* URL of the code executed on.
482 May be empty if unsuccessful. */,
483 ListValue /* result of the script */)
485 // Sent from the renderer to the browser to notify that content scripts are
486 // running in the renderer that the IPC originated from.
487 // Note that the page_id is for the parent (or more accurately the topmost)
488 // frame (e.g. if executing in an iframe this is the page ID of the parent,
489 // unless the parent is an iframe... etc).
490 IPC_MESSAGE_ROUTED3(ExtensionHostMsg_ContentScriptsExecuting,
491 ExecutingScriptsMap,
492 int32 /* page_id of the _topmost_ frame */,
493 GURL /* url of the _topmost_ frame */)
495 IPC_MESSAGE_ROUTED2(ExtensionHostMsg_DidGetApplicationInfo,
496 int32 /* page_id */,
497 WebApplicationInfo)
499 // Sent by the renderer to implement chrome.app.install().
500 IPC_MESSAGE_ROUTED1(ExtensionHostMsg_InstallApplication,
501 WebApplicationInfo)
503 // Sent by the renderer to implement chrome.webstore.install().
504 IPC_MESSAGE_ROUTED4(ExtensionHostMsg_InlineWebstoreInstall,
505 int32 /* install id */,
506 int32 /* return route id */,
507 std::string /* Web Store item ID */,
508 GURL /* requestor URL */)
510 // Sent by the renderer when an App is requesting permission to send server
511 // pushed notifications.
512 IPC_MESSAGE_ROUTED4(ExtensionHostMsg_GetAppNotifyChannel,
513 GURL /* requestor_url */,
514 std::string /* client_id */,
515 int32 /* return_route_id */,
516 int32 /* callback_id */)
518 // Sent by the renderer when a web page is checking if its app is installed.
519 IPC_MESSAGE_ROUTED3(ExtensionHostMsg_GetAppInstallState,
520 GURL /* requestor_url */,
521 int32 /* return_route_id */,
522 int32 /* callback_id */)
524 // Optional Ack message sent to the browser to notify that the response to a
525 // function has been processed.
526 IPC_MESSAGE_ROUTED1(ExtensionHostMsg_ResponseAck,
527 int /* request_id */)
529 // Response to ExtensionMsg_ShouldUnload.
530 IPC_MESSAGE_CONTROL2(ExtensionHostMsg_ShouldUnloadAck,
531 std::string /* extension_id */,
532 int /* sequence_id */)
534 // Response to ExtensionMsg_Unload, after we dispatch the unload event.
535 IPC_MESSAGE_CONTROL1(ExtensionHostMsg_UnloadAck,
536 std::string /* extension_id */)
538 // Informs the browser to increment the keepalive count for the lazy background
539 // page, keeping it alive.
540 IPC_MESSAGE_ROUTED0(ExtensionHostMsg_IncrementLazyKeepaliveCount)
542 // Informs the browser there is one less thing keeping the lazy background page
543 // alive.
544 IPC_MESSAGE_ROUTED0(ExtensionHostMsg_DecrementLazyKeepaliveCount)
546 // Fetches a globally unique ID (for the lifetime of the browser) from the
547 // browser process.
548 IPC_SYNC_MESSAGE_CONTROL0_1(ExtensionHostMsg_GenerateUniqueID,
549 int /* unique_id */)
551 // Resumes resource requests for a newly created app window.
552 IPC_MESSAGE_CONTROL1(ExtensionHostMsg_ResumeRequests, int /* route_id */)
554 // Sent by the renderer when the draggable regions are updated.
555 IPC_MESSAGE_ROUTED1(ExtensionHostMsg_UpdateDraggableRegions,
556 std::vector<extensions::DraggableRegion> /* regions */)