Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: chrome/browser/tab_contents/render_view_context_menu.cc

Issue 8834008: Hide default context menu for platform apps. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Compile on non-Windows OS Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include <utility> 7 #include <utility>
8 8
9 #include "chrome/browser/tab_contents/render_view_context_menu.h" 9 #include "chrome/browser/tab_contents/render_view_context_menu.h"
10 10
(...skipping 28 matching lines...) Expand all
39 #include "chrome/browser/search_engines/template_url_service_factory.h" 39 #include "chrome/browser/search_engines/template_url_service_factory.h"
40 #include "chrome/browser/spellchecker/spellcheck_host.h" 40 #include "chrome/browser/spellchecker/spellcheck_host.h"
41 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" 41 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
42 #include "chrome/browser/tab_contents/spellchecker_submenu_observer.h" 42 #include "chrome/browser/tab_contents/spellchecker_submenu_observer.h"
43 #include "chrome/browser/tab_contents/spelling_menu_observer.h" 43 #include "chrome/browser/tab_contents/spelling_menu_observer.h"
44 #include "chrome/browser/translate/translate_manager.h" 44 #include "chrome/browser/translate/translate_manager.h"
45 #include "chrome/browser/translate/translate_prefs.h" 45 #include "chrome/browser/translate/translate_prefs.h"
46 #include "chrome/browser/translate/translate_tab_helper.h" 46 #include "chrome/browser/translate/translate_tab_helper.h"
47 #include "chrome/browser/ui/browser.h" 47 #include "chrome/browser/ui/browser.h"
48 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" 48 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
49 #include "chrome/browser/ui/browser_list.h"
49 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" 50 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
50 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 51 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
51 #include "chrome/common/chrome_constants.h" 52 #include "chrome/common/chrome_constants.h"
52 #include "chrome/common/chrome_switches.h" 53 #include "chrome/common/chrome_switches.h"
53 #include "chrome/common/pref_names.h" 54 #include "chrome/common/pref_names.h"
54 #include "chrome/common/print_messages.h" 55 #include "chrome/common/print_messages.h"
55 #include "chrome/common/spellcheck_messages.h" 56 #include "chrome/common/spellcheck_messages.h"
56 #include "chrome/common/url_constants.h" 57 #include "chrome/common/url_constants.h"
57 #include "content/browser/child_process_security_policy.h" 58 #include "content/browser/child_process_security_policy.h"
58 #include "content/browser/download/download_manager.h" 59 #include "content/browser/download/download_manager.h"
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 const ExtensionMenuItem::List* all_items = manager->MenuItems(extension_id); 353 const ExtensionMenuItem::List* all_items = manager->MenuItems(extension_id);
353 if (!all_items || all_items->empty()) 354 if (!all_items || all_items->empty())
354 return; 355 return;
355 bool can_cross_incognito = service->CanCrossIncognito(extension); 356 bool can_cross_incognito = service->CanCrossIncognito(extension);
356 ExtensionMenuItem::List items = 357 ExtensionMenuItem::List items =
357 GetRelevantExtensionItems(*all_items, params_, profile_, 358 GetRelevantExtensionItems(*all_items, params_, profile_,
358 can_cross_incognito); 359 can_cross_incognito);
359 if (items.empty()) 360 if (items.empty())
360 return; 361 return;
361 362
362 // If this is the first extension-provided menu item, add a separator. 363 // If this is the first extension-provided menu item, and there are other
363 if (*index == 0) 364 // items in the menu, add a separator.
365 if (*index == 0 && menu_model_.GetItemCount())
364 menu_model_.AddSeparator(); 366 menu_model_.AddSeparator();
365 367
366 int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; 368 int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++;
367 369
368 // Extensions are only allowed one top-level slot (and it can't be a radio or 370 // Extensions are only allowed one top-level slot (and it can't be a radio or
369 // checkbox item because we are going to put the extension icon next to it). 371 // checkbox item because we are going to put the extension icon next to it).
370 // If they have more than that, we automatically push them into a submenu. 372 // If they have more than that, we automatically push them into a submenu.
371 string16 title; 373 string16 title;
372 ExtensionMenuItem::List submenu_items; 374 ExtensionMenuItem::List submenu_items;
373 if (items.size() > 1 || items[0]->type() != ExtensionMenuItem::NORMAL) { 375 if (items.size() > 1 || items[0]->type() != ExtensionMenuItem::NORMAL) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 } 505 }
504 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", 506 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime",
505 base::TimeTicks::Now() - begin); 507 base::TimeTicks::Now() - begin);
506 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); 508 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index);
507 } 509 }
508 510
509 void RenderViewContextMenu::InitMenu() { 511 void RenderViewContextMenu::InitMenu() {
510 bool has_link = !params_.link_url.is_empty(); 512 bool has_link = !params_.link_url.is_empty();
511 bool has_selection = !params_.selection_text.empty(); 513 bool has_selection = !params_.selection_text.empty();
512 514
515 Browser* active_browser = BrowserList::GetLastActive();
asargent_no_longer_on_chrome 2011/12/09 05:34:21 nit: it's probably better to use BrowserList::Find
benwells 2011/12/12 05:30:39 That's much better.
516 if (active_browser) {
517 const Extension* platform_app = active_browser->GetPlatformApp();
asargent_no_longer_on_chrome 2011/12/09 05:34:21 Instead of having the GetPlatformApp method on the
benwells 2011/12/12 05:30:39 To use the URL I would have to look at page_url, n
518 if (platform_app) {
519 int index = 0;
520 AppendExtensionItems(platform_app->id(), &index);
521 return;
522 }
523 }
524
513 if (AppendCustomItems()) { 525 if (AppendCustomItems()) {
514 // If there's a selection, don't early return when there are custom items, 526 // If there's a selection, don't early return when there are custom items,
515 // but fall through to adding the normal ones after the custom ones. 527 // but fall through to adding the normal ones after the custom ones.
516 if (has_selection) { 528 if (has_selection) {
517 menu_model_.AddSeparator(); 529 menu_model_.AddSeparator();
518 } else { 530 } else {
519 // Don't add items for Pepper menu. 531 // Don't add items for Pepper menu.
520 if (!params_.custom_context.is_pepper_menu) 532 if (!params_.custom_context.is_pepper_menu)
521 AppendDeveloperItems(); 533 AppendDeveloperItems();
522 return; 534 return;
(...skipping 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), 1840 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages),
1829 g_browser_process->clipboard()); 1841 g_browser_process->clipboard());
1830 } 1842 }
1831 1843
1832 void RenderViewContextMenu::MediaPlayerActionAt( 1844 void RenderViewContextMenu::MediaPlayerActionAt(
1833 const gfx::Point& location, 1845 const gfx::Point& location,
1834 const WebMediaPlayerAction& action) { 1846 const WebMediaPlayerAction& action) {
1835 source_tab_contents_->render_view_host()-> 1847 source_tab_contents_->render_view_host()->
1836 ExecuteMediaPlayerActionAtLocation(location, action); 1848 ExecuteMediaPlayerActionAtLocation(location, action);
1837 } 1849 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698