tab_android.cc revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/android/tab_android.h" 6c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 7424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "base/android/jni_android.h" 8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/android/jni_array.h" 94e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/android/jni_string.h" 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/debug/trace_event.h" 11424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "chrome/browser/android/chrome_web_contents_delegate_android.h" 12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/browser_about_handler.h" 1358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/chrome_notification_types.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/content_settings/tab_specific_content_settings.h" 156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chrome/browser/favicon/favicon_tab_helper.h" 1646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "chrome/browser/google/google_url_tracker_factory.h" 17c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "chrome/browser/infobars/infobar_service.h" 18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/prerender/prerender_contents.h" 19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/prerender/prerender_manager.h" 20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/prerender/prerender_manager_factory.h" 21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/printing/print_view_manager_basic.h" 22424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "chrome/browser/profiles/profile.h" 23424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "chrome/browser/profiles/profile_android.h" 245c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "chrome/browser/search/search.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/sessions/session_tab_helper.h" 2658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/sync/glue/synced_tab_delegate_android.h" 27116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "chrome/browser/tab_contents/tab_util.h" 28f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.h" 29a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/browser/ui/android/context_menu_helper.h" 304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/android/infobars/infobar_container_android.h" 3158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/ui/android/tab_model/tab_model.h" 3258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/ui/android/tab_model/tab_model_list.h" 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/android/window_android_helper.h" 34424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" 35f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "chrome/browser/ui/search/instant_search_prerenderer.h" 365c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "chrome/browser/ui/search/search_tab_helper.h" 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/tab_contents/core_tab_helper.h" 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/tab_helpers.h" 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/toolbar/toolbar_model_impl.h" 40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/common/url_constants.h" 41f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "components/google/core/browser/google_url_tracker.h" 426d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "components/google/core/browser/google_util.h" 430529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "components/infobars/core/infobar_container.h" 44f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "components/url_fixer/url_fixer.h" 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/android/content_view_core.h" 464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "content/public/browser/navigation_entry.h" 4758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "content/public/browser/notification_service.h" 48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "content/public/browser/user_metrics.h" 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h" 50a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "jni/Tab_jni.h" 516e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "skia/ext/image_operations.h" 52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "third_party/WebKit/public/platform/WebReferrerPolicy.h" 536e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "ui/base/resource/resource_bundle.h" 54116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "ui/base/window_open_disposition.h" 556e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "ui/gfx/android/device_display_info.h" 566e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "ui/gfx/android/java_bitmap.h" 576e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "ui/gfx/favicon_size.h" 586e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "ui/gfx/image/image_skia.h" 59116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 60116680a4aac90f2aa7413d9095a592090648e557Ben Murdochusing content::GlobalRequestID; 61116680a4aac90f2aa7413d9095a592090648e557Ben Murdochusing content::NavigationController; 62116680a4aac90f2aa7413d9095a592090648e557Ben Murdochusing content::WebContents; 63116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 64116680a4aac90f2aa7413d9095a592090648e557Ben Murdochnamespace { 65116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 66116680a4aac90f2aa7413d9095a592090648e557Ben MurdochWebContents* CreateTargetContents(const chrome::NavigateParams& params, 67116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const GURL& url) { 68116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch Profile* profile = params.initiating_profile; 69116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 70116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (profile->IsOffTheRecord() || params.disposition == OFF_THE_RECORD) { 71116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch profile = profile->GetOffTheRecordProfile(); 72116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 73116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch WebContents::CreateParams create_params( 74116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch profile, tab_util::GetSiteInstanceForNewTab(profile, url)); 75116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (params.source_contents) { 76116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch create_params.initial_size = 77116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params.source_contents->GetContainerBounds().size(); 78116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (params.should_set_opener) 79116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch create_params.opener = params.source_contents; 80116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 81116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (params.disposition == NEW_BACKGROUND_TAB) 82116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch create_params.initially_hidden = true; 83116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 84116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch WebContents* target_contents = WebContents::Create(create_params); 85116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 86116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return target_contents; 87116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} 88116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)bool MaybeSwapWithPrerender(const GURL& url, chrome::NavigateParams* params) { 905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Profile* profile = 915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Profile::FromBrowserContext(params->target_contents->GetBrowserContext()); 925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) prerender::PrerenderManager* prerender_manager = 945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) prerender::PrerenderManagerFactory::GetForProfile(profile); 955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (!prerender_manager) 965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return false; 975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return prerender_manager->MaybeUsePrerenderedPage(url, params); 985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 100116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} // namespace 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 102424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TabAndroid* TabAndroid::FromWebContents(content::WebContents* web_contents) { 103424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(web_contents); 104424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!core_tab_helper) 105424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return NULL; 106424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 107424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); 108424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!core_delegate) 109424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return NULL; 110424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 111424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return static_cast<TabAndroid*>(core_delegate); 112424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 113424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 114424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TabAndroid* TabAndroid::GetNativeTab(JNIEnv* env, jobject obj) { 115a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return reinterpret_cast<TabAndroid*>(Java_Tab_getNativePtr(env, obj)); 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)void TabAndroid::AttachTabHelpers(content::WebContents* web_contents) { 11923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) DCHECK(web_contents); 12023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 12123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) TabHelpers::AttachTabHelpers(web_contents); 12223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)} 12323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 124424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TabAndroid::TabAndroid(JNIEnv* env, jobject obj) 125424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) : weak_java_tab_(env, obj), 12658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)) { 127a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_setNativePtr(env, obj, reinterpret_cast<intptr_t>(this)); 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 13058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)TabAndroid::~TabAndroid() { 13158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Java_Tab_clearNativePtr(env, weak_java_tab_.get(env).obj()); 13358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 13458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetJavaObject() { 1365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return weak_java_tab_.get(env); 1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)int TabAndroid::GetAndroidId() const { 1418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return Java_Tab_getId(env, weak_java_tab_.get(env).obj()); 1438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 1448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1450f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)int TabAndroid::GetSyncId() const { 1460f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return Java_Tab_getSyncId(env, weak_java_tab_.get(env).obj()); 1480f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 1490f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 150a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)base::string16 TabAndroid::GetTitle() const { 1518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return base::android::ConvertJavaStringToUTF16( 1535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Java_Tab_getTitle(env, weak_java_tab_.get(env).obj())); 1548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 1558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)GURL TabAndroid::GetURL() const { 1578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return GURL(base::android::ConvertJavaStringToUTF8( 1595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Java_Tab_getUrl(env, weak_java_tab_.get(env).obj()))); 1608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 1618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 162e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochbool TabAndroid::LoadIfNeeded() { 1638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return Java_Tab_loadIfNeeded(env, weak_java_tab_.get(env).obj()); 1658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 1668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 167424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)content::ContentViewCore* TabAndroid::GetContentViewCore() const { 168424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!web_contents()) 169424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return NULL; 170424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 171424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return content::ContentViewCore::FromWebContents(web_contents()); 172424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 173424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 174424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)Profile* TabAndroid::GetProfile() const { 175424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!web_contents()) 176424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return NULL; 177424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 178424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 179424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 180424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 18158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)browser_sync::SyncedTabDelegate* TabAndroid::GetSyncedTabDelegate() const { 18258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return synced_tab_delegate_.get(); 1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 185a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void TabAndroid::SetWindowSessionID(SessionID::id_type window_id) { 186a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) session_window_id_.set_id(window_id); 187a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 188a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!web_contents()) 189a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return; 190a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 191a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) SessionTabHelper* session_tab_helper = 192a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) SessionTabHelper::FromWebContents(web_contents()); 193a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) session_tab_helper->SetWindowID(session_window_id_); 194a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 195a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 1960f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)void TabAndroid::SetSyncId(int sync_id) { 1970f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Java_Tab_setSyncId(env, weak_java_tab_.get(env).obj(), sync_id); 1990f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 2000f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void TabAndroid::HandlePopupNavigation(chrome::NavigateParams* params) { 202116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (params->disposition != SUPPRESS_OPEN && 203116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->disposition != SAVE_TO_DISK && 204116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->disposition != IGNORE_ACTION) { 205116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (!params->url.is_empty()) { 206116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool was_blocked = false; 207116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch GURL url(params->url); 208116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (params->disposition == CURRENT_TAB) { 2095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) params->target_contents = web_contents_.get(); 2105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (!MaybeSwapWithPrerender(url, params)) { 2115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) NavigationController::LoadURLParams load_url_params(url); 2125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) MakeLoadURLParams(params, &load_url_params); 2135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) params->target_contents->GetController().LoadURLWithParams( 2145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) load_url_params); 2155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 216116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } else { 217116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->target_contents = CreateTargetContents(*params, url); 2185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) NavigationController::LoadURLParams load_url_params(url); 2195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) MakeLoadURLParams(params, &load_url_params); 220116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->target_contents->GetController().LoadURLWithParams( 221116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params); 222116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch web_contents_delegate_->AddNewContents(params->source_contents, 223116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->target_contents, 224116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->disposition, 225116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->window_bounds, 226116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->user_gesture, 227116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch &was_blocked); 228116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (was_blocked) 229116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->target_contents = NULL; 230116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 231116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 232116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 2335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool TabAndroid::ShouldWelcomePageLinkToTermsOfService() { 2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NOTIMPLEMENTED(); 2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return false; 2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 240a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool TabAndroid::HasPrerenderedUrl(GURL gurl) { 241a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender::PrerenderManager* prerender_manager = GetPrerenderManager(); 242a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!prerender_manager) 243a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return false; 244a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 245a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) std::vector<content::WebContents*> contents = 246a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender_manager->GetAllPrerenderingContents(); 247a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender::PrerenderContents* prerender_contents; 248a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) for (size_t i = 0; i < contents.size(); ++i) { 249a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender_contents = prerender_manager-> 250a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GetPrerenderContents(contents.at(i)); 251a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (prerender_contents->prerender_url() == gurl && 252a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender_contents->has_finished_loading()) { 253a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return true; 254a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 255a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 256a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return false; 257a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 258a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 259116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid TabAndroid::MakeLoadURLParams( 260116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch chrome::NavigateParams* params, 261116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch NavigationController::LoadURLParams* load_url_params) { 262116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->referrer = params->referrer; 263116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->frame_tree_node_id = params->frame_tree_node_id; 264116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->redirect_chain = params->redirect_chain; 265116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->transition_type = params->transition; 266116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->extra_headers = params->extra_headers; 267116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->should_replace_current_entry = 268116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->should_replace_current_entry; 269116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 270116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (params->transferred_global_request_id != GlobalRequestID()) { 271116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->transferred_global_request_id = 272116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->transferred_global_request_id; 273116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 274116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->is_renderer_initiated = params->is_renderer_initiated; 275116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 276116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Only allows the browser-initiated navigation to use POST. 277116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (params->uses_post && !params->is_renderer_initiated) { 278116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->load_type = 279116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; 280116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->browser_initiated_post_data = 281116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->browser_initiated_post_data; 282116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 283116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} 284116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 285424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void TabAndroid::SwapTabContents(content::WebContents* old_contents, 2865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::WebContents* new_contents, 2875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool did_start_load, 2885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool did_finish_load) { 289424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 2904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // We need to notify the native InfobarContainer so infobars can be swapped. 2924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) InfoBarContainerAndroid* infobar_container = 2934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) reinterpret_cast<InfoBarContainerAndroid*>( 294a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_getNativeInfoBarContainer( 2954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) env, 2964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) weak_java_tab_.get(env).obj())); 297a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch InfoBarService* new_infobar_service = 298a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch new_contents ? InfoBarService::FromWebContents(new_contents) : NULL; 299a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch infobar_container->ChangeInfoBarManager(new_infobar_service); 3004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 301a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_swapWebContents( 302424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) env, 303424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) weak_java_tab_.get(env).obj(), 3045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) reinterpret_cast<intptr_t>(new_contents), 3055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) did_start_load, 3065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) did_finish_load); 307424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 308424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 30958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void TabAndroid::Observe(int type, 31058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const content::NotificationSource& source, 31158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const content::NotificationDetails& details) { 31258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 31358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) switch (type) { 31458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: { 31558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) TabSpecificContentSettings* settings = 31658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) TabSpecificContentSettings::FromWebContents(web_contents()); 31758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (!settings->IsBlockageIndicated(CONTENT_SETTINGS_TYPE_POPUPS)) { 31858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // TODO(dfalcantara): Create an InfoBarDelegate to keep the 31958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // PopupBlockedInfoBar logic native-side instead of straddling the JNI 32058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // boundary. 32158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) int num_popups = 0; 32258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) PopupBlockerTabHelper* popup_blocker_helper = 32358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) PopupBlockerTabHelper::FromWebContents(web_contents()); 32458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (popup_blocker_helper) 32558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) num_popups = popup_blocker_helper->GetBlockedPopupsCount(); 32658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 3275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (num_popups > 0) 3285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PopupBlockedInfoBarDelegate::Create(web_contents(), num_popups); 329f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 33058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) settings->SetBlockageHasBeenIndicated(CONTENT_SETTINGS_TYPE_POPUPS); 33158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 33258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) break; 33358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 33458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) case chrome::NOTIFICATION_FAVICON_UPDATED: 335a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_onFaviconUpdated(env, weak_java_tab_.get(env).obj()); 33658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) break; 3375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case content::NOTIFICATION_NAV_ENTRY_CHANGED: 338a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_onNavEntryChanged(env, weak_java_tab_.get(env).obj()); 3395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) break; 34058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) default: 34158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) NOTREACHED() << "Unexpected notification " << type; 34258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) break; 34358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 34458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 34558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 3465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void TabAndroid::Destroy(JNIEnv* env, jobject obj) { 3475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) delete this; 3485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 350424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void TabAndroid::InitWebContents(JNIEnv* env, 351424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jobject obj, 352424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jboolean incognito, 353424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jobject jcontent_view_core, 354a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) jobject jweb_contents_delegate, 355a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) jobject jcontext_menu_populator) { 356424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) content::ContentViewCore* content_view_core = 357424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) content::ContentViewCore::GetNativeContentViewCore(env, 358424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jcontent_view_core); 359424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DCHECK(content_view_core); 360424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DCHECK(content_view_core->GetWebContents()); 361424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 362424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents_.reset(content_view_core->GetWebContents()); 36323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) AttachTabHelpers(web_contents_.get()); 364424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 365a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) SetWindowSessionID(session_window_id_.id()); 366a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 367424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) session_tab_id_.set_id( 368424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) SessionTabHelper::FromWebContents(web_contents())->session_id().id()); 369a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ContextMenuHelper::FromWebContents(web_contents())->SetPopulator( 370a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) jcontext_menu_populator); 371424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) WindowAndroidHelper::FromWebContents(web_contents())-> 372424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) SetWindowAndroid(content_view_core->GetWindowAndroid()); 373424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CoreTabHelper::FromWebContents(web_contents())->set_delegate(this); 374424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents_delegate_.reset( 375424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) new chrome::android::ChromeWebContentsDelegateAndroid( 376424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) env, jweb_contents_delegate)); 377424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents_delegate_->LoadProgressChanged(web_contents(), 0); 378424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents()->SetDelegate(web_contents_delegate_.get()); 379424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 38058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) notification_registrar_.Add( 38158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) this, 38258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, 38358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) content::Source<content::WebContents>(web_contents())); 38458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) notification_registrar_.Add( 38558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) this, 38658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) chrome::NOTIFICATION_FAVICON_UPDATED, 38758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) content::Source<content::WebContents>(web_contents())); 3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) notification_registrar_.Add( 3895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) this, 3905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::NOTIFICATION_NAV_ENTRY_CHANGED, 3915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::Source<content::NavigationController>( 3925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) &web_contents()->GetController())); 39358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 39458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) synced_tab_delegate_->SetWebContents(web_contents()); 39558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 396424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Verify that the WebContents this tab represents matches the expected 397424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // off the record state. 398424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CHECK_EQ(GetProfile()->IsOffTheRecord(), incognito); 399424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 400424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 401424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void TabAndroid::DestroyWebContents(JNIEnv* env, 402424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jobject obj, 403424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jboolean delete_native) { 40458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) DCHECK(web_contents()); 40558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 40658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) notification_registrar_.Remove( 40758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) this, 40858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, 40958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) content::Source<content::WebContents>(web_contents())); 41058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) notification_registrar_.Remove( 41158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) this, 41258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) chrome::NOTIFICATION_FAVICON_UPDATED, 41358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) content::Source<content::WebContents>(web_contents())); 41423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) notification_registrar_.Remove( 41523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) this, 41623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) content::NOTIFICATION_NAV_ENTRY_CHANGED, 41723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) content::Source<content::NavigationController>( 41823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) &web_contents()->GetController())); 41958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 420424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents()->SetDelegate(NULL); 421424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 422424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (delete_native) { 423424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents_.reset(); 42458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) synced_tab_delegate_->ResetWebContents(); 425424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } else { 426424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Release the WebContents so it does not get deleted by the scoped_ptr. 427424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) ignore_result(web_contents_.release()); 428424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } 429424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 430424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 4315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetWebContents( 4325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) JNIEnv* env, 4335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) jobject obj) { 4345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!web_contents_.get()) 4355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return base::android::ScopedJavaLocalRef<jobject>(); 4365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return web_contents_->GetJavaWebContents(); 4375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 4385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 439424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetProfileAndroid( 440424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) JNIEnv* env, 441424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jobject obj) { 442424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Profile* profile = GetProfile(); 443424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!profile) 444424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return base::android::ScopedJavaLocalRef<jobject>(); 445424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) ProfileAndroid* profile_android = ProfileAndroid::FromProfile(profile); 446424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!profile_android) 447424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return base::android::ScopedJavaLocalRef<jobject>(); 448424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 449424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return profile_android->GetJavaObject(); 450424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 451424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 452a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)TabAndroid::TabLoadStatus TabAndroid::LoadUrl(JNIEnv* env, 453a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) jobject obj, 454a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) jstring url, 455a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) jstring j_extra_headers, 456a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) jbyteArray j_post_data, 457a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) jint page_transition, 458a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) jstring j_referrer_url, 459cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) jint referrer_policy, 460cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) jboolean is_renderer_initiated) { 461a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content::ContentViewCore* content_view = GetContentViewCore(); 462a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!content_view) 463a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return PAGE_LOAD_FAILED; 464a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 465a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GURL gurl(base::android::ConvertJavaStringToUTF8(env, url)); 466a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (gurl.is_empty()) 467a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return PAGE_LOAD_FAILED; 468a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 469a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // If the page was prerendered, use it. 470a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Note in incognito mode, we don't have a PrerenderManager. 471a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 472a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender::PrerenderManager* prerender_manager = 473a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender::PrerenderManagerFactory::GetForProfile(GetProfile()); 474a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (prerender_manager) { 475a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool prefetched_page_loaded = HasPrerenderedUrl(gurl); 476a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Getting the load status before MaybeUsePrerenderedPage() b/c it resets. 477a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) chrome::NavigateParams params(NULL, web_contents()); 478f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) InstantSearchPrerenderer* prerenderer = 479f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) InstantSearchPrerenderer::GetForProfile(GetProfile()); 480f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) if (prerenderer) { 481f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) const base::string16& search_terms = 482f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) chrome::ExtractSearchTermsFromURL(GetProfile(), gurl); 483f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) if (!search_terms.empty() && 484f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) prerenderer->CanCommitQuery(web_contents_.get(), search_terms)) { 485f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) prerenderer->Commit(search_terms); 486f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 487f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) if (prerenderer->UsePrerenderedPage(gurl, ¶ms)) 488f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) return FULL_PRERENDERED_PAGE_LOAD; 489f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) } 490f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) prerenderer->Cancel(); 491f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) } 492a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (prerender_manager->MaybeUsePrerenderedPage(gurl, ¶ms)) { 493a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return prefetched_page_loaded ? 494a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FULL_PRERENDERED_PAGE_LOAD : PARTIAL_PRERENDERED_PAGE_LOAD; 495a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 496a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 497a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 498f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) GURL fixed_url( 499f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) url_fixer::FixupURL(gurl.possibly_invalid_spec(), std::string())); 500a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!fixed_url.is_valid()) 501a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return PAGE_LOAD_FAILED; 502a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 503a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!HandleNonNavigationAboutURL(fixed_url)) { 504a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Notify the GoogleURLTracker of searches, it might want to change the 505a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // actual Google site used (for instance when in the UK, google.co.uk, when 506a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // in the US google.com). 507a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Note that this needs to happen before we initiate the navigation as the 508a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // GoogleURLTracker uses the navigation pending notification to trigger the 509a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // infobar. 510a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (google_util::IsGoogleSearchUrl(fixed_url) && 511a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) (page_transition & content::PAGE_TRANSITION_GENERATED)) { 51246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) GoogleURLTracker* tracker = 51346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) GoogleURLTrackerFactory::GetForProfile(GetProfile()); 51446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) if (tracker) 51546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) tracker->SearchCommitted(); 516a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 517a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 518a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Record UMA "ShowHistory" here. That way it'll pick up both user 519a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // typing chrome://history as well as selecting from the drop down menu. 520a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (fixed_url.spec() == chrome::kChromeUIHistoryURL) { 521a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content::RecordAction(base::UserMetricsAction("ShowHistory")); 522a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 523a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 524a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content::NavigationController::LoadURLParams load_params(fixed_url); 525a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (j_extra_headers) { 526a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) load_params.extra_headers = base::android::ConvertJavaStringToUTF8( 527a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) env, 528a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) j_extra_headers); 529a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 530a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (j_post_data) { 531a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) load_params.load_type = 532a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content::NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; 533a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) std::vector<uint8> post_data; 534a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::android::JavaByteArrayToByteVector(env, j_post_data, &post_data); 535a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) load_params.browser_initiated_post_data = 536a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::RefCountedBytes::TakeVector(&post_data); 537a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 538a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) load_params.transition_type = 539a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content::PageTransitionFromInt(page_transition); 540a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (j_referrer_url) { 541a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) load_params.referrer = content::Referrer( 542a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GURL(base::android::ConvertJavaStringToUTF8(env, j_referrer_url)), 543a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) static_cast<blink::WebReferrerPolicy>(referrer_policy)); 544a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 5455c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const base::string16 search_terms = 5465c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu chrome::ExtractSearchTermsFromURL(GetProfile(), gurl); 5475c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu SearchTabHelper* search_tab_helper = 5485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu SearchTabHelper::FromWebContents(web_contents_.get()); 5495c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu if (!search_terms.empty() && search_tab_helper && 5505c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu search_tab_helper->SupportsInstant()) { 5515c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu search_tab_helper->Submit(search_terms); 5525c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu return DEFAULT_PAGE_LOAD; 5535c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu } 554cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) load_params.is_renderer_initiated = is_renderer_initiated; 555a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content_view->LoadUrl(load_params); 556a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 557a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return DEFAULT_PAGE_LOAD; 558a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 559a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 56058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)ToolbarModel::SecurityLevel TabAndroid::GetSecurityLevel(JNIEnv* env, 56158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) jobject obj) { 56258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return ToolbarModelImpl::GetSecurityLevelForWebContents(web_contents()); 56358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 56458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 5654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void TabAndroid::SetActiveNavigationEntryTitleForUrl(JNIEnv* env, 5664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) jobject obj, 5674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) jstring jurl, 5684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) jstring jtitle) { 5694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) DCHECK(web_contents()); 5704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 571a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 title; 5724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (jtitle) 5734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) title = base::android::ConvertJavaStringToUTF16(env, jtitle); 5744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 5754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::string url; 5764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (jurl) 5774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) url = base::android::ConvertJavaStringToUTF8(env, jurl); 5784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 5794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::NavigationEntry* entry = 5804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) web_contents()->GetController().GetVisibleEntry(); 5814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (entry && url == entry->GetVirtualURL().spec()) 5824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) entry->SetTitle(title); 5834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 5844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 585f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)bool TabAndroid::Print(JNIEnv* env, jobject obj) { 586f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (!web_contents()) 587f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return false; 588f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 589f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) printing::PrintViewManagerBasic::CreateForWebContents(web_contents()); 590f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) printing::PrintViewManagerBasic* print_view_manager = 591f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) printing::PrintViewManagerBasic::FromWebContents(web_contents()); 592f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (print_view_manager == NULL) 593f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return false; 594f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 595f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) print_view_manager->PrintNow(); 596f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return true; 597f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 598f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 5996e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)ScopedJavaLocalRef<jobject> TabAndroid::GetFavicon(JNIEnv* env, jobject obj) { 6006e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ScopedJavaLocalRef<jobject> bitmap; 6016e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) FaviconTabHelper* favicon_tab_helper = 6026e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) FaviconTabHelper::FromWebContents(web_contents_.get()); 6036e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 6046e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) if (!favicon_tab_helper) 6056e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return bitmap; 6066e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) if (!favicon_tab_helper->FaviconIsValid()) 6076e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return bitmap; 6086e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 6096e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) SkBitmap favicon = 6106e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) favicon_tab_helper->GetFavicon() 6116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) .AsImageSkia() 6126e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) .GetRepresentation( 6136e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ResourceBundle::GetSharedInstance().GetMaxScaleFactor()) 6146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) .sk_bitmap(); 6156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 6166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) if (favicon.empty()) { 6176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) favicon = favicon_tab_helper->GetFavicon().AsBitmap(); 6186e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) } 6196e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 6206e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) if (!favicon.empty()) { 6216e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) gfx::DeviceDisplayInfo device_info; 6226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) const float device_scale_factor = device_info.GetDIPScale(); 6236e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) int target_size_dip = device_scale_factor * gfx::kFaviconSize; 6246e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) if (favicon.width() != target_size_dip || 6256e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) favicon.height() != target_size_dip) { 6266e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) favicon = 6276e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) skia::ImageOperations::Resize(favicon, 6286e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) skia::ImageOperations::RESIZE_BEST, 6296e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) target_size_dip, 6306e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) target_size_dip); 6316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) } 6326e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 6336e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) bitmap = gfx::ConvertToJavaBitmap(&favicon); 6346e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) } 6356e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return bitmap; 6366e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} 6376e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 638a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)prerender::PrerenderManager* TabAndroid::GetPrerenderManager() const { 639a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Profile* profile = GetProfile(); 640a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!profile) 641a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return NULL; 642a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return prerender::PrerenderManagerFactory::GetForProfile(profile); 643a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 644a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 6455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)static void Init(JNIEnv* env, jobject obj) { 6465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TRACE_EVENT0("native", "TabAndroid::Init"); 6475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // This will automatically bind to the Java object and pass ownership there. 6485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new TabAndroid(env, obj); 6495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 6505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 651c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { 652c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return RegisterNativesImpl(env); 653c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 654