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