OLD | NEW |
---|---|
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 #include "ios/chrome/browser/reading_list/offline_url_utils.h" | |
12 #import "ios/chrome/browser/tabs/tab.h" | 13 #import "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* GetBookmarkModelForTab(Tab* tab) { |
20 web::WebState* web_state = [tab webState]; | 21 web::WebState* web_state = [tab webState]; |
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 return toolbar_model_.get(); | |
40 } | |
41 | |
42 bool ToolbarModelImplIOS::IsLoading() { | 39 bool ToolbarModelImplIOS::IsLoading() { |
43 // Please note, ToolbarModel's notion of isLoading is slightly different from | 40 // Please note, ToolbarModel's notion of isLoading is slightly different from |
44 // WebState's IsLoading(). | 41 // WebState's IsLoading(). |
45 web::WebState* web_state = delegate_->GetCurrentTab().webState; | 42 web::WebState* web_state = delegate_->GetCurrentTab().webState; |
46 return web_state && web_state->IsLoading() && !IsCurrentTabNativePage(); | 43 return web_state && web_state->IsLoading() && !IsCurrentTabNativePage(); |
47 } | 44 } |
48 | 45 |
49 CGFloat ToolbarModelImplIOS::GetLoadProgressFraction() { | 46 CGFloat ToolbarModelImplIOS::GetLoadProgressFraction() { |
50 web::WebState* webState = delegate_->GetCurrentTab().webState; | 47 web::WebState* webState = delegate_->GetCurrentTab().webState; |
51 return webState ? webState->GetLoadingProgress() : 0.0; | 48 return webState ? webState->GetLoadingProgress() : 0.0; |
(...skipping 23 matching lines...) Expand all Loading... | |
75 Tab* currentTab = delegate_->GetCurrentTab(); | 72 Tab* currentTab = delegate_->GetCurrentTab(); |
76 bookmarks::BookmarkModel* bookmarkModel = GetBookmarkModelForTab(currentTab); | 73 bookmarks::BookmarkModel* bookmarkModel = GetBookmarkModelForTab(currentTab); |
77 return currentTab && bookmarkModel && | 74 return currentTab && bookmarkModel && |
78 bookmarkModel->GetMostRecentlyAddedUserNodeForURL(currentTab.url); | 75 bookmarkModel->GetMostRecentlyAddedUserNodeForURL(currentTab.url); |
79 } | 76 } |
80 | 77 |
81 bool ToolbarModelImplIOS::ShouldDisplayHintText() { | 78 bool ToolbarModelImplIOS::ShouldDisplayHintText() { |
82 Tab* currentTab = delegate_->GetCurrentTab(); | 79 Tab* currentTab = delegate_->GetCurrentTab(); |
83 return [currentTab.webController wantsLocationBarHintText]; | 80 return [currentTab.webController wantsLocationBarHintText]; |
84 } | 81 } |
82 | |
83 base::string16 ToolbarModelImplIOS::GetFormattedURL(size_t* prefix_end) const { | |
84 base::string16 formatted_url = toolbar_model_->GetFormattedURL(prefix_end); | |
85 Tab* currentTab = delegate_->GetCurrentTab(); | |
Eugene But (OOO till 7-30)
2016/12/28 17:02:59
s/currentTab/current_tab
Looks like existing code
Olivier
2016/12/29 12:37:20
Done.
| |
86 if ([currentTab isOffline] && | |
Eugene But (OOO till 7-30)
2016/12/28 17:03:00
If you choose not to add anything to Tab (which is
Olivier
2016/12/29 12:37:20
We need the URL, not the virtualURL.
Done.
| |
87 GetSecurityLevel(true) == security_state::SecurityLevel::NONE) { | |
Eugene But (OOO till 7-30)
2016/12/28 17:02:59
nit: GetSecurityLevel(true /*ignore_editing*/)
Olivier
2016/12/29 12:37:20
Done.
| |
88 return reading_list::StripSchemeFromOnlineUrl(formatted_url); | |
89 } | |
90 return formatted_url; | |
91 } | |
92 | |
93 GURL ToolbarModelImplIOS::GetURL() const { | |
94 return toolbar_model_->GetURL(); | |
95 } | |
96 | |
97 security_state::SecurityLevel ToolbarModelImplIOS::GetSecurityLevel( | |
98 bool ignore_editing) const { | |
99 return toolbar_model_->GetSecurityLevel(ignore_editing); | |
100 } | |
101 | |
102 gfx::VectorIconId ToolbarModelImplIOS::GetVectorIcon() const { | |
103 return toolbar_model_->GetVectorIcon(); | |
104 } | |
105 | |
106 base::string16 ToolbarModelImplIOS::GetSecureVerboseText() const { | |
107 return toolbar_model_->GetSecureVerboseText(); | |
108 } | |
109 | |
110 base::string16 ToolbarModelImplIOS::GetEVCertName() const { | |
111 return toolbar_model_->GetEVCertName(); | |
112 } | |
113 | |
114 bool ToolbarModelImplIOS::ShouldDisplayURL() const { | |
115 return toolbar_model_->ShouldDisplayURL(); | |
116 } | |
OLD | NEW |