OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_BASE_H_ | 5 #ifndef COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_BASE_H_ |
6 #define COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_BASE_H_ | 6 #define COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_BASE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 virtual ~ToolkitDelegate() {} | 43 virtual ~ToolkitDelegate() {} |
44 // Initialize the toolkit's menu. | 44 // Initialize the toolkit's menu. |
45 virtual void Init(ui::SimpleMenuModel* menu_model) = 0; | 45 virtual void Init(ui::SimpleMenuModel* menu_model) = 0; |
46 | 46 |
47 virtual void Cancel() = 0; | 47 virtual void Cancel() = 0; |
48 | 48 |
49 // Updates the actual menu items controlled by the toolkit. | 49 // Updates the actual menu items controlled by the toolkit. |
50 virtual void UpdateMenuItem(int command_id, | 50 virtual void UpdateMenuItem(int command_id, |
51 bool enabled, | 51 bool enabled, |
52 bool hidden, | 52 bool hidden, |
53 const base::string16& title) = 0; | 53 const base::string16& title, |
| 54 gfx::Image* icon) = 0; |
54 }; | 55 }; |
55 | 56 |
56 static const size_t kMaxSelectionTextLength; | 57 static const size_t kMaxSelectionTextLength; |
57 | 58 |
58 static void SetContentCustomCommandIdRange(int first, int last); | 59 static void SetContentCustomCommandIdRange(int first, int last); |
59 | 60 |
60 // Convert a command ID so that it fits within the range for | 61 // Convert a command ID so that it fits within the range for |
61 // content context menu. | 62 // content context menu. |
62 static int ConvertToContentCustomCommandId(int id); | 63 static int ConvertToContentCustomCommandId(int id); |
63 | 64 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // RenderViewContextMenuProxy implementation. | 97 // RenderViewContextMenuProxy implementation. |
97 void AddMenuItem(int command_id, const base::string16& title) override; | 98 void AddMenuItem(int command_id, const base::string16& title) override; |
98 void AddCheckItem(int command_id, const base::string16& title) override; | 99 void AddCheckItem(int command_id, const base::string16& title) override; |
99 void AddSeparator() override; | 100 void AddSeparator() override; |
100 void AddSubMenu(int command_id, | 101 void AddSubMenu(int command_id, |
101 const base::string16& label, | 102 const base::string16& label, |
102 ui::MenuModel* model) override; | 103 ui::MenuModel* model) override; |
103 void UpdateMenuItem(int command_id, | 104 void UpdateMenuItem(int command_id, |
104 bool enabled, | 105 bool enabled, |
105 bool hidden, | 106 bool hidden, |
106 const base::string16& title) override; | 107 const base::string16& title, |
| 108 gfx::Image* icon) override; |
107 content::RenderViewHost* GetRenderViewHost() const override; | 109 content::RenderViewHost* GetRenderViewHost() const override; |
108 content::WebContents* GetWebContents() const override; | 110 content::WebContents* GetWebContents() const override; |
109 content::BrowserContext* GetBrowserContext() const override; | 111 content::BrowserContext* GetBrowserContext() const override; |
110 | 112 |
111 protected: | 113 protected: |
112 friend class RenderViewContextMenuTest; | 114 friend class RenderViewContextMenuTest; |
113 friend class RenderViewContextMenuPrefsTest; | 115 friend class RenderViewContextMenuPrefsTest; |
114 | 116 |
115 void set_content_type(ContextMenuContentType* content_type) { | 117 void set_content_type(ContextMenuContentType* content_type) { |
116 content_type_.reset(content_type); | 118 content_type_.reset(content_type); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 mutable ObserverList<RenderViewContextMenuObserver> observers_; | 176 mutable ObserverList<RenderViewContextMenuObserver> observers_; |
175 | 177 |
176 // Whether a command has been executed. Used to track whether menu observers | 178 // Whether a command has been executed. Used to track whether menu observers |
177 // should be notified of menu closing without execution. | 179 // should be notified of menu closing without execution. |
178 bool command_executed_; | 180 bool command_executed_; |
179 | 181 |
180 scoped_ptr<ContextMenuContentType> content_type_; | 182 scoped_ptr<ContextMenuContentType> content_type_; |
181 | 183 |
182 private: | 184 private: |
183 bool AppendCustomItems(); | 185 bool AppendCustomItems(); |
| 186 void AddCustomItemsToMenu(const std::vector<content::MenuItem>& items, |
| 187 size_t depth, |
| 188 size_t* total_items, |
| 189 ui::SimpleMenuModel::Delegate* delegate, |
| 190 ui::SimpleMenuModel* menu_model); |
| 191 void OnIconDownloaded(int id, |
| 192 int http_status_code, |
| 193 const GURL& image_url, |
| 194 const std::vector<SkBitmap>& bitmaps, |
| 195 const std::vector<gfx::Size>& original_bitmap_sizes); |
184 | 196 |
| 197 typedef std::map<int, content::MenuItem> IconMap; |
| 198 IconMap icon_map_; |
185 // The RenderFrameHost's IDs. | 199 // The RenderFrameHost's IDs. |
186 int render_process_id_; | 200 int render_process_id_; |
187 | 201 |
188 scoped_ptr<ToolkitDelegate> toolkit_delegate_; | 202 scoped_ptr<ToolkitDelegate> toolkit_delegate_; |
| 203 base::WeakPtrFactory<RenderViewContextMenuBase> weak_ptr_factory_; |
189 | 204 |
190 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenuBase); | 205 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenuBase); |
191 }; | 206 }; |
192 | 207 |
193 #endif // COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_BASE_H_ | 208 #endif // COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_BASE_H_ |
OLD | NEW |