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

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

Issue 2401683002: Removes WeakNSObject in ARC files in ios/web. (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | ios/web/web_state/crw_pass_kit_downloader.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ios/weak_nsobject.h"
8 #import "base/mac/scoped_nsobject.h" 7 #import "base/mac/scoped_nsobject.h"
9 #import "base/strings/sys_string_conversions.h" 8 #import "base/strings/sys_string_conversions.h"
10 #import "ios/web/public/navigation_item.h" 9 #import "ios/web/public/navigation_item.h"
11 #import "ios/web/public/navigation_manager.h" 10 #import "ios/web/public/navigation_manager.h"
12 #include "ios/web/public/ssl_status.h" 11 #include "ios/web/public/ssl_status.h"
13 #import "ios/web/web_state/wk_web_view_security_util.h" 12 #import "ios/web/web_state/wk_web_view_security_util.h"
14 #include "net/cert/x509_certificate.h" 13 #include "net/cert/x509_certificate.h"
15 #include "url/gurl.h" 14 #include "url/gurl.h"
16 15
17 #if !defined(__has_feature) || !__has_feature(objc_arc) 16 #if !defined(__has_feature) || !__has_feature(objc_arc)
18 #error "This file requires ARC support." 17 #error "This file requires ARC support."
19 #endif 18 #endif
20 19
21 using base::ScopedCFTypeRef; 20 using base::ScopedCFTypeRef;
22 using net::CertStatus; 21 using net::CertStatus;
23 using web::SecurityStyle; 22 using web::SecurityStyle;
24 23
25 @interface CRWSSLStatusUpdater () { 24 @interface CRWSSLStatusUpdater () {
26 // DataSource for CRWSSLStatusUpdater. 25 // DataSource for CRWSSLStatusUpdater.
27 base::WeakNSProtocol<id<CRWSSLStatusUpdaterDataSource>> _dataSource; 26 __weak id<CRWSSLStatusUpdaterDataSource> _dataSource;
28 // Backs up property of the same name.
29 base::WeakNSProtocol<id<CRWSSLStatusUpdaterDelegate>> _delegate;
30 } 27 }
31 28
32 // Unowned pointer to web::NavigationManager. 29 // Unowned pointer to web::NavigationManager.
33 @property(nonatomic, readonly) web::NavigationManager* navigationManager; 30 @property(nonatomic, readonly) web::NavigationManager* navigationManager;
34 31
35 // Updates |security_style| and |cert_status| for the NavigationItem with ID 32 // Updates |security_style| and |cert_status| for the NavigationItem with ID
36 // |navigationItemID|, if URL and certificate chain still match |host| and 33 // |navigationItemID|, if URL and certificate chain still match |host| and
37 // |certChain|. 34 // |certChain|.
38 - (void)updateSSLStatusForItemWithID:(int)navigationItemID 35 - (void)updateSSLStatusForItemWithID:(int)navigationItemID
39 trust:(ScopedCFTypeRef<SecTrustRef>)trust 36 trust:(ScopedCFTypeRef<SecTrustRef>)trust
40 host:(NSString*)host 37 host:(NSString*)host
41 withSecurityStyle:(SecurityStyle)style 38 withSecurityStyle:(SecurityStyle)style
42 certStatus:(CertStatus)certStatus; 39 certStatus:(CertStatus)certStatus;
43 40
44 // Asynchronously obtains SSL status from given |secTrust| and |host| and 41 // Asynchronously obtains SSL status from given |secTrust| and |host| and
45 // updates current navigation item. Before scheduling update changes SSLStatus' 42 // updates current navigation item. Before scheduling update changes SSLStatus'
46 // cert_status and security_style to default. 43 // cert_status and security_style to default.
47 - (void)scheduleSSLStatusUpdateUsingTrust:(ScopedCFTypeRef<SecTrustRef>)trust 44 - (void)scheduleSSLStatusUpdateUsingTrust:(ScopedCFTypeRef<SecTrustRef>)trust
48 host:(NSString*)host; 45 host:(NSString*)host;
49 46
50 // Notifies delegate about SSLStatus change. 47 // Notifies delegate about SSLStatus change.
51 - (void)didChangeSSLStatusForNavigationItem:(web::NavigationItem*)navItem; 48 - (void)didChangeSSLStatusForNavigationItem:(web::NavigationItem*)navItem;
52 49
53 @end 50 @end
54 51
55 @implementation CRWSSLStatusUpdater 52 @implementation CRWSSLStatusUpdater
56 @synthesize navigationManager = _navigationManager; 53 @synthesize navigationManager = _navigationManager;
54 @synthesize delegate = _delegate;
57 55
58 #pragma mark - Public 56 #pragma mark - Public
59 57
60 - (instancetype)initWithDataSource:(id<CRWSSLStatusUpdaterDataSource>)dataSource 58 - (instancetype)initWithDataSource:(id<CRWSSLStatusUpdaterDataSource>)dataSource
61 navigationManager:(web::NavigationManager*)navigationManager { 59 navigationManager:(web::NavigationManager*)navigationManager {
62 DCHECK(dataSource); 60 DCHECK(dataSource);
63 DCHECK(navigationManager); 61 DCHECK(navigationManager);
64 if (self = [super init]) { 62 if (self = [super init]) {
65 _dataSource.reset(dataSource); 63 _dataSource = dataSource;
66 _navigationManager = navigationManager; 64 _navigationManager = navigationManager;
67 } 65 }
68 return self; 66 return self;
69 } 67 }
70 68
71 - (id<CRWSSLStatusUpdaterDelegate>)delegate {
72 return _delegate.get();
73 }
74
75 - (void)setDelegate:(id<CRWSSLStatusUpdaterDelegate>)delegate {
76 _delegate.reset(delegate);
77 }
78
79 - (void)updateSSLStatusForNavigationItem:(web::NavigationItem*)item 69 - (void)updateSSLStatusForNavigationItem:(web::NavigationItem*)item
80 withCertHost:(NSString*)host 70 withCertHost:(NSString*)host
81 trust:(ScopedCFTypeRef<SecTrustRef>)trust 71 trust:(ScopedCFTypeRef<SecTrustRef>)trust
82 hasOnlySecureContent:(BOOL)hasOnlySecureContent { 72 hasOnlySecureContent:(BOOL)hasOnlySecureContent {
83 web::SSLStatus previousSSLStatus = item->GetSSL(); 73 web::SSLStatus previousSSLStatus = item->GetSSL();
84 74
85 // Starting from iOS9 WKWebView blocks active mixed content, so if 75 // Starting from iOS9 WKWebView blocks active mixed content, so if
86 // |hasOnlySecureContent| returns NO it means passive content. 76 // |hasOnlySecureContent| returns NO it means passive content.
87 item->GetSSL().content_status = 77 item->GetSSL().content_status =
88 hasOnlySecureContent ? web::SSLStatus::NORMAL_CONTENT 78 hasOnlySecureContent ? web::SSLStatus::NORMAL_CONTENT
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 151 }
162 } 152 }
163 153
164 - (void)scheduleSSLStatusUpdateUsingTrust:(ScopedCFTypeRef<SecTrustRef>)trust 154 - (void)scheduleSSLStatusUpdateUsingTrust:(ScopedCFTypeRef<SecTrustRef>)trust
165 host:(NSString*)host { 155 host:(NSString*)host {
166 // Use Navigation Item's unique ID to locate requested item after 156 // Use Navigation Item's unique ID to locate requested item after
167 // obtaining cert status asynchronously. 157 // obtaining cert status asynchronously.
168 int itemID = _navigationManager->GetLastCommittedItem()->GetUniqueID(); 158 int itemID = _navigationManager->GetLastCommittedItem()->GetUniqueID();
169 159
170 DCHECK(_dataSource); 160 DCHECK(_dataSource);
171 base::WeakNSObject<CRWSSLStatusUpdater> weakSelf(self); 161 __weak CRWSSLStatusUpdater* weakSelf = self;
172 [_dataSource SSLStatusUpdater:self 162 [_dataSource SSLStatusUpdater:self
173 querySSLStatusForTrust:trust 163 querySSLStatusForTrust:trust
174 host:host 164 host:host
175 completionHandler:^(SecurityStyle style, CertStatus certStatus) { 165 completionHandler:^(SecurityStyle style, CertStatus certStatus) {
176 [weakSelf updateSSLStatusForItemWithID:itemID 166 [weakSelf updateSSLStatusForItemWithID:itemID
177 trust:std::move(trust) 167 trust:std::move(trust)
178 host:host 168 host:host
179 withSecurityStyle:style 169 withSecurityStyle:style
180 certStatus:certStatus]; 170 certStatus:certStatus];
181 }]; 171 }];
182 } 172 }
183 173
184 - (void)didChangeSSLStatusForNavigationItem:(web::NavigationItem*)navItem { 174 - (void)didChangeSSLStatusForNavigationItem:(web::NavigationItem*)navItem {
185 if ([_delegate respondsToSelector: 175 if ([_delegate respondsToSelector:
186 @selector(SSLStatusUpdater:didChangeSSLStatusForNavigationItem:)]) { 176 @selector(SSLStatusUpdater:didChangeSSLStatusForNavigationItem:)]) {
187 [_delegate SSLStatusUpdater:self 177 [_delegate SSLStatusUpdater:self
188 didChangeSSLStatusForNavigationItem:navItem]; 178 didChangeSSLStatusForNavigationItem:navItem];
189 } 179 }
190 } 180 }
191 181
192 @end 182 @end
OLDNEW
« no previous file with comments | « no previous file | ios/web/web_state/crw_pass_kit_downloader.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698