Chromium Code Reviews| 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 #include "ios/chrome/browser/ui/history/history_collection_view_controller.h" | 5 #include "ios/chrome/browser/ui/history/history_collection_view_controller.h" |
| 6 | 6 |
| 7 #import <MobileCoreServices/MobileCoreServices.h> | 7 #import <MobileCoreServices/MobileCoreServices.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #import "base/ios/weak_nsobject.h" | |
| 12 #include "base/mac/foundation_util.h" | 11 #include "base/mac/foundation_util.h" |
| 13 #import "base/mac/objc_property_releaser.h" | |
| 14 #include "base/mac/scoped_nsobject.h" | |
| 15 #include "base/metrics/user_metrics.h" | 12 #include "base/metrics/user_metrics.h" |
| 16 #include "base/metrics/user_metrics_action.h" | 13 #include "base/metrics/user_metrics_action.h" |
| 17 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 19 #include "components/browsing_data/core/history_notice_utils.h" | 16 #include "components/browsing_data/core/history_notice_utils.h" |
| 20 #include "components/strings/grit/components_strings.h" | 17 #include "components/strings/grit/components_strings.h" |
| 21 #include "components/url_formatter/url_formatter.h" | 18 #include "components/url_formatter/url_formatter.h" |
| 22 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 19 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 23 #include "ios/chrome/browser/chrome_url_constants.h" | 20 #include "ios/chrome/browser/chrome_url_constants.h" |
| 24 #import "ios/chrome/browser/signin/authentication_service.h" | 21 #import "ios/chrome/browser/signin/authentication_service.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 35 #include "ios/chrome/browser/ui/history/history_entry.h" | 32 #include "ios/chrome/browser/ui/history/history_entry.h" |
| 36 #include "ios/chrome/browser/ui/history/history_entry_inserter.h" | 33 #include "ios/chrome/browser/ui/history/history_entry_inserter.h" |
| 37 #import "ios/chrome/browser/ui/history/history_entry_item.h" | 34 #import "ios/chrome/browser/ui/history/history_entry_item.h" |
| 38 #include "ios/chrome/browser/ui/history/history_service_facade.h" | 35 #include "ios/chrome/browser/ui/history/history_service_facade.h" |
| 39 #include "ios/chrome/browser/ui/history/history_service_facade_delegate.h" | 36 #include "ios/chrome/browser/ui/history/history_service_facade_delegate.h" |
| 40 #include "ios/chrome/browser/ui/history/history_util.h" | 37 #include "ios/chrome/browser/ui/history/history_util.h" |
| 41 #import "ios/chrome/browser/ui/url_loader.h" | 38 #import "ios/chrome/browser/ui/url_loader.h" |
| 42 #include "ios/chrome/grit/ios_strings.h" | 39 #include "ios/chrome/grit/ios_strings.h" |
| 43 #import "ios/third_party/material_components_ios/src/components/Collections/src/ MaterialCollections.h" | 40 #import "ios/third_party/material_components_ios/src/components/Collections/src/ MaterialCollections.h" |
| 44 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" | 41 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" |
| 42 #import "ios/third_party/material_components_ios/src/components/ActivityIndicato r/src/MDCActivityIndicator.h" | |
|
lpromero
2017/01/11 18:03:51
Sort
stkhapugin
2017/01/12 14:15:43
Done.
| |
| 45 #import "ios/web/public/referrer.h" | 43 #import "ios/web/public/referrer.h" |
| 46 #import "ios/web/public/web_state/context_menu_params.h" | 44 #import "ios/web/public/web_state/context_menu_params.h" |
| 47 #import "net/base/mac/url_conversions.h" | 45 #import "net/base/mac/url_conversions.h" |
| 48 #include "ui/base/l10n/l10n_util.h" | 46 #include "ui/base/l10n/l10n_util.h" |
| 49 #include "ui/base/l10n/l10n_util_mac.h" | 47 #include "ui/base/l10n/l10n_util_mac.h" |
| 50 | 48 |
| 49 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 50 #error "This file requires ARC support." | |
| 51 #endif | |
| 52 | |
| 51 namespace { | 53 namespace { |
| 52 typedef NS_ENUM(NSInteger, ItemType) { | 54 typedef NS_ENUM(NSInteger, ItemType) { |
| 53 ItemTypeHistoryEntry = kItemTypeEnumZero, | 55 ItemTypeHistoryEntry = kItemTypeEnumZero, |
| 54 ItemTypeEntriesStatus, | 56 ItemTypeEntriesStatus, |
| 55 ItemTypeActivityIndicator, | 57 ItemTypeActivityIndicator, |
| 56 }; | 58 }; |
| 57 // Section identifier for the header (sync information) section. | 59 // Section identifier for the header (sync information) section. |
| 58 const NSInteger kEntriesStatusSectionIdentifier = kSectionIdentifierEnumZero; | 60 const NSInteger kEntriesStatusSectionIdentifier = kSectionIdentifierEnumZero; |
| 59 // Maximum number of entries to retrieve in a single query to history service. | 61 // Maximum number of entries to retrieve in a single query to history service. |
| 60 const int kMaxFetchCount = 100; | 62 const int kMaxFetchCount = 100; |
| 61 // Horizontal inset for item separators. | 63 // Horizontal inset for item separators. |
| 62 const CGFloat kSeparatorInset = 10; | 64 const CGFloat kSeparatorInset = 10; |
| 63 } | 65 } |
| 64 | 66 |
| 65 @interface HistoryCollectionViewController ()<HistoryEntriesStatusItemDelegate, | 67 @interface HistoryCollectionViewController ()<HistoryEntriesStatusItemDelegate, |
| 66 HistoryEntryInserterDelegate, | 68 HistoryEntryInserterDelegate, |
| 67 HistoryEntryItemDelegate, | 69 HistoryEntryItemDelegate, |
| 68 HistoryServiceFacadeDelegate> { | 70 HistoryServiceFacadeDelegate> { |
| 69 base::mac::ObjCPropertyReleaser | |
| 70 _propertyReleaser_HistoryCollectionViewController; | |
| 71 // Facade for communicating with HistoryService and WebHistoryService. | 71 // Facade for communicating with HistoryService and WebHistoryService. |
| 72 std::unique_ptr<HistoryServiceFacade> _historyServiceFacade; | 72 std::unique_ptr<HistoryServiceFacade> _historyServiceFacade; |
| 73 // The main browser state. Not owned by HistoryCollectionViewController. | 73 // The main browser state. Not owned by HistoryCollectionViewController. |
| 74 ios::ChromeBrowserState* _browserState; | 74 ios::ChromeBrowserState* _browserState; |
| 75 // Backing ivar for delegate property. | 75 // Backing ivar for delegate property. |
| 76 base::WeakNSProtocol<id<HistoryCollectionViewControllerDelegate>> _delegate; | 76 __weak id<HistoryCollectionViewControllerDelegate> _delegate; |
| 77 // Backing ivar for URLLoader property. | 77 // Backing ivar for URLLoader property. |
| 78 base::WeakNSProtocol<id<UrlLoader>> _URLLoader; | 78 __weak id<UrlLoader> _URLLoader; |
| 79 } | 79 } |
| 80 | 80 |
| 81 // Object to manage insertion of history entries into the collection view model. | 81 // Object to manage insertion of history entries into the collection view model. |
| 82 @property(nonatomic, retain) HistoryEntryInserter* entryInserter; | 82 @property(nonatomic, strong) HistoryEntryInserter* entryInserter; |
| 83 // Delegate for the history collection view. | 83 // Delegate for the history collection view. |
| 84 @property(nonatomic, assign, readonly) | 84 @property(nonatomic, weak, readonly) id<HistoryCollectionViewControllerDelegate> |
| 85 id<HistoryCollectionViewControllerDelegate> | 85 delegate; |
| 86 delegate; | |
| 87 // UrlLoader for navigating to history entries. | 86 // UrlLoader for navigating to history entries. |
| 88 @property(nonatomic, assign, readonly) id<UrlLoader> URLLoader; | 87 @property(nonatomic, weak, readonly) id<UrlLoader> URLLoader; |
| 89 // The current query for visible history entries. | 88 // The current query for visible history entries. |
| 90 @property(nonatomic, copy) NSString* currentQuery; | 89 @property(nonatomic, copy) NSString* currentQuery; |
| 91 // Coordinator for displaying context menus for history entries. | 90 // Coordinator for displaying context menus for history entries. |
| 92 @property(nonatomic, assign) ContextMenuCoordinator* contextMenuCoordinator; | 91 @property(nonatomic, strong) ContextMenuCoordinator* contextMenuCoordinator; |
|
lpromero
2017/01/11 18:03:51
assign to strong?
stkhapugin
2017/01/12 14:15:44
Seems to be the intended use. Nothing retains cont
| |
| 93 // Type of displayed history entries. Entries can be synced or local, or there | 92 // Type of displayed history entries. Entries can be synced or local, or there |
| 94 // may be no history entries. | 93 // may be no history entries. |
| 95 @property(nonatomic, assign) HistoryEntriesStatus entriesType; | 94 @property(nonatomic, assign) HistoryEntriesStatus entriesType; |
| 96 // YES if the history panel should show a notice about additional forms of | 95 // YES if the history panel should show a notice about additional forms of |
| 97 // browsing history. | 96 // browsing history. |
| 98 @property(nonatomic, assign) | 97 @property(nonatomic, assign) |
| 99 BOOL shouldShowNoticeAboutOtherFormsOfBrowsingHistory; | 98 BOOL shouldShowNoticeAboutOtherFormsOfBrowsingHistory; |
| 100 // YES if there is an outstanding history query. | 99 // YES if there is an outstanding history query. |
| 101 @property(nonatomic, assign, getter=isLoading) BOOL loading; | 100 @property(nonatomic, assign, getter=isLoading) BOOL loading; |
| 102 // YES if there are no more history entries to load. | 101 // YES if there are no more history entries to load. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 @synthesize loading = _loading; | 143 @synthesize loading = _loading; |
| 145 @synthesize finishedLoading = _finishedLoading; | 144 @synthesize finishedLoading = _finishedLoading; |
| 146 @synthesize filterQueryResult = _filterQueryResult; | 145 @synthesize filterQueryResult = _filterQueryResult; |
| 147 | 146 |
| 148 - (instancetype)initWithLoader:(id<UrlLoader>)loader | 147 - (instancetype)initWithLoader:(id<UrlLoader>)loader |
| 149 browserState:(ios::ChromeBrowserState*)browserState | 148 browserState:(ios::ChromeBrowserState*)browserState |
| 150 delegate:(id<HistoryCollectionViewControllerDelegate>) | 149 delegate:(id<HistoryCollectionViewControllerDelegate>) |
| 151 delegate { | 150 delegate { |
| 152 self = [super initWithStyle:CollectionViewControllerStyleDefault]; | 151 self = [super initWithStyle:CollectionViewControllerStyleDefault]; |
| 153 if (self) { | 152 if (self) { |
| 154 _propertyReleaser_HistoryCollectionViewController.Init( | |
| 155 self, [HistoryCollectionViewController class]); | |
| 156 _historyServiceFacade.reset(new HistoryServiceFacade(browserState, self)); | 153 _historyServiceFacade.reset(new HistoryServiceFacade(browserState, self)); |
| 157 _browserState = browserState; | 154 _browserState = browserState; |
| 158 _delegate.reset(delegate); | 155 _delegate = delegate; |
| 159 _URLLoader.reset(loader); | 156 _URLLoader = loader; |
| 160 [self loadModel]; | 157 [self loadModel]; |
| 161 // Add initial info section as header. | 158 // Add initial info section as header. |
| 162 [self.collectionViewModel | 159 [self.collectionViewModel |
| 163 addSectionWithIdentifier:kEntriesStatusSectionIdentifier]; | 160 addSectionWithIdentifier:kEntriesStatusSectionIdentifier]; |
| 164 _entryInserter = | 161 _entryInserter = |
| 165 [[HistoryEntryInserter alloc] initWithModel:self.collectionViewModel]; | 162 [[HistoryEntryInserter alloc] initWithModel:self.collectionViewModel]; |
| 166 _entryInserter.delegate = self; | 163 _entryInserter.delegate = self; |
| 167 _entriesType = NO_ENTRIES; | 164 _entriesType = NO_ENTRIES; |
| 168 [self showHistoryMatchingQuery:nil]; | 165 [self showHistoryMatchingQuery:nil]; |
| 169 } | 166 } |
| 170 return self; | 167 return self; |
| 171 } | 168 } |
| 172 | 169 |
| 173 - (void)viewDidLoad { | 170 - (void)viewDidLoad { |
| 174 [super viewDidLoad]; | 171 [super viewDidLoad]; |
| 175 self.styler.cellLayoutType = MDCCollectionViewCellLayoutTypeList; | 172 self.styler.cellLayoutType = MDCCollectionViewCellLayoutTypeList; |
| 176 self.styler.separatorInset = | 173 self.styler.separatorInset = |
| 177 UIEdgeInsetsMake(0, kSeparatorInset, 0, kSeparatorInset); | 174 UIEdgeInsetsMake(0, kSeparatorInset, 0, kSeparatorInset); |
| 178 self.styler.allowsItemInlay = NO; | 175 self.styler.allowsItemInlay = NO; |
| 179 | 176 |
| 180 self.clearsSelectionOnViewWillAppear = NO; | 177 self.clearsSelectionOnViewWillAppear = NO; |
| 181 self.collectionView.keyboardDismissMode = | 178 self.collectionView.keyboardDismissMode = |
| 182 UIScrollViewKeyboardDismissModeOnDrag; | 179 UIScrollViewKeyboardDismissModeOnDrag; |
| 183 | 180 |
| 184 base::scoped_nsobject<UILongPressGestureRecognizer> longPressRecognizer([ | 181 UILongPressGestureRecognizer* longPressRecognizer = [ |
|
lpromero
2017/01/11 18:03:51
Are there other usage of scoped_nsobject in this f
stkhapugin
2017/01/12 14:15:43
The import is already removed.
| |
| 185 [UILongPressGestureRecognizer alloc] | 182 [UILongPressGestureRecognizer alloc] |
| 186 initWithTarget:self | 183 initWithTarget:self |
| 187 action:@selector(displayContextMenuInvokedByGestureRecognizer:)]); | 184 action:@selector(displayContextMenuInvokedByGestureRecognizer:)]; |
| 188 [self.collectionView addGestureRecognizer:longPressRecognizer]; | 185 [self.collectionView addGestureRecognizer:longPressRecognizer]; |
| 189 } | 186 } |
| 190 | 187 |
| 191 - (BOOL)isEditing { | 188 - (BOOL)isEditing { |
| 192 return self.editor.isEditing; | 189 return self.editor.isEditing; |
| 193 } | 190 } |
| 194 | 191 |
| 195 - (void)setEditing:(BOOL)editing { | 192 - (void)setEditing:(BOOL)editing { |
| 196 [self.editor setEditing:editing animated:YES]; | 193 [self.editor setEditing:editing animated:YES]; |
| 197 } | 194 } |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 self.finishedLoading = result.has_synced_results | 347 self.finishedLoading = result.has_synced_results |
| 351 ? result.finished && result.sync_finished | 348 ? result.finished && result.sync_finished |
| 352 : result.finished; | 349 : result.finished; |
| 353 self.entriesType = result.has_synced_results ? SYNCED_ENTRIES : LOCAL_ENTRIES; | 350 self.entriesType = result.has_synced_results ? SYNCED_ENTRIES : LOCAL_ENTRIES; |
| 354 std::vector<history::HistoryEntry> entries = result.entries; | 351 std::vector<history::HistoryEntry> entries = result.entries; |
| 355 | 352 |
| 356 // Header section should be updated outside of batch updates, otherwise | 353 // Header section should be updated outside of batch updates, otherwise |
| 357 // loading indicator removal will not be observed. | 354 // loading indicator removal will not be observed. |
| 358 [self updateEntriesStatusMessage]; | 355 [self updateEntriesStatusMessage]; |
| 359 | 356 |
| 360 __block base::scoped_nsobject<NSMutableArray> filterResults( | 357 __block NSMutableArray* filterResults = [NSMutableArray array]; |
| 361 [[NSMutableArray array] retain]); | 358 __block NSString* searchQuery = [base::SysUTF16ToNSString(result.query) copy]; |
| 362 __block base::scoped_nsobject<NSString> searchQuery( | |
| 363 [base::SysUTF16ToNSString(result.query) copy]); | |
| 364 [self.collectionView performBatchUpdates:^{ | 359 [self.collectionView performBatchUpdates:^{ |
| 365 // There should always be at least a header section present. | 360 // There should always be at least a header section present. |
| 366 DCHECK([[self collectionViewModel] numberOfSections]); | 361 DCHECK([[self collectionViewModel] numberOfSections]); |
| 367 for (const history::HistoryEntry& entry : entries) { | 362 for (const history::HistoryEntry& entry : entries) { |
| 368 HistoryEntryItem* item = | 363 HistoryEntryItem* item = |
| 369 [[[HistoryEntryItem alloc] initWithType:ItemTypeHistoryEntry | 364 [[HistoryEntryItem alloc] initWithType:ItemTypeHistoryEntry |
| 370 historyEntry:entry | 365 historyEntry:entry |
| 371 browserState:_browserState | 366 browserState:_browserState |
| 372 delegate:self] autorelease]; | 367 delegate:self]; |
| 373 [self.entryInserter insertHistoryEntryItem:item]; | 368 [self.entryInserter insertHistoryEntryItem:item]; |
| 374 if ([self isSearching] || self.filterQueryResult) { | 369 if ([self isSearching] || self.filterQueryResult) { |
| 375 [filterResults addObject:item]; | 370 [filterResults addObject:item]; |
| 376 } | 371 } |
| 377 } | 372 } |
| 378 [self.delegate historyCollectionViewControllerDidChangeEntries:self]; | 373 [self.delegate historyCollectionViewControllerDidChangeEntries:self]; |
| 379 } | 374 } |
| 380 completion:^(BOOL) { | 375 completion:^(BOOL) { |
| 381 if (([self isSearching] && [searchQuery length] > 0 && | 376 if (([self isSearching] && [searchQuery length] > 0 && |
| 382 [self.currentQuery isEqualToString:searchQuery]) || | 377 [self.currentQuery isEqualToString:searchQuery]) || |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 566 query_parser::MatchingAlgorithm::ALWAYS_PREFIX_SEARCH; | 561 query_parser::MatchingAlgorithm::ALWAYS_PREFIX_SEARCH; |
| 567 _historyServiceFacade->QueryHistory(queryString, options); | 562 _historyServiceFacade->QueryHistory(queryString, options); |
| 568 // Also determine whether notice regarding other forms of browsing history | 563 // Also determine whether notice regarding other forms of browsing history |
| 569 // should be shown. | 564 // should be shown. |
| 570 _historyServiceFacade->QueryOtherFormsOfBrowsingHistory(); | 565 _historyServiceFacade->QueryOtherFormsOfBrowsingHistory(); |
| 571 } | 566 } |
| 572 | 567 |
| 573 - (void)updateEntriesStatusMessage { | 568 - (void)updateEntriesStatusMessage { |
| 574 CollectionViewItem* entriesStatusItem = nil; | 569 CollectionViewItem* entriesStatusItem = nil; |
| 575 if (!self.hasHistoryEntries) { | 570 if (!self.hasHistoryEntries) { |
| 576 CollectionViewTextItem* noResultsItem = [[[CollectionViewTextItem alloc] | 571 CollectionViewTextItem* noResultsItem = |
| 577 initWithType:ItemTypeEntriesStatus] autorelease]; | 572 [[CollectionViewTextItem alloc] initWithType:ItemTypeEntriesStatus]; |
| 578 noResultsItem.text = | 573 noResultsItem.text = |
| 579 self.isSearching ? l10n_util::GetNSString(IDS_HISTORY_NO_SEARCH_RESULTS) | 574 self.isSearching ? l10n_util::GetNSString(IDS_HISTORY_NO_SEARCH_RESULTS) |
| 580 : l10n_util::GetNSString(IDS_HISTORY_NO_RESULTS); | 575 : l10n_util::GetNSString(IDS_HISTORY_NO_RESULTS); |
| 581 entriesStatusItem = noResultsItem; | 576 entriesStatusItem = noResultsItem; |
| 582 } else { | 577 } else { |
| 583 HistoryEntriesStatusItem* historyEntriesStatusItem = | 578 HistoryEntriesStatusItem* historyEntriesStatusItem = |
| 584 [[[HistoryEntriesStatusItem alloc] initWithType:ItemTypeEntriesStatus] | 579 [[HistoryEntriesStatusItem alloc] initWithType:ItemTypeEntriesStatus]; |
| 585 autorelease]; | |
| 586 historyEntriesStatusItem.delegate = self; | 580 historyEntriesStatusItem.delegate = self; |
| 587 AuthenticationService* authService = | 581 AuthenticationService* authService = |
| 588 AuthenticationServiceFactory::GetForBrowserState(_browserState); | 582 AuthenticationServiceFactory::GetForBrowserState(_browserState); |
| 589 BOOL signedIn = authService->IsAuthenticated(); | 583 BOOL signedIn = authService->IsAuthenticated(); |
| 590 | 584 |
| 591 historyEntriesStatusItem.hidden = | 585 historyEntriesStatusItem.hidden = |
| 592 self.isSearching || (!signedIn && self.hasHistoryEntries); | 586 self.isSearching || (!signedIn && self.hasHistoryEntries); |
| 593 historyEntriesStatusItem.entriesStatus = self.entriesType; | 587 historyEntriesStatusItem.entriesStatus = self.entriesType; |
| 594 historyEntriesStatusItem.showsOtherBrowsingDataNotice = | 588 historyEntriesStatusItem.showsOtherBrowsingDataNotice = |
| 595 _shouldShowNoticeAboutOtherFormsOfBrowsingHistory; | 589 _shouldShowNoticeAboutOtherFormsOfBrowsingHistory; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 684 } | 678 } |
| 685 | 679 |
| 686 [self.collectionView performBatchUpdates:^{ | 680 [self.collectionView performBatchUpdates:^{ |
| 687 if ([self.collectionViewModel hasItemAtIndexPath:indexPath]) { | 681 if ([self.collectionViewModel hasItemAtIndexPath:indexPath]) { |
| 688 [self.collectionViewModel | 682 [self.collectionViewModel |
| 689 removeItemWithType:[self.collectionViewModel | 683 removeItemWithType:[self.collectionViewModel |
| 690 itemTypeForIndexPath:indexPath] | 684 itemTypeForIndexPath:indexPath] |
| 691 fromSectionWithIdentifier:kSectionIdentifierEnumZero]; | 685 fromSectionWithIdentifier:kSectionIdentifierEnumZero]; |
| 692 [self.collectionView deleteItemsAtIndexPaths:@[ indexPath ]]; | 686 [self.collectionView deleteItemsAtIndexPaths:@[ indexPath ]]; |
| 693 } | 687 } |
| 694 CollectionViewItem* loadingIndicatorItem = [[[CollectionViewItem alloc] | 688 CollectionViewItem* loadingIndicatorItem = |
| 695 initWithType:ItemTypeActivityIndicator] autorelease]; | 689 [[CollectionViewItem alloc] initWithType:ItemTypeActivityIndicator]; |
| 696 loadingIndicatorItem.cellClass = [ActivityIndicatorCell class]; | 690 loadingIndicatorItem.cellClass = [ActivityIndicatorCell class]; |
| 697 [self.collectionViewModel addItem:loadingIndicatorItem | 691 [self.collectionViewModel addItem:loadingIndicatorItem |
| 698 toSectionWithIdentifier:kEntriesStatusSectionIdentifier]; | 692 toSectionWithIdentifier:kEntriesStatusSectionIdentifier]; |
| 699 [self.collectionView insertItemsAtIndexPaths:@[ indexPath ]]; | 693 [self.collectionView insertItemsAtIndexPaths:@[ indexPath ]]; |
| 700 } | 694 } |
| 701 completion:nil]; | 695 completion:nil]; |
| 702 } | 696 } |
| 703 | 697 |
| 704 #pragma mark Context Menu | 698 #pragma mark Context Menu |
| 705 | 699 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 717 // If there's no index path, or the index path is for the header item, do not | 711 // If there's no index path, or the index path is for the header item, do not |
| 718 // display a contextual menu. | 712 // display a contextual menu. |
| 719 if (!touchedItemIndexPath || | 713 if (!touchedItemIndexPath || |
| 720 [touchedItemIndexPath | 714 [touchedItemIndexPath |
| 721 isEqual:[NSIndexPath indexPathForItem:0 inSection:0]]) | 715 isEqual:[NSIndexPath indexPathForItem:0 inSection:0]]) |
| 722 return; | 716 return; |
| 723 | 717 |
| 724 HistoryEntryItem* entry = base::mac::ObjCCastStrict<HistoryEntryItem>( | 718 HistoryEntryItem* entry = base::mac::ObjCCastStrict<HistoryEntryItem>( |
| 725 [self.collectionViewModel itemAtIndexPath:touchedItemIndexPath]); | 719 [self.collectionViewModel itemAtIndexPath:touchedItemIndexPath]); |
| 726 | 720 |
| 727 base::WeakNSObject<HistoryCollectionViewController> weakSelf(self); | 721 __weak HistoryCollectionViewController* weakSelf = self; |
| 728 web::ContextMenuParams params; | 722 web::ContextMenuParams params; |
| 729 params.location = touchLocation; | 723 params.location = touchLocation; |
| 730 params.view.reset([self.collectionView retain]); | 724 params.view.reset(self.collectionView); |
|
lpromero
2017/01/11 18:03:52
Is this a scoped_nsobject? ARC will do the right t
stkhapugin
2017/01/12 14:15:44
Yes and yes:
This will call reset(x) on scoped_n
| |
| 731 NSString* menuTitle = | 725 NSString* menuTitle = |
| 732 base::SysUTF16ToNSString(url_formatter::FormatUrl(entry.URL)); | 726 base::SysUTF16ToNSString(url_formatter::FormatUrl(entry.URL)); |
| 733 params.menu_title.reset([menuTitle copy]); | 727 params.menu_title.reset([menuTitle copy]); |
| 734 | 728 |
| 735 // Present sheet/popover using controller that is added to view hierarchy. | 729 // Present sheet/popover using controller that is added to view hierarchy. |
| 736 UIViewController* topController = [params.view window].rootViewController; | 730 UIViewController* topController = [params.view window].rootViewController; |
| 737 while (topController.presentedViewController) | 731 while (topController.presentedViewController) |
| 738 topController = topController.presentedViewController; | 732 topController = topController.presentedViewController; |
| 739 | 733 |
| 740 self.contextMenuCoordinator = | 734 self.contextMenuCoordinator = |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 816 NSData* plainText = [base::SysUTF8ToNSString(URL.spec()) | 810 NSData* plainText = [base::SysUTF8ToNSString(URL.spec()) |
| 817 dataUsingEncoding:NSUTF8StringEncoding]; | 811 dataUsingEncoding:NSUTF8StringEncoding]; |
| 818 NSDictionary* copiedItem = @{ | 812 NSDictionary* copiedItem = @{ |
| 819 (NSString*)kUTTypeURL : net::NSURLWithGURL(URL), | 813 (NSString*)kUTTypeURL : net::NSURLWithGURL(URL), |
| 820 (NSString*)kUTTypeUTF8PlainText : plainText, | 814 (NSString*)kUTTypeUTF8PlainText : plainText, |
| 821 }; | 815 }; |
| 822 [[UIPasteboard generalPasteboard] setItems:@[ copiedItem ]]; | 816 [[UIPasteboard generalPasteboard] setItems:@[ copiedItem ]]; |
| 823 } | 817 } |
| 824 | 818 |
| 825 @end | 819 @end |
| OLD | NEW |