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

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

Issue 2588733002: Upstream Chrome on iOS source code [9/11]. (Closed)
Patch Set: Created 4 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h"
6
7 #include "base/logging.h"
8 #include "components/omnibox/browser/autocomplete_classifier.h"
9 #include "components/omnibox/browser/autocomplete_input.h"
10 #include "components/omnibox/browser/autocomplete_match.h"
11 #include "components/prefs/pref_service.h"
12 #include "ios/chrome/browser/autocomplete/autocomplete_scheme_classifier_impl.h"
13 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
14 #include "ios/chrome/browser/chrome_url_constants.h"
15 #include "ios/chrome/browser/pref_names.h"
16 #include "ios/chrome/browser/ssl/ios_security_state_tab_helper.h"
17 #import "ios/chrome/browser/tabs/tab.h"
18 #import "ios/chrome/browser/tabs/tab_model.h"
19 #import "ios/web/public/navigation_item.h"
20 #import "ios/web/public/web_state/web_state.h"
21
22 ToolbarModelDelegateIOS::ToolbarModelDelegateIOS(TabModel* tab_model)
23 : tab_model_([tab_model retain]) {}
24
25 ToolbarModelDelegateIOS::~ToolbarModelDelegateIOS() {}
26
27 void ToolbarModelDelegateIOS::SetTabModel(TabModel* tab_model) {
28 DCHECK(tab_model);
29 tab_model_.reset([tab_model retain]);
30 }
31
32 Tab* ToolbarModelDelegateIOS::GetCurrentTab() const {
33 return [tab_model_ currentTab];
34 }
35
36 web::NavigationItem* ToolbarModelDelegateIOS::GetNavigationItem() const {
37 web::WebState* web_state = [GetCurrentTab() webState];
38 web::NavigationManager* navigation_manager =
39 web_state ? web_state->GetNavigationManager() : nullptr;
40 return navigation_manager ? navigation_manager->GetVisibleItem() : nullptr;
41 }
42
43 base::string16 ToolbarModelDelegateIOS::FormattedStringWithEquivalentMeaning(
44 const GURL& url,
45 const base::string16& formatted_url) const {
46 return AutocompleteInput::FormattedStringWithEquivalentMeaning(
47 url, formatted_url, AutocompleteSchemeClassifierImpl());
48 }
49
50 bool ToolbarModelDelegateIOS::GetURL(GURL* url) const {
51 DCHECK(url);
52 web::NavigationItem* item = GetNavigationItem();
53 if (!item)
54 return false;
55 *url = ShouldDisplayURL() ? item->GetVirtualURL() : GURL();
56 return true;
57 }
58
59 bool ToolbarModelDelegateIOS::ShouldDisplayURL() const {
60 web::NavigationItem* item = GetNavigationItem();
61 if (item) {
62 GURL url = item->GetURL();
63 GURL virtual_url = item->GetVirtualURL();
64 if (url.SchemeIs(kChromeUIScheme) ||
65 virtual_url.SchemeIs(kChromeUIScheme)) {
66 if (!url.SchemeIs(kChromeUIScheme))
67 url = virtual_url;
68 const std::string host = url.host();
69 return host != kChromeUIBookmarksHost && host != kChromeUINewTabHost;
70 }
71 }
72 return true;
73 }
74
75 security_state::SecurityLevel ToolbarModelDelegateIOS::GetSecurityLevel()
76 const {
77 web::WebState* web_state = [GetCurrentTab() webState];
78 // If there is no active WebState (which can happen during toolbar
79 // initialization), assume no security style.
80 if (!web_state)
81 return security_state::NONE;
82 auto* client = IOSSecurityStateTabHelper::FromWebState(web_state);
83 security_state::SecurityInfo result;
84 client->GetSecurityInfo(&result);
85 return result.security_level;
86 }
87
88 bool ToolbarModelDelegateIOS::FailsMalwareCheck() const {
89 web::WebState* web_state = [GetCurrentTab() webState];
90 // If there is no active WebState (which can happen during toolbar
91 // initialization), so nothing can fail.
92 if (!web_state)
93 return NO;
94 auto* client = IOSSecurityStateTabHelper::FromWebState(web_state);
95 security_state::SecurityInfo result;
96 client->GetSecurityInfo(&result);
97 return result.malicious_content_status !=
98 security_state::MALICIOUS_CONTENT_STATUS_NONE;
99 }
100
101 scoped_refptr<net::X509Certificate> ToolbarModelDelegateIOS::GetCertificate()
102 const {
103 web::NavigationItem* item = GetNavigationItem();
104 if (item)
105 return item->GetSSL().certificate;
106 return scoped_refptr<net::X509Certificate>();
107 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h ('k') | ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698