Commit 20d192c8 authored by Alexey Baskakov's avatar Alexey Baskakov Committed by Commit Bot

WebApp: Implement IsValidWebAppUrl helper.

It will be needed in BMO's TabHelper to start installation.

It is similar to extensions::IsValidBookmarkAppUrl
but:
- Doesn't use extensions/common/url_pattern.h
- Reports chrome-extension:// url scheme as invalid.
- Reports filesystem: and any inner URL schemes as invalid.

Bug: 875698
Change-Id: I627a8e47593c698ef7acfc286cc310181b095685
Reviewed-on: https://chromium-review.googlesource.com/1180825
Commit-Queue: Alexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584373}
parent 8a1d59b0
......@@ -62,4 +62,11 @@ std::string GenerateExtensionKeyFromURL(const GURL& url) {
return key;
}
bool IsValidWebAppUrl(const GURL& app_url) {
if (app_url.is_empty() || app_url.inner_url())
return false;
return app_url.SchemeIsHTTPOrHTTPS();
}
} // namespace web_app
......@@ -37,6 +37,9 @@ std::string GetAppIdFromApplicationName(const std::string& app_name);
std::string GenerateExtensionIdFromURL(const GURL& url);
std::string GenerateExtensionKeyFromURL(const GURL& url);
// Returns whether the given |app_url| is a valid bookmark app url.
bool IsValidWebAppUrl(const GURL& app_url);
} // namespace web_app
#endif // CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_WEB_APP_HELPERS_H_
......@@ -32,4 +32,29 @@ TEST(WebAppHelpers, GenerateExtensionIdFromURL) {
"https://events.google.com/io2016/?utm_source=web_app_manifest")));
}
TEST(WebAppHelpers, IsValidWebAppUrl) {
EXPECT_TRUE(IsValidWebAppUrl(GURL("https://chromium.org")));
EXPECT_TRUE(IsValidWebAppUrl(GURL("https://www.chromium.org")));
EXPECT_TRUE(
IsValidWebAppUrl(GURL("https://www.chromium.org/path/to/page.html")));
EXPECT_TRUE(IsValidWebAppUrl(GURL("http://chromium.org")));
EXPECT_TRUE(IsValidWebAppUrl(GURL("http://www.chromium.org")));
EXPECT_TRUE(
IsValidWebAppUrl(GURL("http://www.chromium.org/path/to/page.html")));
EXPECT_TRUE(IsValidWebAppUrl(GURL("https://examle.com/foo?bar")));
EXPECT_TRUE(IsValidWebAppUrl(GURL("https://examle.com/foo#bar")));
EXPECT_FALSE(IsValidWebAppUrl(GURL()));
EXPECT_FALSE(IsValidWebAppUrl(
GURL("chrome-extension://oafaagfgbdpldilgjjfjocjglfbolmac")));
EXPECT_FALSE(IsValidWebAppUrl(GURL("ftp://www.chromium.org")));
EXPECT_FALSE(IsValidWebAppUrl(GURL("chrome://flags")));
EXPECT_FALSE(IsValidWebAppUrl(GURL("about:blank")));
EXPECT_FALSE(
IsValidWebAppUrl(GURL("file://mhjfbmdgcfjbbpaeojofohoefgiehjai")));
EXPECT_FALSE(IsValidWebAppUrl(GURL("chrome://extensions")));
EXPECT_FALSE(
IsValidWebAppUrl(GURL("filesystem:http://example.com/path/file.html")));
}
} // namespace web_app
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