| 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 |
| 11 #import "base/ios/weak_nsobject.h" | 11 #import "base/ios/weak_nsobject.h" |
| 12 #import "mojo/public/cpp/system/watcher.h" | 12 #import "mojo/public/cpp/system/watcher.h" |
| 13 | 13 |
| 14 @protocol CRWJSInjectionEvaluator; | 14 @protocol CRWJSInjectionEvaluator; |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 class DictionaryValue; | 17 class DictionaryValue; |
| 18 class Value; | 18 class Value; |
| 19 } // base | 19 } // base |
| 20 | 20 |
| 21 namespace shell { | 21 namespace service_manager { |
| 22 namespace mojom { | 22 namespace mojom { |
| 23 class InterfaceProvider; | 23 class InterfaceProvider; |
| 24 } // mojom | 24 } // mojom |
| 25 } // shell | 25 } // service_manager |
| 26 | 26 |
| 27 namespace web { | 27 namespace web { |
| 28 | 28 |
| 29 // Facade class for Mojo. All inputs and outputs are optimized for communication | 29 // Facade class for Mojo. All inputs and outputs are optimized for communication |
| 30 // with WebUI pages and hence use JSON format. Must be created used and | 30 // with WebUI pages and hence use JSON format. Must be created used and |
| 31 // destroyed on UI thread. | 31 // destroyed on UI thread. |
| 32 class MojoFacade { | 32 class MojoFacade { |
| 33 public: | 33 public: |
| 34 // Constructs MojoFacade. The calling code must retain the ownership of | 34 // Constructs MojoFacade. The calling code must retain the ownership of |
| 35 // |interface_provider| and |script_evaluator|, both can not be null. | 35 // |interface_provider| and |script_evaluator|, both can not be null. |
| 36 MojoFacade(shell::mojom::InterfaceProvider* interface_provider, | 36 MojoFacade(service_manager::mojom::InterfaceProvider* interface_provider, |
| 37 id<CRWJSInjectionEvaluator> script_evaluator); | 37 id<CRWJSInjectionEvaluator> script_evaluator); |
| 38 ~MojoFacade(); | 38 ~MojoFacade(); |
| 39 | 39 |
| 40 // Handles Mojo message received from WebUI page. Returns a valid JSON string | 40 // Handles Mojo message received from WebUI page. Returns a valid JSON string |
| 41 // on success or empty string if supplied JSON does not have required | 41 // on success or empty string if supplied JSON does not have required |
| 42 // structure. Every message must have "name" and "args" keys, where "name" is | 42 // structure. Every message must have "name" and "args" keys, where "name" is |
| 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) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 const base::DictionaryValue* args); | 119 const base::DictionaryValue* args); |
| 120 | 120 |
| 121 // Cancels a handle watch initiated by "support.watch". |args| is a dictionary | 121 // Cancels a handle watch initiated by "support.watch". |args| is a dictionary |
| 122 // which must contain "watchId" key (a number representing id returned from | 122 // which must contain "watchId" key (a number representing id returned from |
| 123 // "support.watch"). | 123 // "support.watch"). |
| 124 // Returns null. | 124 // Returns null. |
| 125 std::unique_ptr<base::Value> HandleSupportCancelWatch( | 125 std::unique_ptr<base::Value> HandleSupportCancelWatch( |
| 126 const base::DictionaryValue* args); | 126 const base::DictionaryValue* args); |
| 127 | 127 |
| 128 // Provides interfaces. | 128 // Provides interfaces. |
| 129 shell::mojom::InterfaceProvider* interface_provider_; | 129 service_manager::mojom::InterfaceProvider* interface_provider_; |
| 130 // Runs JavaScript on WebUI page. | 130 // Runs JavaScript on WebUI page. |
| 131 base::WeakNSProtocol<id<CRWJSInjectionEvaluator>> script_evaluator_; | 131 base::WeakNSProtocol<id<CRWJSInjectionEvaluator>> script_evaluator_; |
| 132 // Id of the last created watch. | 132 // Id of the last created watch. |
| 133 int last_watch_id_; | 133 int last_watch_id_; |
| 134 // Currently active watches created through this facade. | 134 // Currently active watches created through this facade. |
| 135 std::map<int, mojo::Watcher> watchers_; | 135 std::map<int, mojo::Watcher> watchers_; |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 } // web | 138 } // web |
| 139 | 139 |
| 140 #endif // IOS_WEB_WEBUI_MOJO_FACADE_H_ | 140 #endif // IOS_WEB_WEBUI_MOJO_FACADE_H_ |
| OLD | NEW |