| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "chrome/browser/android/tab_android.h" | 5 #include "chrome/browser/android/tab_android.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 30 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 31 #include "chrome/browser/infobars/infobar_service.h" | 31 #include "chrome/browser/infobars/infobar_service.h" |
| 32 #include "chrome/browser/prerender/prerender_contents.h" | 32 #include "chrome/browser/prerender/prerender_contents.h" |
| 33 #include "chrome/browser/prerender/prerender_manager.h" | 33 #include "chrome/browser/prerender/prerender_manager.h" |
| 34 #include "chrome/browser/prerender/prerender_manager_factory.h" | 34 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 35 #include "chrome/browser/printing/print_view_manager_basic.h" | 35 #include "chrome/browser/printing/print_view_manager_basic.h" |
| 36 #include "chrome/browser/printing/print_view_manager_common.h" | 36 #include "chrome/browser/printing/print_view_manager_common.h" |
| 37 #include "chrome/browser/profiles/profile.h" | 37 #include "chrome/browser/profiles/profile.h" |
| 38 #include "chrome/browser/profiles/profile_android.h" | 38 #include "chrome/browser/profiles/profile_android.h" |
| 39 #include "chrome/browser/profiles/profile_manager.h" | 39 #include "chrome/browser/profiles/profile_manager.h" |
| 40 #include "chrome/browser/search/instant_service.h" | |
| 41 #include "chrome/browser/search/instant_service_factory.h" | |
| 42 #include "chrome/browser/search/search.h" | |
| 43 #include "chrome/browser/sessions/session_tab_helper.h" | 40 #include "chrome/browser/sessions/session_tab_helper.h" |
| 44 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 41 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 45 #include "chrome/browser/sync/glue/synced_tab_delegate_android.h" | 42 #include "chrome/browser/sync/glue/synced_tab_delegate_android.h" |
| 46 #include "chrome/browser/tab_contents/tab_util.h" | 43 #include "chrome/browser/tab_contents/tab_util.h" |
| 47 #include "chrome/browser/ui/android/content_settings/popup_blocked_infobar_deleg
ate.h" | 44 #include "chrome/browser/ui/android/content_settings/popup_blocked_infobar_deleg
ate.h" |
| 48 #include "chrome/browser/ui/android/context_menu_helper.h" | 45 #include "chrome/browser/ui/android/context_menu_helper.h" |
| 49 #include "chrome/browser/ui/android/infobars/infobar_container_android.h" | 46 #include "chrome/browser/ui/android/infobars/infobar_container_android.h" |
| 50 #include "chrome/browser/ui/android/tab_model/tab_model.h" | 47 #include "chrome/browser/ui/android/tab_model/tab_model.h" |
| 51 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | 48 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
| 52 #include "chrome/browser/ui/android/view_android_helper.h" | 49 #include "chrome/browser/ui/android/view_android_helper.h" |
| 53 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" | 50 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" |
| 54 #include "chrome/browser/ui/search/instant_search_prerenderer.h" | |
| 55 #include "chrome/browser/ui/search/search_tab_helper.h" | |
| 56 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 51 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 57 #include "chrome/browser/ui/tab_helpers.h" | 52 #include "chrome/browser/ui/tab_helpers.h" |
| 58 #include "chrome/common/render_messages.h" | 53 #include "chrome/common/render_messages.h" |
| 59 #include "chrome/common/search/instant_types.h" | |
| 60 #include "chrome/common/url_constants.h" | 54 #include "chrome/common/url_constants.h" |
| 61 #include "components/bookmarks/browser/bookmark_model.h" | 55 #include "components/bookmarks/browser/bookmark_model.h" |
| 62 #include "components/bookmarks/browser/bookmark_node.h" | 56 #include "components/bookmarks/browser/bookmark_node.h" |
| 63 #include "components/bookmarks/browser/bookmark_utils.h" | 57 #include "components/bookmarks/browser/bookmark_utils.h" |
| 64 #include "components/bookmarks/managed/managed_bookmark_service.h" | 58 #include "components/bookmarks/managed/managed_bookmark_service.h" |
| 65 #include "components/dom_distiller/core/url_utils.h" | 59 #include "components/dom_distiller/core/url_utils.h" |
| 66 #include "components/favicon/content/content_favicon_driver.h" | 60 #include "components/favicon/content/content_favicon_driver.h" |
| 67 #include "components/navigation_interception/intercept_navigation_delegate.h" | 61 #include "components/navigation_interception/intercept_navigation_delegate.h" |
| 68 #include "components/navigation_interception/navigation_params.h" | 62 #include "components/navigation_interception/navigation_params.h" |
| 69 #include "components/offline_pages/offline_page_feature.h" | 63 #include "components/offline_pages/offline_page_feature.h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 void TabAndroid::SwapTabContents(content::WebContents* old_contents, | 255 void TabAndroid::SwapTabContents(content::WebContents* old_contents, |
| 262 content::WebContents* new_contents, | 256 content::WebContents* new_contents, |
| 263 bool did_start_load, | 257 bool did_start_load, |
| 264 bool did_finish_load) { | 258 bool did_finish_load) { |
| 265 JNIEnv* env = base::android::AttachCurrentThread(); | 259 JNIEnv* env = base::android::AttachCurrentThread(); |
| 266 Java_Tab_swapWebContents(env, weak_java_tab_.get(env), | 260 Java_Tab_swapWebContents(env, weak_java_tab_.get(env), |
| 267 new_contents->GetJavaWebContents(), did_start_load, | 261 new_contents->GetJavaWebContents(), did_start_load, |
| 268 did_finish_load); | 262 did_finish_load); |
| 269 } | 263 } |
| 270 | 264 |
| 271 void TabAndroid::DefaultSearchProviderChanged( | |
| 272 bool google_base_url_domain_changed) { | |
| 273 // TODO(kmadhusu): Move this function definition to a common place and update | |
| 274 // BrowserInstantController::DefaultSearchProviderChanged to use the same. | |
| 275 if (!web_contents()) | |
| 276 return; | |
| 277 | |
| 278 InstantService* instant_service = | |
| 279 InstantServiceFactory::GetForProfile(GetProfile()); | |
| 280 if (!instant_service) | |
| 281 return; | |
| 282 | |
| 283 // Send new search URLs to the renderer. | |
| 284 content::RenderProcessHost* rph = web_contents()->GetRenderProcessHost(); | |
| 285 instant_service->SendSearchURLsToRenderer(rph); | |
| 286 | |
| 287 // Reload the contents to ensure that it gets assigned to a non-previledged | |
| 288 // renderer. | |
| 289 if (!instant_service->IsInstantProcess(rph->GetID())) | |
| 290 return; | |
| 291 web_contents()->GetController().Reload(false); | |
| 292 | |
| 293 // As the reload was not triggered by the user we don't want to close any | |
| 294 // infobars. We have to tell the InfoBarService after the reload, otherwise it | |
| 295 // would ignore this call when | |
| 296 // WebContentsObserver::DidStartNavigationToPendingEntry is invoked. | |
| 297 InfoBarService::FromWebContents(web_contents())->set_ignore_next_reload(); | |
| 298 } | |
| 299 | |
| 300 void TabAndroid::OnWebContentsInstantSupportDisabled( | |
| 301 const content::WebContents* contents) { | |
| 302 DCHECK(contents); | |
| 303 if (web_contents() != contents) | |
| 304 return; | |
| 305 | |
| 306 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 307 Java_Tab_onWebContentsInstantSupportDisabled(env, weak_java_tab_.get(env)); | |
| 308 } | |
| 309 | |
| 310 void TabAndroid::Observe(int type, | 265 void TabAndroid::Observe(int type, |
| 311 const content::NotificationSource& source, | 266 const content::NotificationSource& source, |
| 312 const content::NotificationDetails& details) { | 267 const content::NotificationDetails& details) { |
| 313 JNIEnv* env = base::android::AttachCurrentThread(); | 268 JNIEnv* env = base::android::AttachCurrentThread(); |
| 314 switch (type) { | 269 switch (type) { |
| 315 case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: { | 270 case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: { |
| 316 TabSpecificContentSettings* settings = | 271 TabSpecificContentSettings* settings = |
| 317 TabSpecificContentSettings::FromWebContents(web_contents()); | 272 TabSpecificContentSettings::FromWebContents(web_contents()); |
| 318 if (!settings->IsBlockageIndicated(CONTENT_SETTINGS_TYPE_POPUPS)) { | 273 if (!settings->IsBlockageIndicated(CONTENT_SETTINGS_TYPE_POPUPS)) { |
| 319 // TODO(dfalcantara): Create an InfoBarDelegate to keep the | 274 // TODO(dfalcantara): Create an InfoBarDelegate to keep the |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 | 333 |
| 379 SetWindowSessionID(session_window_id_.id()); | 334 SetWindowSessionID(session_window_id_.id()); |
| 380 | 335 |
| 381 session_tab_id_.set_id( | 336 session_tab_id_.set_id( |
| 382 SessionTabHelper::FromWebContents(web_contents())->session_id().id()); | 337 SessionTabHelper::FromWebContents(web_contents())->session_id().id()); |
| 383 ContextMenuHelper::FromWebContents(web_contents())->SetPopulator( | 338 ContextMenuHelper::FromWebContents(web_contents())->SetPopulator( |
| 384 jcontext_menu_populator); | 339 jcontext_menu_populator); |
| 385 ViewAndroidHelper::FromWebContents(web_contents())-> | 340 ViewAndroidHelper::FromWebContents(web_contents())-> |
| 386 SetViewAndroid(web_contents()->GetNativeView()); | 341 SetViewAndroid(web_contents()->GetNativeView()); |
| 387 CoreTabHelper::FromWebContents(web_contents())->set_delegate(this); | 342 CoreTabHelper::FromWebContents(web_contents())->set_delegate(this); |
| 388 SearchTabHelper::FromWebContents(web_contents())->set_delegate(this); | |
| 389 web_contents_delegate_ = | 343 web_contents_delegate_ = |
| 390 base::MakeUnique<android::TabWebContentsDelegateAndroid>( | 344 base::MakeUnique<android::TabWebContentsDelegateAndroid>( |
| 391 env, jweb_contents_delegate); | 345 env, jweb_contents_delegate); |
| 392 web_contents_delegate_->LoadProgressChanged(web_contents(), 0); | 346 web_contents_delegate_->LoadProgressChanged(web_contents(), 0); |
| 393 web_contents()->SetDelegate(web_contents_delegate_.get()); | 347 web_contents()->SetDelegate(web_contents_delegate_.get()); |
| 394 | 348 |
| 395 notification_registrar_.Add( | 349 notification_registrar_.Add( |
| 396 this, | 350 this, |
| 397 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, | 351 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
| 398 content::Source<content::WebContents>(web_contents())); | 352 content::Source<content::WebContents>(web_contents())); |
| 399 notification_registrar_.Add( | 353 notification_registrar_.Add( |
| 400 this, | 354 this, |
| 401 content::NOTIFICATION_NAV_ENTRY_CHANGED, | 355 content::NOTIFICATION_NAV_ENTRY_CHANGED, |
| 402 content::Source<content::NavigationController>( | 356 content::Source<content::NavigationController>( |
| 403 &web_contents()->GetController())); | 357 &web_contents()->GetController())); |
| 404 | 358 |
| 405 favicon::FaviconDriver* favicon_driver = | 359 favicon::FaviconDriver* favicon_driver = |
| 406 favicon::ContentFaviconDriver::FromWebContents(web_contents_.get()); | 360 favicon::ContentFaviconDriver::FromWebContents(web_contents_.get()); |
| 407 | 361 |
| 408 if (favicon_driver) | 362 if (favicon_driver) |
| 409 favicon_driver->AddObserver(this); | 363 favicon_driver->AddObserver(this); |
| 410 | 364 |
| 411 synced_tab_delegate_->SetWebContents(web_contents()); | 365 synced_tab_delegate_->SetWebContents(web_contents()); |
| 412 | 366 |
| 413 // Verify that the WebContents this tab represents matches the expected | 367 // Verify that the WebContents this tab represents matches the expected |
| 414 // off the record state. | 368 // off the record state. |
| 415 CHECK_EQ(GetProfile()->IsOffTheRecord(), incognito); | 369 CHECK_EQ(GetProfile()->IsOffTheRecord(), incognito); |
| 416 | 370 |
| 417 InstantService* instant_service = | |
| 418 InstantServiceFactory::GetForProfile(GetProfile()); | |
| 419 if (instant_service) | |
| 420 instant_service->AddObserver(this); | |
| 421 | |
| 422 if (!blimp_contents_) | 371 if (!blimp_contents_) |
| 423 content_layer_->InsertChild(web_contents_->GetNativeView()->GetLayer(), 0); | 372 content_layer_->InsertChild(web_contents_->GetNativeView()->GetLayer(), 0); |
| 424 } | 373 } |
| 425 | 374 |
| 426 base::android::ScopedJavaLocalRef<jobject> TabAndroid::InitBlimpContents( | 375 base::android::ScopedJavaLocalRef<jobject> TabAndroid::InitBlimpContents( |
| 427 JNIEnv* env, | 376 JNIEnv* env, |
| 428 const JavaParamRef<jobject>& obj, | 377 const JavaParamRef<jobject>& obj, |
| 429 const JavaParamRef<jobject>& j_profile, | 378 const JavaParamRef<jobject>& j_profile, |
| 430 jlong window_android_ptr) { | 379 jlong window_android_ptr) { |
| 431 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile.obj()); | 380 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile.obj()); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 content::NOTIFICATION_NAV_ENTRY_CHANGED, | 435 content::NOTIFICATION_NAV_ENTRY_CHANGED, |
| 487 content::Source<content::NavigationController>( | 436 content::Source<content::NavigationController>( |
| 488 &web_contents()->GetController())); | 437 &web_contents()->GetController())); |
| 489 | 438 |
| 490 favicon::FaviconDriver* favicon_driver = | 439 favicon::FaviconDriver* favicon_driver = |
| 491 favicon::ContentFaviconDriver::FromWebContents(web_contents_.get()); | 440 favicon::ContentFaviconDriver::FromWebContents(web_contents_.get()); |
| 492 | 441 |
| 493 if (favicon_driver) | 442 if (favicon_driver) |
| 494 favicon_driver->RemoveObserver(this); | 443 favicon_driver->RemoveObserver(this); |
| 495 | 444 |
| 496 InstantService* instant_service = | |
| 497 InstantServiceFactory::GetForProfile(GetProfile()); | |
| 498 if (instant_service) | |
| 499 instant_service->RemoveObserver(this); | |
| 500 | |
| 501 web_contents()->SetDelegate(NULL); | 445 web_contents()->SetDelegate(NULL); |
| 502 | 446 |
| 503 if (delete_native) { | 447 if (delete_native) { |
| 504 // Terminate the renderer process if this is the last tab. | 448 // Terminate the renderer process if this is the last tab. |
| 505 // If there's no unload listener, FastShutdownForPageCount kills the | 449 // If there's no unload listener, FastShutdownForPageCount kills the |
| 506 // renderer process. Otherwise, we go with the slow path where renderer | 450 // renderer process. Otherwise, we go with the slow path where renderer |
| 507 // process shuts down itself when ref count becomes 0. | 451 // process shuts down itself when ref count becomes 0. |
| 508 // This helps the render process exit quickly which avoids some issues | 452 // This helps the render process exit quickly which avoids some issues |
| 509 // during shutdown. See https://codereview.chromium.org/146693011/ | 453 // during shutdown. See https://codereview.chromium.org/146693011/ |
| 510 // and http://crbug.com/338709 for details. | 454 // and http://crbug.com/338709 for details. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 | 503 |
| 560 // If the page was prerendered, use it. | 504 // If the page was prerendered, use it. |
| 561 // Note in incognito mode, we don't have a PrerenderManager. | 505 // Note in incognito mode, we don't have a PrerenderManager. |
| 562 | 506 |
| 563 prerender::PrerenderManager* prerender_manager = | 507 prerender::PrerenderManager* prerender_manager = |
| 564 prerender::PrerenderManagerFactory::GetForBrowserContext(GetProfile()); | 508 prerender::PrerenderManagerFactory::GetForBrowserContext(GetProfile()); |
| 565 if (prerender_manager) { | 509 if (prerender_manager) { |
| 566 bool prefetched_page_loaded = HasPrerenderedUrl(gurl); | 510 bool prefetched_page_loaded = HasPrerenderedUrl(gurl); |
| 567 // Getting the load status before MaybeUsePrerenderedPage() b/c it resets. | 511 // Getting the load status before MaybeUsePrerenderedPage() b/c it resets. |
| 568 chrome::NavigateParams params(web_contents()); | 512 chrome::NavigateParams params(web_contents()); |
| 569 InstantSearchPrerenderer* prerenderer = | |
| 570 InstantSearchPrerenderer::GetForProfile(GetProfile()); | |
| 571 if (prerenderer) { | |
| 572 const base::string16& search_terms = | |
| 573 search::ExtractSearchTermsFromURL(GetProfile(), gurl); | |
| 574 if (!search_terms.empty() && | |
| 575 prerenderer->CanCommitQuery(web_contents_.get(), search_terms)) { | |
| 576 EmbeddedSearchRequestParams request_params(gurl); | |
| 577 prerenderer->Commit(search_terms, request_params); | |
| 578 | |
| 579 if (prerenderer->UsePrerenderedPage(gurl, ¶ms)) | |
| 580 return FULL_PRERENDERED_PAGE_LOAD; | |
| 581 } | |
| 582 prerenderer->Cancel(); | |
| 583 } | |
| 584 if (prerender_manager->MaybeUsePrerenderedPage(gurl, ¶ms)) { | 513 if (prerender_manager->MaybeUsePrerenderedPage(gurl, ¶ms)) { |
| 585 return prefetched_page_loaded ? | 514 return prefetched_page_loaded ? |
| 586 FULL_PRERENDERED_PAGE_LOAD : PARTIAL_PRERENDERED_PAGE_LOAD; | 515 FULL_PRERENDERED_PAGE_LOAD : PARTIAL_PRERENDERED_PAGE_LOAD; |
| 587 } | 516 } |
| 588 } | 517 } |
| 589 | 518 |
| 590 GURL fixed_url( | 519 GURL fixed_url( |
| 591 url_formatter::FixupURL(gurl.possibly_invalid_spec(), std::string())); | 520 url_formatter::FixupURL(gurl.possibly_invalid_spec(), std::string())); |
| 592 if (!fixed_url.is_valid()) | 521 if (!fixed_url.is_valid()) |
| 593 return PAGE_LOAD_FAILED; | 522 return PAGE_LOAD_FAILED; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 616 load_params.post_data = | 545 load_params.post_data = |
| 617 content::ResourceRequestBody::FromJavaObject(env, j_post_data); | 546 content::ResourceRequestBody::FromJavaObject(env, j_post_data); |
| 618 } | 547 } |
| 619 load_params.transition_type = | 548 load_params.transition_type = |
| 620 ui::PageTransitionFromInt(page_transition); | 549 ui::PageTransitionFromInt(page_transition); |
| 621 if (j_referrer_url) { | 550 if (j_referrer_url) { |
| 622 load_params.referrer = content::Referrer( | 551 load_params.referrer = content::Referrer( |
| 623 GURL(base::android::ConvertJavaStringToUTF8(env, j_referrer_url)), | 552 GURL(base::android::ConvertJavaStringToUTF8(env, j_referrer_url)), |
| 624 static_cast<blink::WebReferrerPolicy>(referrer_policy)); | 553 static_cast<blink::WebReferrerPolicy>(referrer_policy)); |
| 625 } | 554 } |
| 626 const base::string16 search_terms = | |
| 627 search::ExtractSearchTermsFromURL(GetProfile(), gurl); | |
| 628 SearchTabHelper* search_tab_helper = | |
| 629 SearchTabHelper::FromWebContents(web_contents_.get()); | |
| 630 if (!search_terms.empty() && search_tab_helper && | |
| 631 search_tab_helper->SupportsInstant()) { | |
| 632 EmbeddedSearchRequestParams request_params(gurl); | |
| 633 search_tab_helper->Submit(search_terms, request_params); | |
| 634 return DEFAULT_PAGE_LOAD; | |
| 635 } | |
| 636 load_params.is_renderer_initiated = is_renderer_initiated; | 555 load_params.is_renderer_initiated = is_renderer_initiated; |
| 637 load_params.should_replace_current_entry = should_replace_current_entry; | 556 load_params.should_replace_current_entry = should_replace_current_entry; |
| 638 load_params.intent_received_timestamp = intent_received_timestamp; | 557 load_params.intent_received_timestamp = intent_received_timestamp; |
| 639 load_params.has_user_gesture = has_user_gesture; | 558 load_params.has_user_gesture = has_user_gesture; |
| 640 web_contents()->GetController().LoadURLWithParams(load_params); | 559 web_contents()->GetController().LoadURLWithParams(load_params); |
| 641 } | 560 } |
| 642 return DEFAULT_PAGE_LOAD; | 561 return DEFAULT_PAGE_LOAD; |
| 643 } | 562 } |
| 644 | 563 |
| 645 void TabAndroid::SetActiveNavigationEntryTitleForUrl( | 564 void TabAndroid::SetActiveNavigationEntryTitleForUrl( |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 802 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 884 TRACE_EVENT0("native", "TabAndroid::Init"); | 803 TRACE_EVENT0("native", "TabAndroid::Init"); |
| 885 // This will automatically bind to the Java object and pass ownership there. | 804 // This will automatically bind to the Java object and pass ownership there. |
| 886 new TabAndroid(env, obj); | 805 new TabAndroid(env, obj); |
| 887 } | 806 } |
| 888 | 807 |
| 889 // static | 808 // static |
| 890 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { | 809 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { |
| 891 return RegisterNativesImpl(env); | 810 return RegisterNativesImpl(env); |
| 892 } | 811 } |
| OLD | NEW |