Commit ec7db8a2 authored by eugenebut's avatar eugenebut Committed by Commit bot

[ios] Added WebState::GetLoadingProgress web// API.

This API is necessary to remove loading progress code from Tab, which is
currently stores the loading progress and provides it to Toolbar.
Corresponding method does not exist in WebContents, because on Desktop
the progress is not shown in UI and on Android progress is stored in
WebContentsDelegateAndroid.

BUG=None

Review URL: https://codereview.chromium.org/1905393002

Cr-Commit-Position: refs/heads/master@{#389887}
parent 5274ed69
...@@ -40,6 +40,7 @@ class TestWebState : public WebState { ...@@ -40,6 +40,7 @@ class TestWebState : public WebState {
bool ContentIsHTML() const override; bool ContentIsHTML() const override;
const base::string16& GetTitle() const override; const base::string16& GetTitle() const override;
bool IsLoading() const override; bool IsLoading() const override;
double GetLoadingProgress() const override;
bool IsBeingDestroyed() const override; bool IsBeingDestroyed() const override;
const GURL& GetVisibleURL() const override; const GURL& GetVisibleURL() const override;
const GURL& GetLastCommittedURL() const override; const GURL& GetLastCommittedURL() const override;
......
...@@ -103,6 +103,10 @@ bool TestWebState::IsLoading() const { ...@@ -103,6 +103,10 @@ bool TestWebState::IsLoading() const {
return false; return false;
} }
double TestWebState::GetLoadingProgress() const {
return 0.0;
}
bool TestWebState::IsBeingDestroyed() const { bool TestWebState::IsBeingDestroyed() const {
return false; return false;
} }
......
...@@ -151,6 +151,10 @@ class WebState : public base::SupportsUserData { ...@@ -151,6 +151,10 @@ class WebState : public base::SupportsUserData {
// Returns true if the current page is loading. // Returns true if the current page is loading.
virtual bool IsLoading() const = 0; virtual bool IsLoading() const = 0;
// The fraction of the page load that has completed as a number between 0.0
// (nothing loaded) and 1.0 (fully loaded).
virtual double GetLoadingProgress() const = 0;
// Whether this instance is in the process of being destroyed. // Whether this instance is in the process of being destroyed.
virtual bool IsBeingDestroyed() const = 0; virtual bool IsBeingDestroyed() const = 0;
......
...@@ -98,6 +98,10 @@ class WebStateImpl; ...@@ -98,6 +98,10 @@ class WebStateImpl;
// Returns the current page loading phase. // Returns the current page loading phase.
@property(nonatomic, readonly) web::LoadPhase loadPhase; @property(nonatomic, readonly) web::LoadPhase loadPhase;
// The fraction of the page load that has completed as a number between 0.0
// (nothing loaded) and 1.0 (fully loaded).
@property(nonatomic, readonly) double loadingProgress;
// Returns whether the page can navigate backwards or forwards. // Returns whether the page can navigate backwards or forwards.
@property(nonatomic, readonly) BOOL canGoBack; @property(nonatomic, readonly) BOOL canGoBack;
@property(nonatomic, readonly) BOOL canGoForward; @property(nonatomic, readonly) BOOL canGoForward;
......
...@@ -1659,6 +1659,10 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; ...@@ -1659,6 +1659,10 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5;
return _webView; return _webView;
} }
- (double)loadingProgress {
return [_webView estimatedProgress];
}
- (void)registerLoadRequest:(const GURL&)URL { - (void)registerLoadRequest:(const GURL&)URL {
// Get the navigation type from the last main frame load request, and try to // Get the navigation type from the last main frame load request, and try to
// map that to a PageTransition. // map that to a PageTransition.
......
...@@ -233,6 +233,7 @@ class WebStateImpl : public WebState, public NavigationManagerDelegate { ...@@ -233,6 +233,7 @@ class WebStateImpl : public WebState, public NavigationManagerDelegate {
bool ContentIsHTML() const override; bool ContentIsHTML() const override;
const base::string16& GetTitle() const override; const base::string16& GetTitle() const override;
bool IsLoading() const override; bool IsLoading() const override;
double GetLoadingProgress() const override;
bool IsBeingDestroyed() const override; bool IsBeingDestroyed() const override;
const GURL& GetVisibleURL() const override; const GURL& GetVisibleURL() const override;
const GURL& GetLastCommittedURL() const override; const GURL& GetLastCommittedURL() const override;
......
...@@ -198,6 +198,10 @@ bool WebStateImpl::IsLoading() const { ...@@ -198,6 +198,10 @@ bool WebStateImpl::IsLoading() const {
return is_loading_; return is_loading_;
} }
double WebStateImpl::GetLoadingProgress() const {
return [web_controller_ loadingProgress];
}
bool WebStateImpl::IsBeingDestroyed() const { bool WebStateImpl::IsBeingDestroyed() const {
return is_being_destroyed_; return is_being_destroyed_;
} }
......
...@@ -594,5 +594,14 @@ TEST_F(WebStateTest, ScriptExecution) { ...@@ -594,5 +594,14 @@ TEST_F(WebStateTest, ScriptExecution) {
EXPECT_EQ("bar", string_result); EXPECT_EQ("bar", string_result);
} }
// Tests loading progress.
TEST_F(WebStateTest, LoadingProgress) {
EXPECT_FLOAT_EQ(0.0, web_state_->GetLoadingProgress());
LoadHtml("<html></html>");
base::test::ios::WaitUntilCondition(^bool() {
return web_state_->GetLoadingProgress() == 1.0;
});
}
} // namespace } // namespace
} // namespace web } // namespace web
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