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_
13 #include "base/android/jni_helper.h"
14 #include "base/android/scoped_java_ref.h"
15 #include "base/callback.h"
16 #include "base/id_map.h"
17 #include "content/public/browser/javascript_dialog_manager.h"
18 #include "xwalk/runtime/browser/android/xwalk_contents_client_bridge_base.h"
25 class X509Certificate;
32 // A class that handles the Java<->Native communication for the
33 // XWalkContentsClient. XWalkContentsClientBridge is created and owned by
34 // native XWalkViewContents class and it only has a weak reference to the
35 // its Java peer. Since the Java XWalkContentsClientBridge can have
36 // indirect refs from the Application (via callbacks) and so can outlive
37 // XWalkView, this class notifies it before being destroyed and to nullify
39 class XWalkContentsClientBridge : public XWalkContentsClientBridgeBase {
41 XWalkContentsClientBridge(JNIEnv* env, jobject obj);
42 virtual ~XWalkContentsClientBridge();
44 // XWalkContentsClientBridgeBase implementation
45 virtual void AllowCertificateError(int cert_error,
46 net::X509Certificate* cert,
47 const GURL& request_url,
48 const base::Callback<void(bool)>& callback, // NOLINT
49 bool* cancel_request) OVERRIDE;
51 virtual void RunJavaScriptDialog(
52 content::JavaScriptMessageType message_type,
53 const GURL& origin_url,
54 const base::string16& message_text,
55 const base::string16& default_prompt_text,
56 const content::JavaScriptDialogManager::DialogClosedCallback& callback)
58 virtual void RunBeforeUnloadDialog(
59 const GURL& origin_url,
60 const base::string16& message_text,
61 const content::JavaScriptDialogManager::DialogClosedCallback& callback)
63 virtual void ShowNotification(
64 const content::ShowDesktopNotificationHostMsgParams& params,
69 virtual void UpdateNotificationIcon(
73 virtual void CancelNotification(
79 bool OnReceivedHttpAuthRequest(const base::android::JavaRef<jobject>& handler,
80 const std::string& host,
81 const std::string& realm);
83 void OnNotificationIconDownloaded(
86 const GURL& image_url,
87 const std::vector<SkBitmap>& bitmaps,
88 const std::vector<gfx::Size>& original_bitmap_sizes);
90 // Methods called from Java.
91 void ProceedSslError(JNIEnv* env, jobject obj, jboolean proceed, jint id);
92 void ConfirmJsResult(JNIEnv*, jobject, int id, jstring prompt);
93 void CancelJsResult(JNIEnv*, jobject, int id);
94 void ExitFullscreen(JNIEnv*, jobject, jlong web_contents);
95 void NotificationDisplayed(
96 JNIEnv*, jobject, int id, int process_id, int route_id);
97 void NotificationError(
98 JNIEnv*, jobject, int id, jstring error, int process_id, int route_id);
99 void NotificationClicked(
100 JNIEnv*, jobject, int id, int process_id, int route_id);
101 void NotificationClosed(
102 JNIEnv*, jobject, int id, bool by_user, int process_id, int route_id);
103 void OnFilesSelected(
104 JNIEnv*, jobject, int process_id, int render_id,
105 int mode, jstring filepath, jstring display_name);
106 void OnFilesNotSelected(
107 JNIEnv*, jobject, int process_id, int render_id, int mode);
110 JavaObjectWeakGlobalRef java_ref_;
112 typedef const base::Callback<void(bool)> CertErrorCallback; // NOLINT
113 IDMap<CertErrorCallback, IDMapOwnPointer> pending_cert_error_callbacks_;
114 IDMap<content::JavaScriptDialogManager::DialogClosedCallback, IDMapOwnPointer>
115 pending_js_dialog_callbacks_;
117 typedef std::map<int, std::vector<int> > NotificationDownloadRequestIdMap;
118 NotificationDownloadRequestIdMap downloading_icon_notifications_;
121 bool RegisterXWalkContentsClientBridge(JNIEnv* env);
125 #endif // XWALK_RUNTIME_BROWSER_ANDROID_XWALK_CONTENTS_CLIENT_BRIDGE_H_