| Index: chrome/browser/tab_contents/render_view_context_menu.cc
|
| ===================================================================
|
| --- chrome/browser/tab_contents/render_view_context_menu.cc (revision 80841)
|
| +++ chrome/browser/tab_contents/render_view_context_menu.cc (working copy)
|
| @@ -36,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_prefs.h"
|
| #include "chrome/browser/translate/translate_manager.h"
|
| #include "chrome/common/chrome_constants.h"
|
| @@ -196,87 +197,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();
|
| @@ -294,8 +214,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;
|
|
|
| @@ -318,8 +240,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_.
|
| @@ -364,8 +286,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 {
|
| @@ -417,7 +339,7 @@
|
| 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;
|
|
|
| @@ -506,10 +428,9 @@
|
| case WebContextMenuData::MediaTypePlugin:
|
| AppendPluginItems();
|
| break;
|
| -#ifdef WEBCONTEXT_MEDIATYPEFILE_DEFINED
|
| case WebContextMenuData::MediaTypeFile:
|
| + AppendFileItems();
|
| break;
|
| -#endif
|
| }
|
|
|
| if (params_.is_editable)
|
| @@ -599,6 +520,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;
|
|
|
|
|