Index: components/renderer_context_menu/render_view_context_menu_base.cc |
diff --git a/components/renderer_context_menu/render_view_context_menu_base.cc b/components/renderer_context_menu/render_view_context_menu_base.cc |
index cda6c4667aef1908774a90842753fd62598a7b95..8b3b0bdbbe1faaec711b26ab226a40e328c47e9a 100644 |
--- a/components/renderer_context_menu/render_view_context_menu_base.cc |
+++ b/components/renderer_context_menu/render_view_context_menu_base.cc |
@@ -16,6 +16,7 @@ |
#include "content/public/browser/web_contents.h" |
#include "content/public/common/menu_item.h" |
#include "third_party/WebKit/public/web/WebContextMenuData.h" |
+#include "ui/gfx/image/image.h" |
using blink::WebContextMenuData; |
using blink::WebString; |
@@ -67,11 +68,26 @@ bool IsCustomItemCheckedInternal(const std::vector<content::MenuItem>& items, |
const size_t kMaxCustomMenuDepth = 5; |
const size_t kMaxCustomMenuTotalItems = 1000; |
-void AddCustomItemsToMenu(const std::vector<content::MenuItem>& items, |
- size_t depth, |
- size_t* total_items, |
- ui::SimpleMenuModel::Delegate* delegate, |
- ui::SimpleMenuModel* menu_model) { |
+} // namespace |
+ |
+void RenderViewContextMenuBase::OnIconDownloaded( |
+ int command_id, |
+ int id, |
+ int http_status_code, |
+ const GURL& image_url, |
+ const std::vector<SkBitmap>& bitmaps, |
+ const std::vector<gfx::Size>& original_bitmap_sizes) { |
+ if (bitmaps.empty()) |
+ return; |
+ SetIcon(command_id, gfx::Image(gfx::Image::CreateFrom1xBitmap(bitmaps[0]))); |
+} |
+ |
+void RenderViewContextMenuBase::AddCustomItemsToMenu( |
+ const std::vector<content::MenuItem>& items, |
+ size_t depth, |
+ size_t* total_items, |
+ ui::SimpleMenuModel::Delegate* delegate, |
+ ui::SimpleMenuModel* menu_model) { |
if (depth > kMaxCustomMenuDepth) { |
LOG(ERROR) << "Custom menu too deeply nested."; |
return; |
@@ -79,6 +95,16 @@ void AddCustomItemsToMenu(const std::vector<content::MenuItem>& items, |
for (size_t i = 0; i < items.size(); ++i) { |
int command_id = RenderViewContextMenuBase::ConvertToContentCustomCommandId( |
items[i].action); |
+ if (!items[i].icon.empty()) { |
+ source_web_contents_->DownloadImage( |
+ GURL(items[i].icon), |
+ false, // is_favicon |
lazyboy
2015/02/13 08:10:39
What if we set is_favicon to true? Do we need cook
pals
2015/02/13 09:30:40
Done.
|
+ 0, // no max size |
lazyboy
2015/02/13 08:10:39
Instead of saying "no max size", say "unlimited".
pals
2015/02/13 09:30:40
Done.
|
+ base::Bind(&RenderViewContextMenuBase::OnIconDownloaded, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ command_id)); |
+ } |
+ |
if (!RenderViewContextMenuBase::IsContentCustomCommandId(command_id)) { |
LOG(ERROR) << "Custom menu action value out of range."; |
return; |
@@ -126,8 +152,6 @@ void AddCustomItemsToMenu(const std::vector<content::MenuItem>& items, |
} |
} |
-} // namespace |
- |
// static |
void RenderViewContextMenuBase::SetContentCustomCommandIdRange( |
int first, int last) { |
@@ -159,7 +183,8 @@ RenderViewContextMenuBase::RenderViewContextMenuBase( |
menu_model_(this), |
render_frame_id_(render_frame_host->GetRoutingID()), |
command_executed_(false), |
- render_process_id_(render_frame_host->GetProcess()->GetID()) { |
+ render_process_id_(render_frame_host->GetProcess()->GetID()), |
+ weak_ptr_factory_(this) { |
} |
RenderViewContextMenuBase::~RenderViewContextMenuBase() { |
@@ -215,6 +240,12 @@ void RenderViewContextMenuBase::AddSubMenu(int command_id, |
menu_model_.AddSubMenu(command_id, label, model); |
} |
+void RenderViewContextMenuBase::SetIcon(int command_id, |
+ const gfx::Image& icon) { |
+ if (toolkit_delegate_) |
+ toolkit_delegate_->SetIcon(command_id, icon); |
+} |
+ |
void RenderViewContextMenuBase::UpdateMenuItem(int command_id, |
bool enabled, |
bool hidden, |