提交 1c59ddef 编写于 作者: J John McCutchan 提交者: GitHub

Send richer service protocol respones from the Shell (#2929)

上级 d535a15a
......@@ -47,6 +47,11 @@ UIDartState* UIDartState::CreateForChildIsolate() {
void UIDartState::DidSetIsolate() {
main_port_ = Dart_GetMainPortId();
DartApiScope api_scope;
Dart_Handle debug_name = Dart_DebugName();
if (Dart_IsString(debug_name)) {
debug_name_ = tonic::StdStringFromDart(debug_name);
}
}
UIDartState* UIDartState::Current() {
......
......@@ -39,7 +39,7 @@ class UIDartState : public tonic::DartState {
IsolateClient* isolate_client() { return isolate_client_; }
Dart_Port main_port() const { return main_port_; }
const std::string& debug_name() const { return debug_name_; }
Window* window() const { return window_.get(); }
void set_mojo_services(std::unique_ptr<MojoServices> mojo_services);
......@@ -59,6 +59,7 @@ class UIDartState : public tonic::DartState {
IsolateClient* isolate_client_;
Dart_Port main_port_;
std::string debug_name_;
std::unique_ptr<MojoServices> mojo_services_;
std::unique_ptr<Window> window_;
......
......@@ -113,4 +113,15 @@ Dart_Port RuntimeController::GetMainPort() {
return dart_controller_->dart_state()->main_port();
}
std::string RuntimeController::GetIsolateName() {
if (!dart_controller_) {
return "";
}
if (!dart_controller_->dart_state()) {
return "";
}
return dart_controller_->dart_state()->debug_name();
}
} // namespace blink
......@@ -44,6 +44,8 @@ class RuntimeController : public WindowClient, public IsolateClient {
Dart_Port GetMainPort();
std::string GetIsolateName();
private:
explicit RuntimeController(RuntimeDelegate* client);
......
......@@ -86,6 +86,24 @@ static bool ErrorIsolateSpawn(const char** json_object, const char* view_id) {
return false;
}
static void AppendIsolateRef(std::stringstream* stream,
int64_t main_port,
const std::string name) {
*stream << "{\"type\":\"@Isolate\",\"fixedId\":true,\"id\":\"isolates/";
*stream << main_port << "\",\"name\":\"" << name << "\",";
*stream << "\"number\":\"" << main_port << "\"}";
}
static void AppendFlutterView(std::stringstream* stream,
uintptr_t view_id,
int64_t isolate_id,
const std::string isolate_name) {
*stream << "{\"type\":\"FlutterView\", \"id\": \"" << kViewIdPrefx << "0x"
<< std::hex << view_id << std::dec << "\"," << "\"isolate\":";
AppendIsolateRef(stream, isolate_id, isolate_name);
*stream << "}";
}
} // namespace
void PlatformViewServiceProtocol::RegisterHook(bool running_precompiled_code) {
......@@ -140,8 +158,12 @@ bool PlatformViewServiceProtocol::RunInView(const char* method,
Shell& shell = Shell::Shared();
bool view_existed = false;
Dart_Port main_port = ILLEGAL_PORT;
std::string isolate_name;
shell.RunInPlatformView(view_id_as_num, main_script, packages_file,
asset_directory, &view_existed, &main_port);
asset_directory,
&view_existed,
&main_port,
&isolate_name);
if (!view_existed) {
// If the view did not exist this request has definitely failed.
......@@ -153,10 +175,9 @@ bool PlatformViewServiceProtocol::RunInView(const char* method,
// The view existed and the isolate was created. Success.
std::stringstream response;
response << "{\"type\":\"Success\","
<< "\"viewId\": \"" << kViewIdPrefx << "0x" << std::hex << view_id
<< "\","
<< "\"isolateId\": \"isolates/" << std::dec << main_port << "\""
<< "}";
<< "\"view\":";
AppendFlutterView(&response, view_id_as_num, main_port, isolate_name);
response << "}";
*json_object = strdup(response.str().c_str());
return true;
}
......@@ -185,6 +206,7 @@ bool PlatformViewServiceProtocol::ListViews(const char* method,
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) {
continue;
}
......@@ -193,10 +215,7 @@ bool PlatformViewServiceProtocol::ListViews(const char* method,
} else {
prefix_comma = true;
}
response << "{\"type\":\"FlutterView\", \"id\": \"" << kViewIdPrefx << "0x"
<< std::hex << view_id << "\","
<< "\"isolateId\": \"isolates/" << std::dec << isolate_id << "\""
<< "}";
AppendFlutterView(&response, view_id, isolate_id, isolate_name);
}
response << "]}";
// Copy the response.
......
......@@ -263,6 +263,7 @@ void Shell::WaitForPlatformViewsIdsUIThread(
PlatformViewInfo info;
info.view_id = reinterpret_cast<uintptr_t>(view);
info.isolate_id = view->engine().GetUIIsolateMainPort();
info.isolate_name = view->engine().GetUIIsolateName();
platform_view_ids->push_back(info);
}
latch->Signal();
......@@ -273,7 +274,8 @@ void Shell::RunInPlatformView(uintptr_t view_id,
const char* packages_file,
const char* asset_directory,
bool* view_existed,
int64_t* dart_isolate_id) {
int64_t* dart_isolate_id,
std::string* isolate_name) {
ftl::AutoResetWaitableEvent latch;
FTL_DCHECK(view_id != 0);
FTL_DCHECK(main_script);
......@@ -283,10 +285,10 @@ void Shell::RunInPlatformView(uintptr_t view_id,
blink::Threads::UI()->PostTask([this, view_id, main_script, packages_file,
asset_directory, view_existed,
dart_isolate_id, &latch]() {
dart_isolate_id, isolate_name, &latch]() {
RunInPlatformViewUIThread(view_id, main_script, packages_file,
asset_directory, view_existed, dart_isolate_id,
&latch);
isolate_name, &latch);
});
latch.Wait();
}
......@@ -297,6 +299,7 @@ void Shell::RunInPlatformViewUIThread(uintptr_t view_id,
const std::string& assets_directory,
bool* view_existed,
int64_t* dart_isolate_id,
std::string* isolate_name,
ftl::AutoResetWaitableEvent* latch) {
FTL_DCHECK(ui_thread_checker_ && ui_thread_checker_->CalledOnValidThread());
......@@ -308,6 +311,7 @@ void Shell::RunInPlatformViewUIThread(uintptr_t view_id,
*view_existed = true;
view->engine().RunFromSource(main, packages, assets_directory);
*dart_isolate_id = view->engine().GetUIIsolateMainPort();
*isolate_name = view->engine().GetUIIsolateName();
break;
}
}
......
......@@ -50,6 +50,7 @@ class Shell {
struct PlatformViewInfo {
uintptr_t view_id;
int64_t isolate_id;
std::string isolate_name;
};
// These APIs can be called from any thread.
......@@ -63,7 +64,8 @@ class Shell {
const char* packages_file,
const char* asset_directory,
bool* view_existed,
int64_t* dart_isolate_id);
int64_t* dart_isolate_id,
std::string* isolate_name);
private:
Shell();
......@@ -81,6 +83,7 @@ class Shell {
const std::string& assets_directory,
bool* view_existed,
int64_t* dart_isolate_id,
std::string* isolate_name,
ftl::AutoResetWaitableEvent* latch);
std::unique_ptr<base::Thread> gpu_thread_;
......
......@@ -101,6 +101,13 @@ Dart_Port Engine::GetUIIsolateMainPort() {
return runtime_->GetMainPort();
}
std::string Engine::GetUIIsolateName() {
if (!runtime_) {
return "";
}
return runtime_->GetIsolateName();
}
void Engine::ConnectToEngine(mojo::InterfaceRequest<SkyEngine> request) {
binding_.Bind(request.Pass());
}
......
......@@ -52,6 +52,8 @@ class Engine : public UIDelegate,
Dart_Port GetUIIsolateMainPort();
std::string GetUIIsolateName();
private:
// UIDelegate implementation:
void ConnectToEngine(mojo::InterfaceRequest<SkyEngine> request) override;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册