Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/tab_contents/render_view_context_menu.h" | 5 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 } | 357 } |
| 358 | 358 |
| 359 void RenderViewContextMenu::AppendAllExtensionItems() { | 359 void RenderViewContextMenu::AppendAllExtensionItems() { |
| 360 extension_items_.Clear(); | 360 extension_items_.Clear(); |
| 361 ExtensionService* service = | 361 ExtensionService* service = |
| 362 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 362 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 363 if (!service) | 363 if (!service) |
| 364 return; // In unit-tests, we may not have an ExtensionService. | 364 return; // In unit-tests, we may not have an ExtensionService. |
| 365 MenuManager* menu_manager = service->menu_manager(); | 365 MenuManager* menu_manager = service->menu_manager(); |
| 366 | 366 |
| 367 // Get a list of extension id's that have context menu items, and sort it by | 367 // TODO(fbeaufort) Use EscapeAmpersands when |
|
Yoyo Zhou
2013/03/06 20:18:58
nit: TODOs should have a colon:
TODO(fbeaufort): D
please use gerrit instead
2013/03/20 16:29:13
https://chromiumcodereview.appspot.com/12294022/ h
| |
| 368 // the extension's name. | 368 // https://chromiumcodereview.appspot.com/12294022/ is committed. |
| 369 string16 printable_selection_text = PrintableSelectionText(); | |
| 370 // Escape "&" as "&&". | |
| 371 for (size_t position = printable_selection_text.find('&'); | |
| 372 position != string16::npos; | |
| 373 position = printable_selection_text.find('&', position + 2)) | |
| 374 printable_selection_text.insert(position, 1, '&'); | |
| 375 | |
| 376 // Get a list of extension id's that have context menu items, and sort by the | |
| 377 // top level context menu title of the extension. | |
| 369 std::set<std::string> ids = menu_manager->ExtensionIds(); | 378 std::set<std::string> ids = menu_manager->ExtensionIds(); |
| 370 std::vector<std::pair<std::string, std::string> > sorted_ids; | 379 std::vector<std::pair<std::string, std::string> > sorted_ids; |
| 371 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { | 380 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { |
| 372 const Extension* extension = service->GetExtensionById(*i, false); | 381 const Extension* extension = service->GetExtensionById(*i, false); |
| 373 // Platform apps have their context menus created directly in | 382 // Platform apps have their context menus created directly in |
| 374 // AppendPlatformAppItems. | 383 // AppendPlatformAppItems. |
| 375 if (extension && !extension->is_platform_app()) | 384 if (extension && !extension->is_platform_app()) { |
| 385 std::string menu_title = extension_items_.GetTopLevelContextMenuTitle( | |
| 386 *i, printable_selection_text); | |
| 376 sorted_ids.push_back( | 387 sorted_ids.push_back( |
| 377 std::pair<std::string, std::string>(extension->name(), *i)); | 388 std::pair<std::string, std::string>(menu_title, *i)); |
| 389 } | |
| 378 } | 390 } |
| 379 // TODO(asargent) - See if this works properly for i18n names (bug 32363). | 391 // TODO(asargent) - See if this works properly for i18n names (bug 32363). |
| 380 std::sort(sorted_ids.begin(), sorted_ids.end()); | 392 std::sort(sorted_ids.begin(), sorted_ids.end()); |
| 381 | 393 |
| 382 if (sorted_ids.empty()) | 394 if (sorted_ids.empty()) |
| 383 return; | 395 return; |
| 384 | 396 |
| 385 int index = 0; | 397 int index = 0; |
| 386 base::TimeTicks begin = base::TimeTicks::Now(); | 398 base::TimeTicks begin = base::TimeTicks::Now(); |
| 387 std::vector<std::pair<std::string, std::string> >::const_iterator i; | 399 std::vector<std::pair<std::string, std::string> >::const_iterator i; |
| 388 for (i = sorted_ids.begin(); | 400 for (i = sorted_ids.begin(); i != sorted_ids.end(); ++i) |
| 389 i != sorted_ids.end(); ++i) { | |
| 390 string16 printable_selection_text = PrintableSelectionText(); | |
| 391 // Escape "&" as "&&". | |
| 392 for (size_t position = printable_selection_text.find('&'); | |
| 393 position != string16::npos; | |
| 394 position = printable_selection_text.find('&', position + 2)) | |
| 395 printable_selection_text.insert(position, 1, '&'); | |
| 396 | |
| 397 extension_items_.AppendExtensionItems(i->second, printable_selection_text, | 401 extension_items_.AppendExtensionItems(i->second, printable_selection_text, |
| 398 &index); | 402 &index); |
| 399 } | |
| 400 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", | 403 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", |
| 401 base::TimeTicks::Now() - begin); | 404 base::TimeTicks::Now() - begin); |
| 402 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); | 405 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); |
| 403 } | 406 } |
| 404 | 407 |
| 405 void RenderViewContextMenu::InitMenu() { | 408 void RenderViewContextMenu::InitMenu() { |
| 406 chrome::ViewType view_type = chrome::GetViewType(source_web_contents_); | 409 chrome::ViewType view_type = chrome::GetViewType(source_web_contents_); |
| 407 if (view_type == chrome::VIEW_TYPE_APP_SHELL) { | 410 if (view_type == chrome::VIEW_TYPE_APP_SHELL) { |
| 408 AppendPlatformAppItems(); | 411 AppendPlatformAppItems(); |
| 409 return; | 412 return; |
| (...skipping 1462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1872 source_web_contents_->GetRenderViewHost()-> | 1875 source_web_contents_->GetRenderViewHost()-> |
| 1873 ExecuteMediaPlayerActionAtLocation(location, action); | 1876 ExecuteMediaPlayerActionAtLocation(location, action); |
| 1874 } | 1877 } |
| 1875 | 1878 |
| 1876 void RenderViewContextMenu::PluginActionAt( | 1879 void RenderViewContextMenu::PluginActionAt( |
| 1877 const gfx::Point& location, | 1880 const gfx::Point& location, |
| 1878 const WebPluginAction& action) { | 1881 const WebPluginAction& action) { |
| 1879 source_web_contents_->GetRenderViewHost()-> | 1882 source_web_contents_->GetRenderViewHost()-> |
| 1880 ExecutePluginActionAtLocation(location, action); | 1883 ExecutePluginActionAtLocation(location, action); |
| 1881 } | 1884 } |
| OLD | NEW |