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,
69 void SetBackgroundColor(JNIEnv* env, jobject obj, jint color);
71 // Geolocation API support
72 void ShowGeolocationPrompt(const GURL& origin,
73 const base::Callback<void(bool)>& callback); // NOLINT
74 void HideGeolocationPrompt(const GURL& origin);
75 void InvokeGeolocationCallback(JNIEnv* env,
81 JavaObjectWeakGlobalRef java_ref_;
82 // TODO(guangzhen): The WebContentsDelegate need to take ownership of
83 // WebContents as chrome content design. For xwalk, XWalkContent owns
84 // these two, we need to redesign XWalkContent in the future.
85 // Currently as a workaround, below declaration order makes sure
86 // the WebContents destructed before WebContentsDelegate.
87 scoped_ptr<XWalkWebContentsDelegate> web_contents_delegate_;
88 scoped_ptr<XWalkRenderViewHostExt> render_view_host_ext_;
89 scoped_ptr<XWalkContentsClientBridge> contents_client_bridge_;
90 scoped_ptr<content::WebContents> web_contents_;
91 scoped_ptr<XWalkContent> pending_contents_;
93 // GURL is supplied by the content layer as requesting frame.
94 // Callback is supplied by the content layer, and is invoked with the result
95 // from the permission prompt.
96 typedef std::pair<const GURL, const base::Callback<void(bool)> > /* NOLINT */ \
98 // The first element in the list is always the currently pending request.
99 std::list<OriginCallback> pending_geolocation_prompts_;
102 bool RegisterXWalkContent(JNIEnv* env);
106 #endif // XWALK_RUNTIME_BROWSER_ANDROID_XWALK_CONTENT_H_