Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5156f92

Browse files
authored
[fuchsia] Add dummy setAssetBundle service extension (#4945)
1 parent d42b5b7 commit 5156f92

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

content_handler/service_protocol_hooks.cc

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,32 @@ namespace flutter_runner {
1717
namespace {
1818

1919
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+
}
2046

2147
static void AppendIsolateRef(std::stringstream* stream,
2248
int64_t main_port,
@@ -47,6 +73,9 @@ void ServiceProtocolHooks::RegisterHooks(bool running_precompiled_code) {
4773
// Listing of FlutterViews.
4874
Dart_RegisterRootServiceRequestCallback(kListViewsExtensionName, &ListViews,
4975
nullptr);
76+
77+
Dart_RegisterRootServiceRequestCallback(kSetAssetBundlePathExtensionName,
78+
&SetAssetBundlePath, nullptr);
5079
}
5180

5281
const char* ServiceProtocolHooks::kListViewsExtensionName =
@@ -88,4 +117,48 @@ bool ServiceProtocolHooks::ListViews(const char* method,
88117
return true;
89118
}
90119

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+
91164
} // namespace flutter_runner

content_handler/service_protocol_hooks.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ class ServiceProtocolHooks {
2222
intptr_t num_params,
2323
void* user_data,
2424
const char** json_object);
25+
26+
static const char* kSetAssetBundlePathExtensionName;
27+
static bool SetAssetBundlePath(const char* method,
28+
const char** param_keys,
29+
const char** param_values,
30+
intptr_t num_params,
31+
void* user_data,
32+
const char** json_object);
2533
};
2634

2735
} // namespace flutter_runner

0 commit comments

Comments
 (0)