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

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

Issue 1139383002: [iOS] Upstream URL utilities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 2012 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/chrome_url_util.h"
6
7 #import <UIKit/UIKit.h>
8
9 #include "base/logging.h"
10 #include "base/mac/scoped_nsobject.h"
11 #include "base/strings/string_util.h"
12 #include "base/strings/sys_string_conversions.h"
13 #include "ios/chrome/browser/chrome_url_constants.h"
14 #import "ios/net/url_scheme_util.h"
15 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
16 #include "url/gurl.h"
17
18 bool UrlIsExternalFileReference(const GURL& url) {
19 return url.SchemeIs(ios::GetChromeBrowserProvider()->GetChromeUIScheme()) &&
20 LowerCaseEqualsASCII(url.host(), kChromeUIExternalFileHost);
21 }
22
23 NSURL* UrlToLaunchChrome() {
24 // Determines the target URL scheme that will launch Chrome.
25 NSString* scheme = [[ChromeAppConstants sharedInstance] getBundleURLScheme];
26 return [NSURL URLWithString:[NSString stringWithFormat:@"%@://", scheme]];
27 }
28
29 NSURL* UrlOfChromeAppIcon(int width, int height) {
30 NSString* url =
31 [[ChromeAppConstants sharedInstance] getChromeAppIconURLOfWidth:width
32 height:height];
33 return [NSURL URLWithString:url];
34 }
35
36 bool UrlHasChromeScheme(const GURL& url) {
37 return url.SchemeIs(ios::GetChromeBrowserProvider()->GetChromeUIScheme());
38 }
39
40 bool UrlHasChromeScheme(NSURL* url) {
41 return net::UrlSchemeIs(
42 url, base::SysUTF8ToNSString(
43 ios::GetChromeBrowserProvider()->GetChromeUIScheme()));
44 }
45
46 @implementation ChromeAppConstants {
47 base::scoped_nsobject<NSString> callbackScheme_;
48 base::scoped_nsprotocol<AppIconURLProvider> appIconURLProvider_;
rohitrao (ping after 24h) 2015/05/18 13:34:56 Want to switch to leading underscores for these va
sdefresne 2015/05/18 14:19:54 Done and changed the block to use base::mac::Scope
49 }
50
51 + (ChromeAppConstants*)sharedInstance {
52 static ChromeAppConstants* g_instance = [[ChromeAppConstants alloc] init];
53 return g_instance;
54 }
55
56 - (NSString*)getBundleURLScheme {
57 if (!callbackScheme_) {
58 NSSet* allowableSchemes =
59 [NSSet setWithObjects:@"googlechrome", @"chromium", nil];
60 NSDictionary* info = [[NSBundle mainBundle] infoDictionary];
61 NSArray* urlTypes = [info objectForKey:@"CFBundleURLTypes"];
62 for (NSDictionary* urlType in urlTypes) {
63 DCHECK([urlType isKindOfClass:[NSDictionary class]]);
64 NSArray* schemes = [urlType objectForKey:@"CFBundleURLSchemes"];
65 if (!schemes)
66 continue;
67 DCHECK([schemes isKindOfClass:[NSArray class]]);
68 for (NSString* scheme in schemes) {
69 if ([allowableSchemes containsObject:scheme])
70 callbackScheme_.reset([scheme copy]);
71 }
72 }
73 }
74 DCHECK([callbackScheme_ length]);
75 return callbackScheme_;
76 }
77
78 - (NSString*)getChromeAppIconURLOfWidth:(int)width height:(int)height {
79 if (!appIconURLProvider_) {
80 appIconURLProvider_.reset([^(int width, int height) {
81 return [NSString
82 stringWithFormat:@"https://%@/Icon-%dx%d-%dx.png",
83 @"ssl.gstatic.com/ios-apps/com.google.chrome.ios",
rohitrao (ping after 24h) 2015/05/18 13:34:56 We should consider debranding this.
sdefresne 2015/05/18 14:19:54 Added a TODO.
84 width, height,
85 [[UIScreen mainScreen] scale] == 1.0 ? 1 : 2];
86 } copy]);
87 }
88 return appIconURLProvider_.get()(width, height);
89 }
90
91 - (void)setCallbackSchemeForTesting:(NSString*)scheme {
92 callbackScheme_.reset([scheme copy]);
93 }
94
95 - (void)setAppIconURLProviderForTesting:(AppIconURLProvider)block {
96 appIconURLProvider_.reset([block copy]);
97 }
98
99 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698