| 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_DELEGATE_PROXY_H_ | |
| 6 #define CONTENT_RENDERER_NPAPI_WEBPLUGIN_DELEGATE_PROXY_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <string> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/macros.h" | |
| 14 #include "base/memory/ref_counted.h" | |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/memory/weak_ptr.h" | |
| 17 #include "base/sequenced_task_runner_helpers.h" | |
| 18 #include "build/build_config.h" | |
| 19 #include "content/child/npapi/webplugin_delegate.h" | |
| 20 #include "content/public/common/webplugininfo.h" | |
| 21 #include "ipc/ipc_listener.h" | |
| 22 #include "ipc/ipc_message.h" | |
| 23 #include "ipc/ipc_sender.h" | |
| 24 #include "skia/ext/refptr.h" | |
| 25 #include "ui/gfx/geometry/rect.h" | |
| 26 #include "ui/gfx/native_widget_types.h" | |
| 27 #include "url/gurl.h" | |
| 28 | |
| 29 #if defined(OS_MACOSX) | |
| 30 #include "base/containers/hash_tables.h" | |
| 31 #endif | |
| 32 | |
| 33 struct NPObject; | |
| 34 struct PluginHostMsg_URLRequest_Params; | |
| 35 class SkBitmap; | |
| 36 | |
| 37 namespace base { | |
| 38 class WaitableEvent; | |
| 39 } | |
| 40 | |
| 41 | |
| 42 namespace content { | |
| 43 class PluginChannelHost; | |
| 44 class RenderFrameImpl; | |
| 45 class RenderViewImpl; | |
| 46 class SharedMemoryBitmap; | |
| 47 class WebPluginImpl; | |
| 48 | |
| 49 // An implementation of WebPluginDelegate that proxies all calls to | |
| 50 // the plugin process. | |
| 51 class WebPluginDelegateProxy | |
| 52 : public WebPluginDelegate, | |
| 53 public IPC::Listener, | |
| 54 public IPC::Sender, | |
| 55 public base::SupportsWeakPtr<WebPluginDelegateProxy> { | |
| 56 public: | |
| 57 WebPluginDelegateProxy(WebPluginImpl* plugin, | |
| 58 const std::string& mime_type, | |
| 59 const base::WeakPtr<RenderViewImpl>& render_view, | |
| 60 RenderFrameImpl* render_frame); | |
| 61 | |
| 62 // WebPluginDelegate implementation: | |
| 63 void PluginDestroyed() override; | |
| 64 bool Initialize(const GURL& url, | |
| 65 const std::vector<std::string>& arg_names, | |
| 66 const std::vector<std::string>& arg_values, | |
| 67 bool load_manually) override; | |
| 68 void UpdateGeometry(const gfx::Rect& window_rect, | |
| 69 const gfx::Rect& clip_rect) override; | |
| 70 void Paint(SkCanvas* canvas, const gfx::Rect& rect) override; | |
| 71 void SetFocus(bool focused) override; | |
| 72 bool HandleInputEvent(const blink::WebInputEvent& event, | |
| 73 WebCursor::CursorInfo* cursor) override; | |
| 74 int GetProcessId() override; | |
| 75 | |
| 76 // Informs the plugin that its containing content view has gained or lost | |
| 77 // first responder status. | |
| 78 virtual void SetContentAreaFocus(bool has_focus); | |
| 79 #if defined(OS_MACOSX) | |
| 80 // Informs the plugin that its enclosing window has gained or lost focus. | |
| 81 virtual void SetWindowFocus(bool window_has_focus); | |
| 82 // Informs the plugin that its container (window/tab) has changed visibility. | |
| 83 virtual void SetContainerVisibility(bool is_visible); | |
| 84 // Informs the plugin that its enclosing window's frame has changed. | |
| 85 virtual void WindowFrameChanged(gfx::Rect window_frame, gfx::Rect view_frame); | |
| 86 // Informs the plugin that plugin IME has completed. | |
| 87 // If |text| is empty, composition was cancelled. | |
| 88 virtual void ImeCompositionCompleted(const base::string16& text, | |
| 89 int plugin_id); | |
| 90 #endif | |
| 91 | |
| 92 // IPC::Listener implementation: | |
| 93 bool OnMessageReceived(const IPC::Message& msg) override; | |
| 94 void OnChannelError() override; | |
| 95 | |
| 96 // IPC::Sender implementation: | |
| 97 bool Send(IPC::Message* msg) override; | |
| 98 | |
| 99 protected: | |
| 100 friend class base::DeleteHelper<WebPluginDelegateProxy>; | |
| 101 ~WebPluginDelegateProxy() override; | |
| 102 | |
| 103 private: | |
| 104 struct SharedBitmap { | |
| 105 SharedBitmap(); | |
| 106 ~SharedBitmap(); | |
| 107 | |
| 108 scoped_ptr<SharedMemoryBitmap> bitmap; | |
| 109 skia::RefPtr<SkCanvas> canvas; | |
| 110 }; | |
| 111 | |
| 112 // Message handlers for messages that proxy WebPlugin methods, which | |
| 113 // we translate into calls to the real WebPlugin. | |
| 114 void OnCompleteURL(const std::string& url_in, std::string* url_out, | |
| 115 bool* result); | |
| 116 void OnHandleURLRequest(const PluginHostMsg_URLRequest_Params& params); | |
| 117 void OnInvalidateRect(const gfx::Rect& rect); | |
| 118 void OnResolveProxy(const GURL& url, bool* result, std::string* proxy_list); | |
| 119 void OnSetCookie(const GURL& url, | |
| 120 const GURL& first_party_for_cookies, | |
| 121 const std::string& cookie); | |
| 122 void OnGetCookies(const GURL& url, const GURL& first_party_for_cookies, | |
| 123 std::string* cookies); | |
| 124 void OnCancelDocumentLoad(); | |
| 125 void OnInitiateHTTPRangeRequest(const std::string& url, | |
| 126 const std::string& range_info, | |
| 127 int range_request_id); | |
| 128 void OnDidStartLoading(); | |
| 129 void OnDidStopLoading(); | |
| 130 #if defined(OS_MACOSX) | |
| 131 void OnFocusChanged(bool focused); | |
| 132 void OnStartIme(); | |
| 133 // Accelerated (Core Animation) plugin implementation. | |
| 134 void OnAcceleratedPluginEnabledRendering(); | |
| 135 void OnAcceleratedPluginAllocatedIOSurface(int32_t width, | |
| 136 int32_t height, | |
| 137 uint32_t surface_id); | |
| 138 void OnAcceleratedPluginSwappedIOSurface(); | |
| 139 #endif | |
| 140 // Helper function that sends the UpdateGeometry message. | |
| 141 void SendUpdateGeometry(bool bitmaps_changed); | |
| 142 | |
| 143 // Copies the given rectangle from the back-buffer transport_stores_ bitmap to | |
| 144 // the front-buffer transport_stores_ bitmap. | |
| 145 void CopyFromBackBufferToFrontBuffer(const gfx::Rect& rect); | |
| 146 | |
| 147 // Updates the front-buffer with the given rectangle from the back-buffer, | |
| 148 // either by copying the rectangle or flipping the buffers. | |
| 149 void UpdateFrontBuffer(const gfx::Rect& rect, bool allow_buffer_flipping); | |
| 150 | |
| 151 // Clears the shared memory section and canvases used for windowless plugins. | |
| 152 void ResetWindowlessBitmaps(); | |
| 153 | |
| 154 int front_buffer_index() const { | |
| 155 return front_buffer_index_; | |
| 156 } | |
| 157 | |
| 158 int back_buffer_index() const { | |
| 159 return 1 - front_buffer_index_; | |
| 160 } | |
| 161 | |
| 162 SkCanvas* front_buffer_canvas() const { | |
| 163 return transport_stores_[front_buffer_index()].canvas.get(); | |
| 164 } | |
| 165 | |
| 166 SkCanvas* back_buffer_canvas() const { | |
| 167 return transport_stores_[back_buffer_index()].canvas.get(); | |
| 168 } | |
| 169 | |
| 170 SharedMemoryBitmap* front_buffer_bitmap() const { | |
| 171 return transport_stores_[front_buffer_index()].bitmap.get(); | |
| 172 } | |
| 173 | |
| 174 SharedMemoryBitmap* back_buffer_bitmap() const { | |
| 175 return transport_stores_[back_buffer_index()].bitmap.get(); | |
| 176 } | |
| 177 | |
| 178 #if !defined(OS_WIN) | |
| 179 // Creates a process-local memory section and canvas. PlatformCanvas on | |
| 180 // Windows only works with a DIB, not arbitrary memory. | |
| 181 bool CreateLocalBitmap(std::vector<uint8_t>* memory, | |
| 182 skia::RefPtr<SkCanvas>* canvas); | |
| 183 #endif | |
| 184 | |
| 185 // Creates a shared memory section and canvas. | |
| 186 bool CreateSharedBitmap(scoped_ptr<SharedMemoryBitmap>* memory, | |
| 187 skia::RefPtr<SkCanvas>* canvas); | |
| 188 | |
| 189 // Called for cleanup during plugin destruction. Normally right before the | |
| 190 // plugin window gets destroyed, or when the plugin has crashed (at which | |
| 191 // point the window has already been destroyed). | |
| 192 void WillDestroyWindow(); | |
| 193 | |
| 194 #if defined(OS_WIN) | |
| 195 // Returns true if we should update the plugin geometry synchronously. | |
| 196 bool UseSynchronousGeometryUpdates(); | |
| 197 #endif | |
| 198 | |
| 199 base::WeakPtr<RenderViewImpl> render_view_; | |
| 200 RenderFrameImpl* render_frame_; | |
| 201 WebPluginImpl* plugin_; | |
| 202 bool uses_shared_bitmaps_; | |
| 203 #if defined(OS_MACOSX) | |
| 204 bool uses_compositor_; | |
| 205 #endif | |
| 206 scoped_refptr<PluginChannelHost> channel_host_; | |
| 207 std::string mime_type_; | |
| 208 int instance_id_; | |
| 209 WebPluginInfo info_; | |
| 210 | |
| 211 gfx::Rect plugin_rect_; | |
| 212 gfx::Rect clip_rect_; | |
| 213 | |
| 214 // Bitmap for crashed plugin | |
| 215 SkBitmap* sad_plugin_; | |
| 216 | |
| 217 // True if we got an invalidate from the plugin and are waiting for a paint. | |
| 218 bool invalidate_pending_; | |
| 219 | |
| 220 // If the plugin is transparent or not. | |
| 221 bool transparent_; | |
| 222 | |
| 223 // The index in the transport_stores_ array of the current front buffer | |
| 224 // (i.e., the buffer to display). | |
| 225 int front_buffer_index_; | |
| 226 SharedBitmap transport_stores_[2]; | |
| 227 // This lets us know the total portion of the transport store that has been | |
| 228 // painted since the buffers were created. | |
| 229 gfx::Rect transport_store_painted_; | |
| 230 // This is a bounding box on the portion of the front-buffer that was painted | |
| 231 // on the last buffer flip and which has not yet been re-painted in the | |
| 232 // back-buffer. | |
| 233 gfx::Rect front_buffer_diff_; | |
| 234 | |
| 235 // The url of the main frame hosting the plugin. | |
| 236 GURL page_url_; | |
| 237 | |
| 238 DISALLOW_COPY_AND_ASSIGN(WebPluginDelegateProxy); | |
| 239 }; | |
| 240 | |
| 241 } // namespace content | |
| 242 | |
| 243 #endif // CONTENT_RENDERER_NPAPI_WEBPLUGIN_DELEGATE_PROXY_H_ | |
| OLD | NEW |