Commit 012a9764 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Added WebState::IsVisible() method.

This method will be used to gracefully handle SSL errors when WebState
is not in a tab.

Bug: None
Change-Id: Iee02ce69deda84d595e6bd5ab815317afb82f12d
Reviewed-on: https://chromium-review.googlesource.com/683464
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#504472}
parent 2bb2b389
...@@ -54,6 +54,7 @@ class TestWebState : public WebState { ...@@ -54,6 +54,7 @@ class TestWebState : public WebState {
const base::string16& GetTitle() const override; const base::string16& GetTitle() const override;
bool IsLoading() const override; bool IsLoading() const override;
double GetLoadingProgress() const override; double GetLoadingProgress() const override;
bool IsVisible() const override;
bool IsCrashed() const override; bool IsCrashed() const override;
bool IsEvicted() const override; bool IsEvicted() const override;
bool IsBeingDestroyed() const override; bool IsBeingDestroyed() const override;
...@@ -109,6 +110,7 @@ class TestWebState : public WebState { ...@@ -109,6 +110,7 @@ class TestWebState : public WebState {
BrowserState* browser_state_; BrowserState* browser_state_;
bool web_usage_enabled_; bool web_usage_enabled_;
bool is_loading_; bool is_loading_;
bool is_visible_;
bool is_crashed_; bool is_crashed_;
bool is_evicted_; bool is_evicted_;
CRWContentView* transient_content_view_; CRWContentView* transient_content_view_;
......
...@@ -31,6 +31,7 @@ TestWebState::TestWebState() ...@@ -31,6 +31,7 @@ TestWebState::TestWebState()
: browser_state_(nullptr), : browser_state_(nullptr),
web_usage_enabled_(false), web_usage_enabled_(false),
is_loading_(false), is_loading_(false),
is_visible_(false),
is_crashed_(false), is_crashed_(false),
is_evicted_(false), is_evicted_(false),
trust_level_(kAbsolute), trust_level_(kAbsolute),
...@@ -74,11 +75,13 @@ UIView* TestWebState::GetView() { ...@@ -74,11 +75,13 @@ UIView* TestWebState::GetView() {
} }
void TestWebState::WasShown() { void TestWebState::WasShown() {
is_visible_ = true;
for (auto& observer : observers_) for (auto& observer : observers_)
observer.WasShown(); observer.WasShown();
} }
void TestWebState::WasHidden() { void TestWebState::WasHidden() {
is_visible_ = false;
for (auto& observer : observers_) for (auto& observer : observers_)
observer.WasHidden(); observer.WasHidden();
} }
...@@ -186,6 +189,10 @@ double TestWebState::GetLoadingProgress() const { ...@@ -186,6 +189,10 @@ double TestWebState::GetLoadingProgress() const {
return 0.0; return 0.0;
} }
bool TestWebState::IsVisible() const {
return is_visible_;
}
bool TestWebState::IsCrashed() const { bool TestWebState::IsCrashed() const {
return is_crashed_; return is_crashed_;
} }
......
...@@ -187,6 +187,10 @@ class WebState : public base::SupportsUserData { ...@@ -187,6 +187,10 @@ class WebState : public base::SupportsUserData {
// (nothing loaded) and 1.0 (fully loaded). // (nothing loaded) and 1.0 (fully loaded).
virtual double GetLoadingProgress() const = 0; virtual double GetLoadingProgress() const = 0;
// Whether the WebState is visible. Returns true after WasShown() call and
// false after WasHidden() call.
virtual bool IsVisible() const = 0;
// Returns true if the web process backing this WebState is believed to // Returns true if the web process backing this WebState is believed to
// currently be crashed. // currently be crashed.
virtual bool IsCrashed() const = 0; virtual bool IsCrashed() const = 0;
......
...@@ -103,6 +103,10 @@ class WebStateImpl; ...@@ -103,6 +103,10 @@ class WebStateImpl;
// YES if the web process backing WebView is believed to currently be crashed. // YES if the web process backing WebView is believed to currently be crashed.
@property(nonatomic, assign, getter=isWebProcessCrashed) BOOL webProcessCrashed; @property(nonatomic, assign, getter=isWebProcessCrashed) BOOL webProcessCrashed;
// Whether the WebController is visible. Returns YES after wasShown call and
// NO after wasHidden() call.
@property(nonatomic, assign, getter=isVisible) BOOL visible;
// Designated initializer. Initializes web controller with |webState|. The // Designated initializer. Initializes web controller with |webState|. The
// calling code must retain the ownership of |webState|. // calling code must retain the ownership of |webState|.
- (instancetype)initWithWebState:(web::WebStateImpl*)webState; - (instancetype)initWithWebState:(web::WebStateImpl*)webState;
......
...@@ -923,6 +923,7 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; ...@@ -923,6 +923,7 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5;
@synthesize loadPhase = _loadPhase; @synthesize loadPhase = _loadPhase;
@synthesize shouldSuppressDialogs = _shouldSuppressDialogs; @synthesize shouldSuppressDialogs = _shouldSuppressDialogs;
@synthesize webProcessCrashed = _webProcessCrashed; @synthesize webProcessCrashed = _webProcessCrashed;
@synthesize visible = _visible;
@synthesize nativeProvider = _nativeProvider; @synthesize nativeProvider = _nativeProvider;
@synthesize swipeRecognizerProvider = _swipeRecognizerProvider; @synthesize swipeRecognizerProvider = _swipeRecognizerProvider;
@synthesize webViewProxy = _webViewProxy; @synthesize webViewProxy = _webViewProxy;
...@@ -2769,12 +2770,14 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -2769,12 +2770,14 @@ registerLoadRequestForURL:(const GURL&)requestURL
} }
- (void)wasShown { - (void)wasShown {
self.visible = YES;
if ([self.nativeController respondsToSelector:@selector(wasShown)]) { if ([self.nativeController respondsToSelector:@selector(wasShown)]) {
[self.nativeController wasShown]; [self.nativeController wasShown];
} }
} }
- (void)wasHidden { - (void)wasHidden {
self.visible = NO;
if (_isHalted) if (_isHalted)
return; return;
[self recordStateInHistory]; [self recordStateInHistory];
......
...@@ -211,6 +211,7 @@ class WebStateImpl : public WebState, public NavigationManagerDelegate { ...@@ -211,6 +211,7 @@ class WebStateImpl : public WebState, public NavigationManagerDelegate {
bool IsLoading() const override; bool IsLoading() const override;
double GetLoadingProgress() const override; double GetLoadingProgress() const override;
bool IsCrashed() const override; bool IsCrashed() const override;
bool IsVisible() const override;
bool IsEvicted() const override; bool IsEvicted() const override;
bool IsBeingDestroyed() const override; bool IsBeingDestroyed() const override;
const GURL& GetVisibleURL() const override; const GURL& GetVisibleURL() const override;
......
...@@ -244,6 +244,10 @@ bool WebStateImpl::IsCrashed() const { ...@@ -244,6 +244,10 @@ bool WebStateImpl::IsCrashed() const {
return [web_controller_ isWebProcessCrashed]; return [web_controller_ isWebProcessCrashed];
} }
bool WebStateImpl::IsVisible() const {
return [web_controller_ isVisible];
}
bool WebStateImpl::IsEvicted() const { bool WebStateImpl::IsEvicted() const {
return ![web_controller_ isViewAlive]; return ![web_controller_ isViewAlive];
} }
......
...@@ -266,16 +266,20 @@ TEST_F(WebStateImplTest, ObserverTest) { ...@@ -266,16 +266,20 @@ TEST_F(WebStateImplTest, ObserverTest) {
EXPECT_EQ(web_state_.get(), observer->web_state()); EXPECT_EQ(web_state_.get(), observer->web_state());
// Test that WasShown() is called. // Test that WasShown() is called.
ASSERT_FALSE(web_state_->IsVisible());
ASSERT_FALSE(observer->was_shown_info()); ASSERT_FALSE(observer->was_shown_info());
web_state_->WasShown(); web_state_->WasShown();
ASSERT_TRUE(observer->was_shown_info()); ASSERT_TRUE(observer->was_shown_info());
EXPECT_EQ(web_state_.get(), observer->was_shown_info()->web_state); EXPECT_EQ(web_state_.get(), observer->was_shown_info()->web_state);
EXPECT_TRUE(web_state_->IsVisible());
// Test that WasHidden() is called. // Test that WasHidden() is called.
ASSERT_TRUE(web_state_->IsVisible());
ASSERT_FALSE(observer->was_hidden_info()); ASSERT_FALSE(observer->was_hidden_info());
web_state_->WasHidden(); web_state_->WasHidden();
ASSERT_TRUE(observer->was_hidden_info()); ASSERT_TRUE(observer->was_hidden_info());
EXPECT_EQ(web_state_.get(), observer->was_hidden_info()->web_state); EXPECT_EQ(web_state_.get(), observer->was_hidden_info()->web_state);
EXPECT_FALSE(web_state_->IsVisible());
// Test that LoadProgressChanged() is called. // Test that LoadProgressChanged() is called.
ASSERT_FALSE(observer->change_loading_progress_info()); ASSERT_FALSE(observer->change_loading_progress_info());
......
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