tab_android.cc revision a02191e04bc25c4935f804f2c080ae28663d096d
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" 15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/google/google_url_tracker.h" 16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/google/google_util.h" 17c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "chrome/browser/infobars/infobar_container.h" 18c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "chrome/browser/infobars/infobar_service.h" 19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/prerender/prerender_contents.h" 20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/prerender/prerender_manager.h" 21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/prerender/prerender_manager_factory.h" 22f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/printing/print_view_manager_basic.h" 23424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "chrome/browser/profiles/profile.h" 24424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "chrome/browser/profiles/profile_android.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/sessions/session_tab_helper.h" 2658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/sync/glue/synced_tab_delegate_android.h" 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" 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/tab_contents/core_tab_helper.h" 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/tab_helpers.h" 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/toolbar/toolbar_model_impl.h" 37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/common/net/url_fixer_upper.h" 38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/common/url_constants.h" 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/android/content_view_core.h" 404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "content/public/browser/navigation_entry.h" 4158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "content/public/browser/notification_service.h" 42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "content/public/browser/user_metrics.h" 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h" 44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "jni/Tab_jni.h" 45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "third_party/WebKit/public/platform/WebReferrerPolicy.h" 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 47424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TabAndroid* TabAndroid::FromWebContents(content::WebContents* web_contents) { 48424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(web_contents); 49424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!core_tab_helper) 50424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return NULL; 51424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 52424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); 53424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!core_delegate) 54424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return NULL; 55424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 56424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return static_cast<TabAndroid*>(core_delegate); 57424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 58424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 59424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TabAndroid* TabAndroid::GetNativeTab(JNIEnv* env, jobject obj) { 60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return reinterpret_cast<TabAndroid*>(Java_Tab_getNativePtr(env, obj)); 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)void TabAndroid::AttachTabHelpers(content::WebContents* web_contents) { 6423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) DCHECK(web_contents); 6523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 6623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) TabHelpers::AttachTabHelpers(web_contents); 6723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)} 6823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 69424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TabAndroid::TabAndroid(JNIEnv* env, jobject obj) 70424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) : weak_java_tab_(env, obj), 7158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)) { 72a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_setNativePtr(env, obj, reinterpret_cast<intptr_t>(this)); 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)TabAndroid::~TabAndroid() { 7658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 7758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 7858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (obj.is_null()) 7958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return; 8058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 81a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_clearNativePtr(env, obj.obj()); 8258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 8358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetJavaObject() { 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return weak_java_tab_.get(env); 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)int TabAndroid::GetAndroidId() const { 908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (obj.is_null()) 938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return -1; 94a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return Java_Tab_getId(env, obj.obj()); 958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 970f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)int TabAndroid::GetSyncId() const { 980f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 990f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 1000f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (obj.is_null()) 1010f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return 0; 102a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return Java_Tab_getSyncId(env, obj.obj()); 1030f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 1040f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 105a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)base::string16 TabAndroid::GetTitle() const { 1068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 1088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (obj.is_null()) 109a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return base::string16(); 1108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return base::android::ConvertJavaStringToUTF16( 111a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_getTitle(env, obj.obj())); 1128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 1138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)GURL TabAndroid::GetURL() const { 1158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 1178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (obj.is_null()) 1188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return GURL::EmptyGURL(); 1198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return GURL(base::android::ConvertJavaStringToUTF8( 120a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_getUrl(env, obj.obj()))); 1218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 1228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 123e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochbool TabAndroid::LoadIfNeeded() { 1248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 1268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (obj.is_null()) 1278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return false; 128e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch return Java_Tab_loadIfNeeded(env, obj.obj()); 1298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 1308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 131424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)content::ContentViewCore* TabAndroid::GetContentViewCore() const { 132424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!web_contents()) 133424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return NULL; 134424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 135424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return content::ContentViewCore::FromWebContents(web_contents()); 136424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 137424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 138424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)Profile* TabAndroid::GetProfile() const { 139424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!web_contents()) 140424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return NULL; 141424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 142424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 143424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 144424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 14558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)browser_sync::SyncedTabDelegate* TabAndroid::GetSyncedTabDelegate() const { 14658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return synced_tab_delegate_.get(); 1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 149a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void TabAndroid::SetWindowSessionID(SessionID::id_type window_id) { 150a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) session_window_id_.set_id(window_id); 151a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 152a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!web_contents()) 153a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return; 154a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 155a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) SessionTabHelper* session_tab_helper = 156a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) SessionTabHelper::FromWebContents(web_contents()); 157a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) session_tab_helper->SetWindowID(session_window_id_); 158a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 159a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 1600f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)void TabAndroid::SetSyncId(int sync_id) { 1610f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 1620f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); 1630f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (obj.is_null()) 1640f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return; 165a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_setSyncId(env, obj.obj(), sync_id); 1660f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 1670f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void TabAndroid::HandlePopupNavigation(chrome::NavigateParams* params) { 1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NOTIMPLEMENTED(); 1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void TabAndroid::OnReceivedHttpAuthRequest(jobject auth_handler, 1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::string16& host, 1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::string16& realm) { 1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NOTIMPLEMENTED(); 1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void TabAndroid::AddShortcutToBookmark(const GURL& url, 1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::string16& title, 1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const SkBitmap& skbitmap, 1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int r_value, 1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int g_value, 1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int b_value) { 1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NOTREACHED(); 1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void TabAndroid::EditBookmark(int64 node_id, 1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::string16& node_title, 1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool is_folder, 1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool is_partner_bookmark) { 1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NOTREACHED(); 1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void TabAndroid::OnNewTabPageReady() { 1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NOTREACHED(); 1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool TabAndroid::ShouldWelcomePageLinkToTermsOfService() { 1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NOTIMPLEMENTED(); 2005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return false; 2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 203a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool TabAndroid::HasPrerenderedUrl(GURL gurl) { 204a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender::PrerenderManager* prerender_manager = GetPrerenderManager(); 205a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!prerender_manager) 206a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return false; 207a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 208a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) std::vector<content::WebContents*> contents = 209a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender_manager->GetAllPrerenderingContents(); 210a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender::PrerenderContents* prerender_contents; 211a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) for (size_t i = 0; i < contents.size(); ++i) { 212a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender_contents = prerender_manager-> 213a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GetPrerenderContents(contents.at(i)); 214a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (prerender_contents->prerender_url() == gurl && 215a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender_contents->has_finished_loading()) { 216a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return true; 217a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 218a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 219a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return false; 220a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 221a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 222424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void TabAndroid::SwapTabContents(content::WebContents* old_contents, 2235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::WebContents* new_contents, 2245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool did_start_load, 2255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool did_finish_load) { 226424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 2274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // We need to notify the native InfobarContainer so infobars can be swapped. 2294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) InfoBarContainerAndroid* infobar_container = 2304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) reinterpret_cast<InfoBarContainerAndroid*>( 231a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_getNativeInfoBarContainer( 2324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) env, 2334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) weak_java_tab_.get(env).obj())); 234a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch InfoBarService* new_infobar_service = 235a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch new_contents ? InfoBarService::FromWebContents(new_contents) : NULL; 236a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch infobar_container->ChangeInfoBarManager(new_infobar_service); 2374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 238a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_swapWebContents( 239424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) env, 240424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) weak_java_tab_.get(env).obj(), 2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) reinterpret_cast<intptr_t>(new_contents), 2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) did_start_load, 2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) did_finish_load); 244424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 245424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 24658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void TabAndroid::Observe(int type, 24758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const content::NotificationSource& source, 24858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const content::NotificationDetails& details) { 24958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 25058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) switch (type) { 25158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: { 25258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) TabSpecificContentSettings* settings = 25358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) TabSpecificContentSettings::FromWebContents(web_contents()); 25458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (!settings->IsBlockageIndicated(CONTENT_SETTINGS_TYPE_POPUPS)) { 25558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // TODO(dfalcantara): Create an InfoBarDelegate to keep the 25658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // PopupBlockedInfoBar logic native-side instead of straddling the JNI 25758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // boundary. 25858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) int num_popups = 0; 25958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) PopupBlockerTabHelper* popup_blocker_helper = 26058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) PopupBlockerTabHelper::FromWebContents(web_contents()); 26158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (popup_blocker_helper) 26258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) num_popups = popup_blocker_helper->GetBlockedPopupsCount(); 26358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 2645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (num_popups > 0) 2655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PopupBlockedInfoBarDelegate::Create(web_contents(), num_popups); 266f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 26758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) settings->SetBlockageHasBeenIndicated(CONTENT_SETTINGS_TYPE_POPUPS); 26858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 26958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) break; 27058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 27158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) case chrome::NOTIFICATION_FAVICON_UPDATED: 272a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_onFaviconUpdated(env, weak_java_tab_.get(env).obj()); 27358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) break; 2745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case content::NOTIFICATION_NAV_ENTRY_CHANGED: 275a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Java_Tab_onNavEntryChanged(env, weak_java_tab_.get(env).obj()); 2765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) break; 27758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) default: 27858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) NOTREACHED() << "Unexpected notification " << type; 27958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) break; 28058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 28158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 28258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 2835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void TabAndroid::Destroy(JNIEnv* env, jobject obj) { 2845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) delete this; 2855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (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, 291a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) jobject jweb_contents_delegate, 292a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) jobject jcontext_menu_populator) { 293424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) content::ContentViewCore* content_view_core = 294424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) content::ContentViewCore::GetNativeContentViewCore(env, 295424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jcontent_view_core); 296424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DCHECK(content_view_core); 297424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DCHECK(content_view_core->GetWebContents()); 298424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 299424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents_.reset(content_view_core->GetWebContents()); 30023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) AttachTabHelpers(web_contents_.get()); 301424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 302a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) SetWindowSessionID(session_window_id_.id()); 303a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 304424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) session_tab_id_.set_id( 305424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) SessionTabHelper::FromWebContents(web_contents())->session_id().id()); 306a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ContextMenuHelper::FromWebContents(web_contents())->SetPopulator( 307a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) jcontext_menu_populator); 308424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) WindowAndroidHelper::FromWebContents(web_contents())-> 309424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) SetWindowAndroid(content_view_core->GetWindowAndroid()); 310424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CoreTabHelper::FromWebContents(web_contents())->set_delegate(this); 311424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents_delegate_.reset( 312424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) new chrome::android::ChromeWebContentsDelegateAndroid( 313424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) env, jweb_contents_delegate)); 314424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents_delegate_->LoadProgressChanged(web_contents(), 0); 315424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents()->SetDelegate(web_contents_delegate_.get()); 316424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 31758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) notification_registrar_.Add( 31858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) this, 31958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, 32058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) content::Source<content::WebContents>(web_contents())); 32158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) notification_registrar_.Add( 32258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) this, 32358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) chrome::NOTIFICATION_FAVICON_UPDATED, 32458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) content::Source<content::WebContents>(web_contents())); 3255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) notification_registrar_.Add( 3265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) this, 3275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::NOTIFICATION_NAV_ENTRY_CHANGED, 3285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::Source<content::NavigationController>( 3295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) &web_contents()->GetController())); 33058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 33158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) synced_tab_delegate_->SetWebContents(web_contents()); 33258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 333424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Verify that the WebContents this tab represents matches the expected 334424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // off the record state. 335424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CHECK_EQ(GetProfile()->IsOffTheRecord(), incognito); 336424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 337424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 338424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void TabAndroid::DestroyWebContents(JNIEnv* env, 339424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jobject obj, 340424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jboolean delete_native) { 34158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) DCHECK(web_contents()); 34258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 34358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) notification_registrar_.Remove( 34458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) this, 34558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, 34658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) content::Source<content::WebContents>(web_contents())); 34758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) notification_registrar_.Remove( 34858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) this, 34958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) chrome::NOTIFICATION_FAVICON_UPDATED, 35058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) content::Source<content::WebContents>(web_contents())); 35123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) notification_registrar_.Remove( 35223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) this, 35323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) content::NOTIFICATION_NAV_ENTRY_CHANGED, 35423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) content::Source<content::NavigationController>( 35523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) &web_contents()->GetController())); 35658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 357424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents()->SetDelegate(NULL); 358424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 359424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (delete_native) { 360424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) web_contents_.reset(); 36158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) synced_tab_delegate_->ResetWebContents(); 362424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } else { 363424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Release the WebContents so it does not get deleted by the scoped_ptr. 364424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) ignore_result(web_contents_.release()); 365424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } 366424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 367424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 3685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetWebContents( 3695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) JNIEnv* env, 3705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) jobject obj) { 3715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!web_contents_.get()) 3725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return base::android::ScopedJavaLocalRef<jobject>(); 3735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return web_contents_->GetJavaWebContents(); 3745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 376424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetProfileAndroid( 377424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) JNIEnv* env, 378424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) jobject obj) { 379424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Profile* profile = GetProfile(); 380424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!profile) 381424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return base::android::ScopedJavaLocalRef<jobject>(); 382424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) ProfileAndroid* profile_android = ProfileAndroid::FromProfile(profile); 383424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!profile_android) 384424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return base::android::ScopedJavaLocalRef<jobject>(); 385424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 386424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return profile_android->GetJavaObject(); 387424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 388424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 389a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)TabAndroid::TabLoadStatus TabAndroid::LoadUrl(JNIEnv* env, 390a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) jobject obj, 391a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) jstring url, 392a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) jstring j_extra_headers, 393a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) jbyteArray j_post_data, 394a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) jint page_transition, 395a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) jstring j_referrer_url, 396a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) jint referrer_policy) { 397a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content::ContentViewCore* content_view = GetContentViewCore(); 398a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!content_view) 399a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return PAGE_LOAD_FAILED; 400a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 401a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GURL gurl(base::android::ConvertJavaStringToUTF8(env, url)); 402a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (gurl.is_empty()) 403a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return PAGE_LOAD_FAILED; 404a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 405a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // If the page was prerendered, use it. 406a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Note in incognito mode, we don't have a PrerenderManager. 407a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 408a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender::PrerenderManager* prerender_manager = 409a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prerender::PrerenderManagerFactory::GetForProfile(GetProfile()); 410a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (prerender_manager) { 411a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool prefetched_page_loaded = HasPrerenderedUrl(gurl); 412a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Getting the load status before MaybeUsePrerenderedPage() b/c it resets. 413a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) chrome::NavigateParams params(NULL, web_contents()); 414a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (prerender_manager->MaybeUsePrerenderedPage(gurl, ¶ms)) { 415a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return prefetched_page_loaded ? 416a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FULL_PRERENDERED_PAGE_LOAD : PARTIAL_PRERENDERED_PAGE_LOAD; 417a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 418a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 419a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 420a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GURL fixed_url(URLFixerUpper::FixupURL(gurl.possibly_invalid_spec(), 421a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) std::string())); 422a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!fixed_url.is_valid()) 423a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return PAGE_LOAD_FAILED; 424a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 425a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!HandleNonNavigationAboutURL(fixed_url)) { 426a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Notify the GoogleURLTracker of searches, it might want to change the 427a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // actual Google site used (for instance when in the UK, google.co.uk, when 428a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // in the US google.com). 429a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Note that this needs to happen before we initiate the navigation as the 430a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // GoogleURLTracker uses the navigation pending notification to trigger the 431a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // infobar. 432a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (google_util::IsGoogleSearchUrl(fixed_url) && 433a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) (page_transition & content::PAGE_TRANSITION_GENERATED)) { 434a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleURLTracker::GoogleURLSearchCommitted(GetProfile()); 435a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 436a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 437a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Record UMA "ShowHistory" here. That way it'll pick up both user 438a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // typing chrome://history as well as selecting from the drop down menu. 439a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (fixed_url.spec() == chrome::kChromeUIHistoryURL) { 440a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content::RecordAction(base::UserMetricsAction("ShowHistory")); 441a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 442a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 443a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content::NavigationController::LoadURLParams load_params(fixed_url); 444a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (j_extra_headers) { 445a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) load_params.extra_headers = base::android::ConvertJavaStringToUTF8( 446a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) env, 447a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) j_extra_headers); 448a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 449a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (j_post_data) { 450a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) load_params.load_type = 451a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content::NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; 452a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) std::vector<uint8> post_data; 453a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::android::JavaByteArrayToByteVector(env, j_post_data, &post_data); 454a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) load_params.browser_initiated_post_data = 455a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::RefCountedBytes::TakeVector(&post_data); 456a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 457a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) load_params.transition_type = 458a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content::PageTransitionFromInt(page_transition); 459a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (j_referrer_url) { 460a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) load_params.referrer = content::Referrer( 461a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GURL(base::android::ConvertJavaStringToUTF8(env, j_referrer_url)), 462a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) static_cast<blink::WebReferrerPolicy>(referrer_policy)); 463a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 464a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content_view->LoadUrl(load_params); 465a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 466a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return DEFAULT_PAGE_LOAD; 467a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 468a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 46958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)ToolbarModel::SecurityLevel TabAndroid::GetSecurityLevel(JNIEnv* env, 47058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) jobject obj) { 47158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return ToolbarModelImpl::GetSecurityLevelForWebContents(web_contents()); 47258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 47358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 4744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void TabAndroid::SetActiveNavigationEntryTitleForUrl(JNIEnv* env, 4754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) jobject obj, 4764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) jstring jurl, 4774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) jstring jtitle) { 4784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) DCHECK(web_contents()); 4794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 480a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 title; 4814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (jtitle) 4824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) title = base::android::ConvertJavaStringToUTF16(env, jtitle); 4834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 4844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::string url; 4854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (jurl) 4864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) url = base::android::ConvertJavaStringToUTF8(env, jurl); 4874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 4884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::NavigationEntry* entry = 4894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) web_contents()->GetController().GetVisibleEntry(); 4904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (entry && url == entry->GetVirtualURL().spec()) 4914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) entry->SetTitle(title); 4924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 4934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 494f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)bool TabAndroid::Print(JNIEnv* env, jobject obj) { 495f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (!web_contents()) 496f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return false; 497f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 498f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) printing::PrintViewManagerBasic::CreateForWebContents(web_contents()); 499f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) printing::PrintViewManagerBasic* print_view_manager = 500f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) printing::PrintViewManagerBasic::FromWebContents(web_contents()); 501f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (print_view_manager == NULL) 502f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return false; 503f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 504f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) print_view_manager->PrintNow(); 505f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return true; 506f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 507f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 508a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)prerender::PrerenderManager* TabAndroid::GetPrerenderManager() const { 509a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Profile* profile = GetProfile(); 510a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!profile) 511a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return NULL; 512a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return prerender::PrerenderManagerFactory::GetForProfile(profile); 513a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 514a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 5155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)static void Init(JNIEnv* env, jobject obj) { 5165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TRACE_EVENT0("native", "TabAndroid::Init"); 5175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // This will automatically bind to the Java object and pass ownership there. 5185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new TabAndroid(env, obj); 5195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 5205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 521c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { 522c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return RegisterNativesImpl(env); 523c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 524