Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(677)

Side by Side Diff: webkit/plugins/ppapi/ppapi_plugin_instance.cc

Issue 9085027: Pepper gamepad support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove hardcoded size assert in favour of matching webkit size assert Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/plugins/ppapi/ppapi_plugin_instance.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/plugins/ppapi/ppapi_plugin_instance.h" 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/linked_ptr.h" 10 #include "base/memory/linked_ptr.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/utf_offset_string_conversions.h" 13 #include "base/utf_offset_string_conversions.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "ppapi/c/dev/ppb_console_dev.h" 15 #include "ppapi/c/dev/ppb_console_dev.h"
16 #include "ppapi/c/dev/ppb_find_dev.h" 16 #include "ppapi/c/dev/ppb_find_dev.h"
17 #include "ppapi/c/dev/ppb_gamepad_dev.h"
17 #include "ppapi/c/dev/ppb_zoom_dev.h" 18 #include "ppapi/c/dev/ppb_zoom_dev.h"
18 #include "ppapi/c/dev/ppp_find_dev.h" 19 #include "ppapi/c/dev/ppp_find_dev.h"
19 #include "ppapi/c/dev/ppp_selection_dev.h" 20 #include "ppapi/c/dev/ppp_selection_dev.h"
20 #include "ppapi/c/dev/ppp_zoom_dev.h" 21 #include "ppapi/c/dev/ppp_zoom_dev.h"
21 #include "ppapi/c/pp_rect.h" 22 #include "ppapi/c/pp_rect.h"
22 #include "ppapi/c/ppb_core.h" 23 #include "ppapi/c/ppb_core.h"
23 #include "ppapi/c/ppp_input_event.h" 24 #include "ppapi/c/ppp_input_event.h"
24 #include "ppapi/c/ppp_instance.h" 25 #include "ppapi/c/ppp_instance.h"
25 #include "ppapi/c/ppp_messaging.h" 26 #include "ppapi/c/ppp_messaging.h"
26 #include "ppapi/c/ppp_mouse_lock.h" 27 #include "ppapi/c/ppp_mouse_lock.h"
(...skipping 11 matching lines...) Expand all
38 #include "printing/units.h" 39 #include "printing/units.h"
39 #include "third_party/skia/include/core/SkCanvas.h" 40 #include "third_party/skia/include/core/SkCanvas.h"
40 #include "third_party/skia/include/core/SkRect.h" 41 #include "third_party/skia/include/core/SkRect.h"
41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" 42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h" 43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h"
43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" 44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h"
44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" 45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 48 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
49 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads. h"
48 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
49 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 51 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" 52 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
51 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" 53 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
52 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" 54 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
53 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h" 55 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h"
54 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 56 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
55 #include "webkit/plugins/ppapi/common.h" 57 #include "webkit/plugins/ppapi/common.h"
56 #include "webkit/plugins/ppapi/event_conversion.h" 58 #include "webkit/plugins/ppapi/event_conversion.h"
57 #include "webkit/plugins/ppapi/fullscreen_container.h" 59 #include "webkit/plugins/ppapi/fullscreen_container.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 COMPILE_ASSERT_MATCHING_ENUM(TypeCopy, PP_CURSORTYPE_COPY); 221 COMPILE_ASSERT_MATCHING_ENUM(TypeCopy, PP_CURSORTYPE_COPY);
220 COMPILE_ASSERT_MATCHING_ENUM(TypeNone, PP_CURSORTYPE_NONE); 222 COMPILE_ASSERT_MATCHING_ENUM(TypeNone, PP_CURSORTYPE_NONE);
221 COMPILE_ASSERT_MATCHING_ENUM(TypeNotAllowed, PP_CURSORTYPE_NOTALLOWED); 223 COMPILE_ASSERT_MATCHING_ENUM(TypeNotAllowed, PP_CURSORTYPE_NOTALLOWED);
222 COMPILE_ASSERT_MATCHING_ENUM(TypeZoomIn, PP_CURSORTYPE_ZOOMIN); 224 COMPILE_ASSERT_MATCHING_ENUM(TypeZoomIn, PP_CURSORTYPE_ZOOMIN);
223 COMPILE_ASSERT_MATCHING_ENUM(TypeZoomOut, PP_CURSORTYPE_ZOOMOUT); 225 COMPILE_ASSERT_MATCHING_ENUM(TypeZoomOut, PP_CURSORTYPE_ZOOMOUT);
224 COMPILE_ASSERT_MATCHING_ENUM(TypeGrab, PP_CURSORTYPE_GRAB); 226 COMPILE_ASSERT_MATCHING_ENUM(TypeGrab, PP_CURSORTYPE_GRAB);
225 COMPILE_ASSERT_MATCHING_ENUM(TypeGrabbing, PP_CURSORTYPE_GRABBING); 227 COMPILE_ASSERT_MATCHING_ENUM(TypeGrabbing, PP_CURSORTYPE_GRABBING);
226 // Do not assert WebCursorInfo::TypeCustom == PP_CURSORTYPE_CUSTOM; 228 // Do not assert WebCursorInfo::TypeCustom == PP_CURSORTYPE_CUSTOM;
227 // PP_CURSORTYPE_CUSTOM is pinned to allow new cursor types. 229 // PP_CURSORTYPE_CUSTOM is pinned to allow new cursor types.
228 230
231 // Ensure conversion from WebKit::WebGamepads to PP_GamepadsData_Dev is safe.
232 // See also DCHECKs in SampleGamepads below.
233 COMPILE_ASSERT(sizeof(WebKit::WebGamepads) == sizeof(PP_GamepadsData_Dev),
234 size_difference);
235 COMPILE_ASSERT(sizeof(WebKit::WebGamepad) == sizeof(PP_GamepadData_Dev),
236 size_difference);
237
229 // Sets |*security_origin| to be the WebKit security origin associated with the 238 // Sets |*security_origin| to be the WebKit security origin associated with the
230 // document containing the given plugin instance. On success, returns true. If 239 // document containing the given plugin instance. On success, returns true. If
231 // the instance is invalid, returns false and |*security_origin| will be 240 // the instance is invalid, returns false and |*security_origin| will be
232 // unchanged. 241 // unchanged.
233 bool SecurityOriginForInstance(PP_Instance instance_id, 242 bool SecurityOriginForInstance(PP_Instance instance_id,
234 WebKit::WebSecurityOrigin* security_origin) { 243 WebKit::WebSecurityOrigin* security_origin) {
235 PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id); 244 PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id);
236 if (!instance) 245 if (!instance)
237 return false; 246 return false;
238 247
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 // Only GETs and POSTs are supported. 1312 // Only GETs and POSTs are supported.
1304 if (web_request.httpMethod() != "GET" && 1313 if (web_request.httpMethod() != "GET" &&
1305 web_request.httpMethod() != "POST") 1314 web_request.httpMethod() != "POST")
1306 return PP_ERROR_BADARGUMENT; 1315 return PP_ERROR_BADARGUMENT;
1307 1316
1308 WebString target_str = WebString::fromUTF8(target); 1317 WebString target_str = WebString::fromUTF8(target);
1309 container_->loadFrameRequest(web_request, target_str, false, NULL); 1318 container_->loadFrameRequest(web_request, target_str, false, NULL);
1310 return PP_OK; 1319 return PP_OK;
1311 } 1320 }
1312 1321
1322 void PluginInstance::SampleGamepads(PP_Instance instance,
1323 PP_GamepadsData_Dev* data) {
1324
1325 // Because the WebKit objects have trivial ctors, using offsetof doesn't
1326 // work. Instead use this version based on src/v8/src/globals.h. This
1327 // workaround doesn't work in constant expressions as required for
1328 // COMPILE_ASSERT, so DCHECK instead.
1329
1330 #define OFFSET_OF(type, field) \
1331 (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4)
1332
1333 #define DCHECK_GAMEPADS_OFFSET(webkit_name, pp_name) \
1334 DCHECK(OFFSET_OF(WebKit::WebGamepads, webkit_name) \
1335 == OFFSET_OF(PP_GamepadsData_Dev, pp_name))
1336
1337 #define DCHECK_GAMEPAD_OFFSET(webkit_name, pp_name) \
1338 DCHECK(OFFSET_OF(WebKit::WebGamepad, webkit_name) \
1339 == OFFSET_OF(PP_GamepadData_Dev, pp_name))
1340
1341 DCHECK_GAMEPADS_OFFSET(length, length);
1342 DCHECK_GAMEPADS_OFFSET(items, items);
1343 DCHECK_GAMEPAD_OFFSET(connected, connected);
1344 DCHECK_GAMEPAD_OFFSET(id, id);
1345 DCHECK_GAMEPAD_OFFSET(timestamp, timestamp);
1346 DCHECK_GAMEPAD_OFFSET(axesLength, axes_length);
1347 DCHECK_GAMEPAD_OFFSET(axes, axes);
1348 DCHECK_GAMEPAD_OFFSET(buttonsLength, buttons_length);
1349 DCHECK_GAMEPAD_OFFSET(buttons, buttons);
1350
1351 #undef OFFSET_OF
1352 #undef DCHECK_GAMEPADS_OFFSET
1353 #undef DCHECK_GAMEPAD_OFFSET
1354
1355 delegate()->SampleGamepads(reinterpret_cast<WebKit::WebGamepads*>(data));
1356 }
1357
1313 bool PluginInstance::IsViewAccelerated() { 1358 bool PluginInstance::IsViewAccelerated() {
1314 if (!container_) 1359 if (!container_)
1315 return false; 1360 return false;
1316 1361
1317 WebDocument document = container_->element().document(); 1362 WebDocument document = container_->element().document();
1318 WebFrame* frame = document.frame(); 1363 WebFrame* frame = document.frame();
1319 if (!frame) 1364 if (!frame)
1320 return false; 1365 return false;
1321 WebView* view = frame->view(); 1366 WebView* view = frame->view();
1322 if (!view) 1367 if (!view)
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
2054 screen_size_for_fullscreen_ = gfx::Size(); 2099 screen_size_for_fullscreen_ = gfx::Size();
2055 WebElement element = container_->element(); 2100 WebElement element = container_->element();
2056 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); 2101 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_);
2057 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); 2102 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_);
2058 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); 2103 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_);
2059 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); 2104 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_);
2060 } 2105 }
2061 2106
2062 } // namespace ppapi 2107 } // namespace ppapi
2063 } // namespace webkit 2108 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppapi_plugin_instance.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698