tab_android.cc revision 116680a4aac90f2aa7413d9095a592090648e557
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" 1546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "chrome/browser/google/google_url_tracker_factory.h" 16c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "chrome/browser/infobars/infobar_service.h" 17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/prerender/prerender_contents.h" 18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/prerender/prerender_manager.h" 19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/prerender/prerender_manager_factory.h" 20f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/printing/print_view_manager_basic.h" 21424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "chrome/browser/profiles/profile.h" 22424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "chrome/browser/profiles/profile_android.h" 235c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "chrome/browser/search/search.h" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/sessions/session_tab_helper.h" 2558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/sync/glue/synced_tab_delegate_android.h" 26116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "chrome/browser/tab_contents/tab_util.h" 27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.h" 28a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/browser/ui/android/context_menu_helper.h" 294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/android/infobars/infobar_container_android.h" 3058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/ui/android/tab_model/tab_model.h" 3158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/ui/android/tab_model/tab_model_list.h" 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/android/window_android_helper.h" 33424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" 34f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "chrome/browser/ui/search/instant_search_prerenderer.h" 355c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "chrome/browser/ui/search/search_tab_helper.h" 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/tab_contents/core_tab_helper.h" 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/tab_helpers.h" 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/toolbar/toolbar_model_impl.h" 39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/common/url_constants.h" 40f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "components/google/core/browser/google_url_tracker.h" 416d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "components/google/core/browser/google_util.h" 420529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "components/infobars/core/infobar_container.h" 43f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "components/url_fixer/url_fixer.h" 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/android/content_view_core.h" 454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "content/public/browser/navigation_entry.h" 4658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "content/public/browser/notification_service.h" 47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "content/public/browser/user_metrics.h" 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h" 49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "jni/Tab_jni.h" 50a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "third_party/WebKit/public/platform/WebReferrerPolicy.h" 51116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "ui/base/window_open_disposition.h" 52116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 53116680a4aac90f2aa7413d9095a592090648e557Ben Murdochusing content::GlobalRequestID; 54116680a4aac90f2aa7413d9095a592090648e557Ben Murdochusing content::NavigationController; 55116680a4aac90f2aa7413d9095a592090648e557Ben Murdochusing content::WebContents; 56116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 57116680a4aac90f2aa7413d9095a592090648e557Ben Murdochnamespace { 58116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 59116680a4aac90f2aa7413d9095a592090648e557Ben MurdochWebContents* CreateTargetContents(const chrome::NavigateParams& params, 60116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const GURL& url) { 61116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch Profile* profile = params.initiating_profile; 62116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 63116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (profile->IsOffTheRecord() || params.disposition == OFF_THE_RECORD) { 64116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch profile = profile->GetOffTheRecordProfile(); 65116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 66116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch WebContents::CreateParams create_params( 67116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch profile, tab_util::GetSiteInstanceForNewTab(profile, url)); 68116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (params.source_contents) { 69116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch create_params.initial_size = 70116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params.source_contents->GetContainerBounds().size(); 71116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (params.should_set_opener) 72116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch create_params.opener = params.source_contents; 73116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 74116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (params.disposition == NEW_BACKGROUND_TAB) 75116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch create_params.initially_hidden = true; 76116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 77116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch WebContents* target_contents = WebContents::Create(create_params); 78116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 79116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return target_contents; 80116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} 81116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 82116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} // namespace 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 84424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TabAndroid* TabAndroid::FromWebContents(content::WebContents* web_contents) { 85424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(web_contents); 86424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!core_tab_helper) 87424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return NULL; 88424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 89424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); 90424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!core_delegate) 91424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return NULL; 92424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 93424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return static_cast<TabAndroid*>(core_delegate); 94424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 95424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 96424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TabAndroid* TabAndroid::GetNativeTab(JNIEnv* env, jobject obj) { 97a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return reinterpret_cast<TabAndroid*>(Java_Tab_getNativePtr(env, obj)); 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)void TabAndroid::AttachTabHelpers(content::WebContents* web_contents) { 10123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) DCHECK(web_contents); 10223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 10323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) TabHelpers::AttachTabHelpers(web_contents); 10423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)} 10523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 106424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TabAndroid::TabAndroid(JNIEnv* env, jobject obj) 107424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) : weak_java_tab_(env, obj), 10858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)) { 109a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_setNativePtr(env, obj, reinterpret_cast<intptr_t>(this)); 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)TabAndroid::~TabAndroid() { 11358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 11458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 11558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (obj.is_null()) 11658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return; 11758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 118a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_clearNativePtr(env, obj.obj()); 11958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 12058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetJavaObject() { 1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return weak_java_tab_.get(env); 1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)int TabAndroid::GetAndroidId() const { 1278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 1298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (obj.is_null()) 1308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return -1; 131a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return Java_Tab_getId(env, obj.obj()); 1328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 1338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1340f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)int TabAndroid::GetSyncId() const { 1350f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1360f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 1370f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (obj.is_null()) 1380f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return 0; 139a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return Java_Tab_getSyncId(env, obj.obj()); 1400f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 1410f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 142a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)base::string16 TabAndroid::GetTitle() const { 1438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 1458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (obj.is_null()) 146a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return base::string16(); 1478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return base::android::ConvertJavaStringToUTF16( 148a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_getTitle(env, obj.obj())); 1498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 1508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)GURL TabAndroid::GetURL() const { 1528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 1548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (obj.is_null()) 1558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return GURL::EmptyGURL(); 1568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return GURL(base::android::ConvertJavaStringToUTF8( 157a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_getUrl(env, obj.obj()))); 1588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 1598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 160e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochbool TabAndroid::LoadIfNeeded() { 1618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 1638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (obj.is_null()) 1648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return false; 165e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch return Java_Tab_loadIfNeeded(env, obj.obj()); 1668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 1678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 168424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)content::ContentViewCore* TabAndroid::GetContentViewCore() const { 169424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!web_contents()) 170424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return NULL; 171424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 172424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return content::ContentViewCore::FromWebContents(web_contents()); 173424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 174424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 175424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)Profile* TabAndroid::GetProfile() const { 176424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!web_contents()) 177424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return NULL; 178424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 179424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 180424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 181424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 18258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)browser_sync::SyncedTabDelegate* TabAndroid::GetSyncedTabDelegate() const { 18358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return synced_tab_delegate_.get(); 1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 186a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void TabAndroid::SetWindowSessionID(SessionID::id_type window_id) { 187a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) session_window_id_.set_id(window_id); 188a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 189a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!web_contents()) 190a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return; 191a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 192a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) SessionTabHelper* session_tab_helper = 193a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) SessionTabHelper::FromWebContents(web_contents()); 194a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) session_tab_helper->SetWindowID(session_window_id_); 195a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 196a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 1970f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)void TabAndroid::SetSyncId(int sync_id) { 1980f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1990f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 2000f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (obj.is_null()) 2010f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return; 202a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_setSyncId(env, obj.obj(), sync_id); 2030f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 2040f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void TabAndroid::HandlePopupNavigation(chrome::NavigateParams* params) { 206116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (params->disposition != SUPPRESS_OPEN && 207116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->disposition != SAVE_TO_DISK && 208116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->disposition != IGNORE_ACTION) { 209116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (!params->url.is_empty()) { 210116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool was_blocked = false; 211116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch GURL url(params->url); 212116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch NavigationController::LoadURLParams load_url_params(url); 213116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch MakeLoadURLParams(params, &load_url_params); 214116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (params->disposition == CURRENT_TAB) { 215116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch web_contents_.get()->GetController().LoadURLWithParams(load_url_params); 216116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } else { 217116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->target_contents = CreateTargetContents(*params, url); 218116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->target_contents->GetController().LoadURLWithParams( 219116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params); 220116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch web_contents_delegate_->AddNewContents(params->source_contents, 221116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->target_contents, 222116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->disposition, 223116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->window_bounds, 224116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->user_gesture, 225116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch &was_blocked); 226116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (was_blocked) 227116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->target_contents = NULL; 228116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 229116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 230116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 2315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool TabAndroid::ShouldWelcomePageLinkToTermsOfService() { 2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NOTIMPLEMENTED(); 2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return false; 2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 238a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool TabAndroid::HasPrerenderedUrl(GURL gurl) { 239a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender::PrerenderManager* prerender_manager = GetPrerenderManager(); 240a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!prerender_manager) 241a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return false; 242a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 243a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) std::vector<content::WebContents*> contents = 244a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender_manager->GetAllPrerenderingContents(); 245a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender::PrerenderContents* prerender_contents; 246a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) for (size_t i = 0; i < contents.size(); ++i) { 247a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender_contents = prerender_manager-> 248a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GetPrerenderContents(contents.at(i)); 249a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (prerender_contents->prerender_url() == gurl && 250a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender_contents->has_finished_loading()) { 251a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return true; 252a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 253a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 254a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return false; 255a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 256a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 257116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid TabAndroid::MakeLoadURLParams( 258116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch chrome::NavigateParams* params, 259116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch NavigationController::LoadURLParams* load_url_params) { 260116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->referrer = params->referrer; 261116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->frame_tree_node_id = params->frame_tree_node_id; 262116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->redirect_chain = params->redirect_chain; 263116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->transition_type = params->transition; 264116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->extra_headers = params->extra_headers; 265116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->should_replace_current_entry = 266116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->should_replace_current_entry; 267116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 268116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (params->transferred_global_request_id != GlobalRequestID()) { 269116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->transferred_global_request_id = 270116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->transferred_global_request_id; 271116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 272116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->is_renderer_initiated = params->is_renderer_initiated; 273116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 274116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Only allows the browser-initiated navigation to use POST. 275116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (params->uses_post && !params->is_renderer_initiated) { 276116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->load_type = 277116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; 278116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch load_url_params->browser_initiated_post_data = 279116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch params->browser_initiated_post_data; 280116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 281116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} 282116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 283424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void TabAndroid::SwapTabContents(content::WebContents* old_contents, 2845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::WebContents* new_contents, 2855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool did_start_load, 2865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool did_finish_load) { 287424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 2884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // We need to notify the native InfobarContainer so infobars can be swapped. 2904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) InfoBarContainerAndroid* infobar_container = 2914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) reinterpret_cast<InfoBarContainerAndroid*>( 292a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_getNativeInfoBarContainer( 2934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) env, 2944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) weak_java_tab_.get(env).obj())); 295a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch InfoBarService* new_infobar_service = 296a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch new_contents ? InfoBarService::FromWebContents(new_contents) : NULL; 297a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch infobar_container->ChangeInfoBarManager(new_infobar_service); 2984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 299a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_swapWebContents( 300424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) env, 301424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) weak_java_tab_.get(env).obj(), 3025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) reinterpret_cast<intptr_t>(new_contents), 3035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) did_start_load, 3045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) did_finish_load); 305424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 306424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 30758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void TabAndroid::Observe(int type, 30858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const content::NotificationSource& source, 30958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const content::NotificationDetails& details) { 31058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 31158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) switch (type) { 31258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: { 31358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) TabSpecificContentSettings* settings = 31458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) TabSpecificContentSettings::FromWebContents(web_contents()); 31558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (!settings->IsBlockageIndicated(CONTENT_SETTINGS_TYPE_POPUPS)) { 31658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // TODO(dfalcantara): Create an InfoBarDelegate to keep the 31758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // PopupBlockedInfoBar logic native-side instead of straddling the JNI 31858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // boundary. 31958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) int num_popups = 0; 32058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) PopupBlockerTabHelper* popup_blocker_helper = 32158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) PopupBlockerTabHelper::FromWebContents(web_contents()); 32258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (popup_blocker_helper) 32358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) num_popups = popup_blocker_helper->GetBlockedPopupsCount(); 32458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 3255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (num_popups > 0) 3265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PopupBlockedInfoBarDelegate::Create(web_contents(), num_popups); 327f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 32858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) settings->SetBlockageHasBeenIndicated(CONTENT_SETTINGS_TYPE_POPUPS); 32958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 33058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) break; 33158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 33258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) case chrome::NOTIFICATION_FAVICON_UPDATED: 333a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_onFaviconUpdated(env, weak_java_tab_.get(env).obj()); 33458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) break; 3355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case content::NOTIFICATION_NAV_ENTRY_CHANGED: 336a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_onNavEntryChanged(env, weak_java_tab_.get(env).obj()); 3375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) break; 33858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) default: 33958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) NOTREACHED() << "Unexpected notification " << type; 34058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) break; 34158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 34258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 34358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 3445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void TabAndroid::Destroy(JNIEnv* env, jobject obj) { 3455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) delete this; 3465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 348424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void TabAndroid::InitWebContents(JNIEnv* env, 349424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jobject obj, 350424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jboolean incognito, 351424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jobject jcontent_view_core, 352a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) jobject jweb_contents_delegate, 353a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) jobject jcontext_menu_populator) { 354424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) content::ContentViewCore* content_view_core = 355424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) content::ContentViewCore::GetNativeContentViewCore(env, 356424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jcontent_view_core); 357424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DCHECK(content_view_core); 358424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DCHECK(content_view_core->GetWebContents()); 359424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 360424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents_.reset(content_view_core->GetWebContents()); 36123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) AttachTabHelpers(web_contents_.get()); 362424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 363a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) SetWindowSessionID(session_window_id_.id()); 364a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 365424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) session_tab_id_.set_id( 366424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) SessionTabHelper::FromWebContents(web_contents())->session_id().id()); 367a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ContextMenuHelper::FromWebContents(web_contents())->SetPopulator( 368a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) jcontext_menu_populator); 369424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) WindowAndroidHelper::FromWebContents(web_contents())-> 370424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) SetWindowAndroid(content_view_core->GetWindowAndroid()); 371424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CoreTabHelper::FromWebContents(web_contents())->set_delegate(this); 372424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents_delegate_.reset( 373424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) new chrome::android::ChromeWebContentsDelegateAndroid( 374424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) env, jweb_contents_delegate)); 375424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents_delegate_->LoadProgressChanged(web_contents(), 0); 376424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents()->SetDelegate(web_contents_delegate_.get()); 377424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 37858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) notification_registrar_.Add( 37958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) this, 38058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, 38158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) content::Source<content::WebContents>(web_contents())); 38258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) notification_registrar_.Add( 38358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) this, 38458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) chrome::NOTIFICATION_FAVICON_UPDATED, 38558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) content::Source<content::WebContents>(web_contents())); 3865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) notification_registrar_.Add( 3875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) this, 3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::NOTIFICATION_NAV_ENTRY_CHANGED, 3895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::Source<content::NavigationController>( 3905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) &web_contents()->GetController())); 39158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 39258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) synced_tab_delegate_->SetWebContents(web_contents()); 39358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 394424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Verify that the WebContents this tab represents matches the expected 395424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // off the record state. 396424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CHECK_EQ(GetProfile()->IsOffTheRecord(), incognito); 397424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 398424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 399424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void TabAndroid::DestroyWebContents(JNIEnv* env, 400424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jobject obj, 401424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jboolean delete_native) { 40258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) DCHECK(web_contents()); 40358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 40458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) notification_registrar_.Remove( 40558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) this, 40658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, 40758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) content::Source<content::WebContents>(web_contents())); 40858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) notification_registrar_.Remove( 40958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) this, 41058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) chrome::NOTIFICATION_FAVICON_UPDATED, 41158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) content::Source<content::WebContents>(web_contents())); 41223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) notification_registrar_.Remove( 41323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) this, 41423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) content::NOTIFICATION_NAV_ENTRY_CHANGED, 41523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) content::Source<content::NavigationController>( 41623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) &web_contents()->GetController())); 41758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 418424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents()->SetDelegate(NULL); 419424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 420424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (delete_native) { 421424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents_.reset(); 42258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) synced_tab_delegate_->ResetWebContents(); 423424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } else { 424424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Release the WebContents so it does not get deleted by the scoped_ptr. 425424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) ignore_result(web_contents_.release()); 426424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } 427424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 428424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 4295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetWebContents( 4305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) JNIEnv* env, 4315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) jobject obj) { 4325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!web_contents_.get()) 4335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return base::android::ScopedJavaLocalRef<jobject>(); 4345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return web_contents_->GetJavaWebContents(); 4355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 4365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 437424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetProfileAndroid( 438424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) JNIEnv* env, 439424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jobject obj) { 440424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Profile* profile = GetProfile(); 441424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!profile) 442424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return base::android::ScopedJavaLocalRef<jobject>(); 443424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) ProfileAndroid* profile_android = ProfileAndroid::FromProfile(profile); 444424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!profile_android) 445424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return base::android::ScopedJavaLocalRef<jobject>(); 446424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 447424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return profile_android->GetJavaObject(); 448424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 449424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 450a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)TabAndroid::TabLoadStatus TabAndroid::LoadUrl(JNIEnv* env, 451a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) jobject obj, 452a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) jstring url, 453a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) jstring j_extra_headers, 454a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) jbyteArray j_post_data, 455a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) jint page_transition, 456a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) jstring j_referrer_url, 457cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) jint referrer_policy, 458cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) jboolean is_renderer_initiated) { 459a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content::ContentViewCore* content_view = GetContentViewCore(); 460a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!content_view) 461a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return PAGE_LOAD_FAILED; 462a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 463a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GURL gurl(base::android::ConvertJavaStringToUTF8(env, url)); 464a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (gurl.is_empty()) 465a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return PAGE_LOAD_FAILED; 466a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 467a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // If the page was prerendered, use it. 468a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Note in incognito mode, we don't have a PrerenderManager. 469a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 470a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender::PrerenderManager* prerender_manager = 471a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender::PrerenderManagerFactory::GetForProfile(GetProfile()); 472a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (prerender_manager) { 473a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool prefetched_page_loaded = HasPrerenderedUrl(gurl); 474a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Getting the load status before MaybeUsePrerenderedPage() b/c it resets. 475a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) chrome::NavigateParams params(NULL, web_contents()); 476f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) InstantSearchPrerenderer* prerenderer = 477f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) InstantSearchPrerenderer::GetForProfile(GetProfile()); 478f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) if (prerenderer) { 479f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) const base::string16& search_terms = 480f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) chrome::ExtractSearchTermsFromURL(GetProfile(), gurl); 481f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) if (!search_terms.empty() && 482f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) prerenderer->CanCommitQuery(web_contents_.get(), search_terms)) { 483f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) prerenderer->Commit(search_terms); 484f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 485f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) if (prerenderer->UsePrerenderedPage(gurl, ¶ms)) 486f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) return FULL_PRERENDERED_PAGE_LOAD; 487f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) } 488f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) prerenderer->Cancel(); 489f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) } 490a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (prerender_manager->MaybeUsePrerenderedPage(gurl, ¶ms)) { 491a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return prefetched_page_loaded ? 492a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FULL_PRERENDERED_PAGE_LOAD : PARTIAL_PRERENDERED_PAGE_LOAD; 493a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 494a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 495a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 496f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) GURL fixed_url( 497f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) url_fixer::FixupURL(gurl.possibly_invalid_spec(), std::string())); 498a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!fixed_url.is_valid()) 499a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return PAGE_LOAD_FAILED; 500a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 501a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!HandleNonNavigationAboutURL(fixed_url)) { 502a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Notify the GoogleURLTracker of searches, it might want to change the 503a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // actual Google site used (for instance when in the UK, google.co.uk, when 504a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // in the US google.com). 505a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Note that this needs to happen before we initiate the navigation as the 506a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // GoogleURLTracker uses the navigation pending notification to trigger the 507a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // infobar. 508a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (google_util::IsGoogleSearchUrl(fixed_url) && 509a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) (page_transition & content::PAGE_TRANSITION_GENERATED)) { 51046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) GoogleURLTracker* tracker = 51146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) GoogleURLTrackerFactory::GetForProfile(GetProfile()); 51246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) if (tracker) 51346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) tracker->SearchCommitted(); 514a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 515a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 516a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Record UMA "ShowHistory" here. That way it'll pick up both user 517a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // typing chrome://history as well as selecting from the drop down menu. 518a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (fixed_url.spec() == chrome::kChromeUIHistoryURL) { 519a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content::RecordAction(base::UserMetricsAction("ShowHistory")); 520a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 521a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 522a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content::NavigationController::LoadURLParams load_params(fixed_url); 523a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (j_extra_headers) { 524a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) load_params.extra_headers = base::android::ConvertJavaStringToUTF8( 525a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) env, 526a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) j_extra_headers); 527a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 528a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (j_post_data) { 529a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) load_params.load_type = 530a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content::NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; 531a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) std::vector<uint8> post_data; 532a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::android::JavaByteArrayToByteVector(env, j_post_data, &post_data); 533a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) load_params.browser_initiated_post_data = 534a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::RefCountedBytes::TakeVector(&post_data); 535a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 536a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) load_params.transition_type = 537a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content::PageTransitionFromInt(page_transition); 538a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (j_referrer_url) { 539a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) load_params.referrer = content::Referrer( 540a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GURL(base::android::ConvertJavaStringToUTF8(env, j_referrer_url)), 541a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) static_cast<blink::WebReferrerPolicy>(referrer_policy)); 542a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 5435c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const base::string16 search_terms = 5445c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu chrome::ExtractSearchTermsFromURL(GetProfile(), gurl); 5455c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu SearchTabHelper* search_tab_helper = 5465c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu SearchTabHelper::FromWebContents(web_contents_.get()); 5475c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu if (!search_terms.empty() && search_tab_helper && 5485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu search_tab_helper->SupportsInstant()) { 5495c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu search_tab_helper->Submit(search_terms); 5505c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu return DEFAULT_PAGE_LOAD; 5515c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu } 552cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) load_params.is_renderer_initiated = is_renderer_initiated; 553a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content_view->LoadUrl(load_params); 554a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 555a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return DEFAULT_PAGE_LOAD; 556a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 557a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 55858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)ToolbarModel::SecurityLevel TabAndroid::GetSecurityLevel(JNIEnv* env, 55958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) jobject obj) { 56058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return ToolbarModelImpl::GetSecurityLevelForWebContents(web_contents()); 56158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 56258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 5634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void TabAndroid::SetActiveNavigationEntryTitleForUrl(JNIEnv* env, 5644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) jobject obj, 5654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) jstring jurl, 5664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) jstring jtitle) { 5674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) DCHECK(web_contents()); 5684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 569a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 title; 5704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (jtitle) 5714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) title = base::android::ConvertJavaStringToUTF16(env, jtitle); 5724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 5734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::string url; 5744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (jurl) 5754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) url = base::android::ConvertJavaStringToUTF8(env, jurl); 5764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 5774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::NavigationEntry* entry = 5784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) web_contents()->GetController().GetVisibleEntry(); 5794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (entry && url == entry->GetVirtualURL().spec()) 5804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) entry->SetTitle(title); 5814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 5824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 583f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)bool TabAndroid::Print(JNIEnv* env, jobject obj) { 584f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (!web_contents()) 585f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return false; 586f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 587f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) printing::PrintViewManagerBasic::CreateForWebContents(web_contents()); 588f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) printing::PrintViewManagerBasic* print_view_manager = 589f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) printing::PrintViewManagerBasic::FromWebContents(web_contents()); 590f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (print_view_manager == NULL) 591f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return false; 592f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 593f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) print_view_manager->PrintNow(); 594f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return true; 595f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 596f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 597a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)prerender::PrerenderManager* TabAndroid::GetPrerenderManager() const { 598a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Profile* profile = GetProfile(); 599a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!profile) 600a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return NULL; 601a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return prerender::PrerenderManagerFactory::GetForProfile(profile); 602a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 603a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 6045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)static void Init(JNIEnv* env, jobject obj) { 6055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TRACE_EVENT0("native", "TabAndroid::Init"); 6065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // This will automatically bind to the Java object and pass ownership there. 6075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new TabAndroid(env, obj); 6085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 6095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 610c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { 611c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return RegisterNativesImpl(env); 612c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 613