Upstream version 10.38.210.0
[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_weak_ref.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   explicit XWalkContent(scoped_ptr<content::WebContents> web_contents);
32   ~XWalkContent();
33
34   static XWalkContent* FromID(int render_process_id, int render_view_id);
35   static XWalkContent* FromWebContents(content::WebContents* web_contents);
36
37   jlong GetWebContents(JNIEnv* env, jobject obj);
38   void SetPendingWebContentsForPopup(scoped_ptr<content::WebContents> pending);
39   jlong ReleasePopupXWalkContent(JNIEnv* env, jobject obj);
40   void SetJavaPeers(JNIEnv* env,
41                     jobject obj,
42                     jobject xwalk_content,
43                     jobject web_contents_delegate,
44                     jobject contents_client_bridge,
45                     jobject io_thread_client,
46                     jobject intercept_navigation_delegate);
47   void ClearCache(JNIEnv* env, jobject obj, jboolean include_disk_files);
48   ScopedJavaLocalRef<jstring> DevToolsAgentId(JNIEnv* env, jobject obj);
49   void Destroy(JNIEnv* env, jobject obj);
50   ScopedJavaLocalRef<jstring> GetVersion(JNIEnv* env, jobject obj);
51   jint GetRoutingID(JNIEnv* env, jobject obj);
52   base::android::ScopedJavaLocalRef<jbyteArray> GetState(JNIEnv* env,
53                                                          jobject obj);
54   jboolean SetState(JNIEnv* env, jobject obj, jbyteArray state);
55
56   XWalkRenderViewHostExt* render_view_host_ext() {
57     return render_view_host_ext_.get();
58   }
59
60   XWalkContentsClientBridge* GetContentsClientBridge() {
61     return contents_client_bridge_.get();
62   }
63
64   void SetJsOnlineProperty(JNIEnv* env, jobject obj, jboolean network_up);
65   jboolean SetManifest(JNIEnv* env,
66                        jobject obj,
67                        jstring path,
68                        jstring manifest);
69
70   // Geolocation API support
71   void ShowGeolocationPrompt(const GURL& origin,
72                              const base::Callback<void(bool)>& callback); // NOLINT
73   void HideGeolocationPrompt(const GURL& origin);
74   void InvokeGeolocationCallback(JNIEnv* env,
75                                  jobject obj,
76                                  jboolean value,
77                                  jstring origin);
78
79  private:
80   JavaObjectWeakGlobalRef java_ref_;
81   // TODO(guangzhen): The WebContentsDelegate need to take ownership of
82   // WebContents as chrome content design. For xwalk, XWalkContent owns
83   // these two, we need to redesign XWalkContent in the future.
84   // Currently as a workaround, below declaration order makes sure
85   // the WebContents destructed before WebContentsDelegate.
86   scoped_ptr<XWalkWebContentsDelegate> web_contents_delegate_;
87   scoped_ptr<XWalkRenderViewHostExt> render_view_host_ext_;
88   scoped_ptr<XWalkContentsClientBridge> contents_client_bridge_;
89   scoped_ptr<content::WebContents> web_contents_;
90   scoped_ptr<XWalkContent> pending_contents_;
91
92   // GURL is supplied by the content layer as requesting frame.
93   // Callback is supplied by the content layer, and is invoked with the result
94   // from the permission prompt.
95   typedef std::pair<const GURL, const base::Callback<void(bool)> >  /* NOLINT */ \
96           OriginCallback;
97   // The first element in the list is always the currently pending request.
98   std::list<OriginCallback> pending_geolocation_prompts_;
99 };
100
101 bool RegisterXWalkContent(JNIEnv* env);
102
103 }  // namespace xwalk
104
105 #endif  // XWALK_RUNTIME_BROWSER_ANDROID_XWALK_CONTENT_H_