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

Side by Side Diff: ios/web/net/crw_ssl_status_updater.mm

Issue 2875153003: Added web::GetCommittedItemWithUniqueID function. (Closed)
Patch Set: Added GetCommittedItemIndexWithUniqueID Created 3 years, 6 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 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 #import "ios/web/net/crw_ssl_status_updater.h" 5 #import "ios/web/net/crw_ssl_status_updater.h"
6 6
7 #import "base/mac/scoped_nsobject.h" 7 #import "base/mac/scoped_nsobject.h"
8 #import "base/strings/sys_string_conversions.h" 8 #import "base/strings/sys_string_conversions.h"
9 #include "ios/web/navigation/navigation_manager_util.h"
9 #import "ios/web/public/navigation_item.h" 10 #import "ios/web/public/navigation_item.h"
10 #import "ios/web/public/navigation_manager.h" 11 #import "ios/web/public/navigation_manager.h"
11 #include "ios/web/public/ssl_status.h" 12 #include "ios/web/public/ssl_status.h"
12 #import "ios/web/web_state/wk_web_view_security_util.h" 13 #import "ios/web/web_state/wk_web_view_security_util.h"
13 #include "net/cert/x509_certificate.h" 14 #include "net/cert/x509_certificate.h"
14 #include "url/gurl.h" 15 #include "url/gurl.h"
15 16
16 #if !defined(__has_feature) || !__has_feature(objc_arc) 17 #if !defined(__has_feature) || !__has_feature(objc_arc)
17 #error "This file requires ARC support." 18 #error "This file requires ARC support."
18 #endif 19 #endif
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 } 119 }
119 } 120 }
120 121
121 #pragma mark - Private 122 #pragma mark - Private
122 123
123 - (void)updateSSLStatusForItemWithID:(int)navigationItemID 124 - (void)updateSSLStatusForItemWithID:(int)navigationItemID
124 trust:(ScopedCFTypeRef<SecTrustRef>)trust 125 trust:(ScopedCFTypeRef<SecTrustRef>)trust
125 host:(NSString*)host 126 host:(NSString*)host
126 withSecurityStyle:(SecurityStyle)style 127 withSecurityStyle:(SecurityStyle)style
127 certStatus:(CertStatus)certStatus { 128 certStatus:(CertStatus)certStatus {
128 // The searched item almost always be the last one, so walk backward rather 129 web::NavigationItem* item =
129 // than forward. 130 web::GetCommittedItemWithUniqueID(_navigationManager, navigationItemID);
130 for (int i = _navigationManager->GetItemCount() - 1; 0 <= i; i--) { 131 if (!item)
131 web::NavigationItem* item = _navigationManager->GetItemAtIndex(i); 132 return;
132 if (item->GetUniqueID() != navigationItemID)
133 continue;
134 133
135 // NavigationItem's UniqueID is preserved even after redirects, so 134 // NavigationItem's UniqueID is preserved even after redirects, so
136 // checking that cert and URL match is necessary. 135 // checking that cert and URL match is necessary.
137 scoped_refptr<net::X509Certificate> cert(web::CreateCertFromTrust(trust)); 136 scoped_refptr<net::X509Certificate> cert(web::CreateCertFromTrust(trust));
138 std::string GURLHost = base::SysNSStringToUTF8(host); 137 std::string GURLHost = base::SysNSStringToUTF8(host);
139 web::SSLStatus& SSLStatus = item->GetSSL(); 138 web::SSLStatus& SSLStatus = item->GetSSL();
140 if (item->GetURL().SchemeIsCryptographic() && !!SSLStatus.certificate && 139 if (item->GetURL().SchemeIsCryptographic() && !!SSLStatus.certificate &&
141 SSLStatus.certificate->Equals(cert.get()) && 140 SSLStatus.certificate->Equals(cert.get()) &&
142 item->GetURL().host() == GURLHost) { 141 item->GetURL().host() == GURLHost) {
143 web::SSLStatus previousSSLStatus = item->GetSSL(); 142 web::SSLStatus previousSSLStatus = item->GetSSL();
144 SSLStatus.cert_status = certStatus; 143 SSLStatus.cert_status = certStatus;
145 SSLStatus.security_style = style; 144 SSLStatus.security_style = style;
146 if (!previousSSLStatus.Equals(SSLStatus)) { 145 if (!previousSSLStatus.Equals(SSLStatus)) {
147 [self didChangeSSLStatusForNavigationItem:item]; 146 [self didChangeSSLStatusForNavigationItem:item];
148 }
149 } 147 }
150 return;
151 } 148 }
152 } 149 }
153 150
154 - (void)scheduleSSLStatusUpdateUsingTrust:(ScopedCFTypeRef<SecTrustRef>)trust 151 - (void)scheduleSSLStatusUpdateUsingTrust:(ScopedCFTypeRef<SecTrustRef>)trust
155 host:(NSString*)host { 152 host:(NSString*)host {
156 // Use Navigation Item's unique ID to locate requested item after 153 // Use Navigation Item's unique ID to locate requested item after
157 // obtaining cert status asynchronously. 154 // obtaining cert status asynchronously.
158 int itemID = _navigationManager->GetLastCommittedItem()->GetUniqueID(); 155 int itemID = _navigationManager->GetLastCommittedItem()->GetUniqueID();
159 156
160 DCHECK(_dataSource); 157 DCHECK(_dataSource);
(...skipping 12 matching lines...) Expand all
173 170
174 - (void)didChangeSSLStatusForNavigationItem:(web::NavigationItem*)navItem { 171 - (void)didChangeSSLStatusForNavigationItem:(web::NavigationItem*)navItem {
175 if ([_delegate respondsToSelector: 172 if ([_delegate respondsToSelector:
176 @selector(SSLStatusUpdater:didChangeSSLStatusForNavigationItem:)]) { 173 @selector(SSLStatusUpdater:didChangeSSLStatusForNavigationItem:)]) {
177 [_delegate SSLStatusUpdater:self 174 [_delegate SSLStatusUpdater:self
178 didChangeSSLStatusForNavigationItem:navItem]; 175 didChangeSSLStatusForNavigationItem:navItem];
179 } 176 }
180 } 177 }
181 178
182 @end 179 @end
OLDNEW
« no previous file with comments | « ios/web/navigation/navigation_manager_util_unittest.mm ('k') | ios/web/web_state/ui/crw_web_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698