Skip to content

Commit 42b63f8

Browse files
authored
[webview_flutter] Add removeJavascriptChannels API and Callbacks (#31)
* Implement removeJavascriptChannels() method in native side * Register the callback functions to be invoked when native webview's events like onPageStarted() and onPageFinished() happen Signed-off-by: Seungsoo Lee <[email protected]>
1 parent 749930e commit 42b63f8

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

packages/webview_flutter/tizen/src/webview.cc

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,29 @@ WebView::WebView(flutter::PluginRegistrar* registrar, int viewId,
9292
}
9393
}
9494

95+
webViewInstance_->RegisterOnPageStartedHandler(
96+
[this](LWE::WebContainer* container, const std::string& url) {
97+
LOG_DEBUG("RegisterOnPageStartedHandler(url: %s)\n", url.c_str());
98+
flutter::EncodableMap map;
99+
map.insert(
100+
std::make_pair<flutter::EncodableValue, flutter::EncodableValue>(
101+
flutter::EncodableValue("url"), flutter::EncodableValue(url)));
102+
std::unique_ptr<flutter::EncodableValue> args =
103+
std::make_unique<flutter::EncodableValue>(map);
104+
channel_->InvokeMethod("onPageStarted", std::move(args));
105+
});
106+
webViewInstance_->RegisterOnPageLoadedHandler(
107+
[this](LWE::WebContainer* container, const std::string& url) {
108+
LOG_DEBUG("RegisterOnPageLoadedHandler(url: %s)\n", url.c_str());
109+
flutter::EncodableMap map;
110+
map.insert(
111+
std::make_pair<flutter::EncodableValue, flutter::EncodableValue>(
112+
flutter::EncodableValue("url"), flutter::EncodableValue(url)));
113+
std::unique_ptr<flutter::EncodableValue> args =
114+
std::make_unique<flutter::EncodableValue>(map);
115+
channel_->InvokeMethod("onPageFinished", std::move(args));
116+
});
117+
95118
webViewInstance_->LoadURL(currentUrl_);
96119
}
97120

@@ -593,7 +616,17 @@ void WebView::HandleMethodCall(
593616
}
594617
result->Success();
595618
} else if (methodName.compare("removeJavascriptChannels") == 0) {
596-
result->NotImplemented();
619+
if (std::holds_alternative<flutter::EncodableList>(arguments)) {
620+
auto nameList = std::get<flutter::EncodableList>(arguments);
621+
for (size_t i = 0; i < nameList.size(); i++) {
622+
if (std::holds_alternative<std::string>(nameList[i])) {
623+
webViewInstance_->RemoveJavascriptInterface(
624+
std::get<std::string>(nameList[i]), "postMessage");
625+
}
626+
}
627+
}
628+
result->Success();
629+
597630
} else if (methodName.compare("clearCache") == 0) {
598631
webViewInstance_->ClearCache();
599632
result->Success();

0 commit comments

Comments
 (0)