// 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/public/browser/download_manager.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_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 callback) OVERRIDE { NOTIMPLEMENTED(); } virtual void CancelGeolocationPermissionRequest( int render_process_id, int render_view_id, int bridge_id, const GURL& requesting_frame) OVERRIDE { NOTIMPLEMENTED(); } protected: virtual ~ShellGeolocationPermissionContext() {}; private: DISALLOW_COPY_AND_ASSIGN(ShellGeolocationPermissionContext); }; class ShellSpeechRecognitionPreferences : public SpeechRecognitionPreferences { public: ShellSpeechRecognitionPreferences() {} // Overridden from SpeechRecognitionPreferences: virtual bool FilterProfanities() const OVERRIDE { return false; } protected: virtual ~ShellSpeechRecognitionPreferences() {} private: DISALLOW_COPY_AND_ASSIGN(ShellSpeechRecognitionPreferences); }; } // namespace ShellBrowserContext::ShellBrowserContext() { InitWhileIOAllowed(); } ShellBrowserContext::~ShellBrowserContext() { if (resource_context_.get()) { BrowserThread::DeleteSoon( BrowserThread::IO, FROM_HERE, resource_context_.release()); } } void ShellBrowserContext::InitWhileIOAllowed() { #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 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_); } FilePath ShellBrowserContext::GetPath() { return path_; } bool ShellBrowserContext::IsOffTheRecord() const { return false; } DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() { download_manager_delegate_ = new ShellDownloadManagerDelegate(); 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::GetRequestContextForMedia() { return GetRequestContext(); } ResourceContext* ShellBrowserContext::GetResourceContext() { if (!resource_context_.get()) { resource_context_.reset(new ShellResourceContext( static_cast(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