Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

Use URL components #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions BrowserSimulator/BrowserSimulator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@
D132B941162766E100E4F30D /* NSURL+XCallbackURL.m */,
D132B91C1627652F00E4F30D /* Supporting Files */,
);
name = BrowserSimulator;
path = BrowserSimulator;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -182,7 +181,7 @@
D132B9081627652F00E4F30D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0450;
LastUpgradeCheck = 0830;
ORGANIZATIONNAME = "Google Inc.";
};
buildConfigurationList = D132B90B1627652F00E4F30D /* Build configuration list for PBXProject "BrowserSimulator" */;
Expand Down Expand Up @@ -284,22 +283,35 @@
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -312,15 +324,27 @@
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -334,7 +358,8 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "BrowserSimulator/BrowserSimulator-Prefix.pch";
INFOPLIST_FILE = "BrowserSimulator/BrowserSimulator-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 5.1;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.google.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = BrowserSimulator;
WRAPPER_EXTENSION = app;
};
Expand All @@ -346,7 +371,8 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "BrowserSimulator/BrowserSimulator-Prefix.pch";
INFOPLIST_FILE = "BrowserSimulator/BrowserSimulator-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 5.1;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.google.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = BrowserSimulator;
WRAPPER_EXTENSION = app;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</dict>
</dict>
<key>CFBundleIdentifier</key>
<string>com.google.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
4 changes: 2 additions & 2 deletions BrowserSimulator/BrowserSimulator/BrowserSimulator-Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

#import <Availability.h>

#ifndef __IPHONE_4_0
#warning "This project uses features only available in iOS SDK 4.0 and later."
#ifndef __IPHONE_7_0
#warning "This project uses features only available in iOS SDK 7.0 and later."
#endif

#ifdef __OBJC__
Expand Down
19 changes: 5 additions & 14 deletions BrowserSimulator/BrowserSimulator/FlipsideViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,11 @@

#import "FlipsideViewController.h"

@interface FlipsideViewController ()

@end

@implementation FlipsideViewController

@synthesize textView = textView_;
@synthesize delegate = delegate_;

- (id)initWithNibName:(NSString *)nibNameOrNil
bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.contentSizeForViewInPopover = CGSizeMake(320.0, 480.0);
}
return self;
}

- (void)dealloc {
[textView_ release];
[super dealloc];
Expand All @@ -56,10 +43,14 @@ - (void)viewWillAppear:(BOOL)animated {
self.textView.text = self.delegate.information;
}

- (CGSize)preferredContentSize {
return CGSizeMake(320.0, 480.0);
}

#pragma mark - Actions

- (IBAction)done:(id)sender {
[self.delegate flipsideViewControllerDidFinish:self];
[self.delegate flipsideViewControllerDidFinish:self];
}

@end
8 changes: 4 additions & 4 deletions BrowserSimulator/BrowserSimulator/MainViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ - (void)load:(NSURL *)url {
[self.navigationBar setItems:[NSArray array] animated:NO];

UINavigationItem *item =
[[[UINavigationItem alloc] initWithTitle:nil] autorelease];
[[[UINavigationItem alloc] initWithTitle:@""] autorelease];
item.title = self.sourceApp;
[self.navigationBar pushNavigationItem:item animated:NO];

item = [[[UINavigationItem alloc] initWithTitle:nil] autorelease];
item = [[[UINavigationItem alloc] initWithTitle:@""] autorelease];
if (!self.sourceApp) {
item.leftBarButtonItem =
[[[UIBarButtonItem alloc] initWithTitle:@""
style:UIBarButtonItemStyleBordered
style:UIBarButtonItemStylePlain
target:nil
action:nil] autorelease];
}
Expand All @@ -139,7 +139,7 @@ - (void)load:(NSURL *)url {

UIBarButtonItem *infoButton =
[[[UIBarButtonItem alloc] initWithTitle:@"Info"
style:UIBarButtonItemStyleBordered
style:UIBarButtonItemStylePlain
target:self
action:@selector(showInfo:)]
autorelease];
Expand Down
6 changes: 3 additions & 3 deletions OpenInChromeController.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@
@interface OpenInChromeController : NSObject

// Returns a shared instance of the OpenInChromeController.
+ (OpenInChromeController *)sharedInstance;
+ (instancetype)sharedInstance;

// Returns YES if Google Chrome is installed in the user's system.
- (BOOL)isChromeInstalled;

// Opens a URL in Google Chrome.
- (BOOL)openInChrome:(NSURL *)url;
- (BOOL)openInChrome:(NSURL *)URL;

// iOS displays a "Back to app" link on the device's status line if app was
// launched from another app. This makes the |callbackURL| parameter much less
// useful. Chrome has stopped processing the callback URL and create new tab
// options.
// @warning DEPRECATED: Please use -openInChrome: directly.
- (BOOL)openInChrome:(NSURL *)url
- (BOOL)openInChrome:(NSURL *)URL
withCallbackURL:(NSURL *)callbackURL
createNewTab:(BOOL)createNewTab __attribute__((deprecated));

Expand Down
39 changes: 19 additions & 20 deletions OpenInChromeController.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@

#import "OpenInChromeController.h"

static NSString * const kGoogleChromeHTTPScheme = @"googlechrome:";
static NSString * const kGoogleChromeHTTPSScheme = @"googlechromes:";
static NSString * const kGoogleChromeHTTPScheme = @"googlechrome";
static NSString * const kGoogleChromeHTTPSScheme = @"googlechromes";

@implementation OpenInChromeController

+ (OpenInChromeController *)sharedInstance {
+ (instancetype)sharedInstance {
static OpenInChromeController *sharedInstance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Expand All @@ -50,41 +50,40 @@ + (OpenInChromeController *)sharedInstance {
}

- (BOOL)isChromeInstalled {
NSURL *simpleURL = [NSURL URLWithString:kGoogleChromeHTTPScheme];
return [[UIApplication sharedApplication] canOpenURL:simpleURL];
NSURLComponents *components = [[NSURLComponents alloc] init];
components.scheme = kGoogleChromeHTTPScheme;
return [[UIApplication sharedApplication] canOpenURL:components.URL];
}

- (BOOL)openInChrome:(NSURL *)url {
- (BOOL)openInChrome:(NSURL *)URL {
if ([self isChromeInstalled]) {
NSString *scheme = [url.scheme lowercaseString];
// Replace the URL Scheme with the Chrome equivalent.
NSURLComponents *components =
[NSURLComponents componentsWithURL:URL resolvingAgainstBaseURL:YES];

NSString *scheme = components.scheme;
// Replace the URI Scheme with the Chrome equivalent.
NSString *chromeScheme = nil;
if ([scheme isEqualToString:@"http"]) {
if ([scheme caseInsensitiveCompare:@"http"] == NSOrderedSame) {
chromeScheme = kGoogleChromeHTTPScheme;
} else if ([scheme isEqualToString:@"https"]) {
} else if ([scheme caseInsensitiveCompare:@"https"] == NSOrderedSame) {
chromeScheme = kGoogleChromeHTTPSScheme;
}

// Proceed only if a valid Google Chrome URI Scheme is available.
if (chromeScheme) {
NSString *absoluteString = [url absoluteString];
NSRange rangeForScheme = [absoluteString rangeOfString:@":"];
NSString *urlNoScheme =
[absoluteString substringFromIndex:rangeForScheme.location + 1];
NSString *chromeURLString =
[chromeScheme stringByAppendingString:urlNoScheme];
NSURL *chromeURL = [NSURL URLWithString:chromeURLString];
components.scheme = chromeScheme;
// Open the URL with Google Chrome.
return [[UIApplication sharedApplication] openURL:chromeURL];
return [[UIApplication sharedApplication] openURL:components.URL];
}
}
return NO;
}

- (BOOL)openInChrome:(NSURL *)url
- (BOOL)openInChrome:(NSURL *)URL
withCallbackURL:(NSURL *)callbackURL
createNewTab:(BOOL)createNewTab {
// This deprecated API simply calls the supported -openInChrome: API.
return [self openInChrome:url];
return [self openInChrome:URL];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
D1C1042D162FF67B0074F0BA /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0450;
LastUpgradeCheck = 0830;
ORGANIZATIONNAME = "Google Inc.";
};
buildConfigurationList = D1C10430162FF67B0074F0BA /* Build configuration list for PBXProject "OpenInChromeSampleApp" */;
Expand Down Expand Up @@ -225,22 +225,35 @@
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.1;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -253,15 +266,27 @@
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.1;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -278,6 +303,7 @@
GCC_PREFIX_HEADER = "OpenInChromeSampleApp/OpenInChromeSampleApp-Prefix.pch";
INFOPLIST_FILE = "OpenInChromeSampleApp/OpenInChromeSampleApp-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.mycompany.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = app;
Expand All @@ -293,6 +319,7 @@
GCC_PREFIX_HEADER = "OpenInChromeSampleApp/OpenInChromeSampleApp-Prefix.pch";
INFOPLIST_FILE = "OpenInChromeSampleApp/OpenInChromeSampleApp-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.mycompany.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = app;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.mycompany.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
Loading