diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-09 14:36:33 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-09 14:36:33 +0000 |
commit | a0c7153edf226726a86619119c68f5e660b3930e (patch) | |
tree | 97ea32cf90057ed1c75c45e3c3f6718f12e67a6b /chrome/browser/tab_contents | |
parent | 33db7e323b9d6d1bd8cda94bc3fe5da1727c485a (diff) | |
download | chromium_src-a0c7153edf226726a86619119c68f5e660b3930e.zip chromium_src-a0c7153edf226726a86619119c68f5e660b3930e.tar.gz chromium_src-a0c7153edf226726a86619119c68f5e660b3930e.tar.bz2 |
Chromium: support custom WebCore context menu items in Chromium port (downstream).
Review URL: http://codereview.chromium.org/465123
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34154 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r-- | chrome/browser/tab_contents/render_view_context_menu.cc | 37 | ||||
-rw-r--r-- | chrome/browser/tab_contents/render_view_context_menu.h | 1 |
2 files changed, 38 insertions, 0 deletions
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index d7d299a..5292a68 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -32,6 +32,7 @@ #include "grit/generated_resources.h" #include "net/base/escape.h" #include "net/url_request/url_request.h" +#include "webkit/glue/webmenuitem.h" #include "third_party/WebKit/WebKit/chromium/public/WebMediaPlayerAction.h" #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" @@ -60,6 +61,11 @@ void RenderViewContextMenu::InitMenu() { bool has_link = !params_.link_url.is_empty(); bool has_selection = !params_.selection_text.empty(); + if (AppendCustomItems()) { + AppendDeveloperItems(); + return; + } + // When no special node or text is selected and selection has no link, // show page items. if (params_.media_type == WebContextMenuData::MediaTypeNone && @@ -105,6 +111,17 @@ void RenderViewContextMenu::InitMenu() { AppendDeveloperItems(); } +bool RenderViewContextMenu::AppendCustomItems() { + std::vector<WebMenuItem>& custom_items = params_.custom_items; + for (size_t i = 0; i < custom_items.size(); ++i) { + DCHECK(IDC_CONTENT_CONTEXT_CUSTOM_FIRST + custom_items[i].action < + IDC_CONTENT_CONTEXT_CUSTOM_LAST); + AppendMenuItem(custom_items[i].action + IDC_CONTENT_CONTEXT_CUSTOM_FIRST, + custom_items[i].label); + } + return custom_items.size() > 0; +} + void RenderViewContextMenu::AppendDeveloperItems() { if (g_browser_process->have_inspector_files()) { AppendSeparator(); @@ -317,6 +334,18 @@ bool RenderViewContextMenu::IsItemCommandEnabled(int id) const { return profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck); } + // Process custom actions range. + if ((id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST) && + (id < IDC_CONTENT_CONTEXT_CUSTOM_LAST)) { + unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST; + for (size_t i = 0; i < params_.custom_items.size(); ++i) { + if (params_.custom_items[i].action == action) + return params_.custom_items[i].enabled; + } + NOTREACHED(); + return false; + } + switch (id) { case IDS_CONTENT_CONTEXT_BACK: return source_tab_contents_->controller().CanGoBack(); @@ -506,7 +535,15 @@ void RenderViewContextMenu::ExecuteItemCommand(int id) { profile_->GetPrefs(), NULL); dictionary_language.SetValue(ASCIIToWide(languages[language_number])); } + return; + } + // Process custom actions range. + if ((id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST) && + (id < IDC_CONTENT_CONTEXT_CUSTOM_LAST)) { + unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST; + source_tab_contents_->render_view_host()-> + PerformCustomContextMenuAction(action); return; } diff --git a/chrome/browser/tab_contents/render_view_context_menu.h b/chrome/browser/tab_contents/render_view_context_menu.h index 599051f..a4bb376 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.h +++ b/chrome/browser/tab_contents/render_view_context_menu.h @@ -76,6 +76,7 @@ class RenderViewContextMenu { Profile* profile_; private: + bool AppendCustomItems(); void AppendDeveloperItems(); void AppendLinkItems(); void AppendImageItems(); |