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

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

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

Powered by Google App Engine
This is Rietveld 408576698