OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "athena/content/render_view_context_menu_impl.h" |
| 6 |
| 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "components/renderer_context_menu/context_menu_content_type.h" |
| 9 #include "components/renderer_context_menu/views/toolkit_delegate_views.h" |
| 10 #include "content/public/browser/web_contents.h" |
| 11 #include "ui/views/controls/menu/menu_item_view.h" |
| 12 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 13 #include "ui/views/controls/menu/menu_runner.h" |
| 14 |
| 15 namespace athena { |
| 16 namespace { |
| 17 |
| 18 enum { |
| 19 CMD_BACK, |
| 20 CMD_FORWARD, |
| 21 CMD_RELOAD, |
| 22 CMD_VIEW_SOURCE, |
| 23 CMD_LAST, |
| 24 }; |
| 25 |
| 26 // Max number of custom command ids allowd. |
| 27 const int kNumCustomCommandIds = 1000; |
| 28 |
| 29 void AppendPageItems(ui::SimpleMenuModel* menu_model) { |
| 30 menu_model->AddItem(CMD_BACK, base::ASCIIToUTF16("Back")); |
| 31 menu_model->AddItem(CMD_FORWARD, base::ASCIIToUTF16("Forward")); |
| 32 menu_model->AddItem(CMD_RELOAD, base::ASCIIToUTF16("Reload")); |
| 33 menu_model->AddSeparator(ui::NORMAL_SEPARATOR); |
| 34 menu_model->AddItem(CMD_VIEW_SOURCE, base::ASCIIToUTF16("View Source")); |
| 35 } |
| 36 |
| 37 } // namespace |
| 38 |
| 39 RenderViewContextMenuImpl::RenderViewContextMenuImpl( |
| 40 content::RenderFrameHost* render_frame_host, |
| 41 const content::ContextMenuParams& params) |
| 42 : RenderViewContextMenuBase(render_frame_host, params) { |
| 43 SetContentCustomCommandIdRange(CMD_LAST, CMD_LAST + kNumCustomCommandIds); |
| 44 // TODO(oshima): Support other types |
| 45 set_content_type( |
| 46 new ContextMenuContentType(source_web_contents_, params, true)); |
| 47 set_toolkit_delegate(scoped_ptr<ToolkitDelegate>(new ToolkitDelegateViews)); |
| 48 } |
| 49 |
| 50 RenderViewContextMenuImpl::~RenderViewContextMenuImpl() { |
| 51 } |
| 52 |
| 53 void RenderViewContextMenuImpl::RunMenuAt(views::Widget* parent, |
| 54 const gfx::Point& point, |
| 55 ui::MenuSourceType type) { |
| 56 static_cast<ToolkitDelegateViews*>(toolkit_delegate()) |
| 57 ->RunMenuAt(parent, point, type); |
| 58 } |
| 59 |
| 60 void RenderViewContextMenuImpl::InitMenu() { |
| 61 RenderViewContextMenuBase::InitMenu(); |
| 62 |
| 63 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PAGE)) { |
| 64 AppendPageItems(&menu_model_); |
| 65 } |
| 66 } |
| 67 |
| 68 void RenderViewContextMenuImpl::RecordShownItem(int id) { |
| 69 // TODO(oshima): Imelement UMA stats. crbug.com/401673 |
| 70 NOTIMPLEMENTED(); |
| 71 } |
| 72 |
| 73 void RenderViewContextMenuImpl::RecordUsedItem(int id) { |
| 74 // TODO(oshima): Imelement UMA stats. crbug.com/401673 |
| 75 NOTIMPLEMENTED(); |
| 76 } |
| 77 |
| 78 #if defined(ENABLE_PLUGINS) |
| 79 void RenderViewContextMenuImpl::HandleAuthorizeAllPlugins() { |
| 80 } |
| 81 #endif |
| 82 |
| 83 void RenderViewContextMenuImpl::NotifyMenuShown() { |
| 84 } |
| 85 |
| 86 void RenderViewContextMenuImpl::NotifyURLOpened( |
| 87 const GURL& url, |
| 88 content::WebContents* new_contents) { |
| 89 } |
| 90 |
| 91 bool RenderViewContextMenuImpl::GetAcceleratorForCommandId( |
| 92 int command_id, |
| 93 ui::Accelerator* accelerator) { |
| 94 NOTIMPLEMENTED(); |
| 95 return false; |
| 96 } |
| 97 |
| 98 bool RenderViewContextMenuImpl::IsCommandIdChecked(int command_id) const { |
| 99 return false; |
| 100 } |
| 101 |
| 102 bool RenderViewContextMenuImpl::IsCommandIdEnabled(int command_id) const { |
| 103 if (RenderViewContextMenuBase::IsCommandIdEnabled(command_id)) |
| 104 return true; |
| 105 switch (command_id) { |
| 106 case CMD_BACK: |
| 107 return source_web_contents_->GetController().CanGoBack(); |
| 108 case CMD_FORWARD: |
| 109 return source_web_contents_->GetController().CanGoForward(); |
| 110 case CMD_RELOAD: |
| 111 return true; |
| 112 case CMD_VIEW_SOURCE: |
| 113 return source_web_contents_->GetController().CanViewSource(); |
| 114 } |
| 115 return false; |
| 116 } |
| 117 |
| 118 void RenderViewContextMenuImpl::ExecuteCommand(int command_id, |
| 119 int event_flags) { |
| 120 RenderViewContextMenuBase::ExecuteCommand(command_id, event_flags); |
| 121 if (command_executed_) |
| 122 return; |
| 123 command_executed_ = true; |
| 124 switch (command_id) { |
| 125 case CMD_BACK: |
| 126 source_web_contents_->GetController().GoBack(); |
| 127 break; |
| 128 case CMD_FORWARD: |
| 129 source_web_contents_->GetController().GoForward(); |
| 130 break; |
| 131 case CMD_RELOAD: |
| 132 source_web_contents_->GetController().Reload(true); |
| 133 break; |
| 134 case CMD_VIEW_SOURCE: |
| 135 source_web_contents_->ViewSource(); |
| 136 break; |
| 137 } |
| 138 } |
| 139 |
| 140 } // namespace athena |
OLD | NEW |