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_array.h" | 8 #include "base/android/jni_array.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 } | 201 } |
202 } | 202 } |
203 return false; | 203 return false; |
204 } | 204 } |
205 | 205 |
206 void TabAndroid::SwapTabContents(content::WebContents* old_contents, | 206 void TabAndroid::SwapTabContents(content::WebContents* old_contents, |
207 content::WebContents* new_contents, | 207 content::WebContents* new_contents, |
208 bool did_start_load, | 208 bool did_start_load, |
209 bool did_finish_load) { | 209 bool did_finish_load) { |
210 JNIEnv* env = base::android::AttachCurrentThread(); | 210 JNIEnv* env = base::android::AttachCurrentThread(); |
211 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); | |
212 if (obj.is_null()) | |
213 return; | |
211 | 214 |
212 // We need to notify the native InfobarContainer so infobars can be swapped. | 215 // We need to notify the native InfobarContainer so infobars can be swapped. |
213 InfoBarContainerAndroid* infobar_container = | 216 InfoBarContainerAndroid* infobar_container = |
214 reinterpret_cast<InfoBarContainerAndroid*>( | 217 reinterpret_cast<InfoBarContainerAndroid*>( |
215 Java_Tab_getNativeInfoBarContainer( | 218 Java_Tab_getNativeInfoBarContainer( |
216 env, | 219 env, |
217 weak_java_tab_.get(env).obj())); | 220 obj.obj())); |
218 InfoBarService* new_infobar_service = | 221 InfoBarService* new_infobar_service = |
219 new_contents ? InfoBarService::FromWebContents(new_contents) : NULL; | 222 new_contents ? InfoBarService::FromWebContents(new_contents) : NULL; |
220 infobar_container->ChangeInfoBarManager(new_infobar_service); | 223 infobar_container->ChangeInfoBarManager(new_infobar_service); |
221 | 224 |
222 Java_Tab_swapWebContents( | 225 Java_Tab_swapWebContents( |
223 env, | 226 env, |
224 weak_java_tab_.get(env).obj(), | 227 obj.obj(), |
225 reinterpret_cast<intptr_t>(new_contents), | 228 reinterpret_cast<intptr_t>(new_contents), |
226 did_start_load, | 229 did_start_load, |
227 did_finish_load); | 230 did_finish_load); |
228 } | 231 } |
229 | 232 |
230 void TabAndroid::Observe(int type, | 233 void TabAndroid::Observe(int type, |
231 const content::NotificationSource& source, | 234 const content::NotificationSource& source, |
232 const content::NotificationDetails& details) { | 235 const content::NotificationDetails& details) { |
233 JNIEnv* env = base::android::AttachCurrentThread(); | 236 JNIEnv* env = base::android::AttachCurrentThread(); |
237 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); | |
Yaron
2014/07/02 17:36:16
I'm wondering about this one. Even if we don't hav
Abhishek
2014/07/02 19:44:56
I think if java tab is gone, then there is no mean
Yaron
2014/07/02 20:25:39
Agreed. I was referring to NOTIFICATION_WEB_CONTEN
Abhishek
2014/07/03 05:10:42
Done.
| |
238 if (obj.is_null()) | |
239 return; | |
240 | |
234 switch (type) { | 241 switch (type) { |
235 case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: { | 242 case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: { |
236 TabSpecificContentSettings* settings = | 243 TabSpecificContentSettings* settings = |
237 TabSpecificContentSettings::FromWebContents(web_contents()); | 244 TabSpecificContentSettings::FromWebContents(web_contents()); |
238 if (!settings->IsBlockageIndicated(CONTENT_SETTINGS_TYPE_POPUPS)) { | 245 if (!settings->IsBlockageIndicated(CONTENT_SETTINGS_TYPE_POPUPS)) { |
239 // TODO(dfalcantara): Create an InfoBarDelegate to keep the | 246 // TODO(dfalcantara): Create an InfoBarDelegate to keep the |
240 // PopupBlockedInfoBar logic native-side instead of straddling the JNI | 247 // PopupBlockedInfoBar logic native-side instead of straddling the JNI |
241 // boundary. | 248 // boundary. |
242 int num_popups = 0; | 249 int num_popups = 0; |
243 PopupBlockerTabHelper* popup_blocker_helper = | 250 PopupBlockerTabHelper* popup_blocker_helper = |
244 PopupBlockerTabHelper::FromWebContents(web_contents()); | 251 PopupBlockerTabHelper::FromWebContents(web_contents()); |
245 if (popup_blocker_helper) | 252 if (popup_blocker_helper) |
246 num_popups = popup_blocker_helper->GetBlockedPopupsCount(); | 253 num_popups = popup_blocker_helper->GetBlockedPopupsCount(); |
247 | 254 |
248 if (num_popups > 0) | 255 if (num_popups > 0) |
249 PopupBlockedInfoBarDelegate::Create(web_contents(), num_popups); | 256 PopupBlockedInfoBarDelegate::Create(web_contents(), num_popups); |
250 | 257 |
251 settings->SetBlockageHasBeenIndicated(CONTENT_SETTINGS_TYPE_POPUPS); | 258 settings->SetBlockageHasBeenIndicated(CONTENT_SETTINGS_TYPE_POPUPS); |
252 } | 259 } |
253 break; | 260 break; |
254 } | 261 } |
255 case chrome::NOTIFICATION_FAVICON_UPDATED: | 262 case chrome::NOTIFICATION_FAVICON_UPDATED: |
256 Java_Tab_onFaviconUpdated(env, weak_java_tab_.get(env).obj()); | 263 Java_Tab_onFaviconUpdated(env, obj.obj()); |
257 break; | 264 break; |
258 case content::NOTIFICATION_NAV_ENTRY_CHANGED: | 265 case content::NOTIFICATION_NAV_ENTRY_CHANGED: |
259 Java_Tab_onNavEntryChanged(env, weak_java_tab_.get(env).obj()); | 266 Java_Tab_onNavEntryChanged(env, obj.obj()); |
260 break; | 267 break; |
261 default: | 268 default: |
262 NOTREACHED() << "Unexpected notification " << type; | 269 NOTREACHED() << "Unexpected notification " << type; |
263 break; | 270 break; |
264 } | 271 } |
265 } | 272 } |
266 | 273 |
267 void TabAndroid::Destroy(JNIEnv* env, jobject obj) { | 274 void TabAndroid::Destroy(JNIEnv* env, jobject obj) { |
268 delete this; | 275 delete this; |
269 } | 276 } |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
526 | 533 |
527 static void Init(JNIEnv* env, jobject obj) { | 534 static void Init(JNIEnv* env, jobject obj) { |
528 TRACE_EVENT0("native", "TabAndroid::Init"); | 535 TRACE_EVENT0("native", "TabAndroid::Init"); |
529 // This will automatically bind to the Java object and pass ownership there. | 536 // This will automatically bind to the Java object and pass ownership there. |
530 new TabAndroid(env, obj); | 537 new TabAndroid(env, obj); |
531 } | 538 } |
532 | 539 |
533 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { | 540 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { |
534 return RegisterNativesImpl(env); | 541 return RegisterNativesImpl(env); |
535 } | 542 } |
OLD | NEW |