| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <functional> |
| 6 |
| 5 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 7 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 6 | 8 |
| 7 #include "app/clipboard/clipboard.h" | 9 #include "app/clipboard/clipboard.h" |
| 8 #include "app/clipboard/scoped_clipboard_writer.h" | 10 #include "app/clipboard/scoped_clipboard_writer.h" |
| 9 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
| 10 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 11 #include "base/logging.h" | 13 #include "base/logging.h" |
| 12 #include "chrome/app/chrome_dll_resource.h" | 14 #include "chrome/app/chrome_dll_resource.h" |
| 13 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/debugger/devtools_manager.h" | 16 #include "chrome/browser/debugger/devtools_manager.h" |
| 15 #include "chrome/browser/debugger/devtools_window.h" | 17 #include "chrome/browser/debugger/devtools_window.h" |
| 16 #include "chrome/browser/download/download_manager.h" | 18 #include "chrome/browser/download/download_manager.h" |
| 19 #include "chrome/browser/extensions/extension_menu_manager.h" |
| 20 #include "chrome/browser/extensions/extensions_service.h" |
| 17 #include "chrome/browser/fonts_languages_window.h" | 21 #include "chrome/browser/fonts_languages_window.h" |
| 18 #include "chrome/browser/metrics/user_metrics.h" | 22 #include "chrome/browser/metrics/user_metrics.h" |
| 19 #include "chrome/browser/net/browser_url_util.h" | 23 #include "chrome/browser/net/browser_url_util.h" |
| 20 #include "chrome/browser/page_info_window.h" | 24 #include "chrome/browser/page_info_window.h" |
| 21 #include "chrome/browser/pref_service.h" | 25 #include "chrome/browser/pref_service.h" |
| 22 #include "chrome/browser/profile.h" | 26 #include "chrome/browser/profile.h" |
| 23 #include "chrome/browser/renderer_host/render_view_host.h" | 27 #include "chrome/browser/renderer_host/render_view_host.h" |
| 24 #include "chrome/browser/search_versus_navigate_classifier.h" | 28 #include "chrome/browser/search_versus_navigate_classifier.h" |
| 25 #include "chrome/browser/search_engines/template_url_model.h" | 29 #include "chrome/browser/search_engines/template_url_model.h" |
| 26 #include "chrome/browser/spellcheck_host.h" | 30 #include "chrome/browser/spellcheck_host.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 RenderViewContextMenu::~RenderViewContextMenu() { | 63 RenderViewContextMenu::~RenderViewContextMenu() { |
| 60 } | 64 } |
| 61 | 65 |
| 62 // Menu construction functions ------------------------------------------------- | 66 // Menu construction functions ------------------------------------------------- |
| 63 | 67 |
| 64 void RenderViewContextMenu::Init() { | 68 void RenderViewContextMenu::Init() { |
| 65 InitMenu(); | 69 InitMenu(); |
| 66 DoInit(); | 70 DoInit(); |
| 67 } | 71 } |
| 68 | 72 |
| 73 static bool ExtensionContextMatch(ContextMenuParams params, |
| 74 ExtensionMenuItem::ContextList contexts) { |
| 75 bool has_link = !params.link_url.is_empty(); |
| 76 bool has_selection = !params.selection_text.empty(); |
| 77 |
| 78 if (contexts.Contains(ExtensionMenuItem::ALL) || |
| 79 (has_selection && contexts.Contains(ExtensionMenuItem::SELECTION)) || |
| 80 (has_link && contexts.Contains(ExtensionMenuItem::LINK)) || |
| 81 (params.is_editable && contexts.Contains(ExtensionMenuItem::EDITABLE))) { |
| 82 return true; |
| 83 } |
| 84 |
| 85 switch (params.media_type) { |
| 86 case WebContextMenuData::MediaTypeImage: |
| 87 return contexts.Contains(ExtensionMenuItem::IMAGE); |
| 88 |
| 89 case WebContextMenuData::MediaTypeVideo: |
| 90 return contexts.Contains(ExtensionMenuItem::VIDEO); |
| 91 |
| 92 case WebContextMenuData::MediaTypeAudio: |
| 93 return contexts.Contains(ExtensionMenuItem::AUDIO); |
| 94 |
| 95 default: |
| 96 break; |
| 97 } |
| 98 |
| 99 // PAGE is the least specific context, so we only examine that if none of the |
| 100 // other contexts apply. |
| 101 if (!has_link && !has_selection && !params.is_editable && |
| 102 params.media_type == WebContextMenuData::MediaTypeNone && |
| 103 contexts.Contains(ExtensionMenuItem::PAGE)) |
| 104 return true; |
| 105 |
| 106 return false; |
| 107 } |
| 108 |
| 109 void RenderViewContextMenu::GetItemsForExtension( |
| 110 const std::string& extension_id, |
| 111 std::vector<const ExtensionMenuItem*>* items) { |
| 112 ExtensionsService* service = profile_->GetExtensionsService(); |
| 113 |
| 114 // Get the set of possible items, and iterate to find which ones are |
| 115 // applicable. |
| 116 std::vector<const ExtensionMenuItem*> potential_items = |
| 117 service->menu_manager()->MenuItems(extension_id); |
| 118 |
| 119 std::vector<const ExtensionMenuItem*>::const_iterator i; |
| 120 for (i = potential_items.begin(); i != potential_items.end(); ++i) { |
| 121 const ExtensionMenuItem* item = *i; |
| 122 if (ExtensionContextMatch(params_, item->contexts())) |
| 123 items->push_back(item); |
| 124 } |
| 125 } |
| 126 |
| 127 bool RenderViewContextMenu::MaybeStartExtensionSubMenu( |
| 128 const string16& selection_text, const std::string& extension_name, |
| 129 std::vector<const ExtensionMenuItem*>* items, int* index) { |
| 130 if (items->size() == 0 || |
| 131 (items->size() == 1 && items->at(0)->child_count() == 0)) |
| 132 return false; |
| 133 |
| 134 int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; |
| 135 string16 title; |
| 136 const ExtensionMenuItem* first_item = items->at(0); |
| 137 if (first_item->child_count() > 0) { |
| 138 title = first_item->TitleWithReplacement(selection_text); |
| 139 extension_item_map_[menu_id] = first_item->id(); |
| 140 } else { |
| 141 title = UTF8ToUTF16(extension_name); |
| 142 } |
| 143 StartSubMenu(menu_id, title); |
| 144 |
| 145 // If we have 1 parent item with a submenu of children, pull the |
| 146 // parent out of |items| and put the children in. |
| 147 if (items->size() == 1 && first_item->child_count() > 0) { |
| 148 const ExtensionMenuItem* parent = first_item; |
| 149 items->clear(); |
| 150 for (int j = 0; j < parent->child_count(); j++) { |
| 151 const ExtensionMenuItem* child = parent->ChildAt(j); |
| 152 if (ExtensionContextMatch(params_, child->contexts())) |
| 153 items->push_back(child); |
| 154 } |
| 155 } |
| 156 |
| 157 return true; |
| 158 } |
| 159 |
| 160 void RenderViewContextMenu::AppendExtensionItems( |
| 161 const std::string& extension_id, int* index) { |
| 162 Extension* extension = |
| 163 profile_->GetExtensionsService()->GetExtensionById(extension_id, false); |
| 164 DCHECK_GE(*index, 0); |
| 165 int max_index = |
| 166 IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST - IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST; |
| 167 if (!extension || *index >= max_index) |
| 168 return; |
| 169 |
| 170 std::vector<const ExtensionMenuItem*> items; |
| 171 GetItemsForExtension(extension_id, &items); |
| 172 if (items.empty()) |
| 173 return; |
| 174 |
| 175 string16 selection_text = PrintableSelectionText(); |
| 176 |
| 177 // If this is the first extension-provided menu item, add a separator. |
| 178 if (*index == 0) |
| 179 AppendSeparator(); |
| 180 |
| 181 bool submenu_started = MaybeStartExtensionSubMenu( |
| 182 selection_text, extension->name(), &items, index); |
| 183 |
| 184 ExtensionMenuItem::Type last_type = ExtensionMenuItem::NORMAL; |
| 185 for (std::vector<const ExtensionMenuItem*>::iterator i = items.begin(); |
| 186 i != items.end(); ++i) { |
| 187 const ExtensionMenuItem* item = *i; |
| 188 if (item->type() == ExtensionMenuItem::SEPARATOR) { |
| 189 // We don't want the case of an extension with one top-level item that is |
| 190 // just a separator, so make sure this is inside a submenu. |
| 191 if (submenu_started) { |
| 192 AppendSeparator(); |
| 193 last_type = ExtensionMenuItem::SEPARATOR; |
| 194 } |
| 195 continue; |
| 196 } |
| 197 |
| 198 // Auto-prepend a separator, if needed, to group radio items together. |
| 199 if (item->type() != ExtensionMenuItem::RADIO && |
| 200 item->type() != ExtensionMenuItem::SEPARATOR && |
| 201 last_type == ExtensionMenuItem::RADIO) { |
| 202 AppendSeparator(); |
| 203 } |
| 204 |
| 205 int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; |
| 206 if (menu_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) |
| 207 return; |
| 208 extension_item_map_[menu_id] = item->id(); |
| 209 string16 title = item->TitleWithReplacement(selection_text); |
| 210 if (item->type() == ExtensionMenuItem::NORMAL) { |
| 211 AppendMenuItem(menu_id, title); |
| 212 } else if (item->type() == ExtensionMenuItem::CHECKBOX) { |
| 213 AppendCheckboxMenuItem(menu_id, title); |
| 214 } else if (item->type() == ExtensionMenuItem::RADIO) { |
| 215 // Auto-append a separator if needed to group radio items together. |
| 216 if (*index > 0 && last_type != ExtensionMenuItem::RADIO && |
| 217 last_type != ExtensionMenuItem::SEPARATOR) |
| 218 AppendSeparator(); |
| 219 |
| 220 AppendRadioMenuItem(menu_id, title); |
| 221 } else { |
| 222 NOTREACHED(); |
| 223 } |
| 224 last_type = item->type(); |
| 225 } |
| 226 |
| 227 if (submenu_started) |
| 228 FinishSubMenu(); |
| 229 } |
| 230 |
| 231 void RenderViewContextMenu::AppendAllExtensionItems() { |
| 232 extension_item_map_.clear(); |
| 233 ExtensionsService* service = profile_->GetExtensionsService(); |
| 234 ExtensionMenuManager* menu_manager = service->menu_manager(); |
| 235 |
| 236 // Get a list of extension id's that have context menu items, and sort it by |
| 237 // the extension's name. |
| 238 std::set<std::string> ids = menu_manager->ExtensionIds(); |
| 239 std::vector<std::pair<std::string, std::string> > sorted_ids; |
| 240 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { |
| 241 Extension* extension = service->GetExtensionById(*i, false); |
| 242 if (extension) |
| 243 sorted_ids.push_back( |
| 244 std::pair<std::string, std::string>(extension->name(), *i)); |
| 245 } |
| 246 // TODO(asargent) - See if this works properly for i18n names (bug 32363). |
| 247 std::sort(sorted_ids.begin(), sorted_ids.end()); |
| 248 |
| 249 int index = 0; |
| 250 std::vector<std::pair<std::string, std::string> >::const_iterator i; |
| 251 for (i = sorted_ids.begin(); |
| 252 i != sorted_ids.end(); ++i) { |
| 253 AppendExtensionItems(i->second, &index); |
| 254 } |
| 255 } |
| 256 |
| 69 void RenderViewContextMenu::InitMenu() { | 257 void RenderViewContextMenu::InitMenu() { |
| 70 bool has_link = !params_.link_url.is_empty(); | 258 bool has_link = !params_.link_url.is_empty(); |
| 71 bool has_selection = !params_.selection_text.empty(); | 259 bool has_selection = !params_.selection_text.empty(); |
| 72 | 260 |
| 73 if (AppendCustomItems()) { | 261 if (AppendCustomItems()) { |
| 74 AppendSeparator(); | 262 AppendSeparator(); |
| 75 AppendDeveloperItems(); | 263 AppendDeveloperItems(); |
| 76 return; | 264 return; |
| 77 } | 265 } |
| 78 | 266 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 304 } |
| 117 | 305 |
| 118 if (params_.is_editable) | 306 if (params_.is_editable) |
| 119 AppendEditableItems(); | 307 AppendEditableItems(); |
| 120 else if (has_selection) | 308 else if (has_selection) |
| 121 AppendCopyItem(); | 309 AppendCopyItem(); |
| 122 | 310 |
| 123 if (has_selection) | 311 if (has_selection) |
| 124 AppendSearchProvider(); | 312 AppendSearchProvider(); |
| 125 | 313 |
| 314 if (!is_devtools) |
| 315 AppendAllExtensionItems(); |
| 316 |
| 126 // In the DevTools popup menu, "developer items" is normally the only section, | 317 // In the DevTools popup menu, "developer items" is normally the only section, |
| 127 // so omit the separator there. | 318 // so omit the separator there. |
| 128 if (!is_devtools) | 319 if (!is_devtools) |
| 129 AppendSeparator(); | 320 AppendSeparator(); |
| 130 AppendDeveloperItems(); | 321 AppendDeveloperItems(); |
| 131 } | 322 } |
| 132 | 323 |
| 133 bool RenderViewContextMenu::AppendCustomItems() { | 324 bool RenderViewContextMenu::AppendCustomItems() { |
| 134 std::vector<WebMenuItem>& custom_items = params_.custom_items; | 325 std::vector<WebMenuItem>& custom_items = params_.custom_items; |
| 135 for (size_t i = 0; i < custom_items.size(); ++i) { | 326 for (size_t i = 0; i < custom_items.size(); ++i) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 if (params_.selection_text.empty()) | 431 if (params_.selection_text.empty()) |
| 241 return; | 432 return; |
| 242 | 433 |
| 243 bool is_search; | 434 bool is_search; |
| 244 profile_->GetSearchVersusNavigateClassifier()->Classify( | 435 profile_->GetSearchVersusNavigateClassifier()->Classify( |
| 245 params_.selection_text, std::wstring(), &is_search, | 436 params_.selection_text, std::wstring(), &is_search, |
| 246 &selection_navigation_url_, NULL, NULL, NULL); | 437 &selection_navigation_url_, NULL, NULL, NULL); |
| 247 if (!selection_navigation_url_.is_valid()) | 438 if (!selection_navigation_url_.is_valid()) |
| 248 return; | 439 return; |
| 249 | 440 |
| 250 string16 printable_selection_text( | 441 string16 printable_selection_text = PrintableSelectionText(); |
| 251 WideToUTF16(l10n_util::TruncateString(params_.selection_text, 50))); | |
| 252 // Escape "&" as "&&". | 442 // Escape "&" as "&&". |
| 253 for (size_t i = printable_selection_text.find('&'); i != string16::npos; | 443 for (size_t i = printable_selection_text.find('&'); i != string16::npos; |
| 254 i = printable_selection_text.find('&', i + 2)) | 444 i = printable_selection_text.find('&', i + 2)) |
| 255 printable_selection_text.insert(i, 1, '&'); | 445 printable_selection_text.insert(i, 1, '&'); |
| 256 | 446 |
| 257 if (is_search) { | 447 if (is_search) { |
| 258 const TemplateURL* const default_provider = | 448 const TemplateURL* const default_provider = |
| 259 profile_->GetTemplateURLModel()->GetDefaultSearchProvider(); | 449 profile_->GetTemplateURLModel()->GetDefaultSearchProvider(); |
| 260 if (!default_provider) | 450 if (!default_provider) |
| 261 return; | 451 return; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_MENU)); | 539 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_MENU)); |
| 350 | 540 |
| 351 AppendCheckboxMenuItem(IDC_WRITING_DIRECTION_DEFAULT, | 541 AppendCheckboxMenuItem(IDC_WRITING_DIRECTION_DEFAULT, |
| 352 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT)); | 542 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT)); |
| 353 AppendCheckboxMenuItem(IDC_WRITING_DIRECTION_LTR, | 543 AppendCheckboxMenuItem(IDC_WRITING_DIRECTION_LTR, |
| 354 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR)); | 544 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR)); |
| 355 AppendCheckboxMenuItem(IDC_WRITING_DIRECTION_RTL, | 545 AppendCheckboxMenuItem(IDC_WRITING_DIRECTION_RTL, |
| 356 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL)); | 546 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL)); |
| 357 | 547 |
| 358 FinishSubMenu(); | 548 FinishSubMenu(); |
| 359 #endif // OS_MACOSX | 549 #endif // OS_MACOSX |
| 360 | 550 |
| 361 AppendSeparator(); | 551 AppendSeparator(); |
| 362 AppendMenuItem(IDS_CONTENT_CONTEXT_SELECTALL); | 552 AppendMenuItem(IDS_CONTENT_CONTEXT_SELECTALL); |
| 363 } | 553 } |
| 364 | 554 |
| 555 ExtensionMenuItem* RenderViewContextMenu::GetExtensionMenuItem(int id) const { |
| 556 ExtensionMenuManager* manager = |
| 557 profile_->GetExtensionsService()->menu_manager(); |
| 558 std::map<int, int>::const_iterator i = extension_item_map_.find(id); |
| 559 if (i != extension_item_map_.end()) { |
| 560 ExtensionMenuItem* item = manager->GetItemById(i->second); |
| 561 if (item) |
| 562 return item; |
| 563 } |
| 564 return NULL; |
| 565 } |
| 566 |
| 365 // Menu delegate functions ----------------------------------------------------- | 567 // Menu delegate functions ----------------------------------------------------- |
| 366 | 568 |
| 367 bool RenderViewContextMenu::IsItemCommandEnabled(int id) const { | 569 bool RenderViewContextMenu::IsItemCommandEnabled(int id) const { |
| 368 // Allow Spell Check language items on sub menu for text area context menu. | 570 // Allow Spell Check language items on sub menu for text area context menu. |
| 369 if ((id >= IDC_SPELLCHECK_LANGUAGES_FIRST) && | 571 if ((id >= IDC_SPELLCHECK_LANGUAGES_FIRST) && |
| 370 (id < IDC_SPELLCHECK_LANGUAGES_LAST)) { | 572 (id < IDC_SPELLCHECK_LANGUAGES_LAST)) { |
| 371 return profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck); | 573 return profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck); |
| 372 } | 574 } |
| 373 | 575 |
| 374 // Process custom actions range. | 576 // Process custom actions range. |
| 375 if ((id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST) && | 577 if ((id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST) && |
| 376 (id < IDC_CONTENT_CONTEXT_CUSTOM_LAST)) { | 578 (id < IDC_CONTENT_CONTEXT_CUSTOM_LAST)) { |
| 377 unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST; | 579 unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST; |
| 378 for (size_t i = 0; i < params_.custom_items.size(); ++i) { | 580 for (size_t i = 0; i < params_.custom_items.size(); ++i) { |
| 379 if (params_.custom_items[i].action == action) | 581 if (params_.custom_items[i].action == action) |
| 380 return params_.custom_items[i].enabled; | 582 return params_.custom_items[i].enabled; |
| 381 } | 583 } |
| 382 NOTREACHED(); | 584 NOTREACHED(); |
| 383 return false; | 585 return false; |
| 384 } | 586 } |
| 385 | 587 |
| 588 // Extension items. |
| 589 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
| 590 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
| 591 ExtensionMenuItem* item = GetExtensionMenuItem(id); |
| 592 if (item) |
| 593 return ExtensionContextMatch(params_, item->enabled_contexts()); |
| 594 else |
| 595 return false; |
| 596 } |
| 597 |
| 386 switch (id) { | 598 switch (id) { |
| 387 case IDS_CONTENT_CONTEXT_BACK: | 599 case IDS_CONTENT_CONTEXT_BACK: |
| 388 return source_tab_contents_->controller().CanGoBack(); | 600 return source_tab_contents_->controller().CanGoBack(); |
| 389 | 601 |
| 390 case IDS_CONTENT_CONTEXT_FORWARD: | 602 case IDS_CONTENT_CONTEXT_FORWARD: |
| 391 return source_tab_contents_->controller().CanGoForward(); | 603 return source_tab_contents_->controller().CanGoForward(); |
| 392 | 604 |
| 393 case IDS_CONTENT_CONTEXT_RELOAD: | 605 case IDS_CONTENT_CONTEXT_RELOAD: |
| 394 return source_tab_contents_->delegate()->CanReloadContents( | 606 return source_tab_contents_->delegate()->CanReloadContents( |
| 395 source_tab_contents_); | 607 source_tab_contents_); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 } | 777 } |
| 566 } | 778 } |
| 567 | 779 |
| 568 bool RenderViewContextMenu::ItemIsChecked(int id) const { | 780 bool RenderViewContextMenu::ItemIsChecked(int id) const { |
| 569 // See if the video is set to looping. | 781 // See if the video is set to looping. |
| 570 if (id == IDS_CONTENT_CONTEXT_LOOP) { | 782 if (id == IDS_CONTENT_CONTEXT_LOOP) { |
| 571 return (params_.media_flags & | 783 return (params_.media_flags & |
| 572 WebContextMenuData::MediaLoop) != 0; | 784 WebContextMenuData::MediaLoop) != 0; |
| 573 } | 785 } |
| 574 | 786 |
| 787 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
| 788 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
| 789 ExtensionMenuItem* item = GetExtensionMenuItem(id); |
| 790 if (item) |
| 791 return item->checked(); |
| 792 else |
| 793 return false; |
| 794 } |
| 795 |
| 575 #if defined(OS_MACOSX) | 796 #if defined(OS_MACOSX) |
| 576 if (id == IDC_WRITING_DIRECTION_DEFAULT) | 797 if (id == IDC_WRITING_DIRECTION_DEFAULT) |
| 577 return params_.writing_direction_default & | 798 return params_.writing_direction_default & |
| 578 WebContextMenuData::CheckableMenuItemChecked; | 799 WebContextMenuData::CheckableMenuItemChecked; |
| 579 if (id == IDC_WRITING_DIRECTION_RTL) | 800 if (id == IDC_WRITING_DIRECTION_RTL) |
| 580 return params_.writing_direction_right_to_left & | 801 return params_.writing_direction_right_to_left & |
| 581 WebContextMenuData::CheckableMenuItemChecked; | 802 WebContextMenuData::CheckableMenuItemChecked; |
| 582 if (id == IDC_WRITING_DIRECTION_LTR) | 803 if (id == IDC_WRITING_DIRECTION_LTR) |
| 583 return params_.writing_direction_left_to_right & | 804 return params_.writing_direction_left_to_right & |
| 584 WebContextMenuData::CheckableMenuItemChecked; | 805 WebContextMenuData::CheckableMenuItemChecked; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 | 840 |
| 620 // Process custom actions range. | 841 // Process custom actions range. |
| 621 if ((id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST) && | 842 if ((id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST) && |
| 622 (id < IDC_CONTENT_CONTEXT_CUSTOM_LAST)) { | 843 (id < IDC_CONTENT_CONTEXT_CUSTOM_LAST)) { |
| 623 unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST; | 844 unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST; |
| 624 source_tab_contents_->render_view_host()-> | 845 source_tab_contents_->render_view_host()-> |
| 625 PerformCustomContextMenuAction(action); | 846 PerformCustomContextMenuAction(action); |
| 626 return; | 847 return; |
| 627 } | 848 } |
| 628 | 849 |
| 850 // Process extension menu items. |
| 851 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
| 852 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
| 853 ExtensionMenuManager* manager = |
| 854 profile_->GetExtensionsService()->menu_manager(); |
| 855 std::map<int, int>::const_iterator i = extension_item_map_.find(id); |
| 856 if (i != extension_item_map_.end()) { |
| 857 manager->ExecuteCommand(profile_, source_tab_contents_, params_, |
| 858 i->second); |
| 859 } |
| 860 return; |
| 861 } |
| 862 |
| 863 |
| 629 switch (id) { | 864 switch (id) { |
| 630 case IDS_CONTENT_CONTEXT_OPENLINKNEWTAB: | 865 case IDS_CONTENT_CONTEXT_OPENLINKNEWTAB: |
| 631 OpenURL(params_.link_url, | 866 OpenURL(params_.link_url, |
| 632 source_tab_contents_->delegate() && | 867 source_tab_contents_->delegate() && |
| 633 source_tab_contents_->delegate()->IsApplication() ? | 868 source_tab_contents_->delegate()->IsApplication() ? |
| 634 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB, | 869 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB, |
| 635 PageTransition::LINK); | 870 PageTransition::LINK); |
| 636 break; | 871 break; |
| 637 | 872 |
| 638 case IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW: | 873 case IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW: |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 // Don't enable the web inspector on web inspector if there is no process | 1170 // Don't enable the web inspector on web inspector if there is no process |
| 936 // per tab flag set. | 1171 // per tab flag set. |
| 937 if (IsDevToolsURL(active_entry->url()) && | 1172 if (IsDevToolsURL(active_entry->url()) && |
| 938 !command_line.HasSwitch(switches::kProcessPerTab)) | 1173 !command_line.HasSwitch(switches::kProcessPerTab)) |
| 939 return false; | 1174 return false; |
| 940 } | 1175 } |
| 941 | 1176 |
| 942 return true; | 1177 return true; |
| 943 } | 1178 } |
| 944 | 1179 |
| 1180 string16 RenderViewContextMenu::PrintableSelectionText() { |
| 1181 return WideToUTF16(l10n_util::TruncateString(params_.selection_text, 50)); |
| 1182 } |
| 1183 |
| 945 // Controller functions -------------------------------------------------------- | 1184 // Controller functions -------------------------------------------------------- |
| 946 | 1185 |
| 947 void RenderViewContextMenu::OpenURL( | 1186 void RenderViewContextMenu::OpenURL( |
| 948 const GURL& url, | 1187 const GURL& url, |
| 949 WindowOpenDisposition disposition, | 1188 WindowOpenDisposition disposition, |
| 950 PageTransition::Type transition) { | 1189 PageTransition::Type transition) { |
| 951 source_tab_contents_->OpenURL(url, GURL(), disposition, transition); | 1190 source_tab_contents_->OpenURL(url, GURL(), disposition, transition); |
| 952 } | 1191 } |
| 953 | 1192 |
| 954 void RenderViewContextMenu::CopyImageAt(int x, int y) { | 1193 void RenderViewContextMenu::CopyImageAt(int x, int y) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 967 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), | 1206 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
| 968 g_browser_process->clipboard()); | 1207 g_browser_process->clipboard()); |
| 969 } | 1208 } |
| 970 | 1209 |
| 971 void RenderViewContextMenu::MediaPlayerActionAt( | 1210 void RenderViewContextMenu::MediaPlayerActionAt( |
| 972 const gfx::Point& location, | 1211 const gfx::Point& location, |
| 973 const WebMediaPlayerAction& action) { | 1212 const WebMediaPlayerAction& action) { |
| 974 source_tab_contents_->render_view_host()->MediaPlayerActionAt( | 1213 source_tab_contents_->render_view_host()->MediaPlayerActionAt( |
| 975 location, action); | 1214 location, action); |
| 976 } | 1215 } |
| OLD | NEW |