| 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 #ifndef ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_CLIENT_BRIDGE_H_ | 5 #ifndef ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_CLIENT_BRIDGE_H_ |
| 6 #define ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_CLIENT_BRIDGE_H_ | 6 #define ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_CLIENT_BRIDGE_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 #include <memory> |
| 9 | 10 |
| 10 #include "android_webview/browser/aw_contents_client_bridge_base.h" | 11 #include "android_webview/browser/net/aw_web_resource_request.h" |
| 11 #include "base/android/jni_weak_ref.h" | 12 #include "base/android/jni_weak_ref.h" |
| 12 #include "base/android/scoped_java_ref.h" | 13 #include "base/android/scoped_java_ref.h" |
| 13 #include "base/callback.h" | 14 #include "base/callback.h" |
| 14 #include "base/id_map.h" | 15 #include "base/id_map.h" |
| 16 #include "base/supports_user_data.h" |
| 17 #include "content/public/browser/certificate_request_result_type.h" |
| 15 #include "content/public/browser/javascript_dialog_manager.h" | 18 #include "content/public/browser/javascript_dialog_manager.h" |
| 19 #include "content/public/browser/resource_request_info.h" |
| 20 #include "net/http/http_response_headers.h" |
| 21 |
| 22 class GURL; |
| 23 |
| 24 namespace content { |
| 25 class ClientCertificateDelegate; |
| 26 class WebContents; |
| 27 } |
| 16 | 28 |
| 17 namespace net { | 29 namespace net { |
| 30 class SSLCertRequestInfo; |
| 18 class X509Certificate; | 31 class X509Certificate; |
| 19 } | 32 } |
| 20 | 33 |
| 21 namespace android_webview { | 34 namespace android_webview { |
| 22 | 35 |
| 23 // A class that handles the Java<->Native communication for the | 36 // A class that handles the Java<->Native communication for the |
| 24 // AwContentsClient. AwContentsClientBridge is created and owned by | 37 // AwContentsClient. AwContentsClientBridge is created and owned by |
| 25 // native AwContents class and it only has a weak reference to the | 38 // native AwContents class and it only has a weak reference to the |
| 26 // its Java peer. Since the Java AwContentsClientBridge can have | 39 // its Java peer. Since the Java AwContentsClientBridge can have |
| 27 // indirect refs from the Application (via callbacks) and so can outlive | 40 // indirect refs from the Application (via callbacks) and so can outlive |
| 28 // webview, this class notifies it before being destroyed and to nullify | 41 // webview, this class notifies it before being destroyed and to nullify |
| 29 // any references. | 42 // any references. |
| 30 class AwContentsClientBridge : public AwContentsClientBridgeBase { | 43 class AwContentsClientBridge { |
| 31 public: | 44 public: |
| 45 // Adds the handler to the UserData registry. |
| 46 static void Associate(content::WebContents* web_contents, |
| 47 AwContentsClientBridge* handler); |
| 48 static AwContentsClientBridge* FromWebContents( |
| 49 content::WebContents* web_contents); |
| 50 static AwContentsClientBridge* FromWebContentsGetter( |
| 51 const content::ResourceRequestInfo::WebContentsGetter& |
| 52 web_contents_getter); |
| 53 static AwContentsClientBridge* FromID(int render_process_id, |
| 54 int render_frame_id); |
| 32 AwContentsClientBridge(JNIEnv* env, | 55 AwContentsClientBridge(JNIEnv* env, |
| 33 const base::android::JavaRef<jobject>& obj); | 56 const base::android::JavaRef<jobject>& obj); |
| 34 ~AwContentsClientBridge() override; | 57 ~AwContentsClientBridge(); |
| 35 | 58 |
| 36 // AwContentsClientBridgeBase implementation | 59 // AwContentsClientBridge implementation |
| 37 void AllowCertificateError( | 60 void AllowCertificateError( |
| 38 int cert_error, | 61 int cert_error, |
| 39 net::X509Certificate* cert, | 62 net::X509Certificate* cert, |
| 40 const GURL& request_url, | 63 const GURL& request_url, |
| 41 const base::Callback<void(content::CertificateRequestResultType)>& | 64 const base::Callback<void(content::CertificateRequestResultType)>& |
| 42 callback, | 65 callback, |
| 43 bool* cancel_request) override; | 66 bool* cancel_request); |
| 44 void SelectClientCertificate( | 67 void SelectClientCertificate( |
| 45 net::SSLCertRequestInfo* cert_request_info, | 68 net::SSLCertRequestInfo* cert_request_info, |
| 46 std::unique_ptr<content::ClientCertificateDelegate> delegate) override; | 69 std::unique_ptr<content::ClientCertificateDelegate> delegate); |
| 47 | |
| 48 void RunJavaScriptDialog( | 70 void RunJavaScriptDialog( |
| 49 content::JavaScriptDialogType dialog_type, | 71 content::JavaScriptDialogType dialog_type, |
| 50 const GURL& origin_url, | 72 const GURL& origin_url, |
| 51 const base::string16& message_text, | 73 const base::string16& message_text, |
| 52 const base::string16& default_prompt_text, | 74 const base::string16& default_prompt_text, |
| 53 const content::JavaScriptDialogManager::DialogClosedCallback& callback) | 75 const content::JavaScriptDialogManager::DialogClosedCallback& callback); |
| 54 override; | |
| 55 void RunBeforeUnloadDialog( | 76 void RunBeforeUnloadDialog( |
| 56 const GURL& origin_url, | 77 const GURL& origin_url, |
| 57 const content::JavaScriptDialogManager::DialogClosedCallback& callback) | 78 const content::JavaScriptDialogManager::DialogClosedCallback& callback); |
| 58 override; | |
| 59 bool ShouldOverrideUrlLoading(const base::string16& url, | 79 bool ShouldOverrideUrlLoading(const base::string16& url, |
| 60 bool has_user_gesture, | 80 bool has_user_gesture, |
| 61 bool is_redirect, | 81 bool is_redirect, |
| 62 bool is_main_frame) override; | 82 bool is_main_frame); |
| 63 | |
| 64 void NewDownload(const GURL& url, | 83 void NewDownload(const GURL& url, |
| 65 const std::string& user_agent, | 84 const std::string& user_agent, |
| 66 const std::string& content_disposition, | 85 const std::string& content_disposition, |
| 67 const std::string& mime_type, | 86 const std::string& mime_type, |
| 68 int64_t content_length) override; | 87 int64_t content_length); |
| 69 | 88 |
| 89 // Called when a new login request is detected. See the documentation for |
| 90 // WebViewClient.onReceivedLoginRequest for arguments. Note that |account| |
| 91 // may be empty. |
| 70 void NewLoginRequest(const std::string& realm, | 92 void NewLoginRequest(const std::string& realm, |
| 71 const std::string& account, | 93 const std::string& account, |
| 72 const std::string& args) override; | 94 const std::string& args); |
| 73 | 95 |
| 74 void OnReceivedError(const AwWebResourceRequest& request, | 96 // Called when a resource loading error has occured (e.g. an I/O error, |
| 75 int error_code) override; | 97 // host name lookup failure etc.) |
| 98 void OnReceivedError(const AwWebResourceRequest& request, int error_code); |
| 76 | 99 |
| 77 void OnReceivedHttpError(const AwWebResourceRequest& request, | 100 // Called when a response from the server is received with status code >= 400. |
| 78 const scoped_refptr<const net::HttpResponseHeaders>& | 101 void OnReceivedHttpError( |
| 79 response_headers) override; | 102 const AwWebResourceRequest& request, |
| 103 const scoped_refptr<const net::HttpResponseHeaders>& response_headers); |
| 80 | 104 |
| 81 // Methods called from Java. | 105 // Methods called from Java. |
| 82 void ProceedSslError(JNIEnv* env, | 106 void ProceedSslError(JNIEnv* env, |
| 83 const base::android::JavaRef<jobject>& obj, | 107 const base::android::JavaRef<jobject>& obj, |
| 84 jboolean proceed, | 108 jboolean proceed, |
| 85 jint id); | 109 jint id); |
| 86 void ProvideClientCertificateResponse( | 110 void ProvideClientCertificateResponse( |
| 87 JNIEnv* env, | 111 JNIEnv* env, |
| 88 const base::android::JavaRef<jobject>& object, | 112 const base::android::JavaRef<jobject>& object, |
| 89 jint request_id, | 113 jint request_id, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 109 // doesn't provide Release, so ownership is managed manually. | 133 // doesn't provide Release, so ownership is managed manually. |
| 110 IDMap<content::ClientCertificateDelegate*> | 134 IDMap<content::ClientCertificateDelegate*> |
| 111 pending_client_cert_request_delegates_; | 135 pending_client_cert_request_delegates_; |
| 112 }; | 136 }; |
| 113 | 137 |
| 114 bool RegisterAwContentsClientBridge(JNIEnv* env); | 138 bool RegisterAwContentsClientBridge(JNIEnv* env); |
| 115 | 139 |
| 116 } // namespace android_webview | 140 } // namespace android_webview |
| 117 | 141 |
| 118 #endif // ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_CLIENT_BRIDGE_H_ | 142 #endif // ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_CLIENT_BRIDGE_H_ |
| OLD | NEW |