| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/android/tab_android.h" | 5 #include "chrome/browser/android/tab_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "chrome/browser/android/chrome_web_contents_delegate_android.h" | 10 #include "chrome/browser/android/chrome_web_contents_delegate_android.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | 22 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
| 23 #include "chrome/browser/ui/android/window_android_helper.h" | 23 #include "chrome/browser/ui/android/window_android_helper.h" |
| 24 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" | 24 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" |
| 25 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 25 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 26 #include "chrome/browser/ui/tab_helpers.h" | 26 #include "chrome/browser/ui/tab_helpers.h" |
| 27 #include "chrome/browser/ui/toolbar/toolbar_model_impl.h" | 27 #include "chrome/browser/ui/toolbar/toolbar_model_impl.h" |
| 28 #include "content/public/browser/android/content_view_core.h" | 28 #include "content/public/browser/android/content_view_core.h" |
| 29 #include "content/public/browser/navigation_entry.h" | 29 #include "content/public/browser/navigation_entry.h" |
| 30 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| 31 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
| 32 #include "jni/TabBase_jni.h" | 32 #include "jni/Tab_jni.h" |
| 33 | 33 |
| 34 TabAndroid* TabAndroid::FromWebContents(content::WebContents* web_contents) { | 34 TabAndroid* TabAndroid::FromWebContents(content::WebContents* web_contents) { |
| 35 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(web_contents); | 35 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(web_contents); |
| 36 if (!core_tab_helper) | 36 if (!core_tab_helper) |
| 37 return NULL; | 37 return NULL; |
| 38 | 38 |
| 39 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); | 39 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); |
| 40 if (!core_delegate) | 40 if (!core_delegate) |
| 41 return NULL; | 41 return NULL; |
| 42 | 42 |
| 43 return static_cast<TabAndroid*>(core_delegate); | 43 return static_cast<TabAndroid*>(core_delegate); |
| 44 } | 44 } |
| 45 | 45 |
| 46 TabAndroid* TabAndroid::GetNativeTab(JNIEnv* env, jobject obj) { | 46 TabAndroid* TabAndroid::GetNativeTab(JNIEnv* env, jobject obj) { |
| 47 return reinterpret_cast<TabAndroid*>(Java_TabBase_getNativePtr(env, obj)); | 47 return reinterpret_cast<TabAndroid*>(Java_Tab_getNativePtr(env, obj)); |
| 48 } | 48 } |
| 49 | 49 |
| 50 TabAndroid::TabAndroid(JNIEnv* env, jobject obj) | 50 TabAndroid::TabAndroid(JNIEnv* env, jobject obj) |
| 51 : weak_java_tab_(env, obj), | 51 : weak_java_tab_(env, obj), |
| 52 session_tab_id_(), | 52 session_tab_id_(), |
| 53 synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)) { | 53 synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)) { |
| 54 Java_TabBase_setNativePtr(env, obj, reinterpret_cast<intptr_t>(this)); | 54 Java_Tab_setNativePtr(env, obj, reinterpret_cast<intptr_t>(this)); |
| 55 } | 55 } |
| 56 | 56 |
| 57 TabAndroid::~TabAndroid() { | 57 TabAndroid::~TabAndroid() { |
| 58 JNIEnv* env = base::android::AttachCurrentThread(); | 58 JNIEnv* env = base::android::AttachCurrentThread(); |
| 59 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); | 59 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); |
| 60 if (obj.is_null()) | 60 if (obj.is_null()) |
| 61 return; | 61 return; |
| 62 | 62 |
| 63 Java_TabBase_clearNativePtr(env, obj.obj()); | 63 Java_Tab_clearNativePtr(env, obj.obj()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetJavaObject() { | 66 base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetJavaObject() { |
| 67 JNIEnv* env = base::android::AttachCurrentThread(); | 67 JNIEnv* env = base::android::AttachCurrentThread(); |
| 68 return weak_java_tab_.get(env); | 68 return weak_java_tab_.get(env); |
| 69 } | 69 } |
| 70 | 70 |
| 71 int TabAndroid::GetAndroidId() const { | 71 int TabAndroid::GetAndroidId() const { |
| 72 JNIEnv* env = base::android::AttachCurrentThread(); | 72 JNIEnv* env = base::android::AttachCurrentThread(); |
| 73 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); | 73 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); |
| 74 if (obj.is_null()) | 74 if (obj.is_null()) |
| 75 return -1; | 75 return -1; |
| 76 return Java_TabBase_getId(env, obj.obj()); | 76 return Java_Tab_getId(env, obj.obj()); |
| 77 } | 77 } |
| 78 | 78 |
| 79 int TabAndroid::GetSyncId() const { | 79 int TabAndroid::GetSyncId() const { |
| 80 JNIEnv* env = base::android::AttachCurrentThread(); | 80 JNIEnv* env = base::android::AttachCurrentThread(); |
| 81 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); | 81 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); |
| 82 if (obj.is_null()) | 82 if (obj.is_null()) |
| 83 return 0; | 83 return 0; |
| 84 return Java_TabBase_getSyncId(env, obj.obj()); | 84 return Java_Tab_getSyncId(env, obj.obj()); |
| 85 } | 85 } |
| 86 | 86 |
| 87 base::string16 TabAndroid::GetTitle() const { | 87 base::string16 TabAndroid::GetTitle() const { |
| 88 JNIEnv* env = base::android::AttachCurrentThread(); | 88 JNIEnv* env = base::android::AttachCurrentThread(); |
| 89 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); | 89 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); |
| 90 if (obj.is_null()) | 90 if (obj.is_null()) |
| 91 return base::string16(); | 91 return base::string16(); |
| 92 return base::android::ConvertJavaStringToUTF16( | 92 return base::android::ConvertJavaStringToUTF16( |
| 93 Java_TabBase_getTitle(env, obj.obj())); | 93 Java_Tab_getTitle(env, obj.obj())); |
| 94 } | 94 } |
| 95 | 95 |
| 96 GURL TabAndroid::GetURL() const { | 96 GURL TabAndroid::GetURL() const { |
| 97 JNIEnv* env = base::android::AttachCurrentThread(); | 97 JNIEnv* env = base::android::AttachCurrentThread(); |
| 98 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); | 98 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); |
| 99 if (obj.is_null()) | 99 if (obj.is_null()) |
| 100 return GURL::EmptyGURL(); | 100 return GURL::EmptyGURL(); |
| 101 return GURL(base::android::ConvertJavaStringToUTF8( | 101 return GURL(base::android::ConvertJavaStringToUTF8( |
| 102 Java_TabBase_getUrl(env, obj.obj()))); | 102 Java_Tab_getUrl(env, obj.obj()))); |
| 103 } | 103 } |
| 104 | 104 |
| 105 bool TabAndroid::RestoreIfNeeded() { | 105 bool TabAndroid::RestoreIfNeeded() { |
| 106 JNIEnv* env = base::android::AttachCurrentThread(); | 106 JNIEnv* env = base::android::AttachCurrentThread(); |
| 107 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); | 107 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); |
| 108 if (obj.is_null()) | 108 if (obj.is_null()) |
| 109 return false; | 109 return false; |
| 110 return Java_TabBase_restoreIfNeeded(env, obj.obj()); | 110 return Java_Tab_restoreIfNeeded(env, obj.obj()); |
| 111 } | 111 } |
| 112 | 112 |
| 113 content::ContentViewCore* TabAndroid::GetContentViewCore() const { | 113 content::ContentViewCore* TabAndroid::GetContentViewCore() const { |
| 114 if (!web_contents()) | 114 if (!web_contents()) |
| 115 return NULL; | 115 return NULL; |
| 116 | 116 |
| 117 return content::ContentViewCore::FromWebContents(web_contents()); | 117 return content::ContentViewCore::FromWebContents(web_contents()); |
| 118 } | 118 } |
| 119 | 119 |
| 120 Profile* TabAndroid::GetProfile() const { | 120 Profile* TabAndroid::GetProfile() const { |
| 121 if (!web_contents()) | 121 if (!web_contents()) |
| 122 return NULL; | 122 return NULL; |
| 123 | 123 |
| 124 return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 124 return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 125 } | 125 } |
| 126 | 126 |
| 127 browser_sync::SyncedTabDelegate* TabAndroid::GetSyncedTabDelegate() const { | 127 browser_sync::SyncedTabDelegate* TabAndroid::GetSyncedTabDelegate() const { |
| 128 return synced_tab_delegate_.get(); | 128 return synced_tab_delegate_.get(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void TabAndroid::SetSyncId(int sync_id) { | 131 void TabAndroid::SetSyncId(int sync_id) { |
| 132 JNIEnv* env = base::android::AttachCurrentThread(); | 132 JNIEnv* env = base::android::AttachCurrentThread(); |
| 133 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); | 133 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); |
| 134 if (obj.is_null()) | 134 if (obj.is_null()) |
| 135 return; | 135 return; |
| 136 Java_TabBase_setSyncId(env, obj.obj(), sync_id); | 136 Java_Tab_setSyncId(env, obj.obj(), sync_id); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void TabAndroid::HandlePopupNavigation(chrome::NavigateParams* params) { | 139 void TabAndroid::HandlePopupNavigation(chrome::NavigateParams* params) { |
| 140 NOTIMPLEMENTED(); | 140 NOTIMPLEMENTED(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void TabAndroid::OnReceivedHttpAuthRequest(jobject auth_handler, | 143 void TabAndroid::OnReceivedHttpAuthRequest(jobject auth_handler, |
| 144 const base::string16& host, | 144 const base::string16& host, |
| 145 const base::string16& realm) { | 145 const base::string16& realm) { |
| 146 NOTIMPLEMENTED(); | 146 NOTIMPLEMENTED(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 173 | 173 |
| 174 void TabAndroid::SwapTabContents(content::WebContents* old_contents, | 174 void TabAndroid::SwapTabContents(content::WebContents* old_contents, |
| 175 content::WebContents* new_contents, | 175 content::WebContents* new_contents, |
| 176 bool did_start_load, | 176 bool did_start_load, |
| 177 bool did_finish_load) { | 177 bool did_finish_load) { |
| 178 JNIEnv* env = base::android::AttachCurrentThread(); | 178 JNIEnv* env = base::android::AttachCurrentThread(); |
| 179 | 179 |
| 180 // We need to notify the native InfobarContainer so infobars can be swapped. | 180 // We need to notify the native InfobarContainer so infobars can be swapped. |
| 181 InfoBarContainerAndroid* infobar_container = | 181 InfoBarContainerAndroid* infobar_container = |
| 182 reinterpret_cast<InfoBarContainerAndroid*>( | 182 reinterpret_cast<InfoBarContainerAndroid*>( |
| 183 Java_TabBase_getNativeInfoBarContainer( | 183 Java_Tab_getNativeInfoBarContainer( |
| 184 env, | 184 env, |
| 185 weak_java_tab_.get(env).obj())); | 185 weak_java_tab_.get(env).obj())); |
| 186 InfoBarService* new_infobar_service = new_contents ? | 186 InfoBarService* new_infobar_service = new_contents ? |
| 187 InfoBarService::FromWebContents(new_contents) : NULL; | 187 InfoBarService::FromWebContents(new_contents) : NULL; |
| 188 infobar_container->ChangeInfoBarService(new_infobar_service); | 188 infobar_container->ChangeInfoBarService(new_infobar_service); |
| 189 | 189 |
| 190 Java_TabBase_swapWebContents( | 190 Java_Tab_swapWebContents( |
| 191 env, | 191 env, |
| 192 weak_java_tab_.get(env).obj(), | 192 weak_java_tab_.get(env).obj(), |
| 193 reinterpret_cast<intptr_t>(new_contents), | 193 reinterpret_cast<intptr_t>(new_contents), |
| 194 did_start_load, | 194 did_start_load, |
| 195 did_finish_load); | 195 did_finish_load); |
| 196 } | 196 } |
| 197 | 197 |
| 198 void TabAndroid::Observe(int type, | 198 void TabAndroid::Observe(int type, |
| 199 const content::NotificationSource& source, | 199 const content::NotificationSource& source, |
| 200 const content::NotificationDetails& details) { | 200 const content::NotificationDetails& details) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 214 num_popups = popup_blocker_helper->GetBlockedPopupsCount(); | 214 num_popups = popup_blocker_helper->GetBlockedPopupsCount(); |
| 215 | 215 |
| 216 if (num_popups > 0) | 216 if (num_popups > 0) |
| 217 PopupBlockedInfoBarDelegate::Create(web_contents(), num_popups); | 217 PopupBlockedInfoBarDelegate::Create(web_contents(), num_popups); |
| 218 | 218 |
| 219 settings->SetBlockageHasBeenIndicated(CONTENT_SETTINGS_TYPE_POPUPS); | 219 settings->SetBlockageHasBeenIndicated(CONTENT_SETTINGS_TYPE_POPUPS); |
| 220 } | 220 } |
| 221 break; | 221 break; |
| 222 } | 222 } |
| 223 case chrome::NOTIFICATION_FAVICON_UPDATED: | 223 case chrome::NOTIFICATION_FAVICON_UPDATED: |
| 224 Java_TabBase_onFaviconUpdated(env, weak_java_tab_.get(env).obj()); | 224 Java_Tab_onFaviconUpdated(env, weak_java_tab_.get(env).obj()); |
| 225 break; | 225 break; |
| 226 case content::NOTIFICATION_NAV_ENTRY_CHANGED: | 226 case content::NOTIFICATION_NAV_ENTRY_CHANGED: |
| 227 Java_TabBase_onNavEntryChanged(env, weak_java_tab_.get(env).obj()); | 227 Java_Tab_onNavEntryChanged(env, weak_java_tab_.get(env).obj()); |
| 228 break; | 228 break; |
| 229 default: | 229 default: |
| 230 NOTREACHED() << "Unexpected notification " << type; | 230 NOTREACHED() << "Unexpected notification " << type; |
| 231 break; | 231 break; |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 | 234 |
| 235 void TabAndroid::Destroy(JNIEnv* env, jobject obj) { | 235 void TabAndroid::Destroy(JNIEnv* env, jobject obj) { |
| 236 delete this; | 236 delete this; |
| 237 } | 237 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 383 |
| 384 static void Init(JNIEnv* env, jobject obj) { | 384 static void Init(JNIEnv* env, jobject obj) { |
| 385 TRACE_EVENT0("native", "TabAndroid::Init"); | 385 TRACE_EVENT0("native", "TabAndroid::Init"); |
| 386 // This will automatically bind to the Java object and pass ownership there. | 386 // This will automatically bind to the Java object and pass ownership there. |
| 387 new TabAndroid(env, obj); | 387 new TabAndroid(env, obj); |
| 388 } | 388 } |
| 389 | 389 |
| 390 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { | 390 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { |
| 391 return RegisterNativesImpl(env); | 391 return RegisterNativesImpl(env); |
| 392 } | 392 } |
| OLD | NEW |