Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2149)

Unified Diff: chrome/browser/tab_contents/render_view_context_menu.h

Issue 7713033: Integrate the Spelling service to Chrome. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/profiles/profile.cc ('k') | chrome/browser/tab_contents/render_view_context_menu.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/tab_contents/render_view_context_menu.h
===================================================================
--- chrome/browser/tab_contents/render_view_context_menu.h (revision 99616)
+++ 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 controlling the instance while showing
+// 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(RenderViewContextMenuProxy* proxy, int id)
+// : proxy_(proxy),
+// 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 = response == 200;
+// const char* text = enabled ? "OK" : "ERROR";
+// proxy_->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_;
+// RenderViewContextMenuProxy* proxy_;
+// 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 RenderViewContextMenuProxy {
public:
+ // Add a menu item to a context menu.
+ virtual void AddMenuItem(int command_id, const string16& title) = 0;
+
+ // Update the status and text of the specified context-menu item.
+ 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 RenderViewContextMenuProxy {
+ 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);
};
« no previous file with comments | « chrome/browser/profiles/profile.cc ('k') | chrome/browser/tab_contents/render_view_context_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698