Index: chrome/browser/ui/views/omnibox/omnibox_view_views.cc |
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc |
index ff24a09ed7eec466afcdd84403f7631ba5b4d14c..0caa36c3a6cb67bf2f331aa47eda932c8ea98dca 100644 |
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc |
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc |
@@ -208,6 +208,23 @@ int GetEditFontPixelSize(bool popup_window_mode) { |
kAutocompleteEditFontPixelSize; |
} |
+// Copies |selected_text| as text to the primary clipboard. If |write_url| is |
+// true, this will also write |url| and |text| to the clipboard as a well-formed |
+// URL. |
+void DoCopy(const string16& selected_text, |
+ bool write_url, |
+ const GURL& url, |
+ const string16& text) { |
+ ui::Clipboard* cb = ui::Clipboard::GetForCurrentThread(); |
+ ui::ScopedClipboardWriter scw(cb, ui::Clipboard::BUFFER_STANDARD); |
+ scw.WriteText(selected_text); |
+ if (write_url) { |
+ BookmarkNodeData data; |
+ data.ReadFromTuple(url, text); |
+ data.WriteToClipboard(NULL); |
+ } |
+} |
+ |
} // namespace |
// static |
@@ -768,13 +785,7 @@ void OmniboxViewViews::OnAfterCutOrCopy() { |
bool write_url; |
model()->AdjustTextForCopy(selection_range.GetMin(), selected_text == text, |
&selected_text, &url, &write_url); |
- ui::ScopedClipboardWriter scw(cb, ui::Clipboard::BUFFER_STANDARD); |
- scw.WriteText(selected_text); |
- if (write_url) { |
- BookmarkNodeData data; |
- data.ReadFromTuple(url, text); |
- data.WriteToClipboard(NULL); |
- } |
+ DoCopy(selected_text, write_url, url, text); |
} |
void OmniboxViewViews::OnWriteDragData(ui::OSExchangeData* data) { |
@@ -798,16 +809,28 @@ void OmniboxViewViews::UpdateContextMenu(ui::SimpleMenuModel* menu_contents) { |
menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
IDS_EDIT_SEARCH_ENGINES); |
- int paste_position = menu_contents->GetIndexOfCommandId(IDS_APP_PASTE); |
- if (paste_position >= 0) |
+ if (chrome::search::IsInstantExtendedAPIEnabled( |
+ location_bar_view_->profile())) { |
+ int copy_position = menu_contents->GetIndexOfCommandId(IDS_APP_COPY); |
+ DCHECK(copy_position >= 0); |
menu_contents->InsertItemWithStringIdAt( |
- paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); |
+ copy_position + 1, IDC_COPY_URL, IDS_COPY_URL); |
+ } |
+ |
+ int paste_position = menu_contents->GetIndexOfCommandId(IDS_APP_PASTE); |
+ DCHECK(paste_position >= 0); |
+ menu_contents->InsertItemWithStringIdAt( |
+ paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); |
} |
bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const { |
- return (command_id == IDS_PASTE_AND_GO) ? |
- model()->CanPasteAndGo(GetClipboardText()) : |
- command_updater()->IsCommandEnabled(command_id); |
+ if (command_id == IDS_PASTE_AND_GO) |
+ return model()->CanPasteAndGo(GetClipboardText()); |
+ if (command_id == IDS_COPY_URL) { |
+ return toolbar_model()->WouldReplaceSearchURLWithSearchTerms() && |
+ !model()->user_input_in_progress(); |
+ } |
+ return command_updater()->IsCommandEnabled(command_id); |
} |
bool OmniboxViewViews::IsItemForCommandIdDynamic(int command_id) const { |
@@ -825,12 +848,12 @@ string16 OmniboxViewViews::GetLabelForCommandId(int command_id) const { |
} |
void OmniboxViewViews::ExecuteCommand(int command_id) { |
- if (command_id == IDS_PASTE_AND_GO) { |
+ if (command_id == IDS_PASTE_AND_GO) |
model()->PasteAndGo(GetClipboardText()); |
- return; |
- } |
- |
- command_updater()->ExecuteCommand(command_id); |
+ else if (command_id == IDS_COPY_URL) |
+ CopyURL(); |
+ else |
+ command_updater()->ExecuteCommand(command_id); |
} |
#if defined(OS_CHROMEOS) |
@@ -905,3 +928,8 @@ string16 OmniboxViewViews::GetSelectedText() const { |
// TODO(oshima): Support instant, IME. |
return textfield_->GetSelectedText(); |
} |
+ |
+void OmniboxViewViews::CopyURL() { |
+ const string16& text = toolbar_model()->GetText(false); |
+ DoCopy(text, true, toolbar_model()->GetURL(), text); |
+} |