Chromium Code Reviews| 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/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "cc/layers/layer.h" | |
| 12 #include "chrome/browser/android/chrome_web_contents_delegate_android.h" | 13 #include "chrome/browser/android/chrome_web_contents_delegate_android.h" |
| 14 #include "chrome/browser/android/compositor/tab_content_manager.h" | |
| 13 #include "chrome/browser/android/uma_utils.h" | 15 #include "chrome/browser/android/uma_utils.h" |
| 14 #include "chrome/browser/browser_about_handler.h" | 16 #include "chrome/browser/browser_about_handler.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 18 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 17 #include "chrome/browser/favicon/favicon_tab_helper.h" | 19 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 18 #include "chrome/browser/infobars/infobar_service.h" | 20 #include "chrome/browser/infobars/infobar_service.h" |
| 19 #include "chrome/browser/prerender/prerender_contents.h" | 21 #include "chrome/browser/prerender/prerender_contents.h" |
| 20 #include "chrome/browser/prerender/prerender_manager.h" | 22 #include "chrome/browser/prerender/prerender_manager.h" |
| 21 #include "chrome/browser/prerender/prerender_manager_factory.h" | 23 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 22 #include "chrome/browser/printing/print_view_manager_basic.h" | 24 #include "chrome/browser/printing/print_view_manager_basic.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 } | 105 } |
| 104 | 106 |
| 105 void TabAndroid::AttachTabHelpers(content::WebContents* web_contents) { | 107 void TabAndroid::AttachTabHelpers(content::WebContents* web_contents) { |
| 106 DCHECK(web_contents); | 108 DCHECK(web_contents); |
| 107 | 109 |
| 108 TabHelpers::AttachTabHelpers(web_contents); | 110 TabHelpers::AttachTabHelpers(web_contents); |
| 109 } | 111 } |
| 110 | 112 |
| 111 TabAndroid::TabAndroid(JNIEnv* env, jobject obj) | 113 TabAndroid::TabAndroid(JNIEnv* env, jobject obj) |
| 112 : weak_java_tab_(env, obj), | 114 : weak_java_tab_(env, obj), |
| 115 content_layer_(cc::Layer::Create()), | |
| 116 tab_content_manager_(NULL), | |
| 113 synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)) { | 117 synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)) { |
| 114 Java_Tab_setNativePtr(env, obj, reinterpret_cast<intptr_t>(this)); | 118 Java_Tab_setNativePtr(env, obj, reinterpret_cast<intptr_t>(this)); |
| 115 } | 119 } |
| 116 | 120 |
| 117 TabAndroid::~TabAndroid() { | 121 TabAndroid::~TabAndroid() { |
| 122 GetContentLayer()->RemoveAllChildren(); | |
|
Ted C
2015/02/06 01:52:39
will this not happen when it gets destroyed?
David Trainor- moved to gerrit
2015/02/06 18:37:04
It's a scoped_refptr, so if it's attached to anoth
| |
| 118 JNIEnv* env = base::android::AttachCurrentThread(); | 123 JNIEnv* env = base::android::AttachCurrentThread(); |
| 119 Java_Tab_clearNativePtr(env, weak_java_tab_.get(env).obj()); | 124 Java_Tab_clearNativePtr(env, weak_java_tab_.get(env).obj()); |
| 120 } | 125 } |
| 121 | 126 |
| 122 base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetJavaObject() { | 127 base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetJavaObject() { |
| 123 JNIEnv* env = base::android::AttachCurrentThread(); | 128 JNIEnv* env = base::android::AttachCurrentThread(); |
| 124 return weak_java_tab_.get(env); | 129 return weak_java_tab_.get(env); |
| 125 } | 130 } |
| 126 | 131 |
| 132 scoped_refptr<cc::Layer> TabAndroid::GetContentLayer() const { | |
| 133 return content_layer_; | |
| 134 } | |
| 135 | |
| 127 int TabAndroid::GetAndroidId() const { | 136 int TabAndroid::GetAndroidId() const { |
| 128 JNIEnv* env = base::android::AttachCurrentThread(); | 137 JNIEnv* env = base::android::AttachCurrentThread(); |
| 129 return Java_Tab_getId(env, weak_java_tab_.get(env).obj()); | 138 return Java_Tab_getId(env, weak_java_tab_.get(env).obj()); |
| 130 } | 139 } |
| 131 | 140 |
| 132 int TabAndroid::GetSyncId() const { | 141 int TabAndroid::GetSyncId() const { |
| 133 JNIEnv* env = base::android::AttachCurrentThread(); | 142 JNIEnv* env = base::android::AttachCurrentThread(); |
| 134 return Java_Tab_getSyncId(env, weak_java_tab_.get(env).obj()); | 143 return Java_Tab_getSyncId(env, weak_java_tab_.get(env).obj()); |
| 135 } | 144 } |
| 136 | 145 |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 synced_tab_delegate_->SetWebContents(web_contents()); | 441 synced_tab_delegate_->SetWebContents(web_contents()); |
| 433 | 442 |
| 434 // Verify that the WebContents this tab represents matches the expected | 443 // Verify that the WebContents this tab represents matches the expected |
| 435 // off the record state. | 444 // off the record state. |
| 436 CHECK_EQ(GetProfile()->IsOffTheRecord(), incognito); | 445 CHECK_EQ(GetProfile()->IsOffTheRecord(), incognito); |
| 437 | 446 |
| 438 InstantService* instant_service = | 447 InstantService* instant_service = |
| 439 InstantServiceFactory::GetForProfile(GetProfile()); | 448 InstantServiceFactory::GetForProfile(GetProfile()); |
| 440 if (instant_service) | 449 if (instant_service) |
| 441 instant_service->AddObserver(this); | 450 instant_service->AddObserver(this); |
| 451 | |
| 452 content_layer_->InsertChild(content_view_core->GetLayer(), 0); | |
| 442 } | 453 } |
| 443 | 454 |
| 444 void TabAndroid::DestroyWebContents(JNIEnv* env, | 455 void TabAndroid::DestroyWebContents(JNIEnv* env, |
| 445 jobject obj, | 456 jobject obj, |
| 446 jboolean delete_native) { | 457 jboolean delete_native) { |
| 447 DCHECK(web_contents()); | 458 DCHECK(web_contents()); |
| 448 | 459 |
| 460 content::ContentViewCore* content_view_core = GetContentViewCore(); | |
| 461 if (content_view_core) | |
| 462 content_view_core->GetLayer()->RemoveFromParent(); | |
|
Ted C
2015/02/06 01:52:39
is this not what the change in CVCImpl.cc is doing
David Trainor- moved to gerrit
2015/02/06 18:37:04
This doesn't explicitly call delete content_view_c
| |
| 463 | |
| 449 notification_registrar_.Remove( | 464 notification_registrar_.Remove( |
| 450 this, | 465 this, |
| 451 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, | 466 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
| 452 content::Source<content::WebContents>(web_contents())); | 467 content::Source<content::WebContents>(web_contents())); |
| 453 notification_registrar_.Remove( | 468 notification_registrar_.Remove( |
| 454 this, | 469 this, |
| 455 content::NOTIFICATION_NAV_ENTRY_CHANGED, | 470 content::NOTIFICATION_NAV_ENTRY_CHANGED, |
| 456 content::Source<content::NavigationController>( | 471 content::Source<content::NavigationController>( |
| 457 &web_contents()->GetController())); | 472 &web_contents()->GetController())); |
| 458 | 473 |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 735 } // namespace | 750 } // namespace |
| 736 | 751 |
| 737 void TabAndroid::SetInterceptNavigationDelegate(JNIEnv* env, jobject obj, | 752 void TabAndroid::SetInterceptNavigationDelegate(JNIEnv* env, jobject obj, |
| 738 jobject delegate) { | 753 jobject delegate) { |
| 739 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 754 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 740 InterceptNavigationDelegate::Associate( | 755 InterceptNavigationDelegate::Associate( |
| 741 web_contents(), | 756 web_contents(), |
| 742 make_scoped_ptr(new ChromeInterceptNavigationDelegate(env, delegate))); | 757 make_scoped_ptr(new ChromeInterceptNavigationDelegate(env, delegate))); |
| 743 } | 758 } |
| 744 | 759 |
| 760 void TabAndroid::AttachToTabContentManager(JNIEnv* env, | |
| 761 jobject obj, | |
| 762 jobject jtab_content_manager) { | |
| 763 chrome::android::TabContentManager* tab_content_manager = | |
| 764 chrome::android::TabContentManager::FromJavaObject(jtab_content_manager); | |
| 765 if (tab_content_manager == tab_content_manager_) | |
| 766 return; | |
| 767 | |
| 768 if (tab_content_manager_) | |
| 769 tab_content_manager_->DetachLiveLayer(GetAndroidId(), GetContentLayer()); | |
| 770 tab_content_manager_ = tab_content_manager; | |
| 771 if (tab_content_manager_) | |
| 772 tab_content_manager_->AttachLiveLayer(GetAndroidId(), GetContentLayer()); | |
| 773 } | |
| 774 | |
| 775 void TabAndroid::AttachOverlayContentViewCore(JNIEnv* env, | |
| 776 jobject obj, | |
| 777 jobject jcontent_view_core, | |
| 778 jboolean visible) { | |
| 779 content::ContentViewCore* content_view_core = | |
| 780 content::ContentViewCore::GetNativeContentViewCore(env, | |
| 781 jcontent_view_core); | |
| 782 if (!content_view_core) | |
|
Ted C
2015/02/06 01:52:39
should we allow this? same below
David Trainor- moved to gerrit
2015/02/06 18:37:04
Should we not allow null to be even passed in here
| |
| 783 return; | |
| 784 | |
| 785 content_view_core->GetLayer()->SetHideLayerAndSubtree(!visible); | |
| 786 content_layer_->AddChild(content_view_core->GetLayer()); | |
| 787 } | |
| 788 | |
| 789 void TabAndroid::DetachOverlayContentViewCore(JNIEnv* env, | |
| 790 jobject obj, | |
| 791 jobject jcontent_view_core) { | |
| 792 content::ContentViewCore* content_view_core = | |
| 793 content::ContentViewCore::GetNativeContentViewCore(env, | |
| 794 jcontent_view_core); | |
| 795 if (!content_view_core) | |
| 796 return; | |
| 797 | |
| 798 content_view_core->GetLayer()->RemoveFromParent(); | |
| 799 } | |
| 800 | |
| 801 void TabAndroid::SetOverlayContentViewCoreVisibility(JNIEnv* env, | |
| 802 jobject obj, | |
| 803 jobject jcontent_view_core, | |
| 804 jboolean visible) { | |
| 805 content::ContentViewCore* content_view_core = | |
|
Ted C
2015/02/06 01:52:39
seems odd to have this method on tab when it doesn
David Trainor- moved to gerrit
2015/02/06 18:37:04
Yeah I thought about that too. I can move it to C
| |
| 806 content::ContentViewCore::GetNativeContentViewCore(env, | |
| 807 jcontent_view_core); | |
| 808 if (!content_view_core) | |
| 809 return; | |
| 810 | |
| 811 content_view_core->GetLayer()->SetHideLayerAndSubtree(!visible); | |
| 812 } | |
| 813 | |
| 745 static void Init(JNIEnv* env, jobject obj) { | 814 static void Init(JNIEnv* env, jobject obj) { |
| 746 TRACE_EVENT0("native", "TabAndroid::Init"); | 815 TRACE_EVENT0("native", "TabAndroid::Init"); |
| 747 // This will automatically bind to the Java object and pass ownership there. | 816 // This will automatically bind to the Java object and pass ownership there. |
| 748 new TabAndroid(env, obj); | 817 new TabAndroid(env, obj); |
| 749 } | 818 } |
| 750 | 819 |
| 751 // static | 820 // static |
| 752 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { | 821 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { |
| 753 return RegisterNativesImpl(env); | 822 return RegisterNativesImpl(env); |
| 754 } | 823 } |
| 755 | 824 |
| 756 static void RecordStartupToCommitUma(JNIEnv* env, jclass jcaller) { | 825 static void RecordStartupToCommitUma(JNIEnv* env, jclass jcaller) { |
| 757 // Currently it takes about 2000ms to commit a navigation if the measurement | 826 // Currently it takes about 2000ms to commit a navigation if the measurement |
| 758 // begins very early in the browser start. How many buckets (b) are needed to | 827 // begins very early in the browser start. How many buckets (b) are needed to |
| 759 // explore the _typical_ values with granularity 100ms and a maximum duration | 828 // explore the _typical_ values with granularity 100ms and a maximum duration |
| 760 // of 1 minute? | 829 // of 1 minute? |
| 761 // s^{n+1} / s^{n} = 2100 / 2000 | 830 // s^{n+1} / s^{n} = 2100 / 2000 |
| 762 // s = 1.05 | 831 // s = 1.05 |
| 763 // s^b = 60000 | 832 // s^b = 60000 |
| 764 // b = ln(60000) / ln(1.05) ~= 225 | 833 // b = ln(60000) / ln(1.05) ~= 225 |
| 765 UMA_HISTOGRAM_CUSTOM_TIMES("Startup.FirstCommitNavigationTime", | 834 UMA_HISTOGRAM_CUSTOM_TIMES("Startup.FirstCommitNavigationTime", |
| 766 base::Time::Now() - chrome::android::GetMainEntryPointTime(), | 835 base::Time::Now() - chrome::android::GetMainEntryPointTime(), |
| 767 base::TimeDelta::FromMilliseconds(1), | 836 base::TimeDelta::FromMilliseconds(1), |
| 768 base::TimeDelta::FromMinutes(1), | 837 base::TimeDelta::FromMinutes(1), |
| 769 225); | 838 225); |
| 770 } | 839 } |
| OLD | NEW |