| OLD | NEW |
| 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/chrome/browser/itunes_links/itunes_links_observer.h" | 5 #import "ios/chrome/browser/itunes_links/itunes_links_observer.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #import "base/mac/scoped_nsobject.h" | |
| 11 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 12 #import "ios/chrome/browser/storekit_launcher.h" | 11 #import "ios/chrome/browser/storekit_launcher.h" |
| 13 #import "ios/web/public/web_state/web_state_observer_bridge.h" | 12 #import "ios/web/public/web_state/web_state_observer_bridge.h" |
| 14 #include "ios/web/public/web_state/web_state.h" | 13 #include "ios/web/public/web_state/web_state.h" |
| 15 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 16 | 15 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." |
| 18 #endif |
| 19 |
| 17 @interface ITunesLinksObserver () | 20 @interface ITunesLinksObserver () |
| 18 | 21 |
| 19 // If |URL| points to a product on itunes.apple.com, returns the product ID. | 22 // If |URL| points to a product on itunes.apple.com, returns the product ID. |
| 20 // Otherwise, returns nil. | 23 // Otherwise, returns nil. |
| 21 // Examples of URLs pointing to products on itunes.apple.com can be found in | 24 // Examples of URLs pointing to products on itunes.apple.com can be found in |
| 22 // itunes_links_observer_unittest.mm. | 25 // itunes_links_observer_unittest.mm. |
| 23 + (NSString*)productIDFromURL:(const GURL&)URL; | 26 + (NSString*)productIDFromURL:(const GURL&)URL; |
| 24 | 27 |
| 25 @end | 28 @end |
| 26 | 29 |
| 27 @implementation ITunesLinksObserver { | 30 @implementation ITunesLinksObserver { |
| 28 base::WeakNSProtocol<id<StoreKitLauncher>> _storeKitLauncher; | 31 __weak id<StoreKitLauncher> _storeKitLauncher; |
| 29 std::unique_ptr<web::WebStateObserverBridge> _webStateObserverBridge; | 32 std::unique_ptr<web::WebStateObserverBridge> _webStateObserverBridge; |
| 30 } | 33 } |
| 31 | 34 |
| 32 - (instancetype)initWithWebState:(web::WebState*)webState { | 35 - (instancetype)initWithWebState:(web::WebState*)webState { |
| 33 self = [super init]; | 36 self = [super init]; |
| 34 if (self) { | 37 if (self) { |
| 35 _webStateObserverBridge.reset( | 38 _webStateObserverBridge.reset( |
| 36 new web::WebStateObserverBridge(webState, self)); | 39 new web::WebStateObserverBridge(webState, self)); |
| 37 } | 40 } |
| 38 return self; | 41 return self; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 57 #pragma mark - CRWWebStateObserver | 60 #pragma mark - CRWWebStateObserver |
| 58 | 61 |
| 59 - (void)webStateDidLoadPage:(web::WebState*)webState { | 62 - (void)webStateDidLoadPage:(web::WebState*)webState { |
| 60 GURL URL = webState->GetLastCommittedURL(); | 63 GURL URL = webState->GetLastCommittedURL(); |
| 61 NSString* productID = [ITunesLinksObserver productIDFromURL:URL]; | 64 NSString* productID = [ITunesLinksObserver productIDFromURL:URL]; |
| 62 if (productID) | 65 if (productID) |
| 63 [_storeKitLauncher openAppStore:productID]; | 66 [_storeKitLauncher openAppStore:productID]; |
| 64 } | 67 } |
| 65 | 68 |
| 66 - (void)setStoreKitLauncher:(id<StoreKitLauncher>)storeKitLauncher { | 69 - (void)setStoreKitLauncher:(id<StoreKitLauncher>)storeKitLauncher { |
| 67 _storeKitLauncher.reset(storeKitLauncher); | 70 _storeKitLauncher = storeKitLauncher; |
| 68 } | 71 } |
| 69 | 72 |
| 70 @end | 73 @end |
| OLD | NEW |