| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef IOS_WEB_WEBUI_MOJO_FACADE_H_ | 5 #ifndef IOS_WEB_WEBUI_MOJO_FACADE_H_ |
| 6 #define IOS_WEB_WEBUI_MOJO_FACADE_H_ | 6 #define IOS_WEB_WEBUI_MOJO_FACADE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 // a string representing the name of Mojo message and "args" is a dictionary | 43 // a string representing the name of Mojo message and "args" is a dictionary |
| 44 // with arguments specific for each message name. | 44 // with arguments specific for each message name. |
| 45 // Supported message names with their handler methods in parenthesis: | 45 // Supported message names with their handler methods in parenthesis: |
| 46 // interface_provider.getInterface (HandleInterfaceProviderGetInterface) | 46 // interface_provider.getInterface (HandleInterfaceProviderGetInterface) |
| 47 // core.close (HandleCoreClose) | 47 // core.close (HandleCoreClose) |
| 48 // core.createMessagePipe (HandleCoreCreateMessagePipe) | 48 // core.createMessagePipe (HandleCoreCreateMessagePipe) |
| 49 // core.writeMessage (HandleCoreWriteMessage) | 49 // core.writeMessage (HandleCoreWriteMessage) |
| 50 // core.readMessage (HandleCoreReadMessage) | 50 // core.readMessage (HandleCoreReadMessage) |
| 51 // support.watch (HandleSupportWatch) | 51 // support.watch (HandleSupportWatch) |
| 52 // support.cancelWatch (HandleSupportCancelWatch) | 52 // support.cancelWatch (HandleSupportCancelWatch) |
| 53 // console.log (HandleConsoleLog) |
| 53 std::string HandleMojoMessage(const std::string& mojo_message_as_json); | 54 std::string HandleMojoMessage(const std::string& mojo_message_as_json); |
| 54 | 55 |
| 55 private: | 56 private: |
| 56 // Extracts message name and arguments from the given JSON string obtained | 57 // Extracts message name and arguments from the given JSON string obtained |
| 57 // from WebUI page. This method either succeeds or crashes the app (this | 58 // from WebUI page. This method either succeeds or crashes the app (this |
| 58 // matches other platforms where Mojo API is strict on malformed input). | 59 // matches other platforms where Mojo API is strict on malformed input). |
| 59 void GetMessageNameAndArguments( | 60 void GetMessageNameAndArguments( |
| 60 const std::string& mojo_message_as_json, | 61 const std::string& mojo_message_as_json, |
| 61 std::string* out_name, | 62 std::string* out_name, |
| 62 std::unique_ptr<base::DictionaryValue>* out_args); | 63 std::unique_ptr<base::DictionaryValue>* out_args); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 std::unique_ptr<base::Value> HandleSupportWatch( | 119 std::unique_ptr<base::Value> HandleSupportWatch( |
| 119 const base::DictionaryValue* args); | 120 const base::DictionaryValue* args); |
| 120 | 121 |
| 121 // Cancels a handle watch initiated by "support.watch". |args| is a dictionary | 122 // Cancels a handle watch initiated by "support.watch". |args| is a dictionary |
| 122 // which must contain "watchId" key (a number representing id returned from | 123 // which must contain "watchId" key (a number representing id returned from |
| 123 // "support.watch"). | 124 // "support.watch"). |
| 124 // Returns null. | 125 // Returns null. |
| 125 std::unique_ptr<base::Value> HandleSupportCancelWatch( | 126 std::unique_ptr<base::Value> HandleSupportCancelWatch( |
| 126 const base::DictionaryValue* args); | 127 const base::DictionaryValue* args); |
| 127 | 128 |
| 129 // Logs a message. |args| is a dictionary which must contain "message" key. |
| 130 // Returns null. |
| 131 std::unique_ptr<base::Value> HandleConsoleLog( |
| 132 const base::DictionaryValue* args); |
| 133 |
| 128 // Provides interfaces. | 134 // Provides interfaces. |
| 129 service_manager::mojom::InterfaceProvider* interface_provider_; | 135 service_manager::mojom::InterfaceProvider* interface_provider_; |
| 130 // Runs JavaScript on WebUI page. | 136 // Runs JavaScript on WebUI page. |
| 131 base::WeakNSProtocol<id<CRWJSInjectionEvaluator>> script_evaluator_; | 137 base::WeakNSProtocol<id<CRWJSInjectionEvaluator>> script_evaluator_; |
| 132 // Id of the last created watch. | 138 // Id of the last created watch. |
| 133 int last_watch_id_; | 139 int last_watch_id_; |
| 134 // Currently active watches created through this facade. | 140 // Currently active watches created through this facade. |
| 135 std::map<int, mojo::Watcher> watchers_; | 141 std::map<int, mojo::Watcher> watchers_; |
| 136 }; | 142 }; |
| 137 | 143 |
| 138 } // web | 144 } // web |
| 139 | 145 |
| 140 #endif // IOS_WEB_WEBUI_MOJO_FACADE_H_ | 146 #endif // IOS_WEB_WEBUI_MOJO_FACADE_H_ |
| OLD | NEW |