OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_CLIENT_BRIDGE_H_ | |
6 #define ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_CLIENT_BRIDGE_H_ | |
7 | |
8 #include <jni.h> | |
9 | |
10 #include "android_webview/browser/aw_contents_client_bridge_base.h" | |
11 #include "base/android/jni_weak_ref.h" | |
12 #include "base/android/scoped_java_ref.h" | |
13 #include "base/callback.h" | |
14 #include "base/id_map.h" | |
15 #include "content/public/browser/javascript_dialog_manager.h" | |
16 | |
17 namespace net { | |
18 class X509Certificate; | |
19 } | |
20 | |
21 namespace android_webview { | |
22 | |
23 // A class that handles the Java<->Native communication for the | |
24 // AwContentsClient. AwContentsClientBridge is created and owned by | |
25 // native AwContents class and it only has a weak reference to the | |
26 // its Java peer. Since the Java AwContentsClientBridge can have | |
27 // indirect refs from the Application (via callbacks) and so can outlive | |
28 // webview, this class notifies it before being destroyed and to nullify | |
29 // any references. | |
30 class AwContentsClientBridge : public AwContentsClientBridgeBase { | |
31 public: | |
32 AwContentsClientBridge(JNIEnv* env, | |
33 const base::android::JavaRef<jobject>& obj); | |
34 ~AwContentsClientBridge() override; | |
35 | |
36 // AwContentsClientBridgeBase implementation | |
37 void AllowCertificateError( | |
38 int cert_error, | |
39 net::X509Certificate* cert, | |
40 const GURL& request_url, | |
41 const base::Callback<void(content::CertificateRequestResultType)>& | |
42 callback, | |
43 bool* cancel_request) override; | |
44 void SelectClientCertificate( | |
45 net::SSLCertRequestInfo* cert_request_info, | |
46 std::unique_ptr<content::ClientCertificateDelegate> delegate) override; | |
47 | |
48 void RunJavaScriptDialog( | |
49 content::JavaScriptDialogType dialog_type, | |
50 const GURL& origin_url, | |
51 const base::string16& message_text, | |
52 const base::string16& default_prompt_text, | |
53 const content::JavaScriptDialogManager::DialogClosedCallback& callback) | |
54 override; | |
55 void RunBeforeUnloadDialog( | |
56 const GURL& origin_url, | |
57 const content::JavaScriptDialogManager::DialogClosedCallback& callback) | |
58 override; | |
59 bool ShouldOverrideUrlLoading(const base::string16& url, | |
60 bool has_user_gesture, | |
61 bool is_redirect, | |
62 bool is_main_frame) override; | |
63 | |
64 void NewDownload(const GURL& url, | |
65 const std::string& user_agent, | |
66 const std::string& content_disposition, | |
67 const std::string& mime_type, | |
68 int64_t content_length) override; | |
69 | |
70 void NewLoginRequest(const std::string& realm, | |
71 const std::string& account, | |
72 const std::string& args) override; | |
73 | |
74 void OnReceivedError(const AwWebResourceRequest& request, | |
75 int error_code) override; | |
76 | |
77 void OnReceivedHttpError(const AwWebResourceRequest& request, | |
78 const scoped_refptr<const net::HttpResponseHeaders>& | |
79 response_headers) override; | |
80 | |
81 // Methods called from Java. | |
82 void ProceedSslError(JNIEnv* env, | |
83 const base::android::JavaRef<jobject>& obj, | |
84 jboolean proceed, | |
85 jint id); | |
86 void ProvideClientCertificateResponse( | |
87 JNIEnv* env, | |
88 const base::android::JavaRef<jobject>& object, | |
89 jint request_id, | |
90 const base::android::JavaRef<jobjectArray>& encoded_chain_ref, | |
91 const base::android::JavaRef<jobject>& private_key_ref); | |
92 void ConfirmJsResult(JNIEnv*, | |
93 const base::android::JavaRef<jobject>&, | |
94 int id, | |
95 const base::android::JavaRef<jstring>& prompt); | |
96 void CancelJsResult(JNIEnv*, const base::android::JavaRef<jobject>&, int id); | |
97 | |
98 private: | |
99 void HandleErrorInClientCertificateResponse(int id); | |
100 | |
101 JavaObjectWeakGlobalRef java_ref_; | |
102 | |
103 typedef const base::Callback<void(content::CertificateRequestResultType)> | |
104 CertErrorCallback; | |
105 IDMap<std::unique_ptr<CertErrorCallback>> pending_cert_error_callbacks_; | |
106 IDMap<std::unique_ptr<content::JavaScriptDialogManager::DialogClosedCallback>> | |
107 pending_js_dialog_callbacks_; | |
108 // |pending_client_cert_request_delegates_| owns its pointers, but IDMap | |
109 // doesn't provide Release, so ownership is managed manually. | |
110 IDMap<content::ClientCertificateDelegate*> | |
111 pending_client_cert_request_delegates_; | |
112 }; | |
113 | |
114 bool RegisterAwContentsClientBridge(JNIEnv* env); | |
115 | |
116 } // namespace android_webview | |
117 | |
118 #endif // ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_CLIENT_BRIDGE_H_ | |
OLD | NEW |