summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-07 01:06:38 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-07 01:06:38 +0000
commitef3a0f2426d7d5618a7b0503b4b0260c8d616dc9 (patch)
tree7f8db9ffab7bd9d48420dedea8f0a985a0c8987b
parent666f176c1156fba64ce6c9c935455fdf526be2e7 (diff)
downloadchromium_src-ef3a0f2426d7d5618a7b0503b4b0260c8d616dc9.zip
chromium_src-ef3a0f2426d7d5618a7b0503b4b0260c8d616dc9.tar.gz
chromium_src-ef3a0f2426d7d5618a7b0503b4b0260c8d616dc9.tar.bz2
Refactor render view context menu in preparation for porting.
* RenderViewContextMenu is now cross platform. Each platform needs to implement an inheritor that fills in the virtual methods. * RenderViewContextMenuController was deleted. Platform agnostic elements from it were added to RenderViewContextMenu, while the Menu::Delegate implemenation was moved to RenderViewContextMenuWin. * Some more (minor) refactoring may need to be performed as the rest of the menu actions are ported. * include clipboard_service.h on all platforms (not sure why it wasn't included before) Review URL: http://codereview.chromium.org/40249 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11183 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser.scons2
-rw-r--r--chrome/browser/browser.vcproj4
-rw-r--r--chrome/browser/browser_process_impl.cc2
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.cc2
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc599
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.h85
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu_controller.cc547
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu_controller.h67
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu_win.cc117
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu_win.h48
-rw-r--r--chrome/browser/tab_contents/web_contents_view_win.cc13
-rw-r--r--chrome/chrome.gyp2
-rw-r--r--chrome/common/clipboard_service.h13
-rw-r--r--chrome/common/temp_scaffolding_stubs.h4
14 files changed, 774 insertions, 731 deletions
diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons
index f49195a1..ef38df4 100644
--- a/chrome/browser/browser.scons
+++ b/chrome/browser/browser.scons
@@ -570,8 +570,6 @@ input_files = ChromeFileList([
'tab_contents/provisional_load_details.h',
'tab_contents/render_view_context_menu.cc',
'tab_contents/render_view_context_menu.h',
- 'tab_contents/render_view_context_menu_controller.cc',
- 'tab_contents/render_view_context_menu_controller.h',
'tab_contents/render_view_host_manager.cc',
'tab_contents/render_view_host_manager.h',
'tab_contents/repost_form_warning.h',
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj
index 9c63f9c..c7827fa 100644
--- a/chrome/browser/browser.vcproj
+++ b/chrome/browser/browser.vcproj
@@ -2158,11 +2158,11 @@
>
</File>
<File
- RelativePath=".\tab_contents\render_view_context_menu_controller.cc"
+ RelativePath=".\tab_contents\render_view_context_menu_win.cc"
>
</File>
<File
- RelativePath=".\tab_contents\render_view_context_menu_controller.h"
+ RelativePath=".\tab_contents\render_view_context_menu_win.h"
>
</File>
<File
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 4afa27b..99d3325 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -23,6 +23,7 @@
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/clipboard_service.h"
#include "chrome/common/l10n_util.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
@@ -32,7 +33,6 @@
#include "chrome/browser/automation/automation_provider_list.h"
#include "chrome/browser/icon_manager.h"
#include "chrome/browser/printing/print_job_manager.h"
-#include "chrome/common/clipboard_service.h"
#include "chrome/views/accelerator_handler.h"
#include "chrome/views/view_storage.h"
#elif defined(OS_POSIX)
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index 4460c37..4fce635 100644
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -25,6 +25,7 @@
#include "chrome/browser/worker_host/worker_service.h"
#include "chrome/common/chrome_plugin_lib.h"
#include "chrome/common/chrome_plugin_util.h"
+#include "chrome/common/clipboard_service.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
@@ -38,7 +39,6 @@
#if defined(OS_WIN)
#include "chrome/browser/printing/print_job_manager.h"
#include "chrome/browser/printing/printer_query.h"
-#include "chrome/common/clipboard_service.h"
#elif defined(OS_MACOSX) || defined(OS_LINUX)
// TODO(port) remove this.
#include "chrome/common/temp_scaffolding_stubs.h"
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index 5c0256d..457f6f5 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -4,32 +4,43 @@
#include "chrome/browser/tab_contents/render_view_context_menu.h"
+#include "base/command_line.h"
#include "base/logging.h"
+#include "base/scoped_clipboard_writer.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/browser/spellchecker.h"
+#include "chrome/browser/tab_contents/navigation_entry.h"
+#include "chrome/browser/tab_contents/web_contents.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/clipboard_service.h"
#include "chrome/common/l10n_util.h"
+#include "chrome/common/pref_service.h"
+#include "chrome/common/url_constants.h"
#include "grit/generated_resources.h"
+#if defined(OS_WIN)
+#include "chrome/browser/views/options/fonts_languages_window_view.h"
+#include "chrome/browser/views/page_info_window.h"
+#include "chrome/common/win_util.h"
+#endif
+
RenderViewContextMenu::RenderViewContextMenu(
- Menu::Delegate* delegate,
- gfx::NativeWindow owner,
- ContextNode node,
- const std::wstring& misspelled_word,
- const std::vector<std::wstring>& misspelled_word_suggestions,
- Profile* profile)
- : Menu(delegate, Menu::TOPLEFT, owner),
- misspelled_word_(misspelled_word),
- misspelled_word_suggestions_(misspelled_word_suggestions),
- profile_(profile) {
- InitMenu(node);
+ WebContents* web_contents,
+ const ContextMenuParams& params)
+ : params_(params),
+ source_web_contents_(web_contents),
+ profile_(web_contents->profile()) {
}
RenderViewContextMenu::~RenderViewContextMenu() {
}
+// Menu construction functions -------------------------------------------------
+
void RenderViewContextMenu::InitMenu(ContextNode node) {
if (node.type & ContextNode::PAGE)
AppendPageItems();
@@ -57,91 +68,103 @@ void RenderViewContextMenu::InitMenu(ContextNode node) {
}
void RenderViewContextMenu::AppendDeveloperItems() {
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_INSPECTELEMENT);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_INSPECTELEMENT);
}
void RenderViewContextMenu::AppendLinkItems() {
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_OPENLINKNEWTAB);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_SAVELINKAS);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_COPYLINKLOCATION);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_OPENLINKNEWTAB);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_SAVELINKAS);
+
+ if (params_.link_url.SchemeIs(chrome::kMailToScheme)) {
+ AppendMenuItem(IDS_CONTENT_CONTEXT_COPYLINKLOCATION,
+ l10n_util::GetString(IDS_CONTENT_CONTEXT_COPYEMAILADDRESS));
+ } else {
+ AppendMenuItem(IDS_CONTENT_CONTEXT_COPYLINKLOCATION);
+ }
}
void RenderViewContextMenu::AppendImageItems() {
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_SAVEIMAGEAS);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_COPYIMAGELOCATION);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_COPYIMAGE);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_SAVEIMAGEAS);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_COPYIMAGELOCATION);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_COPYIMAGE);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB);
}
void RenderViewContextMenu::AppendPageItems() {
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_BACK);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_FORWARD);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_RELOAD);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_BACK);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_FORWARD);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_RELOAD);
AppendSeparator();
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_SAVEPAGEAS);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_PRINT);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_VIEWPAGESOURCE);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_VIEWPAGEINFO);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_SAVEPAGEAS);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_PRINT);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_VIEWPAGESOURCE);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_VIEWPAGEINFO);
}
void RenderViewContextMenu::AppendFrameItems() {
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_BACK);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_FORWARD);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_BACK);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_FORWARD);
AppendSeparator();
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_OPENFRAMENEWTAB);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_OPENFRAMENEWWINDOW);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_OPENFRAMEOFFTHERECORD);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_OPENFRAMENEWTAB);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_OPENFRAMENEWWINDOW);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_OPENFRAMEOFFTHERECORD);
AppendSeparator();
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_SAVEFRAMEAS);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_PRINTFRAME);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_VIEWFRAMESOURCE);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_VIEWFRAMEINFO);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_SAVEFRAMEAS);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_PRINTFRAME);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_VIEWFRAMESOURCE);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_VIEWFRAMEINFO);
}
void RenderViewContextMenu::AppendCopyItem() {
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_COPY);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_COPY);
}
void RenderViewContextMenu::AppendSearchProvider() {
DCHECK(profile_);
- if (profile_->GetTemplateURLModel()->GetDefaultSearchProvider() != NULL)
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_SEARCHWEBFOR);
+ const TemplateURL* const default_provider =
+ profile_->GetTemplateURLModel()->GetDefaultSearchProvider();
+ if (default_provider != NULL) {
+ std::wstring label(l10n_util::GetStringF(IDS_CONTENT_CONTEXT_SEARCHWEBFOR,
+ default_provider->short_name(),
+ l10n_util::TruncateString(params_.selection_text, 50)));
+ AppendMenuItem(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, label);
+ }
}
void RenderViewContextMenu::AppendEditableItems() {
// Append Dictionary spell check suggestions.
- for (size_t i = 0; i < misspelled_word_suggestions_.size() &&
+ for (size_t i = 0; i < params_.dictionary_suggestions.size() &&
IDC_SPELLCHECK_SUGGESTION_0 + i <= IDC_SPELLCHECK_SUGGESTION_LAST;
- i ++) {
- AppendMenuItemWithLabel(IDC_SPELLCHECK_SUGGESTION_0 + static_cast<int>(i),
- misspelled_word_suggestions_[i]);
+ ++i) {
+ AppendMenuItem(IDC_SPELLCHECK_SUGGESTION_0 + static_cast<int>(i),
+ params_.dictionary_suggestions[i]);
}
- if (misspelled_word_suggestions_.size() > 0)
+ if (params_.dictionary_suggestions.size() > 0)
AppendSeparator();
// If word is misspelled, give option for "Add to dictionary"
- if (!misspelled_word_.empty()) {
- if (misspelled_word_suggestions_.size() == 0) {
- AppendMenuItemWithLabel(0,
+ if (!params_.misspelled_word.empty()) {
+ if (params_.dictionary_suggestions.size() == 0) {
+ AppendMenuItem(0,
l10n_util::GetString(IDS_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS));
}
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY);
AppendSeparator();
}
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_UNDO);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_REDO);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_UNDO);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_REDO);
AppendSeparator();
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_CUT);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_COPY);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_PASTE);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_DELETE);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_CUT);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_COPY);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_PASTE);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_DELETE);
AppendSeparator();
// Add Spell Check options sub menu.
- spellchecker_sub_menu_ = AppendSubMenu(IDC_SPELLCHECK_MENU,
+ StartSubMenu(IDC_SPELLCHECK_MENU,
l10n_util::GetString(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU));
// Add Spell Check languages to sub menu.
@@ -154,21 +177,467 @@ void RenderViewContextMenu::AppendEditableItems() {
for (size_t i = 0; i < display_languages.size(); ++i) {
std::wstring local_language(l10n_util::GetLocalName(
display_languages[i], app_locale, true));
- spellchecker_sub_menu_->AppendMenuItem(
- IDC_SPELLCHECK_LANGUAGES_FIRST + i, local_language, RADIO);
+ AppendRadioMenuItem(IDC_SPELLCHECK_LANGUAGES_FIRST + i, local_language);
}
// Add item in the sub menu to pop up the fonts and languages options menu.
- spellchecker_sub_menu_->AppendSeparator();
- spellchecker_sub_menu_->AppendDelegateMenuItem(
- IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS);
+ AppendSeparator();
+ AppendMenuItem(IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS);
// Add 'Check the spelling of this field' item in the sub menu.
- spellchecker_sub_menu_->AppendMenuItem(
+ AppendCheckboxMenuItem(
IDC_CHECK_SPELLING_OF_THIS_FIELD,
- l10n_util::GetString(IDS_CONTENT_CONTEXT_CHECK_SPELLING_OF_THIS_FIELD),
- CHECKBOX);
+ l10n_util::GetString(IDS_CONTENT_CONTEXT_CHECK_SPELLING_OF_THIS_FIELD));
+
+ FinishSubMenu();
AppendSeparator();
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_SELECTALL);
+ AppendMenuItem(IDS_CONTENT_CONTEXT_SELECTALL);
+}
+
+// Menu delegate functions -----------------------------------------------------
+
+bool RenderViewContextMenu::IsItemCommandEnabled(int id) const {
+ // Allow Spell Check language items on sub menu for text area context menu.
+ if ((id >= IDC_SPELLCHECK_LANGUAGES_FIRST) &&
+ (id < IDC_SPELLCHECK_LANGUAGES_LAST)) {
+ return true;
+ }
+
+ switch (id) {
+ case IDS_CONTENT_CONTEXT_BACK:
+ return source_web_contents_->controller()->CanGoBack();
+
+ case IDS_CONTENT_CONTEXT_FORWARD:
+ return source_web_contents_->controller()->CanGoForward();
+
+ case IDS_CONTENT_CONTEXT_VIEWPAGESOURCE:
+ case IDS_CONTENT_CONTEXT_VIEWFRAMESOURCE:
+ case IDS_CONTENT_CONTEXT_INSPECTELEMENT:
+ return IsDevCommandEnabled(id);
+
+ case IDS_CONTENT_CONTEXT_OPENLINKNEWTAB:
+ case IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW:
+ case IDS_CONTENT_CONTEXT_COPYLINKLOCATION:
+ return params_.link_url.is_valid();
+
+ case IDS_CONTENT_CONTEXT_SAVELINKAS:
+ return params_.link_url.is_valid() &&
+ URLRequest::IsHandledURL(params_.link_url);
+
+ case IDS_CONTENT_CONTEXT_SAVEIMAGEAS:
+ return params_.image_url.is_valid() &&
+ URLRequest::IsHandledURL(params_.image_url);
+
+ case IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB:
+ // The images shown in the most visited thumbnails do not currently open
+ // in a new tab as they should. Disabling this context menu option for
+ // now, as a quick hack, before we resolve this issue (Issue = 2608).
+ // TODO (sidchat): Enable this option once this issue is resolved.
+ if (params_.image_url.scheme() == "chrome-ui")
+ return false;
+ return true;
+
+ case IDS_CONTENT_CONTEXT_COPYIMAGELOCATION:
+ return params_.image_url.is_valid();
+
+ case IDS_CONTENT_CONTEXT_SAVEPAGEAS:
+ return SavePackage::IsSavableURL(source_web_contents_->GetURL());
+
+ case IDS_CONTENT_CONTEXT_OPENFRAMENEWTAB:
+ case IDS_CONTENT_CONTEXT_OPENFRAMENEWWINDOW:
+ return params_.frame_url.is_valid();
+
+ case IDS_CONTENT_CONTEXT_UNDO:
+ return !!(params_.edit_flags & ContextNode::CAN_UNDO);
+
+ case IDS_CONTENT_CONTEXT_REDO:
+ return !!(params_.edit_flags & ContextNode::CAN_REDO);
+
+ case IDS_CONTENT_CONTEXT_CUT:
+ return !!(params_.edit_flags & ContextNode::CAN_CUT);
+
+ case IDS_CONTENT_CONTEXT_COPY:
+ return !!(params_.edit_flags & ContextNode::CAN_COPY);
+
+ case IDS_CONTENT_CONTEXT_PASTE:
+ return !!(params_.edit_flags & ContextNode::CAN_PASTE);
+
+ case IDS_CONTENT_CONTEXT_DELETE:
+ return !!(params_.edit_flags & ContextNode::CAN_DELETE);
+
+ case IDS_CONTENT_CONTEXT_SELECTALL:
+ return !!(params_.edit_flags & ContextNode::CAN_SELECT_ALL);
+
+ case IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD:
+ return !source_web_contents_->profile()->IsOffTheRecord() &&
+ params_.link_url.is_valid();
+
+ case IDS_CONTENT_CONTEXT_OPENFRAMEOFFTHERECORD:
+ return !source_web_contents_->profile()->IsOffTheRecord() &&
+ params_.frame_url.is_valid();
+
+ case IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY:
+ return !params_.misspelled_word.empty();
+
+ case IDS_CONTENT_CONTEXT_VIEWPAGEINFO:
+ return (source_web_contents_->controller()->GetActiveEntry() != NULL);
+
+ case IDS_CONTENT_CONTEXT_RELOAD:
+ case IDS_CONTENT_CONTEXT_COPYIMAGE:
+ case IDS_CONTENT_CONTEXT_PRINT:
+ case IDS_CONTENT_CONTEXT_SEARCHWEBFOR:
+ case IDC_SPELLCHECK_SUGGESTION_0:
+ case IDC_SPELLCHECK_SUGGESTION_1:
+ case IDC_SPELLCHECK_SUGGESTION_2:
+ case IDC_SPELLCHECK_SUGGESTION_3:
+ case IDC_SPELLCHECK_SUGGESTION_4:
+ case IDC_SPELLCHECK_MENU:
+ case IDC_CHECK_SPELLING_OF_THIS_FIELD:
+ case IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS:
+ case IDS_CONTENT_CONTEXT_VIEWFRAMEINFO:
+ return true;
+
+ case IDS_CONTENT_CONTEXT_SAVEFRAMEAS:
+ case IDS_CONTENT_CONTEXT_PRINTFRAME:
+ case IDS_CONTENT_CONTEXT_ADDSEARCHENGINE: // Not implemented.
+ default:
+ return false;
+ }
+}
+
+bool RenderViewContextMenu::ItemIsChecked(int id) const {
+ // Check box for 'Check the Spelling of this field'.
+ if (id == IDC_CHECK_SPELLING_OF_THIS_FIELD)
+ return params_.spellcheck_enabled;
+
+ // Don't bother getting the display language vector if this isn't a spellcheck
+ // language.
+ if ((id < IDC_SPELLCHECK_LANGUAGES_FIRST) ||
+ (id >= IDC_SPELLCHECK_LANGUAGES_LAST))
+ return false;
+
+ SpellChecker::Languages display_languages;
+ return SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu(
+ source_web_contents_->profile(), &display_languages) ==
+ (id - IDC_SPELLCHECK_LANGUAGES_FIRST);
+}
+
+void RenderViewContextMenu::ExecuteItemCommand(int id) {
+ // Check to see if one of the spell check language ids have been clicked.
+ if (id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
+ id < IDC_SPELLCHECK_LANGUAGES_LAST) {
+ const size_t language_number = id - IDC_SPELLCHECK_LANGUAGES_FIRST;
+ SpellChecker::Languages display_languages;
+ SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu(
+ source_web_contents_->profile(), &display_languages);
+ if (language_number < display_languages.size()) {
+ StringPrefMember dictionary_language;
+ dictionary_language.Init(prefs::kSpellCheckDictionary,
+ source_web_contents_->profile()->GetPrefs(), NULL);
+ dictionary_language.SetValue(display_languages[language_number]);
+ }
+
+ return;
+ }
+
+ switch (id) {
+ case IDS_CONTENT_CONTEXT_OPENLINKNEWTAB:
+ OpenURL(params_.link_url, NEW_BACKGROUND_TAB, PageTransition::LINK);
+ break;
+
+ case IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW:
+ OpenURL(params_.link_url, NEW_WINDOW, PageTransition::LINK);
+ break;
+
+ case IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD:
+ OpenURL(params_.link_url, OFF_THE_RECORD, PageTransition::LINK);
+ break;
+
+ // TODO(paulg): Prompt the user for file name when saving links and images.
+ case IDS_CONTENT_CONTEXT_SAVEIMAGEAS:
+ case IDS_CONTENT_CONTEXT_SAVELINKAS: {
+ const GURL& referrer =
+ params_.frame_url.is_empty() ? params_.page_url : params_.frame_url;
+ const GURL& url =
+ (id == IDS_CONTENT_CONTEXT_SAVELINKAS ? params_.link_url :
+ params_.image_url);
+ DownloadManager* dlm =
+ source_web_contents_->profile()->GetDownloadManager();
+ dlm->DownloadUrl(url, referrer, source_web_contents_);
+ break;
+ }
+
+ case IDS_CONTENT_CONTEXT_COPYLINKLOCATION:
+ WriteURLToClipboard(params_.link_url);
+ break;
+
+ case IDS_CONTENT_CONTEXT_COPYIMAGELOCATION:
+ WriteURLToClipboard(params_.image_url);
+ break;
+
+ case IDS_CONTENT_CONTEXT_COPYIMAGE:
+ CopyImageAt(params_.x, params_.y);
+ break;
+
+ case IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB:
+ OpenURL(params_.image_url, NEW_BACKGROUND_TAB, PageTransition::LINK);
+ break;
+
+ case IDS_CONTENT_CONTEXT_BACK:
+ source_web_contents_->controller()->GoBack();
+ break;
+
+ case IDS_CONTENT_CONTEXT_FORWARD:
+ source_web_contents_->controller()->GoForward();
+ break;
+
+ case IDS_CONTENT_CONTEXT_SAVEPAGEAS:
+ source_web_contents_->OnSavePage();
+ break;
+
+ case IDS_CONTENT_CONTEXT_RELOAD:
+ source_web_contents_->controller()->Reload(true);
+ break;
+
+ case IDS_CONTENT_CONTEXT_PRINT:
+ source_web_contents_->PrintPreview();
+ break;
+
+ case IDS_CONTENT_CONTEXT_VIEWPAGESOURCE:
+ OpenURL(GURL("view-source:" + params_.page_url.spec()),
+ NEW_FOREGROUND_TAB, PageTransition::GENERATED);
+ break;
+
+ case IDS_CONTENT_CONTEXT_INSPECTELEMENT:
+ Inspect(params_.x, params_.y);
+ break;
+
+ case IDS_CONTENT_CONTEXT_VIEWPAGEINFO: {
+#if defined(OS_WIN)
+ NavigationEntry* nav_entry =
+ source_web_contents_->controller()->GetActiveEntry();
+ PageInfoWindow::CreatePageInfo(
+ source_web_contents_->profile(),
+ nav_entry,
+ source_web_contents_->GetContentNativeView(),
+ PageInfoWindow::SECURITY);
+#else
+ // TODO(port): port PageInfoWindow.
+ NOTIMPLEMENTED() << "IDS_CONTENT_CONTEXT_VIEWPAGEINFO";
+#endif
+ break;
+ }
+
+ case IDS_CONTENT_CONTEXT_OPENFRAMENEWTAB:
+ OpenURL(params_.frame_url, NEW_BACKGROUND_TAB, PageTransition::LINK);
+ break;
+
+ case IDS_CONTENT_CONTEXT_OPENFRAMENEWWINDOW:
+ OpenURL(params_.frame_url, NEW_WINDOW, PageTransition::LINK);
+ break;
+
+ case IDS_CONTENT_CONTEXT_OPENFRAMEOFFTHERECORD:
+ OpenURL(params_.frame_url, OFF_THE_RECORD, PageTransition::LINK);
+ break;
+
+ case IDS_CONTENT_CONTEXT_SAVEFRAMEAS:
+#if defined(OS_WIN)
+ win_util::MessageBox(NULL, L"Context Menu Action", L"Save Frame As",
+ MB_OK);
+#else
+ // TODO(port): message box equivalent
+ NOTIMPLEMENTED() << "IDS_CONTENT_CONTEXT_SAVEFRAMEAS";
+#endif
+ break;
+
+ case IDS_CONTENT_CONTEXT_PRINTFRAME:
+#if defined(OS_WIN)
+ win_util::MessageBox(NULL, L"Context Menu Action", L"Print Frame",
+ MB_OK);
+#else
+ // TODO(port): message box equivalent
+ NOTIMPLEMENTED() << "IDS_CONTENT_CONTEXT_PRINTFRAME";
+#endif
+ break;
+
+ case IDS_CONTENT_CONTEXT_VIEWFRAMESOURCE:
+ OpenURL(GURL("view-source:" + params_.frame_url.spec()),
+ NEW_FOREGROUND_TAB, PageTransition::GENERATED);
+ break;
+
+ case IDS_CONTENT_CONTEXT_VIEWFRAMEINFO: {
+ // Deserialize the SSL info.
+ NavigationEntry::SSLStatus ssl;
+ if (!params_.security_info.empty()) {
+ int cert_id, cert_status, security_bits;
+ SSLManager::DeserializeSecurityInfo(params_.security_info,
+ &cert_id,
+ &cert_status,
+ &security_bits);
+ ssl.set_cert_id(cert_id);
+ ssl.set_cert_status(cert_status);
+ ssl.set_security_bits(security_bits);
+ }
+ PageInfoWindow::CreateFrameInfo(
+ source_web_contents_->profile(),
+ params_.frame_url,
+ ssl,
+ source_web_contents_->GetContentNativeView(),
+ PageInfoWindow::SECURITY);
+ break;
+ }
+
+ case IDS_CONTENT_CONTEXT_UNDO:
+ source_web_contents_->render_view_host()->Undo();
+ break;
+
+ case IDS_CONTENT_CONTEXT_REDO:
+ source_web_contents_->render_view_host()->Redo();
+ break;
+
+ case IDS_CONTENT_CONTEXT_CUT:
+ source_web_contents_->render_view_host()->Cut();
+ break;
+
+ case IDS_CONTENT_CONTEXT_COPY:
+ source_web_contents_->render_view_host()->Copy();
+ break;
+
+ case IDS_CONTENT_CONTEXT_PASTE:
+ source_web_contents_->render_view_host()->Paste();
+ break;
+
+ case IDS_CONTENT_CONTEXT_DELETE:
+ source_web_contents_->render_view_host()->Delete();
+ break;
+
+ case IDS_CONTENT_CONTEXT_SELECTALL:
+ source_web_contents_->render_view_host()->SelectAll();
+ break;
+
+ case IDS_CONTENT_CONTEXT_SEARCHWEBFOR: {
+ const TemplateURL* const default_provider = source_web_contents_->
+ profile()->GetTemplateURLModel()->GetDefaultSearchProvider();
+ DCHECK(default_provider); // The context menu should not contain this
+ // item when there is no provider.
+ const TemplateURLRef* const search_url = default_provider->url();
+ DCHECK(search_url->SupportsReplacement());
+ OpenURL(GURL(search_url->ReplaceSearchTerms(*default_provider,
+ params_.selection_text, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE,
+ std::wstring())), NEW_FOREGROUND_TAB, PageTransition::GENERATED);
+ break;
+ }
+
+ case IDC_SPELLCHECK_SUGGESTION_0:
+ case IDC_SPELLCHECK_SUGGESTION_1:
+ case IDC_SPELLCHECK_SUGGESTION_2:
+ case IDC_SPELLCHECK_SUGGESTION_3:
+ case IDC_SPELLCHECK_SUGGESTION_4:
+ source_web_contents_->render_view_host()->Replace(
+ params_.dictionary_suggestions[id - IDC_SPELLCHECK_SUGGESTION_0]);
+ break;
+
+ case IDC_CHECK_SPELLING_OF_THIS_FIELD:
+ source_web_contents_->render_view_host()->ToggleSpellCheck();
+ break;
+ case IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY:
+ source_web_contents_->render_view_host()->AddToDictionary(
+ params_.misspelled_word);
+ break;
+
+ case IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS: {
+#if defined(OS_WIN)
+ FontsLanguagesWindowView* window_ = new FontsLanguagesWindowView(
+ source_web_contents_->profile());
+ views::Window::CreateChromeWindow(
+ source_web_contents_->GetContentNativeView(),
+ gfx::Rect(), window_)->Show();
+ window_->SelectLanguagesTab();
+#else
+ // TODO(port): need views::Window
+ NOTIMPLEMENTED() << "IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS";
+#endif
+ break;
+ }
+
+ case IDS_CONTENT_CONTEXT_ADDSEARCHENGINE: // Not implemented.
+ default:
+ break;
+ }
+}
+
+bool RenderViewContextMenu::IsDevCommandEnabled(int id) const {
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ if (command_line.HasSwitch(switches::kAlwaysEnableDevTools))
+ return true;
+
+ NavigationEntry *active_entry =
+ source_web_contents_->controller()->GetActiveEntry();
+ if (!active_entry)
+ return false;
+
+ // Don't inspect HTML dialogs.
+ if (source_web_contents_->type() == TAB_CONTENTS_HTML_DIALOG)
+ return false;
+
+ // Don't inspect view source.
+ if (active_entry->IsViewSourceMode())
+ return false;
+
+ // Don't inspect inspector, new tab UI, etc.
+ if (active_entry->url().SchemeIs(chrome::kChromeUIScheme))
+ return false;
+
+ // Don't inspect about:network, about:memory, etc.
+ // However, we do want to inspect about:blank, which is often
+ // used by ordinary web pages.
+ if (active_entry->display_url().SchemeIs(chrome::kAboutScheme) &&
+ !LowerCaseEqualsASCII(active_entry->display_url().path(), "blank"))
+ return false;
+
+ // Don't enable the web inspector if JavaScript is disabled
+ if (id == IDS_CONTENT_CONTEXT_INSPECTELEMENT) {
+ PrefService* prefs = source_web_contents_->profile()->GetPrefs();
+ if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled) ||
+ command_line.HasSwitch(switches::kDisableJavaScript))
+ return false;
+ }
+
+ return true;
+}
+
+// Controller functions --------------------------------------------------------
+
+void RenderViewContextMenu::OpenURL(
+ const GURL& url,
+ WindowOpenDisposition disposition,
+ PageTransition::Type transition) {
+ source_web_contents_->OpenURL(url, GURL(), disposition, transition);
+}
+
+void RenderViewContextMenu::CopyImageAt(int x, int y) {
+ source_web_contents_->render_view_host()->CopyImageAt(x, y);
+}
+
+void RenderViewContextMenu::Inspect(int x, int y) {
+ source_web_contents_->render_view_host()->InspectElementAt(x, y);
+}
+
+void RenderViewContextMenu::WriteTextToClipboard(
+ const string16& text) {
+ ClipboardService* clipboard = g_browser_process->clipboard_service();
+
+ if (!clipboard)
+ return;
+
+ ScopedClipboardWriter scw(clipboard);
+ scw.WriteText(text);
+}
+
+void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) {
+ if (url.SchemeIs(chrome::kMailToScheme))
+ WriteTextToClipboard(UTF8ToUTF16(url.path()));
+ else
+ WriteTextToClipboard(UTF8ToUTF16(url.spec()));
}
diff --git a/chrome/browser/tab_contents/render_view_context_menu.h b/chrome/browser/tab_contents/render_view_context_menu.h
index c79b5a4..d6dfaf1 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.h
+++ b/chrome/browser/tab_contents/render_view_context_menu.h
@@ -5,34 +5,59 @@
#ifndef CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_
#define CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_
-#include <vector>
-
-#include "base/gfx/native_widget_types.h"
+#include "base/string16.h"
+#include "chrome/common/page_transition_types.h"
#include "webkit/glue/context_menu.h"
-
-// TODO(port): Port this file.
-#if defined(OS_WIN)
-#include "chrome/views/menu.h"
-#else
-#include "chrome/common/temp_scaffolding_stubs.h"
-#endif
+#include "webkit/glue/window_open_disposition.h"
class Profile;
+class WebContents;
-class RenderViewContextMenu : public Menu {
+class RenderViewContextMenu {
public:
RenderViewContextMenu(
- Menu::Delegate* delegate,
- gfx::NativeWindow owner,
- ContextNode node,
- const std::wstring& misspelled_word,
- const std::vector<std::wstring>& misspelled_word_suggestions,
- Profile* profile);
+ WebContents* web_contents,
+ const ContextMenuParams& params);
virtual ~RenderViewContextMenu();
- private:
+ protected:
void InitMenu(ContextNode node);
+
+ // Functions to be implemented by platform-specific subclasses ---------------
+
+ // Append a normal menu item, taking the name from the id.
+ virtual void AppendMenuItem(int id) = 0;
+
+ // Append a normal menu item, using |label| for the name.
+ virtual void AppendMenuItem(int id, const std::wstring& label) = 0;
+
+ // Append a radio menu item.
+ virtual void AppendRadioMenuItem(int id, const std::wstring& label) = 0;
+
+ // Append a checkbox menu item.
+ virtual void AppendCheckboxMenuItem(int id, const std::wstring& label) = 0;
+
+ // Append a separator.
+ virtual void AppendSeparator() = 0;
+
+ // Start creating a submenu. Any calls to Append*() between calls to
+ // StartSubMenu() and FinishSubMenu() will apply to the submenu rather than
+ // the main menu we are building. We only support at most single-depth
+ // submenus, so calls to StartSubMenu() while we are already building a
+ // submenu will be ignored.
+ virtual void StartSubMenu(int id, const std::wstring& label) = 0;
+
+ // Finish creating the submenu and attach it to the main menu.
+ virtual void FinishSubMenu() = 0;
+
+ // Delegate functions --------------------------------------------------------
+
+ bool IsItemCommandEnabled(int id) const;
+ bool ItemIsChecked(int id) const;
+ void ExecuteItemCommand(int id);
+
+ private:
void AppendDeveloperItems();
void AppendLinkItems();
void AppendImageItems();
@@ -42,13 +67,29 @@ class RenderViewContextMenu : public Menu {
void AppendEditableItems();
void AppendSearchProvider();
- std::wstring misspelled_word_;
- std::vector<std::wstring> misspelled_word_suggestions_;
+ // Opens the specified URL string in a new tab. If |in_current_window| is
+ // false, a new window is created to hold the new tab.
+ void OpenURL(const GURL& url,
+ WindowOpenDisposition disposition,
+ PageTransition::Type transition);
+
+ // Copy to the clipboard an image located at a point in the RenderView
+ void CopyImageAt(int x, int y);
+
+ // Launch the inspector targeting a point in the RenderView
+ void Inspect(int x, int y);
+
+ // Writes the specified text/url to the system clipboard
+ void WriteTextToClipboard(const string16& text);
+ void WriteURLToClipboard(const GURL& url);
+
+ bool IsDevCommandEnabled(int id) const;
+
+ ContextMenuParams params_;
+ WebContents* source_web_contents_;
Profile* profile_;
- Menu* spellchecker_sub_menu_;
DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu);
};
#endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_
-
diff --git a/chrome/browser/tab_contents/render_view_context_menu_controller.cc b/chrome/browser/tab_contents/render_view_context_menu_controller.cc
deleted file mode 100644
index 19c68d4..0000000
--- a/chrome/browser/tab_contents/render_view_context_menu_controller.cc
+++ /dev/null
@@ -1,547 +0,0 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "build/build_config.h"
-
-#include "chrome/browser/tab_contents/render_view_context_menu_controller.h"
-
-#include "base/command_line.h"
-#include "base/path_service.h"
-#include "base/scoped_clipboard_writer.h"
-#include "base/string_util.h"
-#include "chrome/app/chrome_dll_resource.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/download/download_manager.h"
-#include "chrome/browser/download/save_package.h"
-#include "chrome/browser/profile.h"
-#include "chrome/browser/search_engines/template_url_model.h"
-#include "chrome/browser/spellchecker.h"
-#include "chrome/browser/tab_contents/navigation_controller.h"
-#include "chrome/browser/tab_contents/navigation_entry.h"
-#include "chrome/browser/tab_contents/web_contents.h"
-#include "chrome/common/chrome_paths.h"
-#include "chrome/common/chrome_switches.h"
-#include "chrome/common/l10n_util.h"
-#include "chrome/common/pref_names.h"
-#include "chrome/common/pref_service.h"
-#include "chrome/common/url_constants.h"
-#include "grit/generated_resources.h"
-#include "net/base/escape.h"
-#include "net/base/net_util.h"
-#include "net/url_request/url_request.h"
-
-#if defined(OS_WIN)
-// TODO(port): port these files.
-#include "chrome/browser/views/options/fonts_languages_window_view.h"
-#include "chrome/browser/views/page_info_window.h"
-#include "chrome/common/clipboard_service.h"
-#include "chrome/common/win_util.h"
-#endif
-
-RenderViewContextMenuController::RenderViewContextMenuController(
- WebContents* source_web_contents, const ContextMenuParams& params)
- : source_web_contents_(source_web_contents),
- params_(params) {
-}
-
-RenderViewContextMenuController::~RenderViewContextMenuController() {
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// Controller methods
-
-void RenderViewContextMenuController::OpenURL(
- const GURL& url,
- WindowOpenDisposition disposition,
- PageTransition::Type transition) {
- source_web_contents_->OpenURL(url, GURL(), disposition, transition);
-}
-
-void RenderViewContextMenuController::CopyImageAt(int x, int y) {
- source_web_contents_->render_view_host()->CopyImageAt(x, y);
-}
-
-void RenderViewContextMenuController::Inspect(int x, int y) {
- source_web_contents_->render_view_host()->InspectElementAt(x, y);
-}
-
-void RenderViewContextMenuController::WriteTextToClipboard(
- const string16& text) {
- ClipboardService* clipboard = g_browser_process->clipboard_service();
-
- if (!clipboard)
- return;
-
- ScopedClipboardWriter scw(clipboard);
- scw.WriteText(text);
-}
-
-void RenderViewContextMenuController::WriteURLToClipboard(const GURL& url) {
- if (url.SchemeIs(chrome::kMailToScheme))
- WriteTextToClipboard(UTF8ToUTF16(url.path()));
- else
- WriteTextToClipboard(UTF8ToUTF16(url.spec()));
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// Menu::Delegate methods
-
-std::wstring RenderViewContextMenuController::GetLabel(int id) const {
- switch (id) {
- case IDS_CONTENT_CONTEXT_SEARCHWEBFOR: {
- const TemplateURL* const default_provider = source_web_contents_->
- profile()->GetTemplateURLModel()->GetDefaultSearchProvider();
- DCHECK(default_provider); // The context menu should not contain this
- // item when there is no provider.
- return l10n_util::GetStringF(id, default_provider->short_name(),
- l10n_util::TruncateString(params_.selection_text, 50));
- }
-
- case IDS_CONTENT_CONTEXT_COPYLINKLOCATION:
- if (params_.link_url.SchemeIs(chrome::kMailToScheme))
- return l10n_util::GetString(IDS_CONTENT_CONTEXT_COPYEMAILADDRESS);
-
- default:
- return l10n_util::GetString(id);
- }
-}
-
-bool RenderViewContextMenuController::IsCommandEnabled(int id) const {
- // Allow Spell Check language items on sub menu for text area context menu.
- if ((id >= IDC_SPELLCHECK_LANGUAGES_FIRST) &&
- (id < IDC_SPELLCHECK_LANGUAGES_LAST)) {
- return true;
- }
-
- switch (id) {
- case IDS_CONTENT_CONTEXT_BACK:
- return source_web_contents_->controller()->CanGoBack();
-
- case IDS_CONTENT_CONTEXT_FORWARD:
- return source_web_contents_->controller()->CanGoForward();
-
- case IDS_CONTENT_CONTEXT_VIEWPAGESOURCE:
- case IDS_CONTENT_CONTEXT_VIEWFRAMESOURCE:
- case IDS_CONTENT_CONTEXT_INSPECTELEMENT:
- return IsDevCommandEnabled(id);
-
- case IDS_CONTENT_CONTEXT_OPENLINKNEWTAB:
- case IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW:
- case IDS_CONTENT_CONTEXT_COPYLINKLOCATION:
- return params_.link_url.is_valid();
-
- case IDS_CONTENT_CONTEXT_SAVELINKAS:
- return params_.link_url.is_valid() &&
- URLRequest::IsHandledURL(params_.link_url);
-
- case IDS_CONTENT_CONTEXT_SAVEIMAGEAS:
- return params_.image_url.is_valid() &&
- URLRequest::IsHandledURL(params_.image_url);
-
- case IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB:
- // The images shown in the most visited thumbnails do not currently open
- // in a new tab as they should. Disabling this context menu option for
- // now, as a quick hack, before we resolve this issue (Issue = 2608).
- // TODO (sidchat): Enable this option once this issue is resolved.
- if (params_.image_url.scheme() == "chrome-ui")
- return false;
- return true;
-
- case IDS_CONTENT_CONTEXT_COPYIMAGELOCATION:
- return params_.image_url.is_valid();
-
- case IDS_CONTENT_CONTEXT_SAVEPAGEAS:
- return SavePackage::IsSavableURL(source_web_contents_->GetURL());
-
- case IDS_CONTENT_CONTEXT_OPENFRAMENEWTAB:
- case IDS_CONTENT_CONTEXT_OPENFRAMENEWWINDOW:
- return params_.frame_url.is_valid();
-
- case IDS_CONTENT_CONTEXT_UNDO:
- return !!(params_.edit_flags & ContextNode::CAN_UNDO);
-
- case IDS_CONTENT_CONTEXT_REDO:
- return !!(params_.edit_flags & ContextNode::CAN_REDO);
-
- case IDS_CONTENT_CONTEXT_CUT:
- return !!(params_.edit_flags & ContextNode::CAN_CUT);
-
- case IDS_CONTENT_CONTEXT_COPY:
- return !!(params_.edit_flags & ContextNode::CAN_COPY);
-
- case IDS_CONTENT_CONTEXT_PASTE:
- return !!(params_.edit_flags & ContextNode::CAN_PASTE);
-
- case IDS_CONTENT_CONTEXT_DELETE:
- return !!(params_.edit_flags & ContextNode::CAN_DELETE);
-
- case IDS_CONTENT_CONTEXT_SELECTALL:
- return !!(params_.edit_flags & ContextNode::CAN_SELECT_ALL);
-
- case IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD:
- return !source_web_contents_->profile()->IsOffTheRecord() &&
- params_.link_url.is_valid();
-
- case IDS_CONTENT_CONTEXT_OPENFRAMEOFFTHERECORD:
- return !source_web_contents_->profile()->IsOffTheRecord() &&
- params_.frame_url.is_valid();
-
- case IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY:
- return !params_.misspelled_word.empty();
-
- case IDS_CONTENT_CONTEXT_VIEWPAGEINFO:
- return (source_web_contents_->controller()->GetActiveEntry() != NULL);
-
- case IDS_CONTENT_CONTEXT_RELOAD:
- case IDS_CONTENT_CONTEXT_COPYIMAGE:
- case IDS_CONTENT_CONTEXT_PRINT:
- case IDS_CONTENT_CONTEXT_SEARCHWEBFOR:
- case IDC_SPELLCHECK_SUGGESTION_0:
- case IDC_SPELLCHECK_SUGGESTION_1:
- case IDC_SPELLCHECK_SUGGESTION_2:
- case IDC_SPELLCHECK_SUGGESTION_3:
- case IDC_SPELLCHECK_SUGGESTION_4:
- case IDC_SPELLCHECK_MENU:
- case IDC_CHECK_SPELLING_OF_THIS_FIELD:
- case IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS:
- case IDS_CONTENT_CONTEXT_VIEWFRAMEINFO:
- return true;
-
- case IDS_CONTENT_CONTEXT_SAVEFRAMEAS:
- case IDS_CONTENT_CONTEXT_PRINTFRAME:
- case IDS_CONTENT_CONTEXT_ADDSEARCHENGINE: // Not implemented.
- default:
- return false;
- }
-}
-
-bool RenderViewContextMenuController::IsItemChecked(int id) const {
- // Check box for 'Check the Spelling of this field'.
- if (id == IDC_CHECK_SPELLING_OF_THIS_FIELD)
- return params_.spellcheck_enabled;
-
- // Don't bother getting the display language vector if this isn't a spellcheck
- // language.
- if ((id < IDC_SPELLCHECK_LANGUAGES_FIRST) ||
- (id >= IDC_SPELLCHECK_LANGUAGES_LAST))
- return false;
-
- SpellChecker::Languages display_languages;
- return SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu(
- source_web_contents_->profile(), &display_languages) ==
- (id - IDC_SPELLCHECK_LANGUAGES_FIRST);
-}
-
-bool RenderViewContextMenuController::GetAcceleratorInfo(
- int id,
- views::Accelerator* accel) {
- // There are no formally defined accelerators we can query so we assume
- // that Ctrl+C, Ctrl+V, Ctrl+X, Ctrl-A, etc do what they normally do.
- switch (id) {
- case IDS_CONTENT_CONTEXT_UNDO:
- *accel = views::Accelerator(L'Z', false, true, false);
- return true;
-
- case IDS_CONTENT_CONTEXT_REDO:
- *accel = views::Accelerator(L'Z', true, true, false);
- return true;
-
- case IDS_CONTENT_CONTEXT_CUT:
- *accel = views::Accelerator(L'X', false, true, false);
- return true;
-
- case IDS_CONTENT_CONTEXT_COPY:
- *accel = views::Accelerator(L'C', false, true, false);
- return true;
-
- case IDS_CONTENT_CONTEXT_PASTE:
- *accel = views::Accelerator(L'V', false, true, false);
- return true;
-
- case IDS_CONTENT_CONTEXT_SELECTALL:
- *accel = views::Accelerator(L'A', false, true, false);
-
- default:
- return false;
- }
-}
-
-void RenderViewContextMenuController::ExecuteCommand(int id) {
- // Check to see if one of the spell check language ids have been clicked.
- if (id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
- id < IDC_SPELLCHECK_LANGUAGES_LAST) {
- const size_t language_number = id - IDC_SPELLCHECK_LANGUAGES_FIRST;
- SpellChecker::Languages display_languages;
- SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu(
- source_web_contents_->profile(), &display_languages);
- if (language_number < display_languages.size()) {
- StringPrefMember dictionary_language;
- dictionary_language.Init(prefs::kSpellCheckDictionary,
- source_web_contents_->profile()->GetPrefs(), NULL);
- dictionary_language.SetValue(display_languages[language_number]);
- }
-
- return;
- }
-
- switch (id) {
- case IDS_CONTENT_CONTEXT_OPENLINKNEWTAB:
- OpenURL(params_.link_url, NEW_BACKGROUND_TAB, PageTransition::LINK);
- break;
-
- case IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW:
- OpenURL(params_.link_url, NEW_WINDOW, PageTransition::LINK);
- break;
-
- case IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD:
- OpenURL(params_.link_url, OFF_THE_RECORD, PageTransition::LINK);
- break;
-
- // TODO(paulg): Prompt the user for file name when saving links and images.
- case IDS_CONTENT_CONTEXT_SAVEIMAGEAS:
- case IDS_CONTENT_CONTEXT_SAVELINKAS: {
- const GURL& referrer =
- params_.frame_url.is_empty() ? params_.page_url : params_.frame_url;
- const GURL& url =
- (id == IDS_CONTENT_CONTEXT_SAVELINKAS ? params_.link_url :
- params_.image_url);
- DownloadManager* dlm =
- source_web_contents_->profile()->GetDownloadManager();
- dlm->DownloadUrl(url, referrer, source_web_contents_);
- break;
- }
-
- case IDS_CONTENT_CONTEXT_COPYLINKLOCATION:
- WriteURLToClipboard(params_.link_url);
- break;
-
- case IDS_CONTENT_CONTEXT_COPYIMAGELOCATION:
- WriteURLToClipboard(params_.image_url);
- break;
-
- case IDS_CONTENT_CONTEXT_COPYIMAGE:
- CopyImageAt(params_.x, params_.y);
- break;
-
- case IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB:
- OpenURL(params_.image_url, NEW_BACKGROUND_TAB, PageTransition::LINK);
- break;
-
- case IDS_CONTENT_CONTEXT_BACK:
- source_web_contents_->controller()->GoBack();
- break;
-
- case IDS_CONTENT_CONTEXT_FORWARD:
- source_web_contents_->controller()->GoForward();
- break;
-
- case IDS_CONTENT_CONTEXT_SAVEPAGEAS:
- source_web_contents_->OnSavePage();
- break;
-
- case IDS_CONTENT_CONTEXT_RELOAD:
- source_web_contents_->controller()->Reload(true);
- break;
-
- case IDS_CONTENT_CONTEXT_PRINT:
- source_web_contents_->PrintPreview();
- break;
-
- case IDS_CONTENT_CONTEXT_VIEWPAGESOURCE:
- OpenURL(GURL("view-source:" + params_.page_url.spec()),
- NEW_FOREGROUND_TAB, PageTransition::GENERATED);
- break;
-
- case IDS_CONTENT_CONTEXT_INSPECTELEMENT:
- Inspect(params_.x, params_.y);
- break;
-
- case IDS_CONTENT_CONTEXT_VIEWPAGEINFO: {
- NavigationEntry* nav_entry =
- source_web_contents_->controller()->GetActiveEntry();
- PageInfoWindow::CreatePageInfo(
- source_web_contents_->profile(),
- nav_entry,
- source_web_contents_->GetContentNativeView(),
- PageInfoWindow::SECURITY);
- break;
- }
-
- case IDS_CONTENT_CONTEXT_OPENFRAMENEWTAB:
- OpenURL(params_.frame_url, NEW_BACKGROUND_TAB, PageTransition::LINK);
- break;
-
- case IDS_CONTENT_CONTEXT_OPENFRAMENEWWINDOW:
- OpenURL(params_.frame_url, NEW_WINDOW, PageTransition::LINK);
- break;
-
- case IDS_CONTENT_CONTEXT_OPENFRAMEOFFTHERECORD:
- OpenURL(params_.frame_url, OFF_THE_RECORD, PageTransition::LINK);
- break;
-
- case IDS_CONTENT_CONTEXT_SAVEFRAMEAS:
-#if defined(OS_WIN)
- win_util::MessageBox(NULL, L"Context Menu Action", L"Save Frame As",
- MB_OK);
-#else
- // TODO(port): message box equivalent
- NOTIMPLEMENTED() << "IDS_CONTENT_CONTEXT_SAVEFRAMEAS";
-#endif
- break;
-
- case IDS_CONTENT_CONTEXT_PRINTFRAME:
-#if defined(OS_WIN)
- win_util::MessageBox(NULL, L"Context Menu Action", L"Print Frame",
- MB_OK);
-#else
- // TODO(port): message box equivalent
- NOTIMPLEMENTED() << "IDS_CONTENT_CONTEXT_PRINTFRAME";
-#endif
- break;
-
- case IDS_CONTENT_CONTEXT_VIEWFRAMESOURCE:
- OpenURL(GURL("view-source:" + params_.frame_url.spec()),
- NEW_FOREGROUND_TAB, PageTransition::GENERATED);
- break;
-
- case IDS_CONTENT_CONTEXT_VIEWFRAMEINFO: {
- // Deserialize the SSL info.
- NavigationEntry::SSLStatus ssl;
- if (!params_.security_info.empty()) {
- int cert_id, cert_status, security_bits;
- SSLManager::DeserializeSecurityInfo(params_.security_info,
- &cert_id,
- &cert_status,
- &security_bits);
- ssl.set_cert_id(cert_id);
- ssl.set_cert_status(cert_status);
- ssl.set_security_bits(security_bits);
- }
- PageInfoWindow::CreateFrameInfo(
- source_web_contents_->profile(),
- params_.frame_url,
- ssl,
- source_web_contents_->GetContentNativeView(),
- PageInfoWindow::SECURITY);
- break;
- }
-
- case IDS_CONTENT_CONTEXT_UNDO:
- source_web_contents_->render_view_host()->Undo();
- break;
-
- case IDS_CONTENT_CONTEXT_REDO:
- source_web_contents_->render_view_host()->Redo();
- break;
-
- case IDS_CONTENT_CONTEXT_CUT:
- source_web_contents_->render_view_host()->Cut();
- break;
-
- case IDS_CONTENT_CONTEXT_COPY:
- source_web_contents_->render_view_host()->Copy();
- break;
-
- case IDS_CONTENT_CONTEXT_PASTE:
- source_web_contents_->render_view_host()->Paste();
- break;
-
- case IDS_CONTENT_CONTEXT_DELETE:
- source_web_contents_->render_view_host()->Delete();
- break;
-
- case IDS_CONTENT_CONTEXT_SELECTALL:
- source_web_contents_->render_view_host()->SelectAll();
- break;
-
- case IDS_CONTENT_CONTEXT_SEARCHWEBFOR: {
- const TemplateURL* const default_provider = source_web_contents_->
- profile()->GetTemplateURLModel()->GetDefaultSearchProvider();
- DCHECK(default_provider); // The context menu should not contain this
- // item when there is no provider.
- const TemplateURLRef* const search_url = default_provider->url();
- DCHECK(search_url->SupportsReplacement());
- OpenURL(GURL(search_url->ReplaceSearchTerms(*default_provider,
- params_.selection_text, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE,
- std::wstring())), NEW_FOREGROUND_TAB, PageTransition::GENERATED);
- break;
- }
-
- case IDC_SPELLCHECK_SUGGESTION_0:
- case IDC_SPELLCHECK_SUGGESTION_1:
- case IDC_SPELLCHECK_SUGGESTION_2:
- case IDC_SPELLCHECK_SUGGESTION_3:
- case IDC_SPELLCHECK_SUGGESTION_4:
- source_web_contents_->render_view_host()->Replace(
- params_.dictionary_suggestions[id - IDC_SPELLCHECK_SUGGESTION_0]);
- break;
-
- case IDC_CHECK_SPELLING_OF_THIS_FIELD:
- source_web_contents_->render_view_host()->ToggleSpellCheck();
- break;
- case IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY:
- source_web_contents_->render_view_host()->AddToDictionary(
- params_.misspelled_word);
- break;
-
- case IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS: {
-#if defined(OS_WIN)
- FontsLanguagesWindowView* window_ = new FontsLanguagesWindowView(
- source_web_contents_->profile());
- views::Window::CreateChromeWindow(
- source_web_contents_->GetContentNativeView(),
- gfx::Rect(), window_)->Show();
- window_->SelectLanguagesTab();
-#else
- // TODO(port): need views::Window
- NOTIMPLEMENTED() << "IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS";
-#endif
- break;
- }
-
- case IDS_CONTENT_CONTEXT_ADDSEARCHENGINE: // Not implemented.
- default:
- break;
- }
-}
-
-bool RenderViewContextMenuController::IsDevCommandEnabled(int id) const {
- const CommandLine& command_line = *CommandLine::ForCurrentProcess();
- if (command_line.HasSwitch(switches::kAlwaysEnableDevTools))
- return true;
-
- NavigationEntry *active_entry =
- source_web_contents_->controller()->GetActiveEntry();
- if (!active_entry)
- return false;
-
- // Don't inspect HTML dialogs.
- if (source_web_contents_->type() == TAB_CONTENTS_HTML_DIALOG)
- return false;
-
- // Don't inspect view source.
- if (active_entry->IsViewSourceMode())
- return false;
-
- // Don't inspect inspector, new tab UI, etc.
- if (active_entry->url().SchemeIs(chrome::kChromeUIScheme))
- return false;
-
- // Don't inspect about:network, about:memory, etc.
- // However, we do want to inspect about:blank, which is often
- // used by ordinary web pages.
- if (active_entry->display_url().SchemeIs(chrome::kAboutScheme) &&
- !LowerCaseEqualsASCII(active_entry->display_url().path(), "blank"))
- return false;
-
- // Don't enable the web inspector if JavaScript is disabled
- if (id == IDS_CONTENT_CONTEXT_INSPECTELEMENT) {
- PrefService* prefs = source_web_contents_->profile()->GetPrefs();
- if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled) ||
- command_line.HasSwitch(switches::kDisableJavaScript))
- return false;
- }
-
- return true;
-}
diff --git a/chrome/browser/tab_contents/render_view_context_menu_controller.h b/chrome/browser/tab_contents/render_view_context_menu_controller.h
deleted file mode 100644
index 0c72dcc..0000000
--- a/chrome/browser/tab_contents/render_view_context_menu_controller.h
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_RENDERER_HOST_RENDER_VIEW_CONTEXT_MENU_CONTROLLER_H_
-#define CHROME_BROWSER_RENDERER_HOST_RENDER_VIEW_CONTEXT_MENU_CONTROLLER_H_
-
-#include "build/build_config.h"
-
-#include "base/string16.h"
-#include "chrome/common/pref_member.h"
-#include "chrome/common/page_transition_types.h"
-#include "webkit/glue/context_menu.h"
-#include "webkit/glue/window_open_disposition.h"
-
-#if defined(OS_WIN)
-// TODO(port): port this file.
-#include "chrome/views/menu.h"
-#else
-#include "chrome/common/temp_scaffolding_stubs.h"
-#include "chrome/views/accelerator.h"
-#endif
-
-class WebContents;
-
-class RenderViewContextMenuController : public Menu::Delegate {
- public:
- RenderViewContextMenuController(WebContents* source_web_contents,
- const ContextMenuParams& params);
- virtual ~RenderViewContextMenuController();
-
- // Overridden from Menu::Delegate
- virtual std::wstring GetLabel(int id) const;
- virtual bool IsCommandEnabled(int id) const;
- virtual bool IsItemChecked(int id) const;
- virtual void ExecuteCommand(int id);
- virtual bool GetAcceleratorInfo(int id, views::Accelerator* accel);
-
- private:
- // Opens the specified URL string in a new tab. If |in_current_window| is
- // false, a new window is created to hold the new tab.
- void OpenURL(const GURL& url,
- WindowOpenDisposition disposition,
- PageTransition::Type transition);
-
- // Copy to the clipboard an image located at a point in the RenderView
- void CopyImageAt(int x, int y);
-
- // Launch the inspector targeting a point in the RenderView
- void Inspect(int x, int y);
-
- // Writes the specified text/url to the system clipboard
- void WriteTextToClipboard(const string16& text);
- void WriteURLToClipboard(const GURL& url);
-
- bool IsDevCommandEnabled(int id) const;
-
- DISALLOW_EVIL_CONSTRUCTORS(RenderViewContextMenuController);
-
- private:
- WebContents* source_web_contents_;
- ContextMenuParams params_;
- StringPrefMember dictionary_language_;
- int current_dictionary_language_index_;
-};
-
-#endif // CHROME_BROWSER_RENDERER_HOST_RENDER_VIEW_CONTEXT_MENU_CONTROLLER_H_
diff --git a/chrome/browser/tab_contents/render_view_context_menu_win.cc b/chrome/browser/tab_contents/render_view_context_menu_win.cc
new file mode 100644
index 0000000..92ed661
--- /dev/null
+++ b/chrome/browser/tab_contents/render_view_context_menu_win.cc
@@ -0,0 +1,117 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/tab_contents/render_view_context_menu_win.h"
+
+#include "chrome/browser/profile.h"
+#include "chrome/common/l10n_util.h"
+#include "grit/generated_resources.h"
+
+RenderViewContextMenuWin::RenderViewContextMenuWin(
+ WebContents* web_contents,
+ const ContextMenuParams& params,
+ HWND owner)
+ : RenderViewContextMenu(web_contents, params),
+ menu_(this, Menu::TOPLEFT, owner),
+ sub_menu_(NULL) {
+ InitMenu(params.node);
+}
+
+RenderViewContextMenuWin::~RenderViewContextMenuWin() {
+}
+
+void RenderViewContextMenuWin::RunMenuAt(int x, int y) {
+ menu_.RunMenuAt(x, y);
+}
+
+void RenderViewContextMenuWin::AppendMenuItem(int id) {
+ AppendItem(id, l10n_util::GetString(id), Menu::NORMAL);
+}
+
+void RenderViewContextMenuWin::AppendMenuItem(int id,
+ const std::wstring& label) {
+ AppendItem(id, label, Menu::NORMAL);
+}
+
+void RenderViewContextMenuWin::AppendRadioMenuItem(int id,
+ const std::wstring& label) {
+ AppendItem(id, label, Menu::RADIO);
+}
+
+void RenderViewContextMenuWin::AppendCheckboxMenuItem(int id,
+ const std::wstring& label) {
+ AppendItem(id, label, Menu::CHECKBOX);
+}
+
+void RenderViewContextMenuWin::AppendSeparator() {
+ Menu* menu = sub_menu_ ? sub_menu_ : &menu_;
+ menu->AppendSeparator();
+}
+
+void RenderViewContextMenuWin::StartSubMenu(int id, const std::wstring& label) {
+ if (sub_menu_) {
+ NOTREACHED();
+ return;
+ }
+ sub_menu_ = menu_.AppendSubMenu(id, label);
+}
+
+void RenderViewContextMenuWin::FinishSubMenu() {
+ DCHECK(sub_menu_);
+ sub_menu_ = NULL;
+}
+
+void RenderViewContextMenuWin::AppendItem(
+ int id,
+ const std::wstring& label,
+ Menu::MenuItemType type) {
+ Menu* menu = sub_menu_ ? sub_menu_ : &menu_;
+ menu->AppendMenuItem(id, label, type);
+}
+
+bool RenderViewContextMenuWin::IsCommandEnabled(int id) const {
+ return IsItemCommandEnabled(id);
+}
+
+bool RenderViewContextMenuWin::IsItemChecked(int id) const {
+ return ItemIsChecked(id);
+}
+
+void RenderViewContextMenuWin::ExecuteCommand(int id) {
+ ExecuteItemCommand(id);
+}
+
+bool RenderViewContextMenuWin::GetAcceleratorInfo(
+ int id,
+ views::Accelerator* accel) {
+ // There are no formally defined accelerators we can query so we assume
+ // that Ctrl+C, Ctrl+V, Ctrl+X, Ctrl-A, etc do what they normally do.
+ switch (id) {
+ case IDS_CONTENT_CONTEXT_UNDO:
+ *accel = views::Accelerator(L'Z', false, true, false);
+ return true;
+
+ case IDS_CONTENT_CONTEXT_REDO:
+ *accel = views::Accelerator(L'Z', true, true, false);
+ return true;
+
+ case IDS_CONTENT_CONTEXT_CUT:
+ *accel = views::Accelerator(L'X', false, true, false);
+ return true;
+
+ case IDS_CONTENT_CONTEXT_COPY:
+ *accel = views::Accelerator(L'C', false, true, false);
+ return true;
+
+ case IDS_CONTENT_CONTEXT_PASTE:
+ *accel = views::Accelerator(L'V', false, true, false);
+ return true;
+
+ case IDS_CONTENT_CONTEXT_SELECTALL:
+ *accel = views::Accelerator(L'A', false, true, false);
+
+ default:
+ return false;
+ }
+}
diff --git a/chrome/browser/tab_contents/render_view_context_menu_win.h b/chrome/browser/tab_contents/render_view_context_menu_win.h
new file mode 100644
index 0000000..a53d2ef
--- /dev/null
+++ b/chrome/browser/tab_contents/render_view_context_menu_win.h
@@ -0,0 +1,48 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_WIN_H_
+#define CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_WIN_H_
+
+#include "chrome/browser/tab_contents/render_view_context_menu.h"
+#include "chrome/views/accelerator.h"
+#include "chrome/views/menu.h"
+
+class RenderViewContextMenuWin : public RenderViewContextMenu,
+ public Menu::Delegate{
+ public:
+ RenderViewContextMenuWin(WebContents* web_contents,
+ const ContextMenuParams& params,
+ HWND window);
+
+ ~RenderViewContextMenuWin();
+
+ void RunMenuAt(int x, int y);
+
+ // Menu::Delegate implementation ---------------------------------------------
+ virtual bool IsCommandEnabled(int id) const;
+ virtual bool IsItemChecked(int id) const;
+ virtual void ExecuteCommand(int id);
+ // TODO(port): move the logic in this function to RenderViewContextMenu.
+ virtual bool GetAcceleratorInfo(int id, views::Accelerator* accel);
+
+ protected:
+ // RenderViewContextMenu implementation --------------------------------------
+ virtual void AppendMenuItem(int id);
+ virtual void AppendMenuItem(int id, const std::wstring& label);
+ virtual void AppendRadioMenuItem(int id, const std::wstring& label);
+ virtual void AppendCheckboxMenuItem(int id, const std::wstring& label);
+ virtual void AppendSeparator();
+ virtual void StartSubMenu(int id, const std::wstring& label);
+ virtual void FinishSubMenu();
+
+ private:
+ // Append the item to |sub_menu_| if it exists, or |menu_| otherwise.
+ void AppendItem(int id, const std::wstring& label, Menu::MenuItemType type);
+
+ Menu menu_;
+ Menu* sub_menu_;
+};
+
+#endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_WIN_H_
diff --git a/chrome/browser/tab_contents/web_contents_view_win.cc b/chrome/browser/tab_contents/web_contents_view_win.cc
index c0e1aab..48b7466 100644
--- a/chrome/browser/tab_contents/web_contents_view_win.cc
+++ b/chrome/browser/tab_contents/web_contents_view_win.cc
@@ -14,8 +14,7 @@
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_widget_host_view_win.h"
-#include "chrome/browser/tab_contents/render_view_context_menu.h"
-#include "chrome/browser/tab_contents/render_view_context_menu_controller.h"
+#include "chrome/browser/tab_contents/render_view_context_menu_win.h"
#include "chrome/browser/tab_contents/interstitial_page.h"
#include "chrome/browser/tab_contents/tab_contents_delegate.h"
#include "chrome/browser/tab_contents/web_contents.h"
@@ -299,13 +298,9 @@ void WebContentsViewWin::HandleKeyboardEvent(
}
void WebContentsViewWin::ShowContextMenu(const ContextMenuParams& params) {
- RenderViewContextMenuController menu_controller(web_contents_, params);
- RenderViewContextMenu menu(&menu_controller,
- GetHWND(),
- params.node,
- params.misspelled_word,
- params.dictionary_suggestions,
- web_contents_->profile());
+ RenderViewContextMenuWin menu(web_contents_,
+ params,
+ GetHWND());
POINT screen_pt = { params.x, params.y };
MapWindowPoints(GetHWND(), HWND_DESKTOP, &screen_pt, 1);
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 32940f5..9b29a1d 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -919,8 +919,6 @@
'browser/tab_contents/provisional_load_details.h',
'browser/tab_contents/render_view_context_menu.cc',
'browser/tab_contents/render_view_context_menu.h',
- 'browser/tab_contents/render_view_context_menu_controller.cc',
- 'browser/tab_contents/render_view_context_menu_controller.h',
'browser/tab_contents/render_view_host_manager.cc',
'browser/tab_contents/render_view_host_manager.h',
'browser/tab_contents/repost_form_warning.h',
diff --git a/chrome/common/clipboard_service.h b/chrome/common/clipboard_service.h
index ed34afd..2ebcdd0 100644
--- a/chrome/common/clipboard_service.h
+++ b/chrome/common/clipboard_service.h
@@ -2,23 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_COMMON_CLIPBOARD_SERVICE_H__
-#define CHROME_COMMON_CLIPBOARD_SERVICE_H__
-
-#include <string>
-#include <vector>
+#ifndef CHROME_COMMON_CLIPBOARD_SERVICE_H_
+#define CHROME_COMMON_CLIPBOARD_SERVICE_H_
#include "base/clipboard.h"
-class SkBitmap;
-
class ClipboardService : public Clipboard {
public:
ClipboardService() {}
private:
- DISALLOW_EVIL_CONSTRUCTORS(ClipboardService);
+ DISALLOW_COPY_AND_ASSIGN(ClipboardService);
};
-#endif // CHROME_COMMON_CLIPBOARD_SERVICE_H__
+#endif // CHROME_COMMON_CLIPBOARD_SERVICE_H_
diff --git a/chrome/common/temp_scaffolding_stubs.h b/chrome/common/temp_scaffolding_stubs.h
index 22b220c..83dbc74 100644
--- a/chrome/common/temp_scaffolding_stubs.h
+++ b/chrome/common/temp_scaffolding_stubs.h
@@ -175,10 +175,6 @@ void InstallJankometer(const CommandLine&);
//---------------------------------------------------------------------------
// These stubs are for BrowserProcessImpl
-class ClipboardService : public Clipboard {
- public:
-};
-
class CancelableTask;
class ViewMsg_Print_Params;