summaryrefslogtreecommitdiffstats
path: root/extensions/shell/browser
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/shell/browser')
-rw-r--r--extensions/shell/browser/DEPS1
-rw-r--r--extensions/shell/browser/shell_browser_context.cc48
-rw-r--r--extensions/shell/browser/shell_browser_context.h5
-rw-r--r--extensions/shell/browser/shell_network_delegate.cc132
-rw-r--r--extensions/shell/browser/shell_network_delegate.h59
-rw-r--r--extensions/shell/browser/shell_url_request_context_getter.cc42
-rw-r--r--extensions/shell/browser/shell_url_request_context_getter.h58
7 files changed, 318 insertions, 27 deletions
diff --git a/extensions/shell/browser/DEPS b/extensions/shell/browser/DEPS
index 4771a7b..5cb55ce 100644
--- a/extensions/shell/browser/DEPS
+++ b/extensions/shell/browser/DEPS
@@ -13,6 +13,7 @@ include_rules = [
"+content/shell/browser/shell_browser_context.h",
"+content/shell/browser/shell_devtools_delegate.h",
"+content/shell/browser/shell_net_log.h",
+ "+content/shell/browser/shell_url_request_context_getter.h",
# For device backend support.
"+device/core",
diff --git a/extensions/shell/browser/shell_browser_context.cc b/extensions/shell/browser/shell_browser_context.cc
index 8659de1..064dbf3 100644
--- a/extensions/shell/browser/shell_browser_context.cc
+++ b/extensions/shell/browser/shell_browser_context.cc
@@ -7,26 +7,28 @@
#include "base/command_line.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/content_switches.h"
-#include "extensions/browser/extension_network_delegate.h"
-#include "extensions/browser/extension_url_request_context_getter.h"
#include "extensions/browser/guest_view/guest_view_manager.h"
-#include "extensions/common/switches.h"
+#include "extensions/shell/browser/shell_network_delegate.h"
#include "extensions/shell/browser/shell_special_storage_policy.h"
+#include "extensions/shell/browser/shell_url_request_context_getter.h"
namespace extensions {
+namespace {
+
+bool IgnoreCertificateErrors() {
+ return base::CommandLine::ForCurrentProcess()->HasSwitch(
+ ::switches::kIgnoreCertificateErrors);
+}
+
+} // namespace
+
// Create a normal recording browser context. If we used an incognito context
// then app_shell would also have to create a normal context and manage both.
ShellBrowserContext::ShellBrowserContext(net::NetLog* net_log)
: content::ShellBrowserContext(false, NULL),
net_log_(net_log),
- ignore_certificate_errors_(false),
storage_policy_(new ShellSpecialStoragePolicy) {
- base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
- if (cmd_line->HasSwitch(::switches::kIgnoreCertificateErrors) ||
- cmd_line->HasSwitch(switches::kDumpRenderTree)) {
- ignore_certificate_errors_ = true;
- }
}
ShellBrowserContext::~ShellBrowserContext() {
@@ -44,11 +46,11 @@ net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors,
InfoMap* extension_info_map) {
- DCHECK(!url_request_context_getter_.get());
- url_request_context_getter_ =
- new extensions::ExtensionURLRequestContextGetter(
+ DCHECK(!url_request_context_getter());
+ set_url_request_context_getter(
+ new ShellURLRequestContextGetter(
this,
- ignore_certificate_errors_,
+ IgnoreCertificateErrors(),
GetPath(),
content::BrowserThread::UnsafeGetMessageLoopForThread(
content::BrowserThread::IO),
@@ -57,24 +59,24 @@ net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext(
protocol_handlers,
request_interceptors.Pass(),
net_log_,
- extension_info_map);
- Init();
- return url_request_context_getter_.get();
-}
-
-void ShellBrowserContext::Init(){
- content:: BrowserThread:: PostTask(
+ extension_info_map));
+ resource_context_->set_url_request_context_getter(
+ url_request_context_getter());
+ content::BrowserThread::PostTask(
content::BrowserThread::IO,
FROM_HERE,
base::Bind(
- &ShellBrowserContext::InitializationOnIOThread,
+ &ShellBrowserContext::InitURLRequestContextOnIOThread,
base::Unretained(this)));
+ return url_request_context_getter();
}
-void ShellBrowserContext::InitializationOnIOThread() {
+void ShellBrowserContext::InitURLRequestContextOnIOThread() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
- url_request_context_getter_->GetURLRequestContext();
+ // GetURLRequestContext() will create a URLRequestContext if it isn't
+ // initialized.
+ url_request_context_getter()->GetURLRequestContext();
}
void ShellBrowserContext::ProfileFunctionCallOnNonProfileBrowserContext1() {
diff --git a/extensions/shell/browser/shell_browser_context.h b/extensions/shell/browser/shell_browser_context.h
index 11ad208..b763777 100644
--- a/extensions/shell/browser/shell_browser_context.h
+++ b/extensions/shell/browser/shell_browser_context.h
@@ -54,12 +54,9 @@ class ShellBrowserContext : public content::ShellBrowserContext {
virtual void ProfileFunctionCallOnNonProfileBrowserContext15();
private:
- void Init();
- void InitializationOnIOThread();
+ void InitURLRequestContextOnIOThread();
net::NetLog* net_log_;
- bool ignore_certificate_errors_;
scoped_refptr<storage::SpecialStoragePolicy> storage_policy_;
- scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
DISALLOW_COPY_AND_ASSIGN(ShellBrowserContext);
};
diff --git a/extensions/shell/browser/shell_network_delegate.cc b/extensions/shell/browser/shell_network_delegate.cc
new file mode 100644
index 0000000..b148bc3
--- /dev/null
+++ b/extensions/shell/browser/shell_network_delegate.cc
@@ -0,0 +1,132 @@
+// 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 "extensions/shell/browser/shell_network_delegate.h"
+
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/resource_request_info.h"
+#include "extensions/browser/api/web_request/web_request_api.h"
+#include "extensions/browser/extension_system.h"
+#include "extensions/browser/extensions_browser_client.h"
+#include "extensions/browser/process_manager.h"
+#include "net/url_request/url_request.h"
+
+namespace extensions {
+
+namespace {
+bool g_accept_all_cookies = true;
+}
+
+ShellNetworkDelegate::ShellNetworkDelegate(
+ void* browser_context, InfoMap* extension_info_map) {
+ browser_context_ = browser_context;
+ extension_info_map_ = extension_info_map;
+}
+
+ShellNetworkDelegate::~ShellNetworkDelegate() {}
+
+void ShellNetworkDelegate::SetAcceptAllCookies(bool accept) {
+ g_accept_all_cookies = accept;
+}
+
+int ShellNetworkDelegate::OnBeforeURLRequest(
+ net::URLRequest* request,
+ const net::CompletionCallback& callback,
+ GURL* new_url) {
+ return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRequest(
+ browser_context_, extension_info_map_.get(), request, callback, new_url);
+}
+
+int ShellNetworkDelegate::OnBeforeSendHeaders(
+ net::URLRequest* request,
+ const net::CompletionCallback& callback,
+ net::HttpRequestHeaders* headers) {
+ return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeSendHeaders(
+ browser_context_, extension_info_map_.get(), request, callback, headers);
+}
+
+void ShellNetworkDelegate::OnSendHeaders(
+ net::URLRequest* request,
+ const net::HttpRequestHeaders& headers) {
+ ExtensionWebRequestEventRouter::GetInstance()->OnSendHeaders(
+ browser_context_, extension_info_map_.get(), request, headers);
+}
+
+int ShellNetworkDelegate::OnHeadersReceived(
+ net::URLRequest* request,
+ const net::CompletionCallback& callback,
+ const net::HttpResponseHeaders* original_response_headers,
+ scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
+ GURL* allowed_unsafe_redirect_url) {
+ return ExtensionWebRequestEventRouter::GetInstance()->OnHeadersReceived(
+ browser_context_,
+ extension_info_map_.get(),
+ request,
+ callback,
+ original_response_headers,
+ override_response_headers,
+ allowed_unsafe_redirect_url);
+}
+
+void ShellNetworkDelegate::OnBeforeRedirect(
+ net::URLRequest* request,
+ const GURL& new_location) {
+ ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRedirect(
+ browser_context_, extension_info_map_.get(), request, new_location);
+}
+
+
+void ShellNetworkDelegate::OnResponseStarted(
+ net::URLRequest* request) {
+ ExtensionWebRequestEventRouter::GetInstance()->OnResponseStarted(
+ browser_context_, extension_info_map_.get(), request);
+}
+
+void ShellNetworkDelegate::OnCompleted(
+ net::URLRequest* request,
+ bool started) {
+ if (request->status().status() == net::URLRequestStatus::SUCCESS) {
+ bool is_redirect = request->response_headers() &&
+ net::HttpResponseHeaders::IsRedirectResponseCode(
+ request->response_headers()->response_code());
+ if (!is_redirect) {
+ ExtensionWebRequestEventRouter::GetInstance()->OnCompleted(
+ browser_context_, extension_info_map_.get(), request);
+ }
+ return;
+ }
+
+ if (request->status().status() == net::URLRequestStatus::FAILED ||
+ request->status().status() == net::URLRequestStatus::CANCELED) {
+ ExtensionWebRequestEventRouter::GetInstance()->OnErrorOccurred(
+ browser_context_, extension_info_map_.get(), request, started);
+ return;
+ }
+
+ NOTREACHED();
+}
+
+void ShellNetworkDelegate::OnURLRequestDestroyed(
+ net::URLRequest* request) {
+ ExtensionWebRequestEventRouter::GetInstance()->OnURLRequestDestroyed(
+ browser_context_, request);
+}
+
+void ShellNetworkDelegate::OnPACScriptError(
+ int line_number,
+ const base::string16& error) {
+}
+
+net::NetworkDelegate::AuthRequiredResponse
+ShellNetworkDelegate::OnAuthRequired(
+ net::URLRequest* request,
+ const net::AuthChallengeInfo& auth_info,
+ const AuthCallback& callback,
+ net::AuthCredentials* credentials) {
+ return ExtensionWebRequestEventRouter::GetInstance()->OnAuthRequired(
+ browser_context_, extension_info_map_.get(), request, auth_info, callback,
+ credentials);
+}
+
+} // namespace extensions
diff --git a/extensions/shell/browser/shell_network_delegate.h b/extensions/shell/browser/shell_network_delegate.h
new file mode 100644
index 0000000..bd37c3e
--- /dev/null
+++ b/extensions/shell/browser/shell_network_delegate.h
@@ -0,0 +1,59 @@
+// 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 EXTENSIONS_SHELL_BROWSER_SHELL_NETNETWORK_DELEGATE_H_
+#define EXTENSIONS_SHELL_BROWSER_SHELL_NETNETWORK_DELEGATE_H_
+
+#include "extensions/browser/info_map.h"
+#include "net/base/network_delegate.h"
+
+namespace extensions {
+
+class InfoMap;
+
+class ShellNetworkDelegate : public net::NetworkDelegate {
+ public:
+ ShellNetworkDelegate(void* browser_context, InfoMap* extension_info_map);
+ virtual ~ShellNetworkDelegate();
+
+ static void SetAcceptAllCookies(bool accept);
+
+ private:
+ // NetworkDelegate implementation.
+ virtual int OnBeforeURLRequest(net::URLRequest* request,
+ const net::CompletionCallback& callback,
+ GURL* new_url) OVERRIDE;
+ virtual int OnBeforeSendHeaders(net::URLRequest* request,
+ const net::CompletionCallback& callback,
+ net::HttpRequestHeaders* headers) OVERRIDE;
+ virtual void OnSendHeaders(net::URLRequest* request,
+ const net::HttpRequestHeaders& headers) OVERRIDE;
+ virtual int OnHeadersReceived(
+ net::URLRequest* request,
+ const net::CompletionCallback& callback,
+ const net::HttpResponseHeaders* original_response_headers,
+ scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
+ GURL* allowed_unsafe_redirect_url) OVERRIDE;
+ virtual void OnBeforeRedirect(net::URLRequest* request,
+ const GURL& new_location) OVERRIDE;
+ virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE;
+ virtual void OnCompleted(net::URLRequest* request, bool started) OVERRIDE;
+ virtual void OnURLRequestDestroyed(net::URLRequest* request) OVERRIDE;
+ virtual void OnPACScriptError(int line_number,
+ const base::string16& error) OVERRIDE;
+ virtual net::NetworkDelegate::AuthRequiredResponse OnAuthRequired(
+ net::URLRequest* request,
+ const net::AuthChallengeInfo& auth_info,
+ const AuthCallback& callback,
+ net::AuthCredentials* credentials) OVERRIDE;
+
+ void* browser_context_;
+ scoped_refptr<extensions::InfoMap> extension_info_map_;
+
+ DISALLOW_COPY_AND_ASSIGN(ShellNetworkDelegate);
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_SHELL_BROWSER_SHELL_NETNETWORK_DELEGATE_H_
diff --git a/extensions/shell/browser/shell_url_request_context_getter.cc b/extensions/shell/browser/shell_url_request_context_getter.cc
new file mode 100644
index 0000000..e151e02
--- /dev/null
+++ b/extensions/shell/browser/shell_url_request_context_getter.cc
@@ -0,0 +1,42 @@
+// 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 "extensions/shell/browser/shell_url_request_context_getter.h"
+
+#include "content/public/browser/resource_request_info.h"
+#include "extensions/browser/info_map.h"
+#include "extensions/shell/browser/shell_network_delegate.h"
+
+namespace extensions {
+
+ShellURLRequestContextGetter::ShellURLRequestContextGetter(
+ content::BrowserContext* browser_context,
+ bool ignore_certificate_errors,
+ const base::FilePath& base_path,
+ base::MessageLoop* io_loop,
+ base::MessageLoop* file_loop,
+ content::ProtocolHandlerMap* protocol_handlers,
+ content::URLRequestInterceptorScopedVector request_interceptors,
+ net::NetLog* net_log,
+ InfoMap* extension_info_map)
+ : content::ShellURLRequestContextGetter(ignore_certificate_errors,
+ base_path,
+ io_loop,
+ file_loop,
+ protocol_handlers,
+ request_interceptors.Pass(),
+ net_log),
+ browser_context_(browser_context),
+ extension_info_map_(extension_info_map) {
+}
+
+ShellURLRequestContextGetter::~ShellURLRequestContextGetter() {
+}
+
+net::NetworkDelegate*
+ShellURLRequestContextGetter::CreateNetworkDelegate() {
+ return new ShellNetworkDelegate(browser_context_, extension_info_map_);
+}
+
+} // namespace extensions
diff --git a/extensions/shell/browser/shell_url_request_context_getter.h b/extensions/shell/browser/shell_url_request_context_getter.h
new file mode 100644
index 0000000..7926ade
--- /dev/null
+++ b/extensions/shell/browser/shell_url_request_context_getter.h
@@ -0,0 +1,58 @@
+// 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 EXTENSIONS_SHELL_BROWSER_SHELL_URL_REQUEST_CONTEXT_GETTER_H_
+#define EXTENSIONS_SHELL_BROWSER_SHELL_URL_REQUEST_CONTEXT_GETTER_H_
+
+#include "base/files/file_path.h"
+#include "content/shell/browser/shell_url_request_context_getter.h"
+
+namespace base {
+class MessageLoop;
+}
+
+namespace content {
+class BrowserContext;
+}
+
+namespace net {
+class NetworkDelegate;
+class NetLog;
+}
+
+namespace extensions {
+
+class InfoMap;
+
+class ShellURLRequestContextGetter :
+ public content::ShellURLRequestContextGetter {
+ public:
+ ShellURLRequestContextGetter(
+ content::BrowserContext* browser_context,
+ bool ignore_certificate_errors,
+ const base::FilePath& base_path,
+ base::MessageLoop* io_loop,
+ base::MessageLoop* file_loop,
+ content::ProtocolHandlerMap* protocol_handlers,
+ content::URLRequestInterceptorScopedVector request_interceptors,
+ net::NetLog* net_log,
+ InfoMap* extension_info_map);
+
+ // content::ShellURLRequestContextGetter implementation.
+ virtual net::NetworkDelegate* CreateNetworkDelegate() override;
+
+protected:
+ virtual ~ShellURLRequestContextGetter();
+
+private:
+ content::BrowserContext* browser_context_;
+ InfoMap* extension_info_map_;
+
+private:
+ DISALLOW_COPY_AND_ASSIGN(ShellURLRequestContextGetter);
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_SHELL_BROWSER_SHELL_URL_REQUEST_CONTEXT_GETTER_H_