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

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: Removed //mojo/public:sdk usage. 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 <map>
9 #include <string>
10
11 #import "base/ios/weak_nsobject.h"
12 #import "mojo/public/cpp/system/watcher.h"
13
14 @protocol CRWJSInjectionEvaluator;
15
16 namespace base {
17 class DictionaryValue;
18 class Value;
19 } // base
20
21 namespace shell {
22 namespace mojom {
23 class InterfaceProvider;
24 } // mojom
25 } // shell
26
27 namespace web {
28
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
31 // destroyed on UI thread.
32 class MojoFacade {
33 public:
34 // Constructs MojoFacade. The calling code must retain the ownership of
35 // |interface_provider| and |script_evaluator|, both can not be null.
36 MojoFacade(shell::mojom::InterfaceProvider* interface_provider,
37 id<CRWJSInjectionEvaluator> script_evaluator);
38 ~MojoFacade();
39
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
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
44 // with arguments specific for each message name.
45 // Supported message names with their handler methods in parenthesis:
46 // service_provider.connectToService (HandleServiceProviderConnectToService)
47 // core.close (HandleCoreClose)
48 // core.createMessagePipe (HandleCoreCreateMessagePipe)
49 // core.writeMessage (HandleCoreWriteMessage)
50 // core.readMessage (HandleCoreReadMessage)
51 // support.watch (HandleSupportWatch)
52 // support.cancelWatch (HandleSupportCancelWatch)
53 std::string HandleMojoMessage(const std::string& mojo_message_as_json);
54
55 private:
56 // Extracts message name and arguments from the given JSON string obtained
57 // from WebUI page. This method either succeeds or crashes the app.
Jackie Quinn 2016/05/16 22:28:16 "crashes the app" seems like an unfortunate outcom
Eugene But (OOO till 7-30) 2016/05/16 23:39:58 This is what Mojo does on other platforms. Updated
Jackie Quinn 2016/05/17 23:07:06 Thanks :-)
58 void GetMessageNameAndArguments(
59 const std::string& mojo_message_as_json,
60 std::string* out_name,
61 std::unique_ptr<base::DictionaryValue>* out_args);
62
63 // Connects to specified Mojo interface. |args| is a dictionary which must
64 // contain serviceName key, which is a string representing a service name).
Jackie Quinn 2016/05/16 22:28:16 Unpaired paren? Also should "serviceName" be in qu
Eugene But (OOO till 7-30) 2016/05/16 23:39:58 Done.
65 // Returns MojoHandle as a number.
66 std::unique_ptr<base::Value> HandleServiceProviderConnectToService(
67 const base::DictionaryValue* args);
68
69 // Closes the given handle. |args| is a dictionary which must contain "handle"
70 // key, which is a number representing a MojoHandle. Returns MojoResult as a
71 // number.
72 std::unique_ptr<base::Value> HandleCoreClose(
73 const base::DictionaryValue* args);
74
75 // Creates a Mojo message pipe. |args| is a dictionary which must contain
76 // "optionsDict" key. optionsDict is a dictionary with the following keys:
77 // "struct_size" (a number representing the size of this struct; used to allow
78 // for future extensions.), "flags" (a number representing
79 // MojoCreateMessagePipeOptionsFlags; used to specify different modes of
80 // operation.). Returns a dictionary with "handle0" and "handle1" keys (the
Jackie Quinn 2016/05/16 22:28:16 So much punctuation! Remove the periods inside the
Eugene But (OOO till 7-30) 2016/05/16 23:39:58 Updated the comments. Correct. I can not assign s
81 // numbers representing two endpoints (ports) for the message pipe.).
82 std::unique_ptr<base::Value> HandleCoreCreateMessagePipe(
83 base::DictionaryValue* args);
84
85 // Writes a message to the message pipe endpoint given by handle. |args| is a
86 // dictionary which must contain the following keys: "handle" (a number
Jackie Quinn 2016/05/16 22:28:16 Might be more readable to format these (and above)
Eugene But (OOO till 7-30) 2016/05/16 23:39:58 Done.
87 // representing MojoHandle, the endpoint to write to), "buffer" (a dictionary
88 // representing the message data; may be empty), "handles" (an array
89 // representing any handles to attach; handles are transferred on success and
90 // will no longer be valid; may be empty), "flags" (a number representing
91 // MojoWriteMessageFlags). Returns MojoResult as a number.
92 std::unique_ptr<base::Value> HandleCoreWriteMessage(
93 base::DictionaryValue* args);
94
95 // Reads a message from the message pipe endpoint given by handle. |args| is
96 // a dictionary which must contain the following keys: "handle" (a number
97 // representing MojoHandle, the endpoint to read from), "flags" (a number
98 // representing MojoWriteMessageFlags). Returns a dictionary with the
99 // following keys: "result" (a number representing MojoResult), "buffer" (an
100 // array representing message data; non-empty only on success), "handles" (an
101 // array representing MojoHandles transferred, if any).
102 std::unique_ptr<base::Value> HandleCoreReadMessage(
103 const base::DictionaryValue* args);
104
105 // Begins watching a handle for signals to be satisfied or unsatisfiable.
106 // |args| is a dictionary which must contain the following keys: "handle"
107 // (a number representing a MojoHandle), "signals" (a number representing
108 // MojoHandleSignals to watch), "callbackId" (a number representing the id
109 // which should be passed to __crWeb.mojo.mojoWatchSignal call). Returns
110 // watch id as a number.
111 std::unique_ptr<base::Value> HandleSupportWatch(
112 const base::DictionaryValue* args);
113
114 // Cancels a handle watch initiated by "support.watch". |args| is a dictionary
115 // which must contain "watchId" key (a number representing id returned from
116 // "support.watch"). Returns null.
117 std::unique_ptr<base::Value> HandleSupportCancelWatch(
118 const base::DictionaryValue* args);
119
120 // Provides service interfaces.
121 shell::mojom::InterfaceProvider* interface_provider_;
122 // Runs JavaScript on WebUI page.
123 base::WeakNSProtocol<id<CRWJSInjectionEvaluator>> script_evaluator_;
124 // Id of the last created watch.
125 int last_watch_id_;
126 // Currently active watches created through this facade.
127 std::map<int, mojo::Watcher> watchers_;
128 };
129
130 } // web
131
132 #endif // IOS_WEB_WEBUI_MOJO_FACADE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698