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 CONTENT_RENDERER_PEPPER_PEPPER_WEBPLUGIN_IMPL_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_WEBPLUGIN_IMPL_H_
7 
8 #include <memory>
9 #include <string>
10 #include <vector>
11 
12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/sequenced_task_runner_helpers.h"
15 #include "mojo/public/cpp/bindings/remote.h"
16 #include "ppapi/c/pp_var.h"
17 #include "third_party/blink/public/mojom/input/focus_type.mojom-forward.h"
18 #include "third_party/blink/public/web/web_plugin.h"
19 #include "ui/gfx/geometry/rect.h"
20 
21 namespace blink {
22 struct WebPluginParams;
23 struct WebPrintParams;
24 }
25 
26 namespace content {
27 
28 class PepperPluginInstanceImpl;
29 class PluginInstanceThrottlerImpl;
30 class PluginModule;
31 class RenderFrameImpl;
32 
33 class PepperWebPluginImpl : public blink::WebPlugin {
34  public:
35   PepperWebPluginImpl(PluginModule* module,
36                       const blink::WebPluginParams& params,
37                       RenderFrameImpl* render_frame,
38                       std::unique_ptr<PluginInstanceThrottlerImpl> throttler);
39 
instance()40   PepperPluginInstanceImpl* instance() { return instance_.get(); }
41 
42   // blink::WebPlugin implementation.
43   blink::WebPluginContainer* Container() const override;
44   bool Initialize(blink::WebPluginContainer* container) override;
45   void Destroy() override;
46   v8::Local<v8::Object> V8ScriptableObject(v8::Isolate* isolate) override;
UpdateAllLifecyclePhases(blink::DocumentUpdateReason)47   void UpdateAllLifecyclePhases(blink::DocumentUpdateReason) override {}
48   void Paint(cc::PaintCanvas* canvas, const blink::WebRect& rect) override;
49   void UpdateGeometry(const blink::WebRect& window_rect,
50                       const blink::WebRect& clip_rect,
51                       const blink::WebRect& unobscured_rect,
52                       bool is_visible) override;
53   void UpdateFocus(bool focused, blink::mojom::FocusType focus_type) override;
54   void UpdateVisibility(bool visible) override;
55   blink::WebInputEventResult HandleInputEvent(
56       const blink::WebCoalescedInputEvent& event,
57       ui::Cursor* cursor) override;
58   void DidReceiveResponse(const blink::WebURLResponse& response) override;
59   void DidReceiveData(const char* data, size_t data_length) override;
60   void DidFinishLoading() override;
61   void DidFailLoading(const blink::WebURLError&) override;
62   bool HasSelection() const override;
63   blink::WebString SelectionAsText() const override;
64   blink::WebString SelectionAsMarkup() const override;
65   bool CanEditText() const override;
66   bool HasEditableText() const override;
67   bool CanUndo() const override;
68   bool CanRedo() const override;
69   bool ExecuteEditCommand(const blink::WebString& name) override;
70   bool ExecuteEditCommand(const blink::WebString& name,
71                           const blink::WebString& value) override;
72   blink::WebURL LinkAtPosition(const gfx::Point& position) const override;
73   bool GetPrintPresetOptionsFromDocument(
74       blink::WebPrintPresetOptions* preset_options) override;
75   bool IsPdfPlugin() override;
76   bool StartFind(const blink::WebString& search_text,
77                  bool case_sensitive,
78                  int identifier) override;
79   void SelectFindResult(bool forward, int identifier) override;
80   void StopFind() override;
81   bool SupportsPaginatedPrint() override;
82 
83   int PrintBegin(const blink::WebPrintParams& print_params) override;
84   void PrintPage(int page_number, cc::PaintCanvas* canvas) override;
85   void PrintEnd() override;
86 
87   bool CanRotateView() override;
88   void RotateView(RotationType type) override;
89   bool IsPlaceholder() override;
90 
91  private:
92   friend class base::DeleteHelper<PepperWebPluginImpl>;
93 
94   ~PepperWebPluginImpl() override;
95 
96   // Cleared upon successful initialization.
97   struct InitData;
98   std::unique_ptr<InitData> init_data_;
99 
100   // True if the instance represents the entire document in a frame instead of
101   // being an embedded resource.
102   const bool full_frame_;
103 
104   std::unique_ptr<PluginInstanceThrottlerImpl> throttler_;
105   scoped_refptr<PepperPluginInstanceImpl> instance_;
106   gfx::Rect plugin_rect_;
107   PP_Var instance_object_;
108   blink::WebPluginContainer* container_;
109 
110   DISALLOW_COPY_AND_ASSIGN(PepperWebPluginImpl);
111 };
112 
113 }  // namespace content
114 
115 #endif  // CONTENT_RENDERER_PEPPER_PEPPER_WEBPLUGIN_IMPL_H_
116