未验证 提交 69ae5694 编写于 作者: J Jason Simmons 提交者: GitHub

Do not register UI-related native functions in secondary isolates (#6401)

Fixes https://github.com/flutter/flutter/issues/22478
上级 19c135c6
......@@ -35,6 +35,7 @@ namespace blink {
namespace {
static tonic::DartLibraryNatives* g_natives;
static tonic::DartLibraryNatives* g_natives_secondary;
Dart_NativeFunction GetNativeFunction(Dart_Handle name,
int argument_count,
......@@ -42,10 +43,21 @@ Dart_NativeFunction GetNativeFunction(Dart_Handle name,
return g_natives->GetNativeFunction(name, argument_count, auto_setup_scope);
}
Dart_NativeFunction GetNativeFunctionSecondary(Dart_Handle name,
int argument_count,
bool* auto_setup_scope) {
return g_natives_secondary->GetNativeFunction(name, argument_count,
auto_setup_scope);
}
const uint8_t* GetSymbol(Dart_NativeFunction native_function) {
return g_natives->GetSymbol(native_function);
}
const uint8_t* GetSymbolSecondary(Dart_NativeFunction native_function) {
return g_natives_secondary->GetSymbol(native_function);
}
} // namespace
void DartUI::InitForGlobal() {
......@@ -73,13 +85,20 @@ void DartUI::InitForGlobal() {
SemanticsUpdateBuilder::RegisterNatives(g_natives);
Vertices::RegisterNatives(g_natives);
Window::RegisterNatives(g_natives);
// Secondary isolates do not provide UI-related APIs.
g_natives_secondary = new tonic::DartLibraryNatives();
DartRuntimeHooks::RegisterNatives(g_natives_secondary);
}
}
void DartUI::InitForIsolate() {
void DartUI::InitForIsolate(bool is_root_isolate) {
FML_DCHECK(g_natives);
auto get_native_function =
is_root_isolate ? GetNativeFunction : GetNativeFunctionSecondary;
auto get_symbol = is_root_isolate ? GetSymbol : GetSymbolSecondary;
DART_CHECK_VALID(Dart_SetNativeResolver(Dart_LookupLibrary(ToDart("dart:ui")),
GetNativeFunction, GetSymbol));
get_native_function, get_symbol));
}
} // namespace blink
......@@ -12,7 +12,7 @@ namespace blink {
class DartUI {
public:
static void InitForGlobal();
static void InitForIsolate();
static void InitForIsolate(bool is_root_isolate);
private:
FML_DISALLOW_IMPLICIT_CONSTRUCTORS(DartUI);
......
......@@ -243,7 +243,7 @@ bool DartIsolate::LoadLibraries(bool is_root_isolate) {
DartIO::InitForIsolate();
DartUI::InitForIsolate();
DartUI::InitForIsolate(is_root_isolate);
const bool is_service_isolate = Dart_IsServiceIsolate(isolate());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册