4be301a57f9253949e4bb1a35bf5180e035a6116
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / android / xwalk_contents_client_bridge.h
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.
4
5 #ifndef XWALK_RUNTIME_BROWSER_ANDROID_XWALK_CONTENTS_CLIENT_BRIDGE_H_
6 #define XWALK_RUNTIME_BROWSER_ANDROID_XWALK_CONTENTS_CLIENT_BRIDGE_H_
7
8 #include <jni.h>
9 #include <map>
10 #include <string>
11 #include <vector>
12
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"
19
20 namespace gfx {
21 class Size;
22 }
23
24 namespace net {
25 class X509Certificate;
26 }
27
28 class SkBitmap;
29
30 namespace xwalk {
31
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
38 // any references.
39 class XWalkContentsClientBridge : public XWalkContentsClientBridgeBase {
40  public:
41   XWalkContentsClientBridge(JNIEnv* env, jobject obj);
42   virtual ~XWalkContentsClientBridge();
43
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,
49                                      bool* cancel_request) OVERRIDE;
50
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)
57       OVERRIDE;
58   virtual void RunBeforeUnloadDialog(
59       const GURL& origin_url,
60       const base::string16& message_text,
61       const content::JavaScriptDialogManager::DialogClosedCallback& callback)
62       OVERRIDE;
63   virtual void ShowNotification(
64       const content::ShowDesktopNotificationHostMsgParams& params,
65       bool worker,
66       int process_id,
67       int route_id)
68       OVERRIDE;
69   virtual void UpdateNotificationIcon(
70       int notification_id,
71       const SkBitmap& icon)
72       OVERRIDE;
73   virtual void CancelNotification(
74       int notification_id,
75       int process_id,
76       int route_id)
77       OVERRIDE;
78
79   bool OnReceivedHttpAuthRequest(const base::android::JavaRef<jobject>& handler,
80                                  const std::string& host,
81                                  const std::string& realm);
82
83   void OnNotificationIconDownloaded(
84       int id,
85       int http_status_code,
86       const GURL& image_url,
87       const std::vector<SkBitmap>& bitmaps,
88       const std::vector<gfx::Size>& original_bitmap_sizes);
89
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, jint 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
104  private:
105   JavaObjectWeakGlobalRef java_ref_;
106
107   typedef const base::Callback<void(bool)> CertErrorCallback;
108   IDMap<CertErrorCallback, IDMapOwnPointer> pending_cert_error_callbacks_;
109   IDMap<content::JavaScriptDialogManager::DialogClosedCallback, IDMapOwnPointer>
110       pending_js_dialog_callbacks_;
111
112   typedef std::map<int, std::vector<int> > NotificationDownloadRequestIdMap;
113   NotificationDownloadRequestIdMap downloading_icon_notifications_;
114 };
115
116 bool RegisterXWalkContentsClientBridge(JNIEnv* env);
117
118 }  // namespace xwalk
119
120 #endif  // XWALK_RUNTIME_BROWSER_ANDROID_XWALK_CONTENTS_CLIENT_BRIDGE_H_