1010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// found in the LICENSE file.
4010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
5010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// IPC messages for injected Java objects (Gin-based implementation).
6010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
7010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Multiply-included message file, hence no include guard.
8010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
9010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "base/basictypes.h"
10116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/common/android/gin_java_bridge_errors.h"
11010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "content/common/content_export.h"
12010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "ipc/ipc_message_macros.h"
13010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
14010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#undef IPC_MESSAGE_EXPORT
15010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#define IPC_MESSAGE_EXPORT CONTENT_EXPORT
16010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#define IPC_MESSAGE_START GinJavaBridgeMsgStart
17010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
18010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Messages for handling Java objects injected into JavaScript -----------------
19010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciIPC_ENUM_TRAITS_MAX_VALUE(content::GinJavaBridgeError,
211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                          content::kGinJavaBridgeErrorLast)
22116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
23010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Sent from browser to renderer to add a Java object with the given name.
24010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Object IDs are generated on the browser side.
25010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)IPC_MESSAGE_ROUTED2(GinJavaBridgeMsg_AddNamedObject,
26010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                    std::string /* name */,
27010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                    int32 /* object_id */)
28010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
29010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Sent from browser to renderer to remove a Java object with the given name.
30010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)IPC_MESSAGE_ROUTED1(GinJavaBridgeMsg_RemoveNamedObject,
31010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                    std::string /* name */)
32010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
33010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Sent from renderer to browser to get information about methods of
34010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// the given object. The query will only succeed if inspection of injected
35010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// objects is enabled on the browser side.
36010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)IPC_SYNC_MESSAGE_ROUTED1_1(GinJavaBridgeHostMsg_GetMethods,
37010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                           int32 /* object_id */,
38010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                           std::set<std::string> /* returned_method_names */)
39010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
40010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Sent from renderer to browser to find out, if an object has a method with
41010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// the given name.
42010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)IPC_SYNC_MESSAGE_ROUTED2_1(GinJavaBridgeHostMsg_HasMethod,
43010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                           int32 /* object_id */,
44010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                           std::string /* method_name */,
45010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                           bool /* result */)
46010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
47010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Sent from renderer to browser to invoke a method. Method arguments
48010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// are chained into |arguments| list. base::ListValue is used for |result| as
49010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// a container to work around immutability of base::Value.
50010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Empty result list indicates that an error has happened on the Java side
51010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// (either bridge-induced error or an unhandled Java exception) and an exception
52116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// must be thrown into JavaScript. |error_code| indicates the cause of
53116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// the error.
54010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Some special value types that are not supported by base::Value are encoded
55010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// as BinaryValues via GinJavaBridgeValue.
56116680a4aac90f2aa7413d9095a592090648e557Ben MurdochIPC_SYNC_MESSAGE_ROUTED3_2(GinJavaBridgeHostMsg_InvokeMethod,
57010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                           int32 /* object_id */,
58010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                           std::string /* method_name */,
59010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                           base::ListValue /* arguments */,
60116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                           base::ListValue /* result */,
61116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                           content::GinJavaBridgeError /* error_code */)
62010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
63010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Sent from renderer to browser in two cases:
64010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)//
65010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)//  1. (Main usage) To inform that the JS wrapper of the object has
66010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)//     been completely dereferenced and garbage-collected.
67010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)//
68010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)//  2. To notify the browser that wrapper creation has failed.  The browser side
69010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)//     assumes optimistically that every time an object is returned from a
70010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)//     method, the corresponding wrapper object will be successfully created on
71010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)//     the renderer side. Sending of this message informs the browser whether
72010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)//     this expectation has failed.
73010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)IPC_MESSAGE_ROUTED1(GinJavaBridgeHostMsg_ObjectWrapperDeleted,
74010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                    int32 /* object_id */)
75