Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Side by Side Diff: ios/web/webui/mojo_facade.h

Issue 1956113002: [ios Mojo] iOS facade class for Mojo API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef IOS_WEB_WEBUI_MOJO_FACADE_H_
6 #define IOS_WEB_WEBUI_MOJO_FACADE_H_
7
8 #include <string>
9 #include <vector>
10
11 #import "base/ios/weak_nsobject.h"
12
13 @protocol CRWJSInjectionEvaluator;
14
15 namespace base {
16 class DictionaryValue;
17 class Value;
18 } // base
19
20 namespace shell {
21 namespace mojom {
22 class InterfaceProvider;
23 } // mojom
24 } // shell
25
26 namespace web {
27
28 // Facade class for Mojo. All inputs and outputs are optimized for communication
29 // with WebUI pages and hence use JSON format. Must be created used and
30 // destroyed on UI thread.
31 class MojoFacade {
32 public:
33 // Constructs MojoFacade. The calling code must retain the ownership of
34 // |interface_provider| and |script_evaluator|, both can not be null.
35 MojoFacade(shell::mojom::InterfaceProvider* interface_provider,
36 id<CRWJSInjectionEvaluator> script_evaluator);
37 ~MojoFacade();
38
39 // Handles Mojo message received from WebUI page. Returns a valid JSON string
40 // on success or empty string if supplied JSON does not have required
41 // structure. Every message must have "name" and "args" keys, where "name" is
42 // a string representing the name of Mojo message and "args" is a dictionary
43 // with arguments specific for each message name.
44 // Supported message names with their handler methods in parenthesis:
45 // service_provider.connectToService (HandleServiceProviderConnectToService)
46 // core.close (HandleCoreClose)
47 // core.createMessagePipe (HandleCoreCreateMessagePipe)
48 // core.writeMessage (HandleCoreWriteMessage)
49 // core.readMessage (HandleCoreReadMessage)
50 // support.watch (HandleSupportWatch)
51 std::string HandleMojoMessage(const std::string& mojo_message_as_json);
52
53 private:
54 // Extracts message name and arguments from the given JSON string obtained
55 // from WebUI page.
56 bool GetMessageNameAndArguments(
57 const std::string& mojo_message_as_json,
58 std::string* out_name,
59 std::unique_ptr<base::DictionaryValue>* out_args);
60
61 // Connects to specified Mojo interface. |args| is a dictionary which must
62 // contain serviceName key, which is a string representing a service name).
63 // Returns MojoHandle as a number.
64 std::unique_ptr<base::Value> HandleServiceProviderConnectToService(
65 const base::DictionaryValue* args);
66
67 // Closes the given handle. |args| is a dictionary which must contain "handle"
68 // key, which is a number representing a MojoHandle. Returns MojoResult as a
69 // number.
70 std::unique_ptr<base::Value> HandleCoreClose(
71 const base::DictionaryValue* args);
72
73 // Creates a Mojo message pipe. |args| is a dictionary which must contain
74 // "optionsDict" key. optionsDict is a dictionary with the following keys:
75 // "struct_size" (a number representing the size of this struct; used to allow
76 // for future extensions.), "flags" (a number representing
77 // MojoCreateMessagePipeOptionsFlags; used to specify different modes of
78 // operation.). Returns a dictionary with "handle0" and "handle1" keys (the
79 // numbers representing two endpoints (ports) for the message pipe.).
80 std::unique_ptr<base::Value> HandleCoreCreateMessagePipe(
81 base::DictionaryValue* args);
82
83 // Writes a message to the message pipe endpoint given by handle. |args| is a
84 // dictionary which must contain the following keys: "handle" (a number
85 // representing MojoHandle, the endpoint to write to), "buffer" (a dictionary
86 // representing the message data; may be empty), "handles" (an array
87 // representing any handles to attach; handles are transferred on success and
88 // will no longer be valid; may be empty), "flags" (a number representing
89 // MojoWriteMessageFlags). Returns MojoResult as a number.
90 std::unique_ptr<base::Value> HandleCoreWriteMessage(
91 base::DictionaryValue* args);
92
93 // Reads a message from the message pipe endpoint given by handle. |args| is
94 // a dictionary which must contain the following keys: "handle" (a number
95 // representing MojoHandle, the endpoint to read from), "flags" (a number
96 // representing MojoWriteMessageFlags). Returns a dictionary with the
97 // following keys: "result" (a number representing MojoResult), "buffer" (an
98 // array representing message data; non-empty only on success), "handles" (an
99 // array representing MojoHandles transferred, if any).
100 std::unique_ptr<base::Value> HandleCoreReadMessage(
101 const base::DictionaryValue* args);
102
103 // Begins watching a handle for signals to be satisfied or unsatisfiable.
104 // |args| is a dictionary which must contain the following keys: "handle"
105 // (a number representing a MojoHandle), "signals" (a number representing
106 // MojoHandleSignals to watch), "callbackId" (a number representing the id
107 // which should be passed to __crWeb.mojo.mojoWatchSignal call). Returns
108 // MojoResult as a number.
109 std::unique_ptr<base::Value> HandleSupportWatch(
110 const base::DictionaryValue* args);
111
112 // Provides service interfaces.
113 shell::mojom::InterfaceProvider* interface_provider_;
114 // Runs JavaScript on WebUI page.
115 base::WeakNSProtocol<id<CRWJSInjectionEvaluator>> script_evaluator_;
116 // Contexts for currently active watches set through this facade.
117 std::vector<uintptr_t> watch_contexts_;
118 };
119
120 } // web
121
122 #endif // IOS_WEB_WEBUI_MOJO_FACADE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698