blob: d1ecd3e31ac6622d22df19f81a31a9ba814fad7a [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]b0f146f2011-09-15 22:14:2519
20#if defined(OS_WIN)
21#include "base/base_paths_win.h"
[email protected]5cba3bf2012-01-14 02:40:3522#elif defined(OS_LINUX)
23#include "base/nix/xdg_util.h"
[email protected]80ec0b72012-03-22 22:45:2724#elif defined(OS_MACOSX)
25#include "base/base_paths_mac.h"
[email protected]b0f146f2011-09-15 22:14:2526#endif
27
[email protected]810ddc52012-01-24 01:00:3528namespace content {
29
[email protected]71d504f2012-07-25 17:15:2830ShellBrowserContext::ShellBrowserContext(bool off_the_record)
31 : off_the_record_(off_the_record) {
[email protected]11a65b692012-03-30 11:29:1632 InitWhileIOAllowed();
[email protected]b0f146f2011-09-15 22:14:2533}
34
35ShellBrowserContext::~ShellBrowserContext() {
[email protected]e99ca5112011-09-26 17:22:5436 if (resource_context_.get()) {
37 BrowserThread::DeleteSoon(
38 BrowserThread::IO, FROM_HERE, resource_context_.release());
39 }
[email protected]b0f146f2011-09-15 22:14:2540}
41
[email protected]11a65b692012-03-30 11:29:1642void ShellBrowserContext::InitWhileIOAllowed() {
[email protected]aae34062012-07-19 15:52:1543 CommandLine* cmd_line = CommandLine::ForCurrentProcess();
[email protected]e1cf85a22012-08-17 22:39:2344 if (cmd_line->HasSwitch(switches::kDumpRenderTree)) {
[email protected]2f2b9512012-06-08 17:31:0045 CHECK(testing_path_.CreateUniqueTempDir());
46 path_ = testing_path_.path();
47 return;
48 }
[email protected]e1cf85a22012-08-17 22:39:2349 if (cmd_line->HasSwitch(switches::kContentShellDataPath)) {
50 path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath);
51 return;
52 }
[email protected]b0f146f2011-09-15 22:14:2553#if defined(OS_WIN)
[email protected]e99ca5112011-09-26 17:22:5454 CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_));
55 path_ = path_.Append(std::wstring(L"content_shell"));
[email protected]5cba3bf2012-01-14 02:40:3556#elif defined(OS_LINUX)
57 scoped_ptr<base::Environment> env(base::Environment::Create());
[email protected]9528c9a2012-06-13 23:20:2258 FilePath config_dir(
59 base::nix::GetXDGDirectory(env.get(),
60 base::nix::kXdgConfigHomeEnvVar,
61 base::nix::kDotConfigDir));
[email protected]5cba3bf2012-01-14 02:40:3562 path_ = config_dir.Append("content_shell");
[email protected]80ec0b72012-03-22 22:45:2763#elif defined(OS_MACOSX)
64 CHECK(PathService::Get(base::DIR_APP_DATA, &path_));
65 path_ = path_.Append("Chromium Content Shell");
[email protected]70a7f1192012-06-08 01:31:3466#elif defined(OS_ANDROID)
67 DCHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &path_));
68 path_ = path_.Append(FILE_PATH_LITERAL("content_shell"));
[email protected]b0f146f2011-09-15 22:14:2569#else
70 NOTIMPLEMENTED();
71#endif
72
[email protected]e99ca5112011-09-26 17:22:5473 if (!file_util::PathExists(path_))
74 file_util::CreateDirectory(path_);
[email protected]11a65b692012-03-30 11:29:1675}
[email protected]b0f146f2011-09-15 22:14:2576
[email protected]11a65b692012-03-30 11:29:1677FilePath ShellBrowserContext::GetPath() {
[email protected]e99ca5112011-09-26 17:22:5478 return path_;
[email protected]b0f146f2011-09-15 22:14:2579}
80
[email protected]27d6e852012-03-02 21:31:3281bool ShellBrowserContext::IsOffTheRecord() const {
[email protected]71d504f2012-07-25 17:15:2882 return off_the_record_;
[email protected]b0f146f2011-09-15 22:14:2583}
84
[email protected]b441a8492012-06-06 14:55:5785DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() {
[email protected]08c92ac2012-08-21 23:41:4086 DownloadManager* manager = BrowserContext::GetDownloadManager(this);
87
[email protected]b441a8492012-06-06 14:55:5788 download_manager_delegate_ = new ShellDownloadManagerDelegate();
[email protected]08c92ac2012-08-21 23:41:4089 download_manager_delegate_->SetDownloadManager(manager);
90
[email protected]b441a8492012-06-06 14:55:5791 return download_manager_delegate_.get();
[email protected]b0f146f2011-09-15 22:14:2592}
93
[email protected]b0f146f2011-09-15 22:14:2594net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() {
95 if (!url_request_getter_) {
96 url_request_getter_ = new ShellURLRequestContextGetter(
97 GetPath(),
[email protected]ed10dd12011-12-07 12:03:4298 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
99 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE));
[email protected]b0f146f2011-09-15 22:14:25100 }
101 return url_request_getter_;
102}
103
104net::URLRequestContextGetter*
105 ShellBrowserContext::GetRequestContextForRenderProcess(
106 int renderer_child_id) {
107 return GetRequestContext();
108}
109
110net::URLRequestContextGetter*
[email protected]10705a7b2012-08-21 19:07:08111 ShellBrowserContext::GetMediaRequestContext() {
112 return GetRequestContext();
113}
114
115net::URLRequestContextGetter*
116 ShellBrowserContext::GetMediaRequestContextForRenderProcess(
117 int renderer_child_id) {
[email protected]b0f146f2011-09-15 22:14:25118 return GetRequestContext();
119}
120
[email protected]df02aca2012-02-09 21:03:20121ResourceContext* ShellBrowserContext::GetResourceContext() {
[email protected]b0f146f2011-09-15 22:14:25122 if (!resource_context_.get()) {
123 resource_context_.reset(new ShellResourceContext(
[email protected]314c3e22012-02-21 03:57:42124 static_cast<ShellURLRequestContextGetter*>(GetRequestContext())));
[email protected]b0f146f2011-09-15 22:14:25125 }
[email protected]df02aca2012-02-09 21:03:20126 return resource_context_.get();
[email protected]b0f146f2011-09-15 22:14:25127}
128
[email protected]b0f146f2011-09-15 22:14:25129GeolocationPermissionContext*
130 ShellBrowserContext::GetGeolocationPermissionContext() {
[email protected]30e3e9a62012-06-07 20:46:57131 return NULL;
[email protected]b0f146f2011-09-15 22:14:25132}
133
[email protected]c52b2892012-03-07 11:01:02134SpeechRecognitionPreferences*
135 ShellBrowserContext::GetSpeechRecognitionPreferences() {
[email protected]30e3e9a62012-06-07 20:46:57136 return NULL;
[email protected]8238dd62011-09-29 15:13:01137}
138
[email protected]b0f146f2011-09-15 22:14:25139bool ShellBrowserContext::DidLastSessionExitCleanly() {
140 return true;
141}
142
[email protected]55eb70e762012-02-20 17:38:39143quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() {
144 return NULL;
[email protected]b0f146f2011-09-15 22:14:25145}
146
147} // namespace content