blob: 86ae1a444b455cc1ccf871265b54b705b658e2b1 [file] [log] [blame]
[email protected]5cba3bf2012-01-14 02:40:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]b0f146f2011-09-15 22:14:252// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/shell/shell_browser_context.h"
6
[email protected]037edb52011-11-15 21:14:067#include "base/bind.h"
[email protected]2f2b9512012-06-08 17:31:008#include "base/command_line.h"
[email protected]5cba3bf2012-01-14 02:40:359#include "base/environment.h"
[email protected]b0f146f2011-09-15 22:14:2510#include "base/file_util.h"
11#include "base/logging.h"
12#include "base/path_service.h"
[email protected]2e5b60a22011-11-28 15:56:4113#include "base/threading/thread.h"
[email protected]c38831a12011-10-28 12:44:4914#include "content/public/browser/browser_thread.h"
[email protected]98d6f152011-09-29 19:35:5115#include "content/shell/shell_download_manager_delegate.h"
[email protected]c5f1e332011-09-27 01:08:0316#include "content/shell/shell_resource_context.h"
[email protected]2f2b9512012-06-08 17:31:0017#include "content/shell/shell_switches.h"
[email protected]c5f1e332011-09-27 01:08:0318#include "content/shell/shell_url_request_context_getter.h"
[email protected]c280aeb42012-10-17 19:45:4219#include "content/public/common/content_switches.h"
[email protected]b0f146f2011-09-15 22:14:2520
21#if defined(OS_WIN)
22#include "base/base_paths_win.h"
[email protected]5cba3bf2012-01-14 02:40:3523#elif defined(OS_LINUX)
24#include "base/nix/xdg_util.h"
[email protected]80ec0b72012-03-22 22:45:2725#elif defined(OS_MACOSX)
26#include "base/base_paths_mac.h"
[email protected]b0f146f2011-09-15 22:14:2527#endif
28
[email protected]810ddc52012-01-24 01:00:3529namespace content {
30
[email protected]71d504f2012-07-25 17:15:2831ShellBrowserContext::ShellBrowserContext(bool off_the_record)
[email protected]c2dad292012-09-07 21:27:3532 : off_the_record_(off_the_record),
33 ignore_certificate_errors_(false) {
[email protected]11a65b692012-03-30 11:29:1634 InitWhileIOAllowed();
[email protected]b0f146f2011-09-15 22:14:2535}
36
37ShellBrowserContext::~ShellBrowserContext() {
[email protected]e99ca5112011-09-26 17:22:5438 if (resource_context_.get()) {
39 BrowserThread::DeleteSoon(
40 BrowserThread::IO, FROM_HERE, resource_context_.release());
41 }
[email protected]b0f146f2011-09-15 22:14:2542}
43
[email protected]11a65b692012-03-30 11:29:1644void ShellBrowserContext::InitWhileIOAllowed() {
[email protected]aae34062012-07-19 15:52:1545 CommandLine* cmd_line = CommandLine::ForCurrentProcess();
[email protected]d22dc092012-11-19 20:35:5646 if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors) ||
47 cmd_line->HasSwitch(switches::kDumpRenderTree)) {
[email protected]c2dad292012-09-07 21:27:3548 ignore_certificate_errors_ = true;
[email protected]d22dc092012-11-19 20:35:5649 }
[email protected]e1cf85a22012-08-17 22:39:2350 if (cmd_line->HasSwitch(switches::kContentShellDataPath)) {
51 path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath);
52 return;
53 }
[email protected]b0f146f2011-09-15 22:14:2554#if defined(OS_WIN)
[email protected]e99ca5112011-09-26 17:22:5455 CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_));
56 path_ = path_.Append(std::wstring(L"content_shell"));
[email protected]5cba3bf2012-01-14 02:40:3557#elif defined(OS_LINUX)
58 scoped_ptr<base::Environment> env(base::Environment::Create());
[email protected]9528c9a2012-06-13 23:20:2259 FilePath config_dir(
60 base::nix::GetXDGDirectory(env.get(),
61 base::nix::kXdgConfigHomeEnvVar,
62 base::nix::kDotConfigDir));
[email protected]5cba3bf2012-01-14 02:40:3563 path_ = config_dir.Append("content_shell");
[email protected]80ec0b72012-03-22 22:45:2764#elif defined(OS_MACOSX)
65 CHECK(PathService::Get(base::DIR_APP_DATA, &path_));
66 path_ = path_.Append("Chromium Content Shell");
[email protected]70a7f1192012-06-08 01:31:3467#elif defined(OS_ANDROID)
68 DCHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &path_));
69 path_ = path_.Append(FILE_PATH_LITERAL("content_shell"));
[email protected]b0f146f2011-09-15 22:14:2570#else
71 NOTIMPLEMENTED();
72#endif
73
[email protected]e99ca5112011-09-26 17:22:5474 if (!file_util::PathExists(path_))
75 file_util::CreateDirectory(path_);
[email protected]11a65b692012-03-30 11:29:1676}
[email protected]b0f146f2011-09-15 22:14:2577
[email protected]11a65b692012-03-30 11:29:1678FilePath ShellBrowserContext::GetPath() {
[email protected]e99ca5112011-09-26 17:22:5479 return path_;
[email protected]b0f146f2011-09-15 22:14:2580}
81
[email protected]27d6e852012-03-02 21:31:3282bool ShellBrowserContext::IsOffTheRecord() const {
[email protected]71d504f2012-07-25 17:15:2883 return off_the_record_;
[email protected]b0f146f2011-09-15 22:14:2584}
85
[email protected]b441a8492012-06-06 14:55:5786DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() {
[email protected]08c92ac2012-08-21 23:41:4087 DownloadManager* manager = BrowserContext::GetDownloadManager(this);
88
[email protected]59002092012-08-27 19:42:5689 if (!download_manager_delegate_.get()) {
90 download_manager_delegate_ = new ShellDownloadManagerDelegate();
91 download_manager_delegate_->SetDownloadManager(manager);
[email protected]17bc408b22013-01-10 18:40:0892 CommandLine* cmd_line = CommandLine::ForCurrentProcess();
93 if (cmd_line->HasSwitch(switches::kDumpRenderTree)) {
94 download_manager_delegate_->SetDownloadBehaviorForTesting(
95 path_.Append(FILE_PATH_LITERAL("downloads")));
96 }
[email protected]59002092012-08-27 19:42:5697 }
[email protected]08c92ac2012-08-21 23:41:4098
[email protected]b441a8492012-06-06 14:55:5799 return download_manager_delegate_.get();
[email protected]b0f146f2011-09-15 22:14:25100}
101
[email protected]b0f146f2011-09-15 22:14:25102net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() {
103 if (!url_request_getter_) {
104 url_request_getter_ = new ShellURLRequestContextGetter(
[email protected]c2dad292012-09-07 21:27:35105 ignore_certificate_errors_,
[email protected]b0f146f2011-09-15 22:14:25106 GetPath(),
[email protected]ed10dd12011-12-07 12:03:42107 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
108 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE));
[email protected]b0f146f2011-09-15 22:14:25109 }
110 return url_request_getter_;
111}
112
113net::URLRequestContextGetter*
114 ShellBrowserContext::GetRequestContextForRenderProcess(
115 int renderer_child_id) {
116 return GetRequestContext();
117}
118
119net::URLRequestContextGetter*
[email protected]10705a7b2012-08-21 19:07:08120 ShellBrowserContext::GetMediaRequestContext() {
121 return GetRequestContext();
122}
123
124net::URLRequestContextGetter*
125 ShellBrowserContext::GetMediaRequestContextForRenderProcess(
126 int renderer_child_id) {
[email protected]b0f146f2011-09-15 22:14:25127 return GetRequestContext();
128}
129
[email protected]55c0eca2012-09-15 05:12:34130net::URLRequestContextGetter*
[email protected]10eb28162012-09-18 03:04:09131 ShellBrowserContext::GetMediaRequestContextForStoragePartition(
[email protected]27ddfed22012-10-30 23:22:43132 const FilePath& partition_path,
133 bool in_memory) {
[email protected]10eb28162012-09-18 03:04:09134 return GetRequestContext();
135}
136
137net::URLRequestContextGetter*
[email protected]55c0eca2012-09-15 05:12:34138 ShellBrowserContext::GetRequestContextForStoragePartition(
[email protected]27ddfed22012-10-30 23:22:43139 const FilePath& partition_path,
140 bool in_memory) {
[email protected]55c0eca2012-09-15 05:12:34141 return NULL;
142}
143
[email protected]df02aca2012-02-09 21:03:20144ResourceContext* ShellBrowserContext::GetResourceContext() {
[email protected]b0f146f2011-09-15 22:14:25145 if (!resource_context_.get()) {
146 resource_context_.reset(new ShellResourceContext(
[email protected]314c3e22012-02-21 03:57:42147 static_cast<ShellURLRequestContextGetter*>(GetRequestContext())));
[email protected]b0f146f2011-09-15 22:14:25148 }
[email protected]df02aca2012-02-09 21:03:20149 return resource_context_.get();
[email protected]b0f146f2011-09-15 22:14:25150}
151
[email protected]b0f146f2011-09-15 22:14:25152GeolocationPermissionContext*
153 ShellBrowserContext::GetGeolocationPermissionContext() {
[email protected]30e3e9a62012-06-07 20:46:57154 return NULL;
[email protected]b0f146f2011-09-15 22:14:25155}
156
[email protected]c52b2892012-03-07 11:01:02157SpeechRecognitionPreferences*
158 ShellBrowserContext::GetSpeechRecognitionPreferences() {
[email protected]30e3e9a62012-06-07 20:46:57159 return NULL;
[email protected]8238dd62011-09-29 15:13:01160}
161
[email protected]55eb70e762012-02-20 17:38:39162quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() {
163 return NULL;
[email protected]b0f146f2011-09-15 22:14:25164}
165
166} // namespace content