summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkwst <mkwst@chromium.org>2014-10-09 23:51:45 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-10 06:51:59 +0000
commit98ce5ad6bdd2cd058c21f19b997032f3b958cb73 (patch)
tree4c460ee8842febce151e3d4b1885be81a4eff1d3
parentfc01b28a3cad75c15b31b44443109cb9c69e629c (diff)
downloadchromium_src-98ce5ad6bdd2cd058c21f19b997032f3b958cb73.zip
chromium_src-98ce5ad6bdd2cd058c21f19b997032f3b958cb73.tar.gz
chromium_src-98ce5ad6bdd2cd058c21f19b997032f3b958cb73.tar.bz2
Content Shell: Introduce LayoutTestBrowserContext.
This splits the DRT-specific parts of ShellBrowserContext out into a new class that we'll only instantiate when the flag is set. BUG=420994 Review URL: https://codereview.chromium.org/637843003 Cr-Commit-Position: refs/heads/master@{#299068}
-rw-r--r--content/content_shell.gypi2
-rw-r--r--content/shell/BUILD.gn2
-rw-r--r--content/shell/browser/layout_test/layout_test_browser_context.cc54
-rw-r--r--content/shell/browser/layout_test/layout_test_browser_context.h37
-rw-r--r--content/shell/browser/shell_browser_context.cc19
-rw-r--r--content/shell/browser/shell_browser_context.h13
-rw-r--r--content/shell/browser/shell_browser_main_parts.cc13
7 files changed, 117 insertions, 23 deletions
diff --git a/content/content_shell.gypi b/content/content_shell.gypi
index de39c3e..db17510 100644
--- a/content/content_shell.gypi
+++ b/content/content_shell.gypi
@@ -92,6 +92,8 @@
'shell/app/webkit_test_platform_support_win.cc',
'shell/browser/ipc_echo_message_filter.cc',
'shell/browser/ipc_echo_message_filter.h',
+ 'shell/browser/layout_test/layout_test_browser_context.cc',
+ 'shell/browser/layout_test/layout_test_browser_context.h',
'shell/browser/layout_test/layout_test_devtools_frontend.cc',
'shell/browser/layout_test/layout_test_devtools_frontend.h',
'shell/browser/layout_test/layout_test_javascript_dialog_manager.cc',
diff --git a/content/shell/BUILD.gn b/content/shell/BUILD.gn
index 82c7132..15e9f15 100644
--- a/content/shell/BUILD.gn
+++ b/content/shell/BUILD.gn
@@ -41,6 +41,8 @@ static_library("content_shell_lib") {
"app/webkit_test_platform_support_win.cc",
"browser/ipc_echo_message_filter.cc",
"browser/ipc_echo_message_filter.h",
+ "browser/layout_test/layout_test_browser_context.cc",
+ "browser/layout_test/layout_test_browser_context.h",
"browser/layout_test/layout_test_devtools_frontend.cc",
"browser/layout_test/layout_test_devtools_frontend.h",
"browser/layout_test/layout_test_javascript_dialog_manager.cc",
diff --git a/content/shell/browser/layout_test/layout_test_browser_context.cc b/content/shell/browser/layout_test/layout_test_browser_context.cc
new file mode 100644
index 0000000..9bd80d0
--- /dev/null
+++ b/content/shell/browser/layout_test/layout_test_browser_context.cc
@@ -0,0 +1,54 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/shell/browser/layout_test/layout_test_browser_context.h"
+
+#include "base/bind.h"
+#include "base/command_line.h"
+#include "base/files/file_util.h"
+#include "base/logging.h"
+#include "base/path_service.h"
+#include "content/public/browser/resource_context.h"
+#include "content/shell/browser/shell_download_manager_delegate.h"
+#include "content/shell/browser/shell_url_request_context_getter.h"
+
+#if defined(OS_WIN)
+#include "base/base_paths_win.h"
+#elif defined(OS_LINUX)
+#include "base/nix/xdg_util.h"
+#elif defined(OS_MACOSX)
+#include "base/base_paths_mac.h"
+#endif
+
+namespace content {
+
+LayoutTestBrowserContext::LayoutTestBrowserContext(bool off_the_record,
+ net::NetLog* net_log)
+ : ShellBrowserContext(off_the_record, net_log) {
+}
+
+LayoutTestBrowserContext::~LayoutTestBrowserContext() {
+}
+
+void LayoutTestBrowserContext::InitWhileIOAllowed() {
+ ignore_certificate_errors_ = true;
+ ShellBrowserContext::InitWhileIOAllowed();
+}
+
+DownloadManagerDelegate*
+LayoutTestBrowserContext::GetDownloadManagerDelegate() {
+ if (!download_manager_delegate_.get()) {
+ download_manager_delegate_.reset(new ShellDownloadManagerDelegate());
+ download_manager_delegate_->SetDownloadManager(
+ BrowserContext::GetDownloadManager(this));
+ // TODO(mkwst): We can avoid this bit in the future by defining a
+ // LayoutTestDownloadManagerDelegate.
+ download_manager_delegate_->SetDownloadBehaviorForTesting(
+ GetPath().Append(FILE_PATH_LITERAL("downloads")));
+ }
+
+ return download_manager_delegate_.get();
+}
+
+} // namespace content
diff --git a/content/shell/browser/layout_test/layout_test_browser_context.h b/content/shell/browser/layout_test/layout_test_browser_context.h
new file mode 100644
index 0000000..87ffc58
--- /dev/null
+++ b/content/shell/browser/layout_test/layout_test_browser_context.h
@@ -0,0 +1,37 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_SHELL_BROWSER_LAYOUT_TEST_BROWSER_CONTEXT_H_
+#define CONTENT_SHELL_BROWSER_LAYOUT_TEST_BROWSER_CONTEXT_H_
+
+#include "base/compiler_specific.h"
+#include "content/shell/browser/shell_browser_context.h"
+
+namespace net {
+class NetLog;
+}
+
+namespace content {
+
+class DownloadManagerDelegate;
+
+class LayoutTestBrowserContext : public ShellBrowserContext {
+ public:
+ LayoutTestBrowserContext(bool off_the_record, net::NetLog* net_log);
+ virtual ~LayoutTestBrowserContext();
+
+ // BrowserContext implementation.
+ virtual DownloadManagerDelegate* GetDownloadManagerDelegate() override;
+
+ protected:
+ // Performs initialization of the ShellBrowserContext while IO is still
+ // allowed on the current thread.
+ virtual void InitWhileIOAllowed() override;
+
+ DISALLOW_COPY_AND_ASSIGN(LayoutTestBrowserContext);
+};
+
+} // namespace content
+
+#endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_BROWSER_CONTEXT_H_
diff --git a/content/shell/browser/shell_browser_context.cc b/content/shell/browser/shell_browser_context.cc
index 308ed38..733e938 100644
--- a/content/shell/browser/shell_browser_context.cc
+++ b/content/shell/browser/shell_browser_context.cc
@@ -49,9 +49,9 @@ ShellBrowserContext::ShellResourceContext::GetRequestContext() {
ShellBrowserContext::ShellBrowserContext(bool off_the_record,
net::NetLog* net_log)
: resource_context_(new ShellResourceContext),
+ ignore_certificate_errors_(false),
off_the_record_(off_the_record),
net_log_(net_log),
- ignore_certificate_errors_(false),
guest_manager_(NULL) {
InitWhileIOAllowed();
}
@@ -65,10 +65,8 @@ ShellBrowserContext::~ShellBrowserContext() {
void ShellBrowserContext::InitWhileIOAllowed() {
CommandLine* cmd_line = CommandLine::ForCurrentProcess();
- if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors) ||
- cmd_line->HasSwitch(switches::kDumpRenderTree)) {
+ if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors))
ignore_certificate_errors_ = true;
- }
if (cmd_line->HasSwitch(switches::kContentShellDataPath)) {
path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath);
return;
@@ -106,16 +104,10 @@ bool ShellBrowserContext::IsOffTheRecord() const {
}
DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() {
- DownloadManager* manager = BrowserContext::GetDownloadManager(this);
-
if (!download_manager_delegate_.get()) {
download_manager_delegate_.reset(new ShellDownloadManagerDelegate());
- download_manager_delegate_->SetDownloadManager(manager);
- CommandLine* cmd_line = CommandLine::ForCurrentProcess();
- if (cmd_line->HasSwitch(switches::kDumpRenderTree)) {
- download_manager_delegate_->SetDownloadBehaviorForTesting(
- path_.Append(FILE_PATH_LITERAL("downloads")));
- }
+ download_manager_delegate_->SetDownloadManager(
+ BrowserContext::GetDownloadManager(this));
}
return download_manager_delegate_.get();
@@ -137,7 +129,8 @@ net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext(
protocol_handlers,
request_interceptors.Pass(),
net_log_);
- resource_context_->set_url_request_context_getter(url_request_getter_.get());
+ static_cast<ShellResourceContext*>(resource_context_.get())
+ ->set_url_request_context_getter(url_request_getter_.get());
return url_request_getter_.get();
}
diff --git a/content/shell/browser/shell_browser_context.h b/content/shell/browser/shell_browser_context.h
index 81e8b94..15c123d 100644
--- a/content/shell/browser/shell_browser_context.h
+++ b/content/shell/browser/shell_browser_context.h
@@ -94,20 +94,19 @@ class ShellBrowserContext : public BrowserContext {
url_request_getter_ = getter;
}
- scoped_ptr<ShellResourceContext> resource_context_;
-
- private:
-
// Performs initialization of the ShellBrowserContext while IO is still
// allowed on the current thread.
- void InitWhileIOAllowed();
+ virtual void InitWhileIOAllowed();
+ scoped_ptr<ShellResourceContext> resource_context_;
+ bool ignore_certificate_errors_;
+ scoped_ptr<ShellDownloadManagerDelegate> download_manager_delegate_;
+
+ private:
bool off_the_record_;
net::NetLog* net_log_;
- bool ignore_certificate_errors_;
base::FilePath path_;
BrowserPluginGuestManager* guest_manager_;
- scoped_ptr<ShellDownloadManagerDelegate> download_manager_delegate_;
scoped_refptr<ShellURLRequestContextGetter> url_request_getter_;
DISALLOW_COPY_AND_ASSIGN(ShellBrowserContext);
diff --git a/content/shell/browser/shell_browser_main_parts.cc b/content/shell/browser/shell_browser_main_parts.cc
index d6a067f..bf24cd1 100644
--- a/content/shell/browser/shell_browser_main_parts.cc
+++ b/content/shell/browser/shell_browser_main_parts.cc
@@ -16,6 +16,7 @@
#include "content/public/common/content_switches.h"
#include "content/public/common/main_function_params.h"
#include "content/public/common/url_constants.h"
+#include "content/shell/browser/layout_test/layout_test_browser_context.h"
#include "content/shell/browser/shell.h"
#include "content/shell/browser/shell_browser_context.h"
#include "content/shell/browser/shell_devtools_delegate.h"
@@ -128,9 +129,15 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() {
}
#endif
net_log_.reset(new ShellNetLog("content_shell"));
- browser_context_.reset(new ShellBrowserContext(false, net_log_.get()));
- off_the_record_browser_context_.reset(
- new ShellBrowserContext(true, net_log_.get()));
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) {
+ browser_context_.reset(new LayoutTestBrowserContext(false, net_log_.get()));
+ off_the_record_browser_context_.reset(
+ new LayoutTestBrowserContext(true, net_log_.get()));
+ } else {
+ browser_context_.reset(new ShellBrowserContext(false, net_log_.get()));
+ off_the_record_browser_context_.reset(
+ new ShellBrowserContext(true, net_log_.get()));
+ }
Shell::Initialize();
net::NetModule::SetResourceProvider(PlatformResourceProvider);