summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgroby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-07 10:14:20 +0000
committergroby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-07 10:14:20 +0000
commit677a0c0fc6dcf802f39b8d9d76c72050dae6b991 (patch)
tree7bc5e51cf6b25c0ea47d53e8592bd2380abb7583
parent8428bd50d5f0ed473485579445892c6d39870b07 (diff)
downloadchromium_src-677a0c0fc6dcf802f39b8d9d76c72050dae6b991.zip
chromium_src-677a0c0fc6dcf802f39b8d9d76c72050dae6b991.tar.gz
chromium_src-677a0c0fc6dcf802f39b8d9d76c72050dae6b991.tar.bz2
Update shared spellcheck data, with no upward dependency.
BUG=109215 Review URL: https://chromiumcodereview.appspot.com/11366102 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166373 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/renderer/chrome_content_renderer_client.cc23
-rw-r--r--chrome/renderer/chrome_content_renderer_client.h2
-rw-r--r--chrome/renderer/spellchecker/spellcheck_provider.cc31
-rw-r--r--chrome/renderer/spellchecker/spellcheck_provider.h22
4 files changed, 48 insertions, 30 deletions
diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc
index 39837f0..e21d588 100644
--- a/chrome/renderer/chrome_content_renderer_client.cc
+++ b/chrome/renderer/chrome_content_renderer_client.cc
@@ -68,6 +68,7 @@
#include "content/public/common/content_constants.h"
#include "content/public/renderer/render_thread.h"
#include "content/public/renderer/render_view.h"
+#include "content/public/renderer/render_view_visitor.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
#include "grit/renderer_resources.h"
@@ -142,6 +143,24 @@ static void AppendParams(const std::vector<string16>& additional_names,
existing_values->swap(values);
}
+class SpellCheckReplacer : public content::RenderViewVisitor {
+ public:
+ explicit SpellCheckReplacer(SpellCheck* spellcheck)
+ : spellcheck_(spellcheck) {}
+ virtual bool Visit(content::RenderView* render_view) OVERRIDE;
+
+ private:
+ SpellCheck* spellcheck_; // New shared spellcheck for all views. Weak Ptr.
+ DISALLOW_COPY_AND_ASSIGN(SpellCheckReplacer);
+};
+
+bool SpellCheckReplacer::Visit(content::RenderView* render_view) {
+ SpellCheckProvider* provider = SpellCheckProvider::Get(render_view);
+ DCHECK(provider);
+ provider->set_spellcheck(spellcheck_);
+ return true;
+}
+
} // namespace
namespace chrome {
@@ -254,7 +273,7 @@ void ChromeContentRendererClient::RenderViewCreated(
new PrintWebViewHelper(render_view);
#endif
new SearchBox(render_view);
- new SpellCheckProvider(render_view, this);
+ new SpellCheckProvider(render_view, spellcheck_.get());
new prerender::PrerendererClient(render_view);
#if defined(ENABLE_SAFE_BROWSING)
safe_browsing::MalwareDOMDetails::Create(render_view);
@@ -962,6 +981,8 @@ void ChromeContentRendererClient::OnPurgeMemory() {
if (spellcheck_.get())
thread->RemoveObserver(spellcheck_.get());
spellcheck_.reset(new SpellCheck());
+ SpellCheckReplacer replacer(spellcheck_.get());
+ content::RenderView::ForEach(&replacer);
thread->AddObserver(spellcheck_.get());
}
diff --git a/chrome/renderer/chrome_content_renderer_client.h b/chrome/renderer/chrome_content_renderer_client.h
index fc42d9b..bf34928 100644
--- a/chrome/renderer/chrome_content_renderer_client.h
+++ b/chrome/renderer/chrome_content_renderer_client.h
@@ -137,8 +137,6 @@ class ChromeContentRendererClient : public content::ContentRendererClient {
virtual void RegisterPPAPIInterfaceFactories(
webkit::ppapi::PpapiInterfaceFactoryManager* factory_manager) OVERRIDE;
- SpellCheck* spellcheck() const { return spellcheck_.get(); }
-
WebKit::WebPlugin* CreatePlugin(
content::RenderView* render_view,
WebKit::WebFrame* frame,
diff --git a/chrome/renderer/spellchecker/spellcheck_provider.cc b/chrome/renderer/spellchecker/spellcheck_provider.cc
index 0c48828..aa7b949 100644
--- a/chrome/renderer/spellchecker/spellcheck_provider.cc
+++ b/chrome/renderer/spellchecker/spellcheck_provider.cc
@@ -8,7 +8,6 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/common/spellcheck_messages.h"
#include "chrome/common/spellcheck_result.h"
-#include "chrome/renderer/chrome_content_renderer_client.h"
#include "chrome/renderer/spellchecker/spellcheck.h"
#include "content/public/renderer/render_view.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
@@ -109,11 +108,12 @@ int SpellCheckProvider::DocumentTag::GetTag() {
SpellCheckProvider::SpellCheckProvider(
content::RenderView* render_view,
- chrome::ChromeContentRendererClient* renderer_client)
+ SpellCheck* spellcheck)
: content::RenderViewObserver(render_view),
+ content::RenderViewObserverTracker<SpellCheckProvider>(render_view),
document_tag_(this, this->routing_id()),
spelling_panel_visible_(false),
- chrome_content_renderer_client_(renderer_client) {
+ spellcheck_(spellcheck) {
if (render_view) // NULL in unit tests.
render_view->GetWebView()->setSpellCheckClient(this);
}
@@ -205,9 +205,9 @@ void SpellCheckProvider::spellCheck(
WebVector<WebString>* optional_suggestions) {
string16 word(text);
// Will be NULL during unit tests.
- if (chrome_content_renderer_client_) {
+ if (spellcheck_) {
std::vector<string16> suggestions;
- chrome_content_renderer_client_->spellcheck()->SpellCheckWord(
+ spellcheck_->SpellCheckWord(
word.c_str(), word.size(), document_tag_.GetTag(),
&offset, &length, optional_suggestions ? & suggestions : NULL);
if (optional_suggestions)
@@ -236,11 +236,10 @@ void SpellCheckProvider::checkTextOfParagraph(
document_tag_.GetTag();
// Will be NULL during unit tets.
- if (!chrome_content_renderer_client_)
+ if (!spellcheck_)
return;
- chrome_content_renderer_client_->spellcheck()->SpellCheckParagraph(
- string16(text), results);
+ spellcheck_->SpellCheckParagraph(string16(text), results);
#endif
}
@@ -254,9 +253,8 @@ WebString SpellCheckProvider::autoCorrectWord(const WebString& word) {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kEnableSpellingAutoCorrect)) {
// Will be NULL during unit tests.
- if (chrome_content_renderer_client_) {
- return chrome_content_renderer_client_->spellcheck()->
- GetAutoCorrectionWord(word, document_tag_.GetTag());
+ if (spellcheck_) {
+ return spellcheck_->GetAutoCorrectionWord(word, document_tag_.GetTag());
}
}
return string16();
@@ -295,10 +293,9 @@ void SpellCheckProvider::OnRespondSpellingService(
// If |succeeded| is false, we use local spellcheck as a fallback.
if (!succeeded) {
- // |chrome_content_renderer_client| may be NULL in unit tests.
- if (chrome_content_renderer_client_) {
- chrome_content_renderer_client_->spellcheck()->RequestTextChecking(
- line, offset, completion);
+ // |spellcheck_| may be NULL in unit tests.
+ if (spellcheck_) {
+ spellcheck_->RequestTextChecking(line, offset, completion);
return;
}
}
@@ -306,8 +303,8 @@ void SpellCheckProvider::OnRespondSpellingService(
// Double-check the returned spellchecking results with our spellchecker to
// visualize the differences between ours and the on-line spellchecker.
WebKit::WebVector<WebKit::WebTextCheckingResult> textcheck_results;
- if (chrome_content_renderer_client_) {
- chrome_content_renderer_client_->spellcheck()->CreateTextCheckingResults(
+ if (spellcheck_) {
+ spellcheck_->CreateTextCheckingResults(
offset, line, results, &textcheck_results);
} else {
CreateTextCheckingResults(offset, results, &textcheck_results);
diff --git a/chrome/renderer/spellchecker/spellcheck_provider.h b/chrome/renderer/spellchecker/spellcheck_provider.h
index 198b623..cebab25 100644
--- a/chrome/renderer/spellchecker/spellcheck_provider.h
+++ b/chrome/renderer/spellchecker/spellcheck_provider.h
@@ -9,15 +9,13 @@
#include "base/id_map.h"
#include "content/public/renderer/render_view_observer.h"
+#include "content/public/renderer/render_view_observer_tracker.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSpellCheckClient.h"
class RenderView;
+class SpellCheck;
struct SpellCheckResult;
-namespace chrome {
-class ChromeContentRendererClient;
-}
-
namespace WebKit {
class WebString;
class WebTextCheckingCompletion;
@@ -26,13 +24,15 @@ struct WebTextCheckingResult;
// This class deals with invoking browser-side spellcheck mechanism
// which is done asynchronously.
-class SpellCheckProvider : public content::RenderViewObserver,
- public WebKit::WebSpellCheckClient {
+class SpellCheckProvider
+ : public content::RenderViewObserver,
+ public content::RenderViewObserverTracker<SpellCheckProvider>,
+ public WebKit::WebSpellCheckClient {
public:
typedef IDMap<WebKit::WebTextCheckingCompletion> WebTextCheckCompletions;
SpellCheckProvider(content::RenderView* render_view,
- chrome::ChromeContentRendererClient* render_client);
+ SpellCheck* spellcheck);
virtual ~SpellCheckProvider();
// Requests async spell and grammar checker to the platform text
@@ -47,6 +47,9 @@ class SpellCheckProvider : public content::RenderViewObserver,
return text_check_completions_.size();
}
+ // Replace shared spellcheck data.
+ void set_spellcheck(SpellCheck* spellcheck) { spellcheck_ = spellcheck; }
+
// RenderViewObserver implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void FocusedNodeChanged(const WebKit::WebNode& node) OVERRIDE;
@@ -133,9 +136,8 @@ class SpellCheckProvider : public content::RenderViewObserver,
// True if the browser is showing the spelling panel for us.
bool spelling_panel_visible_;
- // The ChromeContentRendererClient used to access the SpellChecker.
- // Weak reference.
- chrome::ChromeContentRendererClient* chrome_content_renderer_client_;
+ // Weak pointer to shared (per RenderView) spellcheck data.
+ SpellCheck* spellcheck_;
DISALLOW_COPY_AND_ASSIGN(SpellCheckProvider);
};