forked from nwjs/nw.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell_browser_context.cc
More file actions
176 lines (152 loc) · 5.54 KB
/
shell_browser_context.cc
File metadata and controls
176 lines (152 loc) · 5.54 KB
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
// Copyright (c) 2012 Intel Corp
// Copyright (c) 2012 The Chromium Authors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell co
// pies of the Software, and to permit persons to whom the Software is furnished
// to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in al
// l copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM
// PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
// S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
// ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "content/nw/src/shell_browser_context.h"
#include "base/command_line.h"
#include "base/environment.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/values.h"
#include "content/public/browser/browser_thread.h"
#include "content/nw/src/browser/shell_download_manager_delegate.h"
#include "content/nw/src/common/shell_switches.h"
#include "content/nw/src/browser/shell_resource_context.h"
#include "content/nw/src/net/shell_url_request_context_getter.h"
#include "content/nw/src/nw_package.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
namespace content {
ShellBrowserContext::ShellBrowserContext(bool off_the_record,
nw::Package* package)
: off_the_record_(off_the_record),
package_(package) {
InitWhileIOAllowed();
}
ShellBrowserContext::~ShellBrowserContext() {
if (resource_context_.get()) {
BrowserThread::DeleteSoon(
BrowserThread::IO, FROM_HERE, resource_context_.release());
}
}
void ShellBrowserContext::InitWhileIOAllowed() {
CommandLine* cmd_line = CommandLine::ForCurrentProcess();
if (cmd_line->HasSwitch(switches::kContentShellDataPath)) {
path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath);
return;
}
FilePath::StringType name(
#if defined(OS_WIN)
L"node-webkit"
#else
"node-webkit"
#endif
);
package_->root()->GetString(switches::kmName, &name);
#if defined(OS_WIN)
CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_));
path_ = path_.Append(name);
#elif defined(OS_LINUX)
scoped_ptr<base::Environment> env(base::Environment::Create());
FilePath config_dir(
base::nix::GetXDGDirectory(env.get(),
base::nix::kXdgConfigHomeEnvVar,
base::nix::kDotConfigDir));
path_ = config_dir.Append(name);
#elif defined(OS_MACOSX)
CHECK(PathService::Get(base::DIR_APP_DATA, &path_));
path_ = path_.Append(name);
#else
NOTIMPLEMENTED();
#endif
if (!file_util::PathExists(path_))
file_util::CreateDirectory(path_);
}
FilePath ShellBrowserContext::GetPath() {
return path_;
}
bool ShellBrowserContext::IsOffTheRecord() const {
return off_the_record_;
}
DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() {
DownloadManager* manager = BrowserContext::GetDownloadManager(this);
if (!download_manager_delegate_.get()) {
download_manager_delegate_ = new ShellDownloadManagerDelegate();
download_manager_delegate_->SetDownloadManager(manager);
}
return download_manager_delegate_.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::GetMediaRequestContext() {
return GetRequestContext();
}
net::URLRequestContextGetter*
ShellBrowserContext::GetMediaRequestContextForRenderProcess(
int renderer_child_id) {
return GetRequestContext();
}
net::URLRequestContextGetter*
ShellBrowserContext::GetMediaRequestContextForStoragePartition(
const FilePath& partition_path,
bool in_memory) {
return GetRequestContext();
}
net::URLRequestContextGetter*
ShellBrowserContext::GetRequestContextForStoragePartition(
const FilePath& partition_path,
bool in_memory) {
return NULL;
}
ResourceContext* ShellBrowserContext::GetResourceContext() {
if (!resource_context_.get()) {
resource_context_.reset(new ShellResourceContext(
static_cast<ShellURLRequestContextGetter*>(GetRequestContext())));
}
return resource_context_.get();
}
GeolocationPermissionContext*
ShellBrowserContext::GetGeolocationPermissionContext() {
return NULL;
}
SpeechRecognitionPreferences*
ShellBrowserContext::GetSpeechRecognitionPreferences() {
return NULL;
}
quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() {
return NULL;
}
} // namespace content