1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_NPAPI_WEBPLUGIN_IMPL_H_
#define CONTENT_RENDERER_NPAPI_WEBPLUGIN_IMPL_H_
#include <map>
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "content/child/npapi/webplugin.h"
#include "content/common/content_export.h"
#include "content/common/webplugin_geometry.h"
#include "third_party/WebKit/public/platform/WebRect.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h"
#include "third_party/WebKit/public/platform/WebVector.h"
#include "third_party/WebKit/public/web/WebPlugin.h"
#include "ui/gfx/native_widget_types.h"
#include "url/gurl.h"
namespace cc {
class IOSurfaceLayer;
}
namespace blink {
class WebFrame;
class WebLayer;
class WebPluginContainer;
class WebURLResponse;
class WebURLLoader;
class WebURLRequest;
struct WebPluginParams;
}
namespace content {
class MultipartResponseDelegate;
class RenderFrameImpl;
class RenderViewImpl;
class WebPluginDelegateProxy;
// This is the WebKit side of the plugin implementation that forwards calls,
// after changing out of WebCore types, to a delegate. The delegate may
// be in a different process.
class WebPluginImpl : public WebPlugin,
public blink::WebPlugin {
public:
WebPluginImpl(
blink::WebFrame* frame,
const blink::WebPluginParams& params,
const base::FilePath& file_path,
const base::WeakPtr<RenderViewImpl>& render_view,
RenderFrameImpl* render_frame);
~WebPluginImpl() override;
// Helper function for sorting post data.
CONTENT_EXPORT static bool SetPostData(blink::WebURLRequest* request,
const char* buf,
uint32 length);
blink::WebFrame* webframe() { return webframe_; }
// blink::WebPlugin methods:
virtual bool initialize(
blink::WebPluginContainer* container);
virtual void destroy();
virtual NPObject* scriptableObject();
virtual struct _NPP* pluginNPP();
virtual bool getFormValue(blink::WebString& value);
virtual void paint(
blink::WebCanvas* canvas, const blink::WebRect& paint_rect);
virtual void updateGeometry(
const blink::WebRect& frame_rect, const blink::WebRect& clip_rect,
const blink::WebVector<blink::WebRect>& cut_outs, bool is_visible);
virtual void updateFocus(bool focused);
virtual void updateVisibility(bool visible);
virtual bool acceptsInputEvents();
virtual bool handleInputEvent(
const blink::WebInputEvent& event, blink::WebCursorInfo& cursor_info);
virtual void didReceiveResponse(const blink::WebURLResponse& response);
virtual void didReceiveData(const char* data, int data_length);
virtual void didFinishLoading();
virtual void didFailLoading(const blink::WebURLError& error);
virtual void didFinishLoadingFrameRequest(
const blink::WebURL& url, void* notify_data);
virtual void didFailLoadingFrameRequest(
const blink::WebURL& url, void* notify_data,
const blink::WebURLError& error);
virtual bool isPlaceholder() override;
// WebPlugin implementation:
void SetWindow(gfx::PluginWindowHandle window) override;
void SetAcceptsInputEvents(bool accepts) override;
void WillDestroyWindow(gfx::PluginWindowHandle window) override;
void CancelResource(unsigned long id) override;
void Invalidate() override;
void InvalidateRect(const gfx::Rect& rect) override;
NPObject* GetWindowScriptNPObject() override;
NPObject* GetPluginElement() override;
bool FindProxyForUrl(const GURL& url, std::string* proxy_list) override;
void SetCookie(const GURL& url,
const GURL& first_party_for_cookies,
const std::string& cookie) override;
std::string GetCookies(const GURL& url,
const GURL& first_party_for_cookies) override;
void HandleURLRequest(const char* url,
const char* method,
const char* target,
const char* buf,
unsigned int len,
int notify_id,
bool popups_allowed,
bool notify_redirects) override;
void CancelDocumentLoad() override;
void InitiateHTTPRangeRequest(const char* url,
const char* range_info,
int pending_request_id) override;
void DidStartLoading() override;
void DidStopLoading() override;
bool IsOffTheRecord() override;
void SetDeferResourceLoading(unsigned long resource_id, bool defer) override;
void URLRedirectResponse(bool allow, int resource_id) override;
bool CheckIfRunInsecureContent(const GURL& url) override;
#if defined(OS_WIN)
void SetWindowlessData(HANDLE pump_messages_event,
gfx::NativeViewId dummy_activation_window) { }
void ReparentPluginWindow(HWND window, HWND parent) { }
void ReportExecutableMemory(size_t size) { }
#endif
#if defined(OS_MACOSX)
WebPluginAcceleratedSurface* GetAcceleratedSurface(
gfx::GpuPreference gpu_preference) override;
void AcceleratedPluginEnabledRendering() override;
void AcceleratedPluginAllocatedIOSurface(int32 width,
int32 height,
uint32 surface_id) override;
void AcceleratedPluginSwappedIOSurface() override;
#endif
private:
// Given a (maybe partial) url, completes using the base url.
GURL CompleteURL(const char* url);
enum RoutingStatus {
ROUTED,
NOT_ROUTED,
INVALID_URL,
GENERAL_FAILURE
};
// Determines the referrer value sent along with outgoing HTTP requests
// issued by plugins.
enum ReferrerValue {
PLUGIN_SRC,
DOCUMENT_URL,
NO_REFERRER
};
// Given a download request, check if we need to route the output to a frame.
// Returns ROUTED if the load is done and routed to a frame, NOT_ROUTED or
// corresponding error codes otherwise.
RoutingStatus RouteToFrame(const char* url,
bool is_javascript_url,
bool popups_allowed,
const char* method,
const char* target,
const char* buf,
unsigned int len,
int notify_id,
ReferrerValue referrer_flag);
// Returns the next avaiable resource id. Returns 0 if the operation fails.
// It may fail if the page has already been closed.
unsigned long GetNextResourceId();
// Initiates HTTP GET/POST requests.
// Returns true on success.
bool InitiateHTTPRequest(unsigned long resource_id,
WebPluginResourceClient* client,
const GURL& url,
const char* method,
const char* buf,
int len,
const char* range_info,
ReferrerValue referrer_flag,
bool notify_redirects,
bool check_mixed_scripting);
gfx::Rect GetWindowClipRect(const gfx::Rect& rect);
// Sets the actual Widget for the plugin.
void SetContainer(blink::WebPluginContainer* container);
// Destroys the plugin instance.
// The response_handle_to_ignore parameter if not NULL indicates the
// resource handle to be left valid during plugin shutdown.
void TearDownPluginInstance(blink::WebURLLoader* loader_to_ignore);
// WebURLLoaderClient implementation. We implement this interface in the
// renderer process, and then use the simple WebPluginResourceClient interface
// to relay the callbacks to the plugin.
void willSendRequest(blink::WebURLLoader* loader,
blink::WebURLRequest& request,
const blink::WebURLResponse& response);
void didSendData(blink::WebURLLoader* loader,
unsigned long long bytes_sent,
unsigned long long total_bytes_to_be_sent);
void didReceiveResponse(blink::WebURLLoader* loader,
const blink::WebURLResponse& response);
void didReceiveData(blink::WebURLLoader* loader, const char *buffer,
int data_length, int encoded_data_length);
void didFinishLoading(blink::WebURLLoader* loader,
double finishTime);
void didFail(blink::WebURLLoader* loader,
const blink::WebURLError& error);
// Helper function to remove the stored information about a resource
// request given its index in m_clients.
void RemoveClient(size_t i);
// Helper function to remove the stored information about a resource
// request given a handle.
void RemoveClient(blink::WebURLLoader* loader);
// Handles HTTP multipart responses, i.e. responses received with a HTTP
// status code of 206.
// Returns false if response is not multipart (may be if we requested
// single range).
bool HandleHttpMultipartResponse(const blink::WebURLResponse& response,
WebPluginResourceClient* client);
void HandleURLRequestInternal(const char* url,
const char* method,
const char* target,
const char* buf,
unsigned int len,
int notify_id,
bool popups_allowed,
ReferrerValue referrer_flag,
bool notify_redirects,
bool check_mixed_scripting);
// Tears down the existing plugin instance and creates a new plugin instance
// to handle the response identified by the loader parameter.
bool ReinitializePluginForResponse(blink::WebURLLoader* loader);
// Delayed task for downloading the plugin source URL.
void OnDownloadPluginSrcUrl();
struct ClientInfo;
// Helper functions
WebPluginResourceClient* GetClientFromLoader(blink::WebURLLoader* loader);
ClientInfo* GetClientInfoFromLoader(blink::WebURLLoader* loader);
// Helper function to set the referrer on the request passed in.
void SetReferrer(blink::WebURLRequest* request, ReferrerValue referrer_flag);
// Check for invalid chars like @, ;, \ before the first / (in path).
bool IsValidUrl(const GURL& url, ReferrerValue referrer_flag);
std::vector<ClientInfo> clients_;
bool windowless_;
gfx::PluginWindowHandle window_;
#if defined(OS_MACOSX)
bool next_io_surface_allocated_;
int32 next_io_surface_width_;
int32 next_io_surface_height_;
uint32 next_io_surface_id_;
scoped_refptr<cc::IOSurfaceLayer> io_surface_layer_;
scoped_ptr<blink::WebLayer> web_layer_;
#endif
bool accepts_input_events_;
RenderFrameImpl* render_frame_;
base::WeakPtr<RenderViewImpl> render_view_;
blink::WebFrame* webframe_;
WebPluginDelegateProxy* delegate_;
// This is just a weak reference.
blink::WebPluginContainer* container_;
// Unique identifier for this plugin, used to track script objects.
struct _NPP* npp_;
typedef std::map<WebPluginResourceClient*, MultipartResponseDelegate*>
MultiPartResponseHandlerMap;
// Tracks HTTP multipart response handlers instantiated for
// a WebPluginResourceClient instance.
MultiPartResponseHandlerMap multi_part_response_map_;
// The plugin source URL.
GURL plugin_url_;
// Indicates if the download would be initiated by the plugin or us.
bool load_manually_;
// Indicates if this is the first geometry update received by the plugin.
bool first_geometry_update_;
// Set to true if the next response error should be ignored.
bool ignore_response_error_;
// The current plugin geometry and clip rectangle.
WebPluginGeometry geometry_;
// The location of the plugin on disk.
base::FilePath file_path_;
// The mime type of the plugin.
std::string mime_type_;
// Holds the list of argument names and values passed to the plugin. We keep
// these so that we can re-initialize the plugin if we need to.
std::vector<std::string> arg_names_;
std::vector<std::string> arg_values_;
class LoaderClient : public blink::WebURLLoaderClient {
public:
LoaderClient(WebPluginImpl*);
virtual void willSendRequest(blink::WebURLLoader*,
blink::WebURLRequest&,
const blink::WebURLResponse&) override;
virtual void didSendData(blink::WebURLLoader*,
unsigned long long bytesSent,
unsigned long long totalBytesToBeSent) override;
virtual void didReceiveResponse(blink::WebURLLoader*,
const blink::WebURLResponse&) override;
virtual void didDownloadData(blink::WebURLLoader*,
int dataLength,
int encodedDataLength) override;
virtual void didReceiveData(blink::WebURLLoader*,
const char* data,
int dataLength,
int encodedDataLength) override;
virtual void didReceiveCachedMetadata(blink::WebURLLoader*,
const char* data,
int dataLength) override;
virtual void didFinishLoading(blink::WebURLLoader*,
double finishTime,
int64_t total_encoded_data_length) override;
virtual void didFail(blink::WebURLLoader*,
const blink::WebURLError&) override;
private:
WebPluginImpl* parent_;
};
LoaderClient loader_client_;
base::WeakPtrFactory<WebPluginImpl> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(WebPluginImpl);
};
} // namespace content
#endif // CONTENT_RENDERER_NPAPI_WEBPLUGIN_IMPL_H_
|