| 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(); |
| 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(); |
| 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 DCHECK(content_view_core); |
| 783 |
| 784 content_view_core->GetLayer()->SetHideLayerAndSubtree(!visible); |
| 785 content_layer_->AddChild(content_view_core->GetLayer()); |
| 786 } |
| 787 |
| 788 void TabAndroid::DetachOverlayContentViewCore(JNIEnv* env, |
| 789 jobject obj, |
| 790 jobject jcontent_view_core) { |
| 791 content::ContentViewCore* content_view_core = |
| 792 content::ContentViewCore::GetNativeContentViewCore(env, |
| 793 jcontent_view_core); |
| 794 DCHECK(content_view_core); |
| 795 |
| 796 content_view_core->GetLayer()->RemoveFromParent(); |
| 797 } |
| 798 |
| 745 static void Init(JNIEnv* env, jobject obj) { | 799 static void Init(JNIEnv* env, jobject obj) { |
| 746 TRACE_EVENT0("native", "TabAndroid::Init"); | 800 TRACE_EVENT0("native", "TabAndroid::Init"); |
| 747 // This will automatically bind to the Java object and pass ownership there. | 801 // This will automatically bind to the Java object and pass ownership there. |
| 748 new TabAndroid(env, obj); | 802 new TabAndroid(env, obj); |
| 749 } | 803 } |
| 750 | 804 |
| 751 // static | 805 // static |
| 752 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { | 806 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { |
| 753 return RegisterNativesImpl(env); | 807 return RegisterNativesImpl(env); |
| 754 } | 808 } |
| 755 | 809 |
| 756 static void RecordStartupToCommitUma(JNIEnv* env, jclass jcaller) { | 810 static void RecordStartupToCommitUma(JNIEnv* env, jclass jcaller) { |
| 757 // Currently it takes about 2000ms to commit a navigation if the measurement | 811 // 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 | 812 // 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 | 813 // explore the _typical_ values with granularity 100ms and a maximum duration |
| 760 // of 1 minute? | 814 // of 1 minute? |
| 761 // s^{n+1} / s^{n} = 2100 / 2000 | 815 // s^{n+1} / s^{n} = 2100 / 2000 |
| 762 // s = 1.05 | 816 // s = 1.05 |
| 763 // s^b = 60000 | 817 // s^b = 60000 |
| 764 // b = ln(60000) / ln(1.05) ~= 225 | 818 // b = ln(60000) / ln(1.05) ~= 225 |
| 765 UMA_HISTOGRAM_CUSTOM_TIMES("Startup.FirstCommitNavigationTime", | 819 UMA_HISTOGRAM_CUSTOM_TIMES("Startup.FirstCommitNavigationTime", |
| 766 base::Time::Now() - chrome::android::GetMainEntryPointTime(), | 820 base::Time::Now() - chrome::android::GetMainEntryPointTime(), |
| 767 base::TimeDelta::FromMilliseconds(1), | 821 base::TimeDelta::FromMilliseconds(1), |
| 768 base::TimeDelta::FromMinutes(1), | 822 base::TimeDelta::FromMinutes(1), |
| 769 225); | 823 225); |
| 770 } | 824 } |
| OLD | NEW |