• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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_CHILD_NPAPI_WEBPLUGIN_DELEGATE_H_
6 #define CONTENT_CHILD_NPAPI_WEBPLUGIN_DELEGATE_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "base/strings/string16.h"
12 #include "build/build_config.h"
13 #include "content/common/cursors/webcursor.h"
14 #include "third_party/npapi/bindings/npapi.h"
15 #include "ui/gfx/native_widget_types.h"
16 
17 class GURL;
18 class SkCanvas;
19 struct NPObject;
20 
21 namespace blink {
22 class WebInputEvent;
23 }
24 
25 namespace gfx {
26 class Rect;
27 }
28 
29 namespace content {
30 
31 class WebPluginResourceClient;
32 
33 // This is the interface that a plugin implementation needs to provide.
34 class WebPluginDelegate {
35  public:
~WebPluginDelegate()36   virtual ~WebPluginDelegate() {}
37 
38   // Initializes the plugin implementation with the given (UTF8) arguments.
39   // Note that the lifetime of WebPlugin must be longer than this delegate.
40   // If this function returns false the plugin isn't started and shouldn't be
41   // called again.  If this method succeeds, then the WebPlugin is valid until
42   // PluginDestroyed is called.
43   // The load_manually parameter if true indicates that the plugin data would
44   // be passed from webkit. if false indicates that the plugin should download
45   // the data. This also controls whether the plugin is instantiated as a full
46   // page plugin (NP_FULL) or embedded (NP_EMBED).
47   virtual bool Initialize(const GURL& url,
48                           const std::vector<std::string>& arg_names,
49                           const std::vector<std::string>& arg_values,
50                           bool load_manually) = 0;
51 
52   // Called when the WebPlugin is being destroyed.  This is a signal to the
53   // delegate that it should tear-down the plugin implementation and not call
54   // methods on the WebPlugin again.
55   virtual void PluginDestroyed() = 0;
56 
57   // Update the geometry of the plugin.  This is a request to move the
58   // plugin, relative to its containing window, to the coords given by
59   // window_rect.  Its contents should be clipped to the coords given
60   // by clip_rect, which are relative to the origin of the plugin
61   // window.  The clip_rect is in plugin-relative coordinates.
62   virtual void UpdateGeometry(const gfx::Rect& window_rect,
63                               const gfx::Rect& clip_rect) = 0;
64 
65   // Tells the plugin to paint the damaged rect.  |canvas| is only used for
66   // windowless plugins.
67   virtual void Paint(SkCanvas* canvas, const gfx::Rect& rect) = 0;
68 
69   // Informs the plugin that it has gained or lost focus. This is only called in
70   // windowless mode.
71   virtual void SetFocus(bool focused) = 0;
72 
73   // For windowless plugins, gives them a user event like mouse/keyboard.
74   // Returns whether the event was handled. This is only called in windowsless
75   // mode. See NPAPI NPP_HandleEvent for more information.
76   virtual bool HandleInputEvent(const blink::WebInputEvent& event,
77                                 WebCursor::CursorInfo* cursor) = 0;
78 
79   // Gets the NPObject associated with the plugin for scripting.
80   virtual NPObject* GetPluginScriptableObject() = 0;
81 
82   // Gets the NPP instance uniquely identifying the plugin for its lifetime.
83   virtual struct _NPP* GetPluginNPP() = 0;
84 
85   // Gets the form value associated with the plugin instance.
86   // Returns false if the value is not available.
87   virtual bool GetFormValue(base::string16* value) = 0;
88 
89   // Receives notification about a resource load that the plugin initiated
90   // for a frame.
91   virtual void DidFinishLoadWithReason(const GURL& url, NPReason reason,
92                                        int notify_id) = 0;
93 
94   // Returns the process id of the process that is running the plugin.
95   virtual int GetProcessId() = 0;
96 
97   // The result, UTF-8 encoded, of the script execution is returned via this
98   // function.
99   virtual void SendJavaScriptStream(const GURL& url,
100                                     const std::string& result,
101                                     bool success,
102                                     int notify_id) = 0;
103 
104   // Receives notification about data being available.
105   virtual void DidReceiveManualResponse(const GURL& url,
106                                         const std::string& mime_type,
107                                         const std::string& headers,
108                                         uint32 expected_length,
109                                         uint32 last_modified) = 0;
110 
111   // Receives the data.
112   virtual void DidReceiveManualData(const char* buffer, int length) = 0;
113 
114   // Indicates end of data load.
115   virtual void DidFinishManualLoading() = 0;
116 
117   // Indicates a failure in data receipt.
118   virtual void DidManualLoadFail() = 0;
119 
120   // Creates a WebPluginResourceClient instance and returns the same.
121   virtual WebPluginResourceClient* CreateResourceClient(
122       unsigned long resource_id,
123       const GURL& url,
124       int notify_id) = 0;
125 
126   // Creates a WebPluginResourceClient instance for an existing stream that is
127   // has become seekable.
128   virtual WebPluginResourceClient* CreateSeekableResourceClient(
129       unsigned long resource_id, int range_request_id) = 0;
130 
131   // Tell the plugin that the given URL should be fetched. This is a result of
132   // loading the plugin data or the plugin calling HandleURLRequest which didn't
133   // end up being routed to another frame or being a javscript:// URL.
134   virtual void FetchURL(unsigned long resource_id,
135                         int notify_id,
136                         const GURL& url,
137                         const GURL& first_party_for_cookies,
138                         const std::string& method,
139                         const char* buf,
140                         unsigned int len,
141                         const GURL& referrer,
142                         bool notify_redirects,
143                         bool is_plugin_src_load,
144                         int origin_pid,
145                         int render_frame_id,
146                         int render_view_id) = 0;
147 
148 };
149 
150 }  // namespace content
151 
152 #endif  // CONTENT_CHILD_NPAPI_WEBPLUGIN_DELEGATE_H_
153