Minor Python style clean-up
[chromium-blink-merge.git] / android_webview / native / aw_contents_client_bridge.h
blob74f13e00403581871b27b2f736df5ebeee2c408f
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.
5 #ifndef ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_CLIENT_BRIDGE_H_
6 #define ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_CLIENT_BRIDGE_H_
8 #include <jni.h>
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"
17 namespace net {
18 class X509Certificate;
21 namespace android_webview {
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, jobject obj);
33 ~AwContentsClientBridge() override;
35 // AwContentsClientBridgeBase implementation
36 void AllowCertificateError(int cert_error,
37 net::X509Certificate* cert,
38 const GURL& request_url,
39 const base::Callback<void(bool)>& callback,
40 bool* cancel_request) override;
41 void SelectClientCertificate(
42 net::SSLCertRequestInfo* cert_request_info,
43 scoped_ptr<content::ClientCertificateDelegate> delegate) override;
45 void RunJavaScriptDialog(
46 content::JavaScriptMessageType message_type,
47 const GURL& origin_url,
48 const base::string16& message_text,
49 const base::string16& default_prompt_text,
50 const content::JavaScriptDialogManager::DialogClosedCallback& callback)
51 override;
52 void RunBeforeUnloadDialog(
53 const GURL& origin_url,
54 const base::string16& message_text,
55 const content::JavaScriptDialogManager::DialogClosedCallback& callback)
56 override;
58 // Methods called from Java.
59 void ProceedSslError(JNIEnv* env, jobject obj, jboolean proceed, jint id);
60 void ProvideClientCertificateResponse(JNIEnv* env, jobject object,
61 jint request_id, jobjectArray encoded_chain_ref,
62 jobject private_key_ref);
63 void ConfirmJsResult(JNIEnv*, jobject, int id, jstring prompt);
64 void CancelJsResult(JNIEnv*, jobject, int id);
66 private:
67 void HandleErrorInClientCertificateResponse(int id);
69 JavaObjectWeakGlobalRef java_ref_;
71 typedef const base::Callback<void(bool)> CertErrorCallback;
72 IDMap<CertErrorCallback, IDMapOwnPointer> pending_cert_error_callbacks_;
73 IDMap<content::JavaScriptDialogManager::DialogClosedCallback, IDMapOwnPointer>
74 pending_js_dialog_callbacks_;
75 // |pending_client_cert_request_delegates_| owns its pointers, but IDMap
76 // doesn't provide Release, so ownership is managed manually.
77 IDMap<content::ClientCertificateDelegate>
78 pending_client_cert_request_delegates_;
81 bool RegisterAwContentsClientBridge(JNIEnv* env);
83 } // namespace android_webview
85 #endif // ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_CLIENT_BRIDGE_H_