summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/spellchecker/spellcheck_provider.h
blob: f51b59411d2bdcf165305ce8f4b9cc2079926c31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// 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_RENDERER_SPELLCHECKER_SPELLCHECK_PROVIDER_H_
#define CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_PROVIDER_H_
#pragma once

#include <vector>

#include "base/id_map.h"
#include "content/renderer/render_view_observer.h"

class RenderView;
class SpellCheck;

namespace WebKit {
class WebString;
class WebTextCheckingResult;
class WebTextCheckingCompletion;
}

// This class deals with invoking browser-side spellcheck mechanism
// which is done asynchronously.
class SpellCheckProvider : public RenderViewObserver {
 public:
  typedef IDMap<WebKit::WebTextCheckingCompletion> WebTextCheckCompletions;

  SpellCheckProvider(RenderView* render_view, SpellCheck* spellcheck);
  virtual ~SpellCheckProvider();

  // Reqeusts async spell and grammar checker to the platform text
  // checker, which is available on the browser process.
  void RequestTextChecking(
      const WebKit::WebString& text,
      int document_tag,
      WebKit::WebTextCheckingCompletion* completion);

  // Check the availability of the platform spellchecker.
  // Makes this virtual for overriding on the unittest.
  virtual bool is_using_platform_spelling_engine() const;

  // The number of ongoing IPC requests.
  size_t pending_text_request_size() const {
    return text_check_completions_.size();
  }

  // RenderViewObserver implementation.
  virtual bool OnMessageReceived(const IPC::Message& message);

 private:
  // A message handler that receives async results for RequestTextChecking().
  void OnSpellCheckerRespondTextCheck(
      int identifier,
      int tag,
      const std::vector<WebKit::WebTextCheckingResult>& results);

  // Holds ongoing spellchecking operations, assigns IDs for the IPC routing.
  WebTextCheckCompletions text_check_completions_;
  // Spellcheck implementation for use. Weak reference.
  SpellCheck* spellcheck_;

  DISALLOW_COPY_AND_ASSIGN(SpellCheckProvider);
};

#endif  // CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_PROVIDER_H_