Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / shell / browser / shell_browser_context.cc
blobb37521e53eee89bfb0455d6af1543751a73728c5
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/shell/browser/shell_browser_context.h"
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/environment.h"
10 #include "base/file_util.h"
11 #include "base/logging.h"
12 #include "base/path_service.h"
13 #include "base/threading/thread.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/resource_context.h"
16 #include "content/public/browser/storage_partition.h"
17 #include "content/public/common/content_switches.h"
18 #include "content/shell/browser/shell_download_manager_delegate.h"
19 #include "content/shell/browser/shell_url_request_context_getter.h"
20 #include "content/shell/common/shell_switches.h"
22 #if defined(OS_WIN)
23 #include "base/base_paths_win.h"
24 #elif defined(OS_LINUX)
25 #include "base/nix/xdg_util.h"
26 #elif defined(OS_MACOSX)
27 #include "base/base_paths_mac.h"
28 #endif
30 namespace content {
32 class ShellBrowserContext::ShellResourceContext : public ResourceContext {
33 public:
34 ShellResourceContext() : getter_(NULL) {}
35 virtual ~ShellResourceContext() {}
37 // ResourceContext implementation:
38 virtual net::HostResolver* GetHostResolver() OVERRIDE {
39 CHECK(getter_);
40 return getter_->host_resolver();
42 virtual net::URLRequestContext* GetRequestContext() OVERRIDE {
43 CHECK(getter_);
44 return getter_->GetURLRequestContext();
46 virtual bool AllowMicAccess(const GURL& origin) OVERRIDE {
47 return false;
49 virtual bool AllowCameraAccess(const GURL& origin) OVERRIDE {
50 return false;
53 void set_url_request_context_getter(ShellURLRequestContextGetter* getter) {
54 getter_ = getter;
57 private:
58 ShellURLRequestContextGetter* getter_;
60 DISALLOW_COPY_AND_ASSIGN(ShellResourceContext);
63 ShellBrowserContext::ShellBrowserContext(bool off_the_record,
64 net::NetLog* net_log)
65 : off_the_record_(off_the_record),
66 net_log_(net_log),
67 ignore_certificate_errors_(false),
68 resource_context_(new ShellResourceContext) {
69 InitWhileIOAllowed();
72 ShellBrowserContext::~ShellBrowserContext() {
73 if (resource_context_) {
74 BrowserThread::DeleteSoon(
75 BrowserThread::IO, FROM_HERE, resource_context_.release());
79 void ShellBrowserContext::InitWhileIOAllowed() {
80 CommandLine* cmd_line = CommandLine::ForCurrentProcess();
81 if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors) ||
82 cmd_line->HasSwitch(switches::kDumpRenderTree)) {
83 ignore_certificate_errors_ = true;
85 if (cmd_line->HasSwitch(switches::kContentShellDataPath)) {
86 path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath);
87 return;
89 #if defined(OS_WIN)
90 CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_));
91 path_ = path_.Append(std::wstring(L"content_shell"));
92 #elif defined(OS_LINUX)
93 scoped_ptr<base::Environment> env(base::Environment::Create());
94 base::FilePath config_dir(
95 base::nix::GetXDGDirectory(env.get(),
96 base::nix::kXdgConfigHomeEnvVar,
97 base::nix::kDotConfigDir));
98 path_ = config_dir.Append("content_shell");
99 #elif defined(OS_MACOSX)
100 CHECK(PathService::Get(base::DIR_APP_DATA, &path_));
101 path_ = path_.Append("Chromium Content Shell");
102 #elif defined(OS_ANDROID)
103 CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &path_));
104 path_ = path_.Append(FILE_PATH_LITERAL("content_shell"));
105 #else
106 NOTIMPLEMENTED();
107 #endif
109 if (!base::PathExists(path_))
110 base::CreateDirectory(path_);
113 base::FilePath ShellBrowserContext::GetPath() const {
114 return path_;
117 bool ShellBrowserContext::IsOffTheRecord() const {
118 return off_the_record_;
121 DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() {
122 DownloadManager* manager = BrowserContext::GetDownloadManager(this);
124 if (!download_manager_delegate_.get()) {
125 download_manager_delegate_.reset(new ShellDownloadManagerDelegate());
126 download_manager_delegate_->SetDownloadManager(manager);
127 CommandLine* cmd_line = CommandLine::ForCurrentProcess();
128 if (cmd_line->HasSwitch(switches::kDumpRenderTree)) {
129 download_manager_delegate_->SetDownloadBehaviorForTesting(
130 path_.Append(FILE_PATH_LITERAL("downloads")));
134 return download_manager_delegate_.get();
137 net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() {
138 return GetDefaultStoragePartition(this)->GetURLRequestContext();
141 net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext(
142 ProtocolHandlerMap* protocol_handlers,
143 ProtocolHandlerScopedVector protocol_interceptors) {
144 DCHECK(!url_request_getter_.get());
145 url_request_getter_ = new ShellURLRequestContextGetter(
146 ignore_certificate_errors_,
147 GetPath(),
148 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
149 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE),
150 protocol_handlers,
151 protocol_interceptors.Pass(),
152 net_log_);
153 resource_context_->set_url_request_context_getter(url_request_getter_.get());
154 return url_request_getter_.get();
157 net::URLRequestContextGetter*
158 ShellBrowserContext::GetRequestContextForRenderProcess(
159 int renderer_child_id) {
160 return GetRequestContext();
163 net::URLRequestContextGetter*
164 ShellBrowserContext::GetMediaRequestContext() {
165 return GetRequestContext();
168 net::URLRequestContextGetter*
169 ShellBrowserContext::GetMediaRequestContextForRenderProcess(
170 int renderer_child_id) {
171 return GetRequestContext();
174 net::URLRequestContextGetter*
175 ShellBrowserContext::GetMediaRequestContextForStoragePartition(
176 const base::FilePath& partition_path,
177 bool in_memory) {
178 return GetRequestContext();
181 void ShellBrowserContext::RequestMidiSysExPermission(
182 int render_process_id,
183 int render_view_id,
184 int bridge_id,
185 const GURL& requesting_frame,
186 bool user_gesture,
187 const MidiSysExPermissionCallback& callback) {
188 // Always reject requests for LayoutTests for now.
189 // TODO(toyoshim): Make it programmable to improve test coverage.
190 if (!CommandLine::ForCurrentProcess()->HasSwitch(
191 switches::kDumpRenderTree)) {
192 callback.Run(false);
193 return;
195 callback.Run(true);
198 void ShellBrowserContext::CancelMidiSysExPermissionRequest(
199 int render_process_id,
200 int render_view_id,
201 int bridge_id,
202 const GURL& requesting_frame) {
205 void ShellBrowserContext::RequestProtectedMediaIdentifierPermission(
206 int render_process_id,
207 int render_view_id,
208 int bridge_id,
209 int group_id,
210 const GURL& requesting_frame,
211 const ProtectedMediaIdentifierPermissionCallback& callback) {
212 callback.Run(true);
215 void ShellBrowserContext::CancelProtectedMediaIdentifierPermissionRequests(
216 int group_id) {
219 net::URLRequestContextGetter*
220 ShellBrowserContext::CreateRequestContextForStoragePartition(
221 const base::FilePath& partition_path,
222 bool in_memory,
223 ProtocolHandlerMap* protocol_handlers,
224 ProtocolHandlerScopedVector protocol_interceptors) {
225 return NULL;
228 ResourceContext* ShellBrowserContext::GetResourceContext() {
229 return resource_context_.get();
232 GeolocationPermissionContext*
233 ShellBrowserContext::GetGeolocationPermissionContext() {
234 return NULL;
237 quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() {
238 return NULL;
241 } // namespace content