• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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 MOJO_EXAMPLES_PEPPER_CONTAINER_APP_PLUGIN_INSTANCE_H_
6 #define MOJO_EXAMPLES_PEPPER_CONTAINER_APP_PLUGIN_INSTANCE_H_
7 
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "mojo/examples/pepper_container_app/plugin_module.h"
11 #include "mojo/examples/pepper_container_app/resource_creation_impl.h"
12 #include "ppapi/c/pp_rect.h"
13 #include "ppapi/shared_impl/scoped_pp_resource.h"
14 #include "ppapi/thunk/ppb_instance_api.h"
15 
16 namespace mojo {
17 namespace examples {
18 
19 class PluginInstance : public ppapi::thunk::PPB_Instance_API {
20  public:
21   explicit PluginInstance(scoped_refptr<PluginModule> plugin_module);
22   virtual ~PluginInstance();
23 
24   // Notifies the plugin that a new instance has been created.
25   bool DidCreate();
26   // Notifies the plugin that the instance has been destroyed.
27   void DidDestroy();
28   // Notifies the plugin that the position or size of the instance has changed.
29   void DidChangeView(const PP_Rect& bounds);
30   // Notifies the plugin that the Graphics 3D context has been invalidated.
31   void Graphics3DContextLost();
32 
33   // Returns true if |device| has been bound as the current display surface.
34   bool IsBoundGraphics(PP_Resource device) const;
35 
pp_instance()36   PP_Instance pp_instance() const { return pp_instance_; }
resource_creation()37   ResourceCreationImpl* resource_creation() { return &resource_creation_; }
plugin_module()38   PluginModule* plugin_module() { return plugin_module_.get(); }
39 
40   // ppapi::thunk::PPB_Instance_API implementation.
41   virtual PP_Bool BindGraphics(PP_Instance instance,
42                                PP_Resource device) OVERRIDE;
43   virtual PP_Bool IsFullFrame(PP_Instance instance) OVERRIDE;
44   virtual const ppapi::ViewData* GetViewData(PP_Instance instance) OVERRIDE;
45   virtual PP_Bool FlashIsFullscreen(PP_Instance instance) OVERRIDE;
46   virtual PP_Var GetWindowObject(PP_Instance instance) OVERRIDE;
47   virtual PP_Var GetOwnerElementObject(PP_Instance instance) OVERRIDE;
48   virtual PP_Var ExecuteScript(PP_Instance instance,
49                                PP_Var script,
50                                PP_Var* exception) OVERRIDE;
51   virtual uint32_t GetAudioHardwareOutputSampleRate(
52       PP_Instance instance) OVERRIDE;
53   virtual uint32_t GetAudioHardwareOutputBufferSize(
54       PP_Instance instance) OVERRIDE;
55   virtual PP_Var GetDefaultCharSet(PP_Instance instance) OVERRIDE;
56   virtual void Log(PP_Instance instance,
57                    PP_LogLevel log_level,
58                    PP_Var value) OVERRIDE;
59   virtual void LogWithSource(PP_Instance instance,
60                              PP_LogLevel log_level,
61                              PP_Var source,
62                              PP_Var value) OVERRIDE;
63   virtual void SetPluginToHandleFindRequests(PP_Instance instance) OVERRIDE;
64   virtual void NumberOfFindResultsChanged(PP_Instance instance,
65                                           int32_t total,
66                                           PP_Bool final_result) OVERRIDE;
67   virtual void SelectedFindResultChanged(PP_Instance instance,
68                                          int32_t index) OVERRIDE;
69   virtual void SetTickmarks(PP_Instance instance,
70                             const PP_Rect* tickmarks,
71                             uint32_t count) OVERRIDE;
72   virtual PP_Bool IsFullscreen(PP_Instance instance) OVERRIDE;
73   virtual PP_Bool SetFullscreen(PP_Instance instance,
74                                 PP_Bool fullscreen) OVERRIDE;
75   virtual PP_Bool GetScreenSize(PP_Instance instance, PP_Size* size) OVERRIDE;
76   virtual ppapi::Resource* GetSingletonResource(
77       PP_Instance instance, ppapi::SingletonResourceID id) OVERRIDE;
78   virtual int32_t RequestInputEvents(PP_Instance instance,
79                                      uint32_t event_classes) OVERRIDE;
80   virtual int32_t RequestFilteringInputEvents(PP_Instance instance,
81                                               uint32_t event_classes) OVERRIDE;
82   virtual void ClearInputEventRequest(PP_Instance instance,
83                                       uint32_t event_classes) OVERRIDE;
84   virtual void StartTrackingLatency(PP_Instance instance) OVERRIDE;
85   virtual void PostMessage(PP_Instance instance, PP_Var message) OVERRIDE;
86   virtual int32_t RegisterMessageHandler(PP_Instance instance,
87                                          void* user_data,
88                                          const PPP_MessageHandler_0_1* handler,
89                                          PP_Resource message_loop) OVERRIDE;
90   virtual void UnregisterMessageHandler(PP_Instance instance) OVERRIDE;
91   virtual PP_Bool SetCursor(PP_Instance instance,
92                             PP_MouseCursor_Type type,
93                             PP_Resource image,
94                             const PP_Point* hot_spot) OVERRIDE;
95   virtual int32_t LockMouse(
96       PP_Instance instance,
97       scoped_refptr<ppapi::TrackedCallback> callback) OVERRIDE;
98   virtual void UnlockMouse(PP_Instance instance) OVERRIDE;
99   virtual void SetTextInputType(PP_Instance instance,
100                                 PP_TextInput_Type type) OVERRIDE;
101   virtual void UpdateCaretPosition(PP_Instance instance,
102                                    const PP_Rect& caret,
103                                    const PP_Rect& bounding_box) OVERRIDE;
104   virtual void CancelCompositionText(PP_Instance instance) OVERRIDE;
105   virtual void SelectionChanged(PP_Instance instance) OVERRIDE;
106   virtual void UpdateSurroundingText(PP_Instance instance,
107                                      const char* text,
108                                      uint32_t caret,
109                                      uint32_t anchor) OVERRIDE;
110   virtual void ZoomChanged(PP_Instance instance, double factor) OVERRIDE;
111   virtual void ZoomLimitsChanged(PP_Instance instance,
112                                  double minimum_factor,
113                                  double maximum_factor) OVERRIDE;
114   virtual PP_Var GetDocumentURL(PP_Instance instance,
115                                 PP_URLComponents_Dev* components) OVERRIDE;
116   virtual void PromiseResolved(PP_Instance instance,
117                                uint32 promise_id) OVERRIDE;
118   virtual void PromiseResolvedWithSession(PP_Instance instance,
119                                           uint32 promise_id,
120                                           PP_Var web_session_id_var) OVERRIDE;
121   virtual void PromiseRejected(PP_Instance instance,
122                                uint32 promise_id,
123                                PP_CdmExceptionCode exception_code,
124                                uint32 system_code,
125                                PP_Var error_description_var) OVERRIDE;
126   virtual void SessionMessage(PP_Instance instance,
127                               PP_Var web_session_id_var,
128                               PP_Var message_var,
129                               PP_Var destination_url_var) OVERRIDE;
130   virtual void SessionReady(PP_Instance instance,
131                             PP_Var web_session_id_var) OVERRIDE;
132   virtual void SessionClosed(PP_Instance instance,
133                              PP_Var web_session_id_var) OVERRIDE;
134   virtual void SessionError(PP_Instance instance,
135                             PP_Var web_session_id_var,
136                             PP_CdmExceptionCode exception_code,
137                             uint32 system_code,
138                             PP_Var error_description_var) OVERRIDE;
139   virtual void DeliverBlock(PP_Instance instance,
140                             PP_Resource decrypted_block,
141                             const PP_DecryptedBlockInfo* block_info) OVERRIDE;
142   virtual void DecoderInitializeDone(PP_Instance instance,
143                                      PP_DecryptorStreamType decoder_type,
144                                      uint32_t request_id,
145                                      PP_Bool success) OVERRIDE;
146   virtual void DecoderDeinitializeDone(PP_Instance instance,
147                                        PP_DecryptorStreamType decoder_type,
148                                        uint32_t request_id) OVERRIDE;
149   virtual void DecoderResetDone(PP_Instance instance,
150                                 PP_DecryptorStreamType decoder_type,
151                                 uint32_t request_id) OVERRIDE;
152   virtual void DeliverFrame(PP_Instance instance,
153                             PP_Resource decrypted_frame,
154                             const PP_DecryptedFrameInfo* frame_info) OVERRIDE;
155   virtual void DeliverSamples(
156       PP_Instance instance,
157       PP_Resource audio_frames,
158       const PP_DecryptedSampleInfo* sample_info) OVERRIDE;
159   virtual PP_Var ResolveRelativeToDocument(
160       PP_Instance instance,
161       PP_Var relative,
162       PP_URLComponents_Dev* components) OVERRIDE;
163   virtual PP_Bool DocumentCanRequest(PP_Instance instance, PP_Var url) OVERRIDE;
164   virtual PP_Bool DocumentCanAccessDocument(PP_Instance instance,
165                                             PP_Instance target) OVERRIDE;
166   virtual PP_Var GetPluginInstanceURL(
167       PP_Instance instance,
168       PP_URLComponents_Dev* components) OVERRIDE;
169   virtual PP_Var GetPluginReferrerURL(
170       PP_Instance instance,
171       PP_URLComponents_Dev* components) OVERRIDE;
172 
173  private:
174   PP_Instance pp_instance_;
175   ResourceCreationImpl resource_creation_;
176   scoped_refptr<PluginModule> plugin_module_;
177   ppapi::ScopedPPResource bound_graphics_;
178 
179   DISALLOW_COPY_AND_ASSIGN(PluginInstance);
180 };
181 
182 }  // namespace examples
183 }  // namespace mojo
184 
185 #endif  // MOJO_EXAMPLES_PEPPER_CONTAINER_APP_PLUGIN_INSTANCE_H_
186