| 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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 g_allocated_web_contents_androids.Get().erase(this); | 274 g_allocated_web_contents_androids.Get().erase(this); |
| 275 Java_WebContentsImpl_clearNativePtr(AttachCurrentThread(), obj_.obj()); | 275 Java_WebContentsImpl_clearNativePtr(AttachCurrentThread(), obj_.obj()); |
| 276 } | 276 } |
| 277 | 277 |
| 278 base::android::ScopedJavaLocalRef<jobject> | 278 base::android::ScopedJavaLocalRef<jobject> |
| 279 WebContentsAndroid::GetJavaObject() { | 279 WebContentsAndroid::GetJavaObject() { |
| 280 return base::android::ScopedJavaLocalRef<jobject>(obj_); | 280 return base::android::ScopedJavaLocalRef<jobject>(obj_); |
| 281 } | 281 } |
| 282 | 282 |
| 283 ScopedJavaLocalRef<jstring> WebContentsAndroid::GetTitle( | 283 ScopedJavaLocalRef<jstring> WebContentsAndroid::GetTitle( |
| 284 JNIEnv* env, jobject obj) const { | 284 JNIEnv* env, |
| 285 const JavaParamRef<jobject>& obj) const { |
| 285 return base::android::ConvertUTF16ToJavaString(env, | 286 return base::android::ConvertUTF16ToJavaString(env, |
| 286 web_contents_->GetTitle()); | 287 web_contents_->GetTitle()); |
| 287 } | 288 } |
| 288 | 289 |
| 289 ScopedJavaLocalRef<jstring> WebContentsAndroid::GetVisibleURL( | 290 ScopedJavaLocalRef<jstring> WebContentsAndroid::GetVisibleURL( |
| 290 JNIEnv* env, jobject obj) const { | 291 JNIEnv* env, |
| 292 const JavaParamRef<jobject>& obj) const { |
| 291 return base::android::ConvertUTF8ToJavaString( | 293 return base::android::ConvertUTF8ToJavaString( |
| 292 env, web_contents_->GetVisibleURL().spec()); | 294 env, web_contents_->GetVisibleURL().spec()); |
| 293 } | 295 } |
| 294 | 296 |
| 295 bool WebContentsAndroid::IsLoading(JNIEnv* env, jobject obj) const { | 297 bool WebContentsAndroid::IsLoading(JNIEnv* env, |
| 298 const JavaParamRef<jobject>& obj) const { |
| 296 return web_contents_->IsLoading(); | 299 return web_contents_->IsLoading(); |
| 297 } | 300 } |
| 298 | 301 |
| 299 bool WebContentsAndroid::IsLoadingToDifferentDocument(JNIEnv* env, | 302 bool WebContentsAndroid::IsLoadingToDifferentDocument( |
| 300 jobject obj) const { | 303 JNIEnv* env, |
| 304 const JavaParamRef<jobject>& obj) const { |
| 301 return web_contents_->IsLoadingToDifferentDocument(); | 305 return web_contents_->IsLoadingToDifferentDocument(); |
| 302 } | 306 } |
| 303 | 307 |
| 304 void WebContentsAndroid::Stop(JNIEnv* env, jobject obj) { | 308 void WebContentsAndroid::Stop(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 305 web_contents_->Stop(); | 309 web_contents_->Stop(); |
| 306 } | 310 } |
| 307 | 311 |
| 308 void WebContentsAndroid::Cut(JNIEnv* env, jobject obj) { | 312 void WebContentsAndroid::Cut(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 309 web_contents_->Cut(); | 313 web_contents_->Cut(); |
| 310 } | 314 } |
| 311 | 315 |
| 312 void WebContentsAndroid::Copy(JNIEnv* env, jobject obj) { | 316 void WebContentsAndroid::Copy(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 313 web_contents_->Copy(); | 317 web_contents_->Copy(); |
| 314 } | 318 } |
| 315 | 319 |
| 316 void WebContentsAndroid::Paste(JNIEnv* env, jobject obj) { | 320 void WebContentsAndroid::Paste(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 317 web_contents_->Paste(); | 321 web_contents_->Paste(); |
| 318 } | 322 } |
| 319 | 323 |
| 320 void WebContentsAndroid::Replace(JNIEnv* env, jobject obj, jstring jstr) { | 324 void WebContentsAndroid::Replace(JNIEnv* env, |
| 325 const JavaParamRef<jobject>& obj, |
| 326 const JavaParamRef<jstring>& jstr) { |
| 321 web_contents_->Replace(base::android::ConvertJavaStringToUTF16(env, jstr)); | 327 web_contents_->Replace(base::android::ConvertJavaStringToUTF16(env, jstr)); |
| 322 } | 328 } |
| 323 | 329 |
| 324 void WebContentsAndroid::SelectAll(JNIEnv* env, jobject obj) { | 330 void WebContentsAndroid::SelectAll(JNIEnv* env, |
| 331 const JavaParamRef<jobject>& obj) { |
| 325 web_contents_->SelectAll(); | 332 web_contents_->SelectAll(); |
| 326 } | 333 } |
| 327 | 334 |
| 328 void WebContentsAndroid::Unselect(JNIEnv* env, jobject obj) { | 335 void WebContentsAndroid::Unselect(JNIEnv* env, |
| 336 const JavaParamRef<jobject>& obj) { |
| 329 web_contents_->Unselect(); | 337 web_contents_->Unselect(); |
| 330 } | 338 } |
| 331 | 339 |
| 332 void WebContentsAndroid::InsertCSS( | 340 void WebContentsAndroid::InsertCSS(JNIEnv* env, |
| 333 JNIEnv* env, jobject jobj, jstring jcss) { | 341 const JavaParamRef<jobject>& jobj, |
| 342 const JavaParamRef<jstring>& jcss) { |
| 334 web_contents_->InsertCSS(base::android::ConvertJavaStringToUTF8(env, jcss)); | 343 web_contents_->InsertCSS(base::android::ConvertJavaStringToUTF8(env, jcss)); |
| 335 } | 344 } |
| 336 | 345 |
| 337 RenderWidgetHostViewAndroid* | 346 RenderWidgetHostViewAndroid* |
| 338 WebContentsAndroid::GetRenderWidgetHostViewAndroid() { | 347 WebContentsAndroid::GetRenderWidgetHostViewAndroid() { |
| 339 RenderWidgetHostView* rwhv = NULL; | 348 RenderWidgetHostView* rwhv = NULL; |
| 340 rwhv = web_contents_->GetRenderWidgetHostView(); | 349 rwhv = web_contents_->GetRenderWidgetHostView(); |
| 341 if (web_contents_->ShowingInterstitialPage()) { | 350 if (web_contents_->ShowingInterstitialPage()) { |
| 342 rwhv = web_contents_->GetInterstitialPage() | 351 rwhv = web_contents_->GetInterstitialPage() |
| 343 ->GetMainFrame() | 352 ->GetMainFrame() |
| 344 ->GetRenderViewHost() | 353 ->GetRenderViewHost() |
| 345 ->GetWidget() | 354 ->GetWidget() |
| 346 ->GetView(); | 355 ->GetView(); |
| 347 } | 356 } |
| 348 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); | 357 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); |
| 349 } | 358 } |
| 350 | 359 |
| 351 jint WebContentsAndroid::GetBackgroundColor(JNIEnv* env, jobject obj) { | 360 jint WebContentsAndroid::GetBackgroundColor(JNIEnv* env, |
| 361 const JavaParamRef<jobject>& obj) { |
| 352 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | 362 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
| 353 if (!rwhva) | 363 if (!rwhva) |
| 354 return SK_ColorWHITE; | 364 return SK_ColorWHITE; |
| 355 return rwhva->GetCachedBackgroundColor(); | 365 return rwhva->GetCachedBackgroundColor(); |
| 356 } | 366 } |
| 357 | 367 |
| 358 ScopedJavaLocalRef<jstring> WebContentsAndroid::GetURL(JNIEnv* env, | 368 ScopedJavaLocalRef<jstring> WebContentsAndroid::GetURL( |
| 359 jobject obj) const { | 369 JNIEnv* env, |
| 370 const JavaParamRef<jobject>& obj) const { |
| 360 return ConvertUTF8ToJavaString(env, web_contents_->GetURL().spec()); | 371 return ConvertUTF8ToJavaString(env, web_contents_->GetURL().spec()); |
| 361 } | 372 } |
| 362 | 373 |
| 363 ScopedJavaLocalRef<jstring> WebContentsAndroid::GetLastCommittedURL( | 374 ScopedJavaLocalRef<jstring> WebContentsAndroid::GetLastCommittedURL( |
| 364 JNIEnv* env, | 375 JNIEnv* env, |
| 365 jobject) const { | 376 const JavaParamRef<jobject>&) const { |
| 366 return ConvertUTF8ToJavaString(env, | 377 return ConvertUTF8ToJavaString(env, |
| 367 web_contents_->GetLastCommittedURL().spec()); | 378 web_contents_->GetLastCommittedURL().spec()); |
| 368 } | 379 } |
| 369 | 380 |
| 370 | 381 jboolean WebContentsAndroid::IsIncognito(JNIEnv* env, |
| 371 jboolean WebContentsAndroid::IsIncognito(JNIEnv* env, jobject obj) { | 382 const JavaParamRef<jobject>& obj) { |
| 372 return web_contents_->GetBrowserContext()->IsOffTheRecord(); | 383 return web_contents_->GetBrowserContext()->IsOffTheRecord(); |
| 373 } | 384 } |
| 374 | 385 |
| 375 void WebContentsAndroid::ResumeLoadingCreatedWebContents(JNIEnv* env, | 386 void WebContentsAndroid::ResumeLoadingCreatedWebContents( |
| 376 jobject obj) { | 387 JNIEnv* env, |
| 388 const JavaParamRef<jobject>& obj) { |
| 377 web_contents_->ResumeLoadingCreatedWebContents(); | 389 web_contents_->ResumeLoadingCreatedWebContents(); |
| 378 } | 390 } |
| 379 | 391 |
| 380 void WebContentsAndroid::OnHide(JNIEnv* env, jobject obj) { | 392 void WebContentsAndroid::OnHide(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 381 web_contents_->WasHidden(); | 393 web_contents_->WasHidden(); |
| 382 } | 394 } |
| 383 | 395 |
| 384 void WebContentsAndroid::OnShow(JNIEnv* env, jobject obj) { | 396 void WebContentsAndroid::OnShow(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 385 web_contents_->WasShown(); | 397 web_contents_->WasShown(); |
| 386 } | 398 } |
| 387 | 399 |
| 388 void WebContentsAndroid::ReleaseMediaPlayers(JNIEnv* env, jobject jobj) { | 400 void WebContentsAndroid::ReleaseMediaPlayers( |
| 401 JNIEnv* env, |
| 402 const JavaParamRef<jobject>& jobj) { |
| 389 #if defined(ENABLE_BROWSER_CDMS) | 403 #if defined(ENABLE_BROWSER_CDMS) |
| 390 web_contents_->ForEachFrame( | 404 web_contents_->ForEachFrame( |
| 391 base::Bind(&ReleaseAllMediaPlayers, base::Unretained(web_contents_))); | 405 base::Bind(&ReleaseAllMediaPlayers, base::Unretained(web_contents_))); |
| 392 #endif // defined(ENABLE_BROWSER_CDMS) | 406 #endif // defined(ENABLE_BROWSER_CDMS) |
| 393 } | 407 } |
| 394 | 408 |
| 395 void WebContentsAndroid::ShowInterstitialPage( | 409 void WebContentsAndroid::ShowInterstitialPage(JNIEnv* env, |
| 396 JNIEnv* env, | 410 const JavaParamRef<jobject>& obj, |
| 397 jobject obj, | 411 const JavaParamRef<jstring>& jurl, |
| 398 jstring jurl, | 412 jlong delegate_ptr) { |
| 399 jlong delegate_ptr) { | |
| 400 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); | 413 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); |
| 401 InterstitialPageDelegateAndroid* delegate = | 414 InterstitialPageDelegateAndroid* delegate = |
| 402 reinterpret_cast<InterstitialPageDelegateAndroid*>(delegate_ptr); | 415 reinterpret_cast<InterstitialPageDelegateAndroid*>(delegate_ptr); |
| 403 InterstitialPage* interstitial = InterstitialPage::Create( | 416 InterstitialPage* interstitial = InterstitialPage::Create( |
| 404 web_contents_, false, url, delegate); | 417 web_contents_, false, url, delegate); |
| 405 delegate->set_interstitial_page(interstitial); | 418 delegate->set_interstitial_page(interstitial); |
| 406 interstitial->Show(); | 419 interstitial->Show(); |
| 407 } | 420 } |
| 408 | 421 |
| 409 jboolean WebContentsAndroid::IsShowingInterstitialPage(JNIEnv* env, | 422 jboolean WebContentsAndroid::IsShowingInterstitialPage( |
| 410 jobject obj) { | 423 JNIEnv* env, |
| 424 const JavaParamRef<jobject>& obj) { |
| 411 return web_contents_->ShowingInterstitialPage(); | 425 return web_contents_->ShowingInterstitialPage(); |
| 412 } | 426 } |
| 413 | 427 |
| 414 jboolean WebContentsAndroid::FocusLocationBarByDefault(JNIEnv* env, | 428 jboolean WebContentsAndroid::FocusLocationBarByDefault( |
| 415 jobject obj) { | 429 JNIEnv* env, |
| 430 const JavaParamRef<jobject>& obj) { |
| 416 return web_contents_->FocusLocationBarByDefault(); | 431 return web_contents_->FocusLocationBarByDefault(); |
| 417 } | 432 } |
| 418 | 433 |
| 419 jboolean WebContentsAndroid::IsRenderWidgetHostViewReady( | 434 jboolean WebContentsAndroid::IsRenderWidgetHostViewReady( |
| 420 JNIEnv* env, | 435 JNIEnv* env, |
| 421 jobject obj) { | 436 const JavaParamRef<jobject>& obj) { |
| 422 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | 437 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
| 423 return view && view->HasValidFrame(); | 438 return view && view->HasValidFrame(); |
| 424 } | 439 } |
| 425 | 440 |
| 426 void WebContentsAndroid::ExitFullscreen(JNIEnv* env, jobject obj) { | 441 void WebContentsAndroid::ExitFullscreen(JNIEnv* env, |
| 442 const JavaParamRef<jobject>& obj) { |
| 427 web_contents_->ExitFullscreen(); | 443 web_contents_->ExitFullscreen(); |
| 428 } | 444 } |
| 429 | 445 |
| 430 void WebContentsAndroid::UpdateTopControlsState( | 446 void WebContentsAndroid::UpdateTopControlsState( |
| 431 JNIEnv* env, | 447 JNIEnv* env, |
| 432 jobject obj, | 448 const JavaParamRef<jobject>& obj, |
| 433 bool enable_hiding, | 449 bool enable_hiding, |
| 434 bool enable_showing, | 450 bool enable_showing, |
| 435 bool animate) { | 451 bool animate) { |
| 436 RenderViewHost* host = web_contents_->GetRenderViewHost(); | 452 RenderViewHost* host = web_contents_->GetRenderViewHost(); |
| 437 if (!host) | 453 if (!host) |
| 438 return; | 454 return; |
| 439 host->Send(new ViewMsg_UpdateTopControlsState(host->GetRoutingID(), | 455 host->Send(new ViewMsg_UpdateTopControlsState(host->GetRoutingID(), |
| 440 enable_hiding, | 456 enable_hiding, |
| 441 enable_showing, | 457 enable_showing, |
| 442 animate)); | 458 animate)); |
| 443 } | 459 } |
| 444 | 460 |
| 445 void WebContentsAndroid::ShowImeIfNeeded(JNIEnv* env, jobject obj) { | 461 void WebContentsAndroid::ShowImeIfNeeded(JNIEnv* env, |
| 462 const JavaParamRef<jobject>& obj) { |
| 446 RenderViewHost* host = web_contents_->GetRenderViewHost(); | 463 RenderViewHost* host = web_contents_->GetRenderViewHost(); |
| 447 if (!host) | 464 if (!host) |
| 448 return; | 465 return; |
| 449 host->Send(new ViewMsg_ShowImeIfNeeded(host->GetRoutingID())); | 466 host->Send(new ViewMsg_ShowImeIfNeeded(host->GetRoutingID())); |
| 450 } | 467 } |
| 451 | 468 |
| 452 void WebContentsAndroid::ScrollFocusedEditableNodeIntoView( | 469 void WebContentsAndroid::ScrollFocusedEditableNodeIntoView( |
| 453 JNIEnv* env, | 470 JNIEnv* env, |
| 454 jobject obj) { | 471 const JavaParamRef<jobject>& obj) { |
| 455 RenderViewHost* host = web_contents_->GetRenderViewHost(); | 472 RenderViewHost* host = web_contents_->GetRenderViewHost(); |
| 456 if (!host) | 473 if (!host) |
| 457 return; | 474 return; |
| 458 host->Send(new InputMsg_ScrollFocusedEditableNodeIntoRect( | 475 host->Send(new InputMsg_ScrollFocusedEditableNodeIntoRect( |
| 459 host->GetRoutingID(), gfx::Rect())); | 476 host->GetRoutingID(), gfx::Rect())); |
| 460 } | 477 } |
| 461 | 478 |
| 462 void WebContentsAndroid::SelectWordAroundCaret(JNIEnv* env, jobject obj) { | 479 void WebContentsAndroid::SelectWordAroundCaret( |
| 480 JNIEnv* env, |
| 481 const JavaParamRef<jobject>& obj) { |
| 463 RenderViewHost* host = web_contents_->GetRenderViewHost(); | 482 RenderViewHost* host = web_contents_->GetRenderViewHost(); |
| 464 if (!host) | 483 if (!host) |
| 465 return; | 484 return; |
| 466 host->SelectWordAroundCaret(); | 485 host->SelectWordAroundCaret(); |
| 467 } | 486 } |
| 468 | 487 |
| 469 void WebContentsAndroid::AdjustSelectionByCharacterOffset(JNIEnv* env, | 488 void WebContentsAndroid::AdjustSelectionByCharacterOffset( |
| 470 jobject obj, | 489 JNIEnv* env, |
| 471 jint start_adjust, | 490 const JavaParamRef<jobject>& obj, |
| 472 jint end_adjust) { | 491 jint start_adjust, |
| 492 jint end_adjust) { |
| 473 web_contents_->AdjustSelectionByCharacterOffset(start_adjust, end_adjust); | 493 web_contents_->AdjustSelectionByCharacterOffset(start_adjust, end_adjust); |
| 474 } | 494 } |
| 475 | 495 |
| 476 void WebContentsAndroid::EvaluateJavaScript(JNIEnv* env, | 496 void WebContentsAndroid::EvaluateJavaScript( |
| 477 jobject obj, | 497 JNIEnv* env, |
| 478 jstring script, | 498 const JavaParamRef<jobject>& obj, |
| 479 jobject callback) { | 499 const JavaParamRef<jstring>& script, |
| 500 const JavaParamRef<jobject>& callback) { |
| 480 RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | 501 RenderViewHost* rvh = web_contents_->GetRenderViewHost(); |
| 481 DCHECK(rvh); | 502 DCHECK(rvh); |
| 482 | 503 |
| 483 if (!rvh->IsRenderViewLive()) { | 504 if (!rvh->IsRenderViewLive()) { |
| 484 if (!static_cast<WebContentsImpl*>(web_contents_)-> | 505 if (!static_cast<WebContentsImpl*>(web_contents_)-> |
| 485 CreateRenderViewForInitialEmptyDocument()) { | 506 CreateRenderViewForInitialEmptyDocument()) { |
| 486 LOG(ERROR) << "Failed to create RenderView in EvaluateJavaScript"; | 507 LOG(ERROR) << "Failed to create RenderView in EvaluateJavaScript"; |
| 487 return; | 508 return; |
| 488 } | 509 } |
| 489 } | 510 } |
| 490 | 511 |
| 491 if (!callback) { | 512 if (!callback) { |
| 492 // No callback requested. | 513 // No callback requested. |
| 493 web_contents_->GetMainFrame()->ExecuteJavaScript( | 514 web_contents_->GetMainFrame()->ExecuteJavaScript( |
| 494 ConvertJavaStringToUTF16(env, script)); | 515 ConvertJavaStringToUTF16(env, script)); |
| 495 return; | 516 return; |
| 496 } | 517 } |
| 497 | 518 |
| 498 // Secure the Java callback in a scoped object and give ownership of it to the | 519 // Secure the Java callback in a scoped object and give ownership of it to the |
| 499 // base::Callback. | 520 // base::Callback. |
| 500 ScopedJavaGlobalRef<jobject> j_callback; | 521 ScopedJavaGlobalRef<jobject> j_callback; |
| 501 j_callback.Reset(env, callback); | 522 j_callback.Reset(env, callback); |
| 502 RenderFrameHost::JavaScriptResultCallback js_callback = | 523 RenderFrameHost::JavaScriptResultCallback js_callback = |
| 503 base::Bind(&JavaScriptResultCallback, j_callback); | 524 base::Bind(&JavaScriptResultCallback, j_callback); |
| 504 | 525 |
| 505 web_contents_->GetMainFrame()->ExecuteJavaScript( | 526 web_contents_->GetMainFrame()->ExecuteJavaScript( |
| 506 ConvertJavaStringToUTF16(env, script), js_callback); | 527 ConvertJavaStringToUTF16(env, script), js_callback); |
| 507 } | 528 } |
| 508 | 529 |
| 509 void WebContentsAndroid::EvaluateJavaScriptForTests(JNIEnv* env, | 530 void WebContentsAndroid::EvaluateJavaScriptForTests( |
| 510 jobject obj, | 531 JNIEnv* env, |
| 511 jstring script, | 532 const JavaParamRef<jobject>& obj, |
| 512 jobject callback) { | 533 const JavaParamRef<jstring>& script, |
| 534 const JavaParamRef<jobject>& callback) { |
| 513 RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | 535 RenderViewHost* rvh = web_contents_->GetRenderViewHost(); |
| 514 DCHECK(rvh); | 536 DCHECK(rvh); |
| 515 | 537 |
| 516 if (!rvh->IsRenderViewLive()) { | 538 if (!rvh->IsRenderViewLive()) { |
| 517 if (!static_cast<WebContentsImpl*>(web_contents_)-> | 539 if (!static_cast<WebContentsImpl*>(web_contents_)-> |
| 518 CreateRenderViewForInitialEmptyDocument()) { | 540 CreateRenderViewForInitialEmptyDocument()) { |
| 519 LOG(ERROR) << "Failed to create RenderView in EvaluateJavaScriptForTests"; | 541 LOG(ERROR) << "Failed to create RenderView in EvaluateJavaScriptForTests"; |
| 520 return; | 542 return; |
| 521 } | 543 } |
| 522 } | 544 } |
| 523 | 545 |
| 524 if (!callback) { | 546 if (!callback) { |
| 525 // No callback requested. | 547 // No callback requested. |
| 526 web_contents_->GetMainFrame()->ExecuteJavaScriptForTests( | 548 web_contents_->GetMainFrame()->ExecuteJavaScriptForTests( |
| 527 ConvertJavaStringToUTF16(env, script)); | 549 ConvertJavaStringToUTF16(env, script)); |
| 528 return; | 550 return; |
| 529 } | 551 } |
| 530 | 552 |
| 531 // Secure the Java callback in a scoped object and give ownership of it to the | 553 // Secure the Java callback in a scoped object and give ownership of it to the |
| 532 // base::Callback. | 554 // base::Callback. |
| 533 ScopedJavaGlobalRef<jobject> j_callback; | 555 ScopedJavaGlobalRef<jobject> j_callback; |
| 534 j_callback.Reset(env, callback); | 556 j_callback.Reset(env, callback); |
| 535 RenderFrameHost::JavaScriptResultCallback js_callback = | 557 RenderFrameHost::JavaScriptResultCallback js_callback = |
| 536 base::Bind(&JavaScriptResultCallback, j_callback); | 558 base::Bind(&JavaScriptResultCallback, j_callback); |
| 537 | 559 |
| 538 web_contents_->GetMainFrame()->ExecuteJavaScriptForTests( | 560 web_contents_->GetMainFrame()->ExecuteJavaScriptForTests( |
| 539 ConvertJavaStringToUTF16(env, script), js_callback); | 561 ConvertJavaStringToUTF16(env, script), js_callback); |
| 540 } | 562 } |
| 541 | 563 |
| 542 void WebContentsAndroid::AddMessageToDevToolsConsole(JNIEnv* env, | 564 void WebContentsAndroid::AddMessageToDevToolsConsole( |
| 543 jobject jobj, | 565 JNIEnv* env, |
| 544 jint level, | 566 const JavaParamRef<jobject>& jobj, |
| 545 jstring message) { | 567 jint level, |
| 568 const JavaParamRef<jstring>& message) { |
| 546 DCHECK_GE(level, 0); | 569 DCHECK_GE(level, 0); |
| 547 DCHECK_LE(level, CONSOLE_MESSAGE_LEVEL_LAST); | 570 DCHECK_LE(level, CONSOLE_MESSAGE_LEVEL_LAST); |
| 548 | 571 |
| 549 web_contents_->GetMainFrame()->AddMessageToConsole( | 572 web_contents_->GetMainFrame()->AddMessageToConsole( |
| 550 static_cast<ConsoleMessageLevel>(level), | 573 static_cast<ConsoleMessageLevel>(level), |
| 551 ConvertJavaStringToUTF8(env, message)); | 574 ConvertJavaStringToUTF8(env, message)); |
| 552 } | 575 } |
| 553 | 576 |
| 554 void WebContentsAndroid::SendMessageToFrame(JNIEnv* env, | 577 void WebContentsAndroid::SendMessageToFrame( |
| 555 jobject obj, | 578 JNIEnv* env, |
| 556 jstring frame_name, | 579 const JavaParamRef<jobject>& obj, |
| 557 jstring message, | 580 const JavaParamRef<jstring>& frame_name, |
| 558 jstring target_origin) { | 581 const JavaParamRef<jstring>& message, |
| 582 const JavaParamRef<jstring>& target_origin) { |
| 559 base::string16 source_origin; | 583 base::string16 source_origin; |
| 560 base::string16 j_target_origin(ConvertJavaStringToUTF16(env, target_origin)); | 584 base::string16 j_target_origin(ConvertJavaStringToUTF16(env, target_origin)); |
| 561 base::string16 j_message(ConvertJavaStringToUTF16(env, message)); | 585 base::string16 j_message(ConvertJavaStringToUTF16(env, message)); |
| 562 std::vector<content::TransferredMessagePort> ports; | 586 std::vector<content::TransferredMessagePort> ports; |
| 563 content::MessagePortProvider::PostMessageToFrame( | 587 content::MessagePortProvider::PostMessageToFrame( |
| 564 web_contents_, source_origin, j_target_origin, j_message, ports); | 588 web_contents_, source_origin, j_target_origin, j_message, ports); |
| 565 } | 589 } |
| 566 | 590 |
| 567 jboolean WebContentsAndroid::HasAccessedInitialDocument( | 591 jboolean WebContentsAndroid::HasAccessedInitialDocument( |
| 568 JNIEnv* env, | 592 JNIEnv* env, |
| 569 jobject jobj) { | 593 const JavaParamRef<jobject>& jobj) { |
| 570 return static_cast<WebContentsImpl*>(web_contents_)-> | 594 return static_cast<WebContentsImpl*>(web_contents_)-> |
| 571 HasAccessedInitialDocument(); | 595 HasAccessedInitialDocument(); |
| 572 } | 596 } |
| 573 | 597 |
| 574 jint WebContentsAndroid::GetThemeColor(JNIEnv* env, jobject obj) { | 598 jint WebContentsAndroid::GetThemeColor(JNIEnv* env, |
| 599 const JavaParamRef<jobject>& obj) { |
| 575 return web_contents_->GetThemeColor(); | 600 return web_contents_->GetThemeColor(); |
| 576 } | 601 } |
| 577 | 602 |
| 578 void WebContentsAndroid::RequestAccessibilitySnapshot(JNIEnv* env, | 603 void WebContentsAndroid::RequestAccessibilitySnapshot( |
| 579 jobject obj, | 604 JNIEnv* env, |
| 580 jobject callback, | 605 const JavaParamRef<jobject>& obj, |
| 581 jfloat y_offset, | 606 const JavaParamRef<jobject>& callback, |
| 582 jfloat x_scroll) { | 607 jfloat y_offset, |
| 608 jfloat x_scroll) { |
| 583 // Secure the Java callback in a scoped object and give ownership of it to the | 609 // Secure the Java callback in a scoped object and give ownership of it to the |
| 584 // base::Callback. | 610 // base::Callback. |
| 585 ScopedJavaGlobalRef<jobject> j_callback; | 611 ScopedJavaGlobalRef<jobject> j_callback; |
| 586 j_callback.Reset(env, callback); | 612 j_callback.Reset(env, callback); |
| 587 gfx::DeviceDisplayInfo device_info; | 613 gfx::DeviceDisplayInfo device_info; |
| 588 ContentViewCoreImpl* contentViewCore = | 614 ContentViewCoreImpl* contentViewCore = |
| 589 ContentViewCoreImpl::FromWebContents(web_contents_); | 615 ContentViewCoreImpl::FromWebContents(web_contents_); |
| 590 | 616 |
| 591 AccessibilitySnapshotParams* params = new AccessibilitySnapshotParams( | 617 AccessibilitySnapshotParams* params = new AccessibilitySnapshotParams( |
| 592 contentViewCore->GetScaleFactor(), y_offset, x_scroll); | 618 contentViewCore->GetScaleFactor(), y_offset, x_scroll); |
| 593 WebContentsImpl::AXTreeSnapshotCallback snapshot_callback = | 619 WebContentsImpl::AXTreeSnapshotCallback snapshot_callback = |
| 594 base::Bind(&AXTreeSnapshotCallback, j_callback, base::Owned(params)); | 620 base::Bind(&AXTreeSnapshotCallback, j_callback, base::Owned(params)); |
| 595 static_cast<WebContentsImpl*>(web_contents_)->RequestAXTreeSnapshot( | 621 static_cast<WebContentsImpl*>(web_contents_)->RequestAXTreeSnapshot( |
| 596 snapshot_callback); | 622 snapshot_callback); |
| 597 } | 623 } |
| 598 | 624 |
| 599 void WebContentsAndroid::ResumeMediaSession(JNIEnv* env, jobject obj) { | 625 void WebContentsAndroid::ResumeMediaSession(JNIEnv* env, |
| 626 const JavaParamRef<jobject>& obj) { |
| 600 web_contents_->ResumeMediaSession(); | 627 web_contents_->ResumeMediaSession(); |
| 601 } | 628 } |
| 602 | 629 |
| 603 void WebContentsAndroid::SuspendMediaSession(JNIEnv* env, jobject obj) { | 630 void WebContentsAndroid::SuspendMediaSession(JNIEnv* env, |
| 631 const JavaParamRef<jobject>& obj) { |
| 604 web_contents_->SuspendMediaSession(); | 632 web_contents_->SuspendMediaSession(); |
| 605 } | 633 } |
| 606 | 634 |
| 607 void WebContentsAndroid::StopMediaSession(JNIEnv* env, jobject obj) { | 635 void WebContentsAndroid::StopMediaSession(JNIEnv* env, |
| 636 const JavaParamRef<jobject>& obj) { |
| 608 web_contents_->StopMediaSession(); | 637 web_contents_->StopMediaSession(); |
| 609 } | 638 } |
| 610 | 639 |
| 611 ScopedJavaLocalRef<jstring> WebContentsAndroid::GetEncoding( | 640 ScopedJavaLocalRef<jstring> WebContentsAndroid::GetEncoding( |
| 612 JNIEnv* env, jobject obj) const { | 641 JNIEnv* env, |
| 642 const JavaParamRef<jobject>& obj) const { |
| 613 return base::android::ConvertUTF8ToJavaString(env, | 643 return base::android::ConvertUTF8ToJavaString(env, |
| 614 web_contents_->GetEncoding()); | 644 web_contents_->GetEncoding()); |
| 615 } | 645 } |
| 616 | 646 |
| 617 void WebContentsAndroid::GetContentBitmap( | 647 void WebContentsAndroid::GetContentBitmap( |
| 618 JNIEnv* env, | 648 JNIEnv* env, |
| 619 const JavaParamRef<jobject>& obj, | 649 const JavaParamRef<jobject>& obj, |
| 620 const JavaParamRef<jobject>& jcallback, | 650 const JavaParamRef<jobject>& jcallback, |
| 621 const JavaParamRef<jobject>& color_type, | 651 const JavaParamRef<jobject>& color_type, |
| 622 jfloat scale, | 652 jfloat scale, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 ScopedJavaLocalRef<jobject> java_bitmap; | 684 ScopedJavaLocalRef<jobject> java_bitmap; |
| 655 if (response == READBACK_SUCCESS) | 685 if (response == READBACK_SUCCESS) |
| 656 java_bitmap = gfx::ConvertToJavaBitmap(&bitmap); | 686 java_bitmap = gfx::ConvertToJavaBitmap(&bitmap); |
| 657 Java_WebContentsImpl_onGetContentBitmapFinished(env, | 687 Java_WebContentsImpl_onGetContentBitmapFinished(env, |
| 658 obj->obj(), | 688 obj->obj(), |
| 659 callback->obj(), | 689 callback->obj(), |
| 660 java_bitmap.obj(), | 690 java_bitmap.obj(), |
| 661 response); | 691 response); |
| 662 } | 692 } |
| 663 } // namespace content | 693 } // namespace content |
| OLD | NEW |