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

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: Moved code out of Browser 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 29 matching lines...) Expand all
40 #include "chrome/browser/search_engines/template_url_service_factory.h" 40 #include "chrome/browser/search_engines/template_url_service_factory.h"
41 #include "chrome/browser/spellchecker/spellcheck_host.h" 41 #include "chrome/browser/spellchecker/spellcheck_host.h"
42 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" 42 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
43 #include "chrome/browser/tab_contents/spellchecker_submenu_observer.h" 43 #include "chrome/browser/tab_contents/spellchecker_submenu_observer.h"
44 #include "chrome/browser/tab_contents/spelling_menu_observer.h" 44 #include "chrome/browser/tab_contents/spelling_menu_observer.h"
45 #include "chrome/browser/translate/translate_manager.h" 45 #include "chrome/browser/translate/translate_manager.h"
46 #include "chrome/browser/translate/translate_prefs.h" 46 #include "chrome/browser/translate/translate_prefs.h"
47 #include "chrome/browser/translate/translate_tab_helper.h" 47 #include "chrome/browser/translate/translate_tab_helper.h"
48 #include "chrome/browser/ui/browser.h" 48 #include "chrome/browser/ui/browser.h"
49 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" 49 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
50 #include "chrome/browser/ui/browser_list.h"
50 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" 51 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
51 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 52 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
53 #include "chrome/browser/web_applications/web_app.h"
52 #include "chrome/common/chrome_constants.h" 54 #include "chrome/common/chrome_constants.h"
53 #include "chrome/common/chrome_switches.h" 55 #include "chrome/common/chrome_switches.h"
54 #include "chrome/common/pref_names.h" 56 #include "chrome/common/pref_names.h"
55 #include "chrome/common/print_messages.h" 57 #include "chrome/common/print_messages.h"
56 #include "chrome/common/spellcheck_messages.h" 58 #include "chrome/common/spellcheck_messages.h"
57 #include "chrome/common/url_constants.h" 59 #include "chrome/common/url_constants.h"
58 #include "content/browser/child_process_security_policy.h" 60 #include "content/browser/child_process_security_policy.h"
59 #include "content/browser/download/download_manager.h" 61 #include "content/browser/download/download_manager.h"
60 #include "content/browser/download/download_stats.h" 62 #include "content/browser/download/download_stats.h"
61 #include "content/browser/download/save_package.h" 63 #include "content/browser/download/save_package.h"
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 const ExtensionMenuItem::List* all_items = manager->MenuItems(extension_id); 355 const ExtensionMenuItem::List* all_items = manager->MenuItems(extension_id);
354 if (!all_items || all_items->empty()) 356 if (!all_items || all_items->empty())
355 return; 357 return;
356 bool can_cross_incognito = service->CanCrossIncognito(extension); 358 bool can_cross_incognito = service->CanCrossIncognito(extension);
357 ExtensionMenuItem::List items = 359 ExtensionMenuItem::List items =
358 GetRelevantExtensionItems(*all_items, params_, profile_, 360 GetRelevantExtensionItems(*all_items, params_, profile_,
359 can_cross_incognito); 361 can_cross_incognito);
360 if (items.empty()) 362 if (items.empty())
361 return; 363 return;
362 364
363 // If this is the first extension-provided menu item, add a separator. 365 // If this is the first extension-provided menu item, and there are other
364 if (*index == 0) 366 // items in the menu, add a separator.
367 if (*index == 0 && menu_model_.GetItemCount())
365 menu_model_.AddSeparator(); 368 menu_model_.AddSeparator();
366 369
367 int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; 370 int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++;
368 371
369 // Extensions are only allowed one top-level slot (and it can't be a radio or 372 // Extensions are only allowed one top-level slot (and it can't be a radio or
370 // checkbox item because we are going to put the extension icon next to it). 373 // checkbox item because we are going to put the extension icon next to it).
371 // If they have more than that, we automatically push them into a submenu. 374 // If they have more than that, we automatically push them into a submenu.
372 string16 title; 375 string16 title;
373 ExtensionMenuItem::List submenu_items; 376 ExtensionMenuItem::List submenu_items;
374 if (items.size() > 1 || items[0]->type() != ExtensionMenuItem::NORMAL) { 377 if (items.size() > 1 || items[0]->type() != ExtensionMenuItem::NORMAL) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 } 507 }
505 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", 508 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime",
506 base::TimeTicks::Now() - begin); 509 base::TimeTicks::Now() - begin);
507 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); 510 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index);
508 } 511 }
509 512
510 void RenderViewContextMenu::InitMenu() { 513 void RenderViewContextMenu::InitMenu() {
511 bool has_link = !params_.unfiltered_link_url.is_empty(); 514 bool has_link = !params_.unfiltered_link_url.is_empty();
512 bool has_selection = !params_.selection_text.empty(); 515 bool has_selection = !params_.selection_text.empty();
513 516
517 Browser* active_browser = BrowserList::FindBrowserWithTabContents(
518 source_tab_contents_);
519 if (active_browser && active_browser->is_app()) {
520 const std::string ext_id = web_app::GetExtensionIdFromApplicationName(
521 active_browser->app_name());
522 const Extension* app =
523 profile_->GetExtensionService()->GetInstalledExtension(ext_id);
524 if (app && app->is_platform_app()) {
Mihai Parparita -not on Chrome 2011/12/13 01:12:45 It seems like you would also want to do another is
525 int index = 0;
526 AppendExtensionItems(app->id(), &index);
527 return;
528 }
529 }
530
514 if (AppendCustomItems()) { 531 if (AppendCustomItems()) {
515 // If there's a selection, don't early return when there are custom items, 532 // If there's a selection, don't early return when there are custom items,
516 // but fall through to adding the normal ones after the custom ones. 533 // but fall through to adding the normal ones after the custom ones.
517 if (has_selection) { 534 if (has_selection) {
518 menu_model_.AddSeparator(); 535 menu_model_.AddSeparator();
519 } else { 536 } else {
520 // Don't add items for Pepper menu. 537 // Don't add items for Pepper menu.
521 if (!params_.custom_context.is_pepper_menu) 538 if (!params_.custom_context.is_pepper_menu)
522 AppendDeveloperItems(); 539 AppendDeveloperItems();
523 return; 540 return;
(...skipping 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), 1857 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages),
1841 g_browser_process->clipboard()); 1858 g_browser_process->clipboard());
1842 } 1859 }
1843 1860
1844 void RenderViewContextMenu::MediaPlayerActionAt( 1861 void RenderViewContextMenu::MediaPlayerActionAt(
1845 const gfx::Point& location, 1862 const gfx::Point& location,
1846 const WebMediaPlayerAction& action) { 1863 const WebMediaPlayerAction& action) {
1847 source_tab_contents_->render_view_host()-> 1864 source_tab_contents_->render_view_host()->
1848 ExecuteMediaPlayerActionAtLocation(location, action); 1865 ExecuteMediaPlayerActionAtLocation(location, action);
1849 } 1866 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/platform_app_browsertest.cc ('k') | chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698