Chromium Code Reviews| Index: chrome/browser/tab_contents/spelling_menu_observer.h |
| =================================================================== |
| --- chrome/browser/tab_contents/spelling_menu_observer.h (revision 0) |
| +++ chrome/browser/tab_contents/spelling_menu_observer.h (revision 0) |
| @@ -0,0 +1,103 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_TAB_CONTENTS_SPELLING_MENU_OBSERVER_H_ |
| +#define CHROME_BROWSER_TAB_CONTENTS_SPELLING_MENU_OBSERVER_H_ |
| +#pragma once |
| + |
| +#include <string> |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/string16.h" |
| +#include "base/timer.h" |
| +#include "chrome/browser/tab_contents/render_view_context_menu_observer.h" |
| +#include "content/common/url_fetcher.h" |
| + |
| +class GURL; |
| +class RenderViewContextMenuDelegate; |
| + |
| +// An observer that listens events from the RenderViewContextMenu class and show |
|
Avi (use Gerrit)
2011/08/23 18:38:19
...listens to events... and shows...
Hironori Bono
2011/08/25 11:18:58
Done.
|
| +// suggestions from the Spelling ("do you mean") service to a context menu while |
| +// we show it. This class implements two interfaces: |
| +// * RenderViewContextMenuObserver |
| +// This interface is used for adding a menu item and update it while showing. |
| +// * URLFethcer::Delegate |
|
Avi (use Gerrit)
2011/08/23 18:38:19
URLFetcher
Hironori Bono
2011/08/25 11:18:58
Done.
|
| +// This interface is used for sending a JSON_RPC request to the Spelling |
| +// service and retrieving its response. |
| +// these interfaces allows this class to make a JSON-RPC call to the Spelling |
|
Avi (use Gerrit)
2011/08/23 18:38:19
Capitalize "these". allows->allow.
Hironori Bono
2011/08/25 11:18:58
Done.
|
| +// service in the background and updates the context menu while showing. The |
|
Avi (use Gerrit)
2011/08/23 18:38:19
s/updates/update/
Hironori Bono
2011/08/25 11:18:58
Done.
|
| +// following snippet describes how to add this class to the observer list of the |
| +// RenderViewContextMenu class. |
| +// |
| +// void RenderViewContextMenu::InitMenu() { |
| +// spelling_menu_observer_.reset(new SpellingMenuObserver(this)); |
| +// if (spelling_menu_observer_.get()) |
| +// observers_.AddObserver(spelling_menu_observer.get()); |
| +// } |
| +// |
| +class SpellingMenuObserver : public RenderViewContextMenuObserver, |
| + public URLFetcher::Delegate { |
| + public: |
| + explicit SpellingMenuObserver(RenderViewContextMenuDelegate* delegate); |
| + virtual ~SpellingMenuObserver(); |
| + |
| + // RenderViewContextMenuObserver implementation. |
| + virtual void InitMenu(const ContextMenuParams& params) OVERRIDE; |
| + virtual bool IsCommandIdSupported(int command_id) OVERRIDE; |
| + virtual bool IsCommandIdEnabled(int command_id) OVERRIDE; |
| + virtual void ExecuteCommand(int command_id) OVERRIDE; |
| + |
| + // URLFetcher::Delegate implementation. |
| + virtual void OnURLFetchComplete(const URLFetcher* source, |
| + const GURL& url, |
| + const net::URLRequestStatus& status, |
| + int response_code, |
| + const net::ResponseCookies& cookies, |
| + const std::string& data) OVERRIDE; |
| + |
| + private: |
| + // Invokes a JSON-RPC call in the background. This function sends a JSON-RPC |
| + // request to the Spelling servive. Chrome will call ParseResponse() when it |
| + // receives the response from the service. |
| + bool Invoke(const string16& text, |
| + const std::string& locale, |
| + net::URLRequestContextGetter* context); |
| + |
| + // Parses the specified response from the Spelling service. |
| + bool ParseResponse(int code, const std::string& data); |
| + |
| + // The callback function for base::RepeatingTimer<SpellingMenuClient>. This |
| + // function updates the animation in the context-menu item. |
| + void OnAnimationTimerExpired(); |
| + |
| + // The interface to add a context-menu item and update it. This class uses |
| + // this interface to avoid accesing context-menu items directly. |
| + RenderViewContextMenuDelegate* delegate_; |
| + |
| + // The string used for animation until we receive a response from the Spelling |
| + // service. |
| + string16 loading_message_; |
| + int loading_frame_; |
| + |
| + // A flag represending whether this call finished successfully. |
| + bool succeeded_; |
| + |
| + // The string representing the result of this call. This string is a |
| + // suggestion when this call finished successfully. Otherwise it is error |
| + // text. Until we receive a response from the Spelling service, this string |
| + // stores the input string. (Since the Spelling service sends only misspelled |
| + // words, we replace these misspelled words in the input text with the |
| + // suggested words to create suggestion text. |
| + string16 result_; |
| + |
| + // The URLFetcher object used for sending a JSON-RPC request. |
| + scoped_ptr<URLFetcher> fetcher_; |
| + |
| + // A timer used for loading animation. |
| + base::RepeatingTimer<SpellingMenuObserver> animation_timer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SpellingMenuObserver); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_TAB_CONTENTS_SPELLING_MENU_OBSERVER_H_ |
| Property changes on: chrome\browser\tab_contents\spelling_menu_observer.h |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |