1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef ANDROID_WEBVIEW_LIB_AW_CONTENT_BROWSER_CLIENT_H_ 6 #define ANDROID_WEBVIEW_LIB_AW_CONTENT_BROWSER_CLIENT_H_ 7 8 #include "android_webview/browser/aw_web_preferences_populater.h" 9 #include "base/basictypes.h" 10 #include "base/compiler_specific.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "content/public/browser/content_browser_client.h" 13 14 struct WebPreferences; 15 16 namespace android_webview { 17 18 class AwBrowserContext; 19 class JniDependencyFactory; 20 21 class AwContentBrowserClient : public content::ContentBrowserClient { 22 public: 23 // This is what AwContentBrowserClient::GetAcceptLangs uses. 24 static std::string GetAcceptLangsImpl(); 25 26 // Deprecated: use AwBrowserContext::GetDefault() instead. 27 static AwBrowserContext* GetAwBrowserContext(); 28 29 AwContentBrowserClient(JniDependencyFactory* native_factory); 30 virtual ~AwContentBrowserClient(); 31 32 // Overriden methods from ContentBrowserClient. 33 virtual void AddCertificate(net::CertificateMimeType cert_type, 34 const void* cert_data, 35 size_t cert_size, 36 int render_process_id, 37 int render_frame_id) OVERRIDE; 38 virtual content::BrowserMainParts* CreateBrowserMainParts( 39 const content::MainFunctionParams& parameters) OVERRIDE; 40 virtual content::WebContentsViewDelegate* GetWebContentsViewDelegate( 41 content::WebContents* web_contents) OVERRIDE; 42 virtual void RenderProcessWillLaunch( 43 content::RenderProcessHost* host) OVERRIDE; 44 virtual net::URLRequestContextGetter* CreateRequestContext( 45 content::BrowserContext* browser_context, 46 content::ProtocolHandlerMap* protocol_handlers, 47 content::URLRequestInterceptorScopedVector request_interceptors) OVERRIDE; 48 virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition( 49 content::BrowserContext* browser_context, 50 const base::FilePath& partition_path, 51 bool in_memory, 52 content::ProtocolHandlerMap* protocol_handlers, 53 content::URLRequestInterceptorScopedVector request_interceptors) OVERRIDE; 54 virtual std::string GetCanonicalEncodingNameByAliasName( 55 const std::string& alias_name) OVERRIDE; 56 virtual void AppendExtraCommandLineSwitches(base::CommandLine* command_line, 57 int child_process_id) OVERRIDE; 58 virtual std::string GetApplicationLocale() OVERRIDE; 59 virtual std::string GetAcceptLangs(content::BrowserContext* context) OVERRIDE; 60 virtual const gfx::ImageSkia* GetDefaultFavicon() OVERRIDE; 61 virtual bool AllowAppCache(const GURL& manifest_url, 62 const GURL& first_party, 63 content::ResourceContext* context) OVERRIDE; 64 virtual bool AllowGetCookie(const GURL& url, 65 const GURL& first_party, 66 const net::CookieList& cookie_list, 67 content::ResourceContext* context, 68 int render_process_id, 69 int render_frame_id) OVERRIDE; 70 virtual bool AllowSetCookie(const GURL& url, 71 const GURL& first_party, 72 const std::string& cookie_line, 73 content::ResourceContext* context, 74 int render_process_id, 75 int render_frame_id, 76 net::CookieOptions* options) OVERRIDE; 77 virtual bool AllowWorkerDatabase( 78 const GURL& url, 79 const base::string16& name, 80 const base::string16& display_name, 81 unsigned long estimated_size, 82 content::ResourceContext* context, 83 const std::vector<std::pair<int, int> >& render_frames) OVERRIDE; 84 virtual bool AllowWorkerFileSystem( 85 const GURL& url, 86 content::ResourceContext* context, 87 const std::vector<std::pair<int, int> >& render_frames) OVERRIDE; 88 virtual bool AllowWorkerIndexedDB( 89 const GURL& url, 90 const base::string16& name, 91 content::ResourceContext* context, 92 const std::vector<std::pair<int, int> >& render_frames) OVERRIDE; 93 virtual content::QuotaPermissionContext* 94 CreateQuotaPermissionContext() OVERRIDE; 95 virtual void AllowCertificateError( 96 int render_process_id, 97 int render_frame_id, 98 int cert_error, 99 const net::SSLInfo& ssl_info, 100 const GURL& request_url, 101 ResourceType::Type resource_type, 102 bool overridable, 103 bool strict_enforcement, 104 const base::Callback<void(bool)>& callback, 105 content::CertificateRequestResultType* result) OVERRIDE; 106 virtual void SelectClientCertificate( 107 int render_process_id, 108 int render_frame_id, 109 const net::HttpNetworkSession* network_session, 110 net::SSLCertRequestInfo* cert_request_info, 111 const base::Callback<void(net::X509Certificate*)>& callback) OVERRIDE; 112 virtual blink::WebNotificationPresenter::Permission 113 CheckDesktopNotificationPermission( 114 const GURL& source_url, 115 content::ResourceContext* context, 116 int render_process_id) OVERRIDE; 117 virtual void ShowDesktopNotification( 118 const content::ShowDesktopNotificationHostMsgParams& params, 119 content::RenderFrameHost* render_frame_host, 120 content::DesktopNotificationDelegate* delegate, 121 base::Closure* cancel_callback) OVERRIDE; 122 virtual void RequestGeolocationPermission( 123 content::WebContents* web_contents, 124 int bridge_id, 125 const GURL& requesting_frame, 126 bool user_gesture, 127 base::Callback<void(bool)> result_callback, 128 base::Closure* cancel_callback) OVERRIDE; 129 virtual void RequestMidiSysExPermission( 130 content::WebContents* web_contents, 131 int bridge_id, 132 const GURL& requesting_frame, 133 bool user_gesture, 134 base::Callback<void(bool)> result_callback, 135 base::Closure* cancel_callback) OVERRIDE; 136 virtual void RequestProtectedMediaIdentifierPermission( 137 content::WebContents* web_contents, 138 const GURL& origin, 139 base::Callback<void(bool)> result_callback, 140 base::Closure* cancel_callback) OVERRIDE; 141 virtual bool CanCreateWindow(const GURL& opener_url, 142 const GURL& opener_top_level_frame_url, 143 const GURL& source_origin, 144 WindowContainerType container_type, 145 const GURL& target_url, 146 const content::Referrer& referrer, 147 WindowOpenDisposition disposition, 148 const blink::WebWindowFeatures& features, 149 bool user_gesture, 150 bool opener_suppressed, 151 content::ResourceContext* context, 152 int render_process_id, 153 int opener_id, 154 bool* no_javascript_access) OVERRIDE; 155 virtual std::string GetWorkerProcessTitle( 156 const GURL& url, 157 content::ResourceContext* context) OVERRIDE; 158 virtual void ResourceDispatcherHostCreated() OVERRIDE; 159 virtual net::NetLog* GetNetLog() OVERRIDE; 160 virtual content::AccessTokenStore* CreateAccessTokenStore() OVERRIDE; 161 virtual bool IsFastShutdownPossible() OVERRIDE; 162 virtual void UpdateInspectorSetting(content::RenderViewHost* rvh, 163 const std::string& key, 164 const std::string& value) OVERRIDE; 165 virtual void ClearCache(content::RenderViewHost* rvh) OVERRIDE; 166 virtual void ClearCookies(content::RenderViewHost* rvh) OVERRIDE; 167 virtual base::FilePath GetDefaultDownloadDirectory() OVERRIDE; 168 virtual std::string GetDefaultDownloadName() OVERRIDE; 169 virtual void DidCreatePpapiPlugin( 170 content::BrowserPpapiHost* browser_host) OVERRIDE; 171 virtual bool AllowPepperSocketAPI( 172 content::BrowserContext* browser_context, 173 const GURL& url, 174 bool private_api, 175 const content::SocketPermissionRequest* params) OVERRIDE; 176 virtual void OverrideWebkitPrefs(content::RenderViewHost* rvh, 177 const GURL& url, 178 WebPreferences* web_prefs) OVERRIDE; 179 #if defined(VIDEO_HOLE) 180 virtual content::ExternalVideoSurfaceContainer* 181 OverrideCreateExternalVideoSurfaceContainer( 182 content::WebContents* web_contents) OVERRIDE; 183 #endif 184 185 private: 186 // Android WebView currently has a single global (non-off-the-record) browser 187 // context. 188 scoped_ptr<AwBrowserContext> browser_context_; 189 scoped_ptr<AwWebPreferencesPopulater> preferences_populater_; 190 191 JniDependencyFactory* native_factory_; 192 193 DISALLOW_COPY_AND_ASSIGN(AwContentBrowserClient); 194 }; 195 196 } // namespace android_webview 197 198 #endif // ANDROID_WEBVIEW_LIB_AW_CONTENT_BROWSER_CLIENT_H_ 199