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

Unified Diff: chrome/browser/tab_contents/render_view_context_menu.cc

Issue 6749021: Added new fileBrowserPrivate and fileHandler extension APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/tab_contents/render_view_context_menu.cc
===================================================================
--- chrome/browser/tab_contents/render_view_context_menu.cc (revision 81101)
+++ chrome/browser/tab_contents/render_view_context_menu.cc (working copy)
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <algorithm>
#include <set>
#include "chrome/browser/tab_contents/render_view_context_menu.h"
@@ -37,6 +36,7 @@
#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/browser/spellcheck_host.h"
#include "chrome/browser/spellchecker_platform_engine.h"
+#include "chrome/browser/tab_contents/context_menu_utils.h"
#include "chrome/browser/translate/translate_manager.h"
#include "chrome/browser/translate/translate_prefs.h"
#include "chrome/browser/ui/download/download_tab_helper.h"
@@ -199,87 +199,6 @@
PlatformInit();
}
-static bool ExtensionContextMatch(const ContextMenuParams& params,
- ExtensionMenuItem::ContextList contexts) {
- bool has_link = !params.link_url.is_empty();
- bool has_selection = !params.selection_text.empty();
- bool in_frame = !params.frame_url.is_empty();
-
- if (contexts.Contains(ExtensionMenuItem::ALL) ||
- (has_selection && contexts.Contains(ExtensionMenuItem::SELECTION)) ||
- (has_link && contexts.Contains(ExtensionMenuItem::LINK)) ||
- (params.is_editable && contexts.Contains(ExtensionMenuItem::EDITABLE)) ||
- (in_frame && contexts.Contains(ExtensionMenuItem::FRAME))) {
- return true;
- }
-
- switch (params.media_type) {
- case WebContextMenuData::MediaTypeImage:
- return contexts.Contains(ExtensionMenuItem::IMAGE);
-
- case WebContextMenuData::MediaTypeVideo:
- return contexts.Contains(ExtensionMenuItem::VIDEO);
-
- case WebContextMenuData::MediaTypeAudio:
- return contexts.Contains(ExtensionMenuItem::AUDIO);
-
- default:
- break;
- }
-
- // PAGE is the least specific context, so we only examine that if none of the
- // other contexts apply (except for FRAME, which is included in PAGE for
- // backwards compatibility).
- if (!has_link && !has_selection && !params.is_editable &&
- params.media_type == WebContextMenuData::MediaTypeNone &&
- contexts.Contains(ExtensionMenuItem::PAGE))
- return true;
-
- return false;
-}
-
-static bool ExtensionPatternMatch(const ExtensionExtent& patterns,
- const GURL& url) {
- // No patterns means no restriction, so that implicitly matches.
- if (patterns.is_empty())
- return true;
- return patterns.ContainsURL(url);
-}
-
-static const GURL& GetDocumentURL(const ContextMenuParams& params) {
- return params.frame_url.is_empty() ? params.page_url : params.frame_url;
-}
-
-// Given a list of items, returns the ones that match given the contents
-// of |params| and the profile.
-static ExtensionMenuItem::List GetRelevantExtensionItems(
- const ExtensionMenuItem::List& items,
- const ContextMenuParams& params,
- Profile* profile,
- bool can_cross_incognito) {
- ExtensionMenuItem::List result;
- for (ExtensionMenuItem::List::const_iterator i = items.begin();
- i != items.end(); ++i) {
- const ExtensionMenuItem* item = *i;
-
- if (!ExtensionContextMatch(params, item->contexts()))
- continue;
-
- const GURL& document_url = GetDocumentURL(params);
- if (!ExtensionPatternMatch(item->document_url_patterns(), document_url))
- continue;
-
- const GURL& target_url =
- params.src_url.is_empty() ? params.link_url : params.src_url;
- if (!ExtensionPatternMatch(item->target_url_patterns(), target_url))
- continue;
-
- if (item->id().profile == profile || can_cross_incognito)
- result.push_back(*i);
- }
- return result;
-}
-
void RenderViewContextMenu::AppendExtensionItems(
const std::string& extension_id, int* index) {
ExtensionService* service = profile_->GetExtensionService();
@@ -297,8 +216,10 @@
return;
bool can_cross_incognito = service->CanCrossIncognito(extension);
ExtensionMenuItem::List items =
- GetRelevantExtensionItems(*all_items, params_, profile_,
- can_cross_incognito);
+ ContextMenuUtils::GetRelevantExtensionItems(*all_items,
+ params_,
+ profile_,
+ can_cross_incognito);
if (items.empty())
return;
@@ -321,8 +242,8 @@
extension_item_map_[menu_id] = item->id();
title = item->TitleWithReplacement(PrintableSelectionText(),
kMaxExtensionItemTitleLength);
- submenu_items = GetRelevantExtensionItems(item->children(), params_,
- profile_, can_cross_incognito);
+ submenu_items = ContextMenuUtils::GetRelevantExtensionItems(
+ item->children(), params_, profile_, can_cross_incognito);
}
// Now add our item(s) to the menu_model_.
@@ -367,8 +288,8 @@
kMaxExtensionItemTitleLength);
if (item->type() == ExtensionMenuItem::NORMAL) {
ExtensionMenuItem::List children =
- GetRelevantExtensionItems(item->children(), params_,
- profile_, can_cross_incognito);
+ ContextMenuUtils::GetRelevantExtensionItems(
+ item->children(), params_, profile_, can_cross_incognito);
if (children.empty()) {
menu_model->AddItem(menu_id, title);
} else {
@@ -420,23 +341,13 @@
if (!service)
return; // In unit-tests, we may not have an ExtensionService.
ExtensionMenuManager* menu_manager = service->menu_manager();
- const GURL& document_url = GetDocumentURL(params_);
+ const GURL& document_url = ContextMenuUtils::GetDocumentURL(params_);
if (!menu_manager->HasAllowedScheme(document_url))
return;
- // Get a list of extension id's that have context menu items, and sort it by
- // the extension's name.
- std::set<std::string> ids = menu_manager->ExtensionIds();
std::vector<std::pair<std::string, std::string> > sorted_ids;
- for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) {
- const Extension* extension = service->GetExtensionById(*i, false);
- if (extension)
- sorted_ids.push_back(
- std::pair<std::string, std::string>(extension->name(), *i));
- }
- // TODO(asargent) - See if this works properly for i18n names (bug 32363).
- std::sort(sorted_ids.begin(), sorted_ids.end());
-
+ ContextMenuUtils::GetSortedContextMenuExtensionIds(service, menu_manager,
+ &sorted_ids);
if (sorted_ids.empty())
return;
@@ -509,10 +420,9 @@
case WebContextMenuData::MediaTypePlugin:
AppendPluginItems();
break;
-#ifdef WEBCONTEXT_MEDIATYPEFILE_DEFINED
case WebContextMenuData::MediaTypeFile:
+ AppendFileItems();
break;
-#endif
}
if (params_.is_editable)
@@ -602,6 +512,10 @@
IDS_CONTENT_CONTEXT_OPENVIDEONEWTAB);
}
+void RenderViewContextMenu::AppendFileItems() {
+ // TODO(zelidrag): Add file context operations here (i.e. cut, copy, paste...)
+}
+
void RenderViewContextMenu::AppendMediaItems() {
int media_flags = params_.media_flags;

Powered by Google App Engine
This is Rietveld 408576698