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" | 11 #import "base/ios/weak_nsobject.h" |
| 12 #include "base/mac/foundation_util.h" | 12 #include "base/mac/foundation_util.h" |
| 13 #import "base/mac/objc_property_releaser.h" | 13 #import "base/mac/objc_property_releaser.h" |
| 14 #include "base/mac/scoped_nsobject.h" | 14 #include "base/mac/scoped_nsobject.h" |
| 15 #include "base/metrics/user_metrics.h" | |
| 16 #include "base/metrics/user_metrics_action.h" | |
| 15 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 17 #include "components/browsing_data/core/history_notice_utils.h" | 19 #include "components/browsing_data/core/history_notice_utils.h" |
| 18 #include "components/strings/grit/components_strings.h" | 20 #include "components/strings/grit/components_strings.h" |
| 19 #include "components/url_formatter/url_formatter.h" | 21 #include "components/url_formatter/url_formatter.h" |
| 20 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 22 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 21 #include "ios/chrome/browser/chrome_url_constants.h" | 23 #include "ios/chrome/browser/chrome_url_constants.h" |
| 22 #import "ios/chrome/browser/signin/authentication_service.h" | 24 #import "ios/chrome/browser/signin/authentication_service.h" |
| 23 #include "ios/chrome/browser/signin/authentication_service_factory.h" | 25 #include "ios/chrome/browser/signin/authentication_service_factory.h" |
| 24 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" | 26 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 // displayed history entries. | 105 // displayed history entries. |
| 104 - (void)updateEntriesStatusMessage; | 106 - (void)updateEntriesStatusMessage; |
| 105 // Removes selected items from the visible collection, but does not delete them | 107 // Removes selected items from the visible collection, but does not delete them |
| 106 // from browser history. | 108 // from browser history. |
| 107 - (void)removeSelectedItemsFromCollection; | 109 - (void)removeSelectedItemsFromCollection; |
| 108 // Removes all items in the collection that are not included in entries. | 110 // Removes all items in the collection that are not included in entries. |
| 109 - (void)filterForHistoryEntries:(NSArray*)entries; | 111 - (void)filterForHistoryEntries:(NSArray*)entries; |
| 110 // Displays context menu on cell pressed with gestureRecognizer. | 112 // Displays context menu on cell pressed with gestureRecognizer. |
| 111 - (void)displayContextMenuInvokedByGestureRecognizer: | 113 - (void)displayContextMenuInvokedByGestureRecognizer: |
| 112 (UILongPressGestureRecognizer*)gestureRecognizer; | 114 (UILongPressGestureRecognizer*)gestureRecognizer; |
| 115 // Helper method for opening URL's and recording metrics. | |
| 116 - (void)openURLWithCompletion:(ProceduralBlock)completionHandler; | |
| 113 // Opens URL in the current tab and dismisses the history view. | 117 // Opens URL in the current tab and dismisses the history view. |
| 114 - (void)openURL:(const GURL&)URL; | 118 - (void)openURL:(const GURL&)URL; |
| 115 // Opens URL in a new non-incognito tab and dismisses the history view. | 119 // Opens URL in a new non-incognito tab and dismisses the history view. |
| 116 - (void)openURLInNewTab:(const GURL&)URL; | 120 - (void)openURLInNewTab:(const GURL&)URL; |
| 117 // Opens URL in a new incognito tab and dismisses the history view. | 121 // Opens URL in a new incognito tab and dismisses the history view. |
| 118 - (void)openURLInNewIncognitoTab:(const GURL&)URL; | 122 - (void)openURLInNewIncognitoTab:(const GURL&)URL; |
| 119 // Copies URL to the clipboard. | 123 // Copies URL to the clipboard. |
| 120 - (void)copyURL:(const GURL&)URL; | 124 - (void)copyURL:(const GURL&)URL; |
| 121 @end | 125 @end |
| 122 | 126 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 138 delegate:(id<HistoryCollectionViewControllerDelegate>) | 142 delegate:(id<HistoryCollectionViewControllerDelegate>) |
| 139 delegate { | 143 delegate { |
| 140 self = [super initWithStyle:CollectionViewControllerStyleDefault]; | 144 self = [super initWithStyle:CollectionViewControllerStyleDefault]; |
| 141 if (self) { | 145 if (self) { |
| 142 _propertyReleaser_HistoryCollectionViewController.Init( | 146 _propertyReleaser_HistoryCollectionViewController.Init( |
| 143 self, [HistoryCollectionViewController class]); | 147 self, [HistoryCollectionViewController class]); |
| 144 _historyServiceFacade.reset(new HistoryServiceFacade(browserState, self)); | 148 _historyServiceFacade.reset(new HistoryServiceFacade(browserState, self)); |
| 145 _browserState = browserState; | 149 _browserState = browserState; |
| 146 _delegate.reset(delegate); | 150 _delegate.reset(delegate); |
| 147 _URLLoader.reset(loader); | 151 _URLLoader.reset(loader); |
| 152 base::RecordAction(base::UserMetricsAction("HistoryPage_EntryLinkClick")); | |
|
lpromero
2016/12/20 23:37:30
Feels weird to have it here. Idem than what Jackie
sczs
2016/12/21 04:24:26
You're right, the "Click" part of the name makes i
Jackie Quinn
2016/12/21 17:18:19
Also I think this is for when you tap on a history
sczs
2016/12/21 19:41:51
Ooooh, that makes everything different! Couldn't f
| |
| 148 [self loadModel]; | 153 [self loadModel]; |
| 149 // Add initial info section as header. | 154 // Add initial info section as header. |
| 150 [self.collectionViewModel | 155 [self.collectionViewModel |
| 151 addSectionWithIdentifier:kEntriesStatusSectionIdentifier]; | 156 addSectionWithIdentifier:kEntriesStatusSectionIdentifier]; |
| 152 _entryInserter = | 157 _entryInserter = |
| 153 [[HistoryEntryInserter alloc] initWithModel:self.collectionViewModel]; | 158 [[HistoryEntryInserter alloc] initWithModel:self.collectionViewModel]; |
| 154 _entryInserter.delegate = self; | 159 _entryInserter.delegate = self; |
| 155 _entriesType = NO_ENTRIES; | 160 _entriesType = NO_ENTRIES; |
| 156 [self showHistoryMatchingQuery:nil]; | 161 [self showHistoryMatchingQuery:nil]; |
| 157 } | 162 } |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 732 l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_COPY); | 737 l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_COPY); |
| 733 ProceduralBlock copyURLAction = ^{ | 738 ProceduralBlock copyURLAction = ^{ |
| 734 [weakSelf copyURL:entry.URL]; | 739 [weakSelf copyURL:entry.URL]; |
| 735 }; | 740 }; |
| 736 [self.contextMenuCoordinator addItemWithTitle:copyURLTitle | 741 [self.contextMenuCoordinator addItemWithTitle:copyURLTitle |
| 737 action:copyURLAction]; | 742 action:copyURLAction]; |
| 738 [self.parentViewController.view endEditing:YES]; | 743 [self.parentViewController.view endEditing:YES]; |
| 739 [self.contextMenuCoordinator start]; | 744 [self.contextMenuCoordinator start]; |
| 740 } | 745 } |
| 741 | 746 |
| 747 - (void)openURLWithCompletion:(ProceduralBlock)completionHandler { | |
|
Jackie Quinn
2016/12/20 23:15:54
Shouldn't this be closeHistoryWithCompletion?
sczs
2016/12/21 04:24:26
You're right I think it would be clearer.
| |
| 748 if ([self.currentQuery length]) { | |
|
lpromero
2016/12/20 23:37:30
Is this always cleared when exiting search? Feels
sczs
2016/12/21 04:24:26
Yes it should (from what I've seen) It was the bes
Jackie Quinn
2016/12/21 17:18:19
There's also self.isSearching.
| |
| 749 base::RecordAction( | |
| 750 base::UserMetricsAction("HistoryPage_SearchResultClick")); | |
|
Jackie Quinn
2016/12/20 23:15:54
Is this always going to be invoked from a click? I
sczs
2016/12/21 04:24:26
I was trying record this action everytime an item
Jackie Quinn
2016/12/21 17:18:19
I feel like it may be better to just have a separa
| |
| 751 } | |
| 752 [self.delegate historyCollectionViewController:self | |
| 753 shouldCloseWithCompletion:completionHandler]; | |
| 754 } | |
| 755 | |
| 742 - (void)openURL:(const GURL&)URL { | 756 - (void)openURL:(const GURL&)URL { |
| 743 GURL copiedURL(URL); | 757 GURL copiedURL(URL); |
| 744 [self.delegate historyCollectionViewController:self | 758 ProceduralBlock completionHandler = ^{ |
| 745 shouldCloseWithCompletion:^{ | 759 [self.URLLoader loadURL:copiedURL |
| 746 [self.URLLoader | 760 referrer:web::Referrer() |
| 747 loadURL:copiedURL | 761 transition:ui::PAGE_TRANSITION_AUTO_BOOKMARK |
| 748 referrer:web::Referrer() | 762 rendererInitiated:NO]; |
| 749 transition:ui::PAGE_TRANSITION_AUTO_BOOKMARK | 763 }; |
| 750 rendererInitiated:NO]; | 764 [self openURLWithCompletion:completionHandler]; |
| 751 }]; | |
| 752 } | 765 } |
| 753 | 766 |
| 754 - (void)openURLInNewTab:(const GURL&)URL { | 767 - (void)openURLInNewTab:(const GURL&)URL { |
| 755 GURL copiedURL(URL); | 768 GURL copiedURL(URL); |
| 756 [self.delegate historyCollectionViewController:self | 769 ProceduralBlock completionHandler = ^{ |
| 757 shouldCloseWithCompletion:^{ | 770 [self.URLLoader webPageOrderedOpen:copiedURL |
| 758 [self.URLLoader webPageOrderedOpen:copiedURL | 771 referrer:web::Referrer() |
| 759 referrer:web::Referrer() | 772 windowName:nil |
| 760 windowName:nil | 773 inIncognito:NO |
| 761 inIncognito:NO | 774 inBackground:NO |
| 762 inBackground:NO | 775 appendTo:kLastTab]; |
| 763 appendTo:kLastTab]; | 776 }; |
| 764 }]; | 777 [self openURLWithCompletion:completionHandler]; |
| 765 } | 778 } |
| 766 | 779 |
| 767 - (void)openURLInNewIncognitoTab:(const GURL&)URL { | 780 - (void)openURLInNewIncognitoTab:(const GURL&)URL { |
| 768 GURL copiedURL(URL); | 781 GURL copiedURL(URL); |
| 769 [self.delegate historyCollectionViewController:self | 782 ProceduralBlock completionHandler = ^{ |
| 770 shouldCloseWithCompletion:^{ | 783 [self.URLLoader webPageOrderedOpen:copiedURL |
| 771 [self.URLLoader webPageOrderedOpen:copiedURL | 784 referrer:web::Referrer() |
| 772 referrer:web::Referrer() | 785 windowName:nil |
| 773 windowName:nil | 786 inIncognito:YES |
| 774 inIncognito:YES | 787 inBackground:NO |
| 775 inBackground:NO | 788 appendTo:kLastTab]; |
| 776 appendTo:kLastTab]; | 789 }; |
| 777 }]; | 790 [self openURLWithCompletion:completionHandler]; |
| 778 } | 791 } |
| 779 | 792 |
| 780 - (void)copyURL:(const GURL&)URL { | 793 - (void)copyURL:(const GURL&)URL { |
| 781 DCHECK(URL.is_valid()); | 794 DCHECK(URL.is_valid()); |
| 782 NSData* plainText = [base::SysUTF8ToNSString(URL.spec()) | 795 NSData* plainText = [base::SysUTF8ToNSString(URL.spec()) |
| 783 dataUsingEncoding:NSUTF8StringEncoding]; | 796 dataUsingEncoding:NSUTF8StringEncoding]; |
| 784 NSDictionary* copiedItem = @{ | 797 NSDictionary* copiedItem = @{ |
| 785 (NSString*)kUTTypeURL : net::NSURLWithGURL(URL), | 798 (NSString*)kUTTypeURL : net::NSURLWithGURL(URL), |
| 786 (NSString*)kUTTypeUTF8PlainText : plainText, | 799 (NSString*)kUTTypeUTF8PlainText : plainText, |
| 787 }; | 800 }; |
| 788 [[UIPasteboard generalPasteboard] setItems:@[ copiedItem ]]; | 801 [[UIPasteboard generalPasteboard] setItems:@[ copiedItem ]]; |
| 789 } | 802 } |
| 790 | 803 |
| 791 @end | 804 @end |
| OLD | NEW |