summaryrefslogtreecommitdiffstats
path: root/mojo
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-29 02:40:30 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-29 02:40:30 +0000
commitc6c6e5651515399af25e8cd70ad17b729c14e09a (patch)
tree1368e8883d88caaa4adbda98a782af5c3af1e1df /mojo
parent43346e39ef7145d80ab53085294fd02fa0c78f6e (diff)
downloadchromium_src-c6c6e5651515399af25e8cd70ad17b729c14e09a.zip
chromium_src-c6c6e5651515399af25e8cd70ad17b729c14e09a.tar.gz
chromium_src-c6c6e5651515399af25e8cd70ad17b729c14e09a.tar.bz2
Mostly useful for testing.
Added default implementations for methods in net::NetworkDelegate to make it easier to implement, and more likely for implementations to be correct. BUG=310297 Review URL: https://codereview.chromium.org/38303002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231489 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo')
-rw-r--r--mojo/mojo.gyp2
-rw-r--r--mojo/shell/context.cc2
-rw-r--r--mojo/shell/loader.cc8
-rw-r--r--mojo/shell/loader.h5
-rw-r--r--mojo/shell/network_delegate.cc27
-rw-r--r--mojo/shell/network_delegate.h24
-rw-r--r--mojo/shell/url_request_context_getter.cc12
-rw-r--r--mojo/shell/url_request_context_getter.h7
8 files changed, 83 insertions, 4 deletions
diff --git a/mojo/mojo.gyp b/mojo/mojo.gyp
index 6402519..7546219 100644
--- a/mojo/mojo.gyp
+++ b/mojo/mojo.gyp
@@ -147,6 +147,8 @@
'shell/context.h',
'shell/loader.cc',
'shell/loader.h',
+ 'shell/network_delegate.cc',
+ 'shell/network_delegate.h',
'shell/run.cc',
'shell/run.h',
'shell/storage.cc',
diff --git a/mojo/shell/context.cc b/mojo/shell/context.cc
index 7f7ad79..c2e2f90 100644
--- a/mojo/shell/context.cc
+++ b/mojo/shell/context.cc
@@ -4,6 +4,7 @@
#include "mojo/shell/context.h"
+#include "mojo/shell/network_delegate.h"
#include "mojo/system/core_impl.h"
namespace mojo {
@@ -14,6 +15,7 @@ Context::Context()
storage_(),
loader_(task_runners_.io_runner(),
task_runners_.file_runner(),
+ scoped_ptr<net::NetworkDelegate>(new NetworkDelegate()),
storage_.profile_path()) {
system::CoreImpl::Init();
}
diff --git a/mojo/shell/loader.cc b/mojo/shell/loader.cc
index 9cf7651..7b73c7d 100644
--- a/mojo/shell/loader.cc
+++ b/mojo/shell/loader.cc
@@ -5,6 +5,7 @@
#include "mojo/shell/loader.h"
#include "base/message_loop/message_loop.h"
+#include "net/base/network_delegate.h"
namespace mojo {
namespace shell {
@@ -40,11 +41,16 @@ void Loader::Job::OnURLFetchComplete(const net::URLFetcher* source) {
Loader::Loader(base::SingleThreadTaskRunner* network_runner,
base::SingleThreadTaskRunner* file_runner,
+ scoped_ptr<net::NetworkDelegate> network_delegate,
base::FilePath base_path)
: file_runner_(file_runner),
cache_thread_(CreateIOThread("cache_thread")),
url_request_context_getter_(new URLRequestContextGetter(
- base_path, network_runner, cache_thread_->message_loop_proxy())) {
+ base_path,
+ network_runner,
+ file_runner,
+ cache_thread_->message_loop_proxy(),
+ network_delegate.Pass())) {
}
Loader::~Loader() {
diff --git a/mojo/shell/loader.h b/mojo/shell/loader.h
index 52c5ea3..ea77079 100644
--- a/mojo/shell/loader.h
+++ b/mojo/shell/loader.h
@@ -14,6 +14,10 @@
#include "net/url_request/url_fetcher_delegate.h"
#include "url/gurl.h"
+namespace net {
+class NetworkDelegate;
+}
+
namespace mojo {
namespace shell {
@@ -48,6 +52,7 @@ class Loader {
Loader(base::SingleThreadTaskRunner* network_runner,
base::SingleThreadTaskRunner* file_runner,
+ scoped_ptr<net::NetworkDelegate> network_delegate,
base::FilePath base_path);
~Loader();
diff --git a/mojo/shell/network_delegate.cc b/mojo/shell/network_delegate.cc
new file mode 100644
index 0000000..e27d1ad
--- /dev/null
+++ b/mojo/shell/network_delegate.cc
@@ -0,0 +1,27 @@
+// 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 "mojo/shell/network_delegate.h"
+
+#include "base/command_line.h"
+#include "mojo/shell/switches.h"
+#include "net/url_request/url_request.h"
+
+namespace mojo {
+namespace shell {
+
+NetworkDelegate::NetworkDelegate() {
+ DetachFromThread();
+}
+
+bool NetworkDelegate::OnCanAccessFile(const net::URLRequest& request,
+ const base::FilePath& path) const {
+ // TODO(aa): We might want to add a --allow-file-urls or something, but
+ // starting conservative.
+ return CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kApp)
+ == request.url().spec();
+}
+
+} // namespace shell
+} // namespace mojo
diff --git a/mojo/shell/network_delegate.h b/mojo/shell/network_delegate.h
new file mode 100644
index 0000000..2110343
--- /dev/null
+++ b/mojo/shell/network_delegate.h
@@ -0,0 +1,24 @@
+// 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 MOJO_SHELL_NETWORK_DELEGATE_H_
+#define MOJO_SHELL_NETWORK_DELEGATE_H_
+
+#include "base/compiler_specific.h"
+#include "net/base/network_delegate.h"
+
+namespace mojo {
+namespace shell {
+
+class NetworkDelegate : public net::NetworkDelegate {
+ public:
+ NetworkDelegate();
+ virtual bool OnCanAccessFile(const net::URLRequest& request,
+ const base::FilePath& path) const OVERRIDE;
+};
+
+} // namespace shell
+} // namespace mojo
+
+#endif // MOJO_SHELL_MOJO_NETWORK_DELEGATE_H_
diff --git a/mojo/shell/url_request_context_getter.cc b/mojo/shell/url_request_context_getter.cc
index aafe1a2..1d01c5e 100644
--- a/mojo/shell/url_request_context_getter.cc
+++ b/mojo/shell/url_request_context_getter.cc
@@ -10,6 +10,7 @@
#include "net/http/http_server_properties_impl.h"
#include "net/proxy/proxy_service.h"
#include "net/ssl/ssl_config_service_defaults.h"
+#include "net/url_request/file_protocol_handler.h"
#include "net/url_request/static_http_user_agent_settings.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_job_factory_impl.h"
@@ -20,10 +21,14 @@ namespace shell {
URLRequestContextGetter::URLRequestContextGetter(
base::FilePath base_path,
base::SingleThreadTaskRunner* network_task_runner,
- base::MessageLoopProxy* cache_task_runner)
+ base::SingleThreadTaskRunner* file_task_runner,
+ base::MessageLoopProxy* cache_task_runner,
+ scoped_ptr<net::NetworkDelegate> network_delegate)
: base_path_(base_path),
+ file_task_runner_(file_task_runner),
network_task_runner_(network_task_runner),
cache_task_runner_(cache_task_runner),
+ network_delegate_(network_delegate.Pass()),
net_log_(new net::NetLog()) {
}
@@ -34,6 +39,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
if (!url_request_context_) {
url_request_context_.reset(new net::URLRequestContext());
url_request_context_->set_net_log(net_log_.get());
+ url_request_context_->set_network_delegate(network_delegate_.get());
storage_.reset(
new net::URLRequestContextStorage(url_request_context_.get()));
@@ -78,7 +84,9 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
new net::URLRequestJobFactoryImpl());
-
+ job_factory->SetProtocolHandler(
+ "file",
+ new net::FileProtocolHandler(file_task_runner_));
storage_->set_job_factory(job_factory.release());
}
diff --git a/mojo/shell/url_request_context_getter.h b/mojo/shell/url_request_context_getter.h
index 67830e7..cc9125d 100644
--- a/mojo/shell/url_request_context_getter.h
+++ b/mojo/shell/url_request_context_getter.h
@@ -8,6 +8,7 @@
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop_proxy.h"
+#include "net/base/network_delegate.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_context_storage.h"
@@ -19,7 +20,9 @@ class URLRequestContextGetter : public net::URLRequestContextGetter {
URLRequestContextGetter(
base::FilePath base_path,
base::SingleThreadTaskRunner* network_task_runner,
- base::MessageLoopProxy* cache_task_runner);
+ base::SingleThreadTaskRunner* file_task_runner,
+ base::MessageLoopProxy* cache_task_runner,
+ scoped_ptr<net::NetworkDelegate> network_delegate);
virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE;
virtual scoped_refptr<base::SingleThreadTaskRunner>
@@ -30,8 +33,10 @@ class URLRequestContextGetter : public net::URLRequestContextGetter {
private:
base::FilePath base_path_;
+ scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
scoped_refptr<base::MessageLoopProxy> cache_task_runner_;
+ scoped_ptr<net::NetworkDelegate> network_delegate_;
scoped_ptr<net::NetLog> net_log_;
scoped_ptr<net::URLRequestContextStorage> storage_;
scoped_ptr<net::URLRequestContext> url_request_context_;