ca6b7990b17a4ecee8f3f40b522700eb8f5531ac
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / android / xwalk_content.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Copyright (c) 2013 Intel Corporation. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 #ifndef XWALK_RUNTIME_BROWSER_ANDROID_XWALK_CONTENT_H_
7 #define XWALK_RUNTIME_BROWSER_ANDROID_XWALK_CONTENT_H_
8
9 #include <list>
10 #include <utility>
11
12 #include "base/android/jni_helper.h"
13 #include "base/android/scoped_java_ref.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "xwalk/runtime/browser/android/renderer_host/xwalk_render_view_host_ext.h"
16
17 using base::android::ScopedJavaLocalRef;
18
19 namespace content {
20 class BrowserContext;
21 class WebContents;
22 }
23
24 namespace xwalk {
25
26 class XWalkWebContentsDelegate;
27 class XWalkContentsClientBridge;
28
29 class XWalkContent {
30  public:
31   XWalkContent(JNIEnv* env, jobject obj, jobject web_contents_delegate,
32       jobject contents_client_bridge);
33   ~XWalkContent();
34
35   static XWalkContent* FromID(int render_process_id, int render_view_id);
36   static XWalkContent* FromWebContents(content::WebContents* web_contents);
37
38   jlong GetWebContents(JNIEnv* env, jobject obj, jobject io_thread_client,
39                       jobject delegate);
40   void ClearCache(JNIEnv* env, jobject obj, jboolean include_disk_files);
41   ScopedJavaLocalRef<jstring> DevToolsAgentId(JNIEnv* env, jobject obj);
42   void Destroy(JNIEnv* env, jobject obj);
43   ScopedJavaLocalRef<jstring> GetVersion(JNIEnv* env, jobject obj);
44   jint GetRoutingID(JNIEnv* env, jobject obj);
45   base::android::ScopedJavaLocalRef<jbyteArray> GetState(JNIEnv* env,
46                                                          jobject obj);
47   jboolean SetState(JNIEnv* env, jobject obj, jbyteArray state);
48
49   XWalkRenderViewHostExt* render_view_host_ext() {
50     return render_view_host_ext_.get();
51   };
52
53   XWalkContentsClientBridge* GetContentsClientBridge() {
54     return contents_client_bridge_.get();
55   };
56
57   void SetJsOnlineProperty(JNIEnv* env, jobject obj, jboolean network_up);
58   jboolean SetManifest(JNIEnv* env,
59                        jobject obj,
60                        jstring path,
61                        jstring manifest);
62
63   // Geolocation API support
64   void ShowGeolocationPrompt(const GURL& origin,
65                              const base::Callback<void(bool)>& callback); // NOLINT
66   void HideGeolocationPrompt(const GURL& origin);
67   void InvokeGeolocationCallback(JNIEnv* env,
68                                  jobject obj,
69                                  jboolean value,
70                                  jstring origin);
71
72  private:
73   content::WebContents* CreateWebContents(JNIEnv* env, jobject io_thread_client,
74                                           jobject delegate);
75
76   JavaObjectWeakGlobalRef java_ref_;
77   scoped_ptr<content::WebContents> web_contents_;
78   scoped_ptr<XWalkWebContentsDelegate> web_contents_delegate_;
79   scoped_ptr<XWalkRenderViewHostExt> render_view_host_ext_;
80   scoped_ptr<XWalkContentsClientBridge> contents_client_bridge_;
81
82   // GURL is supplied by the content layer as requesting frame.
83   // Callback is supplied by the content layer, and is invoked with the result
84   // from the permission prompt.
85   typedef std::pair<const GURL, const base::Callback<void(bool)> >  /* NOLINT */ \
86           OriginCallback;
87   // The first element in the list is always the currently pending request.
88   std::list<OriginCallback> pending_geolocation_prompts_;
89 };
90
91 bool RegisterXWalkContent(JNIEnv* env);
92
93 }  // namespace xwalk
94
95 #endif  // XWALK_RUNTIME_BROWSER_ANDROID_XWALK_CONTENT_H_