Chromium Code Reviews| 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) return false; | |
| 198 | |
| 199 std::vector<content::WebContents*> contents = | |
| 200 prerender_manager->GetAllPrerenderingContents(); | |
| 201 prerender::PrerenderContents* prerender_contents; | |
| 202 for (size_t i = 0; i < contents.size(); ++i) { | |
| 203 prerender_contents = prerender_manager-> | |
| 204 GetPrerenderContents(contents.at(i)); | |
| 205 if (prerender_contents->prerender_url() == | |
| 206 gurl && prerender_contents->has_finished_loading()) { | |
|
David Trainor- moved to gerrit
2014/03/06 22:21:32
gurl on line above?
Ted C
2014/03/06 22:30:43
Done.
| |
| 207 return true; | |
| 208 } | |
| 209 } | |
| 210 return false; | |
| 211 } | |
| 212 | |
| 184 void TabAndroid::SwapTabContents(content::WebContents* old_contents, | 213 void TabAndroid::SwapTabContents(content::WebContents* old_contents, |
| 185 content::WebContents* new_contents, | 214 content::WebContents* new_contents, |
| 186 bool did_start_load, | 215 bool did_start_load, |
| 187 bool did_finish_load) { | 216 bool did_finish_load) { |
| 188 JNIEnv* env = base::android::AttachCurrentThread(); | 217 JNIEnv* env = base::android::AttachCurrentThread(); |
| 189 | 218 |
| 190 // We need to notify the native InfobarContainer so infobars can be swapped. | 219 // We need to notify the native InfobarContainer so infobars can be swapped. |
| 191 InfoBarContainerAndroid* infobar_container = | 220 InfoBarContainerAndroid* infobar_container = |
| 192 reinterpret_cast<InfoBarContainerAndroid*>( | 221 reinterpret_cast<InfoBarContainerAndroid*>( |
| 193 Java_Tab_getNativeInfoBarContainer( | 222 Java_Tab_getNativeInfoBarContainer( |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 Profile* profile = GetProfile(); | 365 Profile* profile = GetProfile(); |
| 337 if (!profile) | 366 if (!profile) |
| 338 return base::android::ScopedJavaLocalRef<jobject>(); | 367 return base::android::ScopedJavaLocalRef<jobject>(); |
| 339 ProfileAndroid* profile_android = ProfileAndroid::FromProfile(profile); | 368 ProfileAndroid* profile_android = ProfileAndroid::FromProfile(profile); |
| 340 if (!profile_android) | 369 if (!profile_android) |
| 341 return base::android::ScopedJavaLocalRef<jobject>(); | 370 return base::android::ScopedJavaLocalRef<jobject>(); |
| 342 | 371 |
| 343 return profile_android->GetJavaObject(); | 372 return profile_android->GetJavaObject(); |
| 344 } | 373 } |
| 345 | 374 |
| 375 TabAndroid::TabLoadStatus TabAndroid::LoadUrl(JNIEnv* env, | |
| 376 jobject obj, | |
| 377 jstring url, | |
| 378 jstring j_extra_headers, | |
| 379 jbyteArray j_post_data, | |
| 380 jint page_transition, | |
| 381 jstring j_referrer_url, | |
| 382 jint referrer_policy) { | |
| 383 content::ContentViewCore* content_view = GetContentViewCore(); | |
| 384 if (!content_view) | |
| 385 return PAGE_LOAD_FAILED; | |
| 386 | |
| 387 GURL gurl(base::android::ConvertJavaStringToUTF8(env, url)); | |
| 388 if (gurl.is_empty()) | |
| 389 return PAGE_LOAD_FAILED; | |
| 390 | |
| 391 // If the page was prerendered, use it. | |
| 392 // Note in incognito mode, we don't have a PrerenderManager. | |
| 393 | |
| 394 prerender::PrerenderManager* prerender_manager = | |
| 395 prerender::PrerenderManagerFactory::GetForProfile(GetProfile()); | |
| 396 if (prerender_manager) { | |
| 397 bool prefetched_page_loaded = HasPrerenderedUrl(gurl); | |
| 398 // Getting the load status before MaybeUsePrerenderedPage() b/c it resets. | |
| 399 chrome::NavigateParams params(NULL, web_contents()); | |
| 400 if (prerender_manager->MaybeUsePrerenderedPage(gurl, ¶ms)) { | |
| 401 return prefetched_page_loaded ? | |
| 402 FULL_PRERENDERED_PAGE_LOAD : PARTIAL_PRERENDERED_PAGE_LOAD; | |
| 403 } | |
| 404 } | |
| 405 | |
| 406 GURL fixed_url(URLFixerUpper::FixupURL(gurl.possibly_invalid_spec(), | |
| 407 std::string())); | |
| 408 if (!fixed_url.is_valid()) | |
| 409 return PAGE_LOAD_FAILED; | |
| 410 | |
| 411 if (!HandleNonNavigationAboutURL(fixed_url)) { | |
| 412 // Notify the GoogleURLTracker of searches, it might want to change the | |
| 413 // actual Google site used (for instance when in the UK, google.co.uk, when | |
| 414 // in the US google.com). | |
| 415 // Note that this needs to happen before we initiate the navigation as the | |
| 416 // GoogleURLTracker uses the navigation pending notification to trigger the | |
| 417 // infobar. | |
| 418 if (google_util::IsGoogleSearchUrl(fixed_url) && | |
| 419 (page_transition & content::PAGE_TRANSITION_GENERATED)) { | |
| 420 GoogleURLTracker::GoogleURLSearchCommitted(GetProfile()); | |
| 421 } | |
| 422 | |
| 423 // Record UMA "ShowHistory" here. That way it'll pick up both user | |
| 424 // typing chrome://history as well as selecting from the drop down menu. | |
| 425 if (fixed_url.spec() == chrome::kChromeUIHistoryURL) { | |
| 426 content::RecordAction(base::UserMetricsAction("ShowHistory")); | |
| 427 } | |
| 428 | |
| 429 content::NavigationController::LoadURLParams load_params(fixed_url); | |
| 430 if (j_extra_headers) | |
| 431 load_params.extra_headers = base::android::ConvertJavaStringToUTF8( | |
| 432 env, j_extra_headers); | |
|
David Trainor- moved to gerrit
2014/03/06 22:21:32
new line before j_extra_headers?
Ted C
2014/03/06 22:30:43
Done.
| |
| 433 if (j_post_data) { | |
| 434 load_params.load_type = | |
| 435 content::NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; | |
| 436 std::vector<uint8> post_data; | |
| 437 base::android::JavaByteArrayToByteVector(env, j_post_data, &post_data); | |
| 438 load_params.browser_initiated_post_data = | |
| 439 base::RefCountedBytes::TakeVector(&post_data); | |
| 440 } | |
| 441 load_params.transition_type = | |
| 442 content::PageTransitionFromInt(page_transition); | |
| 443 if (j_referrer_url) { | |
| 444 load_params.referrer = content::Referrer( | |
| 445 GURL(base::android::ConvertJavaStringToUTF8(env, j_referrer_url)), | |
| 446 static_cast<blink::WebReferrerPolicy>(referrer_policy)); | |
| 447 } | |
| 448 content_view->LoadUrl(load_params); | |
| 449 } | |
| 450 return DEFAULT_PAGE_LOAD; | |
| 451 } | |
| 452 | |
| 346 ToolbarModel::SecurityLevel TabAndroid::GetSecurityLevel(JNIEnv* env, | 453 ToolbarModel::SecurityLevel TabAndroid::GetSecurityLevel(JNIEnv* env, |
| 347 jobject obj) { | 454 jobject obj) { |
| 348 return ToolbarModelImpl::GetSecurityLevelForWebContents(web_contents()); | 455 return ToolbarModelImpl::GetSecurityLevelForWebContents(web_contents()); |
| 349 } | 456 } |
| 350 | 457 |
| 351 void TabAndroid::SetActiveNavigationEntryTitleForUrl(JNIEnv* env, | 458 void TabAndroid::SetActiveNavigationEntryTitleForUrl(JNIEnv* env, |
| 352 jobject obj, | 459 jobject obj, |
| 353 jstring jurl, | 460 jstring jurl, |
| 354 jstring jtitle) { | 461 jstring jtitle) { |
| 355 DCHECK(web_contents()); | 462 DCHECK(web_contents()); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 375 printing::PrintViewManagerBasic::CreateForWebContents(web_contents()); | 482 printing::PrintViewManagerBasic::CreateForWebContents(web_contents()); |
| 376 printing::PrintViewManagerBasic* print_view_manager = | 483 printing::PrintViewManagerBasic* print_view_manager = |
| 377 printing::PrintViewManagerBasic::FromWebContents(web_contents()); | 484 printing::PrintViewManagerBasic::FromWebContents(web_contents()); |
| 378 if (print_view_manager == NULL) | 485 if (print_view_manager == NULL) |
| 379 return false; | 486 return false; |
| 380 | 487 |
| 381 print_view_manager->PrintNow(); | 488 print_view_manager->PrintNow(); |
| 382 return true; | 489 return true; |
| 383 } | 490 } |
| 384 | 491 |
| 492 prerender::PrerenderManager* TabAndroid::GetPrerenderManager() const { | |
| 493 Profile* profile = GetProfile(); | |
| 494 if (!profile) | |
| 495 return NULL; | |
| 496 return prerender::PrerenderManagerFactory::GetForProfile(profile); | |
| 497 } | |
| 498 | |
| 385 static void Init(JNIEnv* env, jobject obj) { | 499 static void Init(JNIEnv* env, jobject obj) { |
| 386 TRACE_EVENT0("native", "TabAndroid::Init"); | 500 TRACE_EVENT0("native", "TabAndroid::Init"); |
| 387 // This will automatically bind to the Java object and pass ownership there. | 501 // This will automatically bind to the Java object and pass ownership there. |
| 388 new TabAndroid(env, obj); | 502 new TabAndroid(env, obj); |
| 389 } | 503 } |
| 390 | 504 |
| 391 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { | 505 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { |
| 392 return RegisterNativesImpl(env); | 506 return RegisterNativesImpl(env); |
| 393 } | 507 } |
| OLD | NEW |