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

Side by Side Diff: ios/chrome/browser/chrome_url_util.mm

Issue 2566993002: [ObjC ARC] Converts ios/chrome/browser:browser to ARC. (Closed)
Patch Set: comments 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
« no previous file with comments | « ios/chrome/browser/chrome_paths.mm ('k') | ios/chrome/browser/crash_loop_detection_util.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 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/chrome_url_util.h" 5 #import "ios/chrome/browser/chrome_url_util.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/foundation_util.h" 10 #include "base/mac/foundation_util.h"
11 #include "base/mac/scoped_block.h" 11 #include "base/mac/scoped_block.h"
12 #include "base/mac/scoped_nsobject.h"
13 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
14 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
15 #include "ios/chrome/browser/chrome_url_constants.h" 14 #include "ios/chrome/browser/chrome_url_constants.h"
16 #import "ios/net/url_scheme_util.h" 15 #import "ios/net/url_scheme_util.h"
17 #include "net/url_request/url_request.h" 16 #include "net/url_request/url_request.h"
18 #include "url/gurl.h" 17 #include "url/gurl.h"
19 #include "url/url_constants.h" 18 #include "url/url_constants.h"
20 19
20 #if !defined(__has_feature) || !__has_feature(objc_arc)
21 #error "This file requires ARC support."
22 #endif
23
21 bool UrlIsExternalFileReference(const GURL& url) { 24 bool UrlIsExternalFileReference(const GURL& url) {
22 return url.SchemeIs(kChromeUIScheme) && 25 return url.SchemeIs(kChromeUIScheme) &&
23 base::LowerCaseEqualsASCII(url.host(), kChromeUIExternalFileHost); 26 base::LowerCaseEqualsASCII(url.host(), kChromeUIExternalFileHost);
24 } 27 }
25 28
26 bool UrlHasChromeScheme(const GURL& url) { 29 bool UrlHasChromeScheme(const GURL& url) {
27 return url.SchemeIs(kChromeUIScheme); 30 return url.SchemeIs(kChromeUIScheme);
28 } 31 }
29 32
30 bool UrlHasChromeScheme(NSURL* url) { 33 bool UrlHasChromeScheme(NSURL* url) {
31 return net::UrlSchemeIs(url, base::SysUTF8ToNSString(kChromeUIScheme)); 34 return net::UrlSchemeIs(url, base::SysUTF8ToNSString(kChromeUIScheme));
32 } 35 }
33 36
34 bool IsHandledProtocol(const std::string& scheme) { 37 bool IsHandledProtocol(const std::string& scheme) {
35 DCHECK_EQ(scheme, base::ToLowerASCII(scheme)); 38 DCHECK_EQ(scheme, base::ToLowerASCII(scheme));
36 if (scheme == url::kAboutScheme) 39 if (scheme == url::kAboutScheme)
37 return true; 40 return true;
38 if (scheme == url::kDataScheme) 41 if (scheme == url::kDataScheme)
39 return true; 42 return true;
40 if (scheme == kChromeUIScheme) 43 if (scheme == kChromeUIScheme)
41 return true; 44 return true;
42 return net::URLRequest::IsHandledProtocol(scheme); 45 return net::URLRequest::IsHandledProtocol(scheme);
43 } 46 }
44 47
45 @implementation ChromeAppConstants { 48 @implementation ChromeAppConstants {
46 base::scoped_nsobject<NSString> _callbackScheme; 49 NSString* _callbackScheme;
47 } 50 }
48 51
49 + (ChromeAppConstants*)sharedInstance { 52 + (ChromeAppConstants*)sharedInstance {
50 static ChromeAppConstants* g_instance = [[ChromeAppConstants alloc] init]; 53 static ChromeAppConstants* g_instance = [[ChromeAppConstants alloc] init];
51 return g_instance; 54 return g_instance;
52 } 55 }
53 56
54 - (NSString*)getBundleURLScheme { 57 - (NSString*)getBundleURLScheme {
55 if (!_callbackScheme) { 58 if (!_callbackScheme) {
56 NSSet* allowableSchemes = 59 NSSet* allowableSchemes =
57 [NSSet setWithObjects:@"googlechrome", @"chromium", 60 [NSSet setWithObjects:@"googlechrome", @"chromium",
58 @"ios-chrome-unittests.http", nil]; 61 @"ios-chrome-unittests.http", nil];
59 NSDictionary* info = [[NSBundle mainBundle] infoDictionary]; 62 NSDictionary* info = [[NSBundle mainBundle] infoDictionary];
60 NSArray* urlTypes = [info objectForKey:@"CFBundleURLTypes"]; 63 NSArray* urlTypes = [info objectForKey:@"CFBundleURLTypes"];
61 for (NSDictionary* urlType in urlTypes) { 64 for (NSDictionary* urlType in urlTypes) {
62 DCHECK([urlType isKindOfClass:[NSDictionary class]]); 65 DCHECK([urlType isKindOfClass:[NSDictionary class]]);
63 NSArray* schemes = 66 NSArray* schemes =
64 base::mac::ObjCCastStrict<NSArray>(urlType[@"CFBundleURLSchemes"]); 67 base::mac::ObjCCastStrict<NSArray>(urlType[@"CFBundleURLSchemes"]);
65 for (NSString* scheme in schemes) { 68 for (NSString* scheme in schemes) {
66 if ([allowableSchemes containsObject:scheme]) 69 if ([allowableSchemes containsObject:scheme])
67 _callbackScheme.reset([scheme copy]); 70 _callbackScheme = [scheme copy];
68 } 71 }
69 } 72 }
70 } 73 }
71 DCHECK([_callbackScheme length]); 74 DCHECK([_callbackScheme length]);
72 return _callbackScheme; 75 return _callbackScheme;
73 } 76 }
74 77
75 - (void)setCallbackSchemeForTesting:(NSString*)scheme { 78 - (void)setCallbackSchemeForTesting:(NSString*)scheme {
76 _callbackScheme.reset([scheme copy]); 79 _callbackScheme = [scheme copy];
77 } 80 }
78 81
79 @end 82 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/chrome_paths.mm ('k') | ios/chrome/browser/crash_loop_detection_util.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698