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

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

Issue 2770223003: [ios] Switches ToolbarModelDelegateIOS to use WebStateList. (Closed)
Patch Set: Fix compile. Created 3 years, 9 months 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 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) {}
sdefresne 2017/03/24 15:09:52 I think we should DCHECK that web_state_list_ is n
rohitrao (ping after 24h) 2017/03/24 15:40:21 I don't think anyone calls SetWebStateList(), so I
24 25
25 ToolbarModelDelegateIOS::~ToolbarModelDelegateIOS() {} 26 ToolbarModelDelegateIOS::~ToolbarModelDelegateIOS() {}
26 27
27 void ToolbarModelDelegateIOS::SetTabModel(TabModel* tab_model) { 28 void ToolbarModelDelegateIOS::SetWebStateList(WebStateList* web_state_list) {
28 DCHECK(tab_model); 29 DCHECK(web_state_list);
29 tab_model_.reset([tab_model retain]); 30 web_state_list_ = web_state_list;
30 } 31 }
31 32
32 Tab* ToolbarModelDelegateIOS::GetCurrentTab() const { 33 web::WebState* ToolbarModelDelegateIOS::GetActiveWebState() const {
33 return [tab_model_ currentTab]; 34 return web_state_list_->GetActiveWebState();
34 } 35 }
35 36
36 web::NavigationItem* ToolbarModelDelegateIOS::GetNavigationItem() const { 37 web::NavigationItem* ToolbarModelDelegateIOS::GetNavigationItem() const {
37 web::WebState* web_state = [GetCurrentTab() webState]; 38 web::WebState* web_state = GetActiveWebState();
38 web::NavigationManager* navigation_manager = 39 web::NavigationManager* navigation_manager =
39 web_state ? web_state->GetNavigationManager() : nullptr; 40 web_state ? web_state->GetNavigationManager() : nullptr;
40 return navigation_manager ? navigation_manager->GetVisibleItem() : nullptr; 41 return navigation_manager ? navigation_manager->GetVisibleItem() : nullptr;
41 } 42 }
42 43
43 base::string16 ToolbarModelDelegateIOS::FormattedStringWithEquivalentMeaning( 44 base::string16 ToolbarModelDelegateIOS::FormattedStringWithEquivalentMeaning(
44 const GURL& url, 45 const GURL& url,
45 const base::string16& formatted_url) const { 46 const base::string16& formatted_url) const {
46 return AutocompleteInput::FormattedStringWithEquivalentMeaning( 47 return AutocompleteInput::FormattedStringWithEquivalentMeaning(
47 url, formatted_url, AutocompleteSchemeClassifierImpl()); 48 url, formatted_url, AutocompleteSchemeClassifierImpl());
(...skipping 19 matching lines...) Expand all
67 url = virtual_url; 68 url = virtual_url;
68 const std::string host = url.host(); 69 const std::string host = url.host();
69 return host != kChromeUIBookmarksHost && host != kChromeUINewTabHost; 70 return host != kChromeUIBookmarksHost && host != kChromeUINewTabHost;
70 } 71 }
71 } 72 }
72 return true; 73 return true;
73 } 74 }
74 75
75 security_state::SecurityLevel ToolbarModelDelegateIOS::GetSecurityLevel() 76 security_state::SecurityLevel ToolbarModelDelegateIOS::GetSecurityLevel()
76 const { 77 const {
77 web::WebState* web_state = [GetCurrentTab() webState]; 78 web::WebState* web_state = GetActiveWebState();
78 // If there is no active WebState (which can happen during toolbar 79 // If there is no active WebState (which can happen during toolbar
79 // initialization), assume no security style. 80 // initialization), assume no security style.
80 if (!web_state) 81 if (!web_state)
81 return security_state::NONE; 82 return security_state::NONE;
82 auto* client = IOSSecurityStateTabHelper::FromWebState(web_state); 83 auto* client = IOSSecurityStateTabHelper::FromWebState(web_state);
83 security_state::SecurityInfo result; 84 security_state::SecurityInfo result;
84 client->GetSecurityInfo(&result); 85 client->GetSecurityInfo(&result);
85 return result.security_level; 86 return result.security_level;
86 } 87 }
87 88
88 scoped_refptr<net::X509Certificate> ToolbarModelDelegateIOS::GetCertificate() 89 scoped_refptr<net::X509Certificate> ToolbarModelDelegateIOS::GetCertificate()
89 const { 90 const {
90 web::NavigationItem* item = GetNavigationItem(); 91 web::NavigationItem* item = GetNavigationItem();
91 if (item) 92 if (item)
92 return item->GetSSL().certificate; 93 return item->GetSSL().certificate;
93 return scoped_refptr<net::X509Certificate>(); 94 return scoped_refptr<net::X509Certificate>();
94 } 95 }
95 96
96 bool ToolbarModelDelegateIOS::FailsMalwareCheck() const { 97 bool ToolbarModelDelegateIOS::FailsMalwareCheck() const {
97 web::WebState* web_state = [GetCurrentTab() webState]; 98 web::WebState* web_state = GetActiveWebState();
98 // If there is no active WebState (which can happen during toolbar 99 // If there is no active WebState (which can happen during toolbar
99 // initialization), so nothing can fail. 100 // initialization), so nothing can fail.
100 if (!web_state) 101 if (!web_state)
101 return NO; 102 return NO;
102 auto* client = IOSSecurityStateTabHelper::FromWebState(web_state); 103 auto* client = IOSSecurityStateTabHelper::FromWebState(web_state);
103 security_state::SecurityInfo result; 104 security_state::SecurityInfo result;
104 client->GetSecurityInfo(&result); 105 client->GetSecurityInfo(&result);
105 return result.malicious_content_status != 106 return result.malicious_content_status !=
106 security_state::MALICIOUS_CONTENT_STATUS_NONE; 107 security_state::MALICIOUS_CONTENT_STATUS_NONE;
107 } 108 }
108 109
109 const gfx::VectorIcon* ToolbarModelDelegateIOS::GetVectorIconOverride() const { 110 const gfx::VectorIcon* ToolbarModelDelegateIOS::GetVectorIconOverride() const {
110 return nullptr; 111 return nullptr;
111 } 112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698