diff options
author | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-05 18:51:48 +0000 |
---|---|---|
committer | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-05 18:51:48 +0000 |
commit | 565f32fc0ffca7ca992aca1a5b43c35e8c96d064 (patch) | |
tree | 79b69dcdf42fc4ef890f4f4f7a67ca41f87175fd /chrome/browser/tab_contents | |
parent | f8d5a5e7651d3a1abcb43ece43ef7bf6fbe49790 (diff) | |
download | chromium_src-565f32fc0ffca7ca992aca1a5b43c35e8c96d064.zip chromium_src-565f32fc0ffca7ca992aca1a5b43c35e8c96d064.tar.gz chromium_src-565f32fc0ffca7ca992aca1a5b43c35e8c96d064.tar.bz2 |
cros: Add app mode restrictions.
- White list ash accelerator actions;
- White list browser accelerators;
- Use a limited render view context menu;
BUG=178469
TEST=Verify Ctrl-N etc is disabled and no accelerator/menu to get a browser
window in app mode.
R=zelidrag@chromium.org,sky@chromium.org
Review URL: https://chromiumcodereview.appspot.com/12389083
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186214 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r-- | chrome/browser/tab_contents/render_view_context_menu.cc | 47 | ||||
-rw-r--r-- | chrome/browser/tab_contents/render_view_context_menu.h | 1 |
2 files changed, 34 insertions, 14 deletions
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index ba0b6bb..8cb23b5 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -18,6 +18,7 @@ #include "base/time.h" #include "base/utf_string_conversions.h" #include "chrome/app/chrome_command_ids.h" +#include "chrome/browser/app_mode/app_mode_utils.h" #include "chrome/browser/autocomplete/autocomplete_classifier.h" #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" #include "chrome/browser/autocomplete/autocomplete_match.h" @@ -231,9 +232,9 @@ void DevToolsInspectElementAt(RenderViewHost* rvh, int x, int y) { } // Helper function to escape "&" as "&&". -void EscapeAmpersands(string16& text) { +void EscapeAmpersands(string16* text) { const char16 ampersand[] = {'&', 0}; - ReplaceChars(text, ampersand, ASCIIToUTF16("&&"), &text); + ReplaceChars(*text, ampersand, ASCIIToUTF16("&&"), text); } } // namespace @@ -298,9 +299,9 @@ bool RenderViewContextMenu::ExtensionContextAndPatternMatch( const content::ContextMenuParams& params, MenuItem::ContextList contexts, const extensions::URLPatternSet& target_url_patterns) { - bool has_link = !params.link_url.is_empty(); - bool has_selection = !params.selection_text.empty(); - bool in_frame = !params.frame_url.is_empty(); + const bool has_link = !params.link_url.is_empty(); + const bool has_selection = !params.selection_text.empty(); + const bool in_frame = !params.frame_url.is_empty(); if (contexts.Contains(MenuItem::ALL) || (has_selection && contexts.Contains(MenuItem::SELECTION)) || @@ -395,7 +396,7 @@ void RenderViewContextMenu::AppendAllExtensionItems() { for (i = sorted_ids.begin(); i != sorted_ids.end(); ++i) { string16 printable_selection_text = PrintableSelectionText(); - EscapeAmpersands(printable_selection_text); + EscapeAmpersands(&printable_selection_text); extension_items_.AppendExtensionItems(i->second, printable_selection_text, &index); @@ -406,6 +407,11 @@ void RenderViewContextMenu::AppendAllExtensionItems() { } void RenderViewContextMenu::InitMenu() { + if (chrome::IsRunningInForcedAppMode()) { + AppendAppModeItems(); + return; + } + chrome::ViewType view_type = chrome::GetViewType(source_web_contents_); if (view_type == chrome::VIEW_TYPE_APP_SHELL) { AppendPlatformAppItems(); @@ -418,8 +424,8 @@ void RenderViewContextMenu::InitMenu() { return; } - bool has_link = !params_.unfiltered_link_url.is_empty(); - bool has_selection = !params_.selection_text.empty(); + const bool has_link = !params_.unfiltered_link_url.is_empty(); + const bool has_selection = !params_.selection_text.empty(); if (AppendCustomItems()) { // If there's a selection, don't early return when there are custom items, @@ -519,6 +525,15 @@ const Extension* RenderViewContextMenu::GetExtension() const { source_web_contents_->GetRenderViewHost()); } +void RenderViewContextMenu::AppendAppModeItems() { + const bool has_selection = !params_.selection_text.empty(); + + if (params_.is_editable) + AppendEditableItems(); + else if (has_selection) + AppendCopyItem(); +} + void RenderViewContextMenu::AppendPlatformAppItems() { const Extension* platform_app = GetExtension(); @@ -528,7 +543,7 @@ void RenderViewContextMenu::AppendPlatformAppItems() { DCHECK(platform_app->is_platform_app()); - bool has_selection = !params_.selection_text.empty(); + const bool has_selection = !params_.selection_text.empty(); // Add undo/redo, cut/copy/paste etc for text fields. if (params_.is_editable) @@ -558,7 +573,7 @@ void RenderViewContextMenu::AppendPlatformAppItems() { } void RenderViewContextMenu::AppendPopupExtensionItems() { - bool has_selection = !params_.selection_text.empty(); + const bool has_selection = !params_.selection_text.empty(); if (params_.is_editable) AppendEditableItems(); @@ -832,7 +847,7 @@ void RenderViewContextMenu::AppendSearchProvider() { return; string16 printable_selection_text = PrintableSelectionText(); - EscapeAmpersands(printable_selection_text); + EscapeAmpersands(&printable_selection_text); if (AutocompleteMatch::IsSearchType(match.type)) { const TemplateURL* const default_provider = @@ -858,7 +873,10 @@ void RenderViewContextMenu::AppendSearchProvider() { } void RenderViewContextMenu::AppendEditableItems() { - AppendSpellingSuggestionsSubMenu(); + const bool use_spellcheck_and_search = !chrome::IsRunningInForcedAppMode(); + + if (use_spellcheck_and_search) + AppendSpellingSuggestionsSubMenu(); menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_UNDO, IDS_CONTENT_CONTEXT_UNDO); @@ -877,13 +895,14 @@ void RenderViewContextMenu::AppendEditableItems() { IDS_CONTENT_CONTEXT_DELETE); menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); - if (!params_.keyword_url.is_empty()) { + if (use_spellcheck_and_search && !params_.keyword_url.is_empty()) { menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ADDSEARCHENGINE, IDS_CONTENT_CONTEXT_ADDSEARCHENGINE); menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); } - AppendSpellcheckOptionsSubMenu(); + if (use_spellcheck_and_search) + AppendSpellcheckOptionsSubMenu(); AppendSpeechInputOptionsSubMenu(); AppendPlatformEditableItems(); diff --git a/chrome/browser/tab_contents/render_view_context_menu.h b/chrome/browser/tab_contents/render_view_context_menu.h index a44e4b8..d93b6ed 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.h +++ b/chrome/browser/tab_contents/render_view_context_menu.h @@ -204,6 +204,7 @@ class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate, // Gets the extension (if any) associated with the WebContents that we're in. const extensions::Extension* GetExtension() const; + void AppendAppModeItems(); void AppendPlatformAppItems(); void AppendPopupExtensionItems(); void AppendPanelItems(); |