OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ppapi/shared_impl/ppb_instance_shared.h" | 5 #include "ppapi/shared_impl/ppb_instance_shared.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
10 #include "ppapi/c/ppb_input_event.h" | 10 #include "ppapi/c/ppb_input_event.h" |
11 #include "ppapi/shared_impl/ppapi_globals.h" | 11 #include "ppapi/shared_impl/ppapi_globals.h" |
| 12 #include "ppapi/shared_impl/ppb_image_data_shared.h" |
12 #include "ppapi/shared_impl/var.h" | 13 #include "ppapi/shared_impl/var.h" |
| 14 #include "ppapi/thunk/enter.h" |
| 15 #include "ppapi/thunk/ppb_image_data_api.h" |
13 | 16 |
14 namespace ppapi { | 17 namespace ppapi { |
15 | 18 |
16 PPB_Instance_Shared::~PPB_Instance_Shared() { | 19 PPB_Instance_Shared::~PPB_Instance_Shared() { |
17 } | 20 } |
18 | 21 |
19 void PPB_Instance_Shared::Log(PP_Instance instance, | 22 void PPB_Instance_Shared::Log(PP_Instance instance, |
20 PP_LogLevel_Dev level, | 23 PP_LogLevel_Dev level, |
21 PP_Var value) { | 24 PP_Var value) { |
22 LogWithSource(instance, level, PP_MakeUndefined(), value); | 25 LogWithSource(instance, level, PP_MakeUndefined(), value); |
(...skipping 22 matching lines...) Expand all Loading... |
45 PP_INPUTEVENT_CLASS_KEYBOARD | | 48 PP_INPUTEVENT_CLASS_KEYBOARD | |
46 PP_INPUTEVENT_CLASS_WHEEL | | 49 PP_INPUTEVENT_CLASS_WHEEL | |
47 PP_INPUTEVENT_CLASS_TOUCH | | 50 PP_INPUTEVENT_CLASS_TOUCH | |
48 PP_INPUTEVENT_CLASS_IME)) | 51 PP_INPUTEVENT_CLASS_IME)) |
49 return PP_ERROR_NOTSUPPORTED; | 52 return PP_ERROR_NOTSUPPORTED; |
50 | 53 |
51 // Everything else is valid. | 54 // Everything else is valid. |
52 return PP_OK; | 55 return PP_OK; |
53 } | 56 } |
54 | 57 |
| 58 bool PPB_Instance_Shared::ValidateSetCursorParams(PP_MouseCursor_Type type, |
| 59 PP_Resource image, |
| 60 const PP_Point* hot_spot) { |
| 61 if (static_cast<int>(type) < static_cast<int>(PP_MOUSECURSOR_TYPE_CUSTOM) || |
| 62 static_cast<int>(type) > static_cast<int>(PP_MOUSECURSOR_TYPE_GRABBING)) |
| 63 return false; // Cursor type out of range. |
| 64 if (type != PP_MOUSECURSOR_TYPE_CUSTOM) { |
| 65 // The image must not be specified if the type isn't custom. However, we |
| 66 // don't require that the hot spot be null since the C++ wrappers and proxy |
| 67 // pass the point by reference and it will normally be specified. |
| 68 return image == 0; |
| 69 } |
| 70 |
| 71 if (!hot_spot) |
| 72 return false; // Hot spot must be specified for custom cursor. |
| 73 |
| 74 thunk::EnterResourceNoLock<thunk::PPB_ImageData_API> enter(image, true); |
| 75 if (enter.failed()) |
| 76 return false; // Invalid image resource. |
| 77 |
| 78 // Validate the image size. A giant cursor can arbitrarily overwrite parts |
| 79 // of the screen resulting in potential spoofing attacks. So we force the |
| 80 // cursor to be a reasonably-sized image. |
| 81 PP_ImageDataDesc desc; |
| 82 if (!PP_ToBool(enter.object()->Describe(&desc))) |
| 83 return false; |
| 84 if (desc.size.width > 32 || desc.size.height > 32) |
| 85 return false; |
| 86 |
| 87 // Validate image format. |
| 88 if (desc.format != PPB_ImageData_Shared::GetNativeImageDataFormat()) |
| 89 return false; |
| 90 |
| 91 // Validate the hot spot location. |
| 92 if (hot_spot->x < 0 || hot_spot->x >= desc.size.width || |
| 93 hot_spot->y < 0 || hot_spot->y >= desc.size.height) |
| 94 return false; |
| 95 return true; |
| 96 } |
| 97 |
55 } // namespace ppapi | 98 } // namespace ppapi |
OLD | NEW |