Chromium Code Reviews| Index: ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.mm |
| diff --git a/ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.mm b/ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.mm |
| index ee723d971155403c6d32fd90441eb0514aa76159..91c53fd70305660c4a16713d8d7d8209914d5773 100644 |
| --- a/ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.mm |
| +++ b/ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.mm |
| @@ -9,15 +9,16 @@ |
| #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" |
| #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| #include "ios/chrome/browser/chrome_url_constants.h" |
| -#import "ios/chrome/browser/tabs/tab.h" |
| +#import "ios/chrome/browser/tabs/legacy_tab_helper.h" |
| +#include "ios/chrome/browser/tabs/tab.h" |
| #include "ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h" |
| #import "ios/web/public/web_state/web_state.h" |
| namespace { |
| const size_t kMaxURLDisplayChars = 32 * 1024; |
| -bookmarks::BookmarkModel* GetBookmarkModelForTab(Tab* tab) { |
| - web::WebState* web_state = [tab webState]; |
| +bookmarks::BookmarkModel* GetBookmarkModelForWebState( |
| + web::WebState* web_state) { |
| if (!web_state) |
| return nullptr; |
| web::BrowserState* browser_state = web_state->GetBrowserState(); |
| @@ -42,44 +43,54 @@ ToolbarModel* ToolbarModelImplIOS::GetToolbarModel() { |
| bool ToolbarModelImplIOS::IsLoading() { |
| // Please note, ToolbarModel's notion of isLoading is slightly different from |
| // WebState's IsLoading(). |
| - web::WebState* web_state = delegate_->GetCurrentTab().webState; |
| + web::WebState* web_state = delegate_->GetActiveWebState(); |
| return web_state && web_state->IsLoading() && !IsCurrentTabNativePage(); |
| } |
| CGFloat ToolbarModelImplIOS::GetLoadProgressFraction() { |
| - web::WebState* webState = delegate_->GetCurrentTab().webState; |
| + web::WebState* webState = delegate_->GetActiveWebState(); |
| return webState ? webState->GetLoadingProgress() : 0.0; |
| } |
| bool ToolbarModelImplIOS::CanGoBack() { |
| - return delegate_->GetCurrentTab().canGoBack; |
| + if (!delegate_) |
| + return false; |
| + web::WebState* web_state = delegate_->GetActiveWebState(); |
| + return web_state && web_state->GetNavigationManager()->CanGoBack(); |
| } |
| bool ToolbarModelImplIOS::CanGoForward() { |
| - return delegate_->GetCurrentTab().canGoForward; |
| + if (!delegate_) |
| + return false; |
| + web::WebState* web_state = delegate_->GetActiveWebState(); |
| + return web_state && web_state->GetNavigationManager()->CanGoForward(); |
| } |
| bool ToolbarModelImplIOS::IsCurrentTabNativePage() { |
| - Tab* current_tab = delegate_->GetCurrentTab(); |
| - return current_tab && current_tab.url.SchemeIs(kChromeUIScheme); |
| + web::WebState* web_state = delegate_->GetActiveWebState(); |
| + return web_state && |
| + web_state->GetLastCommittedURL().SchemeIs(kChromeUIScheme); |
| } |
| bool ToolbarModelImplIOS::IsCurrentTabBookmarked() { |
| - Tab* current_tab = delegate_->GetCurrentTab(); |
| - bookmarks::BookmarkModel* bookmarkModel = GetBookmarkModelForTab(current_tab); |
| - return current_tab && bookmarkModel && |
| - bookmarkModel->IsBookmarked(current_tab.url); |
| + web::WebState* web_state = delegate_->GetActiveWebState(); |
| + bookmarks::BookmarkModel* bookmarkModel = |
| + GetBookmarkModelForWebState(web_state); |
| + return web_state && bookmarkModel && |
| + bookmarkModel->IsBookmarked(web_state->GetLastCommittedURL()); |
| } |
| bool ToolbarModelImplIOS::IsCurrentTabBookmarkedByUser() { |
| - Tab* current_tab = delegate_->GetCurrentTab(); |
| - bookmarks::BookmarkModel* bookmarkModel = GetBookmarkModelForTab(current_tab); |
| - return current_tab && bookmarkModel && |
| - bookmarkModel->GetMostRecentlyAddedUserNodeForURL(current_tab.url); |
| + web::WebState* web_state = delegate_->GetActiveWebState(); |
| + bookmarks::BookmarkModel* bookmarkModel = |
| + GetBookmarkModelForWebState(web_state); |
| + return web_state && bookmarkModel && |
| + bookmarkModel->GetMostRecentlyAddedUserNodeForURL( |
| + web_state->GetLastCommittedURL()); |
| } |
| bool ToolbarModelImplIOS::ShouldDisplayHintText() { |
| - Tab* current_tab = delegate_->GetCurrentTab(); |
| - return [current_tab.webController wantsLocationBarHintText]; |
| + web::WebState* web_state = delegate_->GetActiveWebState(); |
| + Tab* tab = LegacyTabHelper::GetTabForWebState(web_state); |
| + return tab && [tab.webController wantsLocationBarHintText]; |
|
rohitrao (ping after 24h)
2017/03/24 14:13:49
There's no public API for this yet.
|
| } |
| - |