未验证 提交 5156f92d 编写于 作者: Z Zachary Anderson 提交者: GitHub

[fuchsia] Add dummy setAssetBundle service extension (#4945)

上级 d42b5b73
...@@ -17,6 +17,32 @@ namespace flutter_runner { ...@@ -17,6 +17,32 @@ namespace flutter_runner {
namespace { namespace {
constexpr char kViewIdPrefx[] = "_flutterView/"; constexpr char kViewIdPrefx[] = "_flutterView/";
constexpr size_t kViewIdPrefxLength = sizeof(kViewIdPrefx) - 1;
static intptr_t KeyIndex(const char** param_keys,
intptr_t num_params,
const char* key) {
if (param_keys == NULL) {
return -1;
}
for (intptr_t i = 0; i < num_params; i++) {
if (strcmp(param_keys[i], key) == 0) {
return i;
}
}
return -1;
}
static const char* ValueForKey(const char** param_keys,
const char** param_values,
intptr_t num_params,
const char* key) {
intptr_t index = KeyIndex(param_keys, num_params, key);
if (index < 0) {
return NULL;
}
return param_values[index];
}
static void AppendIsolateRef(std::stringstream* stream, static void AppendIsolateRef(std::stringstream* stream,
int64_t main_port, int64_t main_port,
...@@ -47,6 +73,9 @@ void ServiceProtocolHooks::RegisterHooks(bool running_precompiled_code) { ...@@ -47,6 +73,9 @@ void ServiceProtocolHooks::RegisterHooks(bool running_precompiled_code) {
// Listing of FlutterViews. // Listing of FlutterViews.
Dart_RegisterRootServiceRequestCallback(kListViewsExtensionName, &ListViews, Dart_RegisterRootServiceRequestCallback(kListViewsExtensionName, &ListViews,
nullptr); nullptr);
Dart_RegisterRootServiceRequestCallback(kSetAssetBundlePathExtensionName,
&SetAssetBundlePath, nullptr);
} }
const char* ServiceProtocolHooks::kListViewsExtensionName = const char* ServiceProtocolHooks::kListViewsExtensionName =
...@@ -88,4 +117,48 @@ bool ServiceProtocolHooks::ListViews(const char* method, ...@@ -88,4 +117,48 @@ bool ServiceProtocolHooks::ListViews(const char* method,
return true; return true;
} }
const char* ServiceProtocolHooks::kSetAssetBundlePathExtensionName =
"_flutter.setAssetBundlePath";
bool ServiceProtocolHooks::SetAssetBundlePath(const char* method,
const char** param_keys,
const char** param_values,
intptr_t num_params,
void* user_data,
const char** json_object) {
const char* view_id_str =
ValueForKey(param_keys, param_values, num_params, "viewId");
// Ask the App for the list of platform views. This will run a task on
// the UI thread before returning.
App& app = App::Shared();
std::vector<App::PlatformViewInfo> platform_views;
app.WaitForPlatformViewIds(&platform_views);
// Convert the actual flutter view hex id into a number.
uintptr_t view_id_as_num =
std::stoull((view_id_str + kViewIdPrefxLength), nullptr, 16);
// The view existed and the isolate was created. Success.
std::stringstream response;
response << "{\"type\":\"Success\","
<< "\"view\":";
for (auto it = platform_views.begin(); it != platform_views.end(); it++) {
uintptr_t view_id = it->view_id;
int64_t isolate_id = it->isolate_id;
const std::string& isolate_name = it->isolate_name;
if (!view_id || view_id != view_id_as_num) {
continue;
}
// TODO(DX): Set up asset bundle path for the isolate.
AppendFlutterView(&response, view_id, isolate_id, isolate_name);
break;
}
response << "}";
*json_object = strdup(response.str().c_str());
return true;
}
} // namespace flutter_runner } // namespace flutter_runner
...@@ -22,6 +22,14 @@ class ServiceProtocolHooks { ...@@ -22,6 +22,14 @@ class ServiceProtocolHooks {
intptr_t num_params, intptr_t num_params,
void* user_data, void* user_data,
const char** json_object); const char** json_object);
static const char* kSetAssetBundlePathExtensionName;
static bool SetAssetBundlePath(const char* method,
const char** param_keys,
const char** param_values,
intptr_t num_params,
void* user_data,
const char** json_object);
}; };
} // namespace flutter_runner } // namespace flutter_runner
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册