1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_MESSAGE_FILTER_MAC_H_
6#define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_MESSAGE_FILTER_MAC_H_
7
8#include <map>
9
10#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
11#include "chrome/common/spellcheck_result.h"
12#include "content/public/browser/browser_message_filter.h"
13
14// A message filter implementation that receives
15// the Mac-specific spell checker requests from SpellCheckProvider.
16class SpellCheckMessageFilterMac : public content::BrowserMessageFilter {
17 public:
18  explicit SpellCheckMessageFilterMac(int render_process_id);
19
20  // BrowserMessageFilter implementation.
21  virtual void OverrideThreadForMessage(
22      const IPC::Message& message,
23      content::BrowserThread::ID* thread) OVERRIDE;
24  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
25
26  // Adjusts remote_results by examining local_results. Any result that's both
27  // local and remote stays type SPELLING, all others are flagged GRAMMAR.
28  // (This is needed to force gray underline for remote-only results.)
29  static void CombineResults(
30      std::vector<SpellCheckResult>* remote_results,
31      const std::vector<SpellCheckResult>& local_results);
32
33 private:
34  friend class TestingSpellCheckMessageFilter;
35  friend class SpellcheckMessageFilterMacTest;
36
37  virtual ~SpellCheckMessageFilterMac();
38
39  void OnCheckSpelling(const base::string16& word, int route_id, bool* correct);
40  void OnFillSuggestionList(const base::string16& word,
41                            std::vector<base::string16>* suggestions);
42  void OnShowSpellingPanel(bool show);
43  void OnUpdateSpellingPanelWithMisspelledWord(const base::string16& word);
44  void OnRequestTextCheck(int route_id,
45                          int identifier,
46                          const base::string16& text,
47                          std::vector<SpellCheckMarker> markers);
48
49  int ToDocumentTag(int route_id);
50  void RetireDocumentTag(int route_id);
51  std::map<int,int> tag_map_;
52
53  int render_process_id_;
54
55  // A JSON-RPC client that calls the Spelling service in the background.
56  scoped_ptr<SpellingServiceClient> client_;
57
58  DISALLOW_COPY_AND_ASSIGN(SpellCheckMessageFilterMac);
59};
60
61#endif  // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_MESSAGE_FILTER_MAC_H_
62