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

Side by Side Diff: ios/chrome/browser/ui/browser_view_controller.mm

Issue 2674653003: Use IOSImageDataFetcherWrapper in BrowserViewController (Closed)
Patch Set: Change IOSImageDataFetcherWrapper wrapping Created 3 years, 10 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
« no previous file with comments | « ios/chrome/browser/ui/BUILD.gn ('k') | no next file » | 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/ui/browser_view_controller.h" 5 #import "ios/chrome/browser/ui/browser_view_controller.h"
6 6
7 #import <AssetsLibrary/AssetsLibrary.h> 7 #import <AssetsLibrary/AssetsLibrary.h>
8 #import <MobileCoreServices/MobileCoreServices.h> 8 #import <MobileCoreServices/MobileCoreServices.h>
9 #import <PassKit/PassKit.h> 9 #import <PassKit/PassKit.h>
10 #import <Photos/Photos.h> 10 #import <Photos/Photos.h>
(...skipping 18 matching lines...) Expand all
29 #import "base/mac/scoped_block.h" 29 #import "base/mac/scoped_block.h"
30 #import "base/mac/scoped_nsobject.h" 30 #import "base/mac/scoped_nsobject.h"
31 #include "base/macros.h" 31 #include "base/macros.h"
32 #include "base/memory/ptr_util.h" 32 #include "base/memory/ptr_util.h"
33 #include "base/metrics/histogram_macros.h" 33 #include "base/metrics/histogram_macros.h"
34 #include "base/metrics/user_metrics.h" 34 #include "base/metrics/user_metrics.h"
35 #include "base/metrics/user_metrics_action.h" 35 #include "base/metrics/user_metrics_action.h"
36 #include "base/strings/sys_string_conversions.h" 36 #include "base/strings/sys_string_conversions.h"
37 #include "components/bookmarks/browser/base_bookmark_model_observer.h" 37 #include "components/bookmarks/browser/base_bookmark_model_observer.h"
38 #include "components/bookmarks/browser/bookmark_model.h" 38 #include "components/bookmarks/browser/bookmark_model.h"
39 #include "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h"
39 #include "components/infobars/core/infobar_manager.h" 40 #include "components/infobars/core/infobar_manager.h"
40 #include "components/prefs/pref_service.h" 41 #include "components/prefs/pref_service.h"
41 #include "components/reading_list/core/reading_list_switches.h" 42 #include "components/reading_list/core/reading_list_switches.h"
42 #include "components/reading_list/ios/reading_list_model.h" 43 #include "components/reading_list/ios/reading_list_model.h"
43 #include "components/search_engines/search_engines_pref_names.h" 44 #include "components/search_engines/search_engines_pref_names.h"
44 #include "components/search_engines/template_url_service.h" 45 #include "components/search_engines/template_url_service.h"
45 #include "components/sessions/core/tab_restore_service_helper.h" 46 #include "components/sessions/core/tab_restore_service_helper.h"
46 #include "components/strings/grit/components_strings.h" 47 #include "components/strings/grit/components_strings.h"
47 #include "components/toolbar/toolbar_model_impl.h" 48 #include "components/toolbar/toolbar_model_impl.h"
48 #include "ios/chrome/app/tests_hook.h" 49 #include "ios/chrome/app/tests_hook.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 #include "ios/public/provider/chrome/browser/ui/default_ios_web_view_factory.h" 161 #include "ios/public/provider/chrome/browser/ui/default_ios_web_view_factory.h"
161 #import "ios/public/provider/chrome/browser/voice/voice_search_bar.h" 162 #import "ios/public/provider/chrome/browser/voice/voice_search_bar.h"
162 #import "ios/public/provider/chrome/browser/voice/voice_search_bar_owner.h" 163 #import "ios/public/provider/chrome/browser/voice/voice_search_bar_owner.h"
163 #include "ios/public/provider/chrome/browser/voice/voice_search_controller.h" 164 #include "ios/public/provider/chrome/browser/voice/voice_search_controller.h"
164 #include "ios/public/provider/chrome/browser/voice/voice_search_controller_deleg ate.h" 165 #include "ios/public/provider/chrome/browser/voice/voice_search_controller_deleg ate.h"
165 #include "ios/public/provider/chrome/browser/voice/voice_search_provider.h" 166 #include "ios/public/provider/chrome/browser/voice/voice_search_provider.h"
166 #import "ios/web/navigation/crw_session_controller.h" 167 #import "ios/web/navigation/crw_session_controller.h"
167 #import "ios/web/navigation/crw_session_entry.h" 168 #import "ios/web/navigation/crw_session_entry.h"
168 #include "ios/web/navigation/navigation_manager_impl.h" 169 #include "ios/web/navigation/navigation_manager_impl.h"
169 #include "ios/web/public/active_state_manager.h" 170 #include "ios/web/public/active_state_manager.h"
170 #include "ios/web/public/image_fetcher/image_data_fetcher.h"
171 #include "ios/web/public/navigation_item.h" 171 #include "ios/web/public/navigation_item.h"
172 #import "ios/web/public/navigation_manager.h" 172 #import "ios/web/public/navigation_manager.h"
173 #include "ios/web/public/referrer_util.h" 173 #include "ios/web/public/referrer_util.h"
174 #include "ios/web/public/ssl_status.h" 174 #include "ios/web/public/ssl_status.h"
175 #include "ios/web/public/url_scheme_util.h" 175 #include "ios/web/public/url_scheme_util.h"
176 #include "ios/web/public/web_client.h" 176 #include "ios/web/public/web_client.h"
177 #import "ios/web/public/web_state/context_menu_params.h" 177 #import "ios/web/public/web_state/context_menu_params.h"
178 #import "ios/web/public/web_state/crw_web_view_proxy.h" 178 #import "ios/web/public/web_state/crw_web_view_proxy.h"
179 #import "ios/web/public/web_state/ui/crw_native_content_provider.h" 179 #import "ios/web/public/web_state/ui/crw_native_content_provider.h"
180 #include "ios/web/public/web_state/web_state.h" 180 #include "ios/web/public/web_state/web_state.h"
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 std::unique_ptr<InfoBarContainerIOS> _infoBarContainer; 438 std::unique_ptr<InfoBarContainerIOS> _infoBarContainer;
439 439
440 // Bridge class to deliver container change notifications to BVC. 440 // Bridge class to deliver container change notifications to BVC.
441 std::unique_ptr<InfoBarContainerDelegateIOS> _infoBarContainerDelegate; 441 std::unique_ptr<InfoBarContainerDelegateIOS> _infoBarContainerDelegate;
442 442
443 // Voice search bar at the bottom of the view overlayed on |_contentArea| 443 // Voice search bar at the bottom of the view overlayed on |_contentArea|
444 // when displaying voice search results. 444 // when displaying voice search results.
445 base::scoped_nsprotocol<UIView<VoiceSearchBar>*> _voiceSearchBar; 445 base::scoped_nsprotocol<UIView<VoiceSearchBar>*> _voiceSearchBar;
446 446
447 // The image fetcher used to save images and perform image-based searches. 447 // The image fetcher used to save images and perform image-based searches.
448 std::unique_ptr<web::ImageDataFetcher> _imageFetcher; 448 std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> _imageFetcher;
449 449
450 // Card side swipe view. 450 // Card side swipe view.
451 base::scoped_nsobject<CardSideSwipeView> _sideSwipeView; 451 base::scoped_nsobject<CardSideSwipeView> _sideSwipeView;
452 452
453 // Used to cache value of |hasModeToggleSwitch| if set before the tab strip 453 // Used to cache value of |hasModeToggleSwitch| if set before the tab strip
454 // controller has been created. 454 // controller has been created.
455 BOOL _modeToggleNeedsSetting; 455 BOOL _modeToggleNeedsSetting;
456 456
457 // Dominant color cache. Key: (NSString*)url, val: (UIColor*)dominantColor. 457 // Dominant color cache. Key: (NSString*)url, val: (UIColor*)dominantColor.
458 base::scoped_nsobject<NSMutableDictionary> _dominantColorCache; 458 base::scoped_nsobject<NSMutableDictionary> _dominantColorCache;
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 898
899 - (instancetype)initWithTabModel:(TabModel*)model 899 - (instancetype)initWithTabModel:(TabModel*)model
900 browserState:(ios::ChromeBrowserState*)browserState 900 browserState:(ios::ChromeBrowserState*)browserState
901 dependencyFactory: 901 dependencyFactory:
902 (BrowserViewControllerDependencyFactory*)factory { 902 (BrowserViewControllerDependencyFactory*)factory {
903 self = [super initWithNibName:nil bundle:base::mac::FrameworkBundle()]; 903 self = [super initWithNibName:nil bundle:base::mac::FrameworkBundle()];
904 if (self) { 904 if (self) {
905 DCHECK(factory); 905 DCHECK(factory);
906 _propertyReleaser_BrowserViewController.Init(self, 906 _propertyReleaser_BrowserViewController.Init(self,
907 [BrowserViewController class]); 907 [BrowserViewController class]);
908 _imageFetcher = base::MakeUnique<web::ImageDataFetcher>(
909 web::WebThread::GetBlockingPool());
910 _dependencyFactory.reset([factory retain]); 908 _dependencyFactory.reset([factory retain]);
911 _nativeControllersForTabIDs.reset( 909 _nativeControllersForTabIDs.reset(
912 [[NSMapTable strongToWeakObjectsMapTable] retain]); 910 [[NSMapTable strongToWeakObjectsMapTable] retain]);
913 _dialogPresenter.reset([[DialogPresenter alloc] initWithDelegate:self 911 _dialogPresenter.reset([[DialogPresenter alloc] initWithDelegate:self
914 presentingViewController:self]); 912 presentingViewController:self]);
915 _javaScriptDialogPresenter.reset( 913 _javaScriptDialogPresenter.reset(
916 new JavaScriptDialogPresenterImpl(_dialogPresenter)); 914 new JavaScriptDialogPresenterImpl(_dialogPresenter));
917 _webStateDelegate.reset(new web::WebStateDelegateBridge(self)); 915 _webStateDelegate.reset(new web::WebStateDelegateBridge(self));
918 // TODO(leng): Delay this. 916 // TODO(leng): Delay this.
919 [[UpgradeCenter sharedInstance] registerClient:self]; 917 [[UpgradeCenter sharedInstance] registerClient:self];
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 if (!_isOffTheRecord) { 1649 if (!_isOffTheRecord) {
1652 [DefaultIOSWebViewFactory 1650 [DefaultIOSWebViewFactory
1653 registerWebViewFactory:[ChromeWebViewFactory class]]; 1651 registerWebViewFactory:[ChromeWebViewFactory class]];
1654 } 1652 }
1655 NSUInteger count = [_model count]; 1653 NSUInteger count = [_model count];
1656 for (NSUInteger index = 0; index < count; ++index) 1654 for (NSUInteger index = 0; index < count; ++index)
1657 [self installDelegatesForTab:[_model tabAtIndex:index]]; 1655 [self installDelegatesForTab:[_model tabAtIndex:index]];
1658 1656
1659 [self registerForNotifications]; 1657 [self registerForNotifications];
1660 1658
1661 _imageFetcher->SetRequestContextGetter(_browserState->GetRequestContext()); 1659 _imageFetcher = base::MakeUnique<image_fetcher::IOSImageDataFetcherWrapper>(
1660 _browserState->GetRequestContext(), web::WebThread::GetBlockingPool());
1662 _dominantColorCache.reset([[NSMutableDictionary alloc] init]); 1661 _dominantColorCache.reset([[NSMutableDictionary alloc] init]);
1663 1662
1664 // Register for bookmark changed notification (BookmarkModel may be null 1663 // Register for bookmark changed notification (BookmarkModel may be null
1665 // during testing, so explicitly support this). 1664 // during testing, so explicitly support this).
1666 _bookmarkModel = ios::BookmarkModelFactory::GetForBrowserState(_browserState); 1665 _bookmarkModel = ios::BookmarkModelFactory::GetForBrowserState(_browserState);
1667 if (_bookmarkModel) { 1666 if (_bookmarkModel) {
1668 _bookmarkModelBridge.reset(new BrowserBookmarkModelBridge(self)); 1667 _bookmarkModelBridge.reset(new BrowserBookmarkModelBridge(self));
1669 _bookmarkModel->AddObserver(_bookmarkModelBridge.get()); 1668 _bookmarkModel->AddObserver(_bookmarkModelBridge.get());
1670 } 1669 }
1671 } 1670 }
(...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after
3047 } 3046 }
3048 } 3047 }
3049 } 3048 }
3050 3049
3051 #pragma mark - Context menu methods 3050 #pragma mark - Context menu methods
3052 3051
3053 - (void)searchByImageAtURL:(const GURL&)url 3052 - (void)searchByImageAtURL:(const GURL&)url
3054 referrer:(const web::Referrer)referrer { 3053 referrer:(const web::Referrer)referrer {
3055 DCHECK(url.is_valid()); 3054 DCHECK(url.is_valid());
3056 base::WeakNSObject<BrowserViewController> weakSelf(self); 3055 base::WeakNSObject<BrowserViewController> weakSelf(self);
3057 web::ImageFetchedCallback callback = 3056 const GURL image_source_url = url;
3058 ^(const GURL& original_url, int response_code, NSData* data) { 3057 image_fetcher::IOSImageDataFetcherCallback callback = ^(NSData* data) {
3059 GURL originalURL(original_url.spec()); 3058 DCHECK(data);
3060 DCHECK(data); 3059 dispatch_async(dispatch_get_main_queue(), ^{
3061 dispatch_async(dispatch_get_main_queue(), ^{ 3060 [weakSelf searchByImageData:data atURL:image_source_url];
3062 [weakSelf searchByImageData:data atURL:originalURL]; 3061 });
3063 }); 3062 };
3064 }; 3063 _imageFetcher->FetchImageDataWebpDecoded(
3065 _imageFetcher->StartDownload(
3066 url, callback, web::ReferrerHeaderValueForNavigation(url, referrer), 3064 url, callback, web::ReferrerHeaderValueForNavigation(url, referrer),
3067 web::PolicyForNavigation(url, referrer)); 3065 web::PolicyForNavigation(url, referrer));
3068 } 3066 }
3069 3067
3070 - (void)searchByImageData:(NSData*)data atURL:(const GURL&)imageURL { 3068 - (void)searchByImageData:(NSData*)data atURL:(const GURL&)imageURL {
3071 NSData* imageData = data; 3069 NSData* imageData = data;
3072 UIImage* image = [UIImage imageWithData:imageData]; 3070 UIImage* image = [UIImage imageWithData:imageData];
3073 // Downsize the image if its area exceeds kSearchByImageMaxImageArea AND 3071 // Downsize the image if its area exceeds kSearchByImageMaxImageArea AND
3074 // (either its width exceeds kSearchByImageMaxImageWidth OR its height exceeds 3072 // (either its width exceeds kSearchByImageMaxImageWidth OR its height exceeds
3075 // kSearchByImageMaxImageHeight). 3073 // kSearchByImageMaxImageHeight).
(...skipping 29 matching lines...) Expand all
3105 search_args, templateUrlService->search_terms_data(), &post_content)); 3103 search_args, templateUrlService->search_terms_data(), &post_content));
3106 [self addSelectedTabWithURL:result 3104 [self addSelectedTabWithURL:result
3107 postData:&post_content 3105 postData:&post_content
3108 transition:ui::PAGE_TRANSITION_TYPED]; 3106 transition:ui::PAGE_TRANSITION_TYPED];
3109 } 3107 }
3110 3108
3111 - (void)saveImageAtURL:(const GURL&)url 3109 - (void)saveImageAtURL:(const GURL&)url
3112 referrer:(const web::Referrer&)referrer { 3110 referrer:(const web::Referrer&)referrer {
3113 DCHECK(url.is_valid()); 3111 DCHECK(url.is_valid());
3114 3112
3115 web::ImageFetchedCallback callback = 3113 image_fetcher::IOSImageDataFetcherCallback callback = ^(NSData* data) {
3116 ^(const GURL& original_url, int response_code, NSData* data) { 3114 DCHECK(data);
3117 DCHECK(data);
3118 3115
3119 [self managePermissionAndSaveImage:data]; 3116 [self managePermissionAndSaveImage:data];
3120 }; 3117 };
3121 _imageFetcher->StartDownload( 3118 _imageFetcher->FetchImageDataWebpDecoded(
3122 url, callback, web::ReferrerHeaderValueForNavigation(url, referrer), 3119 url, callback, web::ReferrerHeaderValueForNavigation(url, referrer),
3123 web::PolicyForNavigation(url, referrer)); 3120 web::PolicyForNavigation(url, referrer));
3124 } 3121 }
3125 3122
3126 - (void)managePermissionAndSaveImage:(NSData*)data { 3123 - (void)managePermissionAndSaveImage:(NSData*)data {
3127 switch ([PHPhotoLibrary authorizationStatus]) { 3124 switch ([PHPhotoLibrary authorizationStatus]) {
3128 // User was never asked for permission to access photos. 3125 // User was never asked for permission to access photos.
3129 case PHAuthorizationStatusNotDetermined: 3126 case PHAuthorizationStatusNotDetermined:
3130 [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { 3127 [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
3131 // Call -saveImage again to check if chrome needs to display an error or 3128 // Call -saveImage again to check if chrome needs to display an error or
(...skipping 2037 matching lines...) Expand 10 before | Expand all | Expand 10 after
5169 5166
5170 - (UIView*)voiceSearchButton { 5167 - (UIView*)voiceSearchButton {
5171 return _voiceSearchButton; 5168 return _voiceSearchButton;
5172 } 5169 }
5173 5170
5174 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { 5171 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner {
5175 return [self currentLogoAnimationControllerOwner]; 5172 return [self currentLogoAnimationControllerOwner];
5176 } 5173 }
5177 5174
5178 @end 5175 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698