Commit 4695e814 authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

Eliminate need for Chrome to subclass InterceptNavigationDelegate

WebLayer will shortly be incorporating
//components/navigation_interception, following the model set by
//chrome. As a precursor, this CL moves the functionality that is in
the //chrome subclass of InterceptNavigationDelegate to be available to
all embedders via a construction parameter of
InterceptNavigationDelegate. WebLayer will reuse this functionality.

TBR=eroman@chromium.org

Bug: 1031465
Change-Id: I0dae07c117e071d9bc16e937cc5dc5cd64960ced
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2102730
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750517}
parent b12fd8d6
......@@ -4,32 +4,8 @@
#include "chrome/android/chrome_jni_headers/InterceptNavigationDelegateImpl_jni.h"
#include "components/navigation_interception/intercept_navigation_delegate.h"
#include "components/navigation_interception/navigation_params.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "net/base/escape.h"
namespace {
using navigation_interception::InterceptNavigationDelegate;
using navigation_interception::NavigationParams;
class ChromeInterceptNavigationDelegate : public InterceptNavigationDelegate {
public:
ChromeInterceptNavigationDelegate(JNIEnv* env, jobject jdelegate)
: InterceptNavigationDelegate(env, jdelegate) {}
bool ShouldIgnoreNavigation(
const NavigationParams& navigation_params) override {
NavigationParams chrome_navigation_params(navigation_params);
chrome_navigation_params.url() =
GURL(net::EscapeExternalHandlerValue(navigation_params.url().spec()));
return InterceptNavigationDelegate::ShouldIgnoreNavigation(
chrome_navigation_params);
}
};
} // namespace
static void JNI_InterceptNavigationDelegateImpl_AssociateWithWebContents(
JNIEnv* env,
......@@ -38,7 +14,8 @@ static void JNI_InterceptNavigationDelegateImpl_AssociateWithWebContents(
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
content::WebContents* web_contents =
content::WebContents::FromJavaWebContents(jweb_contents);
InterceptNavigationDelegate::Associate(
navigation_interception::InterceptNavigationDelegate::Associate(
web_contents,
std::make_unique<ChromeInterceptNavigationDelegate>(env, jdelegate));
std::make_unique<navigation_interception::InterceptNavigationDelegate>(
env, jdelegate, /*escape_external_handler_value=*/true));
}
include_rules = [
"+components/navigation_interception/jni_headers",
"+net",
"+ui/base",
"+content/public/browser",
......
......@@ -17,6 +17,7 @@
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "net/base/escape.h"
#include "url/gurl.h"
using base::android::ConvertUTF8ToJavaString;
......@@ -76,16 +77,24 @@ InterceptNavigationDelegate::CreateThrottleFor(
}
InterceptNavigationDelegate::InterceptNavigationDelegate(
JNIEnv* env, jobject jdelegate)
: weak_jdelegate_(env, jdelegate) {
}
JNIEnv* env,
jobject jdelegate,
bool escape_external_handler_value)
: weak_jdelegate_(env, jdelegate),
escape_external_handler_value_(escape_external_handler_value) {}
InterceptNavigationDelegate::~InterceptNavigationDelegate() {
}
bool InterceptNavigationDelegate::ShouldIgnoreNavigation(
const NavigationParams& navigation_params) {
if (!navigation_params.url().is_valid())
NavigationParams navigation_params_to_use(navigation_params);
if (escape_external_handler_value_) {
navigation_params_to_use.url() =
GURL(net::EscapeExternalHandlerValue(navigation_params.url().spec()));
}
if (!navigation_params_to_use.url().is_valid())
return false;
JNIEnv* env = base::android::AttachCurrentThread();
......@@ -95,13 +104,13 @@ bool InterceptNavigationDelegate::ShouldIgnoreNavigation(
return false;
bool has_user_gesture_carryover =
!navigation_params.has_user_gesture() &&
!navigation_params_to_use.has_user_gesture() &&
base::TimeTicks::Now() - last_user_gesture_carryover_timestamp_ <=
base::TimeDelta::FromSeconds(
kMaxValidityOfUserGestureCarryoverInSeconds);
ScopedJavaLocalRef<jobject> jobject_params = CreateJavaNavigationParams(
env, navigation_params, has_user_gesture_carryover);
env, navigation_params_to_use, has_user_gesture_carryover);
return Java_InterceptNavigationDelegate_shouldIgnoreNavigation(
env, jdelegate, jobject_params);
......
......@@ -34,7 +34,12 @@ class NavigationParams;
// with the NavigationHandle in the ContentBrowserClient implementation.
class InterceptNavigationDelegate : public base::SupportsUserData::Data {
public:
InterceptNavigationDelegate(JNIEnv* env, jobject jdelegate);
// Pass true for |escape_external_handler_value| to have
// net::EscapeExternalHandlerValue() invoked on URLs passed to
// ShouldIgnoreNavigation() before the navigation is processed.
InterceptNavigationDelegate(JNIEnv* env,
jobject jdelegate,
bool escape_external_handler_value = false);
~InterceptNavigationDelegate() override;
// Associates the InterceptNavigationDelegate with a WebContents using the
......@@ -63,6 +68,7 @@ class InterceptNavigationDelegate : public base::SupportsUserData::Data {
private:
JavaObjectWeakGlobalRef weak_jdelegate_;
base::TimeTicks last_user_gesture_carryover_timestamp_;
bool escape_external_handler_value_ = false;
DISALLOW_COPY_AND_ASSIGN(InterceptNavigationDelegate);
};
......
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