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.
6 #ifndef XWALK_RUNTIME_BROWSER_ANDROID_XWALK_CONTENT_H_
7 #define XWALK_RUNTIME_BROWSER_ANDROID_XWALK_CONTENT_H_
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"
17 using base::android::ScopedJavaLocalRef;
26 class XWalkWebContentsDelegate;
27 class XWalkContentsClientBridge;
31 explicit XWalkContent(scoped_ptr<content::WebContents> web_contents);
34 static XWalkContent* FromID(int render_process_id, int render_view_id);
35 static XWalkContent* FromWebContents(content::WebContents* web_contents);
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,
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,
54 jboolean SetState(JNIEnv* env, jobject obj, jbyteArray state);
56 XWalkRenderViewHostExt* render_view_host_ext() {
57 return render_view_host_ext_.get();
60 XWalkContentsClientBridge* GetContentsClientBridge() {
61 return contents_client_bridge_.get();
64 void SetJsOnlineProperty(JNIEnv* env, jobject obj, jboolean network_up);
65 jboolean SetManifest(JNIEnv* env,
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,
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_;
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 */ \
97 // The first element in the list is always the currently pending request.
98 std::list<OriginCallback> pending_geolocation_prompts_;
101 bool RegisterXWalkContent(JNIEnv* env);
105 #endif // XWALK_RUNTIME_BROWSER_ANDROID_XWALK_CONTENT_H_