| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" |
| 8 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 9 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 10 #include "chrome/browser/android/chrome_web_contents_delegate_android.h" | 11 #include "chrome/browser/android/chrome_web_contents_delegate_android.h" |
| 12 #include "chrome/browser/browser_about_handler.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 15 #include "chrome/browser/google/google_url_tracker.h" |
| 16 #include "chrome/browser/google/google_util.h" |
| 17 #include "chrome/browser/prerender/prerender_contents.h" |
| 18 #include "chrome/browser/prerender/prerender_manager.h" |
| 19 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 13 #include "chrome/browser/printing/print_view_manager_basic.h" | 20 #include "chrome/browser/printing/print_view_manager_basic.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_android.h" | 22 #include "chrome/browser/profiles/profile_android.h" |
| 16 #include "chrome/browser/sessions/session_tab_helper.h" | 23 #include "chrome/browser/sessions/session_tab_helper.h" |
| 17 #include "chrome/browser/sync/glue/synced_tab_delegate_android.h" | 24 #include "chrome/browser/sync/glue/synced_tab_delegate_android.h" |
| 18 #include "chrome/browser/ui/android/content_settings/popup_blocked_infobar_deleg
ate.h" | 25 #include "chrome/browser/ui/android/content_settings/popup_blocked_infobar_deleg
ate.h" |
| 19 #include "chrome/browser/ui/android/context_menu_helper.h" | 26 #include "chrome/browser/ui/android/context_menu_helper.h" |
| 20 #include "chrome/browser/ui/android/infobars/infobar_container_android.h" | 27 #include "chrome/browser/ui/android/infobars/infobar_container_android.h" |
| 21 #include "chrome/browser/ui/android/tab_model/tab_model.h" | 28 #include "chrome/browser/ui/android/tab_model/tab_model.h" |
| 22 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | 29 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
| 23 #include "chrome/browser/ui/android/window_android_helper.h" | 30 #include "chrome/browser/ui/android/window_android_helper.h" |
| 24 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" | 31 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" |
| 25 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 32 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 26 #include "chrome/browser/ui/tab_helpers.h" | 33 #include "chrome/browser/ui/tab_helpers.h" |
| 27 #include "chrome/browser/ui/toolbar/toolbar_model_impl.h" | 34 #include "chrome/browser/ui/toolbar/toolbar_model_impl.h" |
| 35 #include "chrome/common/net/url_fixer_upper.h" |
| 36 #include "chrome/common/url_constants.h" |
| 28 #include "content/public/browser/android/content_view_core.h" | 37 #include "content/public/browser/android/content_view_core.h" |
| 29 #include "content/public/browser/navigation_entry.h" | 38 #include "content/public/browser/navigation_entry.h" |
| 30 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
| 40 #include "content/public/browser/user_metrics.h" |
| 31 #include "content/public/browser/web_contents.h" | 41 #include "content/public/browser/web_contents.h" |
| 32 #include "jni/Tab_jni.h" | 42 #include "jni/Tab_jni.h" |
| 43 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
| 33 | 44 |
| 34 TabAndroid* TabAndroid::FromWebContents(content::WebContents* web_contents) { | 45 TabAndroid* TabAndroid::FromWebContents(content::WebContents* web_contents) { |
| 35 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(web_contents); | 46 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(web_contents); |
| 36 if (!core_tab_helper) | 47 if (!core_tab_helper) |
| 37 return NULL; | 48 return NULL; |
| 38 | 49 |
| 39 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); | 50 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); |
| 40 if (!core_delegate) | 51 if (!core_delegate) |
| 41 return NULL; | 52 return NULL; |
| 42 | 53 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 | 185 |
| 175 void TabAndroid::OnNewTabPageReady() { | 186 void TabAndroid::OnNewTabPageReady() { |
| 176 NOTREACHED(); | 187 NOTREACHED(); |
| 177 } | 188 } |
| 178 | 189 |
| 179 bool TabAndroid::ShouldWelcomePageLinkToTermsOfService() { | 190 bool TabAndroid::ShouldWelcomePageLinkToTermsOfService() { |
| 180 NOTIMPLEMENTED(); | 191 NOTIMPLEMENTED(); |
| 181 return false; | 192 return false; |
| 182 } | 193 } |
| 183 | 194 |
| 195 bool TabAndroid::HasPrerenderedUrl(GURL gurl) { |
| 196 prerender::PrerenderManager* prerender_manager = GetPrerenderManager(); |
| 197 if (!prerender_manager) |
| 198 return false; |
| 199 |
| 200 std::vector<content::WebContents*> contents = |
| 201 prerender_manager->GetAllPrerenderingContents(); |
| 202 prerender::PrerenderContents* prerender_contents; |
| 203 for (size_t i = 0; i < contents.size(); ++i) { |
| 204 prerender_contents = prerender_manager-> |
| 205 GetPrerenderContents(contents.at(i)); |
| 206 if (prerender_contents->prerender_url() == gurl && |
| 207 prerender_contents->has_finished_loading()) { |
| 208 return true; |
| 209 } |
| 210 } |
| 211 return false; |
| 212 } |
| 213 |
| 184 void TabAndroid::SwapTabContents(content::WebContents* old_contents, | 214 void TabAndroid::SwapTabContents(content::WebContents* old_contents, |
| 185 content::WebContents* new_contents, | 215 content::WebContents* new_contents, |
| 186 bool did_start_load, | 216 bool did_start_load, |
| 187 bool did_finish_load) { | 217 bool did_finish_load) { |
| 188 JNIEnv* env = base::android::AttachCurrentThread(); | 218 JNIEnv* env = base::android::AttachCurrentThread(); |
| 189 | 219 |
| 190 // We need to notify the native InfobarContainer so infobars can be swapped. | 220 // We need to notify the native InfobarContainer so infobars can be swapped. |
| 191 InfoBarContainerAndroid* infobar_container = | 221 InfoBarContainerAndroid* infobar_container = |
| 192 reinterpret_cast<InfoBarContainerAndroid*>( | 222 reinterpret_cast<InfoBarContainerAndroid*>( |
| 193 Java_Tab_getNativeInfoBarContainer( | 223 Java_Tab_getNativeInfoBarContainer( |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 Profile* profile = GetProfile(); | 366 Profile* profile = GetProfile(); |
| 337 if (!profile) | 367 if (!profile) |
| 338 return base::android::ScopedJavaLocalRef<jobject>(); | 368 return base::android::ScopedJavaLocalRef<jobject>(); |
| 339 ProfileAndroid* profile_android = ProfileAndroid::FromProfile(profile); | 369 ProfileAndroid* profile_android = ProfileAndroid::FromProfile(profile); |
| 340 if (!profile_android) | 370 if (!profile_android) |
| 341 return base::android::ScopedJavaLocalRef<jobject>(); | 371 return base::android::ScopedJavaLocalRef<jobject>(); |
| 342 | 372 |
| 343 return profile_android->GetJavaObject(); | 373 return profile_android->GetJavaObject(); |
| 344 } | 374 } |
| 345 | 375 |
| 376 TabAndroid::TabLoadStatus TabAndroid::LoadUrl(JNIEnv* env, |
| 377 jobject obj, |
| 378 jstring url, |
| 379 jstring j_extra_headers, |
| 380 jbyteArray j_post_data, |
| 381 jint page_transition, |
| 382 jstring j_referrer_url, |
| 383 jint referrer_policy) { |
| 384 content::ContentViewCore* content_view = GetContentViewCore(); |
| 385 if (!content_view) |
| 386 return PAGE_LOAD_FAILED; |
| 387 |
| 388 GURL gurl(base::android::ConvertJavaStringToUTF8(env, url)); |
| 389 if (gurl.is_empty()) |
| 390 return PAGE_LOAD_FAILED; |
| 391 |
| 392 // If the page was prerendered, use it. |
| 393 // Note in incognito mode, we don't have a PrerenderManager. |
| 394 |
| 395 prerender::PrerenderManager* prerender_manager = |
| 396 prerender::PrerenderManagerFactory::GetForProfile(GetProfile()); |
| 397 if (prerender_manager) { |
| 398 bool prefetched_page_loaded = HasPrerenderedUrl(gurl); |
| 399 // Getting the load status before MaybeUsePrerenderedPage() b/c it resets. |
| 400 chrome::NavigateParams params(NULL, web_contents()); |
| 401 if (prerender_manager->MaybeUsePrerenderedPage(gurl, ¶ms)) { |
| 402 return prefetched_page_loaded ? |
| 403 FULL_PRERENDERED_PAGE_LOAD : PARTIAL_PRERENDERED_PAGE_LOAD; |
| 404 } |
| 405 } |
| 406 |
| 407 GURL fixed_url(URLFixerUpper::FixupURL(gurl.possibly_invalid_spec(), |
| 408 std::string())); |
| 409 if (!fixed_url.is_valid()) |
| 410 return PAGE_LOAD_FAILED; |
| 411 |
| 412 if (!HandleNonNavigationAboutURL(fixed_url)) { |
| 413 // Notify the GoogleURLTracker of searches, it might want to change the |
| 414 // actual Google site used (for instance when in the UK, google.co.uk, when |
| 415 // in the US google.com). |
| 416 // Note that this needs to happen before we initiate the navigation as the |
| 417 // GoogleURLTracker uses the navigation pending notification to trigger the |
| 418 // infobar. |
| 419 if (google_util::IsGoogleSearchUrl(fixed_url) && |
| 420 (page_transition & content::PAGE_TRANSITION_GENERATED)) { |
| 421 GoogleURLTracker::GoogleURLSearchCommitted(GetProfile()); |
| 422 } |
| 423 |
| 424 // Record UMA "ShowHistory" here. That way it'll pick up both user |
| 425 // typing chrome://history as well as selecting from the drop down menu. |
| 426 if (fixed_url.spec() == chrome::kChromeUIHistoryURL) { |
| 427 content::RecordAction(base::UserMetricsAction("ShowHistory")); |
| 428 } |
| 429 |
| 430 content::NavigationController::LoadURLParams load_params(fixed_url); |
| 431 if (j_extra_headers) { |
| 432 load_params.extra_headers = base::android::ConvertJavaStringToUTF8( |
| 433 env, |
| 434 j_extra_headers); |
| 435 } |
| 436 if (j_post_data) { |
| 437 load_params.load_type = |
| 438 content::NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; |
| 439 std::vector<uint8> post_data; |
| 440 base::android::JavaByteArrayToByteVector(env, j_post_data, &post_data); |
| 441 load_params.browser_initiated_post_data = |
| 442 base::RefCountedBytes::TakeVector(&post_data); |
| 443 } |
| 444 load_params.transition_type = |
| 445 content::PageTransitionFromInt(page_transition); |
| 446 if (j_referrer_url) { |
| 447 load_params.referrer = content::Referrer( |
| 448 GURL(base::android::ConvertJavaStringToUTF8(env, j_referrer_url)), |
| 449 static_cast<blink::WebReferrerPolicy>(referrer_policy)); |
| 450 } |
| 451 content_view->LoadUrl(load_params); |
| 452 } |
| 453 return DEFAULT_PAGE_LOAD; |
| 454 } |
| 455 |
| 346 ToolbarModel::SecurityLevel TabAndroid::GetSecurityLevel(JNIEnv* env, | 456 ToolbarModel::SecurityLevel TabAndroid::GetSecurityLevel(JNIEnv* env, |
| 347 jobject obj) { | 457 jobject obj) { |
| 348 return ToolbarModelImpl::GetSecurityLevelForWebContents(web_contents()); | 458 return ToolbarModelImpl::GetSecurityLevelForWebContents(web_contents()); |
| 349 } | 459 } |
| 350 | 460 |
| 351 void TabAndroid::SetActiveNavigationEntryTitleForUrl(JNIEnv* env, | 461 void TabAndroid::SetActiveNavigationEntryTitleForUrl(JNIEnv* env, |
| 352 jobject obj, | 462 jobject obj, |
| 353 jstring jurl, | 463 jstring jurl, |
| 354 jstring jtitle) { | 464 jstring jtitle) { |
| 355 DCHECK(web_contents()); | 465 DCHECK(web_contents()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 375 printing::PrintViewManagerBasic::CreateForWebContents(web_contents()); | 485 printing::PrintViewManagerBasic::CreateForWebContents(web_contents()); |
| 376 printing::PrintViewManagerBasic* print_view_manager = | 486 printing::PrintViewManagerBasic* print_view_manager = |
| 377 printing::PrintViewManagerBasic::FromWebContents(web_contents()); | 487 printing::PrintViewManagerBasic::FromWebContents(web_contents()); |
| 378 if (print_view_manager == NULL) | 488 if (print_view_manager == NULL) |
| 379 return false; | 489 return false; |
| 380 | 490 |
| 381 print_view_manager->PrintNow(); | 491 print_view_manager->PrintNow(); |
| 382 return true; | 492 return true; |
| 383 } | 493 } |
| 384 | 494 |
| 495 prerender::PrerenderManager* TabAndroid::GetPrerenderManager() const { |
| 496 Profile* profile = GetProfile(); |
| 497 if (!profile) |
| 498 return NULL; |
| 499 return prerender::PrerenderManagerFactory::GetForProfile(profile); |
| 500 } |
| 501 |
| 385 static void Init(JNIEnv* env, jobject obj) { | 502 static void Init(JNIEnv* env, jobject obj) { |
| 386 TRACE_EVENT0("native", "TabAndroid::Init"); | 503 TRACE_EVENT0("native", "TabAndroid::Init"); |
| 387 // This will automatically bind to the Java object and pass ownership there. | 504 // This will automatically bind to the Java object and pass ownership there. |
| 388 new TabAndroid(env, obj); | 505 new TabAndroid(env, obj); |
| 389 } | 506 } |
| 390 | 507 |
| 391 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { | 508 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { |
| 392 return RegisterNativesImpl(env); | 509 return RegisterNativesImpl(env); |
| 393 } | 510 } |
| OLD | NEW |