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_CHILD_NPAPI_WEBPLUGIN_H_ 6 #define CONTENT_CHILD_NPAPI_WEBPLUGIN_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/basictypes.h" 12 #include "ui/gfx/native_widget_types.h" 13 #include "ui/gfx/rect.h" 14 #include "ui/gl/gpu_preference.h" 15 16 // TODO(port): this typedef is obviously incorrect on non-Windows 17 // platforms, but now a lot of code now accidentally depends on them 18 // existing. #ifdef out these declarations and fix all the users. 19 typedef void* HANDLE; 20 21 class GURL; 22 struct NPObject; 23 24 namespace content { 25 26 class WebPluginResourceClient; 27 #if defined(OS_MACOSX) 28 class WebPluginAcceleratedSurface; 29 #endif 30 31 // The WebKit side of a plugin implementation. It provides wrappers around 32 // operations that need to interact with the frame and other WebCore objects. 33 class WebPlugin { 34 public: 35 virtual ~WebPlugin() {} 36 37 // Called by the plugin delegate to let the WebPlugin know if the plugin is 38 // windowed (i.e. handle is not NULL) or windowless (handle is NULL). This 39 // tells the WebPlugin to send mouse/keyboard events to the plugin delegate, 40 // as well as the information about the HDC for paint operations. 41 virtual void SetWindow(gfx::PluginWindowHandle window) = 0; 42 43 // Whether input events should be sent to the delegate. 44 virtual void SetAcceptsInputEvents(bool accepts) = 0; 45 46 // Called by the plugin delegate to let it know that the window is being 47 // destroyed. 48 virtual void WillDestroyWindow(gfx::PluginWindowHandle window) = 0; 49 #if defined(OS_WIN) 50 // |pump_messages_event| is a event handle which is used in NPP_HandleEvent 51 // calls to pump messages if the plugin enters a modal loop. 52 // |dummy_activation_window} is used to ensure correct keyboard activation. 53 // It needs to be a child of the parent window. 54 virtual void SetWindowlessData(HANDLE pump_messages_event, 55 gfx::NativeViewId dummy_activation_window) = 0; 56 #endif 57 // Cancels a pending request. 58 virtual void CancelResource(unsigned long id) = 0; 59 virtual void Invalidate() = 0; 60 virtual void InvalidateRect(const gfx::Rect& rect) = 0; 61 62 // Returns the NPObject for the browser's window object. Does not 63 // take a reference. 64 virtual NPObject* GetWindowScriptNPObject() = 0; 65 66 // Returns the DOM element that loaded the plugin. Does not take a 67 // reference. 68 virtual NPObject* GetPluginElement() = 0; 69 70 // Resolves the proxies for the url, returns true on success. 71 virtual bool FindProxyForUrl(const GURL& url, std::string* proxy_list) = 0; 72 73 // Cookies 74 virtual void SetCookie(const GURL& url, 75 const GURL& first_party_for_cookies, 76 const std::string& cookie) = 0; 77 virtual std::string GetCookies(const GURL& url, 78 const GURL& first_party_for_cookies) = 0; 79 80 // Handles GetURL/GetURLNotify/PostURL/PostURLNotify requests initiated 81 // by plugins. If the plugin wants notification of the result, notify_id will 82 // be non-zero. 83 virtual void HandleURLRequest(const char* url, 84 const char* method, 85 const char* target, 86 const char* buf, 87 unsigned int len, 88 int notify_id, 89 bool popups_allowed, 90 bool notify_redirects) = 0; 91 92 // Cancels document load. 93 virtual void CancelDocumentLoad() = 0; 94 95 // Initiates a HTTP range request for an existing stream. 96 virtual void InitiateHTTPRangeRequest(const char* url, 97 const char* range_info, 98 int range_request_id) = 0; 99 100 // Returns true iff in incognito mode. 101 virtual bool IsOffTheRecord() = 0; 102 103 // Called when the WebPluginResourceClient instance is deleted. 104 virtual void ResourceClientDeleted( 105 WebPluginResourceClient* resource_client) {} 106 107 // Defers the loading of the resource identified by resource_id. This is 108 // controlled by the defer parameter. 109 virtual void SetDeferResourceLoading(unsigned long resource_id, 110 bool defer) = 0; 111 112 #if defined(OS_MACOSX) 113 // Called to inform the WebPlugin that the plugin has gained or lost focus. 114 virtual void FocusChanged(bool focused) {} 115 116 // Starts plugin IME. 117 virtual void StartIme() {} 118 119 // Returns the accelerated surface abstraction for accelerated plugins. 120 virtual WebPluginAcceleratedSurface* GetAcceleratedSurface( 121 gfx::GpuPreference gpu_preference) = 0; 122 123 // Core Animation plugin support. CA plugins always render through 124 // the compositor. 125 virtual void AcceleratedPluginEnabledRendering() = 0; 126 virtual void AcceleratedPluginAllocatedIOSurface(int32 width, 127 int32 height, 128 uint32 surface_id) = 0; 129 virtual void AcceleratedPluginSwappedIOSurface() = 0; 130 #endif 131 132 // Handles NPN_URLRedirectResponse calls issued by plugins in response to 133 // HTTP URL redirect notifications. 134 virtual void URLRedirectResponse(bool allow, int resource_id) = 0; 135 }; 136 137 // Simpler version of ResourceHandleClient that lends itself to proxying. 138 class WebPluginResourceClient { 139 public: 140 virtual ~WebPluginResourceClient() {} 141 142 virtual void WillSendRequest(const GURL& url, int http_status_code) = 0; 143 // The request_is_seekable parameter indicates whether byte range requests 144 // can be issued for the underlying stream. 145 virtual void DidReceiveResponse(const std::string& mime_type, 146 const std::string& headers, 147 uint32 expected_length, 148 uint32 last_modified, 149 bool request_is_seekable) = 0; 150 virtual void DidReceiveData(const char* buffer, int length, 151 int data_offset) = 0; 152 // The resource ids passed here ensures that data for range requests 153 // is cleared. This applies for seekable streams. 154 virtual void DidFinishLoading(unsigned long resource_id) = 0; 155 virtual void DidFail(unsigned long resource_id) = 0; 156 virtual bool IsMultiByteResponseExpected() = 0; 157 virtual int ResourceId() = 0; 158 // Tells this object that it will get responses from multiple resources. 159 // This is necessary since the plugin process uses a single instance of 160 // PluginStreamUrl object for multiple range requests. 161 virtual void AddRangeRequestResourceId(unsigned long resource_id) { } 162 }; 163 164 } // namespace content 165 166 #endif // CONTENT_CHILD_NPAPI_WEBPLUGIN_H_ 167