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

Side by Side Diff: chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.cc

Issue 2448943002: Refactor SecurityStateModel/Clients for simplicity and reusability. (Closed)
Patch Set: fix DEPS. Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.h" 5 #include "chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" 8 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/search/search.h" 10 #include "chrome/browser/search/search.h"
11 #include "chrome/browser/ssl/chrome_security_state_model_client.h" 11 #include "chrome/browser/ssl/security_state_tab_helper.h"
12 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
14 #include "components/google/core/browser/google_util.h" 14 #include "components/google/core/browser/google_util.h"
15 #include "components/omnibox/browser/autocomplete_input.h" 15 #include "components/omnibox/browser/autocomplete_input.h"
16 #include "components/prefs/pref_service.h" 16 #include "components/prefs/pref_service.h"
17 #include "components/security_state/core/security_state.h"
17 #include "content/public/browser/navigation_controller.h" 18 #include "content/public/browser/navigation_controller.h"
18 #include "content/public/browser/navigation_entry.h" 19 #include "content/public/browser/navigation_entry.h"
19 #include "content/public/browser/ssl_status.h" 20 #include "content/public/browser/ssl_status.h"
20 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
21 22
22 ChromeToolbarModelDelegate::ChromeToolbarModelDelegate() {} 23 ChromeToolbarModelDelegate::ChromeToolbarModelDelegate() {}
23 24
24 ChromeToolbarModelDelegate::~ChromeToolbarModelDelegate() {} 25 ChromeToolbarModelDelegate::~ChromeToolbarModelDelegate() {}
25 26
26 base::string16 ChromeToolbarModelDelegate::FormattedStringWithEquivalentMeaning( 27 base::string16 ChromeToolbarModelDelegate::FormattedStringWithEquivalentMeaning(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 virtual_url.SchemeIs(content::kChromeUIScheme)) { 62 virtual_url.SchemeIs(content::kChromeUIScheme)) {
62 if (!url.SchemeIs(content::kChromeUIScheme)) 63 if (!url.SchemeIs(content::kChromeUIScheme))
63 url = virtual_url; 64 url = virtual_url;
64 return url.host() != chrome::kChromeUINewTabHost; 65 return url.host() != chrome::kChromeUINewTabHost;
65 } 66 }
66 } 67 }
67 68
68 return !search::IsInstantNTP(GetActiveWebContents()); 69 return !search::IsInstantNTP(GetActiveWebContents());
69 } 70 }
70 71
71 security_state::SecurityStateModel::SecurityLevel 72 security_state::SecurityLevel ChromeToolbarModelDelegate::GetSecurityLevel()
72 ChromeToolbarModelDelegate::GetSecurityLevel() const { 73 const {
73 content::WebContents* web_contents = GetActiveWebContents(); 74 content::WebContents* web_contents = GetActiveWebContents();
74 // If there is no active WebContents (which can happen during toolbar 75 // If there is no active WebContents (which can happen during toolbar
75 // initialization), assume no security style. 76 // initialization), assume no security style.
76 if (!web_contents) 77 if (!web_contents)
77 return security_state::SecurityStateModel::NONE; 78 return security_state::NONE;
78 auto* client = ChromeSecurityStateModelClient::FromWebContents(web_contents); 79 auto* helper = SecurityStateTabHelper::FromWebContents(web_contents);
79 security_state::SecurityStateModel::SecurityInfo security_info; 80 security_state::SecurityInfo security_info;
80 client->GetSecurityInfo(&security_info); 81 helper->GetSecurityInfo(&security_info);
81 return security_info.security_level; 82 return security_info.security_level;
82 } 83 }
83 84
84 scoped_refptr<net::X509Certificate> ChromeToolbarModelDelegate::GetCertificate() 85 scoped_refptr<net::X509Certificate> ChromeToolbarModelDelegate::GetCertificate()
85 const { 86 const {
86 content::NavigationEntry* entry = GetNavigationEntry(); 87 content::NavigationEntry* entry = GetNavigationEntry();
87 if (!entry) 88 if (!entry)
88 return scoped_refptr<net::X509Certificate>(); 89 return scoped_refptr<net::X509Certificate>();
89 return entry->GetSSL().certificate; 90 return entry->GetSSL().certificate;
90 } 91 }
91 92
92 bool ChromeToolbarModelDelegate::FailsMalwareCheck() const { 93 bool ChromeToolbarModelDelegate::FailsMalwareCheck() const {
93 content::WebContents* web_contents = GetActiveWebContents(); 94 content::WebContents* web_contents = GetActiveWebContents();
94 // If there is no active WebContents (which can happen during toolbar 95 // If there is no active WebContents (which can happen during toolbar
95 // initialization), so nothing can fail. 96 // initialization), so nothing can fail.
96 if (!web_contents) 97 if (!web_contents)
97 return false; 98 return false;
98 security_state::SecurityStateModel::SecurityInfo security_info; 99 security_state::SecurityInfo security_info;
99 ChromeSecurityStateModelClient::FromWebContents(web_contents) 100 SecurityStateTabHelper::FromWebContents(web_contents)
100 ->GetSecurityInfo(&security_info); 101 ->GetSecurityInfo(&security_info);
101 return security_info.fails_malware_check; 102 return security_info.fails_malware_check;
102 } 103 }
103 104
104 content::NavigationController* 105 content::NavigationController*
105 ChromeToolbarModelDelegate::GetNavigationController() const { 106 ChromeToolbarModelDelegate::GetNavigationController() const {
106 // This |current_tab| can be null during the initialization of the toolbar 107 // This |current_tab| can be null during the initialization of the toolbar
107 // during window creation (i.e. before any tabs have been added to the 108 // during window creation (i.e. before any tabs have been added to the
108 // window). 109 // window).
109 content::WebContents* current_tab = GetActiveWebContents(); 110 content::WebContents* current_tab = GetActiveWebContents();
110 return current_tab ? &current_tab->GetController() : nullptr; 111 return current_tab ? &current_tab->GetController() : nullptr;
111 } 112 }
112 113
113 content::NavigationEntry* ChromeToolbarModelDelegate::GetNavigationEntry() 114 content::NavigationEntry* ChromeToolbarModelDelegate::GetNavigationEntry()
114 const { 115 const {
115 content::NavigationController* controller = GetNavigationController(); 116 content::NavigationController* controller = GetNavigationController();
116 return controller ? controller->GetVisibleEntry() : nullptr; 117 return controller ? controller->GetVisibleEntry() : nullptr;
117 } 118 }
118 119
119 Profile* ChromeToolbarModelDelegate::GetProfile() const { 120 Profile* ChromeToolbarModelDelegate::GetProfile() const {
120 content::NavigationController* controller = GetNavigationController(); 121 content::NavigationController* controller = GetNavigationController();
121 return controller 122 return controller
122 ? Profile::FromBrowserContext(controller->GetBrowserContext()) 123 ? Profile::FromBrowserContext(controller->GetBrowserContext())
123 : nullptr; 124 : nullptr;
124 } 125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698