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

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: Formatted native file changes to correct inclusion order. Created 6 years, 4 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(JNIEnv* env,
112 jobject obj) const {
113 return ConvertUTF8ToJavaString(env, web_contents_->GetURL().spec());
114 }
115
116 jboolean WebContentsAndroid::IsIncognito(JNIEnv* env, jobject obj) {
117 return web_contents_->GetBrowserContext()->IsOffTheRecord();
118 }
119
120 void WebContentsAndroid::ResumeResponseDeferredAtStart(JNIEnv* env,
121 jobject obj) {
122 static_cast<WebContentsImpl*>(web_contents_)->ResumeResponseDeferredAtStart();
123 }
124
125 void WebContentsAndroid::SetHasPendingNavigationTransitionForTesting(
126 JNIEnv* env,
127 jobject obj) {
128 RenderFrameHost* frame =
129 static_cast<WebContentsImpl*>(web_contents_)->GetMainFrame();
130 BrowserThread::PostTask(
131 BrowserThread::IO,
132 FROM_HERE,
133 base::Bind(&TransitionRequestManager::SetHasPendingTransitionRequest,
134 base::Unretained(TransitionRequestManager::GetInstance()),
135 frame->GetProcess()->GetID(),
136 frame->GetRoutingID(),
137 true));
138 }
139
107 void WebContentsAndroid::OnHide(JNIEnv* env, jobject obj) { 140 void WebContentsAndroid::OnHide(JNIEnv* env, jobject obj) {
108 web_contents_->WasHidden(); 141 web_contents_->WasHidden();
109 PauseVideo(); 142 PauseVideo();
110 } 143 }
111 144
112 void WebContentsAndroid::OnShow(JNIEnv* env, jobject obj) { 145 void WebContentsAndroid::OnShow(JNIEnv* env, jobject obj) {
113 web_contents_->WasShown(); 146 web_contents_->WasShown();
114 } 147 }
115 148
116 void WebContentsAndroid::PauseVideo() { 149 void WebContentsAndroid::PauseVideo() {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 host->GetRoutingID(), gfx::Rect())); 227 host->GetRoutingID(), gfx::Rect()));
195 } 228 }
196 229
197 void WebContentsAndroid::SelectWordAroundCaret(JNIEnv* env, jobject obj) { 230 void WebContentsAndroid::SelectWordAroundCaret(JNIEnv* env, jobject obj) {
198 RenderViewHost* host = web_contents_->GetRenderViewHost(); 231 RenderViewHost* host = web_contents_->GetRenderViewHost();
199 if (!host) 232 if (!host)
200 return; 233 return;
201 host->SelectWordAroundCaret(); 234 host->SelectWordAroundCaret();
202 } 235 }
203 236
237 bool WebContentsAndroid::WillHandleDeferAfterResponseStarted() {
238 JNIEnv* env = AttachCurrentThread();
239 return Java_WebContentsImpl_willHandleDeferAfterResponseStarted(env,
240 obj_.obj());
241 }
242
243 void WebContentsAndroid::DidDeferAfterResponseStarted(
244 const scoped_refptr<net::HttpResponseHeaders>& headers,
245 const GURL& url) {
246 JNIEnv* env = AttachCurrentThread();
247
248 std::vector<GURL> entering_stylesheets;
249 std::string transition_color;
250 if (headers) {
251 TransitionRequestManager::ParseTransitionStylesheetsFromHeaders(
252 headers, entering_stylesheets, url);
253
254 headers->EnumerateHeader(
255 NULL, "X-Transition-Entering-Color", &transition_color);
256 }
257
258 ScopedJavaLocalRef<jstring> jstring_transition_color(
259 ConvertUTF8ToJavaString(env, transition_color));
260
261 Java_WebContentsImpl_didDeferAfterResponseStarted(
262 env, obj_.obj(), jstring_transition_color.obj());
263
264 std::vector<GURL>::const_iterator iter = entering_stylesheets.begin();
265 for (; iter != entering_stylesheets.end(); ++iter) {
266 ScopedJavaLocalRef<jstring> jstring_url(
267 ConvertUTF8ToJavaString(env, iter->spec()));
268 Java_WebContentsImpl_addEnteringStylesheetToTransition(
269 env, obj_.obj(), jstring_url.obj());
270 }
271 }
272
273 void WebContentsAndroid::DidStartNavigationTransitionForFrame(int64 frame_id) {
274 JNIEnv* env = AttachCurrentThread();
275 Java_WebContentsImpl_didStartNavigationTransitionForFrame(
276 env, obj_.obj(), frame_id);
277 }
278
204 } // namespace content 279 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698