Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: content/browser/web_contents/web_contents_android.cc

Issue 414423002: Removing ContentViewCore dependencies from few functions which acts as direct wrapper to WebContents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/web_contents/web_contents_android.h" 5 #include "content/browser/web_contents/web_contents_android.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "content/browser/android/interstitial_page_delegate_android.h" 10 #include "content/browser/android/interstitial_page_delegate_android.h"
11 #include "content/browser/frame_host/interstitial_page_impl.h" 11 #include "content/browser/frame_host/interstitial_page_impl.h"
12 #include "content/browser/media/media_web_contents_observer.h" 12 #include "content/browser/media/media_web_contents_observer.h"
13 #include "content/browser/renderer_host/render_view_host_impl.h" 13 #include "content/browser/renderer_host/render_view_host_impl.h"
14 #include "content/browser/transition_request_manager.h"
15 #include "content/browser/web_contents/web_contents_impl.h"
14 #include "content/common/frame_messages.h" 16 #include "content/common/frame_messages.h"
15 #include "content/common/input_messages.h" 17 #include "content/common/input_messages.h"
16 #include "content/common/view_messages.h" 18 #include "content/common/view_messages.h"
19 #include "content/public/browser/browser_context.h"
17 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
19 #include "jni/WebContentsImpl_jni.h" 22 #include "jni/WebContentsImpl_jni.h"
20 23
21 using base::android::AttachCurrentThread; 24 using base::android::AttachCurrentThread;
22 using base::android::ConvertJavaStringToUTF8; 25 using base::android::ConvertJavaStringToUTF8;
26 using base::android::ConvertUTF8ToJavaString;
23 27
24 namespace content { 28 namespace content {
25 29
26 // static 30 // static
27 WebContents* WebContents::FromJavaWebContents( 31 WebContents* WebContents::FromJavaWebContents(
28 jobject jweb_contents_android) { 32 jobject jweb_contents_android) {
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
30 if (!jweb_contents_android) 34 if (!jweb_contents_android)
31 return NULL; 35 return NULL;
32 36
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); 101 return static_cast<RenderWidgetHostViewAndroid*>(rwhv);
98 } 102 }
99 103
100 jint WebContentsAndroid::GetBackgroundColor(JNIEnv* env, jobject obj) { 104 jint WebContentsAndroid::GetBackgroundColor(JNIEnv* env, jobject obj) {
101 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); 105 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid();
102 if (!rwhva) 106 if (!rwhva)
103 return SK_ColorWHITE; 107 return SK_ColorWHITE;
104 return rwhva->GetCachedBackgroundColor(); 108 return rwhva->GetCachedBackgroundColor();
105 } 109 }
106 110
111 ScopedJavaLocalRef<jstring> WebContentsAndroid::GetURL(
112 JNIEnv* env,
113 jobject obj) const {
114 return ConvertUTF8ToJavaString(env, web_contents_->GetURL().spec());
115 }
116
117 jboolean WebContentsAndroid::IsIncognito(JNIEnv* env, jobject obj) {
118 return web_contents_->GetBrowserContext()->IsOffTheRecord();
119 }
120
121 void WebContentsAndroid::SelectPopupMenuItems(
122 JNIEnv* env,
123 jobject obj,
124 jintArray indices) {
125 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(
126 web_contents_->GetRenderViewHost());
127 DCHECK(rvhi);
128 if (indices == NULL) {
129 rvhi->DidCancelPopupMenu();
130 return;
131 }
132
133 int selected_count = env->GetArrayLength(indices);
134 std::vector<int> selected_indices;
135 jint* indices_ptr = env->GetIntArrayElements(indices, NULL);
136 for (int i = 0; i < selected_count; ++i)
137 selected_indices.push_back(indices_ptr[i]);
138 env->ReleaseIntArrayElements(indices, indices_ptr, JNI_ABORT);
139 rvhi->DidSelectPopupMenuItems(selected_indices);
140 }
141
142 void WebContentsAndroid::HideTextHandles(JNIEnv* env, jobject obj) {
143 if (GetRenderWidgetHostViewAndroid())
144 GetRenderWidgetHostViewAndroid()->HideTextHandles();
145 }
146
147 void WebContentsAndroid::ResetGestureDetection(JNIEnv* env, jobject obj) {
148 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
149 if (rwhv)
150 rwhv->ResetGestureDetection();
151 }
152
153 void WebContentsAndroid::SetDoubleTapSupportEnabled(
154 JNIEnv* env,
155 jobject obj,
156 jboolean enabled) {
157 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
158 if (rwhv)
159 rwhv->SetDoubleTapSupportEnabled(enabled);
160 }
161
162 void WebContentsAndroid::SetMultiTouchZoomSupportEnabled(
163 JNIEnv* env,
164 jobject obj,
165 jboolean enabled) {
166 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
167 if (rwhv)
168 rwhv->SetMultiTouchZoomSupportEnabled(enabled);
169 }
170
171 void WebContentsAndroid::ResumeResponseDeferredAtStart(
172 JNIEnv* env,
173 jobject obj) {
174 static_cast<WebContentsImpl*>(web_contents_)->
175 ResumeResponseDeferredAtStart();
176 }
177
178 void WebContentsAndroid::SetHasPendingNavigationTransitionForTesting(
179 JNIEnv* env,
180 jobject obj) {
181 RenderFrameHost* frame = static_cast<WebContentsImpl*>(web_contents_)->
182 GetMainFrame();
183 BrowserThread::PostTask(
184 BrowserThread::IO,
185 FROM_HERE,
186 base::Bind(
187 &TransitionRequestManager::SetHasPendingTransitionRequest,
188 base::Unretained(TransitionRequestManager::GetInstance()),
189 frame->GetProcess()->GetID(),
190 frame->GetRoutingID(),
191 true));
192 }
193
194 void WebContentsAndroid::SetBackgroundOpaque(
195 JNIEnv* env,
196 jobject jobj,
197 jboolean opaque) {
198 if (GetRenderWidgetHostViewAndroid())
199 GetRenderWidgetHostViewAndroid()->SetBackgroundOpaque(opaque);
200 }
201
202 void WebContentsAndroid::RequestTextSurroundingSelection(
203 int max_length,
204 const base::Callback<
205 void(
206 const base::string16& content,
207 int start_offset,
208 int end_offset)>& callback) {
209 DCHECK(!callback.is_null());
210 RenderFrameHost* focused_frame = web_contents_->GetFocusedFrame();
211 if (!focused_frame)
212 return;
213 if (GetRenderWidgetHostViewAndroid()) {
214 GetRenderWidgetHostViewAndroid()->SetTextSurroundingSelectionCallback(
215 callback);
216 focused_frame->Send(new FrameMsg_TextSurroundingSelectionRequest(
217 focused_frame->GetRoutingID(), max_length));
218 }
219 }
220
107 void WebContentsAndroid::OnHide(JNIEnv* env, jobject obj) { 221 void WebContentsAndroid::OnHide(JNIEnv* env, jobject obj) {
108 web_contents_->WasHidden(); 222 web_contents_->WasHidden();
109 PauseVideo(); 223 PauseVideo();
110 } 224 }
111 225
112 void WebContentsAndroid::OnShow(JNIEnv* env, jobject obj) { 226 void WebContentsAndroid::OnShow(JNIEnv* env, jobject obj) {
113 web_contents_->WasShown(); 227 web_contents_->WasShown();
114 } 228 }
115 229
116 void WebContentsAndroid::PauseVideo() { 230 void WebContentsAndroid::PauseVideo() {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 309 }
196 310
197 void WebContentsAndroid::SelectWordAroundCaret(JNIEnv* env, jobject obj) { 311 void WebContentsAndroid::SelectWordAroundCaret(JNIEnv* env, jobject obj) {
198 RenderViewHost* host = web_contents_->GetRenderViewHost(); 312 RenderViewHost* host = web_contents_->GetRenderViewHost();
199 if (!host) 313 if (!host)
200 return; 314 return;
201 host->SelectWordAroundCaret(); 315 host->SelectWordAroundCaret();
202 } 316 }
203 317
204 } // namespace content 318 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698