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