Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
41e109d
[url_launcher_linux] Support file scheme
jokerttu Nov 1, 2021
ee94d39
[url_launcher_linux] Register directory mime type for tests
jokerttu Nov 10, 2021
18ff23e
Merge remote-tracking branch 'origin/master' into url_launcher_linux_…
jokerttu Jan 7, 2022
a7b908c
[url_launcher_linux] Add domain to file scheme test
jokerttu Jan 7, 2022
9d717df
[url_launcher_linux] Fix memory leak on file scheme test
jokerttu Jan 7, 2022
011c9fb
[url_launcher_linux] Convert pointers to autoptrs
jokerttu Jan 7, 2022
a498e5f
[url_launcher_linux] Fix format
jokerttu Jan 7, 2022
c50438c
Merge remote-tracking branch 'origin/main' into url_launcher_linux_fi…
jokerttu Jan 7, 2022
7279304
[url_launcher_linux] Rename file resource function
jokerttu Jan 7, 2022
7f52fdb
[url_launcer_linux] Update changelog version
jokerttu Jan 7, 2022
c67829b
[url_launcher_linux] Simplify can_launch file check
jokerttu Jan 7, 2022
1b88515
Merge remote-tracking branch 'origin/main' into url_launcher_linux_fi…
jokerttu Jan 11, 2022
3a57774
[url_launcher_linux] Fix memory leak on tests
jokerttu Jan 11, 2022
747ec99
[url_launcher_linux] Update changelog and version
jokerttu Jan 11, 2022
4368f24
[url_launcher_linux] Fix version number to 2.0.3
jokerttu Jan 11, 2022
efcd6ab
[url_launcer_linux] Fix comment format
jokerttu Jan 12, 2022
267fdad
Merge remote-tracking branch 'origin/main' into url_launcher_linux_fi…
jokerttu Jan 12, 2022
f28dd93
Merge branch 'main' into url_launcher_linux_file_scheme_support
jokerttu Jan 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo ap
RUN echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | sudo tee /etc/apt/sources.list.d/google-chrome.list
RUN apt-get update && apt-get install -y --no-install-recommends google-chrome-stable

# Make Chrome the default so http: has a handler for url_launcher tests.
# Make Chrome the default so http: and file: has a handler for url_launcher tests.
RUN apt-get install -y xdg-utils
RUN xdg-settings set default-web-browser google-chrome.desktop
RUN xdg-mime default google-chrome.desktop inode/directory
3 changes: 2 additions & 1 deletion packages/url_launcher/url_launcher_linux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## NEXT
## 2.0.3

* Updates code for new analysis options.
* Fix minor memory leak in Linux url_launcher tests.
* Fixes canLaunch detection for URIs addressing on local or network file systems

## 2.0.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@ TEST(UrlLauncherPlugin, CanLaunchFailureUnhandled) {
expected));
}

TEST(UrlLauncherPlugin, CanLaunchFileSuccess) {
g_autoptr(FlValue) args = fl_value_new_map();
fl_value_set_string_take(args, "url", fl_value_new_string("file:///"));
g_autoptr(FlMethodResponse) response = can_launch(nullptr, args);
ASSERT_NE(response, nullptr);
ASSERT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
g_autoptr(FlValue) expected = fl_value_new_bool(true);
EXPECT_TRUE(fl_value_equal(fl_method_success_response_get_result(
FL_METHOD_SUCCESS_RESPONSE(response)),
expected));
}

TEST(UrlLauncherPlugin, CanLaunchFailureInvalidFileExtension) {
g_autoptr(FlValue) args = fl_value_new_map();
fl_value_set_string_take(
args, "url", fl_value_new_string("file:///madeup.madeupextension"));
g_autoptr(FlMethodResponse) response = can_launch(nullptr, args);
ASSERT_NE(response, nullptr);
ASSERT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
g_autoptr(FlValue) expected = fl_value_new_bool(false);
EXPECT_TRUE(fl_value_equal(fl_method_success_response_get_result(
FL_METHOD_SUCCESS_RESPONSE(response)),
expected));
}

// For consistency with the established mobile implementations,
// an invalid URL should return false, not an error.
TEST(UrlLauncherPlugin, CanLaunchFailureInvalidUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ static gchar* get_url(FlValue* args, GError** error) {
return g_strdup(fl_value_get_string(url_value));
}

// Checks if URI has launchable file resource.
static gboolean can_launch_uri_with_file_resource(FlUrlLauncherPlugin* self,
const gchar* url) {
g_autoptr(GError) error = nullptr;
g_autoptr(GFile) file = g_file_new_for_uri(url);
g_autoptr(GAppInfo) app_info =
g_file_query_default_handler(file, NULL, &error);
return app_info != nullptr;
}

// Called to check if a URL can be launched.
FlMethodResponse* can_launch(FlUrlLauncherPlugin* self, FlValue* args) {
g_autoptr(GError) error = nullptr;
Expand All @@ -60,6 +70,10 @@ FlMethodResponse* can_launch(FlUrlLauncherPlugin* self, FlValue* args) {
g_autoptr(GAppInfo) app_info =
g_app_info_get_default_for_uri_scheme(scheme);
is_launchable = app_info != nullptr;

if (!is_launchable) {
is_launchable = can_launch_uri_with_file_resource(self, url);
}
}

g_autoptr(FlValue) result = fl_value_new_bool(is_launchable);
Expand Down
2 changes: 1 addition & 1 deletion packages/url_launcher/url_launcher_linux/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: url_launcher_linux
description: Linux implementation of the url_launcher plugin.
repository: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_linux
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
version: 2.0.2
version: 2.0.3

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down