Commit c3cf1bd6 authored by Eric Willigers's avatar Eric Willigers Committed by Chromium LUCI CQ

Web Share Target for Chrome OS: Match wildcard content types

We now match wildcards like */* and image/* against
specific content types like image/png

Bug: 1153537
Change-Id: Ic0f5dc64ed92b71cd57c31b550f1330dc4acad96
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2569195
Auto-Submit: Eric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarNancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarMaggie Cai <mxcai@chromium.org>
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834124}
parent 4067cfd3
...@@ -81,7 +81,7 @@ apps::mojom::IntentFilterPtr CreateShareFileFilter( ...@@ -81,7 +81,7 @@ apps::mojom::IntentFilterPtr CreateShareFileFilter(
std::vector<apps::mojom::ConditionValuePtr> mime_type_condition_values; std::vector<apps::mojom::ConditionValuePtr> mime_type_condition_values;
for (auto& mime_type : content_types) { for (auto& mime_type : content_types) {
mime_type_condition_values.push_back(apps_util::MakeConditionValue( mime_type_condition_values.push_back(apps_util::MakeConditionValue(
mime_type, apps::mojom::PatternMatchType::kNone)); mime_type, apps::mojom::PatternMatchType::kMimeType));
} }
if (!mime_type_condition_values.empty()) { if (!mime_type_condition_values.empty()) {
auto mime_type_condition = auto mime_type_condition =
......
...@@ -92,8 +92,9 @@ void CheckUrlScopeFilter(const apps::mojom::IntentFilterPtr& intent_filter, ...@@ -92,8 +92,9 @@ void CheckUrlScopeFilter(const apps::mojom::IntentFilterPtr& intent_filter,
} }
void CheckShareFileFilter(const apps::mojom::IntentFilterPtr& intent_filter, void CheckShareFileFilter(const apps::mojom::IntentFilterPtr& intent_filter,
const std::vector<std::string>& content_types, const std::vector<std::string>& filter_types,
const std::string& different_content_type) { const std::vector<std::string>& accepted_types,
const std::vector<std::string>& rejected_types) {
EXPECT_FALSE(intent_filter->activity_name.has_value()); EXPECT_FALSE(intent_filter->activity_name.has_value());
EXPECT_FALSE(intent_filter->activity_label.has_value()); EXPECT_FALSE(intent_filter->activity_label.has_value());
...@@ -116,16 +117,19 @@ void CheckShareFileFilter(const apps::mojom::IntentFilterPtr& intent_filter, ...@@ -116,16 +117,19 @@ void CheckShareFileFilter(const apps::mojom::IntentFilterPtr& intent_filter,
{ {
const Condition& condition = *intent_filter->conditions[1]; const Condition& condition = *intent_filter->conditions[1];
EXPECT_EQ(condition.condition_type, ConditionType::kMimeType); EXPECT_EQ(condition.condition_type, ConditionType::kMimeType);
EXPECT_EQ(condition.condition_values.size(), content_types.size()); EXPECT_EQ(condition.condition_values.size(), filter_types.size());
for (unsigned i = 0; i < content_types.size(); ++i) { for (unsigned i = 0; i < filter_types.size(); ++i) {
EXPECT_EQ(condition.condition_values[i]->match_type, EXPECT_EQ(condition.condition_values[i]->match_type,
PatternMatchType::kNone); PatternMatchType::kMimeType);
EXPECT_EQ(condition.condition_values[i]->value, content_types[i]); EXPECT_EQ(condition.condition_values[i]->value, filter_types[i]);
}
}
for (const std::string& accepted_type : accepted_types) {
{ {
std::vector<GURL> filesystem_urls(1U); std::vector<GURL> filesystem_urls(1U);
std::vector<std::string> mime_types(1U, content_types[i]); std::vector<std::string> mime_types(1U, accepted_type);
EXPECT_TRUE(apps_util::IntentMatchesFilter( EXPECT_TRUE(apps_util::IntentMatchesFilter(
apps_util::CreateShareIntentFromFiles(filesystem_urls, mime_types), apps_util::CreateShareIntentFromFiles(filesystem_urls, mime_types),
intent_filter)); intent_filter));
...@@ -133,17 +137,16 @@ void CheckShareFileFilter(const apps::mojom::IntentFilterPtr& intent_filter, ...@@ -133,17 +137,16 @@ void CheckShareFileFilter(const apps::mojom::IntentFilterPtr& intent_filter,
{ {
std::vector<GURL> filesystem_urls(3U); std::vector<GURL> filesystem_urls(3U);
std::vector<std::string> mime_types(3U, content_types[i]); std::vector<std::string> mime_types(3U, accepted_type);
EXPECT_TRUE(apps_util::IntentMatchesFilter( EXPECT_TRUE(apps_util::IntentMatchesFilter(
apps_util::CreateShareIntentFromFiles(filesystem_urls, mime_types), apps_util::CreateShareIntentFromFiles(filesystem_urls, mime_types),
intent_filter)); intent_filter));
} }
} }
}
{ for (const std::string& rejected_type : rejected_types) {
std::vector<GURL> filesystem_urls(1U); std::vector<GURL> filesystem_urls(1U);
std::vector<std::string> mime_types(1U, different_content_type); std::vector<std::string> mime_types(1U, rejected_type);
EXPECT_FALSE(apps_util::IntentMatchesFilter( EXPECT_FALSE(apps_util::IntentMatchesFilter(
apps_util::CreateShareIntentFromFiles(filesystem_urls, mime_types), apps_util::CreateShareIntentFromFiles(filesystem_urls, mime_types),
intent_filter)); intent_filter));
...@@ -186,11 +189,42 @@ IN_PROC_BROWSER_TEST_F(WebAppsBaseBrowserTest, PopulateIntentFilters) { ...@@ -186,11 +189,42 @@ IN_PROC_BROWSER_TEST_F(WebAppsBaseBrowserTest, PopulateIntentFilters) {
CheckUrlScopeFilter(target[0], app_url.GetWithoutFilename(), CheckUrlScopeFilter(target[0], app_url.GetWithoutFilename(),
/*different_url=*/GURL("file:///")); /*different_url=*/GURL("file:///"));
const std::vector<std::string> content_types( const std::vector<std::string> filter_types(
{"text/*", "image/svg+xml", "*/*"}); {"text/*", "image/svg+xml", "*/*"});
CheckShareFileFilter( const std::vector<std::string> accepted_types(
target[1], content_types, {"text/plain", "image/svg+xml", "video/webm"});
/*different_content_type=*/"application/vnd.android.package-archive"); const std::vector<std::string> rejected_types; // No types are rejected.
CheckShareFileFilter(target[1], filter_types, accepted_types, rejected_types);
}
IN_PROC_BROWSER_TEST_F(WebAppsBaseBrowserTest, PartialWild) {
ASSERT_TRUE(embedded_test_server()->Start());
const GURL app_url(
embedded_test_server()->GetURL("/web_share_target/partial-wild.html"));
std::vector<mojom::IntentFilterPtr> target;
{
const web_app::WebAppRegistrar* registrar =
web_app::WebAppProvider::Get(browser()->profile())
->registrar()
.AsWebAppRegistrar();
const web_app::AppId app_id =
web_app::InstallWebAppFromManifest(browser(), app_url);
const web_app::WebApp* web_app = registrar->GetAppById(app_id);
ASSERT_TRUE(web_app);
PopulateIntentFilters(*web_app, target);
}
EXPECT_EQ(target.size(), 2U);
CheckUrlScopeFilter(target[0], app_url.GetWithoutFilename(),
/*different_url=*/GURL("file:///"));
const std::vector<std::string> filter_types({"image/*"});
const std::vector<std::string> accepted_types({"image/png", "image/svg+xml"});
const std::vector<std::string> rejected_types(
{"application/vnd.android.package-archive", "text/plain"});
CheckShareFileFilter(target[1], filter_types, accepted_types, rejected_types);
} }
IN_PROC_BROWSER_TEST_F(WebAppsBaseBrowserTest, LaunchWithIntent) { IN_PROC_BROWSER_TEST_F(WebAppsBaseBrowserTest, LaunchWithIntent) {
......
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="manifest" href="partial-wild.json">
<link rel="icon" href="basic-48.png">
</head>
<body>
<h1>Partial Wild</h1>
<script>
window.onload = () => {
navigator.serviceWorker.register('/web_share_target/service_worker.js');
};
</script>
</body>
</html>
{
"name": "Partial Wild",
"icons": [
{
"src": "basic-48.png",
"sizes": "48x48",
"type": "image/png"
},
{
"src": "basic-192.png",
"sizes": "192x192",
"type": "image/png"
}
],
"start_url": "partial-wild.html",
"display": "minimal-ui",
"share_target": {
"action": "/web_share_target/share.html",
"method": "POST",
"enctype": "multipart/form-data",
"params": {
"files": [
{
"name": "graphs",
"accept": "image/*"
}
]
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment