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

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

Issue 1299513002: [Android] Add support for a hung renderer dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 5 years, 4 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
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" 12 #include "cc/layers/layer.h"
13 #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" 14 #include "chrome/browser/android/compositor/tab_content_manager.h"
15 #include "chrome/browser/android/hung_renderer_infobar_delegate.h"
15 #include "chrome/browser/android/metrics/uma_utils.h" 16 #include "chrome/browser/android/metrics/uma_utils.h"
16 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 17 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
17 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" 18 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h"
18 #include "chrome/browser/browser_about_handler.h" 19 #include "chrome/browser/browser_about_handler.h"
19 #include "chrome/browser/chrome_notification_types.h" 20 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 21 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
21 #include "chrome/browser/infobars/infobar_service.h" 22 #include "chrome/browser/infobars/infobar_service.h"
22 #include "chrome/browser/prerender/prerender_contents.h" 23 #include "chrome/browser/prerender/prerender_contents.h"
23 #include "chrome/browser/prerender/prerender_manager.h" 24 #include "chrome/browser/prerender/prerender_manager.h"
24 #include "chrome/browser/prerender/prerender_manager_factory.h" 25 #include "chrome/browser/prerender/prerender_manager_factory.h"
(...skipping 21 matching lines...) Expand all
46 #include "chrome/browser/ui/tab_helpers.h" 47 #include "chrome/browser/ui/tab_helpers.h"
47 #include "chrome/common/instant_types.h" 48 #include "chrome/common/instant_types.h"
48 #include "chrome/common/render_messages.h" 49 #include "chrome/common/render_messages.h"
49 #include "chrome/common/url_constants.h" 50 #include "chrome/common/url_constants.h"
50 #include "components/bookmarks/browser/bookmark_model.h" 51 #include "components/bookmarks/browser/bookmark_model.h"
51 #include "components/bookmarks/browser/bookmark_node.h" 52 #include "components/bookmarks/browser/bookmark_node.h"
52 #include "components/bookmarks/browser/bookmark_utils.h" 53 #include "components/bookmarks/browser/bookmark_utils.h"
53 #include "components/bookmarks/managed/managed_bookmark_service.h" 54 #include "components/bookmarks/managed/managed_bookmark_service.h"
54 #include "components/dom_distiller/core/url_utils.h" 55 #include "components/dom_distiller/core/url_utils.h"
55 #include "components/favicon/content/content_favicon_driver.h" 56 #include "components/favicon/content/content_favicon_driver.h"
57 #include "components/infobars/core/infobar.h"
56 #include "components/infobars/core/infobar_container.h" 58 #include "components/infobars/core/infobar_container.h"
57 #include "components/navigation_interception/intercept_navigation_delegate.h" 59 #include "components/navigation_interception/intercept_navigation_delegate.h"
58 #include "components/navigation_interception/navigation_params.h" 60 #include "components/navigation_interception/navigation_params.h"
59 #include "components/url_formatter/url_fixer.h" 61 #include "components/url_formatter/url_fixer.h"
60 #include "content/public/browser/android/compositor.h" 62 #include "content/public/browser/android/compositor.h"
61 #include "content/public/browser/android/content_view_core.h" 63 #include "content/public/browser/android/content_view_core.h"
62 #include "content/public/browser/browser_thread.h" 64 #include "content/public/browser/browser_thread.h"
63 #include "content/public/browser/interstitial_page.h" 65 #include "content/public/browser/interstitial_page.h"
64 #include "content/public/browser/navigation_entry.h" 66 #include "content/public/browser/navigation_entry.h"
65 #include "content/public/browser/notification_service.h" 67 #include "content/public/browser/notification_service.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 void TabAndroid::AttachTabHelpers(content::WebContents* web_contents) { 119 void TabAndroid::AttachTabHelpers(content::WebContents* web_contents) {
118 DCHECK(web_contents); 120 DCHECK(web_contents);
119 121
120 TabHelpers::AttachTabHelpers(web_contents); 122 TabHelpers::AttachTabHelpers(web_contents);
121 } 123 }
122 124
123 TabAndroid::TabAndroid(JNIEnv* env, jobject obj) 125 TabAndroid::TabAndroid(JNIEnv* env, jobject obj)
124 : weak_java_tab_(env, obj), 126 : weak_java_tab_(env, obj),
125 content_layer_(cc::Layer::Create(content::Compositor::LayerSettings())), 127 content_layer_(cc::Layer::Create(content::Compositor::LayerSettings())),
126 tab_content_manager_(NULL), 128 tab_content_manager_(NULL),
127 synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)) { 129 synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)),
130 hung_renderer_infobar_(nullptr) {
128 Java_Tab_setNativePtr(env, obj, reinterpret_cast<intptr_t>(this)); 131 Java_Tab_setNativePtr(env, obj, reinterpret_cast<intptr_t>(this));
129 } 132 }
130 133
131 TabAndroid::~TabAndroid() { 134 TabAndroid::~TabAndroid() {
132 GetContentLayer()->RemoveAllChildren(); 135 GetContentLayer()->RemoveAllChildren();
133 JNIEnv* env = base::android::AttachCurrentThread(); 136 JNIEnv* env = base::android::AttachCurrentThread();
134 Java_Tab_clearNativePtr(env, weak_java_tab_.get(env).obj()); 137 Java_Tab_clearNativePtr(env, weak_java_tab_.get(env).obj());
135 } 138 }
136 139
137 base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetJavaObject() { 140 base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetJavaObject() {
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 387
385 JNIEnv *env = base::android::AttachCurrentThread(); 388 JNIEnv *env = base::android::AttachCurrentThread();
386 Java_Tab_onFaviconAvailable(env, weak_java_tab_.get(env).obj(), 389 Java_Tab_onFaviconAvailable(env, weak_java_tab_.get(env).obj(),
387 gfx::ConvertToJavaBitmap(&favicon).obj()); 390 gfx::ConvertToJavaBitmap(&favicon).obj());
388 } 391 }
389 392
390 void TabAndroid::OnFaviconUpdated(favicon::FaviconDriver* favicon_driver, 393 void TabAndroid::OnFaviconUpdated(favicon::FaviconDriver* favicon_driver,
391 bool icon_url_changed) { 394 bool icon_url_changed) {
392 } 395 }
393 396
397 void TabAndroid::OnInfoBarRemoved(infobars::InfoBar* infobar, bool animate) {
398 if (hung_renderer_infobar_ && hung_renderer_infobar_ == infobar)
399 hung_renderer_infobar_ = nullptr;
400 }
401
394 void TabAndroid::Destroy(JNIEnv* env, jobject obj) { 402 void TabAndroid::Destroy(JNIEnv* env, jobject obj) {
395 delete this; 403 delete this;
396 } 404 }
397 405
398 void TabAndroid::InitWebContents(JNIEnv* env, 406 void TabAndroid::InitWebContents(JNIEnv* env,
399 jobject obj, 407 jobject obj,
400 jboolean incognito, 408 jboolean incognito,
401 jobject jcontent_view_core, 409 jobject jcontent_view_core,
402 jobject jweb_contents_delegate, 410 jobject jweb_contents_delegate,
403 jobject jcontext_menu_populator) { 411 jobject jcontext_menu_populator) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 454
447 // Verify that the WebContents this tab represents matches the expected 455 // Verify that the WebContents this tab represents matches the expected
448 // off the record state. 456 // off the record state.
449 CHECK_EQ(GetProfile()->IsOffTheRecord(), incognito); 457 CHECK_EQ(GetProfile()->IsOffTheRecord(), incognito);
450 458
451 InstantService* instant_service = 459 InstantService* instant_service =
452 InstantServiceFactory::GetForProfile(GetProfile()); 460 InstantServiceFactory::GetForProfile(GetProfile());
453 if (instant_service) 461 if (instant_service)
454 instant_service->AddObserver(this); 462 instant_service->AddObserver(this);
455 463
464 InfoBarService* infobar_service =
465 InfoBarService::FromWebContents(web_contents());
466 if (infobar_service)
467 infobar_service->AddObserver(this);
468
456 content_layer_->InsertChild(content_view_core->GetLayer(), 0); 469 content_layer_->InsertChild(content_view_core->GetLayer(), 0);
457 } 470 }
458 471
459 void TabAndroid::DestroyWebContents(JNIEnv* env, 472 void TabAndroid::DestroyWebContents(JNIEnv* env,
460 jobject obj, 473 jobject obj,
461 jboolean delete_native) { 474 jboolean delete_native) {
462 DCHECK(web_contents()); 475 DCHECK(web_contents());
463 476
464 content::ContentViewCore* content_view_core = GetContentViewCore(); 477 content::ContentViewCore* content_view_core = GetContentViewCore();
465 if (content_view_core) 478 if (content_view_core)
(...skipping 13 matching lines...) Expand all
479 favicon::ContentFaviconDriver::FromWebContents(web_contents_.get()); 492 favicon::ContentFaviconDriver::FromWebContents(web_contents_.get());
480 493
481 if (favicon_driver) 494 if (favicon_driver)
482 favicon_driver->RemoveObserver(this); 495 favicon_driver->RemoveObserver(this);
483 496
484 InstantService* instant_service = 497 InstantService* instant_service =
485 InstantServiceFactory::GetForProfile(GetProfile()); 498 InstantServiceFactory::GetForProfile(GetProfile());
486 if (instant_service) 499 if (instant_service)
487 instant_service->RemoveObserver(this); 500 instant_service->RemoveObserver(this);
488 501
502 InfoBarService* infobar_service =
503 InfoBarService::FromWebContents(web_contents());
504 if (infobar_service)
505 infobar_service->RemoveObserver(this);
506
489 web_contents()->SetDelegate(NULL); 507 web_contents()->SetDelegate(NULL);
490 508
491 if (delete_native) { 509 if (delete_native) {
492 // Terminate the renderer process if this is the last tab. 510 // Terminate the renderer process if this is the last tab.
493 // If there's no unload listener, FastShutdownForPageCount kills the 511 // If there's no unload listener, FastShutdownForPageCount kills the
494 // renderer process. Otherwise, we go with the slow path where renderer 512 // renderer process. Otherwise, we go with the slow path where renderer
495 // process shuts down itself when ref count becomes 0. 513 // process shuts down itself when ref count becomes 0.
496 // This helps the render process exit quickly which avoids some issues 514 // This helps the render process exit quickly which avoids some issues
497 // during shutdown. See https://codereview.chromium.org/146693011/ 515 // during shutdown. See https://codereview.chromium.org/146693011/
498 // and http://crbug.com/338709 for details. 516 // and http://crbug.com/338709 for details.
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 } 805 }
788 806
789 return -1; 807 return -1;
790 } 808 }
791 809
792 bool TabAndroid::HasPrerenderedUrl(JNIEnv* env, jobject obj, jstring url) { 810 bool TabAndroid::HasPrerenderedUrl(JNIEnv* env, jobject obj, jstring url) {
793 GURL gurl(base::android::ConvertJavaStringToUTF8(env, url)); 811 GURL gurl(base::android::ConvertJavaStringToUTF8(env, url));
794 return HasPrerenderedUrl(gurl); 812 return HasPrerenderedUrl(gurl);
795 } 813 }
796 814
815 void TabAndroid::ShowHungRendererInfoBar(JNIEnv* env, jobject obj) {
816 DCHECK(!hung_renderer_infobar_);
817 InfoBarService* infobar_service =
818 InfoBarService::FromWebContents(web_contents());
819 if (!infobar_service)
820 return;
821
822 scoped_ptr<ConfirmInfoBarDelegate> delegate(
823 new HungRendererInfoBarDelegate(web_contents()));
824 hung_renderer_infobar_ = infobar_service->AddInfoBar(
825 infobar_service->CreateConfirmInfoBar(delegate.Pass()));
826 }
827
828 void TabAndroid::DismissHungRendererInfoBar(JNIEnv* env, jobject obj) {
829 if (!hung_renderer_infobar_)
gone 2015/08/18 20:45:17 instead of hanging onto the infobar*, would it mak
jdduke (slow) 2015/08/21 21:18:30 How would we know we've found it while iterating i
gone 2015/08/21 21:39:30 I think it'd be a little better safety-wise to add
830 return;
831
832 InfoBarService* infobar_service =
833 InfoBarService::FromWebContents(web_contents());
834 if (!infobar_service)
835 return;
836
837 infobar_service->RemoveInfoBar(hung_renderer_infobar_);
838 }
839
797 namespace { 840 namespace {
798 841
799 class ChromeInterceptNavigationDelegate : public InterceptNavigationDelegate { 842 class ChromeInterceptNavigationDelegate : public InterceptNavigationDelegate {
800 public: 843 public:
801 ChromeInterceptNavigationDelegate(JNIEnv* env, jobject jdelegate) 844 ChromeInterceptNavigationDelegate(JNIEnv* env, jobject jdelegate)
802 : InterceptNavigationDelegate(env, jdelegate) {} 845 : InterceptNavigationDelegate(env, jdelegate) {}
803 846
804 bool ShouldIgnoreNavigation( 847 bool ShouldIgnoreNavigation(
805 const NavigationParams& navigation_params) override { 848 const NavigationParams& navigation_params) override {
806 NavigationParams chrome_navigation_params(navigation_params); 849 NavigationParams chrome_navigation_params(navigation_params);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 // s^{n+1} / s^{n} = 2100 / 2000 923 // s^{n+1} / s^{n} = 2100 / 2000
881 // s = 1.05 924 // s = 1.05
882 // s^b = 60000 925 // s^b = 60000
883 // b = ln(60000) / ln(1.05) ~= 225 926 // b = ln(60000) / ln(1.05) ~= 225
884 UMA_HISTOGRAM_CUSTOM_TIMES("Startup.FirstCommitNavigationTime", 927 UMA_HISTOGRAM_CUSTOM_TIMES("Startup.FirstCommitNavigationTime",
885 base::Time::Now() - chrome::android::GetMainEntryPointTime(), 928 base::Time::Now() - chrome::android::GetMainEntryPointTime(),
886 base::TimeDelta::FromMilliseconds(1), 929 base::TimeDelta::FromMilliseconds(1),
887 base::TimeDelta::FromMinutes(1), 930 base::TimeDelta::FromMinutes(1),
888 225); 931 225);
889 } 932 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698