Commit 0dd5860e authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

weblayer: extend set of schemes handled by WebLayer

WebLayer's ShouldOverrideUrlLoading() defines a set of known scheme.
Any URL that not in the set will fail to load if not initiated by a
user gesture. The set is incomplete and needs to include some other
schemes such as 'blob'.

This patch moves from a regex in the java side to
weblayer/browser/content_browser_client_impl.cc where it can use
existing constants.

BUG=1056259
TEST=covered by wpt

Change-Id: I1d38e4f6a27099426786736aeeea6a2f24851882
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2074811Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745301}
parent b0757c20
......@@ -1488,7 +1488,7 @@ class CONTENT_EXPORT ContentBrowserClient {
virtual std::vector<base::FilePath> GetNetworkContextsParentDirectory();
#if defined(OS_ANDROID)
// Only used by Android WebView.
// Only used by Android WebView/WebLayer.
// Returns:
// true - The check was successfully performed without throwing a
// Java exception. |*ignore_navigation| is set to the
......
......@@ -7,10 +7,13 @@
#include <utility>
#include "base/command_line.h"
#include "base/containers/flat_set.h"
#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/no_destructor.h"
#include "base/path_service.h"
#include "base/stl_util.h"
#include "base/strings/string_piece.h"
#include "build/build_config.h"
#include "components/autofill/content/browser/content_autofill_driver_factory.h"
#include "components/captive_portal/core/buildflags.h"
......@@ -28,6 +31,7 @@
#include "content/public/browser/network_service_instance.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/service_names.mojom.h"
#include "content/public/common/url_constants.h"
#include "content/public/common/user_agent.h"
#include "content/public/common/web_preferences.h"
#include "content/public/common/window_container_type.mojom.h"
......@@ -41,6 +45,7 @@
#include "third_party/blink/public/common/user_agent/user_agent_metadata.h"
#include "url/gurl.h"
#include "url/origin.h"
#include "url/url_constants.h"
#include "weblayer/browser/browser_main_parts_impl.h"
#include "weblayer/browser/browser_process.h"
#include "weblayer/browser/feature_list_creator.h"
......@@ -143,6 +148,26 @@ void HandleSSLErrorWrapper(
std::make_unique<weblayer::WebLayerSecurityBlockingPageFactory>());
}
#if defined(OS_ANDROID)
// Returns true if |scheme| identifies one that is handled/known by WebLayer.
bool IsHandledScheme(base::StringPiece scheme) {
DCHECK_EQ(scheme, base::ToLowerASCII(scheme));
static const base::NoDestructor<base::flat_set<base::StringPiece>>
kKnownSchemes(base::flat_set<base::StringPiece>({
content::kChromeDevToolsScheme, content::kChromeUIScheme,
content::kChromeUIUntrustedScheme, url::kAboutScheme,
url::kBlobScheme, url::kDataScheme, url::kFileScheme,
url::kFileSystemScheme, url::kHttpScheme, url::kHttpsScheme,
url::kJavaScriptScheme,
#if BUILDFLAG(ENABLE_WEBSOCKETS)
url::kWsScheme, url::kWssScheme,
#endif // BUILDFLAG(ENABLE_WEBSOCKETS)
url::kContentScheme,
}));
return kKnownSchemes->contains(scheme);
}
#endif // defined(OS_ANDROID)
} // namespace
namespace weblayer {
......@@ -553,6 +578,9 @@ bool ContentBrowserClientImpl::ShouldOverrideUrlLoading(
if (web_contents == nullptr)
return true;
if (gurl.is_valid() && IsHandledScheme(gurl.scheme()))
return true;
JNIEnv* env = base::android::AttachCurrentThread();
base::string16 url = base::UTF8ToUTF16(gurl.possibly_invalid_spec());
......
......@@ -13,9 +13,6 @@ import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* A class that handles navigations that should be transformed to intents. Logic taken primarly from
* //android_webview's AwContentsClient.java:sendBrowsingIntent(), with some additional logic
......@@ -25,25 +22,12 @@ import java.util.regex.Pattern;
public class ExternalNavigationHandler {
private static final String TAG = "ExternalNavHandler";
static final Pattern BROWSER_URI_SCHEMA =
Pattern.compile("(?i)" // switch on case insensitive matching
+ "(" // begin group for schema
+ "(?:http|https|file)://"
+ "|(?:inline|data|about|chrome|javascript):"
+ ")"
+ ".*");
@CalledByNative
private static boolean shouldOverrideUrlLoading(TabImpl tab, String url, boolean hasUserGesture,
boolean isRedirect, boolean isMainFrame) {
// Check for regular URIs that WebLayer supports by itself.
// TODO(blundell): Port over WebViewBrowserActivity's
// isSpecializedHandlerAvailable() check that checks whether there's an app for handling
// the scheme?
Matcher m = BROWSER_URI_SCHEMA.matcher(url);
if (m.matches()) {
return false;
}
if (!hasUserGesture && !isRedirect) {
Log.w(TAG, "Denied starting an intent without a user gesture, URI %s", url);
......
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