| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Multiply-included file, no traditional include guard. | 5 // Multiply-included file, no traditional include guard. |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "content/common/content_export.h" |
| 8 #include "ipc/ipc_message_macros.h" | 9 #include "ipc/ipc_message_macros.h" |
| 9 | 10 |
| 11 #undef IPC_MESSAGE_EXPORT |
| 12 #define IPC_MESSAGE_EXPORT CONTENT_EXPORT |
| 10 #define IPC_MESSAGE_START AwMessagePortMsgStart | 13 #define IPC_MESSAGE_START AwMessagePortMsgStart |
| 11 | 14 |
| 12 //----------------------------------------------------------------------------- | 15 //----------------------------------------------------------------------------- |
| 13 // MessagePort messages | 16 // MessagePort messages |
| 14 // These are messages sent from the browser to the renderer process. | 17 // These are messages sent from the browser to the renderer process. |
| 15 | 18 |
| 16 // Normally the postmessages are exchanged between the renderers and the message | 19 // Normally the postmessages are exchanged between the renderers and the message |
| 17 // itself is opaque to the browser process. The format of the message is a | 20 // itself is opaque to the browser process. The format of the message is a |
| 18 // WebSerializesScriptValue. A WebSerializedScriptValue is a blink structure | 21 // WebSerializesScriptValue. A WebSerializedScriptValue is a blink structure |
| 19 // and can only be serialized/deserialized in renderer. Further, we could not | 22 // and can only be serialized/deserialized in renderer. Further, we could not |
| 20 // have Blink or V8 on the browser side due to their relience on static | 23 // have Blink or V8 on the browser side due to their relience on static |
| 21 // variables. | 24 // variables. |
| 22 // | 25 // |
| 23 // For posting messages from Java (Webview) to JS, we pass the browser/renderer | 26 // For posting messages from Java (Android apps) to JS, we pass the |
| 24 // boundary an extra time and convert the messages to a type that browser can | 27 // browser/renderer boundary an extra time and convert the messages to a type |
| 25 // use. Since WebView is single-process this is not terribly expensive, but | 28 // that browser can use. Within the current implementation specificications, |
| 26 // if we can do the conversion at the browser, then we can drop this code. | 29 // where we use the main frame on the browser side and it always stays within |
| 30 // the same process this is not expensive, but if we can do the conversion at |
| 31 // the browser, then we can drop this code. |
| 27 | 32 |
| 28 // Important Note about multi-process situation: Webview is single process so | 33 // Important Note about multi-process situation: In a multi-process scenario, |
| 29 // such a conversion does not increase the risk due to untrusted renderers. | 34 // the renderer that does the conversion can be theoretically different then the |
| 30 // However, in a multi-process scenario, the renderer that does the conversion | 35 // renderer that receives the message. Although in the current implementation |
| 31 // can be different then the renderer that receives the message. There are | 36 // this doesn't become an issue, there are 2 possible solutions to deal with |
| 32 // 2 possible solutions to deal with this: | 37 // this and make the overall system more robust to future changes: |
| 33 // 1. Do the conversion at the browser side by writing a new serializer | 38 // 1. Do the conversion at the browser side by writing a new serializer |
| 34 // deserializer for WebSerializedScriptValue | 39 // deserializer for WebSerializedScriptValue |
| 35 // 2. Do the conversion at the content layer, at the renderer at the time of | 40 // 2. Do the conversion at the content layer, at the renderer at the time of |
| 36 // receiveing the message. This may need adding new flags to indicate that | 41 // receiving the message. This may need adding new flags to indicate that |
| 37 // message needs to be converted. However, this is complicated due to queing | 42 // message needs to be converted. However, this is complicated due to queing |
| 38 // at the browser side and possibility of ports being shipped to a different | 43 // at the browser side and possibility of ports being shipped to a different |
| 39 // renderer or browser delegate. | 44 // renderer or browser delegate. |
| 40 | 45 |
| 41 | 46 |
| 42 // Tells the renderer to convert the message from a WebSerializeScript | 47 // Tells the renderer to convert the message from a WebSerializeScript |
| 43 // format to a base::ListValue. This IPC is used for messages that are | 48 // format to a base::ListValue. This IPC is used for messages that are |
| 44 // incoming to Android webview from JS. | 49 // incoming to Android apps from JS. |
| 45 IPC_MESSAGE_ROUTED3(AwMessagePortMsg_WebToAppMessage, | 50 IPC_MESSAGE_ROUTED3(AppWebMessagePortMsg_WebToAppMessage, |
| 46 int /* recipient message port id */, | 51 int /* recipient message port id */, |
| 47 base::string16 /* message */, | 52 base::string16 /* message */, |
| 48 std::vector<int> /* sent message port_ids */) | 53 std::vector<int> /* sent message port_ids */) |
| 49 | 54 |
| 50 // Tells the renderer to convert the message from a String16 | 55 // Tells the renderer to convert the message from a String16 |
| 51 // format to a WebSerializedScriptValue. This IPC is used for messages that | 56 // format to a WebSerializedScriptValue. This IPC is used for messages that |
| 52 // are outgoing from Webview to JS. | 57 // are outgoing from Android apps to JS. |
| 53 // TODO(sgurun) when we start supporting other types, use a ListValue instead | 58 // TODO(sgurun) when we start supporting other types, use a ListValue instead |
| 54 // of string16 | 59 // of string16 |
| 55 IPC_MESSAGE_ROUTED3(AwMessagePortMsg_AppToWebMessage, | 60 IPC_MESSAGE_ROUTED3(AppWebMessagePortMsg_AppToWebMessage, |
| 56 int /* recipient message port id */, | 61 int /* recipient message port id */, |
| 57 base::string16 /* message */, | 62 base::string16 /* message */, |
| 58 std::vector<int> /* sent message port_ids */) | 63 std::vector<int> /* sent message port_ids */) |
| 59 | 64 |
| 60 // Used to defer message port closing until after all in-flight messages | 65 // Used to defer message port closing until after all in-flight messages |
| 61 // are flushed from renderer to browser. Renderer piggy-backs the message | 66 // are flushed from renderer to browser. Renderer piggy-backs the message |
| 62 // to browser. | 67 // to browser. |
| 63 IPC_MESSAGE_ROUTED1(AwMessagePortMsg_ClosePort, | 68 IPC_MESSAGE_ROUTED1(AppWebMessagePortMsg_ClosePort, |
| 64 int /* message port id */) | 69 int /* message port id */) |
| 65 | 70 |
| 66 //----------------------------------------------------------------------------- | 71 //----------------------------------------------------------------------------- |
| 67 // These are messages sent from the renderer to the browser process. | 72 // These are messages sent from the renderer to the browser process. |
| 68 | 73 |
| 69 // Response to AwMessagePortMessage_WebToAppMessage | 74 // Response to AppWebMessagePortMessage_WebToAppMessage |
| 70 IPC_MESSAGE_ROUTED3(AwMessagePortHostMsg_ConvertedWebToAppMessage, | 75 IPC_MESSAGE_ROUTED3(AppWebMessagePortHostMsg_ConvertedWebToAppMessage, |
| 71 int /* recipient message port id */, | 76 int /* recipient message port id */, |
| 72 base::ListValue /* converted message */, | 77 base::ListValue /* converted message */, |
| 73 std::vector<int> /* sent message port_ids */) | 78 std::vector<int> /* sent message port_ids */) |
| 74 | 79 |
| 75 // Response to AwMessagePortMessage_AppToWebMessage | 80 // Response to AppWebMessagePortMessage_AppToWebMessage |
| 76 IPC_MESSAGE_ROUTED3(AwMessagePortHostMsg_ConvertedAppToWebMessage, | 81 IPC_MESSAGE_ROUTED3(AppWebMessagePortHostMsg_ConvertedAppToWebMessage, |
| 77 int /* recipient message port id */, | 82 int /* recipient message port id */, |
| 78 base::string16 /* converted message */, | 83 base::string16 /* converted message */, |
| 79 std::vector<int> /* sent message port_ids */) | 84 std::vector<int> /* sent message port_ids */) |
| 80 | 85 |
| 81 // Response to AwMessagePortMsg_ClosePort | 86 // Response to AppWebMessagePortMsg_ClosePort |
| 82 IPC_MESSAGE_ROUTED1(AwMessagePortHostMsg_ClosePortAck, | 87 IPC_MESSAGE_ROUTED1(AppWebMessagePortHostMsg_ClosePortAck, |
| 83 int /* message port id */) | 88 int /* message port id */) |
| OLD | NEW |