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 string16 printable_selection_text = PrintableSelectionText(); | |
368 // Escape "&" as "&&". | |
369 for (size_t position = printable_selection_text.find('&'); | |
Yoyo Zhou
2013/02/19 19:00:50
This is more complex than necessary. Use ReplaceCh
François Beaufort
2013/02/20 11:32:06
I added a TODO to commit this when the other code
| |
370 position != string16::npos; | |
371 position = printable_selection_text.find('&', position + 2)) | |
372 printable_selection_text.insert(position, 1, '&'); | |
373 | |
367 // Get a list of extension id's that have context menu items, and sort it by | 374 // Get a list of extension id's that have context menu items, and sort it by |
Yoyo Zhou
2013/02/19 19:00:50
delete 'it'
François Beaufort
2013/02/20 11:32:06
Done.
| |
368 // the extension's name. | 375 // the top level context menu title of the extension. |
369 std::set<std::string> ids = menu_manager->ExtensionIds(); | 376 std::set<std::string> ids = menu_manager->ExtensionIds(); |
370 std::vector<std::pair<std::string, std::string> > sorted_ids; | 377 std::vector<std::pair<std::string, std::string> > sorted_ids; |
371 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { | 378 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { |
372 const Extension* extension = service->GetExtensionById(*i, false); | 379 const Extension* extension = service->GetExtensionById(*i, false); |
373 // Platform apps have their context menus created directly in | 380 // Platform apps have their context menus created directly in |
374 // AppendPlatformAppItems. | 381 // AppendPlatformAppItems. |
Yoyo Zhou
2013/02/19 19:00:50
Does AppendPlatformAppItems have the same sorting
François Beaufort
2013/02/20 11:32:06
From what I can read, there is no sorting involved
| |
375 if (extension && !extension->is_platform_app()) | 382 if (extension && !extension->is_platform_app()) { |
383 std::string menu_title = extension_items_.GetTopLevelContextMenuTitle(*i, | |
Yoyo Zhou
2013/02/19 19:00:50
nit: put *i on the next line. You can put it on th
François Beaufort
2013/02/20 11:32:06
Done.
| |
384 printable_selection_text); | |
376 sorted_ids.push_back( | 385 sorted_ids.push_back( |
377 std::pair<std::string, std::string>(extension->name(), *i)); | 386 std::pair<std::string, std::string>(menu_title, *i)); |
387 } | |
378 } | 388 } |
379 // TODO(asargent) - See if this works properly for i18n names (bug 32363). | 389 // TODO(asargent) - See if this works properly for i18n names (bug 32363). |
380 std::sort(sorted_ids.begin(), sorted_ids.end()); | 390 std::sort(sorted_ids.begin(), sorted_ids.end()); |
381 | 391 |
382 if (sorted_ids.empty()) | 392 if (sorted_ids.empty()) |
383 return; | 393 return; |
384 | 394 |
385 int index = 0; | 395 int index = 0; |
396 // TODO(fbeaufort): Where to move this UMA now? | |
Yoyo Zhou
2013/02/19 19:00:50
I think it's okay to leave it here.
François Beaufort
2013/02/20 11:32:06
Done.
| |
386 base::TimeTicks begin = base::TimeTicks::Now(); | 397 base::TimeTicks begin = base::TimeTicks::Now(); |
387 std::vector<std::pair<std::string, std::string> >::const_iterator i; | 398 std::vector<std::pair<std::string, std::string> >::const_iterator i; |
388 for (i = sorted_ids.begin(); | 399 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, | 400 extension_items_.AppendExtensionItems(i->second, printable_selection_text, |
Yoyo Zhou
2013/02/19 19:00:50
I don't see how this can behave equivalently to th
François Beaufort
2013/02/20 11:32:06
I'm not sure about what you mean here. Before, pri
Yoyo Zhou
2013/03/06 20:18:58
No. I'm not sure of this, but I believe PrintableS
| |
398 &index); | 401 &index); |
399 } | |
400 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", | 402 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", |
401 base::TimeTicks::Now() - begin); | 403 base::TimeTicks::Now() - begin); |
402 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); | 404 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); |
403 } | 405 } |
404 | 406 |
405 void RenderViewContextMenu::InitMenu() { | 407 void RenderViewContextMenu::InitMenu() { |
406 chrome::ViewType view_type = chrome::GetViewType(source_web_contents_); | 408 chrome::ViewType view_type = chrome::GetViewType(source_web_contents_); |
407 if (view_type == chrome::VIEW_TYPE_APP_SHELL) { | 409 if (view_type == chrome::VIEW_TYPE_APP_SHELL) { |
408 AppendPlatformAppItems(); | 410 AppendPlatformAppItems(); |
409 return; | 411 return; |
(...skipping 1462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1872 source_web_contents_->GetRenderViewHost()-> | 1874 source_web_contents_->GetRenderViewHost()-> |
1873 ExecuteMediaPlayerActionAtLocation(location, action); | 1875 ExecuteMediaPlayerActionAtLocation(location, action); |
1874 } | 1876 } |
1875 | 1877 |
1876 void RenderViewContextMenu::PluginActionAt( | 1878 void RenderViewContextMenu::PluginActionAt( |
1877 const gfx::Point& location, | 1879 const gfx::Point& location, |
1878 const WebPluginAction& action) { | 1880 const WebPluginAction& action) { |
1879 source_web_contents_->GetRenderViewHost()-> | 1881 source_web_contents_->GetRenderViewHost()-> |
1880 ExecutePluginActionAtLocation(location, action); | 1882 ExecutePluginActionAtLocation(location, action); |
1881 } | 1883 } |
OLD | NEW |