OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_contents_client_bridge.h" | 5 #include "android_webview/browser/aw_contents_client_bridge.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "android_webview/browser/aw_contents.h" | 10 #include "android_webview/browser/aw_contents.h" |
11 #include "android_webview/common/devtools_instrumentation.h" | 11 #include "android_webview/common/devtools_instrumentation.h" |
12 #include "android_webview/grit/components_strings.h" | 12 #include "android_webview/grit/components_strings.h" |
13 #include "base/android/jni_android.h" | 13 #include "base/android/jni_android.h" |
14 #include "base/android/jni_array.h" | 14 #include "base/android/jni_array.h" |
15 #include "base/android/jni_string.h" | 15 #include "base/android/jni_string.h" |
16 #include "base/callback_helpers.h" | 16 #include "base/callback_helpers.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
20 #include "base/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/browser/client_certificate_delegate.h" | 22 #include "content/public/browser/client_certificate_delegate.h" |
| 23 #include "content/public/browser/render_frame_host.h" |
23 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
24 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
26 #include "jni/AwContentsClientBridge_jni.h" | 27 #include "jni/AwContentsClientBridge_jni.h" |
27 #include "net/cert/x509_certificate.h" | 28 #include "net/cert/x509_certificate.h" |
28 #include "net/http/http_response_headers.h" | 29 #include "net/http/http_response_headers.h" |
29 #include "net/ssl/openssl_client_key_store.h" | 30 #include "net/ssl/openssl_client_key_store.h" |
30 #include "net/ssl/ssl_cert_request_info.h" | 31 #include "net/ssl/ssl_cert_request_info.h" |
31 #include "net/ssl/ssl_client_cert_type.h" | 32 #include "net/ssl/ssl_client_cert_type.h" |
32 #include "net/ssl/ssl_platform_key_android.h" | 33 #include "net/ssl/ssl_platform_key_android.h" |
33 #include "net/ssl/ssl_private_key.h" | 34 #include "net/ssl/ssl_private_key.h" |
34 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
35 #include "url/gurl.h" | 36 #include "url/gurl.h" |
36 | 37 |
37 using base::android::AttachCurrentThread; | 38 using base::android::AttachCurrentThread; |
38 using base::android::ConvertJavaStringToUTF16; | 39 using base::android::ConvertJavaStringToUTF16; |
39 using base::android::ConvertUTF8ToJavaString; | 40 using base::android::ConvertUTF8ToJavaString; |
40 using base::android::ConvertUTF16ToJavaString; | 41 using base::android::ConvertUTF16ToJavaString; |
41 using base::android::HasException; | 42 using base::android::HasException; |
42 using base::android::JavaRef; | 43 using base::android::JavaRef; |
43 using base::android::ScopedJavaLocalRef; | 44 using base::android::ScopedJavaLocalRef; |
44 using base::android::ToJavaArrayOfStrings; | 45 using base::android::ToJavaArrayOfStrings; |
45 using content::BrowserThread; | 46 using content::BrowserThread; |
| 47 using content::WebContents; |
46 using std::vector; | 48 using std::vector; |
47 | 49 |
48 namespace android_webview { | 50 namespace android_webview { |
49 | 51 |
50 namespace { | 52 namespace { |
51 | 53 |
52 // Must be called on the I/O thread to record a client certificate | 54 // Must be called on the I/O thread to record a client certificate |
53 // and its private key in the OpenSSLClientKeyStore. | 55 // and its private key in the OpenSSLClientKeyStore. |
54 void RecordClientCertificateKey(net::X509Certificate* client_cert, | 56 void RecordClientCertificateKey(net::X509Certificate* client_cert, |
55 scoped_refptr<net::SSLPrivateKey> private_key) { | 57 scoped_refptr<net::SSLPrivateKey> private_key) { |
56 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 58 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
57 net::OpenSSLClientKeyStore::GetInstance()->RecordClientCertPrivateKey( | 59 net::OpenSSLClientKeyStore::GetInstance()->RecordClientCertPrivateKey( |
58 client_cert, std::move(private_key)); | 60 client_cert, std::move(private_key)); |
59 } | 61 } |
60 | 62 |
| 63 const void* const kAwContentsClientBridge = &kAwContentsClientBridge; |
| 64 |
| 65 // This class is invented so that the UserData registry that we inject the |
| 66 // AwContentsClientBridge object does not own and destroy it. |
| 67 class UserData : public base::SupportsUserData::Data { |
| 68 public: |
| 69 static AwContentsClientBridge* GetContents( |
| 70 content::WebContents* web_contents) { |
| 71 if (!web_contents) |
| 72 return NULL; |
| 73 UserData* data = static_cast<UserData*>( |
| 74 web_contents->GetUserData(kAwContentsClientBridge)); |
| 75 return data ? data->contents_ : NULL; |
| 76 } |
| 77 |
| 78 explicit UserData(AwContentsClientBridge* ptr) : contents_(ptr) {} |
| 79 |
| 80 private: |
| 81 AwContentsClientBridge* contents_; |
| 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(UserData); |
| 84 }; |
| 85 |
61 } // namespace | 86 } // namespace |
62 | 87 |
| 88 // static |
| 89 void AwContentsClientBridge::Associate(WebContents* web_contents, |
| 90 AwContentsClientBridge* handler) { |
| 91 web_contents->SetUserData(kAwContentsClientBridge, |
| 92 base::MakeUnique<UserData>(handler)); |
| 93 } |
| 94 |
| 95 // static |
| 96 AwContentsClientBridge* AwContentsClientBridge::FromWebContents( |
| 97 WebContents* web_contents) { |
| 98 return UserData::GetContents(web_contents); |
| 99 } |
| 100 |
| 101 // static |
| 102 AwContentsClientBridge* AwContentsClientBridge::FromWebContentsGetter( |
| 103 const content::ResourceRequestInfo::WebContentsGetter& |
| 104 web_contents_getter) { |
| 105 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 106 WebContents* web_contents = web_contents_getter.Run(); |
| 107 return UserData::GetContents(web_contents); |
| 108 } |
| 109 |
| 110 // static |
| 111 AwContentsClientBridge* AwContentsClientBridge::FromID(int render_process_id, |
| 112 int render_frame_id) { |
| 113 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 114 content::RenderFrameHost* rfh = |
| 115 content::RenderFrameHost::FromID(render_process_id, render_frame_id); |
| 116 content::WebContents* web_contents = |
| 117 content::WebContents::FromRenderFrameHost(rfh); |
| 118 return UserData::GetContents(web_contents); |
| 119 } |
| 120 |
63 AwContentsClientBridge::AwContentsClientBridge(JNIEnv* env, | 121 AwContentsClientBridge::AwContentsClientBridge(JNIEnv* env, |
64 const JavaRef<jobject>& obj) | 122 const JavaRef<jobject>& obj) |
65 : java_ref_(env, obj) { | 123 : java_ref_(env, obj) { |
66 DCHECK(!obj.is_null()); | 124 DCHECK(!obj.is_null()); |
67 Java_AwContentsClientBridge_setNativeContentsClientBridge( | 125 Java_AwContentsClientBridge_setNativeContentsClientBridge( |
68 env, obj, reinterpret_cast<intptr_t>(this)); | 126 env, obj, reinterpret_cast<intptr_t>(this)); |
69 } | 127 } |
70 | 128 |
71 AwContentsClientBridge::~AwContentsClientBridge() { | 129 AwContentsClientBridge::~AwContentsClientBridge() { |
72 JNIEnv* env = AttachCurrentThread(); | 130 JNIEnv* env = AttachCurrentThread(); |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 pending_client_cert_request_delegates_.Remove(request_id); | 584 pending_client_cert_request_delegates_.Remove(request_id); |
527 | 585 |
528 delete delegate; | 586 delete delegate; |
529 } | 587 } |
530 | 588 |
531 bool RegisterAwContentsClientBridge(JNIEnv* env) { | 589 bool RegisterAwContentsClientBridge(JNIEnv* env) { |
532 return RegisterNativesImpl(env); | 590 return RegisterNativesImpl(env); |
533 } | 591 } |
534 | 592 |
535 } // namespace android_webview | 593 } // namespace android_webview |
OLD | NEW |