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(
74 virtual void OnWebLayoutPageScaleFactorChanged(
75 float page_scale_factor)
78 bool OnReceivedHttpAuthRequest(const base::android::JavaRef<jobject>& handler,
79 const std::string& host,
80 const std::string& realm);
82 void OnNotificationIconDownloaded(
85 const GURL& image_url,
86 const std::vector<SkBitmap>& bitmaps,
87 const std::vector<gfx::Size>& original_bitmap_sizes);
89 // Methods called from Java.
90 void ProceedSslError(JNIEnv* env, jobject obj, jboolean proceed, jint id);
91 void ConfirmJsResult(JNIEnv*, jobject, int id, jstring prompt);
92 void CancelJsResult(JNIEnv*, jobject, int id);
93 void ExitFullscreen(JNIEnv*, jobject, jlong web_contents);
94 void NotificationDisplayed(JNIEnv*, jobject, jlong delegate);
95 void NotificationError(JNIEnv*, jobject, jlong delegate);
96 void NotificationClicked(JNIEnv*, jobject, jint id, jlong delegate);
97 void NotificationClosed(JNIEnv*, jobject, jint id, bool by_user,
100 JNIEnv*, jobject, int process_id, int render_id,
101 int mode, jstring filepath, jstring display_name);
102 void OnFilesNotSelected(
103 JNIEnv*, jobject, int process_id, int render_id, int mode);
106 JavaObjectWeakGlobalRef java_ref_;
108 typedef const base::Callback<void(bool)> CertErrorCallback; // NOLINT
109 IDMap<CertErrorCallback, IDMapOwnPointer> pending_cert_error_callbacks_;
110 IDMap<content::JavaScriptDialogManager::DialogClosedCallback, IDMapOwnPointer>
111 pending_js_dialog_callbacks_;
113 typedef std::pair<int, content::RenderFrameHost*>
114 NotificationDownloadRequestInfos;
115 typedef std::map<int, NotificationDownloadRequestInfos >
116 NotificationDownloadRequestIdMap;
117 NotificationDownloadRequestIdMap downloading_icon_notifications_;
120 bool RegisterXWalkContentsClientBridge(JNIEnv* env);
124 #endif // XWALK_RUNTIME_BROWSER_ANDROID_XWALK_CONTENTS_CLIENT_BRIDGE_H_