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_array.h" | 8 #include "base/android/jni_array.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 jobject) const { | 229 jobject) const { |
230 return ConvertUTF8ToJavaString(env, | 230 return ConvertUTF8ToJavaString(env, |
231 web_contents_->GetLastCommittedURL().spec()); | 231 web_contents_->GetLastCommittedURL().spec()); |
232 } | 232 } |
233 | 233 |
234 | 234 |
235 jboolean WebContentsAndroid::IsIncognito(JNIEnv* env, jobject obj) { | 235 jboolean WebContentsAndroid::IsIncognito(JNIEnv* env, jobject obj) { |
236 return web_contents_->GetBrowserContext()->IsOffTheRecord(); | 236 return web_contents_->GetBrowserContext()->IsOffTheRecord(); |
237 } | 237 } |
238 | 238 |
239 void WebContentsAndroid::ResumeResponseDeferredAtStart(JNIEnv* env, | |
240 jobject obj) { | |
241 static_cast<WebContentsImpl*>(web_contents_)->ResumeResponseDeferredAtStart(); | |
242 } | |
243 | |
244 void WebContentsAndroid::ResumeLoadingCreatedWebContents(JNIEnv* env, | 239 void WebContentsAndroid::ResumeLoadingCreatedWebContents(JNIEnv* env, |
245 jobject obj) { | 240 jobject obj) { |
246 web_contents_->ResumeLoadingCreatedWebContents(); | 241 web_contents_->ResumeLoadingCreatedWebContents(); |
247 } | 242 } |
248 | 243 |
249 void WebContentsAndroid::SetHasPendingNavigationTransitionForTesting( | |
250 JNIEnv* env, | |
251 jobject obj) { | |
252 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
253 switches::kEnableExperimentalWebPlatformFeatures); | |
254 RenderFrameHost* frame = | |
255 static_cast<WebContentsImpl*>(web_contents_)->GetMainFrame(); | |
256 BrowserThread::PostTask( | |
257 BrowserThread::IO, | |
258 FROM_HERE, | |
259 base::Bind( | |
260 &TransitionRequestManager::AddPendingTransitionRequestDataForTesting, | |
261 base::Unretained(TransitionRequestManager::GetInstance()), | |
262 frame->GetProcess()->GetID(), | |
263 frame->GetRoutingID())); | |
264 } | |
265 | |
266 void WebContentsAndroid::SetupTransitionView(JNIEnv* env, | |
267 jobject jobj, | |
268 jstring markup) { | |
269 web_contents_->GetMainFrame()->Send(new FrameMsg_SetupTransitionView( | |
270 web_contents_->GetMainFrame()->GetRoutingID(), | |
271 ConvertJavaStringToUTF8(env, markup))); | |
272 } | |
273 | |
274 void WebContentsAndroid::BeginExitTransition(JNIEnv* env, | |
275 jobject jobj, | |
276 jstring css_selector, | |
277 jboolean exit_to_native_app) { | |
278 web_contents_->GetMainFrame()->Send(new FrameMsg_BeginExitTransition( | |
279 web_contents_->GetMainFrame()->GetRoutingID(), | |
280 ConvertJavaStringToUTF8(env, css_selector), | |
281 exit_to_native_app)); | |
282 } | |
283 | |
284 void WebContentsAndroid::RevertExitTransition(JNIEnv* env, | |
285 jobject jobj) { | |
286 web_contents_->GetMainFrame()->Send(new FrameMsg_RevertExitTransition( | |
287 web_contents_->GetMainFrame()->GetRoutingID())); | |
288 } | |
289 | |
290 void WebContentsAndroid::HideTransitionElements(JNIEnv* env, | |
291 jobject jobj, | |
292 jstring css_selector) { | |
293 web_contents_->GetMainFrame()->Send( | |
294 new FrameMsg_HideTransitionElements( | |
295 web_contents_->GetMainFrame()->GetRoutingID(), | |
296 ConvertJavaStringToUTF8(env, css_selector))); | |
297 } | |
298 | |
299 void WebContentsAndroid::ShowTransitionElements(JNIEnv* env, | |
300 jobject jobj, | |
301 jstring css_selector) { | |
302 web_contents_->GetMainFrame()->Send( | |
303 new FrameMsg_ShowTransitionElements( | |
304 web_contents_->GetMainFrame()->GetRoutingID(), | |
305 ConvertJavaStringToUTF8(env, css_selector))); | |
306 } | |
307 | |
308 | |
309 void WebContentsAndroid::ClearNavigationTransitionData(JNIEnv* env, | |
310 jobject jobj) { | |
311 static_cast<WebContentsImpl*>(web_contents_)->ClearNavigationTransitionData(); | |
312 } | |
313 | |
314 void WebContentsAndroid::FetchTransitionElements(JNIEnv* env, | |
315 jobject jobj, | |
316 jstring jurl) { | |
317 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); | |
318 RenderFrameHost* frame = web_contents_->GetMainFrame(); | |
319 | |
320 scoped_ptr<TransitionLayerData> transition_data(new TransitionLayerData()); | |
321 BrowserThread::PostTaskAndReplyWithResult( | |
322 BrowserThread::IO, | |
323 FROM_HERE, | |
324 base::Bind(&TransitionRequestManager::GetPendingTransitionRequest, | |
325 base::Unretained(TransitionRequestManager::GetInstance()), | |
326 frame->GetProcess()->GetID(), | |
327 frame->GetRoutingID(), | |
328 url, | |
329 transition_data.get()), | |
330 base::Bind(&WebContentsAndroid::OnTransitionElementsFetched, | |
331 weak_factory_.GetWeakPtr(), | |
332 base::Passed(&transition_data))); | |
333 } | |
334 | |
335 void WebContentsAndroid::OnTransitionElementsFetched( | |
336 scoped_ptr<const TransitionLayerData> transition_data, | |
337 bool has_transition_data) { | |
338 // FetchTransitionElements is called after the navigation transition state | |
339 // machine starts, which means there must be transition data. | |
340 DCHECK(has_transition_data); | |
341 JNIEnv* env = AttachCurrentThread(); | |
342 | |
343 std::vector<TransitionElement>::const_iterator it = | |
344 transition_data->elements.begin(); | |
345 for (; it != transition_data->elements.end(); ++it) { | |
346 ScopedJavaLocalRef<jstring> jstring_name(ConvertUTF8ToJavaString(env, | |
347 it->id)); | |
348 Java_WebContentsImpl_addNavigationTransitionElements( | |
349 env, obj_.obj(), jstring_name.obj(), | |
350 it->rect.x(), it->rect.y(), it->rect.width(), it->rect.height()); | |
351 } | |
352 | |
353 ScopedJavaLocalRef<jstring> jstring_css_selector( | |
354 ConvertUTF8ToJavaString(env, transition_data->css_selector)); | |
355 Java_WebContentsImpl_onTransitionElementsFetched( | |
356 env, obj_.obj(), jstring_css_selector.obj()); | |
357 } | |
358 | |
359 void WebContentsAndroid::OnHide(JNIEnv* env, jobject obj) { | 244 void WebContentsAndroid::OnHide(JNIEnv* env, jobject obj) { |
360 web_contents_->WasHidden(); | 245 web_contents_->WasHidden(); |
361 } | 246 } |
362 | 247 |
363 void WebContentsAndroid::OnShow(JNIEnv* env, jobject obj) { | 248 void WebContentsAndroid::OnShow(JNIEnv* env, jobject obj) { |
364 web_contents_->WasShown(); | 249 web_contents_->WasShown(); |
365 } | 250 } |
366 | 251 |
367 void WebContentsAndroid::ReleaseMediaPlayers(JNIEnv* env, jobject jobj) { | 252 void WebContentsAndroid::ReleaseMediaPlayers(JNIEnv* env, jobject jobj) { |
368 #if defined(ENABLE_BROWSER_CDMS) | 253 #if defined(ENABLE_BROWSER_CDMS) |
369 web_contents_->ForEachFrame( | 254 web_contents_->ForEachFrame( |
370 base::Bind(&ReleaseAllMediaPlayers, base::Unretained(web_contents_))); | 255 base::Bind(&ReleaseAllMediaPlayers, base::Unretained(web_contents_))); |
371 #endif // defined(ENABLE_BROWSER_CDMS) | 256 #endif // defined(ENABLE_BROWSER_CDMS) |
372 } | 257 } |
373 | 258 |
374 void WebContentsAndroid::AddStyleSheetByURL( | |
375 JNIEnv* env, | |
376 jobject obj, | |
377 jstring url) { | |
378 web_contents_->GetMainFrame()->Send(new FrameMsg_AddStyleSheetByURL( | |
379 web_contents_->GetMainFrame()->GetRoutingID(), | |
380 ConvertJavaStringToUTF8(env, url))); | |
381 } | |
382 | |
383 void WebContentsAndroid::ShowInterstitialPage( | 259 void WebContentsAndroid::ShowInterstitialPage( |
384 JNIEnv* env, | 260 JNIEnv* env, |
385 jobject obj, | 261 jobject obj, |
386 jstring jurl, | 262 jstring jurl, |
387 jlong delegate_ptr) { | 263 jlong delegate_ptr) { |
388 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); | 264 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); |
389 InterstitialPageDelegateAndroid* delegate = | 265 InterstitialPageDelegateAndroid* delegate = |
390 reinterpret_cast<InterstitialPageDelegateAndroid*>(delegate_ptr); | 266 reinterpret_cast<InterstitialPageDelegateAndroid*>(delegate_ptr); |
391 InterstitialPage* interstitial = InterstitialPage::Create( | 267 InterstitialPage* interstitial = InterstitialPage::Create( |
392 web_contents_, false, url, delegate); | 268 web_contents_, false, url, delegate); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 host->GetRoutingID(), gfx::Rect())); | 318 host->GetRoutingID(), gfx::Rect())); |
443 } | 319 } |
444 | 320 |
445 void WebContentsAndroid::SelectWordAroundCaret(JNIEnv* env, jobject obj) { | 321 void WebContentsAndroid::SelectWordAroundCaret(JNIEnv* env, jobject obj) { |
446 RenderViewHost* host = web_contents_->GetRenderViewHost(); | 322 RenderViewHost* host = web_contents_->GetRenderViewHost(); |
447 if (!host) | 323 if (!host) |
448 return; | 324 return; |
449 host->SelectWordAroundCaret(); | 325 host->SelectWordAroundCaret(); |
450 } | 326 } |
451 | 327 |
452 bool WebContentsAndroid::WillHandleDeferAfterResponseStarted() { | |
453 JNIEnv* env = AttachCurrentThread(); | |
454 return Java_WebContentsImpl_willHandleDeferAfterResponseStarted(env, | |
455 obj_.obj()); | |
456 } | |
457 | |
458 void WebContentsAndroid::DidDeferAfterResponseStarted( | |
459 const TransitionLayerData& transition_data) { | |
460 JNIEnv* env = AttachCurrentThread(); | |
461 std::vector<GURL> entering_stylesheets; | |
462 std::string transition_color; | |
463 if (transition_data.response_headers.get()) { | |
464 TransitionRequestManager::ParseTransitionStylesheetsFromHeaders( | |
465 transition_data.response_headers, | |
466 entering_stylesheets, | |
467 transition_data.request_url); | |
468 | |
469 transition_data.response_headers->EnumerateHeader( | |
470 NULL, "X-Transition-Entering-Color", &transition_color); | |
471 } | |
472 | |
473 ScopedJavaLocalRef<jstring> jstring_markup( | |
474 ConvertUTF8ToJavaString(env, transition_data.markup)); | |
475 | |
476 ScopedJavaLocalRef<jstring> jstring_css_selector( | |
477 ConvertUTF8ToJavaString(env, transition_data.css_selector)); | |
478 | |
479 ScopedJavaLocalRef<jstring> jstring_transition_color( | |
480 ConvertUTF8ToJavaString(env, transition_color)); | |
481 | |
482 Java_WebContentsImpl_didDeferAfterResponseStarted( | |
483 env, | |
484 obj_.obj(), | |
485 jstring_markup.obj(), | |
486 jstring_css_selector.obj(), | |
487 jstring_transition_color.obj()); | |
488 | |
489 std::vector<GURL>::const_iterator iter = entering_stylesheets.begin(); | |
490 for (; iter != entering_stylesheets.end(); ++iter) { | |
491 ScopedJavaLocalRef<jstring> jstring_url( | |
492 ConvertUTF8ToJavaString(env, iter->spec())); | |
493 Java_WebContentsImpl_addEnteringStylesheetToTransition( | |
494 env, obj_.obj(), jstring_url.obj()); | |
495 } | |
496 } | |
497 | |
498 void WebContentsAndroid::DidStartNavigationTransitionForFrame(int64 frame_id) { | |
499 JNIEnv* env = AttachCurrentThread(); | |
500 Java_WebContentsImpl_didStartNavigationTransitionForFrame( | |
501 env, obj_.obj(), frame_id); | |
502 } | |
503 | |
504 void WebContentsAndroid::EvaluateJavaScript(JNIEnv* env, | 328 void WebContentsAndroid::EvaluateJavaScript(JNIEnv* env, |
505 jobject obj, | 329 jobject obj, |
506 jstring script, | 330 jstring script, |
507 jobject callback) { | 331 jobject callback) { |
508 RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | 332 RenderViewHost* rvh = web_contents_->GetRenderViewHost(); |
509 DCHECK(rvh); | 333 DCHECK(rvh); |
510 | 334 |
511 if (!rvh->IsRenderViewLive()) { | 335 if (!rvh->IsRenderViewLive()) { |
512 if (!static_cast<WebContentsImpl*>(web_contents_)-> | 336 if (!static_cast<WebContentsImpl*>(web_contents_)-> |
513 CreateRenderViewForInitialEmptyDocument()) { | 337 CreateRenderViewForInitialEmptyDocument()) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 ScopedJavaGlobalRef<jobject> j_callback; | 390 ScopedJavaGlobalRef<jobject> j_callback; |
567 j_callback.Reset(env, callback); | 391 j_callback.Reset(env, callback); |
568 WebContentsImpl::AXTreeSnapshotCallback snapshot_callback = | 392 WebContentsImpl::AXTreeSnapshotCallback snapshot_callback = |
569 base::Bind(&AXTreeSnapshotCallback, j_callback); | 393 base::Bind(&AXTreeSnapshotCallback, j_callback); |
570 | 394 |
571 static_cast<WebContentsImpl*>(web_contents_)->RequestAXTreeSnapshot( | 395 static_cast<WebContentsImpl*>(web_contents_)->RequestAXTreeSnapshot( |
572 snapshot_callback); | 396 snapshot_callback); |
573 } | 397 } |
574 | 398 |
575 } // namespace content | 399 } // namespace content |
OLD | NEW |