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 XWALK_RUNTIME_BROWSER_ANDROID_XWALK_CONTENTS_CLIENT_BRIDGE_H_
6 #define XWALK_RUNTIME_BROWSER_ANDROID_XWALK_CONTENTS_CLIENT_BRIDGE_H_
14 #include "base/android/jni_weak_ref.h"
15 #include "base/android/scoped_java_ref.h"
16 #include "base/callback.h"
17 #include "base/id_map.h"
18 #include "content/public/browser/javascript_dialog_manager.h"
19 #include "xwalk/runtime/browser/android/xwalk_contents_client_bridge_base.h"
26 class X509Certificate;
33 // A class that handles the Java<->Native communication for the
34 // XWalkContentsClient. XWalkContentsClientBridge is created and owned by
35 // native XWalkViewContents class and it only has a weak reference to the
36 // its Java peer. Since the Java XWalkContentsClientBridge can have
37 // indirect refs from the Application (via callbacks) and so can outlive
38 // XWalkView, this class notifies it before being destroyed and to nullify
40 class XWalkContentsClientBridge : public XWalkContentsClientBridgeBase {
42 XWalkContentsClientBridge(JNIEnv* env, jobject obj);
43 virtual ~XWalkContentsClientBridge();
45 // XWalkContentsClientBridgeBase implementation
46 virtual void AllowCertificateError(int cert_error,
47 net::X509Certificate* cert,
48 const GURL& request_url,
49 const base::Callback<void(bool)>& callback, // NOLINT
50 bool* cancel_request) OVERRIDE;
52 virtual void RunJavaScriptDialog(
53 content::JavaScriptMessageType message_type,
54 const GURL& origin_url,
55 const base::string16& message_text,
56 const base::string16& default_prompt_text,
57 const content::JavaScriptDialogManager::DialogClosedCallback& callback)
59 virtual void RunBeforeUnloadDialog(
60 const GURL& origin_url,
61 const base::string16& message_text,
62 const content::JavaScriptDialogManager::DialogClosedCallback& callback)
64 virtual void ShowNotification(
65 const content::ShowDesktopNotificationHostMsgParams& params,
66 content::RenderFrameHost* render_frame_host,
67 content::DesktopNotificationDelegate* delegate,
68 base::Closure* cancel_callback)
70 virtual void UpdateNotificationIcon(
75 bool OnReceivedHttpAuthRequest(const base::android::JavaRef<jobject>& handler,
76 const std::string& host,
77 const std::string& realm);
79 void OnNotificationIconDownloaded(
82 const GURL& image_url,
83 const std::vector<SkBitmap>& bitmaps,
84 const std::vector<gfx::Size>& original_bitmap_sizes);
86 // Methods called from Java.
87 void ProceedSslError(JNIEnv* env, jobject obj, jboolean proceed, jint id);
88 void ConfirmJsResult(JNIEnv*, jobject, int id, jstring prompt);
89 void CancelJsResult(JNIEnv*, jobject, int id);
90 void ExitFullscreen(JNIEnv*, jobject, jlong web_contents);
91 void NotificationDisplayed(JNIEnv*, jobject, jlong delegate);
92 void NotificationError(JNIEnv*, jobject, jlong delegate);
93 void NotificationClicked(JNIEnv*, jobject, jint id, jlong delegate);
94 void NotificationClosed(JNIEnv*, jobject, jint id, bool by_user,
97 JNIEnv*, jobject, int process_id, int render_id,
98 int mode, jstring filepath, jstring display_name);
99 void OnFilesNotSelected(
100 JNIEnv*, jobject, int process_id, int render_id, int mode);
103 JavaObjectWeakGlobalRef java_ref_;
105 typedef const base::Callback<void(bool)> CertErrorCallback; // NOLINT
106 IDMap<CertErrorCallback, IDMapOwnPointer> pending_cert_error_callbacks_;
107 IDMap<content::JavaScriptDialogManager::DialogClosedCallback, IDMapOwnPointer>
108 pending_js_dialog_callbacks_;
110 typedef std::pair<int, content::RenderFrameHost*>
111 NotificationDownloadRequestInfos;
112 typedef std::map<int, NotificationDownloadRequestInfos >
113 NotificationDownloadRequestIdMap;
114 NotificationDownloadRequestIdMap downloading_icon_notifications_;
117 bool RegisterXWalkContentsClientBridge(JNIEnv* env);
121 #endif // XWALK_RUNTIME_BROWSER_ANDROID_XWALK_CONTENTS_CLIENT_BRIDGE_H_