| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #define PEPPER_APIS_ENABLED 1 | 5 #define PEPPER_APIS_ENABLED 1 |
| 6 | 6 |
| 7 #include "webkit/glue/plugins/webplugin_delegate_pepper_impl.h" | 7 #include "chrome/renderer/webplugin_delegate_pepper.h" |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "app/gfx/blit.h" |
| 12 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 13 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 14 #include "base/process_util.h" | 15 #include "base/process_util.h" |
| 15 #include "base/scoped_ptr.h" | 16 #include "base/scoped_ptr.h" |
| 16 #include "base/stats_counters.h" | 17 #include "base/stats_counters.h" |
| 17 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 18 #include "webkit/api/public/WebInputEvent.h" | 19 #include "webkit/api/public/WebInputEvent.h" |
| 19 #include "webkit/glue/glue_util.h" | 20 #include "webkit/glue/glue_util.h" |
| 20 #include "webkit/glue/plugins/plugin_constants_win.h" | 21 #include "webkit/glue/plugins/plugin_constants_win.h" |
| 21 #include "webkit/glue/plugins/plugin_instance.h" | 22 #include "webkit/glue/plugins/plugin_instance.h" |
| 22 #include "webkit/glue/plugins/plugin_lib.h" | 23 #include "webkit/glue/plugins/plugin_lib.h" |
| 23 #include "webkit/glue/plugins/plugin_list.h" | 24 #include "webkit/glue/plugins/plugin_list.h" |
| 24 #include "webkit/glue/plugins/plugin_stream_url.h" | 25 #include "webkit/glue/plugins/plugin_stream_url.h" |
| 25 #include "webkit/glue/webkit_glue.h" | 26 #include "webkit/glue/webkit_glue.h" |
| 26 | 27 |
| 27 using webkit_glue::WebPlugin; | 28 using webkit_glue::WebPlugin; |
| 28 using webkit_glue::WebPluginDelegate; | 29 using webkit_glue::WebPluginDelegate; |
| 29 using webkit_glue::WebPluginResourceClient; | 30 using webkit_glue::WebPluginResourceClient; |
| 30 using WebKit::WebCursorInfo; | 31 using WebKit::WebCursorInfo; |
| 31 using WebKit::WebKeyboardEvent; | 32 using WebKit::WebKeyboardEvent; |
| 32 using WebKit::WebInputEvent; | 33 using WebKit::WebInputEvent; |
| 33 using WebKit::WebMouseEvent; | 34 using WebKit::WebMouseEvent; |
| 34 using WebKit::WebMouseWheelEvent; | 35 using WebKit::WebMouseWheelEvent; |
| 35 | 36 |
| 37 namespace { |
| 38 const uint32 kBytesPerPixel = 4; // Only 8888 RGBA for now. |
| 39 } // namespace |
| 36 | 40 |
| 37 WebPluginDelegatePepperImpl* WebPluginDelegatePepperImpl::Create( | 41 uint32 WebPluginDelegatePepper::next_buffer_id = 0; |
| 42 |
| 43 WebPluginDelegatePepper* WebPluginDelegatePepper::Create( |
| 38 const FilePath& filename, | 44 const FilePath& filename, |
| 39 const std::string& mime_type, | 45 const std::string& mime_type, |
| 40 gfx::PluginWindowHandle containing_view) { | 46 gfx::PluginWindowHandle containing_view) { |
| 41 scoped_refptr<NPAPI::PluginLib> plugin_lib = | 47 scoped_refptr<NPAPI::PluginLib> plugin_lib = |
| 42 NPAPI::PluginLib::CreatePluginLib(filename); | 48 NPAPI::PluginLib::CreatePluginLib(filename); |
| 43 if (plugin_lib.get() == NULL) | 49 if (plugin_lib.get() == NULL) |
| 44 return NULL; | 50 return NULL; |
| 45 | 51 |
| 46 NPError err = plugin_lib->NP_Initialize(); | 52 NPError err = plugin_lib->NP_Initialize(); |
| 47 if (err != NPERR_NO_ERROR) | 53 if (err != NPERR_NO_ERROR) |
| 48 return NULL; | 54 return NULL; |
| 49 | 55 |
| 50 scoped_refptr<NPAPI::PluginInstance> instance = | 56 scoped_refptr<NPAPI::PluginInstance> instance = |
| 51 plugin_lib->CreateInstance(mime_type); | 57 plugin_lib->CreateInstance(mime_type); |
| 52 return new WebPluginDelegatePepperImpl(containing_view, instance.get()); | 58 return new WebPluginDelegatePepper(containing_view, instance.get()); |
| 53 } | 59 } |
| 54 | 60 |
| 55 bool WebPluginDelegatePepperImpl::Initialize( | 61 bool WebPluginDelegatePepper::Initialize( |
| 56 const GURL& url, | 62 const GURL& url, |
| 57 const std::vector<std::string>& arg_names, | 63 const std::vector<std::string>& arg_names, |
| 58 const std::vector<std::string>& arg_values, | 64 const std::vector<std::string>& arg_values, |
| 59 WebPlugin* plugin, | 65 WebPlugin* plugin, |
| 60 bool load_manually) { | 66 bool load_manually) { |
| 61 plugin_ = plugin; | 67 plugin_ = plugin; |
| 62 | 68 |
| 63 instance_->set_web_plugin(plugin_); | 69 instance_->set_web_plugin(plugin_); |
| 64 int argc = 0; | 70 int argc = 0; |
| 65 scoped_array<char*> argn(new char*[arg_names.size()]); | 71 scoped_array<char*> argn(new char*[arg_names.size()]); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 80 // a valid window handle causes subtle bugs with plugins which retreive | 86 // a valid window handle causes subtle bugs with plugins which retreive |
| 81 // the window handle and validate the same. The window handle can be | 87 // the window handle and validate the same. The window handle can be |
| 82 // retreived via NPN_GetValue of NPNVnetscapeWindow. | 88 // retreived via NPN_GetValue of NPNVnetscapeWindow. |
| 83 instance_->set_window_handle(parent_); | 89 instance_->set_window_handle(parent_); |
| 84 | 90 |
| 85 plugin_url_ = url.spec(); | 91 plugin_url_ = url.spec(); |
| 86 | 92 |
| 87 return true; | 93 return true; |
| 88 } | 94 } |
| 89 | 95 |
| 90 void WebPluginDelegatePepperImpl::DestroyInstance() { | 96 void WebPluginDelegatePepper::DestroyInstance() { |
| 91 if (instance_ && (instance_->npp()->ndata != NULL)) { | 97 if (instance_ && (instance_->npp()->ndata != NULL)) { |
| 92 // Shutdown all streams before destroying so that | 98 // Shutdown all streams before destroying so that |
| 93 // no streams are left "in progress". Need to do | 99 // no streams are left "in progress". Need to do |
| 94 // this before calling set_web_plugin(NULL) because the | 100 // this before calling set_web_plugin(NULL) because the |
| 95 // instance uses the helper to do the download. | 101 // instance uses the helper to do the download. |
| 96 instance_->CloseStreams(); | 102 instance_->CloseStreams(); |
| 97 | 103 |
| 98 window_.window = NULL; | 104 window_.window = NULL; |
| 99 instance_->NPP_SetWindow(&window_); | 105 instance_->NPP_SetWindow(&window_); |
| 100 | 106 |
| 101 instance_->NPP_Destroy(); | 107 instance_->NPP_Destroy(); |
| 102 | 108 |
| 103 instance_->set_web_plugin(NULL); | 109 instance_->set_web_plugin(NULL); |
| 104 | 110 |
| 105 instance_ = 0; | 111 instance_ = 0; |
| 106 } | 112 } |
| 107 } | 113 } |
| 108 | 114 |
| 109 void WebPluginDelegatePepperImpl::UpdateGeometry( | 115 void WebPluginDelegatePepper::UpdateGeometry( |
| 110 const gfx::Rect& window_rect, | 116 const gfx::Rect& window_rect, |
| 111 const gfx::Rect& clip_rect) { | 117 const gfx::Rect& clip_rect) { |
| 112 WindowlessUpdateGeometry(window_rect, clip_rect); | 118 // Only resend to the instance if the geometry has changed. |
| 119 if (window_rect == window_rect_ && clip_rect == clip_rect_) |
| 120 return; |
| 121 |
| 122 clip_rect_ = clip_rect; |
| 123 cutout_rects_.clear(); |
| 124 |
| 125 if (window_rect_ == window_rect) |
| 126 return; |
| 127 window_rect_ = window_rect; |
| 128 uint32 buffer_size = window_rect.height() * |
| 129 window_rect.width() * |
| 130 kBytesPerPixel; |
| 131 if (buffer_size_ < buffer_size) { |
| 132 buffer_size_ = buffer_size; |
| 133 plugin_buffer_ = TransportDIB::Create(buffer_size, ++next_buffer_id); |
| 134 } |
| 135 |
| 136 if (!instance()) |
| 137 return; |
| 138 |
| 139 // TODO(sehr): do we need all this? |
| 140 window_.clipRect.top = clip_rect_.y(); |
| 141 window_.clipRect.left = clip_rect_.x(); |
| 142 window_.clipRect.bottom = clip_rect_.y() + clip_rect_.height(); |
| 143 window_.clipRect.right = clip_rect_.x() + clip_rect_.width(); |
| 144 window_.height = window_rect_.height(); |
| 145 window_.width = window_rect_.width(); |
| 146 window_.x = window_rect_.x(); |
| 147 window_.y = window_rect_.y(); |
| 148 window_.type = NPWindowTypeDrawable; |
| 113 } | 149 } |
| 114 | 150 |
| 115 NPObject* WebPluginDelegatePepperImpl::GetPluginScriptableObject() { | 151 NPObject* WebPluginDelegatePepper::GetPluginScriptableObject() { |
| 116 return instance_->GetPluginScriptableObject(); | 152 return instance_->GetPluginScriptableObject(); |
| 117 } | 153 } |
| 118 | 154 |
| 119 void WebPluginDelegatePepperImpl::DidFinishLoadWithReason( | 155 void WebPluginDelegatePepper::DidFinishLoadWithReason( |
| 120 const GURL& url, | 156 const GURL& url, |
| 121 NPReason reason, | 157 NPReason reason, |
| 122 intptr_t notify_data) { | 158 intptr_t notify_data) { |
| 123 instance()->DidFinishLoadWithReason( | 159 instance()->DidFinishLoadWithReason( |
| 124 url, reason, reinterpret_cast<void*>(notify_data)); | 160 url, reason, reinterpret_cast<void*>(notify_data)); |
| 125 } | 161 } |
| 126 | 162 |
| 127 int WebPluginDelegatePepperImpl::GetProcessId() { | 163 int WebPluginDelegatePepper::GetProcessId() { |
| 128 // We are in process, so the plugin pid is this current process pid. | 164 // We are in process, so the plugin pid is this current process pid. |
| 129 return base::GetCurrentProcId(); | 165 return base::GetCurrentProcId(); |
| 130 } | 166 } |
| 131 | 167 |
| 132 void WebPluginDelegatePepperImpl::SendJavaScriptStream( | 168 void WebPluginDelegatePepper::SendJavaScriptStream( |
| 133 const GURL& url, | 169 const GURL& url, |
| 134 const std::string& result, | 170 const std::string& result, |
| 135 bool success, | 171 bool success, |
| 136 bool notify_needed, | 172 bool notify_needed, |
| 137 intptr_t notify_data) { | 173 intptr_t notify_data) { |
| 138 instance()->SendJavaScriptStream(url, result, success, notify_needed, | 174 instance()->SendJavaScriptStream(url, result, success, notify_needed, |
| 139 notify_data); | 175 notify_data); |
| 140 } | 176 } |
| 141 | 177 |
| 142 void WebPluginDelegatePepperImpl::DidReceiveManualResponse( | 178 void WebPluginDelegatePepper::DidReceiveManualResponse( |
| 143 const GURL& url, const std::string& mime_type, | 179 const GURL& url, const std::string& mime_type, |
| 144 const std::string& headers, uint32 expected_length, uint32 last_modified) { | 180 const std::string& headers, uint32 expected_length, uint32 last_modified) { |
| 145 instance()->DidReceiveManualResponse(url, mime_type, headers, | 181 instance()->DidReceiveManualResponse(url, mime_type, headers, |
| 146 expected_length, last_modified); | 182 expected_length, last_modified); |
| 147 } | 183 } |
| 148 | 184 |
| 149 void WebPluginDelegatePepperImpl::DidReceiveManualData(const char* buffer, | 185 void WebPluginDelegatePepper::DidReceiveManualData(const char* buffer, |
| 150 int length) { | 186 int length) { |
| 151 instance()->DidReceiveManualData(buffer, length); | 187 instance()->DidReceiveManualData(buffer, length); |
| 152 } | 188 } |
| 153 | 189 |
| 154 void WebPluginDelegatePepperImpl::DidFinishManualLoading() { | 190 void WebPluginDelegatePepper::DidFinishManualLoading() { |
| 155 instance()->DidFinishManualLoading(); | 191 instance()->DidFinishManualLoading(); |
| 156 } | 192 } |
| 157 | 193 |
| 158 void WebPluginDelegatePepperImpl::DidManualLoadFail() { | 194 void WebPluginDelegatePepper::DidManualLoadFail() { |
| 159 instance()->DidManualLoadFail(); | 195 instance()->DidManualLoadFail(); |
| 160 } | 196 } |
| 161 | 197 |
| 162 FilePath WebPluginDelegatePepperImpl::GetPluginPath() { | 198 FilePath WebPluginDelegatePepper::GetPluginPath() { |
| 163 return instance()->plugin_lib()->plugin_info().path; | 199 return instance()->plugin_lib()->plugin_info().path; |
| 164 } | 200 } |
| 165 | 201 |
| 166 WebPluginResourceClient* WebPluginDelegatePepperImpl::CreateResourceClient( | 202 WebPluginResourceClient* WebPluginDelegatePepper::CreateResourceClient( |
| 167 int resource_id, const GURL& url, bool notify_needed, | 203 int resource_id, const GURL& url, bool notify_needed, |
| 168 intptr_t notify_data, intptr_t existing_stream) { | 204 intptr_t notify_data, intptr_t existing_stream) { |
| 169 // Stream already exists. This typically happens for range requests | 205 // Stream already exists. This typically happens for range requests |
| 170 // initiated via NPN_RequestRead. | 206 // initiated via NPN_RequestRead. |
| 171 if (existing_stream) { | 207 if (existing_stream) { |
| 172 NPAPI::PluginStream* plugin_stream = | 208 NPAPI::PluginStream* plugin_stream = |
| 173 reinterpret_cast<NPAPI::PluginStream*>(existing_stream); | 209 reinterpret_cast<NPAPI::PluginStream*>(existing_stream); |
| 174 | 210 |
| 175 return plugin_stream->AsResourceClient(); | 211 return plugin_stream->AsResourceClient(); |
| 176 } | 212 } |
| 177 | 213 |
| 178 std::string mime_type; | 214 std::string mime_type; |
| 179 NPAPI::PluginStreamUrl *stream = instance()->CreateStream( | 215 NPAPI::PluginStreamUrl *stream = instance()->CreateStream( |
| 180 resource_id, url, mime_type, notify_needed, | 216 resource_id, url, mime_type, notify_needed, |
| 181 reinterpret_cast<void*>(notify_data)); | 217 reinterpret_cast<void*>(notify_data)); |
| 182 return stream; | 218 return stream; |
| 183 } | 219 } |
| 184 | 220 |
| 185 bool WebPluginDelegatePepperImpl::IsPluginDelegateWindow( | 221 bool WebPluginDelegatePepper::IsPluginDelegateWindow( |
| 186 gfx::NativeWindow window) { | 222 gfx::NativeWindow window) { |
| 187 return false; | 223 return false; |
| 188 } | 224 } |
| 189 | 225 |
| 190 bool WebPluginDelegatePepperImpl::GetPluginNameFromWindow( | 226 bool WebPluginDelegatePepper::GetPluginNameFromWindow( |
| 191 gfx::NativeWindow window, std::wstring *plugin_name) { | 227 gfx::NativeWindow window, std::wstring *plugin_name) { |
| 192 return false; | 228 return false; |
| 193 } | 229 } |
| 194 | 230 |
| 195 bool WebPluginDelegatePepperImpl::IsDummyActivationWindow( | 231 bool WebPluginDelegatePepper::IsDummyActivationWindow( |
| 196 gfx::NativeWindow window) { | 232 gfx::NativeWindow window) { |
| 197 return false; | 233 return false; |
| 198 } | 234 } |
| 199 | 235 |
| 200 WebPluginDelegatePepperImpl::WebPluginDelegatePepperImpl( | 236 WebPluginDelegatePepper::WebPluginDelegatePepper( |
| 201 gfx::PluginWindowHandle containing_view, | 237 gfx::PluginWindowHandle containing_view, |
| 202 NPAPI::PluginInstance *instance) | 238 NPAPI::PluginInstance *instance) |
| 203 : plugin_(NULL), | 239 : plugin_(NULL), |
| 204 instance_(instance), | 240 instance_(instance), |
| 205 parent_(containing_view) { | 241 parent_(containing_view), |
| 242 buffer_size_(0), |
| 243 plugin_buffer_(0), |
| 244 background_canvas_(0) { |
| 206 memset(&window_, 0, sizeof(window_)); | 245 memset(&window_, 0, sizeof(window_)); |
| 207 } | 246 } |
| 208 | 247 |
| 209 WebPluginDelegatePepperImpl::~WebPluginDelegatePepperImpl() { | 248 WebPluginDelegatePepper::~WebPluginDelegatePepper() { |
| 210 DestroyInstance(); | 249 DestroyInstance(); |
| 211 } | 250 } |
| 212 | 251 |
| 213 void WebPluginDelegatePepperImpl::PluginDestroyed() { | 252 void WebPluginDelegatePepper::PluginDestroyed() { |
| 214 delete this; | 253 delete this; |
| 215 } | 254 } |
| 216 | 255 |
| 217 void WebPluginDelegatePepperImpl::Paint(gfx::NativeDrawingContext context, const
gfx::Rect& rect) { | 256 void WebPluginDelegatePepper::Paint(gfx::NativeDrawingContext context, |
| 257 const gfx::Rect& rect) { |
| 258 static StatsRate plugin_paint("Plugin.Paint"); |
| 259 StatsScope<StatsRate> scope(plugin_paint); |
| 260 // Blit from background_context to context. |
| 261 if (background_canvas_ != NULL) { |
| 262 gfx::Point origin(window_rect_.origin().x(), window_rect_.origin().y()); |
| 263 gfx::BlitCanvasToContext(context, rect, background_canvas_, origin); |
| 264 } |
| 265 } |
| 266 |
| 267 void WebPluginDelegatePepper::Print(gfx::NativeDrawingContext context) { |
| 218 NOTIMPLEMENTED(); | 268 NOTIMPLEMENTED(); |
| 219 } | 269 } |
| 220 | 270 |
| 221 void WebPluginDelegatePepperImpl::Print(gfx::NativeDrawingContext context) { | 271 void WebPluginDelegatePepper::InstallMissingPlugin() { |
| 222 NOTIMPLEMENTED(); | 272 NOTIMPLEMENTED(); |
| 223 } | 273 } |
| 224 | 274 |
| 225 void WebPluginDelegatePepperImpl::InstallMissingPlugin() { | 275 void WebPluginDelegatePepper::SetFocus() { |
| 226 NOTIMPLEMENTED(); | |
| 227 } | |
| 228 | |
| 229 void WebPluginDelegatePepperImpl::WindowlessUpdateGeometry( | |
| 230 const gfx::Rect& window_rect, | |
| 231 const gfx::Rect& clip_rect) { | |
| 232 // Only resend to the instance if the geometry has changed. | |
| 233 if (window_rect == window_rect_ && clip_rect == clip_rect_) | |
| 234 return; | |
| 235 | |
| 236 // We will inform the instance of this change when we call NPP_SetWindow. | |
| 237 clip_rect_ = clip_rect; | |
| 238 cutout_rects_.clear(); | |
| 239 | |
| 240 if (window_rect_ != window_rect) { | |
| 241 window_rect_ = window_rect; | |
| 242 WindowlessSetWindow(true); | |
| 243 // TODO(sehr): update the context here? | |
| 244 } | |
| 245 } | |
| 246 | |
| 247 void WebPluginDelegatePepperImpl::WindowlessPaint( | |
| 248 gfx::NativeDrawingContext context, | |
| 249 const gfx::Rect& damage_rect) { | |
| 250 static StatsRate plugin_paint("Plugin.Paint"); | |
| 251 StatsScope<StatsRate> scope(plugin_paint); | |
| 252 // TODO(sehr): save the context here? | |
| 253 } | |
| 254 | |
| 255 void WebPluginDelegatePepperImpl::WindowlessSetWindow(bool force_set_window) { | |
| 256 if (!instance()) | |
| 257 return; | |
| 258 | |
| 259 if (window_rect_.IsEmpty()) // wait for geometry to be set. | |
| 260 return; | |
| 261 | |
| 262 window_.clipRect.top = clip_rect_.y(); | |
| 263 window_.clipRect.left = clip_rect_.x(); | |
| 264 window_.clipRect.bottom = clip_rect_.y() + clip_rect_.height(); | |
| 265 window_.clipRect.right = clip_rect_.x() + clip_rect_.width(); | |
| 266 window_.height = window_rect_.height(); | |
| 267 window_.width = window_rect_.width(); | |
| 268 window_.x = window_rect_.x(); | |
| 269 window_.y = window_rect_.y(); | |
| 270 window_.type = NPWindowTypeDrawable; | |
| 271 | |
| 272 NPError err = instance()->NPP_SetWindow(&window_); | |
| 273 DCHECK(err == NPERR_NO_ERROR); | |
| 274 } | |
| 275 | |
| 276 void WebPluginDelegatePepperImpl::SetFocus() { | |
| 277 NPEvent npevent; | 276 NPEvent npevent; |
| 278 | 277 |
| 279 npevent.type = NPEventType_Focus; | 278 npevent.type = NPEventType_Focus; |
| 280 npevent.size = sizeof(NPEvent); | 279 npevent.size = sizeof(NPEvent); |
| 281 // TODO(sehr): what timestamp should this have? | 280 // TODO(sehr): what timestamp should this have? |
| 282 npevent.timeStampSeconds = 0.0; | 281 npevent.timeStampSeconds = 0.0; |
| 283 // Currently this API only supports gaining focus. | 282 // Currently this API only supports gaining focus. |
| 284 npevent.u.focus.value = 1; | 283 npevent.u.focus.value = 1; |
| 285 instance()->NPP_HandleEvent(&npevent); | 284 instance()->NPP_HandleEvent(&npevent); |
| 286 } | 285 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 reinterpret_cast<const WebMouseWheelEvent*>(event); | 350 reinterpret_cast<const WebMouseWheelEvent*>(event); |
| 352 npevent->u.wheel.modifier = mouse_wheel_event->modifiers; | 351 npevent->u.wheel.modifier = mouse_wheel_event->modifiers; |
| 353 npevent->u.wheel.deltaX = mouse_wheel_event->deltaX; | 352 npevent->u.wheel.deltaX = mouse_wheel_event->deltaX; |
| 354 npevent->u.wheel.deltaY = mouse_wheel_event->deltaY; | 353 npevent->u.wheel.deltaY = mouse_wheel_event->deltaY; |
| 355 npevent->u.wheel.wheelTicksX = mouse_wheel_event->wheelTicksX; | 354 npevent->u.wheel.wheelTicksX = mouse_wheel_event->wheelTicksX; |
| 356 npevent->u.wheel.wheelTicksY = mouse_wheel_event->wheelTicksY; | 355 npevent->u.wheel.wheelTicksY = mouse_wheel_event->wheelTicksY; |
| 357 npevent->u.wheel.scrollByPage = mouse_wheel_event->scrollByPage; | 356 npevent->u.wheel.scrollByPage = mouse_wheel_event->scrollByPage; |
| 358 } | 357 } |
| 359 } // namespace | 358 } // namespace |
| 360 | 359 |
| 361 bool WebPluginDelegatePepperImpl::HandleInputEvent(const WebInputEvent& event, | 360 bool WebPluginDelegatePepper::HandleInputEvent(const WebInputEvent& event, |
| 362 WebCursorInfo* cursor_info) { | 361 WebCursorInfo* cursor_info) { |
| 363 NPEvent npevent; | 362 NPEvent npevent; |
| 364 | 363 |
| 365 npevent.type = ConvertEventTypes(event.type); | 364 npevent.type = ConvertEventTypes(event.type); |
| 366 npevent.size = sizeof(NPEvent); | 365 npevent.size = sizeof(NPEvent); |
| 367 npevent.timeStampSeconds = event.timeStampSeconds; | 366 npevent.timeStampSeconds = event.timeStampSeconds; |
| 368 switch (npevent.type) { | 367 switch (npevent.type) { |
| 369 case NPEventType_Undefined: | 368 case NPEventType_Undefined: |
| 370 return false; | 369 return false; |
| 371 case NPEventType_MouseDown: | 370 case NPEventType_MouseDown: |
| 372 case NPEventType_MouseUp: | 371 case NPEventType_MouseUp: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 386 BuildCharEvent(&event, &npevent); | 385 BuildCharEvent(&event, &npevent); |
| 387 break; | 386 break; |
| 388 case NPEventType_Minimize: | 387 case NPEventType_Minimize: |
| 389 case NPEventType_Focus: | 388 case NPEventType_Focus: |
| 390 case NPEventType_Device: | 389 case NPEventType_Device: |
| 391 NOTIMPLEMENTED(); | 390 NOTIMPLEMENTED(); |
| 392 break; | 391 break; |
| 393 } | 392 } |
| 394 return instance()->NPP_HandleEvent(&npevent) != 0; | 393 return instance()->NPP_HandleEvent(&npevent) != 0; |
| 395 } | 394 } |
| 395 |
| 396 NPError WebPluginDelegatePepper::InitializeRenderContext( |
| 397 NPRenderType type, NPRenderContext* context) { |
| 398 switch (type) { |
| 399 case NPRenderGraphicsRGBA: { |
| 400 int width = window_rect_.width(); |
| 401 int height = window_rect_.height(); |
| 402 background_canvas_ = new skia::PlatformCanvas(width, height, false); |
| 403 plugin_canvas_ = plugin_buffer_->GetPlatformCanvas(width, height); |
| 404 if (background_canvas_ == NULL || plugin_canvas_ == NULL) { |
| 405 return NPERR_GENERIC_ERROR; |
| 406 } |
| 407 context->u.graphicsRgba.region = plugin_buffer_->memory(); |
| 408 context->u.graphicsRgba.stride = width * kBytesPerPixel; |
| 409 return NPERR_NO_ERROR; |
| 410 } |
| 411 default: |
| 412 return NPERR_GENERIC_ERROR; |
| 413 } |
| 414 } |
| 415 |
| 416 NPError WebPluginDelegatePepper::FlushRenderContext( |
| 417 NPRenderContext* context) { |
| 418 gfx::BlitCanvasToCanvas(background_canvas_, |
| 419 window_rect_, |
| 420 plugin_canvas_, |
| 421 window_rect_.origin()); |
| 422 return NPERR_NO_ERROR; |
| 423 } |
| OLD | NEW |