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

Side by Side Diff: ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.mm

Issue 2775943002: Revert of [ios] Switches ToolbarModelDelegateIOS to use WebStateList. (Closed)
Patch Set: Created 3 years, 9 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.h" 5 #include "ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.h"
6 6
7 #include "components/bookmarks/browser/bookmark_model.h" 7 #include "components/bookmarks/browser/bookmark_model.h"
8 #include "components/toolbar/toolbar_model_impl.h" 8 #include "components/toolbar/toolbar_model_impl.h"
9 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" 9 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
10 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 10 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
11 #include "ios/chrome/browser/chrome_url_constants.h" 11 #include "ios/chrome/browser/chrome_url_constants.h"
12 #import "ios/chrome/browser/tabs/legacy_tab_helper.h" 12 #import "ios/chrome/browser/tabs/tab.h"
13 #include "ios/chrome/browser/tabs/tab.h"
14 #include "ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h" 13 #include "ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h"
15 #import "ios/web/public/web_state/web_state.h" 14 #import "ios/web/public/web_state/web_state.h"
16 15
17 namespace { 16 namespace {
18 const size_t kMaxURLDisplayChars = 32 * 1024; 17 const size_t kMaxURLDisplayChars = 32 * 1024;
19 18
20 bookmarks::BookmarkModel* GetBookmarkModelForWebState( 19 bookmarks::BookmarkModel* GetBookmarkModelForTab(Tab* tab) {
21 web::WebState* web_state) { 20 web::WebState* web_state = [tab webState];
22 if (!web_state) 21 if (!web_state)
23 return nullptr; 22 return nullptr;
24 web::BrowserState* browser_state = web_state->GetBrowserState(); 23 web::BrowserState* browser_state = web_state->GetBrowserState();
25 if (!browser_state) 24 if (!browser_state)
26 return nullptr; 25 return nullptr;
27 return ios::BookmarkModelFactory::GetForBrowserState( 26 return ios::BookmarkModelFactory::GetForBrowserState(
28 ios::ChromeBrowserState::FromBrowserState(browser_state)); 27 ios::ChromeBrowserState::FromBrowserState(browser_state));
29 } 28 }
30 } // namespace 29 } // namespace
31 30
32 ToolbarModelImplIOS::ToolbarModelImplIOS(ToolbarModelDelegateIOS* delegate) { 31 ToolbarModelImplIOS::ToolbarModelImplIOS(ToolbarModelDelegateIOS* delegate) {
33 delegate_ = delegate; 32 delegate_ = delegate;
34 toolbar_model_.reset(new ToolbarModelImpl(delegate, kMaxURLDisplayChars)); 33 toolbar_model_.reset(new ToolbarModelImpl(delegate, kMaxURLDisplayChars));
35 } 34 }
36 35
37 ToolbarModelImplIOS::~ToolbarModelImplIOS() {} 36 ToolbarModelImplIOS::~ToolbarModelImplIOS() {}
38 37
39 ToolbarModel* ToolbarModelImplIOS::GetToolbarModel() { 38 ToolbarModel* ToolbarModelImplIOS::GetToolbarModel() {
40 return toolbar_model_.get(); 39 return toolbar_model_.get();
41 } 40 }
42 41
43 bool ToolbarModelImplIOS::IsLoading() { 42 bool ToolbarModelImplIOS::IsLoading() {
44 // Please note, ToolbarModel's notion of isLoading is slightly different from 43 // Please note, ToolbarModel's notion of isLoading is slightly different from
45 // WebState's IsLoading(). 44 // WebState's IsLoading().
46 web::WebState* web_state = delegate_->GetActiveWebState(); 45 web::WebState* web_state = delegate_->GetCurrentTab().webState;
47 return web_state && web_state->IsLoading() && !IsCurrentTabNativePage(); 46 return web_state && web_state->IsLoading() && !IsCurrentTabNativePage();
48 } 47 }
49 48
50 CGFloat ToolbarModelImplIOS::GetLoadProgressFraction() { 49 CGFloat ToolbarModelImplIOS::GetLoadProgressFraction() {
51 web::WebState* webState = delegate_->GetActiveWebState(); 50 web::WebState* webState = delegate_->GetCurrentTab().webState;
52 return webState ? webState->GetLoadingProgress() : 0.0; 51 return webState ? webState->GetLoadingProgress() : 0.0;
53 } 52 }
54 53
55 bool ToolbarModelImplIOS::CanGoBack() { 54 bool ToolbarModelImplIOS::CanGoBack() {
56 if (!delegate_) 55 return delegate_->GetCurrentTab().canGoBack;
57 return false;
58 web::WebState* web_state = delegate_->GetActiveWebState();
59 return web_state && web_state->GetNavigationManager()->CanGoBack();
60 } 56 }
61 57
62 bool ToolbarModelImplIOS::CanGoForward() { 58 bool ToolbarModelImplIOS::CanGoForward() {
63 if (!delegate_) 59 return delegate_->GetCurrentTab().canGoForward;
64 return false;
65 web::WebState* web_state = delegate_->GetActiveWebState();
66 return web_state && web_state->GetNavigationManager()->CanGoForward();
67 } 60 }
68 61
69 bool ToolbarModelImplIOS::IsCurrentTabNativePage() { 62 bool ToolbarModelImplIOS::IsCurrentTabNativePage() {
70 web::WebState* web_state = delegate_->GetActiveWebState(); 63 Tab* current_tab = delegate_->GetCurrentTab();
71 return web_state && 64 return current_tab && current_tab.url.SchemeIs(kChromeUIScheme);
72 web_state->GetLastCommittedURL().SchemeIs(kChromeUIScheme);
73 } 65 }
74 66
75 bool ToolbarModelImplIOS::IsCurrentTabBookmarked() { 67 bool ToolbarModelImplIOS::IsCurrentTabBookmarked() {
76 web::WebState* web_state = delegate_->GetActiveWebState(); 68 Tab* current_tab = delegate_->GetCurrentTab();
77 bookmarks::BookmarkModel* bookmarkModel = 69 bookmarks::BookmarkModel* bookmarkModel = GetBookmarkModelForTab(current_tab);
78 GetBookmarkModelForWebState(web_state); 70 return current_tab && bookmarkModel &&
79 return web_state && bookmarkModel && 71 bookmarkModel->IsBookmarked(current_tab.url);
80 bookmarkModel->IsBookmarked(web_state->GetLastCommittedURL());
81 } 72 }
82 73
83 bool ToolbarModelImplIOS::IsCurrentTabBookmarkedByUser() { 74 bool ToolbarModelImplIOS::IsCurrentTabBookmarkedByUser() {
84 web::WebState* web_state = delegate_->GetActiveWebState(); 75 Tab* current_tab = delegate_->GetCurrentTab();
85 bookmarks::BookmarkModel* bookmarkModel = 76 bookmarks::BookmarkModel* bookmarkModel = GetBookmarkModelForTab(current_tab);
86 GetBookmarkModelForWebState(web_state); 77 return current_tab && bookmarkModel &&
87 return web_state && bookmarkModel && 78 bookmarkModel->GetMostRecentlyAddedUserNodeForURL(current_tab.url);
88 bookmarkModel->GetMostRecentlyAddedUserNodeForURL(
89 web_state->GetLastCommittedURL());
90 } 79 }
91 80
92 bool ToolbarModelImplIOS::ShouldDisplayHintText() { 81 bool ToolbarModelImplIOS::ShouldDisplayHintText() {
93 web::WebState* web_state = delegate_->GetActiveWebState(); 82 Tab* current_tab = delegate_->GetCurrentTab();
94 Tab* tab = LegacyTabHelper::GetTabForWebState(web_state); 83 return [current_tab.webController wantsLocationBarHintText];
95 return tab && [tab.webController wantsLocationBarHintText];
96 } 84 }
85
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698