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

Side by Side Diff: ios/chrome/browser/ui/dialogs/nsurl_protection_space_util.mm

Issue 2921833002: [iOS Clean] Created OverlayService.
Patch Set: Cancel overlays on queue deallocation 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
(Empty)
1 // Copyright 2015 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/dialogs/nsurl_protection_space_util.h"
6
7 #include "base/numerics/safe_conversions.h"
8 #include "base/strings/sys_string_conversions.h"
9 #include "components/strings/grit/components_strings.h"
10 #include "components/url_formatter/elide_url.h"
11 #include "ui/base/l10n/l10n_util.h"
12 #include "url/gurl.h"
13 #include "url/scheme_host_port.h"
14
15 #if !defined(__has_feature) || !__has_feature(objc_arc)
16 #error "This file requires ARC support."
17 #endif
18
19 namespace ios_internal {
20 namespace nsurlprotectionspace_util {
21
22 NSString* MessageForHTTPAuth(NSURLProtectionSpace* protectionSpace) {
23 DCHECK(CanShow(protectionSpace));
24
25 if (protectionSpace.receivesCredentialSecurely)
26 return RequesterIdentity(protectionSpace);
27
28 NSString* securityWarning =
29 l10n_util::GetNSString(IDS_PAGE_INFO_NOT_SECURE_SUMMARY);
30 return
31 [NSString stringWithFormat:@"%@ %@", RequesterIdentity(protectionSpace),
32 securityWarning];
33 }
34
35 BOOL CanShow(NSURLProtectionSpace* protectionSpace) {
36 if (protectionSpace.host.length == 0)
37 return NO;
38
39 if (!base::IsValueInRangeForNumericType<uint16_t>(protectionSpace.port))
40 return NO; // Port is invalid.
41
42 if (!protectionSpace.isProxy && !RequesterOrigin(protectionSpace).is_valid())
43 return NO; // Can't construct origin for non-proxy requester.
44
45 return YES;
46 }
47
48 NSString* RequesterIdentity(NSURLProtectionSpace* protectionSpace) {
49 GURL requesterOrigin = RequesterOrigin(protectionSpace);
50 int formatID = protectionSpace.isProxy ? IDS_LOGIN_DIALOG_PROXY_AUTHORITY
51 : IDS_LOGIN_DIALOG_AUTHORITY;
52 if (!requesterOrigin.is_valid()) {
53 // May be invalid for SOCKS proxy type.
54 return l10n_util::GetNSStringF(
55 formatID, base::SysNSStringToUTF16(protectionSpace.host));
56 }
57 base::string16 authority =
58 url_formatter::FormatUrlForSecurityDisplay(requesterOrigin);
59
60 return l10n_util::GetNSStringF(formatID, authority);
61 }
62
63 GURL RequesterOrigin(NSURLProtectionSpace* protectionSpace) {
64 std::string scheme = base::SysNSStringToUTF8(protectionSpace.protocol);
65 std::string host = base::SysNSStringToUTF8(protectionSpace.host);
66 uint16_t port = base::checked_cast<uint16_t>(protectionSpace.port);
67
68 return GURL(url::SchemeHostPort(scheme, host, port).Serialize());
69 }
70
71 } // namespace nsurlprotectionspace_util
72 } // namespace ios_internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698