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 "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "ppapi/c/dev/ppb_console_dev.h" | |
13 #include "ppapi/c/dev/ppb_find_dev.h" | 12 #include "ppapi/c/dev/ppb_find_dev.h" |
14 #include "ppapi/c/dev/ppb_fullscreen_dev.h" | 13 #include "ppapi/c/dev/ppb_fullscreen_dev.h" |
15 #include "ppapi/c/dev/ppb_memory_dev.h" | 14 #include "ppapi/c/dev/ppb_memory_dev.h" |
16 #include "ppapi/c/dev/ppb_zoom_dev.h" | 15 #include "ppapi/c/dev/ppb_zoom_dev.h" |
17 #include "ppapi/c/dev/ppp_find_dev.h" | 16 #include "ppapi/c/dev/ppp_find_dev.h" |
18 #include "ppapi/c/dev/ppp_mouse_lock_dev.h" | 17 #include "ppapi/c/dev/ppp_mouse_lock_dev.h" |
19 #include "ppapi/c/dev/ppp_policy_update_dev.h" | 18 #include "ppapi/c/dev/ppp_policy_update_dev.h" |
20 #include "ppapi/c/dev/ppp_selection_dev.h" | 19 #include "ppapi/c/dev/ppp_selection_dev.h" |
21 #include "ppapi/c/dev/ppp_zoom_dev.h" | 20 #include "ppapi/c/dev/ppp_zoom_dev.h" |
22 #include "ppapi/c/pp_input_event.h" | 21 #include "ppapi/c/pp_input_event.h" |
23 #include "ppapi/c/pp_instance.h" | 22 #include "ppapi/c/pp_instance.h" |
24 #include "ppapi/c/pp_rect.h" | 23 #include "ppapi/c/pp_rect.h" |
25 #include "ppapi/c/pp_resource.h" | 24 #include "ppapi/c/pp_resource.h" |
26 #include "ppapi/c/pp_var.h" | 25 #include "ppapi/c/pp_var.h" |
27 #include "ppapi/c/ppb_core.h" | 26 #include "ppapi/c/ppb_core.h" |
28 #include "ppapi/c/ppb_instance.h" | 27 #include "ppapi/c/ppb_instance.h" |
29 #include "ppapi/c/ppp_input_event.h" | 28 #include "ppapi/c/ppp_input_event.h" |
30 #include "ppapi/c/ppp_instance.h" | 29 #include "ppapi/c/ppp_instance.h" |
31 #include "ppapi/c/ppp_messaging.h" | 30 #include "ppapi/c/ppp_messaging.h" |
32 #include "ppapi/c/private/ppb_instance_private.h" | 31 #include "ppapi/c/private/ppb_instance_private.h" |
33 #include "ppapi/c/private/ppp_instance_private.h" | 32 #include "ppapi/c/private/ppp_instance_private.h" |
34 #include "ppapi/shared_impl/input_event_impl.h" | 33 #include "ppapi/shared_impl/input_event_impl.h" |
35 #include "ppapi/shared_impl/resource.h" | 34 #include "ppapi/shared_impl/resource.h" |
36 #include "ppapi/shared_impl/var.h" | 35 #include "ppapi/shared_impl/var.h" |
37 #include "ppapi/thunk/enter.h" | 36 #include "ppapi/thunk/enter.h" |
38 #include "ppapi/thunk/ppb_buffer_api.h" | 37 #include "ppapi/thunk/ppb_buffer_api.h" |
39 #include "printing/units.h" | 38 #include "printing/units.h" |
40 #include "skia/ext/platform_canvas.h" | 39 #include "skia/ext/platform_canvas.h" |
41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" | |
43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
48 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
49 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" | 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" |
50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 48 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
51 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 49 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
52 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 using ppapi::thunk::EnterResourceNoLock; | 97 using ppapi::thunk::EnterResourceNoLock; |
100 using ppapi::thunk::PPB_Buffer_API; | 98 using ppapi::thunk::PPB_Buffer_API; |
101 using ppapi::thunk::PPB_Graphics2D_API; | 99 using ppapi::thunk::PPB_Graphics2D_API; |
102 using ppapi::thunk::PPB_Graphics3D_API; | 100 using ppapi::thunk::PPB_Graphics3D_API; |
103 using ppapi::thunk::PPB_ImageData_API; | 101 using ppapi::thunk::PPB_ImageData_API; |
104 using ppapi::thunk::PPB_Instance_FunctionAPI; | 102 using ppapi::thunk::PPB_Instance_FunctionAPI; |
105 using ppapi::thunk::PPB_Surface3D_API; | 103 using ppapi::thunk::PPB_Surface3D_API; |
106 using ppapi::Var; | 104 using ppapi::Var; |
107 using WebKit::WebBindings; | 105 using WebKit::WebBindings; |
108 using WebKit::WebCanvas; | 106 using WebKit::WebCanvas; |
109 using WebKit::WebConsoleMessage; | |
110 using WebKit::WebCursorInfo; | 107 using WebKit::WebCursorInfo; |
111 using WebKit::WebDocument; | 108 using WebKit::WebDocument; |
112 using WebKit::WebFrame; | 109 using WebKit::WebFrame; |
113 using WebKit::WebInputEvent; | 110 using WebKit::WebInputEvent; |
114 using WebKit::WebPluginContainer; | 111 using WebKit::WebPluginContainer; |
115 using WebKit::WebString; | 112 using WebKit::WebString; |
116 using WebKit::WebURLRequest; | 113 using WebKit::WebURLRequest; |
117 using WebKit::WebView; | 114 using WebKit::WebView; |
118 | 115 |
119 namespace webkit { | 116 namespace webkit { |
(...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1438 try_catch.SetException("Exception caught"); | 1435 try_catch.SetException("Exception caught"); |
1439 WebBindings::releaseVariantValue(&result); | 1436 WebBindings::releaseVariantValue(&result); |
1440 return PP_MakeUndefined(); | 1437 return PP_MakeUndefined(); |
1441 } | 1438 } |
1442 | 1439 |
1443 PP_Var ret = NPVariantToPPVar(this, &result); | 1440 PP_Var ret = NPVariantToPPVar(this, &result); |
1444 WebBindings::releaseVariantValue(&result); | 1441 WebBindings::releaseVariantValue(&result); |
1445 return ret; | 1442 return ret; |
1446 } | 1443 } |
1447 | 1444 |
1448 void PluginInstance::Log(PP_Instance instance, | |
1449 int log_level, | |
1450 PP_Var value) { | |
1451 // TODO(brettw) get the plugin name and use it as the source. | |
1452 LogWithSource(instance, log_level, PP_MakeUndefined(), value); | |
1453 } | |
1454 | |
1455 void PluginInstance::LogWithSource(PP_Instance instance, | |
1456 int log_level, | |
1457 PP_Var source, | |
1458 PP_Var value) { | |
1459 // Convert the log level, defaulting to error. | |
1460 WebConsoleMessage::Level web_level; | |
1461 switch (log_level) { | |
1462 case PP_LOGLEVEL_TIP: | |
1463 web_level = WebConsoleMessage::LevelTip; | |
1464 break; | |
1465 case PP_LOGLEVEL_LOG: | |
1466 web_level = WebConsoleMessage::LevelLog; | |
1467 break; | |
1468 case PP_LOGLEVEL_WARNING: | |
1469 web_level = WebConsoleMessage::LevelWarning; | |
1470 break; | |
1471 case PP_LOGLEVEL_ERROR: | |
1472 default: | |
1473 web_level = WebConsoleMessage::LevelError; | |
1474 break; | |
1475 } | |
1476 | |
1477 // Format is the "<source>: <value>". The source defaults to the module name | |
1478 // if the source isn't a string or is empty. | |
1479 std::string message; | |
1480 if (source.type == PP_VARTYPE_STRING) | |
1481 message = Var::PPVarToLogString(source); | |
1482 if (message.empty()) | |
1483 message = module()->name(); | |
1484 message.append(": "); | |
1485 message.append(Var::PPVarToLogString(value)); | |
1486 | |
1487 container()->element().document().frame()->addMessageToConsole( | |
1488 WebConsoleMessage(web_level, WebString(UTF8ToUTF16(message)))); | |
1489 } | |
1490 | |
1491 PP_Bool PluginInstance::IsFullscreen(PP_Instance instance) { | 1445 PP_Bool PluginInstance::IsFullscreen(PP_Instance instance) { |
1492 return PP_FromBool(fullscreen_); | 1446 return PP_FromBool(fullscreen_); |
1493 } | 1447 } |
1494 | 1448 |
1495 PP_Bool PluginInstance::SetFullscreen(PP_Instance instance, | 1449 PP_Bool PluginInstance::SetFullscreen(PP_Instance instance, |
1496 PP_Bool fullscreen) { | 1450 PP_Bool fullscreen) { |
1497 SetFullscreen(PP_ToBool(fullscreen), true); | 1451 SetFullscreen(PP_ToBool(fullscreen), true); |
1498 return PP_TRUE; | 1452 return PP_TRUE; |
1499 } | 1453 } |
1500 | 1454 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 } | 1541 } |
1588 | 1542 |
1589 void PluginInstance::DoSetCursor(WebCursorInfo* cursor) { | 1543 void PluginInstance::DoSetCursor(WebCursorInfo* cursor) { |
1590 cursor_.reset(cursor); | 1544 cursor_.reset(cursor); |
1591 if (fullscreen_container_) | 1545 if (fullscreen_container_) |
1592 fullscreen_container_->DidChangeCursor(*cursor); | 1546 fullscreen_container_->DidChangeCursor(*cursor); |
1593 } | 1547 } |
1594 | 1548 |
1595 } // namespace ppapi | 1549 } // namespace ppapi |
1596 } // namespace webkit | 1550 } // namespace webkit |
OLD | NEW |