1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
// Copyright (c) 2012 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 "content/shell/shell_browser_context.h"
#include "base/bind.h"
#include "base/environment.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/threading/thread.h"
#include "content/browser/download/download_manager_impl.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/geolocation_permission_context.h"
#include "content/public/browser/speech_recognition_preferences.h"
#include "content/shell/shell_browser_main_parts.h"
#include "content/shell/shell_download_manager_delegate.h"
#include "content/shell/shell_resource_context.h"
#include "content/shell/shell_url_request_context_getter.h"
#if defined(OS_WIN)
#include "base/base_paths_win.h"
#elif defined(OS_LINUX)
#include "base/nix/xdg_util.h"
#elif defined(OS_MACOSX)
#include "base/base_paths_mac.h"
#endif
using content::BrowserThread;
namespace content {
namespace {
#if defined(OS_LINUX)
const char kDotConfigDir[] = ".config";
const char kXdgConfigHomeEnvVar[] = "XDG_CONFIG_HOME";
#endif
class ShellGeolocationPermissionContext : public GeolocationPermissionContext {
public:
ShellGeolocationPermissionContext() {
}
// GeolocationPermissionContext implementation).
virtual void RequestGeolocationPermission(
int render_process_id,
int render_view_id,
int bridge_id,
const GURL& requesting_frame,
base::Callback<void(bool)> callback) OVERRIDE {
NOTIMPLEMENTED();
}
virtual void CancelGeolocationPermissionRequest(
int render_process_id,
int render_view_id,
int bridge_id,
const GURL& requesting_frame) OVERRIDE {
NOTIMPLEMENTED();
}
private:
DISALLOW_COPY_AND_ASSIGN(ShellGeolocationPermissionContext);
};
class ShellSpeechRecognitionPreferences : public SpeechRecognitionPreferences {
public:
ShellSpeechRecognitionPreferences() {
}
// Overridden from SpeechRecognitionPreferences:
virtual bool FilterProfanities() const OVERRIDE {
return false;
}
virtual void SetFilterProfanities(bool filter_profanities) OVERRIDE {
}
private:
DISALLOW_COPY_AND_ASSIGN(ShellSpeechRecognitionPreferences);
};
} // namespace
ShellBrowserContext::ShellBrowserContext(
ShellBrowserMainParts* shell_main_parts)
: shell_main_parts_(shell_main_parts) {
}
ShellBrowserContext::~ShellBrowserContext() {
if (resource_context_.get()) {
BrowserThread::DeleteSoon(
BrowserThread::IO, FROM_HERE, resource_context_.release());
}
}
FilePath ShellBrowserContext::GetPath() {
if (!path_.empty())
return path_;
#if defined(OS_WIN)
CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_));
path_ = path_.Append(std::wstring(L"content_shell"));
#elif defined(OS_LINUX)
scoped_ptr<base::Environment> env(base::Environment::Create());
FilePath config_dir(base::nix::GetXDGDirectory(env.get(),
kXdgConfigHomeEnvVar,
kDotConfigDir));
path_ = config_dir.Append("content_shell");
#elif defined(OS_MACOSX)
CHECK(PathService::Get(base::DIR_APP_DATA, &path_));
path_ = path_.Append("Chromium Content Shell");
#else
NOTIMPLEMENTED();
#endif
if (!file_util::PathExists(path_))
file_util::CreateDirectory(path_);
return path_;
}
bool ShellBrowserContext::IsOffTheRecord() const {
return false;
}
DownloadManager* ShellBrowserContext::GetDownloadManager() {
if (!download_manager_.get()) {
download_manager_delegate_ = new ShellDownloadManagerDelegate();
download_manager_ = new DownloadManagerImpl(download_manager_delegate_,
NULL);
download_manager_delegate_->SetDownloadManager(download_manager_.get());
download_manager_->Init(this);
}
return download_manager_.get();
}
net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() {
if (!url_request_getter_) {
url_request_getter_ = new ShellURLRequestContextGetter(
GetPath(),
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE));
}
return url_request_getter_;
}
net::URLRequestContextGetter*
ShellBrowserContext::GetRequestContextForRenderProcess(
int renderer_child_id) {
return GetRequestContext();
}
net::URLRequestContextGetter*
ShellBrowserContext::GetRequestContextForMedia() {
return GetRequestContext();
}
ResourceContext* ShellBrowserContext::GetResourceContext() {
if (!resource_context_.get()) {
resource_context_.reset(new ShellResourceContext(
static_cast<ShellURLRequestContextGetter*>(GetRequestContext())));
}
return resource_context_.get();
}
GeolocationPermissionContext*
ShellBrowserContext::GetGeolocationPermissionContext() {
if (!geolocation_permission_context_) {
geolocation_permission_context_ =
new ShellGeolocationPermissionContext();
}
return geolocation_permission_context_;
}
SpeechRecognitionPreferences*
ShellBrowserContext::GetSpeechRecognitionPreferences() {
if (!speech_recognition_preferences_.get())
speech_recognition_preferences_ = new ShellSpeechRecognitionPreferences();
return speech_recognition_preferences_.get();
}
bool ShellBrowserContext::DidLastSessionExitCleanly() {
return true;
}
quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() {
return NULL;
}
} // namespace content
|