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