Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / browser / web_contents / web_contents_android.h
blobaea90fb67e9f387568c98a2f33ad6bbca226a259
1 // Copyright 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.
5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_ANDROID_H_
6 #define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_ANDROID_H_
8 #include <jni.h>
10 #include "base/android/scoped_java_ref.h"
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/supports_user_data.h"
16 #include "content/browser/frame_host/navigation_controller_android.h"
17 #include "content/browser/renderer_host/render_widget_host_view_android.h"
18 #include "content/browser/transition_request_manager.h"
19 #include "content/common/content_export.h"
21 namespace content {
23 class WebContents;
24 struct TransitionLayerData;
26 // Android wrapper around WebContents that provides safer passage from java and
27 // back to native and provides java with a means of communicating with its
28 // native counterpart.
29 class CONTENT_EXPORT WebContentsAndroid
30 : public base::SupportsUserData::Data {
31 public:
32 static bool Register(JNIEnv* env);
34 explicit WebContentsAndroid(WebContents* web_contents);
35 ~WebContentsAndroid() override;
37 WebContents* web_contents() const { return web_contents_; }
39 base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
41 // Methods called from Java
42 base::android::ScopedJavaLocalRef<jstring> GetTitle(JNIEnv* env,
43 jobject obj) const;
44 base::android::ScopedJavaLocalRef<jstring> GetVisibleURL(JNIEnv* env,
45 jobject obj) const;
47 bool IsLoading(JNIEnv* env, jobject obj) const;
48 bool IsLoadingToDifferentDocument(JNIEnv* env, jobject obj) const;
50 void Stop(JNIEnv* env, jobject obj);
51 jint GetBackgroundColor(JNIEnv* env, jobject obj);
52 base::android::ScopedJavaLocalRef<jstring> GetURL(JNIEnv* env, jobject) const;
53 base::android::ScopedJavaLocalRef<jstring> GetLastCommittedURL(JNIEnv* env,
54 jobject) const;
55 jboolean IsIncognito(JNIEnv* env, jobject obj);
57 void ResumeResponseDeferredAtStart(JNIEnv* env, jobject obj);
58 void SetHasPendingNavigationTransitionForTesting(JNIEnv* env, jobject obj);
59 void SetupTransitionView(JNIEnv* env, jobject jobj, jstring markup);
60 void BeginExitTransition(JNIEnv* env, jobject jobj, jstring css_selector,
61 jboolean exit_to_native_app);
62 void RevertExitTransition(JNIEnv* env, jobject jobj);
63 void HideTransitionElements(JNIEnv* env, jobject jobj, jstring css_selector);
64 void ShowTransitionElements(JNIEnv* env, jobject jobj, jstring css_selector);
65 void ClearNavigationTransitionData(JNIEnv* env, jobject jobj);
66 void FetchTransitionElements(JNIEnv* env, jobject jobj, jstring jurl);
67 void OnTransitionElementsFetched(
68 scoped_ptr<const TransitionLayerData> transition_data,
69 bool has_transition_data);
71 // This method is invoked when the request is deferred immediately after
72 // receiving response headers.
73 void DidDeferAfterResponseStarted(const TransitionLayerData& transition_data);
75 // This method is invoked when a navigation transition is detected, to
76 // determine if the embedder intends to handle it.
77 bool WillHandleDeferAfterResponseStarted();
79 // This method is invoked when a navigation transition has started.
80 void DidStartNavigationTransitionForFrame(int64 frame_id);
82 void OnHide(JNIEnv* env, jobject obj);
83 void OnShow(JNIEnv* env, jobject obj);
84 void ReleaseMediaPlayers(JNIEnv* env, jobject jobj);
86 void AddStyleSheetByURL(
87 JNIEnv* env, jobject obj, jstring url);
88 void ShowInterstitialPage(
89 JNIEnv* env, jobject obj, jstring jurl, jlong delegate_ptr);
90 jboolean IsShowingInterstitialPage(JNIEnv* env, jobject obj);
91 jboolean IsRenderWidgetHostViewReady(JNIEnv* env, jobject obj);
92 void ExitFullscreen(JNIEnv* env, jobject obj);
93 void UpdateTopControlsState(
94 JNIEnv* env,
95 jobject obj,
96 bool enable_hiding,
97 bool enable_showing,
98 bool animate);
99 void ShowImeIfNeeded(JNIEnv* env, jobject obj);
100 void ScrollFocusedEditableNodeIntoView(JNIEnv* env, jobject obj);
101 void SelectWordAroundCaret(JNIEnv* env, jobject obj);
103 void InsertCSS(JNIEnv* env, jobject jobj, jstring jcss);
104 void EvaluateJavaScript(JNIEnv* env,
105 jobject obj,
106 jstring script,
107 jobject callback);
109 void AddMessageToDevToolsConsole(JNIEnv* env,
110 jobject jobj,
111 jint level,
112 jstring message);
114 jboolean HasAccessedInitialDocument(JNIEnv* env, jobject jobj);
116 jint GetThemeColor(JNIEnv* env, jobject obj);
118 private:
119 RenderWidgetHostViewAndroid* GetRenderWidgetHostViewAndroid();
121 WebContents* web_contents_;
122 NavigationControllerAndroid navigation_controller_;
123 base::android::ScopedJavaGlobalRef<jobject> obj_;
125 base::WeakPtrFactory<WebContentsAndroid> weak_factory_;
127 DISALLOW_COPY_AND_ASSIGN(WebContentsAndroid);
130 } // namespace content
132 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_ANDROID_H_