| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "android_webview/browser/aw_content_browser_client.h" | 5 #include "android_webview/browser/aw_content_browser_client.h" |
| 6 | 6 |
| 7 #include "android_webview/browser/aw_browser_context.h" | 7 #include "android_webview/browser/aw_browser_context.h" |
| 8 #include "android_webview/browser/aw_browser_main_parts.h" | 8 #include "android_webview/browser/aw_browser_main_parts.h" |
| 9 #include "android_webview/browser/aw_contents_client_bridge_base.h" | 9 #include "android_webview/browser/aw_contents_client_bridge_base.h" |
| 10 #include "android_webview/browser/aw_cookie_access_policy.h" | 10 #include "android_webview/browser/aw_cookie_access_policy.h" |
| 11 #include "android_webview/browser/aw_quota_permission_context.h" | 11 #include "android_webview/browser/aw_quota_permission_context.h" |
| 12 #include "android_webview/browser/aw_web_preferences_populater.h" | 12 #include "android_webview/browser/aw_web_preferences_populater.h" |
| 13 #include "android_webview/browser/jni_dependency_factory.h" | 13 #include "android_webview/browser/jni_dependency_factory.h" |
| 14 #include "android_webview/browser/net_disk_cache_remover.h" | 14 #include "android_webview/browser/net_disk_cache_remover.h" |
| 15 #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele
gate.h" | 15 #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele
gate.h" |
| 16 #include "android_webview/common/render_view_messages.h" |
| 16 #include "android_webview/common/url_constants.h" | 17 #include "android_webview/common/url_constants.h" |
| 17 #include "base/base_paths_android.h" | 18 #include "base/base_paths_android.h" |
| 18 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 19 #include "content/public/browser/access_token_store.h" | 20 #include "content/public/browser/access_token_store.h" |
| 21 #include "content/public/browser/browser_message_filter.h" |
| 22 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/child_process_security_policy.h" | 23 #include "content/public/browser/child_process_security_policy.h" |
| 21 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
| 22 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
| 23 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/common/url_constants.h" | 27 #include "content/public/common/url_constants.h" |
| 25 #include "grit/ui_resources.h" | 28 #include "grit/ui_resources.h" |
| 26 #include "net/android/network_library.h" | 29 #include "net/android/network_library.h" |
| 27 #include "net/ssl/ssl_cert_request_info.h" | 30 #include "net/ssl/ssl_cert_request_info.h" |
| 28 #include "net/ssl/ssl_info.h" | 31 #include "net/ssl/ssl_info.h" |
| 29 #include "ui/base/l10n/l10n_util_android.h" | 32 #include "ui/base/l10n/l10n_util_android.h" |
| 30 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
| 31 #include "webkit/common/webpreferences.h" | 34 #include "webkit/common/webpreferences.h" |
| 32 | 35 |
| 36 using content::BrowserThread; |
| 37 |
| 33 namespace android_webview { | 38 namespace android_webview { |
| 34 namespace { | 39 namespace { |
| 35 | 40 |
| 41 // TODO(sgurun) move this to its own file. |
| 42 // This class filters out incoming aw_contents related IPC messages for the |
| 43 // renderer process on the IPC thread. |
| 44 class AwContentsMessageFilter : public content::BrowserMessageFilter { |
| 45 public: |
| 46 explicit AwContentsMessageFilter(int process_id); |
| 47 |
| 48 // BrowserMessageFilter methods. |
| 49 virtual void OverrideThreadForMessage( |
| 50 const IPC::Message& message, |
| 51 BrowserThread::ID* thread) OVERRIDE; |
| 52 virtual bool OnMessageReceived( |
| 53 const IPC::Message& message, |
| 54 bool* message_was_ok) OVERRIDE; |
| 55 |
| 56 void OnShouldOverrideUrlLoading(int routing_id, |
| 57 const base::string16& url, |
| 58 bool* ignore_navigation); |
| 59 |
| 60 private: |
| 61 virtual ~AwContentsMessageFilter(); |
| 62 |
| 63 int process_id_; |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(AwContentsMessageFilter); |
| 66 }; |
| 67 |
| 68 AwContentsMessageFilter::AwContentsMessageFilter(int process_id) |
| 69 : process_id_(process_id) { |
| 70 } |
| 71 |
| 72 AwContentsMessageFilter::~AwContentsMessageFilter() { |
| 73 } |
| 74 |
| 75 void AwContentsMessageFilter::OverrideThreadForMessage( |
| 76 const IPC::Message& message, BrowserThread::ID* thread) { |
| 77 if (message.type() == AwViewHostMsg_ShouldOverrideUrlLoading::ID) { |
| 78 *thread = BrowserThread::UI; |
| 79 } |
| 80 } |
| 81 |
| 82 bool AwContentsMessageFilter::OnMessageReceived(const IPC::Message& message, |
| 83 bool* message_was_ok) { |
| 84 bool handled = true; |
| 85 IPC_BEGIN_MESSAGE_MAP_EX(AwContentsMessageFilter, message, *message_was_ok) |
| 86 IPC_MESSAGE_HANDLER(AwViewHostMsg_ShouldOverrideUrlLoading, |
| 87 OnShouldOverrideUrlLoading) |
| 88 IPC_MESSAGE_UNHANDLED(handled = false) |
| 89 IPC_END_MESSAGE_MAP() |
| 90 return handled; |
| 91 } |
| 92 |
| 93 void AwContentsMessageFilter::OnShouldOverrideUrlLoading( |
| 94 int routing_id, |
| 95 const base::string16& url, |
| 96 bool* ignore_navigation) { |
| 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 98 *ignore_navigation = false; |
| 99 AwContentsClientBridgeBase* client = |
| 100 AwContentsClientBridgeBase::FromID(process_id_, routing_id); |
| 101 if (client) { |
| 102 *ignore_navigation = client->ShouldOverrideUrlLoading(url); |
| 103 } else { |
| 104 LOG(WARNING) << "Failed to find the associated render view host for url: " |
| 105 << url; |
| 106 } |
| 107 } |
| 108 |
| 36 class AwAccessTokenStore : public content::AccessTokenStore { | 109 class AwAccessTokenStore : public content::AccessTokenStore { |
| 37 public: | 110 public: |
| 38 AwAccessTokenStore() { } | 111 AwAccessTokenStore() { } |
| 39 | 112 |
| 40 // content::AccessTokenStore implementation | 113 // content::AccessTokenStore implementation |
| 41 virtual void LoadAccessTokens( | 114 virtual void LoadAccessTokens( |
| 42 const LoadAccessTokensCallbackType& request) OVERRIDE { | 115 const LoadAccessTokensCallbackType& request) OVERRIDE { |
| 43 AccessTokenStore::AccessTokenSet access_token_set; | 116 AccessTokenStore::AccessTokenSet access_token_set; |
| 44 // AccessTokenSet and net::URLRequestContextGetter not used on Android, | 117 // AccessTokenSet and net::URLRequestContextGetter not used on Android, |
| 45 // but Run needs to be called to finish the geolocation setup. | 118 // but Run needs to be called to finish the geolocation setup. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // really does need that priviledge. Check here to ensure we rethink this | 188 // really does need that priviledge. Check here to ensure we rethink this |
| 116 // when the time comes. See crbug.com/156062. | 189 // when the time comes. See crbug.com/156062. |
| 117 CHECK(content::RenderProcessHost::run_renderer_in_process()); | 190 CHECK(content::RenderProcessHost::run_renderer_in_process()); |
| 118 | 191 |
| 119 // Grant content: and file: scheme to the whole process, since we impose | 192 // Grant content: and file: scheme to the whole process, since we impose |
| 120 // per-view access checks. | 193 // per-view access checks. |
| 121 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme( | 194 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme( |
| 122 host->GetID(), android_webview::kContentScheme); | 195 host->GetID(), android_webview::kContentScheme); |
| 123 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme( | 196 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme( |
| 124 host->GetID(), chrome::kFileScheme); | 197 host->GetID(), chrome::kFileScheme); |
| 198 |
| 199 host->AddFilter(new AwContentsMessageFilter(host->GetID())); |
| 125 } | 200 } |
| 126 | 201 |
| 127 net::URLRequestContextGetter* | 202 net::URLRequestContextGetter* |
| 128 AwContentBrowserClient::CreateRequestContext( | 203 AwContentBrowserClient::CreateRequestContext( |
| 129 content::BrowserContext* browser_context, | 204 content::BrowserContext* browser_context, |
| 130 content::ProtocolHandlerMap* protocol_handlers) { | 205 content::ProtocolHandlerMap* protocol_handlers) { |
| 131 DCHECK(browser_context_.get() == browser_context); | 206 DCHECK(browser_context_.get() == browser_context); |
| 132 return browser_context_->CreateRequestContext(protocol_handlers); | 207 return browser_context_->CreateRequestContext(protocol_handlers); |
| 133 } | 208 } |
| 134 | 209 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 if (cancel_request) | 340 if (cancel_request) |
| 266 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY; | 341 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY; |
| 267 } | 342 } |
| 268 | 343 |
| 269 void AwContentBrowserClient::SelectClientCertificate( | 344 void AwContentBrowserClient::SelectClientCertificate( |
| 270 int render_process_id, | 345 int render_process_id, |
| 271 int render_view_id, | 346 int render_view_id, |
| 272 const net::HttpNetworkSession* network_session, | 347 const net::HttpNetworkSession* network_session, |
| 273 net::SSLCertRequestInfo* cert_request_info, | 348 net::SSLCertRequestInfo* cert_request_info, |
| 274 const base::Callback<void(net::X509Certificate*)>& callback) { | 349 const base::Callback<void(net::X509Certificate*)>& callback) { |
| 275 LOG(INFO) << "Client certificate request from " | 350 LOG(WARNING) << "Client certificate request from " |
| 276 << cert_request_info->host_and_port | 351 << cert_request_info->host_and_port |
| 277 << " rejected. (Client certificates not supported in WebView)"; | 352 << " rejected. (Client certificates not supported in WebView)"; |
| 278 callback.Run(NULL); | 353 callback.Run(NULL); |
| 279 } | 354 } |
| 280 | 355 |
| 281 blink::WebNotificationPresenter::Permission | 356 blink::WebNotificationPresenter::Permission |
| 282 AwContentBrowserClient::CheckDesktopNotificationPermission( | 357 AwContentBrowserClient::CheckDesktopNotificationPermission( |
| 283 const GURL& source_url, | 358 const GURL& source_url, |
| 284 content::ResourceContext* context, | 359 content::ResourceContext* context, |
| 285 int render_process_id) { | 360 int render_process_id) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 WebPreferences* web_prefs) { | 483 WebPreferences* web_prefs) { |
| 409 if (!preferences_populater_.get()) { | 484 if (!preferences_populater_.get()) { |
| 410 preferences_populater_ = make_scoped_ptr(native_factory_-> | 485 preferences_populater_ = make_scoped_ptr(native_factory_-> |
| 411 CreateWebPreferencesPopulater()); | 486 CreateWebPreferencesPopulater()); |
| 412 } | 487 } |
| 413 preferences_populater_->PopulateFor( | 488 preferences_populater_->PopulateFor( |
| 414 content::WebContents::FromRenderViewHost(rvh), web_prefs); | 489 content::WebContents::FromRenderViewHost(rvh), web_prefs); |
| 415 } | 490 } |
| 416 | 491 |
| 417 } // namespace android_webview | 492 } // namespace android_webview |
| OLD | NEW |