Index: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm |
diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm |
index deb9b2d6ef362d65c0bd8b97d6b8273cd378325a..1148855f9b885ce2c3232a93bd87fc696baf66ce 100644 |
--- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm |
+++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm |
@@ -96,6 +96,13 @@ BOOL ThePasteboardIsTooDamnBig() { |
[self delete:nil]; |
} |
+- (void)copyURL:(id)sender { |
+ AutocompleteTextFieldObserver* observer = [self observer]; |
+ DCHECK(observer); |
+ if (observer->CanCopy()) |
+ observer->CopyURLToPasteboard([NSPasteboard generalPasteboard]); |
+} |
+ |
// This class assumes that the delegate is an AutocompleteTextField. |
// Enforce that assumption. |
- (AutocompleteTextField*)delegate { |
@@ -208,6 +215,16 @@ BOOL ThePasteboardIsTooDamnBig() { |
[menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_COPY) |
action:@selector(copy:) |
keyEquivalent:@""]; |
+ |
+ if ([self isEditable]) { |
+ // Copy URL if the URL has been replaced by the Extended Instant API. |
+ DCHECK([self observer]); |
+ NSString* label = l10n_util::GetNSStringWithFixup(IDS_COPY_URL_MAC); |
+ [menu addItemWithTitle:label |
+ action:@selector(copyURL:) |
+ keyEquivalent:@""]; |
+ } |
+ |
[menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_PASTE) |
action:@selector(paste:) |
keyEquivalent:@""]; |
@@ -218,28 +235,21 @@ BOOL ThePasteboardIsTooDamnBig() { |
// Paste and go/search. |
AutocompleteTextFieldObserver* observer = [self observer]; |
DCHECK(observer); |
- if (observer && observer->CanPasteAndGo()) { |
- const int string_id = observer->GetPasteActionStringId(); |
- NSString* label = l10n_util::GetNSStringWithFixup(string_id); |
- |
- // TODO(rohitrao): If the clipboard is empty, should we show a |
- // greyed-out "Paste and Go" or nothing at all? |
- if ([label length]) { |
- [menu addItemWithTitle:label |
- action:@selector(pasteAndGo:) |
- keyEquivalent:@""]; |
- } |
- } |
- |
- NSString* label = l10n_util::GetNSStringWithFixup(IDS_EDIT_SEARCH_ENGINES); |
+ const int string_id = observer->GetPasteActionStringId(); |
+ NSString* label = l10n_util::GetNSStringWithFixup(string_id); |
DCHECK([label length]); |
- if ([label length]) { |
- [menu addItem:[NSMenuItem separatorItem]]; |
- NSMenuItem* item = [menu addItemWithTitle:label |
- action:@selector(commandDispatch:) |
- keyEquivalent:@""]; |
- [item setTag:IDC_EDIT_SEARCH_ENGINES]; |
- } |
+ [menu addItemWithTitle:label |
+ action:@selector(pasteAndGo:) |
+ keyEquivalent:@""]; |
+ |
+ NSString* search_engine_label = |
+ l10n_util::GetNSStringWithFixup(IDS_EDIT_SEARCH_ENGINES); |
+ DCHECK([search_engine_label length]); |
+ [menu addItem:[NSMenuItem separatorItem]]; |
+ NSMenuItem* item = [menu addItemWithTitle:search_engine_label |
+ action:@selector(commandDispatch:) |
+ keyEquivalent:@""]; |
+ [item setTag:IDC_EDIT_SEARCH_ENGINES]; |
} |
return menu; |
@@ -471,6 +481,18 @@ BOOL ThePasteboardIsTooDamnBig() { |
- (BOOL)validateMenuItem:(NSMenuItem*)item { |
if ([item action] == @selector(copyToFindPboard:)) |
return [self selectedRange].length > 0; |
+ if ([item action] == @selector(pasteAndGo:)) { |
+ // TODO(rohitrao): If the clipboard is empty, should we show a |
+ // greyed-out "Paste and Go" or nothing at all? |
+ AutocompleteTextFieldObserver* observer = [self observer]; |
+ DCHECK(observer); |
+ return observer->CanPasteAndGo(); |
+ } |
+ if ([item action] == @selector(copyURL:)) { |
+ AutocompleteTextFieldObserver* observer = [self observer]; |
+ DCHECK(observer); |
+ return observer->ShouldEnableCopyURL(); |
+ } |
return [super validateMenuItem:item]; |
} |