1 // Copyright 2017 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 COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PANEL_H
6 #define COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PANEL_H
7 
8 #include "base/macros.h"
9 #include "components/spellcheck/common/spellcheck_panel.mojom.h"
10 #include "components/spellcheck/spellcheck_buildflags.h"
11 #include "content/public/renderer/render_frame_observer.h"
12 #include "mojo/public/cpp/bindings/pending_receiver.h"
13 #include "mojo/public/cpp/bindings/receiver_set.h"
14 #include "mojo/public/cpp/bindings/remote.h"
15 #include "services/service_manager/public/cpp/binder_registry.h"
16 #include "third_party/blink/public/platform/web_spell_check_panel_host_client.h"
17 
18 #if !BUILDFLAG(HAS_SPELLCHECK_PANEL)
19 #error "Spellcheck panel should be enabled."
20 #endif
21 
22 namespace service_manager {
23 class LocalInterfaceProvider;
24 }
25 
26 class SpellCheckPanel : public content::RenderFrameObserver,
27                         public blink::WebSpellCheckPanelHostClient,
28                         public spellcheck::mojom::SpellCheckPanel {
29  public:
30   SpellCheckPanel(content::RenderFrame* render_frame,
31                   service_manager::BinderRegistry* registry,
32                   service_manager::LocalInterfaceProvider* embedder_provider);
33   ~SpellCheckPanel() override;
34 
35  private:
36   // content::RenderFrameObserver:
37   void OnDestruct() override;
38 
39   // blink::WebSpellCheckPanelHostClient:
40   bool IsShowingSpellingUI() override;
41   void ShowSpellingUI(bool show) override;
42   void UpdateSpellingUIWithMisspelledWord(
43       const blink::WebString& word) override;
44 
45   // Binds browser receivers for the frame SpellCheckPanel interface.
46   void SpellCheckPanelReceiver(
47       mojo::PendingReceiver<spellcheck::mojom::SpellCheckPanel> receiver);
48 
49   // spellcheck::mojom::SpellCheckPanel:
50   void ToggleSpellPanel(bool visible) override;
51   void AdvanceToNextMisspelling() override;
52 
53   mojo::Remote<spellcheck::mojom::SpellCheckPanelHost> GetSpellCheckPanelHost();
54 
55   // SpellCheckPanel receivers.
56   mojo::ReceiverSet<spellcheck::mojom::SpellCheckPanel> receivers_;
57 
58   // True if the browser is showing the spelling panel.
59   bool spelling_panel_visible_;
60 
61   service_manager::LocalInterfaceProvider* embedder_provider_;
62 
63   DISALLOW_COPY_AND_ASSIGN(SpellCheckPanel);
64 };
65 
66 #endif
67