OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "webkit/glue/plugins/pepper_plugin_instance.h" | 5 #include "webkit/glue/plugins/pepper_plugin_instance.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/histogram.h" | 8 #include "base/histogram.h" |
9 #if defined(OS_MACOSX) | 9 #if defined(OS_MACOSX) |
10 #include "base/mac_util.h" | 10 #include "base/mac_util.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "third_party/ppapi/c/dev/ppp_find_dev.h" | 26 #include "third_party/ppapi/c/dev/ppp_find_dev.h" |
27 #include "third_party/ppapi/c/dev/ppp_zoom_dev.h" | 27 #include "third_party/ppapi/c/dev/ppp_zoom_dev.h" |
28 #include "third_party/ppapi/c/pp_event.h" | 28 #include "third_party/ppapi/c/pp_event.h" |
29 #include "third_party/ppapi/c/pp_instance.h" | 29 #include "third_party/ppapi/c/pp_instance.h" |
30 #include "third_party/ppapi/c/pp_rect.h" | 30 #include "third_party/ppapi/c/pp_rect.h" |
31 #include "third_party/ppapi/c/pp_resource.h" | 31 #include "third_party/ppapi/c/pp_resource.h" |
32 #include "third_party/ppapi/c/pp_var.h" | 32 #include "third_party/ppapi/c/pp_var.h" |
33 #include "third_party/ppapi/c/ppb_core.h" | 33 #include "third_party/ppapi/c/ppb_core.h" |
34 #include "third_party/ppapi/c/ppb_instance.h" | 34 #include "third_party/ppapi/c/ppb_instance.h" |
35 #include "third_party/ppapi/c/ppp_instance.h" | 35 #include "third_party/ppapi/c/ppp_instance.h" |
36 #include "third_party/WebKit/WebKit/chromium/public/WebBindings.h" | |
37 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" | 36 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" |
38 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" | 37 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" |
39 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" | 38 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" |
40 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 39 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
41 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" | 40 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" |
42 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" | 41 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" |
43 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" | 42 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" |
44 #include "webkit/glue/plugins/pepper_buffer.h" | 43 #include "webkit/glue/plugins/pepper_buffer.h" |
45 #include "webkit/glue/plugins/pepper_graphics_2d.h" | 44 #include "webkit/glue/plugins/pepper_graphics_2d.h" |
46 #include "webkit/glue/plugins/pepper_event_conversion.h" | 45 #include "webkit/glue/plugins/pepper_event_conversion.h" |
47 #include "webkit/glue/plugins/pepper_image_data.h" | 46 #include "webkit/glue/plugins/pepper_image_data.h" |
48 #include "webkit/glue/plugins/pepper_plugin_delegate.h" | 47 #include "webkit/glue/plugins/pepper_plugin_delegate.h" |
49 #include "webkit/glue/plugins/pepper_plugin_module.h" | 48 #include "webkit/glue/plugins/pepper_plugin_module.h" |
50 #include "webkit/glue/plugins/pepper_string.h" | 49 #include "webkit/glue/plugins/pepper_string.h" |
51 #include "webkit/glue/plugins/pepper_url_loader.h" | 50 #include "webkit/glue/plugins/pepper_url_loader.h" |
52 #include "webkit/glue/plugins/pepper_var.h" | 51 #include "webkit/glue/plugins/pepper_var.h" |
53 | 52 |
54 using WebKit::WebBindings; | |
55 using WebKit::WebCanvas; | 53 using WebKit::WebCanvas; |
56 using WebKit::WebCursorInfo; | 54 using WebKit::WebCursorInfo; |
57 using WebKit::WebFrame; | 55 using WebKit::WebFrame; |
58 using WebKit::WebInputEvent; | 56 using WebKit::WebInputEvent; |
59 using WebKit::WebPluginContainer; | 57 using WebKit::WebPluginContainer; |
60 | 58 |
61 namespace pepper { | 59 namespace pepper { |
62 | 60 |
63 #if defined(OS_WIN) | 61 #if defined(OS_WIN) |
64 // Exported by pdf.dll | 62 // Exported by pdf.dll |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 return instance->BindGraphics(device_id); | 153 return instance->BindGraphics(device_id); |
156 } | 154 } |
157 | 155 |
158 bool IsFullFrame(PP_Instance instance_id) { | 156 bool IsFullFrame(PP_Instance instance_id) { |
159 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); | 157 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); |
160 if (!instance) | 158 if (!instance) |
161 return false; | 159 return false; |
162 return instance->full_frame(); | 160 return instance->full_frame(); |
163 } | 161 } |
164 | 162 |
165 PP_Var ExecuteScript(PP_Instance instance_id, | |
166 PP_Var script, | |
167 PP_Var* exception) { | |
168 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); | |
169 if (!instance) | |
170 return PP_MakeVoid(); | |
171 return instance->ExecuteScript(script, exception); | |
172 } | |
173 | |
174 const PPB_Instance ppb_instance = { | 163 const PPB_Instance ppb_instance = { |
175 &GetWindowObject, | 164 &GetWindowObject, |
176 &GetOwnerElementObject, | 165 &GetOwnerElementObject, |
177 &BindGraphics, | 166 &BindGraphics, |
178 &IsFullFrame, | 167 &IsFullFrame, |
179 &ExecuteScript, | |
180 }; | 168 }; |
181 | 169 |
182 void NumberOfFindResultsChanged(PP_Instance instance_id, | 170 void NumberOfFindResultsChanged(PP_Instance instance_id, |
183 int32_t total, | 171 int32_t total, |
184 bool final_result) { | 172 bool final_result) { |
185 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); | 173 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); |
186 if (!instance) | 174 if (!instance) |
187 return; | 175 return; |
188 | 176 |
189 DCHECK_NE(instance->find_identifier(), -1); | 177 DCHECK_NE(instance->find_identifier(), -1); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 } | 319 } |
332 | 320 |
333 return true; | 321 return true; |
334 } | 322 } |
335 | 323 |
336 bool PluginInstance::SetCursor(PP_CursorType_Dev type) { | 324 bool PluginInstance::SetCursor(PP_CursorType_Dev type) { |
337 cursor_.reset(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type))); | 325 cursor_.reset(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type))); |
338 return true; | 326 return true; |
339 } | 327 } |
340 | 328 |
341 PP_Var PluginInstance::ExecuteScript(PP_Var script, PP_Var* exception) { | |
342 TryCatch try_catch(exception); | |
343 if (try_catch.HasException()) | |
344 return PP_MakeVoid(); | |
345 | |
346 // Convert the script into an inconvenient NPString object. | |
347 String* script_string = GetString(script); | |
348 if (!script_string) { | |
349 try_catch.SetException("Script param to ExecuteScript must be a string."); | |
350 return PP_MakeVoid(); | |
351 } | |
352 NPString np_script; | |
353 np_script.UTF8Characters = script_string->value().c_str(); | |
354 np_script.UTF8Length = script_string->value().length(); | |
355 | |
356 // Get the current frame to pass to the evaluate function. | |
357 WebFrame* frame = container_->element().document().frame(); | |
358 if (!frame) { | |
359 try_catch.SetException("No frame to execute script in."); | |
360 return PP_MakeVoid(); | |
361 } | |
362 | |
363 NPVariant result; | |
364 bool ok = WebBindings::evaluate(NULL, frame->windowObject(), &np_script, | |
365 &result); | |
366 if (!ok) { | |
367 // TODO(brettw) bug 54011: The TryCatch isn't working properly and | |
368 // doesn't actually catch this exception. | |
369 try_catch.SetException("Exception caught"); | |
370 WebBindings::releaseVariantValue(&result); | |
371 return PP_MakeVoid(); | |
372 } | |
373 | |
374 PP_Var ret = NPVariantToPPVar(&result); | |
375 WebBindings::releaseVariantValue(&result); | |
376 return ret; | |
377 } | |
378 | |
379 void PluginInstance::Delete() { | 329 void PluginInstance::Delete() { |
380 instance_interface_->Delete(GetPPInstance()); | 330 instance_interface_->Delete(GetPPInstance()); |
381 | 331 |
382 container_ = NULL; | 332 container_ = NULL; |
383 } | 333 } |
384 | 334 |
385 bool PluginInstance::Initialize(WebPluginContainer* container, | 335 bool PluginInstance::Initialize(WebPluginContainer* container, |
386 const std::vector<std::string>& arg_names, | 336 const std::vector<std::string>& arg_names, |
387 const std::vector<std::string>& arg_values, | 337 const std::vector<std::string>& arg_values, |
388 bool full_frame) { | 338 bool full_frame) { |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 bounds.size.width = dest_rect.width(); | 809 bounds.size.width = dest_rect.width(); |
860 bounds.size.height = dest_rect.height(); | 810 bounds.size.height = dest_rect.height(); |
861 | 811 |
862 CGContextDrawImage(canvas, bounds, image); | 812 CGContextDrawImage(canvas, bounds, image); |
863 CGContextRestoreGState(canvas); | 813 CGContextRestoreGState(canvas); |
864 } | 814 } |
865 #endif // defined(OS_MACOSX) | 815 #endif // defined(OS_MACOSX) |
866 | 816 |
867 | 817 |
868 } // namespace pepper | 818 } // namespace pepper |
OLD | NEW |