@@ -17,6 +17,32 @@ namespace flutter_runner {
17
17
namespace {
18
18
19
19
constexpr char kViewIdPrefx [] = " _flutterView/" ;
20
+ constexpr size_t kViewIdPrefxLength = sizeof (kViewIdPrefx ) - 1 ;
21
+
22
+ static intptr_t KeyIndex (const char ** param_keys,
23
+ intptr_t num_params,
24
+ const char * key) {
25
+ if (param_keys == NULL ) {
26
+ return -1 ;
27
+ }
28
+ for (intptr_t i = 0 ; i < num_params; i++) {
29
+ if (strcmp (param_keys[i], key) == 0 ) {
30
+ return i;
31
+ }
32
+ }
33
+ return -1 ;
34
+ }
35
+
36
+ static const char * ValueForKey (const char ** param_keys,
37
+ const char ** param_values,
38
+ intptr_t num_params,
39
+ const char * key) {
40
+ intptr_t index = KeyIndex (param_keys, num_params, key);
41
+ if (index < 0 ) {
42
+ return NULL ;
43
+ }
44
+ return param_values[index];
45
+ }
20
46
21
47
static void AppendIsolateRef (std::stringstream* stream,
22
48
int64_t main_port,
@@ -47,6 +73,9 @@ void ServiceProtocolHooks::RegisterHooks(bool running_precompiled_code) {
47
73
// Listing of FlutterViews.
48
74
Dart_RegisterRootServiceRequestCallback (kListViewsExtensionName , &ListViews,
49
75
nullptr );
76
+
77
+ Dart_RegisterRootServiceRequestCallback (kSetAssetBundlePathExtensionName ,
78
+ &SetAssetBundlePath, nullptr );
50
79
}
51
80
52
81
const char * ServiceProtocolHooks::kListViewsExtensionName =
@@ -88,4 +117,48 @@ bool ServiceProtocolHooks::ListViews(const char* method,
88
117
return true ;
89
118
}
90
119
120
+ const char * ServiceProtocolHooks::kSetAssetBundlePathExtensionName =
121
+ " _flutter.setAssetBundlePath" ;
122
+
123
+ bool ServiceProtocolHooks::SetAssetBundlePath (const char * method,
124
+ const char ** param_keys,
125
+ const char ** param_values,
126
+ intptr_t num_params,
127
+ void * user_data,
128
+ const char ** json_object) {
129
+ const char * view_id_str =
130
+ ValueForKey (param_keys, param_values, num_params, " viewId" );
131
+
132
+ // Ask the App for the list of platform views. This will run a task on
133
+ // the UI thread before returning.
134
+ App& app = App::Shared ();
135
+ std::vector<App::PlatformViewInfo> platform_views;
136
+ app.WaitForPlatformViewIds (&platform_views);
137
+
138
+ // Convert the actual flutter view hex id into a number.
139
+ uintptr_t view_id_as_num =
140
+ std::stoull ((view_id_str + kViewIdPrefxLength ), nullptr , 16 );
141
+
142
+ // The view existed and the isolate was created. Success.
143
+ std::stringstream response;
144
+ response << " {\" type\" :\" Success\" ,"
145
+ << " \" view\" :" ;
146
+ for (auto it = platform_views.begin (); it != platform_views.end (); it++) {
147
+ uintptr_t view_id = it->view_id ;
148
+ int64_t isolate_id = it->isolate_id ;
149
+ const std::string& isolate_name = it->isolate_name ;
150
+ if (!view_id || view_id != view_id_as_num) {
151
+ continue ;
152
+ }
153
+
154
+ // TODO(DX): Set up asset bundle path for the isolate.
155
+
156
+ AppendFlutterView (&response, view_id, isolate_id, isolate_name);
157
+ break ;
158
+ }
159
+ response << " }" ;
160
+ *json_object = strdup (response.str ().c_str ());
161
+ return true ;
162
+ }
163
+
91
164
} // namespace flutter_runner
0 commit comments