tab_android.cc revision f2477e01787aa58f445919b809d89e252beef54f
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" 84e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/android/jni_string.h" 9424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "chrome/browser/android/chrome_web_contents_delegate_android.h" 1058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h" 11c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/browser_process.h" 1258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/chrome_notification_types.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/content_settings/tab_specific_content_settings.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/extensions/tab_helper.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/favicon/favicon_tab_helper.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/history/history_tab_helper.h" 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/infobars/infobar_service.h" 18d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "chrome/browser/net/net_error_tab_helper.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/password_manager/password_manager.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/password_manager/password_manager_delegate_impl.h" 214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" 224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/predictors/resource_prefetch_predictor_tab_helper.h" 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/prerender/prerender_tab_helper.h" 24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/printing/print_view_manager_basic.h" 25424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "chrome/browser/profiles/profile.h" 26424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "chrome/browser/profiles/profile_android.h" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/sessions/session_tab_helper.h" 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ssl/ssl_tab_helper.h" 2958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/sync/glue/synced_tab_delegate_android.h" 304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/tab_contents/navigation_metrics_recorder.h" 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/translate/translate_tab_helper.h" 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/alternate_error_tab_observer.h" 33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.h" 344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/android/infobars/infobar_container_android.h" 3558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/ui/android/tab_model/tab_model.h" 3658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/ui/android/tab_model/tab_model_list.h" 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/android/window_android_helper.h" 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" 39424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_tab_contents.h" 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/find_bar/find_tab_helper.h" 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/prefs/prefs_tab_helper.h" 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/tab_contents/core_tab_helper.h" 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/toolbar/toolbar_model_impl.h" 467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "components/autofill/content/browser/autofill_driver_impl.h" 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/android/content_view_core.h" 484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "content/public/browser/navigation_entry.h" 4958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "content/public/browser/notification_service.h" 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h" 51c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "extensions/browser/view_type_utils.h" 52c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "jni/TabBase_jni.h" 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 54f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if defined(ENABLE_MANAGED_USERS) 55f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" 56f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif 57f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace { 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kTabHelpersInitializedUserDataKey[] = 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "TabAndroidTabHelpersInitialized"; 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 65424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void BrowserTabContents::AttachTabHelpers(content::WebContents* contents) { 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If already initialized, nothing to be done. 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::SupportsUserData::Data* initialization_tag = 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) contents->GetUserData(&kTabHelpersInitializedUserDataKey); 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (initialization_tag) 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Mark as initialized. 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) contents->SetUserData(&kTabHelpersInitializedUserDataKey, 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) new base::SupportsUserData::Data()); 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Set the view type. 77c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) extensions::SetViewType(contents, extensions::VIEW_TYPE_TAB_CONTENTS); 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SessionTabHelper comes first because it sets up the tab ID, and other 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // helpers may rely on that. 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SessionTabHelper::CreateForWebContents(contents); 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AlternateErrorPageTabObserver::CreateForWebContents(contents); 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) autofill::TabAutofillManagerDelegate::CreateForWebContents(contents); 877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) autofill::AutofillDriverImpl::CreateForWebContentsAndDelegate( 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) contents, 89c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) autofill::TabAutofillManagerDelegate::FromWebContents(contents), 90a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) g_browser_process->GetApplicationLocale(), 91eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill::AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER); 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BookmarkTabHelper::CreateForWebContents(contents); 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CoreTabHelper::CreateForWebContents(contents); 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extensions::TabHelper::CreateForWebContents(contents); 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FaviconTabHelper::CreateForWebContents(contents); 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FindTabHelper::CreateForWebContents(contents); 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HistoryTabHelper::CreateForWebContents(contents); 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InfoBarService::CreateForWebContents(contents); 994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) NavigationMetricsRecorder::CreateForWebContents(contents); 100d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) chrome_browser_net::NetErrorTabHelper::CreateForWebContents(contents); 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PasswordManagerDelegateImpl::CreateForWebContents(contents); 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PasswordManager::CreateForWebContentsAndDelegate( 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contents, PasswordManagerDelegateImpl::FromWebContents(contents)); 104424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) PopupBlockerTabHelper::CreateForWebContents(contents); 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PrefsTabHelper::CreateForWebContents(contents); 1063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) prerender::PrerenderTabHelper::CreateForWebContentsWithPasswordManager( 1073551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) contents, PasswordManager::FromWebContents(contents)); 10858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) SingleTabModeTabHelper::CreateForWebContents(contents); 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SSLTabHelper::CreateForWebContents(contents); 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TabSpecificContentSettings::CreateForWebContents(contents); 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TranslateTabHelper::CreateForWebContents(contents); 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowAndroidHelper::CreateForWebContents(contents); 1134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (predictors::ResourcePrefetchPredictorFactory::GetForProfile(profile)) { 1154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) predictors::ResourcePrefetchPredictorTabHelper::CreateForWebContents( 1164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) contents); 1174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 118f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 119f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if defined(ENABLE_MANAGED_USERS) 120f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (profile->IsManaged()) 121f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ManagedModeNavigationObserver::CreateForWebContents(contents); 122f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 125424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// TODO(dtrainor): Refactor so we do not need this method. 126424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void TabAndroid::InitTabHelpers(content::WebContents* contents) { 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BrowserTabContents::AttachTabHelpers(contents); 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 130424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TabAndroid* TabAndroid::FromWebContents(content::WebContents* web_contents) { 131424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(web_contents); 132424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!core_tab_helper) 133424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return NULL; 134424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 135424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); 136424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!core_delegate) 137424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return NULL; 138424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 139424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return static_cast<TabAndroid*>(core_delegate); 140424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 141424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 142424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TabAndroid* TabAndroid::GetNativeTab(JNIEnv* env, jobject obj) { 143424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return reinterpret_cast<TabAndroid*>(Java_TabBase_getNativePtr(env, obj)); 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 146424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TabAndroid::TabAndroid(JNIEnv* env, jobject obj) 147424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) : weak_java_tab_(env, obj), 148424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) session_tab_id_(), 14958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)) { 150f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) Java_TabBase_setNativePtr(env, obj, reinterpret_cast<intptr_t>(this)); 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)TabAndroid::~TabAndroid() { 15458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 15558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 15658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (obj.is_null()) 15758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return; 15858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 15958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) Java_TabBase_clearNativePtr(env, obj.obj()); 16058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 16158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 1628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)int TabAndroid::GetAndroidId() const { 1638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 1658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (obj.is_null()) 1668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return -1; 1678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return Java_TabBase_getId(env, obj.obj()); 1688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 1698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1700f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)int TabAndroid::GetSyncId() const { 1710f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1720f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 1730f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (obj.is_null()) 1740f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return 0; 1750f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return Java_TabBase_getSyncId(env, obj.obj()); 1760f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 1770f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)string16 TabAndroid::GetTitle() const { 1798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1808bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 1818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (obj.is_null()) 1828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return string16(); 1838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return base::android::ConvertJavaStringToUTF16( 1848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) Java_TabBase_getTitle(env, obj.obj())); 1858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 1868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)GURL TabAndroid::GetURL() const { 1888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 1908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (obj.is_null()) 1918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return GURL::EmptyGURL(); 1928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return GURL(base::android::ConvertJavaStringToUTF8( 1938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) Java_TabBase_getUrl(env, obj.obj()))); 1948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 1958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)bool TabAndroid::RestoreIfNeeded() { 1978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 1998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (obj.is_null()) 2008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return false; 2018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return Java_TabBase_restoreIfNeeded(env, obj.obj()); 2028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 2038bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 204424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)content::ContentViewCore* TabAndroid::GetContentViewCore() const { 205424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!web_contents()) 206424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return NULL; 207424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 208424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return content::ContentViewCore::FromWebContents(web_contents()); 209424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 210424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 211424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)Profile* TabAndroid::GetProfile() const { 212424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!web_contents()) 213424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return NULL; 214424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 215424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 216424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 217424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 21858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)browser_sync::SyncedTabDelegate* TabAndroid::GetSyncedTabDelegate() const { 21958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return synced_tab_delegate_.get(); 2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)void TabAndroid::SetSyncId(int sync_id) { 2230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 2240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 2250f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (obj.is_null()) 2260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return; 2270f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) Java_TabBase_setSyncId(env, obj.obj(), sync_id); 2280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 2290f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 230424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void TabAndroid::SwapTabContents(content::WebContents* old_contents, 231424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) content::WebContents* new_contents) { 232424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 2334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // We need to notify the native InfobarContainer so infobars can be swapped. 2354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) InfoBarContainerAndroid* infobar_container = 2364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) reinterpret_cast<InfoBarContainerAndroid*>( 2374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) Java_TabBase_getNativeInfoBarContainer( 2384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) env, 2394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) weak_java_tab_.get(env).obj())); 2404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) InfoBarService* new_infobar_service = new_contents ? 2414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) InfoBarService::FromWebContents(new_contents) : NULL; 242f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) infobar_container->ChangeInfoBarService(new_infobar_service); 2434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 244424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Java_TabBase_swapWebContents( 245424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) env, 246424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) weak_java_tab_.get(env).obj(), 247f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) reinterpret_cast<intptr_t>(new_contents)); 248424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 249424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 25058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void TabAndroid::Observe(int type, 25158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const content::NotificationSource& source, 25258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const content::NotificationDetails& details) { 25358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 25458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) switch (type) { 25558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: { 25658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) TabSpecificContentSettings* settings = 25758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) TabSpecificContentSettings::FromWebContents(web_contents()); 25858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (!settings->IsBlockageIndicated(CONTENT_SETTINGS_TYPE_POPUPS)) { 25958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // TODO(dfalcantara): Create an InfoBarDelegate to keep the 26058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // PopupBlockedInfoBar logic native-side instead of straddling the JNI 26158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // boundary. 26258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) int num_popups = 0; 26358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) PopupBlockerTabHelper* popup_blocker_helper = 26458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) PopupBlockerTabHelper::FromWebContents(web_contents()); 26558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (popup_blocker_helper) 26658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) num_popups = popup_blocker_helper->GetBlockedPopupsCount(); 26758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 268f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (num_popups > 0) { 269f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) PopupBlockedInfoBarDelegate::Create( 270f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) InfoBarService::FromWebContents(web_contents()), 271f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) num_popups); 272f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 273f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 27458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) settings->SetBlockageHasBeenIndicated(CONTENT_SETTINGS_TYPE_POPUPS); 27558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 27658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) break; 27758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 27858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) case chrome::NOTIFICATION_FAVICON_UPDATED: 27958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) Java_TabBase_onFaviconUpdated(env, weak_java_tab_.get(env).obj()); 28058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) break; 28158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) default: 28258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) NOTREACHED() << "Unexpected notification " << type; 28358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) break; 28458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 28558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 28658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 287424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void TabAndroid::InitWebContents(JNIEnv* env, 288424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jobject obj, 289424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jboolean incognito, 290424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jobject jcontent_view_core, 291424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jobject jweb_contents_delegate) { 292424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) content::ContentViewCore* content_view_core = 293424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) content::ContentViewCore::GetNativeContentViewCore(env, 294424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jcontent_view_core); 295424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DCHECK(content_view_core); 296424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DCHECK(content_view_core->GetWebContents()); 297424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 298424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents_.reset(content_view_core->GetWebContents()); 299424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) InitTabHelpers(web_contents_.get()); 300424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 301424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) session_tab_id_.set_id( 302424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) SessionTabHelper::FromWebContents(web_contents())->session_id().id()); 303424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) WindowAndroidHelper::FromWebContents(web_contents())-> 304424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) SetWindowAndroid(content_view_core->GetWindowAndroid()); 305424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CoreTabHelper::FromWebContents(web_contents())->set_delegate(this); 306424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents_delegate_.reset( 307424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) new chrome::android::ChromeWebContentsDelegateAndroid( 308424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) env, jweb_contents_delegate)); 309424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents_delegate_->LoadProgressChanged(web_contents(), 0); 310424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents()->SetDelegate(web_contents_delegate_.get()); 311424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 31258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) notification_registrar_.Add( 31358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) this, 31458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, 31558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) content::Source<content::WebContents>(web_contents())); 31658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) notification_registrar_.Add( 31758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) this, 31858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) chrome::NOTIFICATION_FAVICON_UPDATED, 31958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) content::Source<content::WebContents>(web_contents())); 32058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 32158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) synced_tab_delegate_->SetWebContents(web_contents()); 32258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 32358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Set the window ID if there is a valid TabModel. 32458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) TabModel* model = TabModelList::GetTabModelWithProfile(GetProfile()); 32558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (model) { 32658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) SessionID window_id; 32758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) window_id.set_id(model->GetSessionId()); 32858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 32958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) SessionTabHelper* session_tab_helper = 33058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) SessionTabHelper::FromWebContents(web_contents()); 33158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) session_tab_helper->SetWindowID(window_id); 33258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 33358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 334424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Verify that the WebContents this tab represents matches the expected 335424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // off the record state. 336424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CHECK_EQ(GetProfile()->IsOffTheRecord(), incognito); 337424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 338424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 339424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void TabAndroid::DestroyWebContents(JNIEnv* env, 340424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jobject obj, 341424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jboolean delete_native) { 34258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) DCHECK(web_contents()); 34358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 34458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) notification_registrar_.Remove( 34558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) this, 34658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, 34758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) content::Source<content::WebContents>(web_contents())); 34858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) notification_registrar_.Remove( 34958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) this, 35058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) chrome::NOTIFICATION_FAVICON_UPDATED, 35158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) content::Source<content::WebContents>(web_contents())); 35258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 353424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents()->SetDelegate(NULL); 354424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 355424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (delete_native) { 356424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents_.reset(); 35758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) synced_tab_delegate_->ResetWebContents(); 358424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } else { 359424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Release the WebContents so it does not get deleted by the scoped_ptr. 360424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) ignore_result(web_contents_.release()); 361424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } 362424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 363424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 364424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetProfileAndroid( 365424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) JNIEnv* env, 366424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jobject obj) { 367424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Profile* profile = GetProfile(); 368424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!profile) 369424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return base::android::ScopedJavaLocalRef<jobject>(); 370424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) ProfileAndroid* profile_android = ProfileAndroid::FromProfile(profile); 371424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!profile_android) 372424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return base::android::ScopedJavaLocalRef<jobject>(); 373424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 374424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return profile_android->GetJavaObject(); 375424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 376424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 37758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)ToolbarModel::SecurityLevel TabAndroid::GetSecurityLevel(JNIEnv* env, 37858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) jobject obj) { 37958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return ToolbarModelImpl::GetSecurityLevelForWebContents(web_contents()); 38058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 38158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 3824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void TabAndroid::SetActiveNavigationEntryTitleForUrl(JNIEnv* env, 3834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) jobject obj, 3844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) jstring jurl, 3854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) jstring jtitle) { 3864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) DCHECK(web_contents()); 3874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) string16 title; 3894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (jtitle) 3904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) title = base::android::ConvertJavaStringToUTF16(env, jtitle); 3914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::string url; 3934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (jurl) 3944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) url = base::android::ConvertJavaStringToUTF8(env, jurl); 3954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::NavigationEntry* entry = 3974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) web_contents()->GetController().GetVisibleEntry(); 3984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (entry && url == entry->GetVirtualURL().spec()) 3994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) entry->SetTitle(title); 4004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 4014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 402f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)bool TabAndroid::Print(JNIEnv* env, jobject obj) { 403f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (!web_contents()) 404f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return false; 405f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 406f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) printing::PrintViewManagerBasic::CreateForWebContents(web_contents()); 407f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) printing::PrintViewManagerBasic* print_view_manager = 408f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) printing::PrintViewManagerBasic::FromWebContents(web_contents()); 409f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (print_view_manager == NULL) 410f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return false; 411f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 412f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) print_view_manager->PrintNow(); 413f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return true; 414f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 415f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 416c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { 417c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return RegisterNativesImpl(env); 418c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 419