Skip to content

Commit

Permalink
[fuchsia] Add dummy setAssetBundle service extension (flutter#4945)
Browse files Browse the repository at this point in the history
  • Loading branch information
zanderso authored Apr 6, 2018
1 parent d42b5b7 commit 5156f92
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
73 changes: 73 additions & 0 deletions content_handler/service_protocol_hooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,32 @@ namespace flutter_runner {
namespace {

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,
int64_t main_port,
Expand Down Expand Up @@ -47,6 +73,9 @@ void ServiceProtocolHooks::RegisterHooks(bool running_precompiled_code) {
// Listing of FlutterViews.
Dart_RegisterRootServiceRequestCallback(kListViewsExtensionName, &ListViews,
nullptr);

Dart_RegisterRootServiceRequestCallback(kSetAssetBundlePathExtensionName,
&SetAssetBundlePath, nullptr);
}

const char* ServiceProtocolHooks::kListViewsExtensionName =
Expand Down Expand Up @@ -88,4 +117,48 @@ bool ServiceProtocolHooks::ListViews(const char* method,
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
8 changes: 8 additions & 0 deletions content_handler/service_protocol_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ class ServiceProtocolHooks {
intptr_t num_params,
void* user_data,
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
Expand Down

0 comments on commit 5156f92

Please sign in to comment.