summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-27 15:36:27 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-27 15:36:27 +0000
commit53d96fbbf880cad9f26d7f60941b6ea36baeb617 (patch)
treecdfed9fd6cf3efd18a205aeee216ab6a344ce5a2 /content
parentf309053b6d0629741c5a2386131dcdce1001845d (diff)
downloadchromium_src-53d96fbbf880cad9f26d7f60941b6ea36baeb617.zip
chromium_src-53d96fbbf880cad9f26d7f60941b6ea36baeb617.tar.gz
chromium_src-53d96fbbf880cad9f26d7f60941b6ea36baeb617.tar.bz2
[content shell] block loading of non-local resources during layout tests, and add support for rewriting layout test urls
BUG=111316 TBR=jam@chromium.org Review URL: https://chromiumcodereview.appspot.com/11348246 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169661 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/public/renderer/content_renderer_client.cc1
-rw-r--r--content/public/renderer/content_renderer_client.h1
-rw-r--r--content/renderer/render_view_impl.cc6
-rw-r--r--content/shell/shell_content_browser_client.cc40
-rw-r--r--content/shell/shell_content_browser_client.h4
-rw-r--r--content/shell/shell_content_renderer_client.cc65
-rw-r--r--content/shell/shell_content_renderer_client.h6
-rw-r--r--content/shell/shell_messages.h4
-rw-r--r--content/shell/shell_render_process_observer.cc6
-rw-r--r--content/shell/shell_render_process_observer.h5
-rw-r--r--content/shell/shell_switches.cc3
-rw-r--r--content/shell/shell_switches.h1
12 files changed, 140 insertions, 2 deletions
diff --git a/content/public/renderer/content_renderer_client.cc b/content/public/renderer/content_renderer_client.cc
index 8edfa65..baf3240 100644
--- a/content/public/renderer/content_renderer_client.cc
+++ b/content/public/renderer/content_renderer_client.cc
@@ -80,6 +80,7 @@ bool ContentRendererClient::WillSendRequest(
WebKit::WebFrame* frame,
PageTransition transition_type,
const GURL& url,
+ const GURL& first_party_for_cookies,
GURL* new_url) {
return false;
}
diff --git a/content/public/renderer/content_renderer_client.h b/content/public/renderer/content_renderer_client.h
index 646da02..f12b29a 100644
--- a/content/public/renderer/content_renderer_client.h
+++ b/content/public/renderer/content_renderer_client.h
@@ -155,6 +155,7 @@ class CONTENT_EXPORT ContentRendererClient {
virtual bool WillSendRequest(WebKit::WebFrame* frame,
PageTransition transition_type,
const GURL& url,
+ const GURL& first_party_for_cookies,
GURL* new_url);
// Whether to pump events when sending sync cookie messages. Needed if the
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
index 51f6585..d145b28 100644
--- a/content/renderer/render_view_impl.cc
+++ b/content/renderer/render_view_impl.cc
@@ -3589,7 +3589,11 @@ void RenderViewImpl::willSendRequest(WebFrame* frame,
GURL request_url(request.url());
GURL new_url;
if (GetContentClient()->renderer()->WillSendRequest(
- frame, transition_type, request_url, &new_url)) {
+ frame,
+ transition_type,
+ request_url,
+ request.firstPartyForCookies(),
+ &new_url)) {
request.setURL(WebURL(new_url));
}
diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc
index 067591b..8c95f62 100644
--- a/content/shell/shell_content_browser_client.cc
+++ b/content/shell/shell_content_browser_client.cc
@@ -5,13 +5,16 @@
#include "content/shell/shell_content_browser_client.h"
#include "base/command_line.h"
-#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/path_service.h"
+#include "content/public/browser/render_process_host.h"
#include "content/public/browser/resource_dispatcher_host.h"
#include "content/shell/geolocation/shell_access_token_store.h"
#include "content/shell/shell.h"
#include "content/shell/shell_browser_context.h"
#include "content/shell/shell_browser_main_parts.h"
#include "content/shell/shell_devtools_delegate.h"
+#include "content/shell/shell_messages.h"
#include "content/shell/shell_resource_dispatcher_host_delegate.h"
#include "content/shell/shell_switches.h"
#include "content/shell/shell_web_contents_view_delegate_creator.h"
@@ -28,8 +31,36 @@
namespace content {
+namespace {
+
+FilePath GetWebKitRootDirFilePath() {
+ FilePath base_path;
+ PathService::Get(base::DIR_SOURCE_ROOT, &base_path);
+ if (file_util::PathExists(
+ base_path.Append(FILE_PATH_LITERAL("third_party/WebKit")))) {
+ // We're in a WebKit-in-chrome checkout.
+ return base_path.Append(FILE_PATH_LITERAL("third_party/WebKit"));
+ } else if (file_util::PathExists(
+ base_path.Append(FILE_PATH_LITERAL("chromium")))) {
+ // We're in a WebKit-only checkout on Windows.
+ return base_path.Append(FILE_PATH_LITERAL("../.."));
+ } else if (file_util::PathExists(
+ base_path.Append(FILE_PATH_LITERAL("webkit/support")))) {
+ // We're in a WebKit-only/xcodebuild checkout on Mac
+ return base_path.Append(FILE_PATH_LITERAL("../../.."));
+ }
+ // We're in a WebKit-only, make-build, so the DIR_SOURCE_ROOT is already the
+ // WebKit root. That, or we have no idea where we are.
+ return base_path;
+}
+
+} // namespace
+
ShellContentBrowserClient::ShellContentBrowserClient()
: shell_browser_main_parts_(NULL) {
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
+ return;
+ webkit_source_dir_ = GetWebKitRootDirFilePath();
}
ShellContentBrowserClient::~ShellContentBrowserClient() {
@@ -41,6 +72,13 @@ BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts(
return shell_browser_main_parts_;
}
+void ShellContentBrowserClient::RenderProcessHostCreated(
+ RenderProcessHost* host) {
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
+ return;
+ host->Send(new ShellViewMsg_SetWebKitSourceDir(webkit_source_dir_));
+}
+
void ShellContentBrowserClient::RenderViewHostCreated(
RenderViewHost* render_view_host) {
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
diff --git a/content/shell/shell_content_browser_client.h b/content/shell/shell_content_browser_client.h
index 40caaca..06f6516 100644
--- a/content/shell/shell_content_browser_client.h
+++ b/content/shell/shell_content_browser_client.h
@@ -8,6 +8,7 @@
#include <string>
#include "base/compiler_specific.h"
+#include "base/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "content/public/browser/content_browser_client.h"
@@ -25,6 +26,7 @@ class ShellContentBrowserClient : public ContentBrowserClient {
// ContentBrowserClient overrides.
virtual BrowserMainParts* CreateBrowserMainParts(
const MainFunctionParams& parameters) OVERRIDE;
+ virtual void RenderProcessHostCreated(RenderProcessHost* host) OVERRIDE;
virtual void RenderViewHostCreated(
RenderViewHost* render_view_host) OVERRIDE;
virtual void AppendExtraCommandLineSwitches(CommandLine* command_line,
@@ -58,6 +60,8 @@ class ShellContentBrowserClient : public ContentBrowserClient {
scoped_ptr<ShellResourceDispatcherHostDelegate>
resource_dispatcher_host_delegate_;
+ FilePath webkit_source_dir_;
+
ShellBrowserMainParts* shell_browser_main_parts_;
};
diff --git a/content/shell/shell_content_renderer_client.cc b/content/shell/shell_content_renderer_client.cc
index 01e73b0..bec3da5 100644
--- a/content/shell/shell_content_renderer_client.cc
+++ b/content/shell/shell_content_renderer_client.cc
@@ -6,8 +6,11 @@
#include "base/callback.h"
#include "base/command_line.h"
+#include "base/sys_string_conversions.h"
+#include "base/utf_string_conversions.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_switches.h"
+#include "content/public/common/url_constants.h"
#include "content/public/test/layouttest_support.h"
#include "content/shell/shell_render_process_observer.h"
#include "content/shell/shell_switches.h"
@@ -17,10 +20,31 @@
#include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestProxy.h"
#include "v8/include/v8.h"
+using WebKit::WebFrame;
using WebTestRunner::WebTestProxyBase;
namespace content {
+namespace {
+
+bool IsLocalhost(const std::string& host) {
+ return host == "127.0.0.1" || host == "localhost";
+}
+
+bool HostIsUsedBySomeTestsToGenerateError(const std::string& host) {
+ return host == "255.255.255.255";
+}
+
+bool IsExternalPage(const GURL& url) {
+ return !url.host().empty() &&
+ (url.SchemeIs(chrome::kHttpScheme) ||
+ url.SchemeIs(chrome::kHttpsScheme)) &&
+ !IsLocalhost(url.host()) &&
+ !HostIsUsedBySomeTestsToGenerateError(url.host());
+}
+
+} // namespace
+
ShellContentRendererClient::ShellContentRendererClient() {
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) {
EnableWebTestProxyCreation(
@@ -51,6 +75,26 @@ bool ShellContentRendererClient::OverrideCreatePlugin(
return false;
}
+bool ShellContentRendererClient::WillSendRequest(
+ WebFrame* frame,
+ PageTransition transition_type,
+ const GURL& url,
+ const GURL& first_party_for_cookies,
+ GURL* new_url) {
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ if (!command_line->HasSwitch(switches::kDumpRenderTree))
+ return false;
+ if (!command_line->HasSwitch(switches::kAllowExternalPages) &&
+ IsExternalPage(url) && !IsExternalPage(first_party_for_cookies)) {
+ ShellRenderProcessObserver::GetInstance()->test_delegate()->printMessage(
+ std::string("Blocked access to external URL " + url.spec() + "\n"));
+ *new_url = GURL();
+ return true;
+ }
+ *new_url = RewriteLayoutTestsURL(url);
+ return true;
+}
+
void ShellContentRendererClient::WebTestProxyCreated(RenderView* render_view,
WebTestProxyBase* proxy) {
WebKitTestRunner* test_runner = new WebKitTestRunner(render_view);
@@ -65,4 +109,25 @@ void ShellContentRendererClient::WebTestProxyCreated(RenderView* render_view,
ShellRenderProcessObserver::GetInstance()->test_interfaces());
}
+GURL ShellContentRendererClient::RewriteLayoutTestsURL(const GURL& url) {
+ const char kPrefix[] = "file:///tmp/LayoutTests/";
+ const int kPrefixLen = arraysize(kPrefix) - 1;
+
+ if (url.spec().compare(0, kPrefixLen, kPrefix, kPrefixLen))
+ return url;
+
+ FilePath replace_path =
+ ShellRenderProcessObserver::GetInstance()->webkit_source_dir().Append(
+ FILE_PATH_LITERAL("LayoutTests/"));
+#if defined(OS_WIN)
+ std::string utf8_path = WideToUTF8(replace_path.value());
+#else
+ std::string utf8_path =
+ WideToUTF8(base::SysNativeMBToWide(replace_path.value()));
+#endif
+ std::string new_url =
+ std::string("file://") + utf8_path + url.spec().substr(kPrefixLen);
+ return GURL(new_url);
+}
+
} // namespace content
diff --git a/content/shell/shell_content_renderer_client.h b/content/shell/shell_content_renderer_client.h
index 1ccf7ac..a71e3b4 100644
--- a/content/shell/shell_content_renderer_client.h
+++ b/content/shell/shell_content_renderer_client.h
@@ -34,10 +34,16 @@ class ShellContentRendererClient : public ContentRendererClient {
WebKit::WebFrame* frame,
const WebKit::WebPluginParams& params,
WebKit::WebPlugin** plugin) OVERRIDE;
+ virtual bool WillSendRequest(WebKit::WebFrame* frame,
+ PageTransition transition_type,
+ const GURL& url,
+ const GURL& first_party_for_cookies,
+ GURL* new_url) OVERRIDE;
private:
void WebTestProxyCreated(RenderView* render_view,
WebTestRunner::WebTestProxyBase* proxy);
+ GURL RewriteLayoutTestsURL(const GURL& url);
scoped_ptr<ShellRenderProcessObserver> shell_observer_;
};
diff --git a/content/shell/shell_messages.h b/content/shell/shell_messages.h
index d770e34..ac5a96a 100644
--- a/content/shell/shell_messages.h
+++ b/content/shell/shell_messages.h
@@ -30,6 +30,10 @@ IPC_MESSAGE_ROUTED1(ShellViewMsg_CaptureImageDump,
// Tells the renderer to reset all test runners.
IPC_MESSAGE_CONTROL0(ShellViewMsg_ResetAll)
+// Sets the path to the WebKit checkout.
+IPC_MESSAGE_CONTROL1(ShellViewMsg_SetWebKitSourceDir,
+ FilePath /* webkit source dir */)
+
// Send a text dump of the WebContents to the render host.
IPC_MESSAGE_ROUTED1(ShellViewHostMsg_TextDump,
std::string /* dump */)
diff --git a/content/shell/shell_render_process_observer.cc b/content/shell/shell_render_process_observer.cc
index 7c25ecf..ec26b6d 100644
--- a/content/shell/shell_render_process_observer.cc
+++ b/content/shell/shell_render_process_observer.cc
@@ -79,6 +79,7 @@ bool ShellRenderProcessObserver::OnControlMessageReceived(
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ShellRenderProcessObserver, message)
IPC_MESSAGE_HANDLER(ShellViewMsg_ResetAll, OnResetAll)
+ IPC_MESSAGE_HANDLER(ShellViewMsg_SetWebKitSourceDir, OnSetWebKitSourceDir)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
@@ -93,4 +94,9 @@ void ShellRenderProcessObserver::OnResetAll() {
}
}
+void ShellRenderProcessObserver::OnSetWebKitSourceDir(
+ const FilePath& webkit_source_dir) {
+ webkit_source_dir_ = webkit_source_dir;
+}
+
} // namespace content
diff --git a/content/shell/shell_render_process_observer.h b/content/shell/shell_render_process_observer.h
index 505c6e0..807239f 100644
--- a/content/shell/shell_render_process_observer.h
+++ b/content/shell/shell_render_process_observer.h
@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
+#include "base/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "content/public/renderer/render_process_observer.h"
@@ -44,15 +45,19 @@ class ShellRenderProcessObserver : public RenderProcessObserver {
WebTestRunner::WebTestInterfaces* test_interfaces() const {
return test_interfaces_.get();
}
+ const FilePath& webkit_source_dir() const { return webkit_source_dir_; }
private:
// Message handlers.
void OnResetAll();
+ void OnSetWebKitSourceDir(const FilePath& webkit_source_dir);
scoped_ptr<WebTestRunner::WebTestInterfaces> test_interfaces_;
RenderView* main_render_view_;
WebTestRunner::WebTestDelegate* test_delegate_;
+ FilePath webkit_source_dir_;
+
DISALLOW_COPY_AND_ASSIGN(ShellRenderProcessObserver);
};
diff --git a/content/shell/shell_switches.cc b/content/shell/shell_switches.cc
index 35e0c5e..be7f7cd 100644
--- a/content/shell/shell_switches.cc
+++ b/content/shell/shell_switches.cc
@@ -6,6 +6,9 @@
namespace switches {
+// Allow access to external pages during layout tests.
+const char kAllowExternalPages[] = "allow-external-pages";
+
// Check whether all system dependencies for running layout tests are met.
const char kCheckLayoutTestSysDeps[] = "check-layout-test-sys-deps";
diff --git a/content/shell/shell_switches.h b/content/shell/shell_switches.h
index 4fa203b..c440013 100644
--- a/content/shell/shell_switches.h
+++ b/content/shell/shell_switches.h
@@ -9,6 +9,7 @@
namespace switches {
+extern const char kAllowExternalPages[];
extern const char kCheckLayoutTestSysDeps[];
extern const char kContentBrowserTest[];
extern const char kContentShellDataPath[];