2 Copyright (C) 2014 Samsung Electronics
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "browser_context_efl.h"
22 #include "base/bind.h"
23 #include "base/file_util.h"
24 #include "base/path_service.h"
25 #include "components/visitedlink/browser/visitedlink_master.h"
26 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/render_view_host.h"
28 #include "content/public/browser/web_contents.h"
29 #include "eweb_context.h"
33 BrowserContextEfl::ResourceContextEfl::ResourceContextEfl(BrowserContextEfl *ctx)
35 browser_context_(ctx) {
38 BrowserContextEfl::~BrowserContextEfl() {
39 if (resource_context_) {
40 DCHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, resource_context_));
41 resource_context_ = NULL;
45 BrowserContextEfl::ResourceContextEfl::~ResourceContextEfl() {
48 net::HostResolver* BrowserContextEfl::ResourceContextEfl::GetHostResolver() {
50 return getter_->host_resolver();
53 net::URLRequestContext* BrowserContextEfl::ResourceContextEfl::GetRequestContext() {
55 return getter_->GetURLRequestContext();
58 bool BrowserContextEfl::ResourceContextEfl::AllowMicAccess(const GURL& origin) {
62 bool BrowserContextEfl::ResourceContextEfl::AllowCameraAccess(const GURL& origin) {
66 void BrowserContextEfl::ResourceContextEfl::set_url_request_context_getter(
67 URLRequestContextGetterEfl* getter) {
71 BrowserContextEfl::BrowserContextEfl(EWebContext* web_context)
72 : resource_context_(NULL),
73 web_context_(web_context),
74 #if defined(ENABLE_NOTIFICATIONS)
75 notification_controllerefl_(new NotificationControllerEfl()),
77 temp_dir_creation_attempted_(false) {
78 InitVisitedLinkMaster();
81 net::URLRequestContextGetter* BrowserContextEfl::GetRequestContext() {
82 return GetStoragePartition(this, NULL)->GetURLRequestContext();
85 ResourceContext* BrowserContextEfl::GetResourceContext() {
86 if (!resource_context_)
87 resource_context_ = new ResourceContextEfl(this);
89 return resource_context_;
92 base::FilePath BrowserContextEfl::GetPath() const {
93 // TODO: Figure out something better for data storage.
95 static base::FilePath path;
96 static bool pathInitialized = false;
99 PathService::Get(base::DIR_TEMP, &path);
104 content::NotificationControllerEfl*
105 BrowserContextEfl::GetNotificationController() const {
106 #if defined(ENABLE_NOTIFICATIONS)
107 return notification_controllerefl_.get();
113 net::URLRequestContextGetter* BrowserContextEfl::CreateRequestContext(
114 content::ProtocolHandlerMap* protocol_handlers,
115 URLRequestInterceptorScopedVector request_interceptors) {
116 // TODO: Implement support for chromium network log
117 request_context_getter_ = new URLRequestContextGetterEfl(
121 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
122 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE),
124 request_interceptors.Pass(),
127 resource_context_->set_url_request_context_getter(request_context_getter_.get());
128 return request_context_getter_.get();
131 void BrowserContextEfl::SetCertificate(const char* certificate_file) {
132 base::FilePath* certificate_path = new base::FilePath(certificate_file);
133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
134 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
135 base::Bind(&BrowserContextEfl::ReadCertificateAndAdd, base::Owned(certificate_path)));
138 void BrowserContextEfl::ReadCertificateAndAdd(base::FilePath* file_path) {
139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
140 std::string cert_contents;
141 base::ReadFileToString(*file_path, &cert_contents);
142 scoped_refptr<net::X509Certificate> cert(net::X509Certificate::CreateFromBytes(
143 cert_contents.c_str(), cert_contents.size()));
145 DLOG(ERROR) << "User certificate could not be parsed.";
148 int err_code = net::CertDatabase::GetInstance()->CheckUserCert(cert.get());
149 if (net::OK != err_code) {
150 DLOG(ERROR) << "User certificate is not valid. Error code : " << err_code;
153 err_code = net::CertDatabase::GetInstance()->AddUserCert(cert.get());
154 if (net::OK != err_code) {
155 DLOG(ERROR) << "User certificate could not be added. Error code : " << err_code;
160 void BrowserContextEfl::InitVisitedLinkMaster() {
161 visitedlink_master_.reset(new visitedlink::VisitedLinkMaster(this, this, false));
162 visitedlink_master_->Init();
165 void BrowserContextEfl::AddVisitedURLs(const std::vector<GURL>& urls) {
166 DCHECK(visitedlink_master_);
167 visitedlink_master_->AddURLs(urls);
170 void BrowserContextEfl::RebuildTable(const scoped_refptr<URLEnumerator>& enumerator) {
171 // WebView rebuilds from WebChromeClient.getVisitedHistory. The client
172 // can change in the lifetime of this WebView and may not yet be set here.
173 // Therefore this initialization path is not used.
174 enumerator->OnComplete(true);