From ff14e140433a50db7f146538c0f9ef2a2eb203cd Mon Sep 17 00:00:00 2001 From: Arnaud Renevier Date: Tue, 27 May 2014 15:06:57 -0700 Subject: [PATCH] Add Tizen-platform implementation of BrowserContext Change-Id: I8c0be557f590092a064d75fb73e900d3a36846d1 --- tizen_src/impl/browser_context_efl.cc | 172 ++++++++++++++++++++++++++++++++++ tizen_src/impl/browser_context_efl.h | 141 ++++++++++++++++++++++++++++ tizen_src/impl/chromium-efl.gyp | 2 + 3 files changed, 315 insertions(+) create mode 100644 tizen_src/impl/browser_context_efl.cc create mode 100644 tizen_src/impl/browser_context_efl.h diff --git a/tizen_src/impl/browser_context_efl.cc b/tizen_src/impl/browser_context_efl.cc new file mode 100644 index 0000000..f051715 --- /dev/null +++ b/tizen_src/impl/browser_context_efl.cc @@ -0,0 +1,172 @@ +/* + Copyright (C) 2014 Samsung Electronics + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "browser_context_efl.h" + +#include "base/file_util.h" +#include "base/path_service.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/render_view_host.h" +#include "content/public/browser/web_contents.h" +#include "eweb_context.h" + +namespace content { + +BrowserContextEfl::ResourceContextEfl::ResourceContextEfl(BrowserContextEfl *ctx) + : getter_(NULL), + browser_context_(ctx) { +} + +BrowserContextEfl::ResourceContextEfl::~ResourceContextEfl() { +} + +net::HostResolver* BrowserContextEfl::ResourceContextEfl::GetHostResolver() { + CHECK(getter_); + return getter_->host_resolver(); +} + +net::URLRequestContext* BrowserContextEfl::ResourceContextEfl::GetRequestContext() { + CHECK(getter_); + return getter_->GetURLRequestContext(); +} + +bool BrowserContextEfl::ResourceContextEfl::AllowMicAccess(const GURL& origin) { + return false; +} + +bool BrowserContextEfl::ResourceContextEfl::AllowCameraAccess(const GURL& origin) { + return false; +} + +void BrowserContextEfl::ResourceContextEfl::set_url_request_context_getter( + URLRequestContextGetterEfl* getter) { + getter_ = getter; +} + +BrowserContextEfl::BrowserContextEfl(EWebContext* web_context) + : web_context_(web_context), +#if defined(ENABLE_NOTIFICATIONS) + notification_controllerefl_(new NotificationControllerEfl()), +#endif + temp_dir_creation_attempted_(false) { +} + +net::URLRequestContextGetter* BrowserContextEfl::GetRequestContext() { + return GetStoragePartition(this, NULL)->GetURLRequestContext(); +} + +void BrowserContextEfl::RequestProtectedMediaIdentifierPermission( + WebContents* web_contents, + const GURL& origin, + base::Callback result_callback, + base::Closure* cancel_callback) { + //FIXME : need proper implementation + result_callback.Run(false); +} + +void BrowserContextEfl::CancelProtectedMediaIdentifierPermissionRequests( + int group_id) { + //FIXME : need proper implementation +} + +ResourceContext* BrowserContextEfl::GetResourceContext() { + if (!resource_context_) + resource_context_.reset(new ResourceContextEfl(this)); + + return resource_context_.get(); +} + +base::FilePath BrowserContextEfl::GetPath() const { + // TODO: Figure out something better for data storage. + + static base::FilePath path; + static bool pathInitialized = false; + + if (!pathInitialized) + PathService::Get(base::DIR_TEMP, &path); + + return path; +} + +content::NotificationControllerEfl* +BrowserContextEfl::GetNotificationController() const { +#if defined(ENABLE_NOTIFICATIONS) + return notification_controllerefl_.get(); +#else + return NULL; +#endif +} + +void BrowserContextEfl::RequestMidiSysExPermission( + WebContents* web_contents, + int bridge_id, + const GURL& requesting_frame, + bool user_gesture, + base::Callback result_callback, + base::Closure* cancel_callback) { + // TODO: Follow bug http://crbug.com/257618 for implementation. + result_callback.Run(false); +} + +net::URLRequestContextGetter* BrowserContextEfl::CreateRequestContext( + content::ProtocolHandlerMap* protocol_handlers) { + // TODO: Implement support for chromium network log + request_context_getter_ = new URLRequestContextGetterEfl( + *web_context_, + false, + GetPath(), + BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), + BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE), + protocol_handlers, + NULL); + GetRequestContext(); + resource_context_->set_url_request_context_getter(request_context_getter_.get()); + return request_context_getter_.get(); +} + +void BrowserContextEfl::SetCertificate(const char* certificate_file) { + base::FilePath* certificate_path = new base::FilePath(certificate_file); + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, + base::Bind(&BrowserContextEfl::ReadCertificateAndAdd, base::Owned(certificate_path))); +} + +void BrowserContextEfl::ReadCertificateAndAdd(base::FilePath* file_path) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); + std::string cert_contents; + base::ReadFileToString(*file_path, &cert_contents); + scoped_refptr cert(net::X509Certificate::CreateFromBytes( + cert_contents.c_str(), cert_contents.size())); + if (!cert) { + DLOG(ERROR) << "User certificate could not be parsed."; + return; + } + int err_code = net::CertDatabase::GetInstance()->CheckUserCert(cert.get()); + if (net::OK != err_code) { + DLOG(ERROR) << "User certificate is not valid. Error code : " << err_code; + return; + } + err_code = net::CertDatabase::GetInstance()->AddUserCert(cert.get()); + if (net::OK != err_code) { + DLOG(ERROR) << "User certificate could not be added. Error code : " << err_code; + return; + } +} + +} diff --git a/tizen_src/impl/browser_context_efl.h b/tizen_src/impl/browser_context_efl.h new file mode 100644 index 0000000..646454d --- /dev/null +++ b/tizen_src/impl/browser_context_efl.h @@ -0,0 +1,141 @@ +/* + Copyright (C) 2014 Samsung Electronics + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef BROWSER_CONTEXT_EFL +#define BROWSER_CONTEXT_EFL + +#include "base/memory/scoped_ptr.h" +#include "base/files/scoped_temp_dir.h" +#include "content/public/browser/content_browser_client.h" +#include "content/public/browser/browser_context.h" +#include "content/public/browser/storage_partition.h" +#include "content/public/browser/resource_context.h" +#include "url_request_context_getter_efl.h" +#include "browser/notification/notification_controller_efl.h" +#include "browser/download_manager_delegate_efl.h" +#include "net/url_request/url_request_context.h" + +class EWebContext; + +namespace content { + +class BrowserContextEfl + : public BrowserContext { + public: + BrowserContextEfl(EWebContext*); + + virtual bool IsOffTheRecord() const OVERRIDE { return false; } + virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; + URLRequestContextGetterEfl* GetRequestContextEfl() + { return request_context_getter_.get(); } + virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(int) OVERRIDE + { return GetRequestContext(); } + virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE + { return GetRequestContext(); } + virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(int) OVERRIDE + { return GetRequestContext(); } + virtual net::URLRequestContextGetter* GetMediaRequestContextForStoragePartition( + const base::FilePath&, bool) OVERRIDE + { return GetRequestContext(); } + + void RequestProtectedMediaIdentifierPermission( + WebContents* web_contents, + const GURL& origin, + base::Callback result_callback, + base::Closure* cancel_callback) OVERRIDE; + + virtual void CancelProtectedMediaIdentifierPermissionRequests( + int group_id) OVERRIDE; + + virtual ResourceContext* GetResourceContext() OVERRIDE; + + virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE + { return &download_manager_delegate_; } + + virtual BrowserPluginGuestManager* GetGuestManager() OVERRIDE + { return 0; } + + virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE + { return 0; } + + virtual PushMessagingService* GetPushMessagingService() OVERRIDE + { return 0; } + + virtual base::FilePath GetPath() const OVERRIDE; + + net::URLRequestContextGetter* CreateRequestContext( + content::ProtocolHandlerMap* protocol_handlers); + void SetCertificate(const char* certificate_file); + EWebContext* WebContext() const + { return web_context_; } + + content::NotificationControllerEfl* GetNotificationController() const; + + virtual void RequestMidiSysExPermission( + WebContents* web_contents, + int bridge_id, + const GURL& requesting_frame, + bool user_gesture, + base::Callback result_callback, + base::Closure* cancel_callback) OVERRIDE; + + virtual void CancelMidiSysExPermissionRequest( + int render_process_id, + int render_view_id, + int bridge_id, + const GURL& requesting_frame) OVERRIDE {} + + class ResourceContextEfl : public ResourceContext { + public: + ResourceContextEfl(BrowserContextEfl*); + virtual ~ResourceContextEfl(); + + virtual net::HostResolver* GetHostResolver() OVERRIDE; + virtual net::URLRequestContext* GetRequestContext() OVERRIDE; + virtual bool AllowMicAccess(const GURL& origin) OVERRIDE; + virtual bool AllowCameraAccess(const GURL& origin) OVERRIDE; + void set_url_request_context_getter(URLRequestContextGetterEfl* getter); + BrowserContextEfl* getBrowserContext() { return browser_context_; }; + + private: + URLRequestContextGetterEfl* getter_; + BrowserContextEfl *browser_context_; + + DISALLOW_COPY_AND_ASSIGN(ResourceContextEfl); + }; + + private: + static void ReadCertificateAndAdd(base::FilePath* file_path); + + scoped_ptr resource_context_; + scoped_refptr request_context_getter_; + EWebContext* web_context_; +#if defined(ENABLE_NOTIFICATIONS) + scoped_ptr notification_controllerefl_; +#endif + DownloadManagerDelegateEfl download_manager_delegate_; + base::ScopedTempDir temp_dir_; + bool temp_dir_creation_attempted_; + + DISALLOW_COPY_AND_ASSIGN(BrowserContextEfl); +}; + +} + +#endif diff --git a/tizen_src/impl/chromium-efl.gyp b/tizen_src/impl/chromium-efl.gyp index bf99c92..da4469b 100644 --- a/tizen_src/impl/chromium-efl.gyp +++ b/tizen_src/impl/chromium-efl.gyp @@ -63,6 +63,8 @@ 'browser/renderer_host/native_web_keyboard_event_efl.cc', 'browser/renderer_host/web_cache_manager_efl.cc', 'browser/renderer_host/web_cache_manager_efl.h', + 'browser_context_efl.cc', + 'browser_context_efl.h', 'cache_params_efl.h', 'command_line_efl.cc', 'command_line_efl.h', -- 2.7.4