Commit e8bbb37f authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Disable fullscreen for SadTab.

Additionally, this CL updates CRWGenericContentView's contentSize
adjustment logic to ensure that scrolling doesn't get disabled.

Bug: 807957
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Idf48f9b79966520f31477b0a58415eb286f037ae
Reviewed-on: https://chromium-review.googlesource.com/917642Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537450}
parent 374de998
...@@ -36,9 +36,11 @@ source_set("web") { ...@@ -36,9 +36,11 @@ source_set("web") {
"//components/strings", "//components/strings",
"//ios/chrome/app/strings:ios_strings_grit", "//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser", "//ios/chrome/browser",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/snapshots", "//ios/chrome/browser/snapshots",
"//ios/chrome/browser/ui", "//ios/chrome/browser/ui",
"//ios/chrome/browser/ui/commands:commands", "//ios/chrome/browser/ui/commands:commands",
"//ios/chrome/browser/ui/fullscreen",
"//ios/chrome/browser/ui/util:util", "//ios/chrome/browser/ui/util:util",
"//ios/web", "//ios/web",
"//ui/base", "//ui/base",
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#import "ios/web/public/web_state/web_state_user_data.h" #import "ios/web/public/web_state/web_state_user_data.h"
@protocol SadTabTabHelperDelegate; @protocol SadTabTabHelperDelegate;
class ScopedFullscreenDisabler;
// SadTabTabHelper listens to RenderProcessGone events and presents a // SadTabTabHelper listens to RenderProcessGone events and presents a
// SadTabView view appropriately. // SadTabView view appropriately.
...@@ -53,6 +54,10 @@ class SadTabTabHelper : public web::WebStateUserData<SadTabTabHelper>, ...@@ -53,6 +54,10 @@ class SadTabTabHelper : public web::WebStateUserData<SadTabTabHelper>,
// Presents a new SadTabView via the web_state object. // Presents a new SadTabView via the web_state object.
void PresentSadTab(const GURL& url_causing_failure); void PresentSadTab(const GURL& url_causing_failure);
// Called when the Sad Tab is added or removed from the WebState's content
// area.
void SetIsShowingSadTab(bool showing_sad_tab);
// Loads the current page after renderer crash while displaying the page // Loads the current page after renderer crash while displaying the page
// placeholder during the load. Reloading the page which was not visible to // placeholder during the load. Reloading the page which was not visible to
// the user during the crash is a better user experience than presenting // the user during the crash is a better user experience than presenting
...@@ -67,9 +72,16 @@ class SadTabTabHelper : public web::WebStateUserData<SadTabTabHelper>, ...@@ -67,9 +72,16 @@ class SadTabTabHelper : public web::WebStateUserData<SadTabTabHelper>,
// Removes UIApplicationDidBecomeActiveNotification observer. // Removes UIApplicationDidBecomeActiveNotification observer.
void RemoveApplicationDidBecomeActiveObserver(); void RemoveApplicationDidBecomeActiveObserver();
// Creates or resets the fullscreen disabler depending on whether the sad tab
// is currently visible.
void UpdateFullscreenDisabler();
// WebStateObserver: // WebStateObserver:
void WasShown(web::WebState* web_state) override; void WasShown(web::WebState* web_state) override;
void WasHidden(web::WebState* web_state) override;
void RenderProcessGone(web::WebState* web_state) override; void RenderProcessGone(web::WebState* web_state) override;
void DidStartNavigation(web::WebState* web_state,
web::NavigationContext* navigation_context) override;
void DidFinishNavigation(web::WebState* web_state, void DidFinishNavigation(web::WebState* web_state,
web::NavigationContext* navigation_context) override; web::NavigationContext* navigation_context) override;
void WebStateDestroyed(web::WebState* web_state) override; void WebStateDestroyed(web::WebState* web_state) override;
...@@ -90,6 +102,12 @@ class SadTabTabHelper : public web::WebStateUserData<SadTabTabHelper>, ...@@ -90,6 +102,12 @@ class SadTabTabHelper : public web::WebStateUserData<SadTabTabHelper>,
// used to determine time window for repeated crashes. // used to determine time window for repeated crashes.
std::unique_ptr<base::ElapsedTimer> last_failed_timer_; std::unique_ptr<base::ElapsedTimer> last_failed_timer_;
// Whether a Sad Tab is being shown over |web_state_|'s content area.
bool showing_sad_tab_ = false;
// The fullscreen disabler for when the sad tab is visible.
std::unique_ptr<ScopedFullscreenDisabler> fullscreen_disabler_;
// Stores the interval window in seconds during which a second // Stores the interval window in seconds during which a second
// RenderProcessGone failure will be considered a repeat failure. // RenderProcessGone failure will be considered a repeat failure.
double repeat_failure_interval_ = kDefaultRepeatFailureInterval; double repeat_failure_interval_ = kDefaultRepeatFailureInterval;
......
...@@ -12,11 +12,15 @@ ...@@ -12,11 +12,15 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/chrome_url_constants.h" #include "ios/chrome/browser/chrome_url_constants.h"
#include "ios/chrome/browser/ui/fullscreen/fullscreen_controller_factory.h"
#include "ios/chrome/browser/ui/fullscreen/scoped_fullscreen_disabler.h"
#import "ios/chrome/browser/web/page_placeholder_tab_helper.h" #import "ios/chrome/browser/web/page_placeholder_tab_helper.h"
#import "ios/chrome/browser/web/sad_tab_tab_helper_delegate.h" #import "ios/chrome/browser/web/sad_tab_tab_helper_delegate.h"
#import "ios/web/public/navigation_manager.h" #import "ios/web/public/navigation_manager.h"
#include "ios/web/public/web_state/navigation_context.h" #include "ios/web/public/web_state/navigation_context.h"
#include "ios/web/public/web_state/web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -83,6 +87,11 @@ void SadTabTabHelper::WasShown(web::WebState* web_state) { ...@@ -83,6 +87,11 @@ void SadTabTabHelper::WasShown(web::WebState* web_state) {
ReloadTab(); ReloadTab();
requires_reload_on_becoming_visible_ = false; requires_reload_on_becoming_visible_ = false;
} }
UpdateFullscreenDisabler();
}
void SadTabTabHelper::WasHidden(web::WebState* web_state) {
UpdateFullscreenDisabler();
} }
void SadTabTabHelper::RenderProcessGone(web::WebState* web_state) { void SadTabTabHelper::RenderProcessGone(web::WebState* web_state) {
...@@ -103,6 +112,13 @@ void SadTabTabHelper::RenderProcessGone(web::WebState* web_state) { ...@@ -103,6 +112,13 @@ void SadTabTabHelper::RenderProcessGone(web::WebState* web_state) {
PresentSadTab(web_state->GetLastCommittedURL()); PresentSadTab(web_state->GetLastCommittedURL());
} }
void SadTabTabHelper::DidStartNavigation(
web::WebState* web_state,
web::NavigationContext* navigation_context) {
// The sad tab is removed when a new navigation begins.
SetIsShowingSadTab(false);
}
void SadTabTabHelper::DidFinishNavigation( void SadTabTabHelper::DidFinishNavigation(
web::WebState* web_state, web::WebState* web_state,
web::NavigationContext* navigation_context) { web::NavigationContext* navigation_context) {
...@@ -136,6 +152,15 @@ void SadTabTabHelper::PresentSadTab(const GURL& url_causing_failure) { ...@@ -136,6 +152,15 @@ void SadTabTabHelper::PresentSadTab(const GURL& url_causing_failure) {
last_failed_url_ = url_causing_failure; last_failed_url_ = url_causing_failure;
last_failed_timer_ = std::make_unique<base::ElapsedTimer>(); last_failed_timer_ = std::make_unique<base::ElapsedTimer>();
SetIsShowingSadTab(true);
}
void SadTabTabHelper::SetIsShowingSadTab(bool showing_sad_tab) {
if (showing_sad_tab_ != showing_sad_tab) {
showing_sad_tab_ = showing_sad_tab;
UpdateFullscreenDisabler();
}
} }
void SadTabTabHelper::ReloadTab() { void SadTabTabHelper::ReloadTab() {
...@@ -173,3 +198,20 @@ void SadTabTabHelper::RemoveApplicationDidBecomeActiveObserver() { ...@@ -173,3 +198,20 @@ void SadTabTabHelper::RemoveApplicationDidBecomeActiveObserver() {
application_did_become_active_observer_ = nil; application_did_become_active_observer_ = nil;
} }
} }
void SadTabTabHelper::UpdateFullscreenDisabler() {
if (showing_sad_tab_ && web_state_->IsVisible()) {
ios::ChromeBrowserState* browser_state =
ios::ChromeBrowserState::FromBrowserState(
web_state_->GetBrowserState());
FullscreenController* fullscreen_controller =
FullscreenControllerFactory::GetInstance()->GetForBrowserState(
browser_state);
if (fullscreen_controller) {
fullscreen_disabler_ =
std::make_unique<ScopedFullscreenDisabler>(fullscreen_controller);
}
} else {
fullscreen_disabler_ = nullptr;
}
}
...@@ -90,10 +90,10 @@ ...@@ -90,10 +90,10 @@
self.view.frame = CGRectMake(0.0, 0.0, viewSize.width, viewSize.height); self.view.frame = CGRectMake(0.0, 0.0, viewSize.width, viewSize.height);
// UIScrollViews only scroll vertically if the content size's height is // UIScrollViews only scroll vertically if the content size's height is
// greater than that of its content rect. // greater than that of its bounds.
if (viewSize.height <= CGRectGetHeight(contentRect)) { if (viewSize.height <= _lastLayoutSize.height) {
CGFloat singlePixel = 1.0f / [[UIScreen mainScreen] scale]; CGFloat singlePixel = 1.0f / [[UIScreen mainScreen] scale];
viewSize.height = CGRectGetHeight(contentRect) + singlePixel; viewSize.height = _lastLayoutSize.height + singlePixel;
} }
self.scrollView.contentSize = viewSize; self.scrollView.contentSize = viewSize;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment