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

Commit ac12d06

Browse files
committed
Started loading the plugin registrant specified by the framework instead of looking for it.
1 parent 42a834a commit ac12d06

File tree

1 file changed

+11
-34
lines changed

1 file changed

+11
-34
lines changed

runtime/dart_plugin_registrant.cc

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,12 @@
77
#include <string>
88

99
#include "flutter/fml/trace_event.h"
10+
#include "fml/logging.h"
1011
#include "third_party/tonic/converter/dart_converter.h"
1112
#include "third_party/tonic/logging/dart_invoke.h"
1213

1314
namespace flutter {
1415

15-
namespace {
16-
bool EndsWith(const std::string& str, const std::string& ending) {
17-
if (str.size() >= ending.size()) {
18-
return (0 ==
19-
str.compare(str.size() - ending.size(), ending.size(), ending));
20-
} else {
21-
return false;
22-
}
23-
}
24-
25-
Dart_Handle FindDartPluginRegistrantLibrary() {
26-
// TODO(99308): Instead of finding this, it could be passed down from the
27-
// tool.
28-
Dart_Handle libraries = Dart_GetLoadedLibraries();
29-
intptr_t length = 0;
30-
Dart_ListLength(libraries, &length);
31-
for (intptr_t i = 0; i < length; ++i) {
32-
Dart_Handle library = Dart_ListGetAt(libraries, i);
33-
std::string library_name =
34-
tonic::DartConverter<std::string>::FromDart(Dart_ToString(library));
35-
if (EndsWith(library_name,
36-
"dart_tool/flutter_build/dart_plugin_registrant.dart'")) {
37-
return library;
38-
}
39-
}
40-
return Dart_Null();
41-
}
42-
} // namespace
43-
4416
bool InvokeDartPluginRegistrantIfAvailable(Dart_Handle library_handle) {
4517
TRACE_EVENT0("flutter", "InvokeDartPluginRegistrantIfAvailable");
4618

@@ -65,12 +37,17 @@ bool InvokeDartPluginRegistrantIfAvailable(Dart_Handle library_handle) {
6537
}
6638

6739
bool FindAndInvokeDartPluginRegistrant() {
68-
auto dart_plugin_registrant_library = FindDartPluginRegistrantLibrary();
69-
if (!Dart_IsNull(dart_plugin_registrant_library)) {
70-
return InvokeDartPluginRegistrantIfAvailable(
71-
dart_plugin_registrant_library);
72-
} else {
40+
Dart_Handle ui_library =
41+
Dart_LookupLibrary(tonic::ToDart("package:flutter/services.dart"));
42+
Dart_Handle registrant_file_uri =
43+
Dart_GetField(ui_library, tonic::ToDart("dartPluginRegistrantFileURI"));
44+
std::string registrant_file_uri_string =
45+
tonic::DartConverter<std::string>::FromDart(registrant_file_uri);
46+
if (registrant_file_uri_string.empty()) {
7347
return false;
48+
} else {
49+
Dart_Handle registrant_library = Dart_LookupLibrary(registrant_file_uri);
50+
return InvokeDartPluginRegistrantIfAvailable(registrant_library);
7451
}
7552
}
7653
} // namespace flutter

0 commit comments

Comments
 (0)