summaryrefslogtreecommitdiff
path: root/chromium/components/spellcheck/browser/spellcheck_message_filter_platform.h
blob: 75e538838c8bbe5ef713a4db8b12958db784a931 (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
67
68
69
70
71
72
73
// Copyright (c) 2012 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 COMPONENTS_SPELLCHECK_BROWSER_SPELLCHECK_MESSAGE_FILTER_PLATFORM_H_
#define COMPONENTS_SPELLCHECK_BROWSER_SPELLCHECK_MESSAGE_FILTER_PLATFORM_H_

#include <map>

#include "base/macros.h"
#include "build/build_config.h"
#include "components/spellcheck/browser/spelling_service_client.h"
#include "components/spellcheck/common/spellcheck_result.h"
#include "content/public/browser/browser_message_filter.h"

class SpellCheckerSessionBridge;

// A message filter implementation that receives
// the platform-specific spell checker requests from SpellCheckProvider.
class SpellCheckMessageFilterPlatform : public content::BrowserMessageFilter {
 public:
  explicit SpellCheckMessageFilterPlatform(int render_process_id);

  // BrowserMessageFilter implementation.
  void OverrideThreadForMessage(const IPC::Message& message,
                                content::BrowserThread::ID* thread) override;
  bool OnMessageReceived(const IPC::Message& message) override;

  // Adjusts remote_results by examining local_results. Any result that's both
  // local and remote stays type SPELLING, all others are flagged GRAMMAR.
  // (This is needed to force gray underline for remote-only results.)
  static void CombineResults(
      std::vector<SpellCheckResult>* remote_results,
      const std::vector<SpellCheckResult>& local_results);

 private:
  friend class TestingSpellCheckMessageFilter;
  friend class SpellcheckMessageFilterPlatformMacTest;

  ~SpellCheckMessageFilterPlatform() override;

  void OnCheckSpelling(const base::string16& word, int route_id, bool* correct);
  void OnFillSuggestionList(const base::string16& word,
                            std::vector<base::string16>* suggestions);
  void OnRequestTextCheck(int route_id,
                          int identifier,
                          const base::string16& text);

  int ToDocumentTag(int route_id);
  void RetireDocumentTag(int route_id);
  std::map<int,int> tag_map_;

  int render_process_id_;

#if defined(OS_ANDROID)
  friend struct content::BrowserThread::DeleteOnThread<
      content::BrowserThread::UI>;
  friend class base::DeleteHelper<SpellCheckMessageFilterPlatform>;

  void OnToggleSpellCheck(bool enabled, bool checked);
  void OnDestruct() const override;

  // Android-specific object used to query the Android spellchecker.
  std::unique_ptr<SpellCheckerSessionBridge> impl_;
#else
  // A JSON-RPC client that calls the Spelling service in the background.
  std::unique_ptr<SpellingServiceClient> client_;
#endif

  DISALLOW_COPY_AND_ASSIGN(SpellCheckMessageFilterPlatform);
};

#endif  // COMPONENTS_SPELLCHECK_BROWSER_SPELLCHECK_MESSAGE_FILTER_PLATFORM_H_