| 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 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 29 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 30 #import "ios/chrome/browser/ui/context_menu/context_menu_coordinator.h" | 30 #import "ios/chrome/browser/ui/context_menu/context_menu_coordinator.h" |
| 31 #include "ios/chrome/browser/ui/history/history_entries_status_item.h" | 31 #include "ios/chrome/browser/ui/history/history_entries_status_item.h" |
| 32 #include "ios/chrome/browser/ui/history/history_entry.h" | 32 #include "ios/chrome/browser/ui/history/history_entry.h" |
| 33 #include "ios/chrome/browser/ui/history/history_entry_inserter.h" | 33 #include "ios/chrome/browser/ui/history/history_entry_inserter.h" |
| 34 #import "ios/chrome/browser/ui/history/history_entry_item.h" | 34 #import "ios/chrome/browser/ui/history/history_entry_item.h" |
| 35 #include "ios/chrome/browser/ui/history/history_service_facade.h" | 35 #include "ios/chrome/browser/ui/history/history_service_facade.h" |
| 36 #include "ios/chrome/browser/ui/history/history_service_facade_delegate.h" | 36 #include "ios/chrome/browser/ui/history/history_service_facade_delegate.h" |
| 37 #include "ios/chrome/browser/ui/history/history_util.h" | 37 #include "ios/chrome/browser/ui/history/history_util.h" |
| 38 #import "ios/chrome/browser/ui/url_loader.h" | 38 #import "ios/chrome/browser/ui/url_loader.h" |
| 39 #import "ios/chrome/browser/ui/util/pasteboard_util.h" |
| 39 #include "ios/chrome/grit/ios_strings.h" | 40 #include "ios/chrome/grit/ios_strings.h" |
| 40 #import "ios/third_party/material_components_ios/src/components/ActivityIndicato
r/src/MDCActivityIndicator.h" | 41 #import "ios/third_party/material_components_ios/src/components/ActivityIndicato
r/src/MDCActivityIndicator.h" |
| 41 #import "ios/third_party/material_components_ios/src/components/Collections/src/
MaterialCollections.h" | 42 #import "ios/third_party/material_components_ios/src/components/Collections/src/
MaterialCollections.h" |
| 42 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" | 43 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
| 43 #import "ios/web/public/referrer.h" | 44 #import "ios/web/public/referrer.h" |
| 44 #import "ios/web/public/web_state/context_menu_params.h" | 45 #import "ios/web/public/web_state/context_menu_params.h" |
| 45 #import "net/base/mac/url_conversions.h" | 46 #import "net/base/mac/url_conversions.h" |
| 46 #include "ui/base/l10n/l10n_util.h" | 47 #include "ui/base/l10n/l10n_util.h" |
| 47 #include "ui/base/l10n/l10n_util_mac.h" | 48 #include "ui/base/l10n/l10n_util_mac.h" |
| 48 | 49 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 - (void)addLoadingIndicator; | 121 - (void)addLoadingIndicator; |
| 121 // Displays context menu on cell pressed with gestureRecognizer. | 122 // Displays context menu on cell pressed with gestureRecognizer. |
| 122 - (void)displayContextMenuInvokedByGestureRecognizer: | 123 - (void)displayContextMenuInvokedByGestureRecognizer: |
| 123 (UILongPressGestureRecognizer*)gestureRecognizer; | 124 (UILongPressGestureRecognizer*)gestureRecognizer; |
| 124 // Opens URL in the current tab and dismisses the history view. | 125 // Opens URL in the current tab and dismisses the history view. |
| 125 - (void)openURL:(const GURL&)URL; | 126 - (void)openURL:(const GURL&)URL; |
| 126 // Opens URL in a new non-incognito tab and dismisses the history view. | 127 // Opens URL in a new non-incognito tab and dismisses the history view. |
| 127 - (void)openURLInNewTab:(const GURL&)URL; | 128 - (void)openURLInNewTab:(const GURL&)URL; |
| 128 // Opens URL in a new incognito tab and dismisses the history view. | 129 // Opens URL in a new incognito tab and dismisses the history view. |
| 129 - (void)openURLInNewIncognitoTab:(const GURL&)URL; | 130 - (void)openURLInNewIncognitoTab:(const GURL&)URL; |
| 130 // Copies URL to the clipboard. | |
| 131 - (void)copyURL:(const GURL&)URL; | |
| 132 @end | 131 @end |
| 133 | 132 |
| 134 @implementation HistoryCollectionViewController | 133 @implementation HistoryCollectionViewController |
| 135 | 134 |
| 136 @synthesize searching = _searching; | 135 @synthesize searching = _searching; |
| 137 @synthesize entryInserter = _entryInserter; | 136 @synthesize entryInserter = _entryInserter; |
| 138 @synthesize currentQuery = _currentQuery; | 137 @synthesize currentQuery = _currentQuery; |
| 139 @synthesize contextMenuCoordinator = _contextMenuCoordinator; | 138 @synthesize contextMenuCoordinator = _contextMenuCoordinator; |
| 140 @synthesize entriesType = _entriesType; | 139 @synthesize entriesType = _entriesType; |
| 141 @synthesize shouldShowNoticeAboutOtherFormsOfBrowsingHistory = | 140 @synthesize shouldShowNoticeAboutOtherFormsOfBrowsingHistory = |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 inSectionWithIdentifier:sectionIdentifier]; | 284 inSectionWithIdentifier:sectionIdentifier]; |
| 286 [self.collectionView | 285 [self.collectionView |
| 287 selectItemAtIndexPath:indexPath | 286 selectItemAtIndexPath:indexPath |
| 288 animated:NO | 287 animated:NO |
| 289 scrollPosition:UICollectionViewScrollPositionNone]; | 288 scrollPosition:UICollectionViewScrollPositionNone]; |
| 290 [self deleteSelectedItemsFromHistory]; | 289 [self deleteSelectedItemsFromHistory]; |
| 291 } | 290 } |
| 292 } | 291 } |
| 293 | 292 |
| 294 - (void)historyEntryItemDidRequestCopy:(HistoryEntryItem*)item { | 293 - (void)historyEntryItemDidRequestCopy:(HistoryEntryItem*)item { |
| 295 [self copyURL:item.URL]; | 294 StoreURLInPasteboard(item.URL); |
| 296 } | 295 } |
| 297 | 296 |
| 298 - (void)historyEntryItemDidRequestOpenInNewTab:(HistoryEntryItem*)item { | 297 - (void)historyEntryItemDidRequestOpenInNewTab:(HistoryEntryItem*)item { |
| 299 [self openURLInNewTab:item.URL]; | 298 [self openURLInNewTab:item.URL]; |
| 300 } | 299 } |
| 301 | 300 |
| 302 - (void)historyEntryItemDidRequestOpenInNewIncognitoTab: | 301 - (void)historyEntryItemDidRequestOpenInNewIncognitoTab: |
| 303 (HistoryEntryItem*)item { | 302 (HistoryEntryItem*)item { |
| 304 [self openURLInNewIncognitoTab:item.URL]; | 303 [self openURLInNewIncognitoTab:item.URL]; |
| 305 } | 304 } |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 ProceduralBlock openInNewIncognitoTabAction = ^{ | 751 ProceduralBlock openInNewIncognitoTabAction = ^{ |
| 753 [weakSelf openURLInNewIncognitoTab:entry.URL]; | 752 [weakSelf openURLInNewIncognitoTab:entry.URL]; |
| 754 }; | 753 }; |
| 755 [self.contextMenuCoordinator addItemWithTitle:openInNewIncognitoTabTitle | 754 [self.contextMenuCoordinator addItemWithTitle:openInNewIncognitoTabTitle |
| 756 action:openInNewIncognitoTabAction]; | 755 action:openInNewIncognitoTabAction]; |
| 757 | 756 |
| 758 // Add "Copy URL" option. | 757 // Add "Copy URL" option. |
| 759 NSString* copyURLTitle = | 758 NSString* copyURLTitle = |
| 760 l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_COPY); | 759 l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_COPY); |
| 761 ProceduralBlock copyURLAction = ^{ | 760 ProceduralBlock copyURLAction = ^{ |
| 762 [weakSelf copyURL:entry.URL]; | 761 StoreURLInPasteboard(entry.URL); |
| 763 }; | 762 }; |
| 764 [self.contextMenuCoordinator addItemWithTitle:copyURLTitle | 763 [self.contextMenuCoordinator addItemWithTitle:copyURLTitle |
| 765 action:copyURLAction]; | 764 action:copyURLAction]; |
| 766 [self.parentViewController.view endEditing:YES]; | 765 [self.parentViewController.view endEditing:YES]; |
| 767 [self.contextMenuCoordinator start]; | 766 [self.contextMenuCoordinator start]; |
| 768 } | 767 } |
| 769 | 768 |
| 770 - (void)openURL:(const GURL&)URL { | 769 - (void)openURL:(const GURL&)URL { |
| 771 GURL copiedURL(URL); | 770 GURL copiedURL(URL); |
| 772 [self.delegate historyCollectionViewController:self | 771 [self.delegate historyCollectionViewController:self |
| (...skipping 25 matching lines...) Expand all Loading... |
| 798 shouldCloseWithCompletion:^{ | 797 shouldCloseWithCompletion:^{ |
| 799 [self.URLLoader webPageOrderedOpen:copiedURL | 798 [self.URLLoader webPageOrderedOpen:copiedURL |
| 800 referrer:web::Referrer() | 799 referrer:web::Referrer() |
| 801 windowName:nil | 800 windowName:nil |
| 802 inIncognito:YES | 801 inIncognito:YES |
| 803 inBackground:NO | 802 inBackground:NO |
| 804 appendTo:kLastTab]; | 803 appendTo:kLastTab]; |
| 805 }]; | 804 }]; |
| 806 } | 805 } |
| 807 | 806 |
| 808 - (void)copyURL:(const GURL&)URL { | |
| 809 DCHECK(URL.is_valid()); | |
| 810 NSData* plainText = [base::SysUTF8ToNSString(URL.spec()) | |
| 811 dataUsingEncoding:NSUTF8StringEncoding]; | |
| 812 NSDictionary* copiedItem = @{ | |
| 813 (NSString*)kUTTypeURL : net::NSURLWithGURL(URL), | |
| 814 (NSString*)kUTTypeUTF8PlainText : plainText, | |
| 815 }; | |
| 816 [[UIPasteboard generalPasteboard] setItems:@[ copiedItem ]]; | |
| 817 } | |
| 818 | |
| 819 @end | 807 @end |
| OLD | NEW |