Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Side by Side Diff: chrome/browser/android/tab_android.cc

Issue 908093003: Revert of Add support for ContentViewCore helpers on Tab (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/android/tab_android.h ('k') | content/browser/android/content_view_core_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
13 #include "chrome/browser/android/chrome_web_contents_delegate_android.h" 12 #include "chrome/browser/android/chrome_web_contents_delegate_android.h"
14 #include "chrome/browser/android/compositor/tab_content_manager.h"
15 #include "chrome/browser/android/uma_utils.h" 13 #include "chrome/browser/android/uma_utils.h"
16 #include "chrome/browser/browser_about_handler.h" 14 #include "chrome/browser/browser_about_handler.h"
17 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 16 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
19 #include "chrome/browser/favicon/favicon_tab_helper.h" 17 #include "chrome/browser/favicon/favicon_tab_helper.h"
20 #include "chrome/browser/infobars/infobar_service.h" 18 #include "chrome/browser/infobars/infobar_service.h"
21 #include "chrome/browser/prerender/prerender_contents.h" 19 #include "chrome/browser/prerender/prerender_contents.h"
22 #include "chrome/browser/prerender/prerender_manager.h" 20 #include "chrome/browser/prerender/prerender_manager.h"
23 #include "chrome/browser/prerender/prerender_manager_factory.h" 21 #include "chrome/browser/prerender/prerender_manager_factory.h"
24 #include "chrome/browser/printing/print_view_manager_basic.h" 22 #include "chrome/browser/printing/print_view_manager_basic.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 103 }
106 104
107 void TabAndroid::AttachTabHelpers(content::WebContents* web_contents) { 105 void TabAndroid::AttachTabHelpers(content::WebContents* web_contents) {
108 DCHECK(web_contents); 106 DCHECK(web_contents);
109 107
110 TabHelpers::AttachTabHelpers(web_contents); 108 TabHelpers::AttachTabHelpers(web_contents);
111 } 109 }
112 110
113 TabAndroid::TabAndroid(JNIEnv* env, jobject obj) 111 TabAndroid::TabAndroid(JNIEnv* env, jobject obj)
114 : weak_java_tab_(env, obj), 112 : weak_java_tab_(env, obj),
115 content_layer_(cc::Layer::Create()),
116 tab_content_manager_(NULL),
117 synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)) { 113 synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)) {
118 Java_Tab_setNativePtr(env, obj, reinterpret_cast<intptr_t>(this)); 114 Java_Tab_setNativePtr(env, obj, reinterpret_cast<intptr_t>(this));
119 } 115 }
120 116
121 TabAndroid::~TabAndroid() { 117 TabAndroid::~TabAndroid() {
122 GetContentLayer()->RemoveAllChildren();
123 JNIEnv* env = base::android::AttachCurrentThread(); 118 JNIEnv* env = base::android::AttachCurrentThread();
124 Java_Tab_clearNativePtr(env, weak_java_tab_.get(env).obj()); 119 Java_Tab_clearNativePtr(env, weak_java_tab_.get(env).obj());
125 } 120 }
126 121
127 base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetJavaObject() { 122 base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetJavaObject() {
128 JNIEnv* env = base::android::AttachCurrentThread(); 123 JNIEnv* env = base::android::AttachCurrentThread();
129 return weak_java_tab_.get(env); 124 return weak_java_tab_.get(env);
130 } 125 }
131 126
132 scoped_refptr<cc::Layer> TabAndroid::GetContentLayer() const {
133 return content_layer_;
134 }
135
136 int TabAndroid::GetAndroidId() const { 127 int TabAndroid::GetAndroidId() const {
137 JNIEnv* env = base::android::AttachCurrentThread(); 128 JNIEnv* env = base::android::AttachCurrentThread();
138 return Java_Tab_getId(env, weak_java_tab_.get(env).obj()); 129 return Java_Tab_getId(env, weak_java_tab_.get(env).obj());
139 } 130 }
140 131
141 int TabAndroid::GetSyncId() const { 132 int TabAndroid::GetSyncId() const {
142 JNIEnv* env = base::android::AttachCurrentThread(); 133 JNIEnv* env = base::android::AttachCurrentThread();
143 return Java_Tab_getSyncId(env, weak_java_tab_.get(env).obj()); 134 return Java_Tab_getSyncId(env, weak_java_tab_.get(env).obj());
144 } 135 }
145 136
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 synced_tab_delegate_->SetWebContents(web_contents()); 432 synced_tab_delegate_->SetWebContents(web_contents());
442 433
443 // Verify that the WebContents this tab represents matches the expected 434 // Verify that the WebContents this tab represents matches the expected
444 // off the record state. 435 // off the record state.
445 CHECK_EQ(GetProfile()->IsOffTheRecord(), incognito); 436 CHECK_EQ(GetProfile()->IsOffTheRecord(), incognito);
446 437
447 InstantService* instant_service = 438 InstantService* instant_service =
448 InstantServiceFactory::GetForProfile(GetProfile()); 439 InstantServiceFactory::GetForProfile(GetProfile());
449 if (instant_service) 440 if (instant_service)
450 instant_service->AddObserver(this); 441 instant_service->AddObserver(this);
451
452 content_layer_->InsertChild(content_view_core->GetLayer(), 0);
453 } 442 }
454 443
455 void TabAndroid::DestroyWebContents(JNIEnv* env, 444 void TabAndroid::DestroyWebContents(JNIEnv* env,
456 jobject obj, 445 jobject obj,
457 jboolean delete_native) { 446 jboolean delete_native) {
458 DCHECK(web_contents()); 447 DCHECK(web_contents());
459 448
460 content::ContentViewCore* content_view_core = GetContentViewCore();
461 if (content_view_core)
462 content_view_core->GetLayer()->RemoveFromParent();
463
464 notification_registrar_.Remove( 449 notification_registrar_.Remove(
465 this, 450 this,
466 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, 451 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
467 content::Source<content::WebContents>(web_contents())); 452 content::Source<content::WebContents>(web_contents()));
468 notification_registrar_.Remove( 453 notification_registrar_.Remove(
469 this, 454 this,
470 content::NOTIFICATION_NAV_ENTRY_CHANGED, 455 content::NOTIFICATION_NAV_ENTRY_CHANGED,
471 content::Source<content::NavigationController>( 456 content::Source<content::NavigationController>(
472 &web_contents()->GetController())); 457 &web_contents()->GetController()));
473 458
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 } // namespace 735 } // namespace
751 736
752 void TabAndroid::SetInterceptNavigationDelegate(JNIEnv* env, jobject obj, 737 void TabAndroid::SetInterceptNavigationDelegate(JNIEnv* env, jobject obj,
753 jobject delegate) { 738 jobject delegate) {
754 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 739 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
755 InterceptNavigationDelegate::Associate( 740 InterceptNavigationDelegate::Associate(
756 web_contents(), 741 web_contents(),
757 make_scoped_ptr(new ChromeInterceptNavigationDelegate(env, delegate))); 742 make_scoped_ptr(new ChromeInterceptNavigationDelegate(env, delegate)));
758 } 743 }
759 744
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
799 static void Init(JNIEnv* env, jobject obj) { 745 static void Init(JNIEnv* env, jobject obj) {
800 TRACE_EVENT0("native", "TabAndroid::Init"); 746 TRACE_EVENT0("native", "TabAndroid::Init");
801 // This will automatically bind to the Java object and pass ownership there. 747 // This will automatically bind to the Java object and pass ownership there.
802 new TabAndroid(env, obj); 748 new TabAndroid(env, obj);
803 } 749 }
804 750
805 // static 751 // static
806 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { 752 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) {
807 return RegisterNativesImpl(env); 753 return RegisterNativesImpl(env);
808 } 754 }
809 755
810 static void RecordStartupToCommitUma(JNIEnv* env, jclass jcaller) { 756 static void RecordStartupToCommitUma(JNIEnv* env, jclass jcaller) {
811 // Currently it takes about 2000ms to commit a navigation if the measurement 757 // Currently it takes about 2000ms to commit a navigation if the measurement
812 // begins very early in the browser start. How many buckets (b) are needed to 758 // begins very early in the browser start. How many buckets (b) are needed to
813 // explore the _typical_ values with granularity 100ms and a maximum duration 759 // explore the _typical_ values with granularity 100ms and a maximum duration
814 // of 1 minute? 760 // of 1 minute?
815 // s^{n+1} / s^{n} = 2100 / 2000 761 // s^{n+1} / s^{n} = 2100 / 2000
816 // s = 1.05 762 // s = 1.05
817 // s^b = 60000 763 // s^b = 60000
818 // b = ln(60000) / ln(1.05) ~= 225 764 // b = ln(60000) / ln(1.05) ~= 225
819 UMA_HISTOGRAM_CUSTOM_TIMES("Startup.FirstCommitNavigationTime", 765 UMA_HISTOGRAM_CUSTOM_TIMES("Startup.FirstCommitNavigationTime",
820 base::Time::Now() - chrome::android::GetMainEntryPointTime(), 766 base::Time::Now() - chrome::android::GetMainEntryPointTime(),
821 base::TimeDelta::FromMilliseconds(1), 767 base::TimeDelta::FromMilliseconds(1),
822 base::TimeDelta::FromMinutes(1), 768 base::TimeDelta::FromMinutes(1),
823 225); 769 225);
824 } 770 }
OLDNEW
« no previous file with comments | « chrome/browser/android/tab_android.h ('k') | content/browser/android/content_view_core_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698