Chromium Code Reviews| Index: chrome/browser/tab_contents/render_view_context_menu.h |
| =================================================================== |
| --- chrome/browser/tab_contents/render_view_context_menu.h (revision 97777) |
| +++ chrome/browser/tab_contents/render_view_context_menu.h (working copy) |
| @@ -12,9 +12,11 @@ |
| #include "base/memory/scoped_ptr.h" |
| #include "base/memory/scoped_vector.h" |
| +#include "base/observer_list.h" |
| #include "base/string16.h" |
| #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| #include "chrome/browser/extensions/extension_menu_manager.h" |
| +#include "chrome/browser/tab_contents/render_view_context_menu_observer.h" |
| #include "content/common/page_transition_types.h" |
| #include "ui/base/models/simple_menu_model.h" |
| #include "webkit/glue/context_menu.h" |
| @@ -22,7 +24,9 @@ |
| class ExtensionMenuItem; |
| class Profile; |
| +class RenderViewHost; |
| class TabContents; |
| +class SpellingMenuObserver; |
| namespace gfx { |
| class Point; |
| @@ -32,8 +36,75 @@ |
| struct WebMediaPlayerAction; |
| } |
| -class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate { |
| +// An interface that controls a RenderViewContextMenu instance from observers. |
| +// This interface is designed mainly for controling the instance while showing |
|
Avi (use Gerrit)
2011/08/23 18:38:19
typo: controlling
Hironori Bono
2011/08/25 11:18:58
Done.
|
| +// so we can add a context-menu item that takes long time to create its text, |
| +// such as retrieving the item text from a server. The simplest usage is: |
| +// 1. Adding an item with temporary text; |
| +// 2. Posting a background task that creates the item text, and; |
| +// 3. Calling UpdateMenuItem() in the callback function. |
| +// The following snippet describes the simple usage that updates a context-menu |
| +// item with this interface. |
| +// |
| +// class MyTask : public URLFetcher::Delegate { |
| +// public: |
| +// MyTask(RenderViewContextMenuDelegate* delegate, int id) |
| +// : delegate_(delegate), |
| +// id_(id) { |
| +// } |
| +// virtual ~MyTask() { |
| +// } |
| +// virtual void OnURLFetchComplete(const URLFetcher* source, |
| +// const GURL& url, |
| +// const net::URLRequestStatus& status, |
| +// int response, |
| +// const net::ResponseCookies& cookies, |
| +// const std::string& data) { |
| +// bool enabled = respose == 200; |
|
Avi (use Gerrit)
2011/08/23 18:38:19
response
Hironori Bono
2011/08/25 11:18:58
Done.
|
| +// const char* text = enabled ? "OK" : "ERROR"; |
| +// delegate_->UpdateMenuItem(id_, enabled, ASCIIToUTF16(text)); |
| +// } |
| +// void Start(const GURL* url, net::URLRequestContextGetter* context) { |
| +// fetcher_.reset(new URLFetcher(url, URLFetcher::GET, this)); |
| +// fetcher_->set_request_context(context); |
| +// fetcher_->Start(); |
| +// } |
| +// |
| +// private: |
| +// URLFetcher fetcher_; |
| +// RenderViewContextMenuDelegate* delegate_; |
| +// int id_; |
| +// }; |
| +// |
| +// void RenderViewContextMenu::AppendEditableItems() { |
| +// // Add a menu item with temporary text shown while we create the final |
| +// // text. |
| +// menu_model_.AddItemWithStringId(IDC_MY_ITEM, IDC_MY_TEXT); |
| +// |
| +// // Start a task that creates the final text. |
| +// my_task_ = new MyTask(this, IDC_MY_ITEM); |
| +// my_task_->Start(...); |
| +// } |
| +// |
| +class RenderViewContextMenuDelegate { |
|
Avi (use Gerrit)
2011/08/23 18:38:19
This naming seems backwards from most usage of the
Hironori Bono
2011/08/25 11:18:58
Thank you for your description. This is just cause
Avi (use Gerrit)
2011/08/25 14:59:12
That's better. I'm struggling to come up with a go
Hironori Bono
2011/08/29 08:17:04
It is a good question. I initially tried to split
|
| public: |
| + // Add a menu item to a context menu. |
| + virtual void AddMenuItem(int command_id, const string16& title) = 0; |
| + |
| + // Update the stauts and text of the specified context-menu item. |
|
Avi (use Gerrit)
2011/08/23 18:38:19
status
Hironori Bono
2011/08/25 11:18:58
Done.
|
| + virtual void UpdateMenuItem(int command_id, |
| + bool enabled, |
| + const string16& title) = 0; |
| + |
| + // Retrieve the RenderViewHost (or Profile) instance associated with a context |
| + // menu, respectively. |
| + virtual RenderViewHost* GetRenderViewHost() const = 0; |
| + virtual Profile* GetProfile() const = 0; |
| +}; |
| + |
| +class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate, |
| + public RenderViewContextMenuDelegate { |
| + public: |
| static const size_t kMaxExtensionItemTitleLength; |
| static const size_t kMaxSelectionTextLength; |
| @@ -55,6 +126,14 @@ |
| virtual void MenuWillShow(ui::SimpleMenuModel* source) OVERRIDE; |
| virtual void MenuClosed(ui::SimpleMenuModel* source) OVERRIDE; |
| + // RenderViewContextMenuDelegate implementation. |
| + virtual void AddMenuItem(int command_id, const string16& title) OVERRIDE; |
| + virtual void UpdateMenuItem(int command_id, |
| + bool enabled, |
| + const string16& title) OVERRIDE; |
| + virtual RenderViewHost* GetRenderViewHost() const; |
| + virtual Profile* GetProfile() const; |
| + |
| protected: |
| void InitMenu(); |
| @@ -170,6 +249,12 @@ |
| ScopedVector<ui::SimpleMenuModel> extension_menu_models_; |
| scoped_refptr<ProtocolHandlerRegistry> protocol_handler_registry_; |
| + // An observer that handles a spelling-menu items. |
| + scoped_ptr<SpellingMenuObserver> spelling_menu_observer_; |
| + |
| + // Our observers. |
| + mutable ObserverList<RenderViewContextMenuObserver> observers_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu); |
| }; |