| OLD | NEW |
| (Empty) |
| 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_NPAPI_WEBPLUGIN_IMPL_H_ | |
| 6 #define CONTENT_RENDERER_NPAPI_WEBPLUGIN_IMPL_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 | |
| 11 #include <map> | |
| 12 #include <string> | |
| 13 #include <vector> | |
| 14 | |
| 15 #include "base/files/file_path.h" | |
| 16 #include "base/macros.h" | |
| 17 #include "base/memory/scoped_ptr.h" | |
| 18 #include "base/memory/weak_ptr.h" | |
| 19 #include "build/build_config.h" | |
| 20 #include "content/child/npapi/webplugin.h" | |
| 21 #include "content/common/content_export.h" | |
| 22 #include "content/common/webplugin_geometry.h" | |
| 23 #include "third_party/WebKit/public/platform/WebRect.h" | |
| 24 #include "third_party/WebKit/public/platform/WebString.h" | |
| 25 #include "third_party/WebKit/public/platform/WebURLRequest.h" | |
| 26 #include "third_party/WebKit/public/platform/WebVector.h" | |
| 27 #include "third_party/WebKit/public/web/WebPlugin.h" | |
| 28 #include "ui/gfx/native_widget_types.h" | |
| 29 #include "url/gurl.h" | |
| 30 | |
| 31 namespace cc { | |
| 32 class IOSurfaceLayer; | |
| 33 } | |
| 34 | |
| 35 namespace blink { | |
| 36 class WebFrame; | |
| 37 class WebLayer; | |
| 38 class WebPluginContainer; | |
| 39 class WebURLResponse; | |
| 40 class WebURLLoader; | |
| 41 class WebURLRequest; | |
| 42 struct WebPluginParams; | |
| 43 } | |
| 44 | |
| 45 namespace content { | |
| 46 class MultipartResponseDelegate; | |
| 47 class RenderFrameImpl; | |
| 48 class RenderViewImpl; | |
| 49 class WebPluginDelegateProxy; | |
| 50 | |
| 51 // This is the WebKit side of the plugin implementation that forwards calls, | |
| 52 // after changing out of WebCore types, to a delegate. The delegate may | |
| 53 // be in a different process. | |
| 54 class WebPluginImpl : public WebPlugin, | |
| 55 public blink::WebPlugin { | |
| 56 public: | |
| 57 WebPluginImpl( | |
| 58 blink::WebFrame* frame, | |
| 59 const blink::WebPluginParams& params, | |
| 60 const base::FilePath& file_path, | |
| 61 const base::WeakPtr<RenderViewImpl>& render_view, | |
| 62 RenderFrameImpl* render_frame); | |
| 63 ~WebPluginImpl() override; | |
| 64 | |
| 65 // Helper function for sorting post data. | |
| 66 CONTENT_EXPORT static bool SetPostData(blink::WebURLRequest* request, | |
| 67 const char* buf, | |
| 68 uint32_t length); | |
| 69 | |
| 70 blink::WebFrame* webframe() { return webframe_; } | |
| 71 | |
| 72 // blink::WebPlugin methods: | |
| 73 bool initialize(blink::WebPluginContainer* container) override; | |
| 74 void destroy() override; | |
| 75 void updateAllLifecyclePhases() override; | |
| 76 void paint(blink::WebCanvas* canvas, | |
| 77 const blink::WebRect& paint_rect) override; | |
| 78 void updateGeometry(const blink::WebRect& window_rect, | |
| 79 const blink::WebRect& clip_rect, | |
| 80 const blink::WebRect& unobscured_rect, | |
| 81 const blink::WebVector<blink::WebRect>& cut_outs_rects, | |
| 82 bool is_visible) override; | |
| 83 void updateFocus(bool focused, blink::WebFocusType focus_type) override; | |
| 84 void updateVisibility(bool visible) override; | |
| 85 bool acceptsInputEvents() override; | |
| 86 blink::WebInputEventResult handleInputEvent( | |
| 87 const blink::WebInputEvent& event, | |
| 88 blink::WebCursorInfo& cursor_info) override; | |
| 89 void didReceiveResponse(const blink::WebURLResponse& response) override {} | |
| 90 void didReceiveData(const char* data, int data_length) override {} | |
| 91 void didFinishLoading() override {} | |
| 92 void didFailLoading(const blink::WebURLError& error) override {} | |
| 93 bool isPlaceholder() override; | |
| 94 | |
| 95 // WebPlugin implementation: | |
| 96 void Invalidate() override; | |
| 97 void InvalidateRect(const gfx::Rect& rect) override; | |
| 98 bool FindProxyForUrl(const GURL& url, std::string* proxy_list) override; | |
| 99 void SetCookie(const GURL& url, | |
| 100 const GURL& first_party_for_cookies, | |
| 101 const std::string& cookie) override; | |
| 102 std::string GetCookies(const GURL& url, | |
| 103 const GURL& first_party_for_cookies) override; | |
| 104 void CancelDocumentLoad() override; | |
| 105 void DidStartLoading() override; | |
| 106 void DidStopLoading() override; | |
| 107 bool IsOffTheRecord() override; | |
| 108 #if defined(OS_MACOSX) | |
| 109 WebPluginAcceleratedSurface* GetAcceleratedSurface( | |
| 110 gfx::GpuPreference gpu_preference) override; | |
| 111 void AcceleratedPluginEnabledRendering() override; | |
| 112 void AcceleratedPluginAllocatedIOSurface(int32_t width, | |
| 113 int32_t height, | |
| 114 uint32_t surface_id) override; | |
| 115 void AcceleratedPluginSwappedIOSurface() override; | |
| 116 #endif | |
| 117 | |
| 118 private: | |
| 119 // Given a (maybe partial) url, completes using the base url. | |
| 120 GURL CompleteURL(const char* url); | |
| 121 | |
| 122 enum RoutingStatus { | |
| 123 ROUTED, | |
| 124 NOT_ROUTED, | |
| 125 INVALID_URL, | |
| 126 GENERAL_FAILURE | |
| 127 }; | |
| 128 | |
| 129 // Determines the referrer value sent along with outgoing HTTP requests | |
| 130 // issued by plugins. | |
| 131 enum ReferrerValue { | |
| 132 PLUGIN_SRC, | |
| 133 DOCUMENT_URL, | |
| 134 NO_REFERRER | |
| 135 }; | |
| 136 | |
| 137 // Given a download request, check if we need to route the output to a frame. | |
| 138 // Returns ROUTED if the load is done and routed to a frame, NOT_ROUTED or | |
| 139 // corresponding error codes otherwise. | |
| 140 RoutingStatus RouteToFrame(const char* url, | |
| 141 bool is_javascript_url, | |
| 142 bool popups_allowed, | |
| 143 const char* method, | |
| 144 const char* target, | |
| 145 const char* buf, | |
| 146 unsigned int len, | |
| 147 ReferrerValue referrer_flag); | |
| 148 | |
| 149 // Returns the next avaiable resource id. Returns 0 if the operation fails. | |
| 150 // It may fail if the page has already been closed. | |
| 151 unsigned long GetNextResourceId(); | |
| 152 | |
| 153 gfx::Rect GetWindowClipRect(const gfx::Rect& rect); | |
| 154 | |
| 155 // Sets the actual Widget for the plugin. | |
| 156 void SetContainer(blink::WebPluginContainer* container); | |
| 157 | |
| 158 // Destroys the plugin instance. | |
| 159 // The response_handle_to_ignore parameter if not NULL indicates the | |
| 160 // resource handle to be left valid during plugin shutdown. | |
| 161 void TearDownPluginInstance(blink::WebURLLoader* loader_to_ignore); | |
| 162 | |
| 163 // Tears down the existing plugin instance and creates a new plugin instance | |
| 164 // to handle the response identified by the loader parameter. | |
| 165 bool ReinitializePluginForResponse(blink::WebURLLoader* loader); | |
| 166 | |
| 167 | |
| 168 // Helper function to set the referrer on the request passed in. | |
| 169 void SetReferrer(blink::WebURLRequest* request, ReferrerValue referrer_flag); | |
| 170 | |
| 171 // Check for invalid chars like @, ;, \ before the first / (in path). | |
| 172 bool IsValidUrl(const GURL& url, ReferrerValue referrer_flag); | |
| 173 | |
| 174 #if defined(OS_MACOSX) | |
| 175 bool next_io_surface_allocated_; | |
| 176 int32_t next_io_surface_width_; | |
| 177 int32_t next_io_surface_height_; | |
| 178 uint32_t next_io_surface_id_; | |
| 179 scoped_refptr<cc::IOSurfaceLayer> io_surface_layer_; | |
| 180 scoped_ptr<blink::WebLayer> web_layer_; | |
| 181 #endif | |
| 182 RenderFrameImpl* render_frame_; | |
| 183 base::WeakPtr<RenderViewImpl> render_view_; | |
| 184 blink::WebFrame* webframe_; | |
| 185 | |
| 186 WebPluginDelegateProxy* delegate_; | |
| 187 | |
| 188 // This is just a weak reference. | |
| 189 blink::WebPluginContainer* container_; | |
| 190 | |
| 191 // The plugin source URL. | |
| 192 GURL plugin_url_; | |
| 193 | |
| 194 // Indicates if the download would be initiated by the plugin or us. | |
| 195 bool load_manually_; | |
| 196 | |
| 197 // Indicates if this is the first geometry update received by the plugin. | |
| 198 bool first_geometry_update_; | |
| 199 | |
| 200 // Set to true if the next response error should be ignored. | |
| 201 bool ignore_response_error_; | |
| 202 | |
| 203 // The current plugin geometry and clip rectangle. | |
| 204 WebPluginGeometry geometry_; | |
| 205 | |
| 206 // The location of the plugin on disk. | |
| 207 base::FilePath file_path_; | |
| 208 | |
| 209 // The mime type of the plugin. | |
| 210 std::string mime_type_; | |
| 211 | |
| 212 // Holds the list of argument names and values passed to the plugin. We keep | |
| 213 // these so that we can re-initialize the plugin if we need to. | |
| 214 std::vector<std::string> arg_names_; | |
| 215 std::vector<std::string> arg_values_; | |
| 216 | |
| 217 DISALLOW_COPY_AND_ASSIGN(WebPluginImpl); | |
| 218 }; | |
| 219 | |
| 220 } // namespace content | |
| 221 | |
| 222 #endif // CONTENT_RENDERER_NPAPI_WEBPLUGIN_IMPL_H_ | |
| OLD | NEW |