summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
Diffstat (limited to 'content')
-rw-r--r--content/content_shell.gypi2
-rw-r--r--content/public/common/content_switches.cc4
-rw-r--r--content/public/common/content_switches.h1
-rw-r--r--content/shell/shell_browser_context.cc7
-rw-r--r--content/shell/shell_browser_context.h7
-rw-r--r--content/shell/shell_browser_main_parts.cc7
-rw-r--r--content/shell/shell_browser_main_parts.h7
-rw-r--r--content/shell/shell_content_browser_client.cc5
-rw-r--r--content/shell/shell_content_browser_client.h1
-rw-r--r--content/shell/shell_net_log.cc72
-rw-r--r--content/shell/shell_net_log.h28
-rw-r--r--content/shell/shell_url_request_context_getter.cc14
-rw-r--r--content/shell/shell_url_request_context_getter.h5
13 files changed, 150 insertions, 10 deletions
diff --git a/content/content_shell.gypi b/content/content_shell.gypi
index 812d4a2..f52459d 100644
--- a/content/content_shell.gypi
+++ b/content/content_shell.gypi
@@ -137,6 +137,8 @@
'shell/shell_login_dialog.h',
'shell/shell_message_filter.cc',
'shell/shell_message_filter.h',
+ 'shell/shell_net_log.cc',
+ 'shell/shell_net_log.h',
'shell/shell_network_delegate.cc',
'shell/shell_network_delegate.h',
'shell/shell_plugin_service_filter.cc',
diff --git a/content/public/common/content_switches.cc b/content/public/common/content_switches.cc
index aaad345..3b86d0d 100644
--- a/content/public/common/content_switches.cc
+++ b/content/public/common/content_switches.cc
@@ -165,6 +165,10 @@ const char kDisableLocalStorage[] = "disable-local-storage";
// builds.
const char kDisableLogging[] = "disable-logging";
+// Enables displaying net log events on the command line, or writing the events
+// to a separate file if a file name is given.
+const char kLogNetLog[] = "log-net-log";
+
// Prevent plugins from running.
const char kDisablePlugins[] = "disable-plugins";
diff --git a/content/public/common/content_switches.h b/content/public/common/content_switches.h
index 7218b239..11ce33e 100644
--- a/content/public/common/content_switches.h
+++ b/content/public/common/content_switches.h
@@ -66,6 +66,7 @@ CONTENT_EXPORT extern const char kDisableJavaScript[];
extern const char kDisableJavaScriptI18NAPI[];
CONTENT_EXPORT extern const char kDisableLocalStorage[];
CONTENT_EXPORT extern const char kDisableLogging[];
+CONTENT_EXPORT extern const char kLogNetLog[];
CONTENT_EXPORT extern const char kDisableSmoothScrolling[];
CONTENT_EXPORT extern const char kDisablePlugins[];
extern const char kDisableRemoteFonts[];
diff --git a/content/shell/shell_browser_context.cc b/content/shell/shell_browser_context.cc
index b3228a0..7cdaba1 100644
--- a/content/shell/shell_browser_context.cc
+++ b/content/shell/shell_browser_context.cc
@@ -54,8 +54,10 @@ class ShellBrowserContext::ShellResourceContext : public ResourceContext {
DISALLOW_COPY_AND_ASSIGN(ShellResourceContext);
};
-ShellBrowserContext::ShellBrowserContext(bool off_the_record)
+ShellBrowserContext::ShellBrowserContext(bool off_the_record,
+ net::NetLog* net_log)
: off_the_record_(off_the_record),
+ net_log_(net_log),
ignore_certificate_errors_(false),
resource_context_(new ShellResourceContext) {
InitWhileIOAllowed();
@@ -138,7 +140,8 @@ net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext(
GetPath(),
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE),
- protocol_handlers);
+ protocol_handlers,
+ net_log_);
resource_context_->set_url_request_context_getter(url_request_getter_.get());
return url_request_getter_.get();
}
diff --git a/content/shell/shell_browser_context.h b/content/shell/shell_browser_context.h
index 9146499..7248707 100644
--- a/content/shell/shell_browser_context.h
+++ b/content/shell/shell_browser_context.h
@@ -13,6 +13,10 @@
#include "content/public/browser/content_browser_client.h"
#include "net/url_request/url_request_job_factory.h"
+namespace net {
+class NetLog;
+}
+
namespace content {
class DownloadManagerDelegate;
@@ -22,7 +26,7 @@ class ShellURLRequestContextGetter;
class ShellBrowserContext : public BrowserContext {
public:
- explicit ShellBrowserContext(bool off_the_record);
+ ShellBrowserContext(bool off_the_record, net::NetLog* net_log);
virtual ~ShellBrowserContext();
// BrowserContext implementation.
@@ -61,6 +65,7 @@ class ShellBrowserContext : public BrowserContext {
void InitWhileIOAllowed();
bool off_the_record_;
+ net::NetLog* net_log_;
bool ignore_certificate_errors_;
base::FilePath path_;
scoped_ptr<ShellResourceContext> resource_context_;
diff --git a/content/shell/shell_browser_main_parts.cc b/content/shell/shell_browser_main_parts.cc
index 8df887e..71ee4d5 100644
--- a/content/shell/shell_browser_main_parts.cc
+++ b/content/shell/shell_browser_main_parts.cc
@@ -18,6 +18,7 @@
#include "content/shell/shell.h"
#include "content/shell/shell_browser_context.h"
#include "content/shell/shell_devtools_delegate.h"
+#include "content/shell/shell_net_log.h"
#include "googleurl/src/gurl.h"
#include "grit/net_resources.h"
#include "net/base/net_module.h"
@@ -107,8 +108,10 @@ void ShellBrowserMainParts::PreEarlyInitialization() {
}
void ShellBrowserMainParts::PreMainMessageLoopRun() {
- browser_context_.reset(new ShellBrowserContext(false));
- off_the_record_browser_context_.reset(new ShellBrowserContext(true));
+ net_log_.reset(new ShellNetLog());
+ 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);
diff --git a/content/shell/shell_browser_main_parts.h b/content/shell/shell_browser_main_parts.h
index ab8dbce..8ba4c1f 100644
--- a/content/shell/shell_browser_main_parts.h
+++ b/content/shell/shell_browser_main_parts.h
@@ -13,6 +13,10 @@ namespace base {
class Thread;
}
+namespace net {
+class NetLog;
+}
+
namespace content {
class ShellBrowserContext;
@@ -42,7 +46,10 @@ class ShellBrowserMainParts : public BrowserMainParts {
return off_the_record_browser_context_.get();
}
+ net::NetLog* net_log() { return net_log_.get(); }
+
private:
+ scoped_ptr<net::NetLog> net_log_;
scoped_ptr<ShellBrowserContext> browser_context_;
scoped_ptr<ShellBrowserContext> off_the_record_browser_context_;
diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc
index a292904..412f24c 100644
--- a/content/shell/shell_content_browser_client.cc
+++ b/content/shell/shell_content_browser_client.cc
@@ -23,6 +23,7 @@
#include "content/shell/shell_browser_main_parts.h"
#include "content/shell/shell_devtools_delegate.h"
#include "content/shell/shell_message_filter.h"
+#include "content/shell/shell_net_log.h"
#include "content/shell/shell_quota_permission_context.h"
#include "content/shell/shell_resource_dispatcher_host_delegate.h"
#include "content/shell/shell_web_contents_view_delegate_creator.h"
@@ -183,6 +184,10 @@ ShellContentBrowserClient::CreateQuotaPermissionContext() {
return new ShellQuotaPermissionContext();
}
+net::NetLog* ShellContentBrowserClient::GetNetLog() {
+ return shell_browser_main_parts_->net_log();
+}
+
#if defined(OS_ANDROID)
void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
const CommandLine& command_line,
diff --git a/content/shell/shell_content_browser_client.h b/content/shell/shell_content_browser_client.h
index 592984c..d88ca8a 100644
--- a/content/shell/shell_content_browser_client.h
+++ b/content/shell/shell_content_browser_client.h
@@ -56,6 +56,7 @@ class ShellContentBrowserClient : public ContentBrowserClient,
virtual WebContentsViewDelegate* GetWebContentsViewDelegate(
WebContents* web_contents) OVERRIDE;
virtual QuotaPermissionContext* CreateQuotaPermissionContext() OVERRIDE;
+ virtual net::NetLog* GetNetLog() OVERRIDE;
#if defined(OS_ANDROID)
virtual void GetAdditionalMappedFilesForChildProcess(
diff --git a/content/shell/shell_net_log.cc b/content/shell/shell_net_log.cc
new file mode 100644
index 0000000..03443d2
--- /dev/null
+++ b/content/shell/shell_net_log.cc
@@ -0,0 +1,72 @@
+// Copyright 2013 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/shell_net_log.h"
+
+#include <stdio.h>
+
+#include "base/command_line.h"
+#include "base/files/file_path.h"
+#include "base/values.h"
+#include "content/public/common/content_switches.h"
+#include "net/base/net_log_logger.h"
+
+namespace content {
+
+namespace {
+
+base::DictionaryValue* GetShellConstants() {
+ base::DictionaryValue* constants_dict = net::NetLogLogger::GetConstants();
+
+ // Add a dictionary with client information
+ base::DictionaryValue* dict = new DictionaryValue();
+
+ dict->SetString("name", "content_shell");
+ dict->SetString("command_line",
+ CommandLine::ForCurrentProcess()->GetCommandLineString());
+
+ constants_dict->Set("clientInfo", dict);
+
+ return constants_dict;
+}
+
+} // namespace
+
+ShellNetLog::ShellNetLog() {
+ const CommandLine* command_line = CommandLine::ForCurrentProcess();
+
+ if (command_line->HasSwitch(switches::kLogNetLog)) {
+ base::FilePath log_path =
+ command_line->GetSwitchValuePath(switches::kLogNetLog);
+ // Much like logging.h, bypass threading restrictions by using fopen
+ // directly. Have to write on a thread that's shutdown to handle events on
+ // shutdown properly, and posting events to another thread as they occur
+ // would result in an unbounded buffer size, so not much can be gained by
+ // doing this on another thread. It's only used when debugging, so
+ // performance is not a big concern.
+ FILE* file = NULL;
+#if defined(OS_WIN)
+ file = _wfopen(log_path.value().c_str(), L"w");
+#elif defined(OS_POSIX)
+ file = fopen(log_path.value().c_str(), "w");
+#endif
+
+ if (file == NULL) {
+ LOG(ERROR) << "Could not open file " << log_path.value()
+ << " for net logging";
+ } else {
+ scoped_ptr<base::Value> constants(GetShellConstants());
+ net_log_logger_.reset(new net::NetLogLogger(file, *constants));
+ net_log_logger_->StartObserving(this);
+ }
+ }
+}
+
+ShellNetLog::~ShellNetLog() {
+ // Remove the observer we own before we're destroyed.
+ if (net_log_logger_)
+ RemoveThreadSafeObserver(net_log_logger_.get());
+}
+
+} // namespace content
diff --git a/content/shell/shell_net_log.h b/content/shell/shell_net_log.h
new file mode 100644
index 0000000..ead9108
--- /dev/null
+++ b/content/shell/shell_net_log.h
@@ -0,0 +1,28 @@
+// Copyright 2013 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_SHELL_CONTENT_BROWSER_CLIENT_H_
+#define CONTENT_SHELL_SHELL_CONTENT_BROWSER_CLIENT_H_
+
+#include <string>
+
+#include "base/memory/scoped_ptr.h"
+#include "net/base/net_log_logger.h"
+
+namespace content {
+
+class ShellNetLog : public net::NetLog {
+ public:
+ ShellNetLog();
+ virtual ~ShellNetLog();
+
+ private:
+ scoped_ptr<net::NetLogLogger> net_log_logger_;
+
+ DISALLOW_COPY_AND_ASSIGN(ShellNetLog);
+};
+
+} // namespace content
+
+#endif // CONTENT_SHELL_SHELL_CONTENT_BROWSER_CLIENT_H_
diff --git a/content/shell/shell_url_request_context_getter.cc b/content/shell/shell_url_request_context_getter.cc
index e392c51..431392b 100644
--- a/content/shell/shell_url_request_context_getter.cc
+++ b/content/shell/shell_url_request_context_getter.cc
@@ -61,11 +61,13 @@ ShellURLRequestContextGetter::ShellURLRequestContextGetter(
const base::FilePath& base_path,
base::MessageLoop* io_loop,
base::MessageLoop* file_loop,
- ProtocolHandlerMap* protocol_handlers)
+ ProtocolHandlerMap* protocol_handlers,
+ net::NetLog* net_log)
: ignore_certificate_errors_(ignore_certificate_errors),
base_path_(base_path),
io_loop_(io_loop),
- file_loop_(file_loop) {
+ file_loop_(file_loop),
+ net_log_(net_log) {
// Must first be created on the UI thread.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -91,6 +93,7 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
url_request_context_.reset(new net::URLRequestContext());
+ url_request_context_->set_net_log(net_log_);
network_delegate_.reset(new ShellNetworkDelegate);
if (command_line.HasSwitch(switches::kDumpRenderTree))
ShellNetworkDelegate::SetAcceptAllCookies(false);
@@ -105,7 +108,8 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() {
new net::StaticHttpUserAgentSettings("en-us,en", EmptyString()));
scoped_ptr<net::HostResolver> host_resolver(
- net::HostResolver::CreateDefaultResolver(NULL));
+ net::HostResolver::CreateDefaultResolver(
+ url_request_context_->net_log()));
storage_->set_cert_verifier(net::CertVerifier::CreateDefault());
storage_->set_transport_security_state(new net::TransportSecurityState);
@@ -117,7 +121,7 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() {
net::ProxyService::CreateUsingSystemProxyResolver(
proxy_config_service_.release(),
0,
- NULL));
+ url_request_context_->net_log()));
}
storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults);
storage_->set_http_auth_handler_factory(
@@ -157,6 +161,8 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() {
network_delegate_.get();
network_session_params.http_server_properties =
url_request_context_->http_server_properties();
+ network_session_params.net_log =
+ url_request_context_->net_log();
network_session_params.ignore_certificate_errors =
ignore_certificate_errors_;
if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) {
diff --git a/content/shell/shell_url_request_context_getter.h b/content/shell/shell_url_request_context_getter.h
index d7a96b2..d1afb6f 100644
--- a/content/shell/shell_url_request_context_getter.h
+++ b/content/shell/shell_url_request_context_getter.h
@@ -21,6 +21,7 @@ namespace net {
class HostResolver;
class MappedHostResolver;
class NetworkDelegate;
+class NetLog;
class ProxyConfigService;
class URLRequestContextStorage;
}
@@ -34,7 +35,8 @@ class ShellURLRequestContextGetter : public net::URLRequestContextGetter {
const base::FilePath& base_path,
base::MessageLoop* io_loop,
base::MessageLoop* file_loop,
- ProtocolHandlerMap* protocol_handlers);
+ ProtocolHandlerMap* protocol_handlers,
+ net::NetLog* net_log);
// net::URLRequestContextGetter implementation.
virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE;
@@ -51,6 +53,7 @@ class ShellURLRequestContextGetter : public net::URLRequestContextGetter {
base::FilePath base_path_;
base::MessageLoop* io_loop_;
base::MessageLoop* file_loop_;
+ net::NetLog* net_log_;
scoped_ptr<net::ProxyConfigService> proxy_config_service_;
scoped_ptr<net::NetworkDelegate> network_delegate_;