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 #import "ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h" | 5 #import "ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "components/omnibox/browser/autocomplete_classifier.h" | 8 #include "components/omnibox/browser/autocomplete_classifier.h" |
9 #include "components/omnibox/browser/autocomplete_input.h" | 9 #include "components/omnibox/browser/autocomplete_input.h" |
10 #include "components/omnibox/browser/autocomplete_match.h" | 10 #include "components/omnibox/browser/autocomplete_match.h" |
11 #include "components/prefs/pref_service.h" | 11 #include "components/prefs/pref_service.h" |
12 #include "ios/chrome/browser/autocomplete/autocomplete_scheme_classifier_impl.h" | 12 #include "ios/chrome/browser/autocomplete/autocomplete_scheme_classifier_impl.h" |
13 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 13 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
14 #include "ios/chrome/browser/chrome_url_constants.h" | 14 #include "ios/chrome/browser/chrome_url_constants.h" |
15 #include "ios/chrome/browser/pref_names.h" | 15 #include "ios/chrome/browser/pref_names.h" |
16 #include "ios/chrome/browser/ssl/ios_security_state_tab_helper.h" | 16 #include "ios/chrome/browser/ssl/ios_security_state_tab_helper.h" |
17 #include "ios/shared/chrome/browser/tabs/web_state_list.h" | 17 #import "ios/chrome/browser/tabs/tab.h" |
| 18 #import "ios/chrome/browser/tabs/tab_model.h" |
18 #import "ios/web/public/navigation_item.h" | 19 #import "ios/web/public/navigation_item.h" |
19 #import "ios/web/public/navigation_manager.h" | |
20 #import "ios/web/public/ssl_status.h" | |
21 #import "ios/web/public/web_state/web_state.h" | 20 #import "ios/web/public/web_state/web_state.h" |
22 | 21 |
23 ToolbarModelDelegateIOS::ToolbarModelDelegateIOS(WebStateList* web_state_list) | 22 ToolbarModelDelegateIOS::ToolbarModelDelegateIOS(TabModel* tab_model) |
24 : web_state_list_(web_state_list) {} | 23 : tab_model_([tab_model retain]) {} |
25 | 24 |
26 ToolbarModelDelegateIOS::~ToolbarModelDelegateIOS() {} | 25 ToolbarModelDelegateIOS::~ToolbarModelDelegateIOS() {} |
27 | 26 |
28 web::WebState* ToolbarModelDelegateIOS::GetActiveWebState() const { | 27 void ToolbarModelDelegateIOS::SetTabModel(TabModel* tab_model) { |
29 return web_state_list_->GetActiveWebState(); | 28 DCHECK(tab_model); |
| 29 tab_model_.reset([tab_model retain]); |
| 30 } |
| 31 |
| 32 Tab* ToolbarModelDelegateIOS::GetCurrentTab() const { |
| 33 return [tab_model_ currentTab]; |
30 } | 34 } |
31 | 35 |
32 web::NavigationItem* ToolbarModelDelegateIOS::GetNavigationItem() const { | 36 web::NavigationItem* ToolbarModelDelegateIOS::GetNavigationItem() const { |
33 web::WebState* web_state = GetActiveWebState(); | 37 web::WebState* web_state = [GetCurrentTab() webState]; |
34 web::NavigationManager* navigation_manager = | 38 web::NavigationManager* navigation_manager = |
35 web_state ? web_state->GetNavigationManager() : nullptr; | 39 web_state ? web_state->GetNavigationManager() : nullptr; |
36 return navigation_manager ? navigation_manager->GetVisibleItem() : nullptr; | 40 return navigation_manager ? navigation_manager->GetVisibleItem() : nullptr; |
37 } | 41 } |
38 | 42 |
39 base::string16 ToolbarModelDelegateIOS::FormattedStringWithEquivalentMeaning( | 43 base::string16 ToolbarModelDelegateIOS::FormattedStringWithEquivalentMeaning( |
40 const GURL& url, | 44 const GURL& url, |
41 const base::string16& formatted_url) const { | 45 const base::string16& formatted_url) const { |
42 return AutocompleteInput::FormattedStringWithEquivalentMeaning( | 46 return AutocompleteInput::FormattedStringWithEquivalentMeaning( |
43 url, formatted_url, AutocompleteSchemeClassifierImpl()); | 47 url, formatted_url, AutocompleteSchemeClassifierImpl()); |
(...skipping 19 matching lines...) Expand all Loading... |
63 url = virtual_url; | 67 url = virtual_url; |
64 const std::string host = url.host(); | 68 const std::string host = url.host(); |
65 return host != kChromeUIBookmarksHost && host != kChromeUINewTabHost; | 69 return host != kChromeUIBookmarksHost && host != kChromeUINewTabHost; |
66 } | 70 } |
67 } | 71 } |
68 return true; | 72 return true; |
69 } | 73 } |
70 | 74 |
71 security_state::SecurityLevel ToolbarModelDelegateIOS::GetSecurityLevel() | 75 security_state::SecurityLevel ToolbarModelDelegateIOS::GetSecurityLevel() |
72 const { | 76 const { |
73 web::WebState* web_state = GetActiveWebState(); | 77 web::WebState* web_state = [GetCurrentTab() webState]; |
74 // If there is no active WebState (which can happen during toolbar | 78 // If there is no active WebState (which can happen during toolbar |
75 // initialization), assume no security style. | 79 // initialization), assume no security style. |
76 if (!web_state) | 80 if (!web_state) |
77 return security_state::NONE; | 81 return security_state::NONE; |
78 auto* client = IOSSecurityStateTabHelper::FromWebState(web_state); | 82 auto* client = IOSSecurityStateTabHelper::FromWebState(web_state); |
79 security_state::SecurityInfo result; | 83 security_state::SecurityInfo result; |
80 client->GetSecurityInfo(&result); | 84 client->GetSecurityInfo(&result); |
81 return result.security_level; | 85 return result.security_level; |
82 } | 86 } |
83 | 87 |
84 scoped_refptr<net::X509Certificate> ToolbarModelDelegateIOS::GetCertificate() | 88 scoped_refptr<net::X509Certificate> ToolbarModelDelegateIOS::GetCertificate() |
85 const { | 89 const { |
86 web::NavigationItem* item = GetNavigationItem(); | 90 web::NavigationItem* item = GetNavigationItem(); |
87 if (item) | 91 if (item) |
88 return item->GetSSL().certificate; | 92 return item->GetSSL().certificate; |
89 return scoped_refptr<net::X509Certificate>(); | 93 return scoped_refptr<net::X509Certificate>(); |
90 } | 94 } |
91 | 95 |
92 bool ToolbarModelDelegateIOS::FailsMalwareCheck() const { | 96 bool ToolbarModelDelegateIOS::FailsMalwareCheck() const { |
93 web::WebState* web_state = GetActiveWebState(); | 97 web::WebState* web_state = [GetCurrentTab() webState]; |
94 // If there is no active WebState (which can happen during toolbar | 98 // If there is no active WebState (which can happen during toolbar |
95 // initialization), so nothing can fail. | 99 // initialization), so nothing can fail. |
96 if (!web_state) | 100 if (!web_state) |
97 return NO; | 101 return NO; |
98 auto* client = IOSSecurityStateTabHelper::FromWebState(web_state); | 102 auto* client = IOSSecurityStateTabHelper::FromWebState(web_state); |
99 security_state::SecurityInfo result; | 103 security_state::SecurityInfo result; |
100 client->GetSecurityInfo(&result); | 104 client->GetSecurityInfo(&result); |
101 return result.malicious_content_status != | 105 return result.malicious_content_status != |
102 security_state::MALICIOUS_CONTENT_STATUS_NONE; | 106 security_state::MALICIOUS_CONTENT_STATUS_NONE; |
103 } | 107 } |
104 | 108 |
105 const gfx::VectorIcon* ToolbarModelDelegateIOS::GetVectorIconOverride() const { | 109 const gfx::VectorIcon* ToolbarModelDelegateIOS::GetVectorIconOverride() const { |
106 return nullptr; | 110 return nullptr; |
107 } | 111 } |
OLD | NEW |