Commit e23f989b authored by meacer's avatar meacer Committed by Commit Bot

Allow data URL navigations for Android WebView until PlzNavigate ships

BUG=732976
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_site_isolation

Review-Url: https://codereview.chromium.org/2969473003
Cr-Commit-Position: refs/heads/master@{#486092}
parent b980b4b5
......@@ -167,6 +167,9 @@ void AwBrowserMainParts::PreMainMessageLoopRun() {
new AwGeolocationDelegate());
content::RenderFrameHost::AllowInjectingJavaScriptForAndroidWebView();
// TODO(meacer): Remove when PlzNavigate ships.
content::RenderFrameHost::AllowDataUrlNavigationForAndroidWebView();
}
bool AwBrowserMainParts::MainMessageLoopRun(int* result_code) {
......
......@@ -739,4 +739,31 @@ public class AwContentsTest extends AwTestBase {
awContents = createAwTestContainerView(mContentsClient).getAwContents();
awContents.resumeTimers();
}
/** Regression test for https://crbug.com/732976. Load a data URL, then immediately
* after that load a javascript URL. The data URL navigation shouldn't be blocked.
*/
@LargeTest
@Feature({"AndroidWebView"})
public void testJavaScriptUrlAfterLoadData() throws Throwable {
AwTestContainerView testView = createAwTestContainerViewOnMainSync(mContentsClient);
final AwContents awContents = testView.getAwContents();
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
// Run javascript navigation immediately, without waiting for the completion of data
// URL.
awContents.loadData("<html>test</html>", "text/html", "utf-8");
awContents.loadUrl("javascript: void(0)");
}
});
mContentsClient.getOnPageFinishedHelper().waitForCallback(
0, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
assertEquals("data:text/html,<html>test</html>", awContents.getLastCommittedUrl());
TestAwContentsClient.AddMessageToConsoleHelper consoleHelper =
mContentsClient.getAddMessageToConsoleHelper();
assertEquals(0, consoleHelper.getMessages().size());
}
}
......@@ -7,11 +7,13 @@
#include "base/feature_list.h"
#include "base/memory/ptr_util.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "content/browser/frame_host/frame_tree.h"
#include "content/browser/frame_host/frame_tree_node.h"
#include "content/browser/frame_host/navigation_handle_impl.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/common/browser_side_navigation_policy.h"
#include "content/public/common/console_message_level.h"
#include "content/public/common/content_features.h"
#include "url/url_constants.h"
......@@ -31,6 +33,18 @@ DataUrlNavigationThrottle::~DataUrlNavigationThrottle() {}
NavigationThrottle::ThrottleCheckResult
DataUrlNavigationThrottle::WillProcessResponse() {
#if defined(OS_ANDROID)
// This should ideally be done in CreateThrottleForNavigation(), but
// NavigationHandleImpl::GetRenderFrameHost() expects to not be run before
// WillProcessResponse().
// TODO(meacer): Remove this special case when PlzNavigate is enabled.
if (!IsBrowserSideNavigationEnabled() &&
navigation_handle()
->GetRenderFrameHost()
->IsDataUrlNavigationAllowedForAndroidWebView()) {
return PROCEED;
}
#endif
NavigationHandleImpl* handle =
static_cast<NavigationHandleImpl*>(navigation_handle());
if (handle->is_download())
......
......@@ -169,10 +169,16 @@ int g_next_accessibility_reset_token = 1;
// The next value to use for the javascript callback id.
int g_next_javascript_callback_id = 1;
#if defined(OS_ANDROID)
// Whether to allow injecting javascript into any kind of frame (for Android
// WebView).
bool g_allow_injecting_javascript = false;
// Whether to allow data URL navigations for Android WebView.
// TODO(meacer): Remove after PlzNavigate ships.
bool g_allow_data_url_navigation = false;
#endif
// The (process id, routing id) pair that identifies one RenderFrame.
typedef std::pair<int32_t, int32_t> RenderFrameHostID;
typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*>
......@@ -378,6 +384,16 @@ void RenderFrameHost::AllowInjectingJavaScriptForAndroidWebView() {
g_allow_injecting_javascript = true;
}
// static
void RenderFrameHost::AllowDataUrlNavigationForAndroidWebView() {
g_allow_data_url_navigation = true;
}
// static
bool RenderFrameHost::IsDataUrlNavigationAllowedForAndroidWebView() {
return g_allow_data_url_navigation;
}
void CreateMediaPlayerRenderer(
content::RenderFrameHost* render_frame_host,
const service_manager::BindSourceInfo& source_info,
......@@ -3775,8 +3791,11 @@ void RenderFrameHostImpl::UpdatePermissionsForNavigation(
}
bool RenderFrameHostImpl::CanExecuteJavaScript() {
return g_allow_injecting_javascript ||
!frame_tree_node_->current_url().is_valid() ||
#if defined(OS_ANDROID)
if (g_allow_injecting_javascript)
return true;
#endif
return !frame_tree_node_->current_url().is_valid() ||
frame_tree_node_->current_url().SchemeIs(kChromeDevToolsScheme) ||
ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
GetProcess()->GetID()) ||
......
......@@ -66,6 +66,11 @@ class CONTENT_EXPORT RenderFrameHost : public IPC::Listener,
// is present only to support Android WebView and must not be used in other
// configurations.
static void AllowInjectingJavaScriptForAndroidWebView();
// Temporary hack to enable data URLs on Android Webview until PlzNavigate
// ships.
static void AllowDataUrlNavigationForAndroidWebView();
static bool IsDataUrlNavigationAllowedForAndroidWebView();
#endif
// Returns a RenderFrameHost given its accessibility tree ID.
......
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