PluginViewEfl.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /*
  2. * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
  3. * Copyright (C) 2008 Collabora Ltd. All rights reserved.
  4. * Copyright (C) 2008 INdT - Instituto Nokia de Tecnologia
  5. * Copyright (C) 2009-2010 ProFUSION embedded systems
  6. * Copyright (C) 2009-2011 Samsung Electronics
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  18. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
  21. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  25. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #include "config.h"
  30. #include "PluginView.h"
  31. #include "Frame.h"
  32. #include "FrameView.h"
  33. #include "GraphicsContext.h"
  34. #include "HTMLNames.h"
  35. #include "HTMLPlugInElement.h"
  36. #include "HostWindow.h"
  37. #include "JSDOMWindowBase.h"
  38. #include "MouseEvent.h"
  39. #include "NotImplemented.h"
  40. #include "PluginPackage.h"
  41. #include "ScriptController.h"
  42. #include "npruntime_impl.h"
  43. #include "runtime/JSLock.h"
  44. #include "runtime/Operations.h"
  45. #include <Ecore_Evas.h>
  46. #include <Ecore_X.h>
  47. #include <Evas.h>
  48. namespace WebCore {
  49. using namespace HTMLNames;
  50. bool PluginView::dispatchNPEvent(NPEvent& event)
  51. {
  52. if (!m_plugin->pluginFuncs()->event)
  53. return false;
  54. PluginView::setCurrentPluginView(this);
  55. JSC::JSLock::DropAllLocks dropAllLocks(JSDOMWindowBase::commonVM());
  56. setCallingPlugin(true);
  57. bool accepted = m_plugin->pluginFuncs()->event(m_instance, &event);
  58. setCallingPlugin(false);
  59. PluginView::setCurrentPluginView(0);
  60. return accepted;
  61. }
  62. #if defined(XP_UNIX)
  63. void PluginView::handleFocusInEvent()
  64. {
  65. notImplemented();
  66. }
  67. void PluginView::handleFocusOutEvent()
  68. {
  69. notImplemented();
  70. }
  71. #endif
  72. void PluginView::handleKeyboardEvent(KeyboardEvent*)
  73. {
  74. notImplemented();
  75. }
  76. void PluginView::handleMouseEvent(MouseEvent* event)
  77. {
  78. NPEvent xEvent;
  79. #if defined(XP_UNIX)
  80. const IntRect rect = parent()->contentsToScreen(IntRect(0, 0, event->offsetX(), event->offsetY()));
  81. const int eventX = rect.width();
  82. const int eventY = rect.height();
  83. if (event->type() == eventNames().mousemoveEvent
  84. || event->type() == eventNames().mouseoutEvent
  85. || event->type() == eventNames().mouseoverEvent) {
  86. xEvent.type = MotionNotify;
  87. xEvent.xmotion.x = eventX;
  88. xEvent.xmotion.y = eventY;
  89. } else if (event->type() == eventNames().mousedownEvent) {
  90. xEvent.type = ButtonPress;
  91. xEvent.xbutton.x = eventX;
  92. xEvent.xbutton.y = eventY;
  93. xEvent.xbutton.button = event->button() + 1; // DOM MouseEvent counts from 0, and XButtonEvent from 1.
  94. } else if (event->type() == eventNames().mouseupEvent) {
  95. xEvent.type = ButtonRelease;
  96. xEvent.xbutton.x = eventX;
  97. xEvent.xbutton.y = eventY;
  98. xEvent.xbutton.button = event->button() + 1;
  99. } else
  100. return;
  101. #endif
  102. if (dispatchNPEvent(xEvent))
  103. event->setDefaultHandled();
  104. }
  105. void PluginView::updatePluginWidget()
  106. {
  107. notImplemented();
  108. }
  109. void PluginView::setFocus(bool focused)
  110. {
  111. if (focused)
  112. m_element->document()->setFocusedElement(m_element);
  113. Widget::setFocus(focused);
  114. }
  115. void PluginView::show()
  116. {
  117. setSelfVisible(true);
  118. Widget::show();
  119. }
  120. void PluginView::hide()
  121. {
  122. setSelfVisible(false);
  123. Widget::hide();
  124. }
  125. void PluginView::paint(GraphicsContext* context, const IntRect& rect)
  126. {
  127. if (!m_isStarted)
  128. paintMissingPluginIcon(context, rect);
  129. }
  130. void PluginView::setParent(ScrollView* parent)
  131. {
  132. Widget::setParent(parent);
  133. if (parent)
  134. init();
  135. }
  136. void PluginView::setNPWindowRect(const IntRect&)
  137. {
  138. notImplemented();
  139. }
  140. void PluginView::setNPWindowIfNeeded()
  141. {
  142. }
  143. void PluginView::setParentVisible(bool visible)
  144. {
  145. Widget::setParentVisible(visible);
  146. }
  147. NPError PluginView::handlePostReadFile(Vector<char>& buffer, uint32_t len, const char* buf)
  148. {
  149. String filename(buf, len);
  150. if (filename.startsWith("file:///"))
  151. #if defined(XP_UNIX)
  152. filename = filename.substring(7);
  153. #else
  154. filename = filename.substring(8);
  155. #endif
  156. long long size;
  157. if (!getFileSize(filename, size))
  158. return NPERR_FILE_NOT_FOUND;
  159. FILE* fileHandle = fopen(filename.utf8().data(), "r");
  160. if (!fileHandle)
  161. return NPERR_FILE_NOT_FOUND;
  162. buffer.resize(size);
  163. int bytesRead = fread(buffer.data(), 1, size, fileHandle);
  164. fclose(fileHandle);
  165. if (bytesRead <= 0)
  166. return NPERR_FILE_NOT_FOUND;
  167. return NPERR_NO_ERROR;
  168. }
  169. bool PluginView::platformGetValueStatic(NPNVariable variable, void* value, NPError* result)
  170. {
  171. switch (variable) {
  172. case NPNVToolkit:
  173. *static_cast<uint32_t*>(value) = 0;
  174. *result = NPERR_NO_ERROR;
  175. return true;
  176. case NPNVSupportsXEmbedBool:
  177. *static_cast<NPBool*>(value) = false;
  178. *result = NPERR_NO_ERROR;
  179. return true;
  180. case NPNVjavascriptEnabledBool:
  181. *static_cast<NPBool*>(value) = true;
  182. *result = NPERR_NO_ERROR;
  183. return true;
  184. case NPNVSupportsWindowless:
  185. *static_cast<NPBool*>(value) = false;
  186. *result = NPERR_NO_ERROR;
  187. return true;
  188. default:
  189. return false;
  190. }
  191. }
  192. bool PluginView::platformGetValue(NPNVariable variable, void* value, NPError* result)
  193. {
  194. if (!value || !result)
  195. return false;
  196. switch (variable) {
  197. case NPNVxDisplay:
  198. *static_cast<void**>(value) = static_cast<Display*>(ecore_x_display_get());
  199. *result = NPERR_NO_ERROR;
  200. return true;
  201. case NPNVxtAppContext:
  202. *result = NPERR_GENERIC_ERROR;
  203. return true;
  204. case NPNVWindowNPObject: {
  205. if (m_isJavaScriptPaused) {
  206. *result = NPERR_GENERIC_ERROR;
  207. return true;
  208. }
  209. NPObject* windowScriptObject = m_parentFrame->script()->windowScriptNPObject();
  210. // Return value is expected to be retained, as described here: <http://www.mozilla.org/projects/plugin/npruntime.html>
  211. if (windowScriptObject)
  212. _NPN_RetainObject(windowScriptObject);
  213. *static_cast<void**>(value) = windowScriptObject;
  214. *result = NPERR_NO_ERROR;
  215. return true;
  216. }
  217. case NPNVPluginElementNPObject: {
  218. if (m_isJavaScriptPaused) {
  219. *result = NPERR_GENERIC_ERROR;
  220. return true;
  221. }
  222. NPObject* pluginScriptObject = 0;
  223. if (m_element->hasTagName(appletTag) || m_element->hasTagName(embedTag) || m_element->hasTagName(objectTag))
  224. pluginScriptObject = static_cast<HTMLPlugInElement*>(m_element)->getNPObject();
  225. // Return value is expected to be retained, as described here: <http://www.mozilla.org/projects/plugin/npruntime.html>
  226. if (pluginScriptObject)
  227. _NPN_RetainObject(pluginScriptObject);
  228. *static_cast<void**>(value) = pluginScriptObject;
  229. *result = NPERR_NO_ERROR;
  230. return true;
  231. }
  232. case NPNVnetscapeWindow: {
  233. Evas* evas = evas_object_evas_get(m_parentFrame->view()->evasObject());
  234. if (!evas)
  235. return false;
  236. Ecore_Evas* ecoreEvas = ecore_evas_ecore_evas_get(evas);
  237. *static_cast<XID*>(value) = static_cast<Window>(ecore_evas_window_get(ecoreEvas));
  238. *result = NPERR_NO_ERROR;
  239. return true;
  240. }
  241. case NPNVToolkit:
  242. if (m_plugin->quirks().contains(PluginQuirkRequiresGtkToolKit)) {
  243. *static_cast<uint32_t*>(value) = 2;
  244. *result = NPERR_NO_ERROR;
  245. return true;
  246. }
  247. return false;
  248. default:
  249. return false;
  250. }
  251. }
  252. void PluginView::invalidateRect(const IntRect& rect)
  253. {
  254. invalidateWindowlessPluginRect(rect);
  255. }
  256. void PluginView::invalidateRect(NPRect* rect)
  257. {
  258. if (!rect) {
  259. invalidate();
  260. return;
  261. }
  262. invalidateRect(IntRect(rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top));
  263. }
  264. void PluginView::invalidateRegion(NPRegion)
  265. {
  266. notImplemented();
  267. }
  268. void PluginView::forceRedraw()
  269. {
  270. notImplemented();
  271. }
  272. bool PluginView::platformStart()
  273. {
  274. ASSERT(m_isStarted);
  275. ASSERT(m_status == PluginStatusLoadedSuccessfully);
  276. notImplemented();
  277. return true;
  278. }
  279. void PluginView::platformDestroy()
  280. {
  281. }
  282. } // namespace WebCore