| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <set> | 6 #include <set> |
| 7 | 7 |
| 8 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 8 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 9 | 9 |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/stl_util-inl.h" | 14 #include "base/stl_util-inl.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "chrome/app/chrome_command_ids.h" | 18 #include "chrome/app/chrome_command_ids.h" |
| 19 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 19 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 20 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 20 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 21 #include "chrome/browser/autocomplete/autocomplete_match.h" | 21 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 22 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 23 #include "chrome/browser/child_process_security_policy.h" | 23 #include "chrome/browser/child_process_security_policy.h" |
| 24 #include "chrome/browser/debugger/devtools_manager.h" | 24 #include "chrome/browser/debugger/devtools_manager.h" |
| 25 #include "chrome/browser/debugger/devtools_window.h" | 25 #include "chrome/browser/debugger/devtools_window.h" |
| 26 #include "chrome/browser/download/download_manager.h" | 26 #include "chrome/browser/download/download_manager.h" |
| 27 #include "chrome/browser/extensions/extension_event_router.h" | 27 #include "chrome/browser/extensions/extension_event_router.h" |
| 28 #include "chrome/browser/extensions/extensions_service.h" | 28 #include "chrome/browser/extensions/extension_service.h" |
| 29 #include "chrome/browser/fonts_languages_window.h" | 29 #include "chrome/browser/fonts_languages_window.h" |
| 30 #include "chrome/browser/metrics/user_metrics.h" | 30 #include "chrome/browser/metrics/user_metrics.h" |
| 31 #include "chrome/browser/net/browser_url_util.h" | 31 #include "chrome/browser/net/browser_url_util.h" |
| 32 #include "chrome/browser/page_info_window.h" | 32 #include "chrome/browser/page_info_window.h" |
| 33 #include "chrome/browser/platform_util.h" | 33 #include "chrome/browser/platform_util.h" |
| 34 #include "chrome/browser/prefs/pref_member.h" | 34 #include "chrome/browser/prefs/pref_member.h" |
| 35 #include "chrome/browser/prefs/pref_service.h" | 35 #include "chrome/browser/prefs/pref_service.h" |
| 36 #include "chrome/browser/profiles/profile.h" | 36 #include "chrome/browser/profiles/profile.h" |
| 37 #include "chrome/browser/renderer_host/render_view_host.h" | 37 #include "chrome/browser/renderer_host/render_view_host.h" |
| 38 #include "chrome/browser/search_engines/template_url.h" | 38 #include "chrome/browser/search_engines/template_url.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 continue; | 176 continue; |
| 177 | 177 |
| 178 if (item->id().profile == profile || can_cross_incognito) | 178 if (item->id().profile == profile || can_cross_incognito) |
| 179 result.push_back(*i); | 179 result.push_back(*i); |
| 180 } | 180 } |
| 181 return result; | 181 return result; |
| 182 } | 182 } |
| 183 | 183 |
| 184 void RenderViewContextMenu::AppendExtensionItems( | 184 void RenderViewContextMenu::AppendExtensionItems( |
| 185 const std::string& extension_id, int* index) { | 185 const std::string& extension_id, int* index) { |
| 186 ExtensionsService* service = profile_->GetExtensionsService(); | 186 ExtensionService* service = profile_->GetExtensionService(); |
| 187 ExtensionMenuManager* manager = service->menu_manager(); | 187 ExtensionMenuManager* manager = service->menu_manager(); |
| 188 const Extension* extension = service->GetExtensionById(extension_id, false); | 188 const Extension* extension = service->GetExtensionById(extension_id, false); |
| 189 bool can_cross_incognito = service->CanCrossIncognito(extension); | 189 bool can_cross_incognito = service->CanCrossIncognito(extension); |
| 190 DCHECK_GE(*index, 0); | 190 DCHECK_GE(*index, 0); |
| 191 int max_index = | 191 int max_index = |
| 192 IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST - IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST; | 192 IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST - IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST; |
| 193 if (!extension || *index >= max_index) | 193 if (!extension || *index >= max_index) |
| 194 return; | 194 return; |
| 195 | 195 |
| 196 // Find matching items. | 196 // Find matching items. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 } else if (item->type() == ExtensionMenuItem::SEPARATOR) { | 295 } else if (item->type() == ExtensionMenuItem::SEPARATOR) { |
| 296 if (i != items.begin() && last_type != ExtensionMenuItem::SEPARATOR) { | 296 if (i != items.begin() && last_type != ExtensionMenuItem::SEPARATOR) { |
| 297 menu_model->AddSeparator(); | 297 menu_model->AddSeparator(); |
| 298 } | 298 } |
| 299 } | 299 } |
| 300 last_type = item->type(); | 300 last_type = item->type(); |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 | 303 |
| 304 void RenderViewContextMenu::SetExtensionIcon(const std::string& extension_id) { | 304 void RenderViewContextMenu::SetExtensionIcon(const std::string& extension_id) { |
| 305 ExtensionsService* service = profile_->GetExtensionsService(); | 305 ExtensionService* service = profile_->GetExtensionService(); |
| 306 ExtensionMenuManager* menu_manager = service->menu_manager(); | 306 ExtensionMenuManager* menu_manager = service->menu_manager(); |
| 307 | 307 |
| 308 int index = menu_model_.GetItemCount() - 1; | 308 int index = menu_model_.GetItemCount() - 1; |
| 309 DCHECK_GE(index, 0); | 309 DCHECK_GE(index, 0); |
| 310 | 310 |
| 311 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); | 311 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); |
| 312 DCHECK(icon.width() == kFavIconSize); | 312 DCHECK(icon.width() == kFavIconSize); |
| 313 DCHECK(icon.height() == kFavIconSize); | 313 DCHECK(icon.height() == kFavIconSize); |
| 314 | 314 |
| 315 menu_model_.SetIcon(index, icon); | 315 menu_model_.SetIcon(index, icon); |
| 316 } | 316 } |
| 317 | 317 |
| 318 void RenderViewContextMenu::AppendAllExtensionItems() { | 318 void RenderViewContextMenu::AppendAllExtensionItems() { |
| 319 extension_item_map_.clear(); | 319 extension_item_map_.clear(); |
| 320 ExtensionsService* service = profile_->GetExtensionsService(); | 320 ExtensionService* service = profile_->GetExtensionService(); |
| 321 if (!service) | 321 if (!service) |
| 322 return; // In unit-tests, we may not have an ExtensionService. | 322 return; // In unit-tests, we may not have an ExtensionService. |
| 323 ExtensionMenuManager* menu_manager = service->menu_manager(); | 323 ExtensionMenuManager* menu_manager = service->menu_manager(); |
| 324 const GURL& document_url = GetDocumentURL(params_); | 324 const GURL& document_url = GetDocumentURL(params_); |
| 325 if (!menu_manager->HasAllowedScheme(document_url)) | 325 if (!menu_manager->HasAllowedScheme(document_url)) |
| 326 return; | 326 return; |
| 327 | 327 |
| 328 // Get a list of extension id's that have context menu items, and sort it by | 328 // Get a list of extension id's that have context menu items, and sort it by |
| 329 // the extension's name. | 329 // the extension's name. |
| 330 std::set<std::string> ids = menu_manager->ExtensionIds(); | 330 std::set<std::string> ids = menu_manager->ExtensionIds(); |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 | 720 |
| 721 menu_model_.AddSubMenu( | 721 menu_model_.AddSubMenu( |
| 722 IDC_WRITING_DIRECTION_MENU, | 722 IDC_WRITING_DIRECTION_MENU, |
| 723 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_MENU), | 723 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_MENU), |
| 724 &bidi_submenu_model_); | 724 &bidi_submenu_model_); |
| 725 } | 725 } |
| 726 #endif // OS_MACOSX | 726 #endif // OS_MACOSX |
| 727 | 727 |
| 728 ExtensionMenuItem* RenderViewContextMenu::GetExtensionMenuItem(int id) const { | 728 ExtensionMenuItem* RenderViewContextMenu::GetExtensionMenuItem(int id) const { |
| 729 ExtensionMenuManager* manager = | 729 ExtensionMenuManager* manager = |
| 730 profile_->GetExtensionsService()->menu_manager(); | 730 profile_->GetExtensionService()->menu_manager(); |
| 731 std::map<int, ExtensionMenuItem::Id>::const_iterator i = | 731 std::map<int, ExtensionMenuItem::Id>::const_iterator i = |
| 732 extension_item_map_.find(id); | 732 extension_item_map_.find(id); |
| 733 if (i != extension_item_map_.end()) { | 733 if (i != extension_item_map_.end()) { |
| 734 ExtensionMenuItem* item = manager->GetItemById(i->second); | 734 ExtensionMenuItem* item = manager->GetItemById(i->second); |
| 735 if (item) | 735 if (item) |
| 736 return item; | 736 return item; |
| 737 } | 737 } |
| 738 return NULL; | 738 return NULL; |
| 739 } | 739 } |
| 740 | 740 |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1077 unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST; | 1077 unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST; |
| 1078 source_tab_contents_->render_view_host()-> | 1078 source_tab_contents_->render_view_host()-> |
| 1079 PerformCustomContextMenuAction(action); | 1079 PerformCustomContextMenuAction(action); |
| 1080 return; | 1080 return; |
| 1081 } | 1081 } |
| 1082 | 1082 |
| 1083 // Process extension menu items. | 1083 // Process extension menu items. |
| 1084 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && | 1084 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
| 1085 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { | 1085 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
| 1086 ExtensionMenuManager* manager = | 1086 ExtensionMenuManager* manager = |
| 1087 profile_->GetExtensionsService()->menu_manager(); | 1087 profile_->GetExtensionService()->menu_manager(); |
| 1088 std::map<int, ExtensionMenuItem::Id>::const_iterator i = | 1088 std::map<int, ExtensionMenuItem::Id>::const_iterator i = |
| 1089 extension_item_map_.find(id); | 1089 extension_item_map_.find(id); |
| 1090 if (i != extension_item_map_.end()) { | 1090 if (i != extension_item_map_.end()) { |
| 1091 manager->ExecuteCommand(profile_, source_tab_contents_, params_, | 1091 manager->ExecuteCommand(profile_, source_tab_contents_, params_, |
| 1092 i->second); | 1092 i->second); |
| 1093 } | 1093 } |
| 1094 return; | 1094 return; |
| 1095 } | 1095 } |
| 1096 | 1096 |
| 1097 | 1097 |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1462 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), | 1462 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
| 1463 g_browser_process->clipboard()); | 1463 g_browser_process->clipboard()); |
| 1464 } | 1464 } |
| 1465 | 1465 |
| 1466 void RenderViewContextMenu::MediaPlayerActionAt( | 1466 void RenderViewContextMenu::MediaPlayerActionAt( |
| 1467 const gfx::Point& location, | 1467 const gfx::Point& location, |
| 1468 const WebMediaPlayerAction& action) { | 1468 const WebMediaPlayerAction& action) { |
| 1469 source_tab_contents_->render_view_host()->MediaPlayerActionAt( | 1469 source_tab_contents_->render_view_host()->MediaPlayerActionAt( |
| 1470 location, action); | 1470 location, action); |
| 1471 } | 1471 } |
| OLD | NEW |