summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/webkit/WebCore/plugins
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2009-03-23 10:18:55 +0100
committerSimon Hausmann <simon.hausmann@nokia.com>2009-03-23 10:18:55 +0100
commite5fcad302d86d316390c6b0f62759a067313e8a9 (patch)
treec2afbf6f1066b6ce261f14341cf6d310e5595bc1 /src/3rdparty/webkit/WebCore/plugins
Long live Qt 4.5!
Diffstat (limited to 'src/3rdparty/webkit/WebCore/plugins')
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/MimeType.cpp70
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/MimeType.h52
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/MimeType.idl32
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/MimeTypeArray.cpp95
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/MimeTypeArray.h56
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/MimeTypeArray.idl33
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/Plugin.cpp91
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/Plugin.h57
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/Plugin.idl36
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/PluginArray.cpp100
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/PluginArray.h58
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/PluginArray.idl34
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/PluginData.cpp63
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/PluginData.h74
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/PluginDatabase.cpp375
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/PluginDatabase.h84
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/PluginDebug.h57
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/PluginInfoStore.cpp103
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/PluginInfoStore.h48
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/PluginMainThreadScheduler.cpp116
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/PluginMainThreadScheduler.h86
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/PluginPackage.cpp240
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/PluginPackage.h118
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/PluginQuirkSet.h62
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/PluginStream.cpp476
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/PluginStream.h123
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/PluginView.cpp938
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/PluginView.h302
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/mac/PluginDataMac.mm76
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/mac/PluginPackageMac.cpp378
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/mac/PluginViewMac.cpp704
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/npapi.cpp177
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/npfunctions.h204
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/qt/PluginDataQt.cpp108
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/qt/PluginPackageQt.cpp200
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/qt/PluginViewQt.cpp488
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/win/PluginDataWin.cpp72
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/win/PluginDatabaseWin.cpp354
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/win/PluginMessageThrottlerWin.cpp123
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/win/PluginMessageThrottlerWin.h72
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/win/PluginPackageWin.cpp375
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/win/PluginViewWin.cpp841
42 files changed, 8151 insertions, 0 deletions
diff --git a/src/3rdparty/webkit/WebCore/plugins/MimeType.cpp b/src/3rdparty/webkit/WebCore/plugins/MimeType.cpp
new file mode 100644
index 0000000000..c4b051c180
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/MimeType.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "MimeType.h"
+
+#include "Frame.h"
+#include "Page.h"
+#include "Plugin.h"
+#include "PluginData.h"
+#include "Settings.h"
+
+namespace WebCore {
+
+MimeType::MimeType(PassRefPtr<PluginData> pluginData, unsigned index)
+ : m_pluginData(pluginData)
+ , m_index(index)
+{
+}
+
+MimeType::~MimeType()
+{
+}
+
+const String &MimeType::type() const
+{
+ return m_pluginData->mimes()[m_index]->type;
+}
+
+const String &MimeType::suffixes() const
+{
+ return m_pluginData->mimes()[m_index]->suffixes;
+}
+
+const String &MimeType::description() const
+{
+ return m_pluginData->mimes()[m_index]->desc;
+}
+
+PassRefPtr<Plugin> MimeType::enabledPlugin() const
+{
+ const Page* p = m_pluginData->page();
+ if (!p || !p->settings()->arePluginsEnabled())
+ return 0;
+
+ const PluginInfo *info = m_pluginData->mimes()[m_index]->plugin;
+ const Vector<PluginInfo*>& plugins = m_pluginData->plugins();
+ for (size_t i = 0; i < plugins.size(); ++i) {
+ if (plugins[i] == info)
+ return Plugin::create(m_pluginData.get(), i);
+ }
+ return 0;
+}
+
+} // namespace WebCore
diff --git a/src/3rdparty/webkit/WebCore/plugins/MimeType.h b/src/3rdparty/webkit/WebCore/plugins/MimeType.h
new file mode 100644
index 0000000000..520791890d
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/MimeType.h
@@ -0,0 +1,52 @@
+/*
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef MimeType_h
+#define MimeType_h
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+#include <wtf/RefCounted.h>
+
+#include "PluginData.h"
+
+namespace WebCore {
+
+ class Plugin;
+ class String;
+
+ class MimeType : public RefCounted<MimeType> {
+ public:
+ static PassRefPtr<MimeType> create(PassRefPtr<PluginData> pluginData, unsigned index) { return adoptRef(new MimeType(pluginData, index)); }
+ ~MimeType();
+
+ const String &type() const;
+ const String &suffixes() const;
+ const String &description() const;
+ PassRefPtr<Plugin> enabledPlugin() const;
+
+ private:
+ MimeType(PassRefPtr<PluginData>, unsigned index);
+ RefPtr<PluginData> m_pluginData;
+ unsigned m_index;
+ };
+
+}
+
+#endif
diff --git a/src/3rdparty/webkit/WebCore/plugins/MimeType.idl b/src/3rdparty/webkit/WebCore/plugins/MimeType.idl
new file mode 100644
index 0000000000..71fcca204c
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/MimeType.idl
@@ -0,0 +1,32 @@
+/*
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ Copyright (C) 2008 Apple Inc. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+module window {
+
+ interface [
+ GenerateConstructor
+ ] MimeType {
+ readonly attribute DOMString type;
+ readonly attribute DOMString suffixes;
+ readonly attribute DOMString description;
+ readonly attribute Plugin enabledPlugin;
+ };
+
+}
diff --git a/src/3rdparty/webkit/WebCore/plugins/MimeTypeArray.cpp b/src/3rdparty/webkit/WebCore/plugins/MimeTypeArray.cpp
new file mode 100644
index 0000000000..7fabad7d20
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/MimeTypeArray.cpp
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "MimeTypeArray.h"
+
+#include "AtomicString.h"
+#include "Frame.h"
+#include "Page.h"
+#include "Plugin.h"
+#include "PluginData.h"
+
+namespace WebCore {
+
+MimeTypeArray::MimeTypeArray(Frame* frame)
+ : m_frame(frame)
+{
+}
+
+MimeTypeArray::~MimeTypeArray()
+{
+}
+
+unsigned MimeTypeArray::length() const
+{
+ PluginData* data = getPluginData();
+ if (!data)
+ return 0;
+ return data->mimes().size();
+}
+
+PassRefPtr<MimeType> MimeTypeArray::item(unsigned index)
+{
+ PluginData* data = getPluginData();
+ if (!data)
+ return 0;
+ const Vector<MimeClassInfo*>& mimes = data->mimes();
+ if (index >= mimes.size())
+ return 0;
+ return MimeType::create(data, index).get();
+}
+
+bool MimeTypeArray::canGetItemsForName(const AtomicString& propertyName)
+{
+ PluginData *data = getPluginData();
+ if (!data)
+ return 0;
+ const Vector<MimeClassInfo*>& mimes = data->mimes();
+ for (unsigned i = 0; i < mimes.size(); ++i) {
+ if (mimes[i]->type == propertyName)
+ return true;
+ }
+ return false;
+}
+
+PassRefPtr<MimeType> MimeTypeArray::namedItem(const AtomicString& propertyName)
+{
+ PluginData *data = getPluginData();
+ if (!data)
+ return 0;
+ const Vector<MimeClassInfo*>& mimes = data->mimes();
+ for (unsigned i = 0; i < mimes.size(); ++i) {
+ if (mimes[i]->type == propertyName)
+ return MimeType::create(data, i).get();
+ }
+ return 0;
+}
+
+PluginData* MimeTypeArray::getPluginData() const
+{
+ if (!m_frame)
+ return 0;
+ Page* p = m_frame->page();
+ if (!p)
+ return 0;
+ return p->pluginData();
+}
+
+} // namespace WebCore
diff --git a/src/3rdparty/webkit/WebCore/plugins/MimeTypeArray.h b/src/3rdparty/webkit/WebCore/plugins/MimeTypeArray.h
new file mode 100644
index 0000000000..a1e3d522f7
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/MimeTypeArray.h
@@ -0,0 +1,56 @@
+/*
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ Copyright (C) 2008 Apple Inc. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef MimeTypeArray_h
+#define MimeTypeArray_h
+
+#include "MimeType.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+ class AtomicString;
+ class Frame;
+ class PluginData;
+
+ class MimeTypeArray : public RefCounted<MimeTypeArray> {
+ public:
+ static PassRefPtr<MimeTypeArray> create(Frame* frame) { return adoptRef(new MimeTypeArray(frame)); }
+ ~MimeTypeArray();
+
+ void disconnectFrame() { m_frame = 0; }
+
+ unsigned length() const;
+ PassRefPtr<MimeType> item(unsigned index);
+ bool canGetItemsForName(const AtomicString& propertyName);
+ PassRefPtr<MimeType> namedItem(const AtomicString& propertyName);
+
+ private:
+ MimeTypeArray(Frame*);
+ PluginData* getPluginData() const;
+
+ Frame* m_frame;
+ };
+
+} // namespace WebCore
+
+#endif // MimeTypeArray_h
diff --git a/src/3rdparty/webkit/WebCore/plugins/MimeTypeArray.idl b/src/3rdparty/webkit/WebCore/plugins/MimeTypeArray.idl
new file mode 100644
index 0000000000..5316d567fc
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/MimeTypeArray.idl
@@ -0,0 +1,33 @@
+/*
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ Copyright (C) 2008 Apple Inc. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+module window {
+
+ interface [
+ GenerateConstructor,
+ HasNameGetter,
+ HasIndexGetter
+ ] MimeTypeArray {
+ readonly attribute unsigned long length;
+ MimeType item(in unsigned long index);
+ MimeType namedItem(in DOMString name);
+ };
+
+}
diff --git a/src/3rdparty/webkit/WebCore/plugins/Plugin.cpp b/src/3rdparty/webkit/WebCore/plugins/Plugin.cpp
new file mode 100644
index 0000000000..e8c98b346d
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/Plugin.cpp
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "Plugin.h"
+
+#include "AtomicString.h"
+#include "PluginData.h"
+#include "Frame.h"
+
+namespace WebCore {
+
+Plugin::Plugin(PluginData* pluginData, unsigned index)
+ : m_pluginData(pluginData)
+ , m_index(index)
+{
+}
+
+Plugin::~Plugin()
+{
+}
+
+String Plugin::name() const
+{
+ return m_pluginData->plugins()[m_index]->name;
+}
+
+String Plugin::filename() const
+{
+ return m_pluginData->plugins()[m_index]->file;
+}
+
+String Plugin::description() const
+{
+ return m_pluginData->plugins()[m_index]->desc;
+}
+
+unsigned Plugin::length() const
+{
+ return m_pluginData->plugins()[m_index]->mimes.size();
+}
+
+PassRefPtr<MimeType> Plugin::item(unsigned index)
+{
+ const Vector<PluginInfo*>& plugins = m_pluginData->plugins();
+ if (index >= plugins[m_index]->mimes.size())
+ return 0;
+
+ MimeClassInfo* mime = plugins[m_index]->mimes[index];
+
+ const Vector<MimeClassInfo*>& mimes = m_pluginData->mimes();
+ for (unsigned i = 0; i < mimes.size(); ++i)
+ if (mimes[i] == mime)
+ return MimeType::create(m_pluginData.get(), i).get();
+ return 0;
+}
+
+bool Plugin::canGetItemsForName(const AtomicString& propertyName)
+{
+ const Vector<MimeClassInfo*>& mimes = m_pluginData->mimes();
+ for (unsigned i = 0; i < mimes.size(); ++i)
+ if (mimes[i]->type == propertyName)
+ return true;
+ return false;
+}
+
+PassRefPtr<MimeType> Plugin::namedItem(const AtomicString& propertyName)
+{
+ const Vector<MimeClassInfo*>& mimes = m_pluginData->mimes();
+ for (unsigned i = 0; i < mimes.size(); ++i)
+ if (mimes[i]->type == propertyName)
+ return MimeType::create(m_pluginData.get(), i).get();
+ return 0;
+}
+
+} // namespace WebCore
diff --git a/src/3rdparty/webkit/WebCore/plugins/Plugin.h b/src/3rdparty/webkit/WebCore/plugins/Plugin.h
new file mode 100644
index 0000000000..9a5697dbe7
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/Plugin.h
@@ -0,0 +1,57 @@
+/*
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef Plugin_h
+#define Plugin_h
+
+#include "MimeType.h"
+#include <wtf/RefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+ class AtomicString;
+ class Plugin;
+ class PluginData;
+ class String;
+
+ class Plugin : public RefCounted<Plugin> {
+ public:
+ static PassRefPtr<Plugin> create(PluginData* pluginData, unsigned index) { return adoptRef(new Plugin(pluginData, index)); }
+ ~Plugin();
+
+ String name() const;
+ String filename() const;
+ String description() const;
+
+ unsigned length() const;
+
+ PassRefPtr<MimeType> item(unsigned index);
+ bool canGetItemsForName(const AtomicString& propertyName);
+ PassRefPtr<MimeType> namedItem(const AtomicString& propertyName);
+
+ private:
+ Plugin(PluginData*, unsigned index);
+ RefPtr<PluginData> m_pluginData;
+ unsigned m_index;
+ };
+
+} // namespace WebCore
+
+#endif // Plugin_h
diff --git a/src/3rdparty/webkit/WebCore/plugins/Plugin.idl b/src/3rdparty/webkit/WebCore/plugins/Plugin.idl
new file mode 100644
index 0000000000..8ecef36e6a
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/Plugin.idl
@@ -0,0 +1,36 @@
+/*
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ Copyright (C) 2008 Apple Inc. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+module window {
+
+ interface [
+ GenerateConstructor,
+ HasNameGetter,
+ HasIndexGetter
+ ] Plugin {
+ readonly attribute DOMString name;
+ readonly attribute DOMString filename;
+ readonly attribute DOMString description;
+ readonly attribute unsigned long length;
+ MimeType item(in unsigned long index);
+ MimeType namedItem(in DOMString name);
+ };
+
+}
diff --git a/src/3rdparty/webkit/WebCore/plugins/PluginArray.cpp b/src/3rdparty/webkit/WebCore/plugins/PluginArray.cpp
new file mode 100644
index 0000000000..b37d3c01fb
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/PluginArray.cpp
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "PluginArray.h"
+
+#include "AtomicString.h"
+#include "Frame.h"
+#include "Page.h"
+#include "Plugin.h"
+#include "PluginData.h"
+
+namespace WebCore {
+
+PluginArray::PluginArray(Frame* frame)
+ : m_frame(frame)
+{
+}
+
+PluginArray::~PluginArray()
+{
+}
+
+unsigned PluginArray::length() const
+{
+ PluginData* data = getPluginData();
+ if (!data)
+ return 0;
+ return data->plugins().size();
+}
+
+PassRefPtr<Plugin> PluginArray::item(unsigned index)
+{
+ PluginData* data = getPluginData();
+ if (!data)
+ return 0;
+ const Vector<PluginInfo*>& plugins = data->plugins();
+ if (index >= plugins.size())
+ return 0;
+ return Plugin::create(data, index).get();
+}
+
+bool PluginArray::canGetItemsForName(const AtomicString& propertyName)
+{
+ PluginData* data = getPluginData();
+ if (!data)
+ return 0;
+ const Vector<PluginInfo*>& plugins = data->plugins();
+ for (unsigned i = 0; i < plugins.size(); ++i) {
+ if (plugins[i]->name == propertyName)
+ return true;
+ }
+ return false;
+}
+
+PassRefPtr<Plugin> PluginArray::namedItem(const AtomicString& propertyName)
+{
+ PluginData* data = getPluginData();
+ if (!data)
+ return 0;
+ const Vector<PluginInfo*>& plugins = data->plugins();
+ for (unsigned i = 0; i < plugins.size(); ++i) {
+ if (plugins[i]->name == propertyName)
+ return Plugin::create(data, i).get();
+ }
+ return 0;
+}
+
+void PluginArray::refresh(bool reload)
+{
+ Page::refreshPlugins(reload);
+}
+
+PluginData* PluginArray::getPluginData() const
+{
+ if (!m_frame)
+ return 0;
+ Page* p = m_frame->page();
+ if (!p)
+ return 0;
+ return p->pluginData();
+}
+
+} // namespace WebCore
diff --git a/src/3rdparty/webkit/WebCore/plugins/PluginArray.h b/src/3rdparty/webkit/WebCore/plugins/PluginArray.h
new file mode 100644
index 0000000000..197ac88f68
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/PluginArray.h
@@ -0,0 +1,58 @@
+/*
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ Copyright (C) 2008 Apple Inc. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef PluginArray_h
+#define PluginArray_h
+
+#include "Plugin.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+ class AtomicString;
+ class Frame;
+ class PluginData;
+
+ class PluginArray : public RefCounted<PluginArray> {
+ public:
+ static PassRefPtr<PluginArray> create(Frame* frame) { return adoptRef(new PluginArray(frame)); }
+ ~PluginArray();
+
+ void disconnectFrame() { m_frame = 0; }
+
+ unsigned length() const;
+ PassRefPtr<Plugin> item(unsigned index);
+ bool canGetItemsForName(const AtomicString& propertyName);
+ PassRefPtr<Plugin> namedItem(const AtomicString& propertyName);
+
+ void refresh(bool reload);
+
+ private:
+ PluginArray(Frame*);
+ PluginData* getPluginData() const;
+
+ Frame* m_frame;
+ };
+
+} // namespace WebCore
+
+#endif // PluginArray_h
diff --git a/src/3rdparty/webkit/WebCore/plugins/PluginArray.idl b/src/3rdparty/webkit/WebCore/plugins/PluginArray.idl
new file mode 100644
index 0000000000..4a55c562e6
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/PluginArray.idl
@@ -0,0 +1,34 @@
+/*
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ Copyright (C) 2008 Apple Inc. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+module window {
+
+ interface [
+ GenerateConstructor,
+ HasNameGetter,
+ HasIndexGetter
+ ] PluginArray {
+ readonly attribute unsigned long length;
+ Plugin item(in unsigned long index);
+ Plugin namedItem(in DOMString name);
+ void refresh(in boolean reload);
+ };
+
+}
diff --git a/src/3rdparty/webkit/WebCore/plugins/PluginData.cpp b/src/3rdparty/webkit/WebCore/plugins/PluginData.cpp
new file mode 100644
index 0000000000..ca4bda5053
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/PluginData.cpp
@@ -0,0 +1,63 @@
+/*
+ Copyright (C) 2000 Harri Porten (porten@kde.org)
+ Copyright (C) 2000 Daniel Molkentin (molkentin@kde.org)
+ Copyright (C) 2000 Stefan Schimanski (schimmi@kde.org)
+ Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All Rights Reserved.
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+#include "PluginData.h"
+
+namespace WebCore {
+
+PluginData::PluginData(const Page* page)
+ : m_page(page)
+{
+ initPlugins();
+
+ for (unsigned i = 0; i < m_plugins.size(); ++i) {
+ const PluginInfo* plugin = m_plugins[i];
+ for (unsigned j = 0; j < plugin->mimes.size(); ++j)
+ m_mimes.append(plugin->mimes[j]);
+ }
+}
+
+PluginData::~PluginData()
+{
+ deleteAllValues(m_plugins);
+ deleteAllValues(m_mimes);
+}
+
+bool PluginData::supportsMimeType(const String& mimeType) const
+{
+ for (unsigned i = 0; i < m_mimes.size(); ++i)
+ if (m_mimes[i]->type == mimeType)
+ return true;
+ return false;
+}
+
+String PluginData::pluginNameForMimeType(const String& mimeType) const
+{
+ for (unsigned i = 0; i < m_mimes.size(); ++i)
+ if (m_mimes[i]->type == mimeType)
+ return m_mimes[i]->plugin->name;
+ return String();
+}
+
+}
diff --git a/src/3rdparty/webkit/WebCore/plugins/PluginData.h b/src/3rdparty/webkit/WebCore/plugins/PluginData.h
new file mode 100644
index 0000000000..b2866bff8c
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/PluginData.h
@@ -0,0 +1,74 @@
+/*
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef PluginData_h
+#define PluginData_h
+
+#include <wtf/RefCounted.h>
+#include <wtf/Vector.h>
+#include "PlatformString.h"
+
+namespace WebCore {
+
+ class Page;
+ struct PluginInfo;
+
+ struct MimeClassInfo {
+ String type;
+ String desc;
+ String suffixes;
+ PluginInfo* plugin;
+ };
+
+ struct PluginInfo {
+ String name;
+ String file;
+ String desc;
+ Vector<MimeClassInfo*> mimes;
+ };
+
+ // FIXME: merge with PluginDatabase in the future
+ class PluginData : public RefCounted<PluginData> {
+ public:
+ static PassRefPtr<PluginData> create(const Page* page) { return adoptRef(new PluginData(page)); }
+ ~PluginData();
+
+ void disconnectPage() { m_page = 0; }
+ const Page* page() const { return m_page; }
+
+ const Vector<PluginInfo*>& plugins() const { return m_plugins; }
+ const Vector<MimeClassInfo*>& mimes() const { return m_mimes; }
+
+ bool supportsMimeType(const String& mimeType) const;
+ String pluginNameForMimeType(const String& mimeType) const;
+
+ static void refresh();
+
+ private:
+ PluginData(const Page*);
+ void initPlugins();
+
+ Vector<PluginInfo*> m_plugins;
+ Vector<MimeClassInfo*> m_mimes;
+ const Page* m_page;
+ };
+
+}
+
+#endif
diff --git a/src/3rdparty/webkit/WebCore/plugins/PluginDatabase.cpp b/src/3rdparty/webkit/WebCore/plugins/PluginDatabase.cpp
new file mode 100644
index 0000000000..8626277aa6
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/PluginDatabase.cpp
@@ -0,0 +1,375 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
+ *
+ * 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 "PluginDatabase.h"
+
+#include "Frame.h"
+#include "KURL.h"
+#include "PluginPackage.h"
+#include <stdlib.h>
+
+namespace WebCore {
+
+PluginDatabase* PluginDatabase::installedPlugins()
+{
+ static PluginDatabase* plugins = 0;
+
+ if (!plugins) {
+ plugins = new PluginDatabase;
+ plugins->setPluginDirectories(PluginDatabase::defaultPluginDirectories());
+ plugins->refresh();
+ }
+
+ return plugins;
+}
+
+bool PluginDatabase::isMIMETypeRegistered(const String& mimeType)
+{
+ if (mimeType.isNull())
+ return false;
+ if (m_registeredMIMETypes.contains(mimeType))
+ return true;
+ // No plugin was found, try refreshing the database and searching again
+ return (refresh() && m_registeredMIMETypes.contains(mimeType));
+}
+
+void PluginDatabase::addExtraPluginDirectory(const String& directory)
+{
+ m_pluginDirectories.append(directory);
+ refresh();
+}
+
+bool PluginDatabase::refresh()
+{
+ bool pluginSetChanged = false;
+
+ if (!m_plugins.isEmpty()) {
+ PluginSet pluginsToUnload;
+ getDeletedPlugins(pluginsToUnload);
+
+ // Unload plugins
+ PluginSet::const_iterator end = pluginsToUnload.end();
+ for (PluginSet::const_iterator it = pluginsToUnload.begin(); it != end; ++it)
+ remove(it->get());
+
+ pluginSetChanged = !pluginsToUnload.isEmpty();
+ }
+
+ HashSet<String> paths;
+ getPluginPathsInDirectories(paths);
+
+ HashMap<String, time_t> pathsWithTimes;
+
+ // We should only skip unchanged files if we didn't remove any plugins above. If we did remove
+ // any plugins, we need to look at every plugin file so that, e.g., if the user has two versions
+ // of RealPlayer installed and just removed the newer one, we'll pick up the older one.
+ bool shouldSkipUnchangedFiles = !pluginSetChanged;
+
+ HashSet<String>::const_iterator pathsEnd = paths.end();
+ for (HashSet<String>::const_iterator it = paths.begin(); it != pathsEnd; ++it) {
+ time_t lastModified;
+ if (!getFileModificationTime(*it, lastModified))
+ continue;
+
+ pathsWithTimes.add(*it, lastModified);
+
+ // If the path's timestamp hasn't changed since the last time we ran refresh(), we don't have to do anything.
+ if (shouldSkipUnchangedFiles && m_pluginPathsWithTimes.get(*it) == lastModified)
+ continue;
+
+ if (RefPtr<PluginPackage> oldPackage = m_pluginsByPath.get(*it)) {
+ ASSERT(!shouldSkipUnchangedFiles || oldPackage->lastModified() != lastModified);
+ remove(oldPackage.get());
+ }
+
+ RefPtr<PluginPackage> package = PluginPackage::createPackage(*it, lastModified);
+ if (package && add(package.release()))
+ pluginSetChanged = true;
+ }
+
+ // Cache all the paths we found with their timestamps for next time.
+ pathsWithTimes.swap(m_pluginPathsWithTimes);
+
+ if (!pluginSetChanged)
+ return false;
+
+ m_registeredMIMETypes.clear();
+
+ // Register plug-in MIME types
+ PluginSet::const_iterator end = m_plugins.end();
+ for (PluginSet::const_iterator it = m_plugins.begin(); it != end; ++it) {
+ // Get MIME types
+ MIMEToDescriptionsMap::const_iterator map_end = (*it)->mimeToDescriptions().end();
+ for (MIMEToDescriptionsMap::const_iterator map_it = (*it)->mimeToDescriptions().begin(); map_it != map_end; ++map_it) {
+ m_registeredMIMETypes.add(map_it->first);
+ }
+ }
+
+ return true;
+}
+
+Vector<PluginPackage*> PluginDatabase::plugins() const
+{
+ Vector<PluginPackage*> result;
+
+ PluginSet::const_iterator end = m_plugins.end();
+ for (PluginSet::const_iterator it = m_plugins.begin(); it != end; ++it)
+ result.append((*it).get());
+
+ return result;
+}
+
+int PluginDatabase::preferredPluginCompare(const void* a, const void* b)
+{
+ PluginPackage* pluginA = *static_cast<PluginPackage* const*>(a);
+ PluginPackage* pluginB = *static_cast<PluginPackage* const*>(b);
+
+ return pluginA->compare(*pluginB);
+}
+
+PluginPackage* PluginDatabase::pluginForMIMEType(const String& mimeType)
+{
+ if (mimeType.isEmpty())
+ return 0;
+
+ String key = mimeType.lower();
+ PluginSet::const_iterator end = m_plugins.end();
+
+ Vector<PluginPackage*, 2> pluginChoices;
+
+ for (PluginSet::const_iterator it = m_plugins.begin(); it != end; ++it) {
+ if ((*it)->mimeToDescriptions().contains(key))
+ pluginChoices.append((*it).get());
+ }
+
+ if (pluginChoices.isEmpty())
+ return 0;
+
+ qsort(pluginChoices.data(), pluginChoices.size(), sizeof(PluginPackage*), PluginDatabase::preferredPluginCompare);
+
+ return pluginChoices[0];
+}
+
+String PluginDatabase::MIMETypeForExtension(const String& extension) const
+{
+ if (extension.isEmpty())
+ return String();
+
+ PluginSet::const_iterator end = m_plugins.end();
+ String mimeType;
+ Vector<PluginPackage*, 2> pluginChoices;
+ HashMap<PluginPackage*, String> mimeTypeForPlugin;
+
+ for (PluginSet::const_iterator it = m_plugins.begin(); it != end; ++it) {
+ MIMEToExtensionsMap::const_iterator mime_end = (*it)->mimeToExtensions().end();
+
+ for (MIMEToExtensionsMap::const_iterator mime_it = (*it)->mimeToExtensions().begin(); mime_it != mime_end; ++mime_it) {
+ const Vector<String>& extensions = mime_it->second;
+ bool foundMapping = false;
+ for (unsigned i = 0; i < extensions.size(); i++) {
+ if (equalIgnoringCase(extensions[i], extension)) {
+ PluginPackage* plugin = (*it).get();
+ pluginChoices.append(plugin);
+ mimeTypeForPlugin.add(plugin, mime_it->first);
+ foundMapping = true;
+ break;
+ }
+ }
+ if (foundMapping)
+ break;
+ }
+ }
+
+ if (pluginChoices.isEmpty())
+ return String();
+
+ qsort(pluginChoices.data(), pluginChoices.size(), sizeof(PluginPackage*), PluginDatabase::preferredPluginCompare);
+
+ return mimeTypeForPlugin.get(pluginChoices[0]);
+}
+
+PluginPackage* PluginDatabase::findPlugin(const KURL& url, String& mimeType)
+{
+ PluginPackage* plugin = pluginForMIMEType(mimeType);
+ String filename = url.string();
+
+ if (!plugin) {
+ String filename = url.lastPathComponent();
+ if (!filename.endsWith("/")) {
+ int extensionPos = filename.reverseFind('.');
+ if (extensionPos != -1) {
+ String extension = filename.substring(extensionPos + 1);
+
+ mimeType = MIMETypeForExtension(extension);
+ plugin = pluginForMIMEType(mimeType);
+ }
+ }
+ }
+
+ // FIXME: if no plugin could be found, query Windows for the mime type
+ // corresponding to the extension.
+
+ return plugin;
+}
+
+void PluginDatabase::getDeletedPlugins(PluginSet& plugins) const
+{
+ PluginSet::const_iterator end = m_plugins.end();
+ for (PluginSet::const_iterator it = m_plugins.begin(); it != end; ++it) {
+ if (!fileExists((*it)->path()))
+ plugins.add(*it);
+ }
+}
+
+bool PluginDatabase::add(PassRefPtr<PluginPackage> prpPackage)
+{
+ ASSERT_ARG(prpPackage, prpPackage);
+
+ RefPtr<PluginPackage> package = prpPackage;
+
+ if (!m_plugins.add(package).second)
+ return false;
+
+ m_pluginsByPath.add(package->path(), package);
+ return true;
+}
+
+void PluginDatabase::remove(PluginPackage* package)
+{
+ m_plugins.remove(package);
+ m_pluginsByPath.remove(package->path());
+}
+
+#if !PLATFORM(WIN_OS) || PLATFORM(WX)
+// For Safari/Win the following three methods are implemented
+// in PluginDatabaseWin.cpp, but if we can use WebCore constructs
+// for the logic we should perhaps move it here under XP_WIN?
+
+Vector<String> PluginDatabase::defaultPluginDirectories()
+{
+ Vector<String> paths;
+
+ // Add paths specific to each platform
+#if defined(XP_UNIX)
+ String userPluginPath = homeDirectoryPath();
+ userPluginPath.append(String("/.mozilla/plugins"));
+ paths.append(userPluginPath);
+
+ userPluginPath = homeDirectoryPath();
+ userPluginPath.append(String("/.netscape/plugins"));
+ paths.append(userPluginPath);
+
+ paths.append("/usr/lib/browser/plugins");
+ paths.append("/usr/local/lib/mozilla/plugins");
+ paths.append("/usr/lib/firefox/plugins");
+ paths.append("/usr/lib64/browser-plugins");
+ paths.append("/usr/lib/browser-plugins");
+ paths.append("/usr/lib/mozilla/plugins");
+ paths.append("/usr/local/netscape/plugins");
+ paths.append("/opt/mozilla/plugins");
+ paths.append("/opt/mozilla/lib/plugins");
+ paths.append("/opt/netscape/plugins");
+ paths.append("/opt/netscape/communicator/plugins");
+ paths.append("/usr/lib/netscape/plugins");
+ paths.append("/usr/lib/netscape/plugins-libc5");
+ paths.append("/usr/lib/netscape/plugins-libc6");
+ paths.append("/usr/lib64/netscape/plugins");
+ paths.append("/usr/lib64/mozilla/plugins");
+
+ String mozHome(getenv("MOZILLA_HOME"));
+ mozHome.append("/plugins");
+ paths.append(mozHome);
+
+ Vector<String> mozPaths;
+ String mozPath(getenv("MOZ_PLUGIN_PATH"));
+ mozPath.split(UChar(':'), /* allowEmptyEntries */ false, mozPaths);
+ paths.append(mozPaths);
+#elif defined(XP_MACOSX)
+ String userPluginPath = homeDirectoryPath();
+ userPluginPath.append(String("/Library/Internet Plug-Ins"));
+ paths.append(userPluginPath);
+ paths.append("/Library/Internet Plug-Ins");
+#elif defined(XP_WIN)
+ String userPluginPath = homeDirectoryPath();
+ userPluginPath.append(String("\\Application Data\\Mozilla\\plugins"));
+ paths.append(userPluginPath);
+#endif
+
+ // Add paths specific to each port
+#if PLATFORM(QT)
+ Vector<String> qtPaths;
+ String qtPath(getenv("QTWEBKIT_PLUGIN_PATH"));
+ qtPath.split(UChar(':'), /* allowEmptyEntries */ false, qtPaths);
+ paths.append(qtPaths);
+#endif
+
+ return paths;
+}
+
+bool PluginDatabase::isPreferredPluginDirectory(const String& path)
+{
+ String preferredPath = homeDirectoryPath();
+
+#if defined(XP_UNIX)
+ preferredPath.append(String("/.mozilla/plugins"));
+#elif defined(XP_MACOSX)
+ preferredPath.append(String("/Library/Internet Plug-Ins"));
+#elif defined(XP_WIN)
+ preferredPath.append(String("\\Application Data\\Mozilla\\plugins"));
+#endif
+
+ // TODO: We should normalize the path before doing a comparison.
+ return path == preferredPath;
+}
+
+void PluginDatabase::getPluginPathsInDirectories(HashSet<String>& paths) const
+{
+ // FIXME: This should be a case insensitive set.
+ HashSet<String> uniqueFilenames;
+
+#if defined(XP_UNIX)
+ String fileNameFilter("*.so");
+#else
+ String fileNameFilter("");
+#endif
+
+ Vector<String>::const_iterator dirsEnd = m_pluginDirectories.end();
+ for (Vector<String>::const_iterator dIt = m_pluginDirectories.begin(); dIt != dirsEnd; ++dIt) {
+ Vector<String> pluginPaths = listDirectory(*dIt, fileNameFilter);
+ Vector<String>::const_iterator pluginsEnd = pluginPaths.end();
+ for (Vector<String>::const_iterator pIt = pluginPaths.begin(); pIt != pluginsEnd; ++pIt) {
+ if (!fileExists(*pIt))
+ continue;
+
+ paths.add(*pIt);
+ }
+ }
+}
+
+#endif // !PLATFORM(WIN_OS)
+
+}
diff --git a/src/3rdparty/webkit/WebCore/plugins/PluginDatabase.h b/src/3rdparty/webkit/WebCore/plugins/PluginDatabase.h
new file mode 100644
index 0000000000..58839a295d
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/PluginDatabase.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef PluginDatabase_H
+#define PluginDatabase_H
+
+#include "PlatformString.h"
+#include "PluginPackage.h"
+#include "StringHash.h"
+
+#include <wtf/Vector.h>
+#include <wtf/HashSet.h>
+
+namespace WebCore {
+ class Element;
+ class Frame;
+ class IntSize;
+ class KURL;
+ class PluginPackage;
+
+ typedef HashSet<RefPtr<PluginPackage>, PluginPackageHash> PluginSet;
+
+ class PluginDatabase {
+ public:
+ static PluginDatabase* installedPlugins();
+
+ bool refresh();
+ Vector<PluginPackage*> plugins() const;
+ bool isMIMETypeRegistered(const String& mimeType);
+ void addExtraPluginDirectory(const String&);
+
+ static bool isPreferredPluginDirectory(const String& directory);
+ static int preferredPluginCompare(const void*, const void*);
+
+ PluginPackage* findPlugin(const KURL&, String& mimeType);
+
+ private:
+ void setPluginDirectories(const Vector<String>& directories) { m_pluginDirectories = directories; }
+
+ void getPluginPathsInDirectories(HashSet<String>&) const;
+ void getDeletedPlugins(PluginSet&) const;
+
+ // Returns whether the plugin was actually added or not (it won't be added if it's a duplicate of an existing plugin).
+ bool add(PassRefPtr<PluginPackage>);
+ void remove(PluginPackage*);
+
+ PluginPackage* pluginForMIMEType(const String& mimeType);
+ String MIMETypeForExtension(const String& extension) const;
+
+ static Vector<String> defaultPluginDirectories();
+
+ Vector<String> m_pluginDirectories;
+ HashSet<String> m_registeredMIMETypes;
+ PluginSet m_plugins;
+ HashMap<String, RefPtr<PluginPackage> > m_pluginsByPath;
+ HashMap<String, time_t> m_pluginPathsWithTimes;
+ };
+
+} // namespace WebCore
+
+#endif
diff --git a/src/3rdparty/webkit/WebCore/plugins/PluginDebug.h b/src/3rdparty/webkit/WebCore/plugins/PluginDebug.h
new file mode 100644
index 0000000000..a57c209b34
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/PluginDebug.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef PluginDebug_h
+#define PluginDebug_h
+
+#include "Logging.h"
+#include "npruntime_internal.h"
+
+#if !LOG_DISABLED
+
+static const char* const errorStrings[] = {
+ "No errors occurred.", /* NPERR_NO_ERROR */
+ "Error with no specific error code occurred.", /* NPERR_GENERIC_ERROR */
+ "Invalid instance passed to the plug-in.", /* NPERR_INVALID_INSTANCE_ERROR */
+ "Function table invalid.", /* NPERR_INVALID_FUNCTABLE_ERROR */
+ "Loading of plug-in failed.", /* NPERR_MODULE_LOAD_FAILED_ERROR */
+ "Memory allocation failed.", /* NPERR_OUT_OF_MEMORY_ERROR */
+ "Plug-in missing or invalid.", /* NPERR_INVALID_PLUGIN_ERROR */
+ "Plug-in directory missing or invalid.", /* NPERR_INVALID_PLUGIN_DIR_ERROR */
+ "Versions of plug-in and Communicator do not match.", /* NPERR_INCOMPATIBLE_VERSION_ERROR */
+ "Parameter missing or invalid.", /* NPERR_INVALID_PARAM */
+ "URL missing or invalid.", /* NPERR_INVALID_URL */
+ "File missing or invalid.", /* NPERR_FILE_NOT_FOUND */
+ "Stream contains no data.", /* NPERR_NO_DATA */
+ "Seekable stream expected.", /* NPERR_STREAM_NOT_SEEKABLE */
+ "Unknown error code"
+};
+
+#endif
+
+#define LOG_NPERROR(err) if (err != NPERR_NO_ERROR) LOG_VERBOSE(Plugin, "%s\n", errorStrings[err])
+#define LOG_PLUGIN_NET_ERROR() LOG_VERBOSE(Plugin, "Stream failed due to problems with network, disk I/O, lack of memory, or other problems.\n")
+
+#endif
diff --git a/src/3rdparty/webkit/WebCore/plugins/PluginInfoStore.cpp b/src/3rdparty/webkit/WebCore/plugins/PluginInfoStore.cpp
new file mode 100644
index 0000000000..732a1e1f11
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/PluginInfoStore.cpp
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ *
+ * 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 "PluginInfoStore.h"
+
+#include "KURL.h"
+#include "PluginData.h"
+#include "PluginDatabase.h"
+#include "PluginPackage.h"
+
+namespace WebCore {
+
+PluginInfo* PluginInfoStore::createPluginInfoForPluginAtIndex(unsigned i)
+{
+ PluginDatabase *db = PluginDatabase::installedPlugins();
+ PluginInfo* info = new PluginInfo;
+ PluginPackage* package = db->plugins()[i];
+
+ info->name = package->name();
+ info->file = package->fileName();
+ info->desc = package->description();
+
+ const MIMEToDescriptionsMap& mimeToDescriptions = package->mimeToDescriptions();
+ MIMEToDescriptionsMap::const_iterator end = mimeToDescriptions.end();
+ for (MIMEToDescriptionsMap::const_iterator it = mimeToDescriptions.begin(); it != end; ++it) {
+ MimeClassInfo* mime = new MimeClassInfo;
+ info->mimes.append(mime);
+
+ mime->type = it->first;
+ mime->desc = it->second;
+ mime->plugin = info;
+
+ Vector<String> extensions = package->mimeToExtensions().get(mime->type);
+
+ for (unsigned i = 0; i < extensions.size(); i++) {
+ if (i > 0)
+ mime->suffixes += ",";
+
+ mime->suffixes += extensions[i];
+ }
+ }
+
+ return info;
+}
+
+unsigned PluginInfoStore::pluginCount() const
+{
+ return PluginDatabase::installedPlugins()->plugins().size();
+}
+
+
+String PluginInfoStore::pluginNameForMIMEType(const String& mimeType)
+{
+ String mimeTypeCopy(mimeType);
+
+ if (PluginPackage* package = PluginDatabase::installedPlugins()->findPlugin(KURL(), mimeTypeCopy)) {
+ ASSERT(mimeType == mimeTypeCopy);
+
+ return package->name();
+ }
+
+ return String();
+}
+
+
+bool PluginInfoStore::supportsMIMEType(const WebCore::String& mimeType)
+{
+ return PluginDatabase::installedPlugins()->isMIMETypeRegistered(mimeType);
+}
+
+void refreshPlugins(bool reloadOpenPages)
+{
+ PluginDatabase::installedPlugins()->refresh();
+
+ if (reloadOpenPages) {
+ // FIXME: reload open pages
+ }
+}
+
+}
diff --git a/src/3rdparty/webkit/WebCore/plugins/PluginInfoStore.h b/src/3rdparty/webkit/WebCore/plugins/PluginInfoStore.h
new file mode 100644
index 0000000000..302cf8cdcd
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/PluginInfoStore.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef PluginInfoStore_h
+#define PluginInfoStore_h
+
+#include "PlatformString.h"
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+struct PluginInfo;
+
+class PluginInfoStore {
+public:
+ PluginInfo *createPluginInfoForPluginAtIndex(unsigned);
+ unsigned pluginCount() const;
+ static String pluginNameForMIMEType(const String& mimeType);
+ static bool supportsMIMEType(const String& mimeType);
+};
+
+void refreshPlugins(bool reloadOpenPages);
+
+}
+
+#endif
diff --git a/src/3rdparty/webkit/WebCore/plugins/PluginMainThreadScheduler.cpp b/src/3rdparty/webkit/WebCore/plugins/PluginMainThreadScheduler.cpp
new file mode 100644
index 0000000000..7528676b12
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/PluginMainThreadScheduler.cpp
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * 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 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 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 "PluginMainThreadScheduler.h"
+#include <wtf/StdLibExtras.h>
+
+namespace WebCore {
+
+PluginMainThreadScheduler& PluginMainThreadScheduler::scheduler()
+{
+ DEFINE_STATIC_LOCAL(PluginMainThreadScheduler, scheduler, ());
+
+ return scheduler;
+}
+
+PluginMainThreadScheduler::PluginMainThreadScheduler()
+ : m_callPending(false)
+{
+}
+
+void PluginMainThreadScheduler::scheduleCall(NPP npp, MainThreadFunction function, void* userData)
+{
+ MutexLocker lock(m_queueMutex);
+
+ CallQueueMap::iterator it = m_callQueueMap.find(npp);
+ if (it == m_callQueueMap.end())
+ return;
+
+ it->second.append(Call(function, userData));
+
+ if (!m_callPending) {
+ callOnMainThread(mainThreadCallback, this);
+ m_callPending = true;
+ }
+}
+
+void PluginMainThreadScheduler::registerPlugin(NPP npp)
+{
+ MutexLocker lock(m_queueMutex);
+
+ ASSERT(!m_callQueueMap.contains(npp));
+ m_callQueueMap.set(npp, Deque<Call>());
+}
+
+void PluginMainThreadScheduler::unregisterPlugin(NPP npp)
+{
+ MutexLocker lock(m_queueMutex);
+
+ ASSERT(m_callQueueMap.contains(npp));
+ m_callQueueMap.remove(npp);
+}
+
+void PluginMainThreadScheduler::dispatchCallsForPlugin(NPP npp, const Deque<Call>& calls)
+{
+ Deque<Call>::const_iterator end = calls.end();
+ for (Deque<Call>::const_iterator it = calls.begin(); it != end; ++it) {
+ // Check if the plug-in has been destroyed.
+ {
+ MutexLocker lock(m_queueMutex);
+ if (!m_callQueueMap.contains(npp))
+ return;
+ }
+
+ (*it).performCall();
+ }
+}
+
+void PluginMainThreadScheduler::dispatchCalls()
+{
+ m_queueMutex.lock();
+ CallQueueMap copy(m_callQueueMap);
+
+ {
+ // Empty all the queues in the original map
+ CallQueueMap::iterator end = m_callQueueMap.end();
+ for (CallQueueMap::iterator it = m_callQueueMap.begin(); it != end; ++it)
+ it->second.clear();
+ }
+
+ m_callPending = false;
+ m_queueMutex.unlock();
+
+ CallQueueMap::iterator end = copy.end();
+ for (CallQueueMap::iterator it = copy.begin(); it != end; ++it)
+ dispatchCallsForPlugin(it->first, it->second);
+}
+
+void PluginMainThreadScheduler::mainThreadCallback(void* context)
+{
+ static_cast<PluginMainThreadScheduler*>(context)->dispatchCalls();
+}
+
+} // namespace WebCore
diff --git a/src/3rdparty/webkit/WebCore/plugins/PluginMainThreadScheduler.h b/src/3rdparty/webkit/WebCore/plugins/PluginMainThreadScheduler.h
new file mode 100644
index 0000000000..8872d56aee
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/PluginMainThreadScheduler.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * 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 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 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.
+ */
+
+#ifndef PluginMainThreadScheduler_h
+#define PluginMainThreadScheduler_h
+
+#include <wtf/Deque.h>
+#include <wtf/HashMap.h>
+#include <wtf/MainThread.h>
+#include <wtf/Threading.h>
+
+typedef struct _NPP NPP_t;
+typedef NPP_t* NPP;
+
+namespace WebCore {
+
+class PluginMainThreadScheduler {
+public:
+ typedef void MainThreadFunction(void*);
+
+ static PluginMainThreadScheduler& scheduler();
+
+ void scheduleCall(NPP, MainThreadFunction*, void* userData);
+
+ void registerPlugin(NPP);
+ void unregisterPlugin(NPP);
+
+private:
+ PluginMainThreadScheduler();
+ void dispatchCalls();
+
+ class Call;
+
+ void dispatchCallsForPlugin(NPP, const Deque<Call>& calls);
+ typedef HashMap<NPP, Deque<Call> > CallQueueMap;
+
+ static void mainThreadCallback(void* context);
+
+ class Call {
+ public:
+ Call(MainThreadFunction* function, void* userData)
+ : m_function(function)
+ , m_userData(userData)
+ {
+ }
+
+ void performCall() const
+ {
+ m_function(m_userData);
+ }
+
+ private:
+ MainThreadFunction* m_function;
+ void* m_userData;
+ };
+
+ bool m_callPending;
+ CallQueueMap m_callQueueMap;
+ Mutex m_queueMutex;
+};
+
+} // namespace WebCore
+
+#endif // PluginMainThreadScheduler_h
diff --git a/src/3rdparty/webkit/WebCore/plugins/PluginPackage.cpp b/src/3rdparty/webkit/WebCore/plugins/PluginPackage.cpp
new file mode 100644
index 0000000000..1c684b93df
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/PluginPackage.cpp
@@ -0,0 +1,240 @@
+/*
+ * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Collabora Ltd. All rights reserved.
+ *
+ * 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 "PluginPackage.h"
+
+#include "CString.h"
+#include "MIMETypeRegistry.h"
+#include "PluginDatabase.h"
+#include "PluginDebug.h"
+#include "Timer.h"
+#include "npruntime_impl.h"
+#include <string.h>
+#include <wtf/OwnArrayPtr.h>
+
+namespace WebCore {
+
+PluginPackage::~PluginPackage()
+{
+ // This destructor gets called during refresh() if PluginDatabase's
+ // PluginSet hash is already populated, as it removes items from
+ // the hash table. Calling the destructor on a loaded plug-in of
+ // course would cause a crash, so we check to call unload before we
+ // ASSERT.
+ // FIXME: There is probably a better way to fix this.
+ if (m_loadCount == 0)
+ unloadWithoutShutdown();
+ else
+ unload();
+
+ ASSERT(!m_isLoaded);
+}
+
+void PluginPackage::freeLibrarySoon()
+{
+ ASSERT(!m_freeLibraryTimer.isActive());
+ ASSERT(m_module);
+ ASSERT(m_loadCount == 0);
+
+ m_freeLibraryTimer.startOneShot(0);
+}
+
+void PluginPackage::freeLibraryTimerFired(Timer<PluginPackage>*)
+{
+ ASSERT(m_module);
+ ASSERT(m_loadCount == 0);
+
+ unloadModule(m_module);
+ m_module = 0;
+}
+
+
+int PluginPackage::compare(const PluginPackage& compareTo) const
+{
+ // Sort plug-ins that allow multiple instances first.
+ bool AallowsMultipleInstances = !quirks().contains(PluginQuirkDontAllowMultipleInstances);
+ bool BallowsMultipleInstances = !compareTo.quirks().contains(PluginQuirkDontAllowMultipleInstances);
+ if (AallowsMultipleInstances != BallowsMultipleInstances)
+ return AallowsMultipleInstances ? -1 : 1;
+
+ // Sort plug-ins in a preferred path first.
+ bool AisInPreferredDirectory = PluginDatabase::isPreferredPluginDirectory(parentDirectory());
+ bool BisInPreferredDirectory = PluginDatabase::isPreferredPluginDirectory(compareTo.parentDirectory());
+ if (AisInPreferredDirectory != BisInPreferredDirectory)
+ return AisInPreferredDirectory ? -1 : 1;
+
+ int diff = strcmp(name().utf8().data(), compareTo.name().utf8().data());
+ if (diff)
+ return diff;
+
+ if (diff = compareFileVersion(compareTo.version()))
+ return diff;
+
+ return strcmp(parentDirectory().utf8().data(), compareTo.parentDirectory().utf8().data());
+}
+
+PluginPackage::PluginPackage(const String& path, const time_t& lastModified)
+ : m_isLoaded(false)
+ , m_loadCount(0)
+ , m_path(path)
+ , m_moduleVersion(0)
+ , m_module(0)
+ , m_lastModified(lastModified)
+ , m_freeLibraryTimer(this, &PluginPackage::freeLibraryTimerFired)
+{
+ m_fileName = pathGetFileName(m_path);
+ m_parentDirectory = m_path.left(m_path.length() - m_fileName.length() - 1);
+}
+
+void PluginPackage::unload()
+{
+ if (!m_isLoaded)
+ return;
+
+ if (--m_loadCount > 0)
+ return;
+
+ m_NPP_Shutdown();
+
+ unloadWithoutShutdown();
+}
+
+void PluginPackage::unloadWithoutShutdown()
+{
+ if (!m_isLoaded)
+ return;
+
+ ASSERT(m_loadCount == 0);
+ ASSERT(m_module);
+
+ // <rdar://5530519>: Crash when closing tab with pdf file (Reader 7 only)
+ // If the plugin has subclassed its parent window, as with Reader 7, we may have
+ // gotten here by way of the plugin's internal window proc forwarding a message to our
+ // original window proc. If we free the plugin library from here, we will jump back
+ // to code we just freed when we return, so delay calling FreeLibrary at least until
+ // the next message loop
+ freeLibrarySoon();
+
+ m_isLoaded = false;
+}
+
+PassRefPtr<PluginPackage> PluginPackage::createPackage(const String& path, const time_t& lastModified)
+{
+ RefPtr<PluginPackage> package = adoptRef(new PluginPackage(path, lastModified));
+
+ if (!package->fetchInfo())
+ return 0;
+
+ return package.release();
+}
+
+#if defined(XP_UNIX)
+void PluginPackage::determineQuirks(const String& mimeType)
+{
+ if (MIMETypeRegistry::isJavaAppletMIMEType(mimeType)) {
+ // Because a single process cannot create multiple VMs, and we cannot reliably unload a
+ // Java VM, we cannot unload the Java plugin, or we'll lose reference to our only VM
+ m_quirks.add(PluginQuirkDontUnloadPlugin);
+
+ // Setting the window region to an empty region causes bad scrolling repaint problems
+ // with the Java plug-in.
+ m_quirks.add(PluginQuirkDontClipToZeroRectWhenScrolling);
+ return;
+ }
+
+ if (mimeType == "application/x-shockwave-flash") {
+ static const PlatformModuleVersion flashTenVersion(0x0a000000);
+
+ if (compareFileVersion(flashTenVersion) >= 0) {
+ // Flash 10.0 b218 doesn't like having a NULL window handle
+ m_quirks.add(PluginQuirkDontSetNullWindowHandleOnDestroy);
+#if PLATFORM(QT)
+ m_quirks.add(PluginQuirkRequiresGtkToolKit);
+#endif
+ } else {
+ // Flash 9 and older requests windowless plugins if we return a mozilla user agent
+ m_quirks.add(PluginQuirkWantsMozillaUserAgent);
+ }
+
+ m_quirks.add(PluginQuirkThrottleInvalidate);
+ m_quirks.add(PluginQuirkThrottleWMUserPlusOneMessages);
+ m_quirks.add(PluginQuirkFlashURLNotifyBug);
+ }
+}
+#endif
+
+#if !PLATFORM(WIN_OS)
+void PluginPackage::determineModuleVersionFromDescription()
+{
+ // It's a bit lame to detect the plugin version by parsing it
+ // from the plugin description string, but it doesn't seem that
+ // version information is available in any standardized way at
+ // the module level, like in Windows
+
+ if (m_description.isEmpty())
+ return;
+
+ if (m_description.startsWith("Shockwave Flash") && m_description.length() >= 19) {
+ // The flash version as a PlatformModuleVersion differs on Unix from Windows
+ // since the revision can be larger than a 8 bits, so we allow it 16 here and
+ // push the major/minor up 8 bits. Thus on Unix, Flash's version may be
+ // 0x0a000000 instead of 0x000a0000.
+
+ Vector<String> versionParts;
+ m_description.substring(16).split(' ', /*allowEmptyEntries =*/ false, versionParts);
+ if (versionParts.isEmpty())
+ return;
+
+ if (versionParts.size() >= 1) {
+ Vector<String> majorMinorParts;
+ versionParts[0].split('.', majorMinorParts);
+ if (majorMinorParts.size() >= 1) {
+ bool converted = false;
+ unsigned major = majorMinorParts[0].toUInt(&converted);
+ if (converted)
+ m_moduleVersion = (major & 0xff) << 24;
+ }
+ if (majorMinorParts.size() == 2) {
+ bool converted = false;
+ unsigned minor = majorMinorParts[1].toUInt(&converted);
+ if (converted)
+ m_moduleVersion |= (minor & 0xff) << 16;
+ }
+ }
+
+ if (versionParts.size() >= 2) {
+ String revision = versionParts[1];
+ if (revision.length() > 1 && (revision[0] == 'r' || revision[0] == 'b')) {
+ revision.remove(0, 1);
+ m_moduleVersion |= revision.toInt() & 0xffff;
+ }
+ }
+ }
+}
+#endif
+
+}
diff --git a/src/3rdparty/webkit/WebCore/plugins/PluginPackage.h b/src/3rdparty/webkit/WebCore/plugins/PluginPackage.h
new file mode 100644
index 0000000000..707eb25dbf
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/PluginPackage.h
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef PluginPackage_H
+#define PluginPackage_H
+
+#include "FileSystem.h"
+#include "PlatformString.h"
+#include "PluginQuirkSet.h"
+#include "StringHash.h"
+#include "Timer.h"
+#include "npruntime_internal.h"
+#include <wtf/HashMap.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+ typedef HashMap<String, String> MIMEToDescriptionsMap;
+ typedef HashMap<String, Vector<String> > MIMEToExtensionsMap;
+
+ class PluginPackage : public RefCounted<PluginPackage> {
+ public:
+ ~PluginPackage();
+ static PassRefPtr<PluginPackage> createPackage(const String& path, const time_t& lastModified);
+
+ const String& name() const { return m_name; }
+ const String& description() const { return m_description; }
+ const String& path() const { return m_path; }
+ const String& fileName() const { return m_fileName; }
+ const String& parentDirectory() const { return m_parentDirectory; }
+ time_t lastModified() const { return m_lastModified; }
+
+ const MIMEToDescriptionsMap& mimeToDescriptions() const { return m_mimeToDescriptions; }
+ const MIMEToExtensionsMap& mimeToExtensions() const { return m_mimeToExtensions; }
+
+ unsigned hash() const;
+ static bool equal(const PluginPackage& a, const PluginPackage& b);
+
+ bool load();
+ void unload();
+ void unloadWithoutShutdown();
+
+ const NPPluginFuncs* pluginFuncs() const { return &m_pluginFuncs; }
+ int compareFileVersion(const PlatformModuleVersion&) const;
+ int compare(const PluginPackage&) const;
+ PluginQuirkSet quirks() const { return m_quirks; }
+ const PlatformModuleVersion& version() const { return m_moduleVersion; }
+
+ private:
+ PluginPackage(const String& path, const time_t& lastModified);
+ bool fetchInfo();
+ bool isPluginBlacklisted();
+ void determineQuirks(const String& mimeType);
+
+ void determineModuleVersionFromDescription();
+
+ bool m_isLoaded;
+ int m_loadCount;
+
+ String m_description;
+ String m_path;
+ String m_fileName;
+ String m_name;
+ String m_parentDirectory;
+
+ PlatformModuleVersion m_moduleVersion;
+
+ MIMEToDescriptionsMap m_mimeToDescriptions;
+ MIMEToExtensionsMap m_mimeToExtensions;
+
+ PlatformModule m_module;
+ time_t m_lastModified;
+
+ NPP_ShutdownProcPtr m_NPP_Shutdown;
+ NPPluginFuncs m_pluginFuncs;
+ NPNetscapeFuncs m_browserFuncs;
+
+ void freeLibrarySoon();
+ void freeLibraryTimerFired(Timer<PluginPackage>*);
+ Timer<PluginPackage> m_freeLibraryTimer;
+
+ PluginQuirkSet m_quirks;
+ };
+
+ struct PluginPackageHash {
+ static unsigned hash(const uintptr_t key) { return reinterpret_cast<PluginPackage*>(key)->hash(); }
+ static unsigned hash(const RefPtr<PluginPackage>& key) { return key->hash(); }
+
+ static bool equal(const uintptr_t a, const uintptr_t b) { return equal(reinterpret_cast<PluginPackage*>(a), reinterpret_cast<PluginPackage*>(b)); }
+ static bool equal(const RefPtr<PluginPackage>& a, const RefPtr<PluginPackage>& b) { return PluginPackage::equal(*a.get(), *b.get()); }
+ static const bool safeToCompareToEmptyOrDeleted = false;
+ };
+
+} // namespace WebCore
+
+#endif
diff --git a/src/3rdparty/webkit/WebCore/plugins/PluginQuirkSet.h b/src/3rdparty/webkit/WebCore/plugins/PluginQuirkSet.h
new file mode 100644
index 0000000000..b652c6e328
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/PluginQuirkSet.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 OR ITS 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.
+ */
+
+#ifndef PluginQuirkSet_h
+#define PluginQuirkSet_h
+
+
+namespace WebCore {
+
+ enum PluginQuirk {
+ PluginQuirkWantsMozillaUserAgent = 1 << 0,
+ PluginQuirkDeferFirstSetWindowCall = 1 << 1,
+ PluginQuirkThrottleInvalidate = 1 << 2,
+ PluginQuirkRemoveWindowlessVideoParam = 1 << 3,
+ PluginQuirkThrottleWMUserPlusOneMessages = 1 << 4,
+ PluginQuirkDontUnloadPlugin = 1 << 5,
+ PluginQuirkDontCallWndProcForSameMessageRecursively = 1 << 6,
+ PluginQuirkHasModalMessageLoop = 1 << 7,
+ PluginQuirkFlashURLNotifyBug = 1 << 8,
+ PluginQuirkDontClipToZeroRectWhenScrolling = 1 << 9,
+ PluginQuirkDontSetNullWindowHandleOnDestroy = 1 << 10,
+ PluginQuirkDontAllowMultipleInstances = 1 << 11,
+ PluginQuirkRequiresGtkToolKit = 1 << 12,
+ };
+
+ class PluginQuirkSet {
+ public:
+ PluginQuirkSet() : m_quirks(0) { }
+ void add(PluginQuirk quirk) { m_quirks |= quirk; }
+ bool contains(PluginQuirk quirk) const { return m_quirks & quirk; }
+ private:
+ unsigned m_quirks;
+ };
+
+} // namespace WebCore
+
+#endif // PluginQuirkSet_h
diff --git a/src/3rdparty/webkit/WebCore/plugins/PluginStream.cpp b/src/3rdparty/webkit/WebCore/plugins/PluginStream.cpp
new file mode 100644
index 0000000000..2cf2accdd2
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/PluginStream.cpp
@@ -0,0 +1,476 @@
+/*
+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
+ *
+ * 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 "PluginStream.h"
+
+#include "CString.h"
+#include "DocumentLoader.h"
+#include "Frame.h"
+#include "FrameLoader.h"
+#include "PluginDebug.h"
+#include "SharedBuffer.h"
+#include "SubresourceLoader.h"
+#include <StringExtras.h>
+
+// We use -2 here because some plugins like to return -1 to indicate error
+// and this way we won't clash with them.
+static const int WebReasonNone = -2;
+
+using std::max;
+using std::min;
+
+namespace WebCore {
+
+typedef HashMap<NPStream*, NPP> StreamMap;
+static StreamMap& streams()
+{
+ static StreamMap staticStreams;
+ return staticStreams;
+}
+
+PluginStream::PluginStream(PluginStreamClient* client, Frame* frame, const ResourceRequest& resourceRequest, bool sendNotification, void* notifyData, const NPPluginFuncs* pluginFuncs, NPP instance, const PluginQuirkSet& quirks)
+ : m_resourceRequest(resourceRequest)
+ , m_client(client)
+ , m_frame(frame)
+ , m_notifyData(notifyData)
+ , m_sendNotification(sendNotification)
+ , m_streamState(StreamBeforeStarted)
+ , m_loadManually(false)
+ , m_delayDeliveryTimer(this, &PluginStream::delayDeliveryTimerFired)
+ , m_deliveryData(0)
+ , m_tempFileHandle(invalidPlatformFileHandle)
+ , m_pluginFuncs(pluginFuncs)
+ , m_instance(instance)
+ , m_quirks(quirks)
+{
+ ASSERT(m_instance);
+
+ m_stream.url = 0;
+ m_stream.ndata = 0;
+ m_stream.pdata = 0;
+ m_stream.end = 0;
+ m_stream.notifyData = 0;
+ m_stream.lastmodified = 0;
+
+ streams().add(&m_stream, m_instance);
+}
+
+PluginStream::~PluginStream()
+{
+ ASSERT(m_streamState != StreamStarted);
+ ASSERT(!m_loader);
+
+ free((char*)m_stream.url);
+
+ streams().remove(&m_stream);
+}
+
+void PluginStream::start()
+{
+ ASSERT(!m_loadManually);
+
+ m_loader = NetscapePlugInStreamLoader::create(m_frame, this);
+
+ m_loader->setShouldBufferData(false);
+ m_loader->documentLoader()->addPlugInStreamLoader(m_loader.get());
+ m_loader->load(m_resourceRequest);
+}
+
+void PluginStream::stop()
+{
+ m_streamState = StreamStopped;
+
+ if (m_loadManually) {
+ ASSERT(!m_loader);
+
+ DocumentLoader* documentLoader = m_frame->loader()->activeDocumentLoader();
+ ASSERT(documentLoader);
+
+ if (documentLoader->isLoadingMainResource())
+ documentLoader->cancelMainResourceLoad(m_frame->loader()->cancelledError(m_resourceRequest));
+
+ return;
+ }
+
+ if (m_loader) {
+ m_loader->cancel();
+ m_loader = 0;
+ }
+}
+
+void PluginStream::startStream()
+{
+ ASSERT(m_streamState == StreamBeforeStarted);
+
+ const KURL& responseURL = m_resourceResponse.url();
+
+ // Some plugins (Flash) expect that javascript URLs are passed back decoded as this is the
+ // format used when requesting the URL.
+ if (responseURL.protocolIs("javascript"))
+ m_stream.url = strdup(decodeURLEscapeSequences(responseURL.string()).utf8().data());
+ else
+ m_stream.url = strdup(responseURL.string().utf8().data());
+
+ CString mimeTypeStr = m_resourceResponse.mimeType().utf8();
+
+ long long expectedContentLength = m_resourceResponse.expectedContentLength();
+
+ if (m_resourceResponse.isHTTP()) {
+ Vector<UChar> stringBuilder;
+ String separator(": ");
+
+ String statusLine = String::format("HTTP %lu OK\n", m_resourceResponse.httpStatusCode());
+
+ stringBuilder.append(statusLine.characters(), statusLine.length());
+
+ HTTPHeaderMap::const_iterator end = m_resourceResponse.httpHeaderFields().end();
+ for (HTTPHeaderMap::const_iterator it = m_resourceResponse.httpHeaderFields().begin(); it != end; ++it) {
+ stringBuilder.append(it->first.characters(), it->first.length());
+ stringBuilder.append(separator.characters(), separator.length());
+ stringBuilder.append(it->second.characters(), it->second.length());
+ stringBuilder.append('\n');
+ }
+
+ m_headers = String::adopt(stringBuilder).utf8();
+
+ // If the content is encoded (most likely compressed), then don't send its length to the plugin,
+ // which is only interested in the decoded length, not yet known at the moment.
+ // <rdar://problem/4470599> tracks a request for -[NSURLResponse expectedContentLength] to incorporate this logic.
+ String contentEncoding = m_resourceResponse.httpHeaderField("Content-Encoding");
+ if (!contentEncoding.isNull() && contentEncoding != "identity")
+ expectedContentLength = -1;
+ }
+
+ m_stream.headers = m_headers.data();
+ m_stream.pdata = 0;
+ m_stream.ndata = this;
+ m_stream.end = max(expectedContentLength, 0LL);
+ m_stream.lastmodified = m_resourceResponse.lastModifiedDate();
+ m_stream.notifyData = m_notifyData;
+
+ m_transferMode = NP_NORMAL;
+ m_offset = 0;
+ m_reason = WebReasonNone;
+
+ // Protect the stream if destroystream is called from within the newstream handler
+ RefPtr<PluginStream> protect(this);
+
+ // calling into a plug-in could result in re-entrance if the plug-in yields
+ // control to the system (rdar://5744899). prevent this by deferring further
+ // loading while calling into the plug-in.
+ if (m_loader)
+ m_loader->setDefersLoading(true);
+ NPError npErr = m_pluginFuncs->newstream(m_instance, (NPMIMEType)mimeTypeStr.data(), &m_stream, false, &m_transferMode);
+ if (m_loader)
+ m_loader->setDefersLoading(false);
+
+ // If the stream was destroyed in the call to newstream we return
+ if (m_reason != WebReasonNone)
+ return;
+
+ if (npErr != NPERR_NO_ERROR) {
+ cancelAndDestroyStream(npErr);
+ return;
+ }
+
+ m_streamState = StreamStarted;
+
+ if (m_transferMode == NP_NORMAL)
+ return;
+
+ m_path = openTemporaryFile("WKP", m_tempFileHandle);
+
+ // Something went wrong, cancel loading the stream
+ if (!isHandleValid(m_tempFileHandle))
+ cancelAndDestroyStream(NPRES_NETWORK_ERR);
+}
+
+NPP PluginStream::ownerForStream(NPStream* stream)
+{
+ return streams().get(stream);
+}
+
+void PluginStream::cancelAndDestroyStream(NPReason reason)
+{
+ RefPtr<PluginStream> protect(this);
+
+ destroyStream(reason);
+ stop();
+}
+
+void PluginStream::destroyStream(NPReason reason)
+{
+ m_reason = reason;
+ if (m_reason != NPRES_DONE) {
+ // Stop any pending data from being streamed
+ if (m_deliveryData)
+ m_deliveryData->resize(0);
+ } else if (m_deliveryData && m_deliveryData->size() > 0) {
+ // There is more data to be streamed, don't destroy the stream now.
+ return;
+ }
+ destroyStream();
+}
+
+void PluginStream::destroyStream()
+{
+ if (m_streamState == StreamStopped)
+ return;
+
+ ASSERT(m_reason != WebReasonNone);
+ ASSERT(!m_deliveryData || m_deliveryData->size() == 0);
+
+ closeFile(m_tempFileHandle);
+
+ bool newStreamCalled = m_stream.ndata;
+
+ if (newStreamCalled) {
+ if (m_reason == NPRES_DONE && (m_transferMode == NP_ASFILE || m_transferMode == NP_ASFILEONLY)) {
+ ASSERT(!m_path.isNull());
+
+ if (m_loader)
+ m_loader->setDefersLoading(true);
+ m_pluginFuncs->asfile(m_instance, &m_stream, m_path.data());
+ if (m_loader)
+ m_loader->setDefersLoading(false);
+ }
+
+ if (m_streamState != StreamBeforeStarted) {
+ if (m_loader)
+ m_loader->setDefersLoading(true);
+
+ NPError npErr = m_pluginFuncs->destroystream(m_instance, &m_stream, m_reason);
+
+ if (m_loader)
+ m_loader->setDefersLoading(false);
+
+ LOG_NPERROR(npErr);
+ }
+
+ m_stream.ndata = 0;
+ }
+
+ if (m_sendNotification) {
+ // Flash 9 can dereference null if we call NPP_URLNotify without first calling NPP_NewStream
+ // for requests made with NPN_PostURLNotify; see <rdar://5588807>
+ if (m_loader)
+ m_loader->setDefersLoading(true);
+ if (!newStreamCalled && m_quirks.contains(PluginQuirkFlashURLNotifyBug) &&
+ equalIgnoringCase(m_resourceRequest.httpMethod(), "POST")) {
+ // Protect the stream if NPN_DestroyStream is called from NPP_NewStream
+ RefPtr<PluginStream> protect(this);
+
+ m_transferMode = NP_NORMAL;
+ m_stream.url = "";
+ m_stream.notifyData = m_notifyData;
+
+ static char emptyMimeType[] = "";
+ m_pluginFuncs->newstream(m_instance, emptyMimeType, &m_stream, false, &m_transferMode);
+ m_pluginFuncs->destroystream(m_instance, &m_stream, m_reason);
+
+ // in successful requests, the URL is dynamically allocated and freed in our
+ // destructor, so reset it to 0
+ m_stream.url = 0;
+ }
+ m_pluginFuncs->urlnotify(m_instance, m_resourceRequest.url().string().utf8().data(), m_reason, m_notifyData);
+ if (m_loader)
+ m_loader->setDefersLoading(false);
+ }
+
+ m_streamState = StreamStopped;
+
+ // streamDidFinishLoading can cause us to be deleted.
+ RefPtr<PluginStream> protect(this);
+ if (!m_loadManually)
+ m_client->streamDidFinishLoading(this);
+
+ if (!m_path.isNull()) {
+ String tempFilePath = String::fromUTF8(m_path.data());
+ deleteFile(tempFilePath);
+ }
+}
+
+void PluginStream::delayDeliveryTimerFired(Timer<PluginStream>* timer)
+{
+ ASSERT(timer == &m_delayDeliveryTimer);
+
+ deliverData();
+}
+
+void PluginStream::deliverData()
+{
+ ASSERT(m_deliveryData);
+
+ if (m_streamState == StreamStopped)
+ // FIXME: We should cancel our job in the SubresourceLoader on error so we don't reach this case
+ return;
+
+ ASSERT(m_streamState != StreamBeforeStarted);
+
+ if (!m_stream.ndata || m_deliveryData->size() == 0)
+ return;
+
+ int32 totalBytes = m_deliveryData->size();
+ int32 totalBytesDelivered = 0;
+
+ if (m_loader)
+ m_loader->setDefersLoading(true);
+ while (totalBytesDelivered < totalBytes) {
+ int32 deliveryBytes = m_pluginFuncs->writeready(m_instance, &m_stream);
+
+ if (deliveryBytes <= 0) {
+ m_delayDeliveryTimer.startOneShot(0);
+ break;
+ } else {
+ deliveryBytes = min(deliveryBytes, totalBytes - totalBytesDelivered);
+ int32 dataLength = deliveryBytes;
+ char* data = m_deliveryData->data() + totalBytesDelivered;
+
+ // Write the data
+ deliveryBytes = m_pluginFuncs->write(m_instance, &m_stream, m_offset, dataLength, (void*)data);
+ if (deliveryBytes < 0) {
+ LOG_PLUGIN_NET_ERROR();
+ cancelAndDestroyStream(NPRES_NETWORK_ERR);
+ return;
+ }
+ deliveryBytes = min(deliveryBytes, dataLength);
+ m_offset += deliveryBytes;
+ totalBytesDelivered += deliveryBytes;
+ }
+ }
+ if (m_loader)
+ m_loader->setDefersLoading(false);
+
+ if (totalBytesDelivered > 0) {
+ if (totalBytesDelivered < totalBytes) {
+ int remainingBytes = totalBytes - totalBytesDelivered;
+ memmove(m_deliveryData->data(), m_deliveryData->data() + totalBytesDelivered, remainingBytes);
+ m_deliveryData->resize(remainingBytes);
+ } else {
+ m_deliveryData->resize(0);
+ if (m_reason != WebReasonNone)
+ destroyStream();
+ }
+ }
+}
+
+void PluginStream::sendJavaScriptStream(const KURL& requestURL, const CString& resultString)
+{
+ didReceiveResponse(0, ResourceResponse(requestURL, "text/plain", resultString.length(), "", ""));
+
+ if (m_streamState == StreamStopped)
+ return;
+
+ if (!resultString.isNull()) {
+ didReceiveData(0, resultString.data(), resultString.length());
+ if (m_streamState == StreamStopped)
+ return;
+ }
+
+ m_loader = 0;
+
+ destroyStream(resultString.isNull() ? NPRES_NETWORK_ERR : NPRES_DONE);
+}
+
+void PluginStream::didReceiveResponse(NetscapePlugInStreamLoader* loader, const ResourceResponse& response)
+{
+ ASSERT(loader == m_loader);
+ ASSERT(m_streamState == StreamBeforeStarted);
+
+ m_resourceResponse = response;
+
+ startStream();
+}
+
+void PluginStream::didReceiveData(NetscapePlugInStreamLoader* loader, const char* data, int length)
+{
+ ASSERT(loader == m_loader);
+ ASSERT(length > 0);
+ ASSERT(m_streamState == StreamStarted);
+
+ // If the plug-in cancels the stream in deliverData it could be deleted,
+ // so protect it here.
+ RefPtr<PluginStream> protect(this);
+
+ if (m_transferMode != NP_ASFILEONLY) {
+ if (!m_deliveryData)
+ m_deliveryData.set(new Vector<char>);
+
+ int oldSize = m_deliveryData->size();
+ m_deliveryData->resize(oldSize + length);
+ memcpy(m_deliveryData->data() + oldSize, data, length);
+
+ deliverData();
+ }
+
+ if (m_streamState != StreamStopped && isHandleValid(m_tempFileHandle)) {
+ int bytesWritten = writeToFile(m_tempFileHandle, data, length);
+ if (bytesWritten != length)
+ cancelAndDestroyStream(NPRES_NETWORK_ERR);
+ }
+}
+
+void PluginStream::didFail(NetscapePlugInStreamLoader* loader, const ResourceError&)
+{
+ ASSERT(loader == m_loader);
+
+ LOG_PLUGIN_NET_ERROR();
+
+ // destroyStream can result in our being deleted
+ RefPtr<PluginStream> protect(this);
+
+ destroyStream(NPRES_NETWORK_ERR);
+
+ m_loader = 0;
+}
+
+void PluginStream::didFinishLoading(NetscapePlugInStreamLoader* loader)
+{
+ ASSERT(loader == m_loader);
+ ASSERT(m_streamState == StreamStarted);
+
+ // destroyStream can result in our being deleted
+ RefPtr<PluginStream> protect(this);
+
+ destroyStream(NPRES_DONE);
+
+ m_loader = 0;
+}
+
+bool PluginStream::wantsAllStreams() const
+{
+ if (!m_pluginFuncs->getvalue)
+ return false;
+
+ void* result = 0;
+ if (m_pluginFuncs->getvalue(m_instance, NPPVpluginWantsAllNetworkStreams, &result) != NPERR_NO_ERROR)
+ return false;
+
+ return result != 0;
+}
+
+}
diff --git a/src/3rdparty/webkit/WebCore/plugins/PluginStream.h b/src/3rdparty/webkit/WebCore/plugins/PluginStream.h
new file mode 100644
index 0000000000..dc08f01744
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/PluginStream.h
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef PluginStream_H
+#define PluginStream_H
+
+#include "CString.h"
+#include "FileSystem.h"
+#include "KURL.h"
+#include "NetscapePlugInStreamLoader.h"
+#include "PlatformString.h"
+#include "PluginQuirkSet.h"
+#include "ResourceRequest.h"
+#include "ResourceResponse.h"
+#include "StringHash.h"
+#include "Timer.h"
+#include "npruntime_internal.h"
+#include <wtf/HashMap.h>
+#include <wtf/OwnPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+ class Frame;
+ class PluginStream;
+
+ enum PluginStreamState { StreamBeforeStarted, StreamStarted, StreamStopped };
+
+ class PluginStreamClient {
+ public:
+ virtual ~PluginStreamClient() {}
+ virtual void streamDidFinishLoading(PluginStream*) {}
+ };
+
+ class PluginStream : public RefCounted<PluginStream>, private NetscapePlugInStreamLoaderClient {
+ public:
+ static PassRefPtr<PluginStream> create(PluginStreamClient* client, Frame* frame, const ResourceRequest& request, bool sendNotification, void* notifyData, const NPPluginFuncs* functions, NPP instance, const PluginQuirkSet& quirks)
+ {
+ return adoptRef(new PluginStream(client, frame, request, sendNotification, notifyData, functions, instance, quirks));
+ }
+ virtual ~PluginStream();
+
+ void start();
+ void stop();
+
+ void startStream();
+
+ void setLoadManually(bool loadManually) { m_loadManually = loadManually; }
+
+ void sendJavaScriptStream(const KURL& requestURL, const CString& resultString);
+ void cancelAndDestroyStream(NPReason);
+
+ static NPP ownerForStream(NPStream*);
+
+ // NetscapePlugInStreamLoaderClient
+ virtual void didReceiveResponse(NetscapePlugInStreamLoader*, const ResourceResponse&);
+ virtual void didReceiveData(NetscapePlugInStreamLoader*, const char*, int);
+ virtual void didFail(NetscapePlugInStreamLoader*, const ResourceError&);
+ virtual void didFinishLoading(NetscapePlugInStreamLoader*);
+ virtual bool wantsAllStreams() const;
+
+ private:
+ PluginStream(PluginStreamClient*, Frame*, const ResourceRequest&, bool sendNotification, void* notifyData, const NPPluginFuncs*, NPP instance, const PluginQuirkSet&);
+
+ void deliverData();
+ void destroyStream(NPReason);
+ void destroyStream();
+
+ ResourceRequest m_resourceRequest;
+ ResourceResponse m_resourceResponse;
+
+ PluginStreamClient* m_client;
+ Frame* m_frame;
+ RefPtr<NetscapePlugInStreamLoader> m_loader;
+ void* m_notifyData;
+ bool m_sendNotification;
+ PluginStreamState m_streamState;
+ bool m_loadManually;
+
+ Timer<PluginStream> m_delayDeliveryTimer;
+ void delayDeliveryTimerFired(Timer<PluginStream>*);
+
+ OwnPtr< Vector<char> > m_deliveryData;
+
+ PlatformFileHandle m_tempFileHandle;
+
+ const NPPluginFuncs* m_pluginFuncs;
+ NPP m_instance;
+ uint16 m_transferMode;
+ int32 m_offset;
+ CString m_headers;
+ CString m_path;
+ NPReason m_reason;
+ NPStream m_stream;
+ PluginQuirkSet m_quirks;
+ };
+
+} // namespace WebCore
+
+#endif
diff --git a/src/3rdparty/webkit/WebCore/plugins/PluginView.cpp b/src/3rdparty/webkit/WebCore/plugins/PluginView.cpp
new file mode 100644
index 0000000000..61d31577ff
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/PluginView.cpp
@@ -0,0 +1,938 @@
+/*
+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Collabora Ltd. All rights reserved.
+ *
+ * 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 "Document.h"
+#include "DocumentLoader.h"
+#include "Element.h"
+#include "FrameLoader.h"
+#include "FrameTree.h"
+#include "Frame.h"
+#include "FrameView.h"
+#include "GraphicsContext.h"
+#include "Image.h"
+#include "HTMLNames.h"
+#include "HTMLPlugInElement.h"
+#include "JSDOMWindow.h"
+#include "KeyboardEvent.h"
+#include "MIMETypeRegistry.h"
+#include "MouseEvent.h"
+#include "NotImplemented.h"
+#include "Page.h"
+#include "FocusController.h"
+#include "PlatformMouseEvent.h"
+#if PLATFORM(WIN_OS) && !PLATFORM(WX) && ENABLE(NETSCAPE_PLUGIN_API)
+#include "PluginMessageThrottlerWin.h"
+#endif
+#include "PluginPackage.h"
+#include "JSDOMBinding.h"
+#include "ScriptController.h"
+#include "ScriptValue.h"
+#include "PluginDatabase.h"
+#include "PluginDebug.h"
+#include "PluginMainThreadScheduler.h"
+#include "PluginPackage.h"
+#include "RenderObject.h"
+#include "c_instance.h"
+#include "npruntime_impl.h"
+#include "runtime_root.h"
+#include "Settings.h"
+#include "runtime.h"
+#include <runtime/JSLock.h>
+#include <runtime/JSValue.h>
+#include <wtf/ASCIICType.h>
+
+using JSC::ExecState;
+using JSC::JSLock;
+using JSC::JSObject;
+using JSC::JSValue;
+using JSC::JSValuePtr;
+using JSC::UString;
+
+using std::min;
+
+using namespace WTF;
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+static int s_callingPlugin;
+
+static String scriptStringIfJavaScriptURL(const KURL& url)
+{
+ if (!url.protocolIs("javascript"))
+ return String();
+
+ // This returns an unescaped string
+ return decodeURLEscapeSequences(url.string().substring(11));
+}
+
+PluginView* PluginView::s_currentPluginView = 0;
+
+void PluginView::popPopupsStateTimerFired(Timer<PluginView>*)
+{
+ popPopupsEnabledState();
+}
+
+IntRect PluginView::windowClipRect() const
+{
+ // Start by clipping to our bounds.
+ IntRect clipRect(m_windowRect);
+
+ // Take our element and get the clip rect from the enclosing layer and frame view.
+ RenderLayer* layer = m_element->renderer()->enclosingLayer();
+ FrameView* parentView = m_element->document()->view();
+ clipRect.intersect(parentView->windowClipRectForLayer(layer, true));
+
+ return clipRect;
+}
+
+void PluginView::setFrameRect(const IntRect& rect)
+{
+ if (m_element->document()->printing())
+ return;
+
+ if (rect != frameRect())
+ Widget::setFrameRect(rect);
+
+ updatePluginWidget();
+
+#if PLATFORM(WIN_OS)
+ // On Windows, always call plugin to change geometry.
+ setNPWindowRect(rect);
+#elif XP_UNIX
+ // On Unix, only call plugin if it's full-page.
+ if (m_mode == NP_FULL)
+ setNPWindowRect(rect);
+#endif
+}
+
+void PluginView::frameRectsChanged()
+{
+ updatePluginWidget();
+}
+
+void PluginView::handleEvent(Event* event)
+{
+ if (!m_plugin || m_isWindowed)
+ return;
+
+ if (event->isMouseEvent())
+ handleMouseEvent(static_cast<MouseEvent*>(event));
+ else if (event->isKeyboardEvent())
+ handleKeyboardEvent(static_cast<KeyboardEvent*>(event));
+}
+
+bool PluginView::start()
+{
+ if (m_isStarted)
+ return false;
+
+ PluginMainThreadScheduler::scheduler().registerPlugin(m_instance);
+
+ ASSERT(m_plugin);
+ ASSERT(m_plugin->pluginFuncs()->newp);
+
+ NPError npErr;
+ {
+ PluginView::setCurrentPluginView(this);
+ JSC::JSLock::DropAllLocks dropAllLocks(false);
+ setCallingPlugin(true);
+ npErr = m_plugin->pluginFuncs()->newp((NPMIMEType)m_mimeType.data(), m_instance, m_mode, m_paramCount, m_paramNames, m_paramValues, NULL);
+ setCallingPlugin(false);
+ LOG_NPERROR(npErr);
+ PluginView::setCurrentPluginView(0);
+ }
+
+ if (npErr != NPERR_NO_ERROR)
+ return false;
+
+ m_isStarted = true;
+
+ if (!m_url.isEmpty() && !m_loadManually) {
+ FrameLoadRequest frameLoadRequest;
+ frameLoadRequest.resourceRequest().setHTTPMethod("GET");
+ frameLoadRequest.resourceRequest().setURL(m_url);
+ load(frameLoadRequest, false, 0);
+ }
+
+ return true;
+}
+
+void PluginView::setCurrentPluginView(PluginView* pluginView)
+{
+ s_currentPluginView = pluginView;
+}
+
+PluginView* PluginView::currentPluginView()
+{
+ return s_currentPluginView;
+}
+
+static char* createUTF8String(const String& str)
+{
+ CString cstr = str.utf8();
+ char* result = reinterpret_cast<char*>(fastMalloc(cstr.length() + 1));
+
+ strncpy(result, cstr.data(), cstr.length() + 1);
+
+ return result;
+}
+
+static bool getString(ScriptController* proxy, JSValuePtr result, String& string)
+{
+ if (!proxy || !result || result->isUndefined())
+ return false;
+ JSLock lock(false);
+
+ ExecState* exec = proxy->globalObject()->globalExec();
+ UString ustring = result->toString(exec);
+ exec->clearException();
+
+ string = ustring;
+ return true;
+}
+
+void PluginView::performRequest(PluginRequest* request)
+{
+ // don't let a plugin start any loads if it is no longer part of a document that is being
+ // displayed unless the loads are in the same frame as the plugin.
+ const String& targetFrameName = request->frameLoadRequest().frameName();
+ if (m_parentFrame->loader()->documentLoader() != m_parentFrame->loader()->activeDocumentLoader() &&
+ (targetFrameName.isNull() || m_parentFrame->tree()->find(targetFrameName) != m_parentFrame))
+ return;
+
+ KURL requestURL = request->frameLoadRequest().resourceRequest().url();
+ String jsString = scriptStringIfJavaScriptURL(requestURL);
+
+ if (jsString.isNull()) {
+ // if this is not a targeted request, create a stream for it. otherwise,
+ // just pass it off to the loader
+ if (targetFrameName.isEmpty()) {
+ RefPtr<PluginStream> stream = PluginStream::create(this, m_parentFrame, request->frameLoadRequest().resourceRequest(), request->sendNotification(), request->notifyData(), plugin()->pluginFuncs(), instance(), m_plugin->quirks());
+ m_streams.add(stream);
+ stream->start();
+ } else {
+ m_parentFrame->loader()->load(request->frameLoadRequest().resourceRequest(), targetFrameName);
+
+ // FIXME: <rdar://problem/4807469> This should be sent when the document has finished loading
+ if (request->sendNotification()) {
+ PluginView::setCurrentPluginView(this);
+ JSC::JSLock::DropAllLocks dropAllLocks(false);
+ setCallingPlugin(true);
+ m_plugin->pluginFuncs()->urlnotify(m_instance, requestURL.string().utf8().data(), NPRES_DONE, request->notifyData());
+ setCallingPlugin(false);
+ PluginView::setCurrentPluginView(0);
+ }
+ }
+ return;
+ }
+
+ // Targeted JavaScript requests are only allowed on the frame that contains the JavaScript plugin
+ // and this has been made sure in ::load.
+ ASSERT(targetFrameName.isEmpty() || m_parentFrame->tree()->find(targetFrameName) == m_parentFrame);
+
+ // Executing a script can cause the plugin view to be destroyed, so we keep a reference to the parent frame.
+ RefPtr<Frame> parentFrame = m_parentFrame;
+ JSValuePtr result = m_parentFrame->loader()->executeScript(jsString, request->shouldAllowPopups()).jsValue();
+
+ if (targetFrameName.isNull()) {
+ String resultString;
+
+ CString cstr;
+ if (getString(parentFrame->script(), result, resultString))
+ cstr = resultString.utf8();
+
+ RefPtr<PluginStream> stream = PluginStream::create(this, m_parentFrame, request->frameLoadRequest().resourceRequest(), request->sendNotification(), request->notifyData(), plugin()->pluginFuncs(), instance(), m_plugin->quirks());
+ m_streams.add(stream);
+ stream->sendJavaScriptStream(requestURL, cstr);
+ }
+}
+
+void PluginView::requestTimerFired(Timer<PluginView>* timer)
+{
+ ASSERT(timer == &m_requestTimer);
+ ASSERT(m_requests.size() > 0);
+ ASSERT(!m_isJavaScriptPaused);
+
+ PluginRequest* request = m_requests[0];
+ m_requests.remove(0);
+
+ // Schedule a new request before calling performRequest since the call to
+ // performRequest can cause the plugin view to be deleted.
+ if (m_requests.size() > 0)
+ m_requestTimer.startOneShot(0);
+
+ performRequest(request);
+ delete request;
+}
+
+void PluginView::scheduleRequest(PluginRequest* request)
+{
+ m_requests.append(request);
+
+ if (!m_isJavaScriptPaused)
+ m_requestTimer.startOneShot(0);
+}
+
+NPError PluginView::load(const FrameLoadRequest& frameLoadRequest, bool sendNotification, void* notifyData)
+{
+ ASSERT(frameLoadRequest.resourceRequest().httpMethod() == "GET" || frameLoadRequest.resourceRequest().httpMethod() == "POST");
+
+ KURL url = frameLoadRequest.resourceRequest().url();
+
+ if (url.isEmpty())
+ return NPERR_INVALID_URL;
+
+ // Don't allow requests to be made when the document loader is stopping all loaders.
+ if (m_parentFrame->loader()->documentLoader()->isStopping())
+ return NPERR_GENERIC_ERROR;
+
+ const String& targetFrameName = frameLoadRequest.frameName();
+ String jsString = scriptStringIfJavaScriptURL(url);
+
+ if (!jsString.isNull()) {
+ Settings* settings = m_parentFrame->settings();
+
+ // Return NPERR_GENERIC_ERROR if JS is disabled. This is what Mozilla does.
+ if (!settings || !settings->isJavaScriptEnabled())
+ return NPERR_GENERIC_ERROR;
+
+ // For security reasons, only allow JS requests to be made on the frame that contains the plug-in.
+ if (!targetFrameName.isNull() && m_parentFrame->tree()->find(targetFrameName) != m_parentFrame)
+ return NPERR_INVALID_PARAM;
+ } else if (!FrameLoader::canLoad(url, String(), m_parentFrame->document())) {
+ return NPERR_GENERIC_ERROR;
+ }
+
+ PluginRequest* request = new PluginRequest(frameLoadRequest, sendNotification, notifyData, arePopupsAllowed());
+ scheduleRequest(request);
+
+ return NPERR_NO_ERROR;
+}
+
+static KURL makeURL(const KURL& baseURL, const char* relativeURLString)
+{
+ String urlString = relativeURLString;
+
+ // Strip return characters.
+ urlString.replace('\n', "");
+ urlString.replace('\r', "");
+
+ return KURL(baseURL, urlString);
+}
+
+NPError PluginView::getURLNotify(const char* url, const char* target, void* notifyData)
+{
+ FrameLoadRequest frameLoadRequest;
+
+ frameLoadRequest.setFrameName(target);
+ frameLoadRequest.resourceRequest().setHTTPMethod("GET");
+ frameLoadRequest.resourceRequest().setURL(makeURL(m_baseURL, url));
+
+ return load(frameLoadRequest, true, notifyData);
+}
+
+NPError PluginView::getURL(const char* url, const char* target)
+{
+ FrameLoadRequest frameLoadRequest;
+
+ frameLoadRequest.setFrameName(target);
+ frameLoadRequest.resourceRequest().setHTTPMethod("GET");
+ frameLoadRequest.resourceRequest().setURL(makeURL(m_baseURL, url));
+
+ return load(frameLoadRequest, false, 0);
+}
+
+NPError PluginView::postURLNotify(const char* url, const char* target, uint32 len, const char* buf, NPBool file, void* notifyData)
+{
+ return handlePost(url, target, len, buf, file, notifyData, true, true);
+}
+
+NPError PluginView::postURL(const char* url, const char* target, uint32 len, const char* buf, NPBool file)
+{
+ // As documented, only allow headers to be specified via NPP_PostURL when using a file.
+ return handlePost(url, target, len, buf, file, 0, false, file);
+}
+
+NPError PluginView::newStream(NPMIMEType type, const char* target, NPStream** stream)
+{
+ notImplemented();
+ // Unsupported
+ return NPERR_GENERIC_ERROR;
+}
+
+int32 PluginView::write(NPStream* stream, int32 len, void* buffer)
+{
+ notImplemented();
+ // Unsupported
+ return -1;
+}
+
+NPError PluginView::destroyStream(NPStream* stream, NPReason reason)
+{
+ PluginStream* browserStream = static_cast<PluginStream*>(stream->ndata);
+
+ if (!stream || PluginStream::ownerForStream(stream) != m_instance)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ browserStream->cancelAndDestroyStream(reason);
+ return NPERR_NO_ERROR;
+}
+
+void PluginView::status(const char* message)
+{
+ if (Page* page = m_parentFrame->page())
+ page->chrome()->setStatusbarText(m_parentFrame, String(message));
+}
+
+NPError PluginView::setValue(NPPVariable variable, void* value)
+{
+ switch (variable) {
+ case NPPVpluginWindowBool:
+ m_isWindowed = value;
+ return NPERR_NO_ERROR;
+ case NPPVpluginTransparentBool:
+ m_isTransparent = value;
+ return NPERR_NO_ERROR;
+#if defined(XP_MACOSX)
+ case NPPVpluginDrawingModel:
+ return NPERR_NO_ERROR;
+ case NPPVpluginEventModel:
+ return NPERR_NO_ERROR;
+#endif
+ default:
+ notImplemented();
+ return NPERR_GENERIC_ERROR;
+ }
+}
+
+void PluginView::invalidateTimerFired(Timer<PluginView>* timer)
+{
+ ASSERT(timer == &m_invalidateTimer);
+
+ for (unsigned i = 0; i < m_invalidRects.size(); i++)
+ invalidateRect(m_invalidRects[i]);
+ m_invalidRects.clear();
+}
+
+
+void PluginView::pushPopupsEnabledState(bool state)
+{
+ m_popupStateStack.append(state);
+}
+
+void PluginView::popPopupsEnabledState()
+{
+ m_popupStateStack.removeLast();
+}
+
+bool PluginView::arePopupsAllowed() const
+{
+ if (!m_popupStateStack.isEmpty())
+ return m_popupStateStack.last();
+
+ return false;
+}
+
+void PluginView::setJavaScriptPaused(bool paused)
+{
+ if (m_isJavaScriptPaused == paused)
+ return;
+ m_isJavaScriptPaused = paused;
+
+ if (m_isJavaScriptPaused)
+ m_requestTimer.stop();
+ else if (!m_requests.isEmpty())
+ m_requestTimer.startOneShot(0);
+}
+
+PassRefPtr<JSC::Bindings::Instance> PluginView::bindingInstance()
+{
+#if ENABLE(NETSCAPE_PLUGIN_API)
+ NPObject* object = 0;
+
+ if (!m_plugin || !m_plugin->pluginFuncs()->getvalue)
+ return 0;
+
+ NPError npErr;
+ {
+ PluginView::setCurrentPluginView(this);
+ JSC::JSLock::DropAllLocks dropAllLocks(false);
+ setCallingPlugin(true);
+ npErr = m_plugin->pluginFuncs()->getvalue(m_instance, NPPVpluginScriptableNPObject, &object);
+ setCallingPlugin(false);
+ PluginView::setCurrentPluginView(0);
+ }
+
+ if (npErr != NPERR_NO_ERROR || !object)
+ return 0;
+
+ RefPtr<JSC::Bindings::RootObject> root = m_parentFrame->script()->createRootObject(this);
+ RefPtr<JSC::Bindings::Instance> instance = JSC::Bindings::CInstance::create(object, root.release());
+
+ _NPN_ReleaseObject(object);
+
+ return instance.release();
+#else
+ return 0;
+#endif
+}
+
+void PluginView::disconnectStream(PluginStream* stream)
+{
+ ASSERT(m_streams.contains(stream));
+
+ m_streams.remove(stream);
+}
+
+void PluginView::setParameters(const Vector<String>& paramNames, const Vector<String>& paramValues)
+{
+ ASSERT(paramNames.size() == paramValues.size());
+
+ unsigned size = paramNames.size();
+ unsigned paramCount = 0;
+
+ m_paramNames = reinterpret_cast<char**>(fastMalloc(sizeof(char*) * size));
+ m_paramValues = reinterpret_cast<char**>(fastMalloc(sizeof(char*) * size));
+
+ for (unsigned i = 0; i < size; i++) {
+ if (m_plugin->quirks().contains(PluginQuirkRemoveWindowlessVideoParam) && equalIgnoringCase(paramNames[i], "windowlessvideo"))
+ continue;
+
+ m_paramNames[paramCount] = createUTF8String(paramNames[i]);
+ m_paramValues[paramCount] = createUTF8String(paramValues[i]);
+
+ paramCount++;
+ }
+
+ m_paramCount = paramCount;
+}
+
+PluginView::PluginView(Frame* parentFrame, const IntSize& size, PluginPackage* plugin, Element* element, const KURL& url, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually)
+ : m_parentFrame(parentFrame)
+ , m_plugin(plugin)
+ , m_element(element)
+ , m_isStarted(false)
+ , m_url(url)
+ , m_baseURL(m_parentFrame->loader()->completeURL(m_parentFrame->document()->baseURL().string()))
+ , m_status(PluginStatusLoadedSuccessfully)
+ , m_requestTimer(this, &PluginView::requestTimerFired)
+ , m_invalidateTimer(this, &PluginView::invalidateTimerFired)
+ , m_popPopupsStateTimer(this, &PluginView::popPopupsStateTimerFired)
+ , m_paramNames(0)
+ , m_paramValues(0)
+ , m_instance(0)
+#if defined(XP_MACOSX)
+ , m_isWindowed(false)
+#else
+ , m_isWindowed(true)
+#endif
+ , m_isTransparent(false)
+ , m_haveInitialized(false)
+#if PLATFORM(GTK) || defined(Q_WS_X11)
+ , m_needsXEmbed(false)
+#endif
+#if PLATFORM(WIN_OS) && !PLATFORM(WX) && ENABLE(NETSCAPE_PLUGIN_API)
+ , m_pluginWndProc(0)
+ , m_lastMessage(0)
+ , m_isCallingPluginWndProc(false)
+#endif
+#if (PLATFORM(QT) && PLATFORM(WIN_OS)) || defined(XP_MACOSX)
+ , m_window(0)
+#endif
+ , m_loadManually(loadManually)
+ , m_manualStream(0)
+ , m_isJavaScriptPaused(false)
+{
+ if (!m_plugin) {
+ m_status = PluginStatusCanNotFindPlugin;
+ return;
+ }
+
+ m_instance = &m_instanceStruct;
+ m_instance->ndata = this;
+ m_instance->pdata = 0;
+
+ m_mimeType = mimeType.utf8();
+
+ setParameters(paramNames, paramValues);
+
+#ifdef XP_UNIX
+ m_npWindow.ws_info = 0;
+#endif
+
+ m_mode = m_loadManually ? NP_FULL : NP_EMBED;
+
+ resize(size);
+}
+
+void PluginView::didReceiveResponse(const ResourceResponse& response)
+{
+ if (m_status != PluginStatusLoadedSuccessfully)
+ return;
+
+ ASSERT(m_loadManually);
+ ASSERT(!m_manualStream);
+
+ m_manualStream = PluginStream::create(this, m_parentFrame, m_parentFrame->loader()->activeDocumentLoader()->request(), false, 0, plugin()->pluginFuncs(), instance(), m_plugin->quirks());
+ m_manualStream->setLoadManually(true);
+
+ m_manualStream->didReceiveResponse(0, response);
+}
+
+void PluginView::didReceiveData(const char* data, int length)
+{
+ if (m_status != PluginStatusLoadedSuccessfully)
+ return;
+
+ ASSERT(m_loadManually);
+ ASSERT(m_manualStream);
+
+ m_manualStream->didReceiveData(0, data, length);
+}
+
+void PluginView::didFinishLoading()
+{
+ if (m_status != PluginStatusLoadedSuccessfully)
+ return;
+
+ ASSERT(m_loadManually);
+ ASSERT(m_manualStream);
+
+ m_manualStream->didFinishLoading(0);
+}
+
+void PluginView::didFail(const ResourceError& error)
+{
+ if (m_status != PluginStatusLoadedSuccessfully)
+ return;
+
+ ASSERT(m_loadManually);
+ ASSERT(m_manualStream);
+
+ m_manualStream->didFail(0, error);
+}
+
+void PluginView::setCallingPlugin(bool b) const
+{
+ if (!m_plugin->quirks().contains(PluginQuirkHasModalMessageLoop))
+ return;
+
+ if (b)
+ ++s_callingPlugin;
+ else
+ --s_callingPlugin;
+
+ ASSERT(s_callingPlugin >= 0);
+}
+
+bool PluginView::isCallingPlugin()
+{
+ return s_callingPlugin > 0;
+}
+
+PluginView* PluginView::create(Frame* parentFrame, const IntSize& size, Element* element, const KURL& url, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually)
+{
+ // if we fail to find a plugin for this MIME type, findPlugin will search for
+ // a plugin by the file extension and update the MIME type, so pass a mutable String
+ String mimeTypeCopy = mimeType;
+ PluginPackage* plugin = PluginDatabase::installedPlugins()->findPlugin(url, mimeTypeCopy);
+
+ // No plugin was found, try refreshing the database and searching again
+ if (!plugin && PluginDatabase::installedPlugins()->refresh()) {
+ mimeTypeCopy = mimeType;
+ plugin = PluginDatabase::installedPlugins()->findPlugin(url, mimeTypeCopy);
+ }
+
+ return new PluginView(parentFrame, size, plugin, element, url, paramNames, paramValues, mimeTypeCopy, loadManually);
+}
+
+void PluginView::freeStringArray(char** stringArray, int length)
+{
+ if (!stringArray)
+ return;
+
+ for (int i = 0; i < length; i++)
+ fastFree(stringArray[i]);
+
+ fastFree(stringArray);
+}
+
+static inline bool startsWithBlankLine(const Vector<char>& buffer)
+{
+ return buffer.size() > 0 && buffer[0] == '\n';
+}
+
+static inline int locationAfterFirstBlankLine(const Vector<char>& buffer)
+{
+ const char* bytes = buffer.data();
+ unsigned length = buffer.size();
+
+ for (unsigned i = 0; i < length - 4; i++) {
+ // Support for Acrobat. It sends "\n\n".
+ if (bytes[i] == '\n' && bytes[i + 1] == '\n')
+ return i + 2;
+
+ // Returns the position after 2 CRLF's or 1 CRLF if it is the first line.
+ if (bytes[i] == '\r' && bytes[i + 1] == '\n') {
+ i += 2;
+ if (i == 2)
+ return i;
+ else if (bytes[i] == '\n')
+ // Support for Director. It sends "\r\n\n" (3880387).
+ return i + 1;
+ else if (bytes[i] == '\r' && bytes[i + 1] == '\n')
+ // Support for Flash. It sends "\r\n\r\n" (3758113).
+ return i + 2;
+ }
+ }
+
+ return -1;
+}
+
+static inline const char* findEOL(const char* bytes, unsigned length)
+{
+ // According to the HTTP specification EOL is defined as
+ // a CRLF pair. Unfortunately, some servers will use LF
+ // instead. Worse yet, some servers will use a combination
+ // of both (e.g. <header>CRLFLF<body>), so findEOL needs
+ // to be more forgiving. It will now accept CRLF, LF or
+ // CR.
+ //
+ // It returns NULL if EOLF is not found or it will return
+ // a pointer to the first terminating character.
+ for (unsigned i = 0; i < length; i++) {
+ if (bytes[i] == '\n')
+ return bytes + i;
+ if (bytes[i] == '\r') {
+ // Check to see if spanning buffer bounds
+ // (CRLF is across reads). If so, wait for
+ // next read.
+ if (i + 1 == length)
+ break;
+
+ return bytes + i;
+ }
+ }
+
+ return 0;
+}
+
+static inline String capitalizeRFC822HeaderFieldName(const String& name)
+{
+ bool capitalizeCharacter = true;
+ String result;
+
+ for (unsigned i = 0; i < name.length(); i++) {
+ UChar c;
+
+ if (capitalizeCharacter && name[i] >= 'a' && name[i] <= 'z')
+ c = toASCIIUpper(name[i]);
+ else if (!capitalizeCharacter && name[i] >= 'A' && name[i] <= 'Z')
+ c = toASCIILower(name[i]);
+ else
+ c = name[i];
+
+ if (name[i] == '-')
+ capitalizeCharacter = true;
+ else
+ capitalizeCharacter = false;
+
+ result.append(c);
+ }
+
+ return result;
+}
+
+static inline HTTPHeaderMap parseRFC822HeaderFields(const Vector<char>& buffer, unsigned length)
+{
+ const char* bytes = buffer.data();
+ const char* eol;
+ String lastKey;
+ HTTPHeaderMap headerFields;
+
+ // Loop ove rlines until we're past the header, or we can't find any more end-of-lines
+ while ((eol = findEOL(bytes, length))) {
+ const char* line = bytes;
+ int lineLength = eol - bytes;
+
+ // Move bytes to the character after the terminator as returned by findEOL.
+ bytes = eol + 1;
+ if ((*eol == '\r') && (*bytes == '\n'))
+ bytes++; // Safe since findEOL won't return a spanning CRLF.
+
+ length -= (bytes - line);
+ if (lineLength == 0)
+ // Blank line; we're at the end of the header
+ break;
+ else if (*line == ' ' || *line == '\t') {
+ // Continuation of the previous header
+ if (lastKey.isNull()) {
+ // malformed header; ignore it and continue
+ continue;
+ } else {
+ // Merge the continuation of the previous header
+ String currentValue = headerFields.get(lastKey);
+ String newValue(line, lineLength);
+
+ headerFields.set(lastKey, currentValue + newValue);
+ }
+ } else {
+ // Brand new header
+ const char* colon;
+ for (colon = line; *colon != ':' && colon != eol; colon++) {
+ // empty loop
+ }
+ if (colon == eol)
+ // malformed header; ignore it and continue
+ continue;
+ else {
+ lastKey = capitalizeRFC822HeaderFieldName(String(line, colon - line));
+ String value;
+
+ for (colon++; colon != eol; colon++) {
+ if (*colon != ' ' && *colon != '\t')
+ break;
+ }
+ if (colon == eol)
+ value = "";
+ else
+ value = String(colon, eol - colon);
+
+ String oldValue = headerFields.get(lastKey);
+ if (!oldValue.isNull()) {
+ String tmp = oldValue;
+ tmp += ", ";
+ tmp += value;
+ value = tmp;
+ }
+
+ headerFields.set(lastKey, value);
+ }
+ }
+ }
+
+ return headerFields;
+}
+
+NPError PluginView::handlePost(const char* url, const char* target, uint32 len, const char* buf, bool file, void* notifyData, bool sendNotification, bool allowHeaders)
+{
+ if (!url || !len || !buf)
+ return NPERR_INVALID_PARAM;
+
+ FrameLoadRequest frameLoadRequest;
+
+ HTTPHeaderMap headerFields;
+ Vector<char> buffer;
+
+ if (file) {
+ NPError readResult = handlePostReadFile(buffer, len, buf);
+ if(readResult != NPERR_NO_ERROR)
+ return readResult;
+ } else {
+ buffer.resize(len);
+ memcpy(buffer.data(), buf, len);
+ }
+
+ const char* postData = buffer.data();
+ int postDataLength = buffer.size();
+
+ if (allowHeaders) {
+ if (startsWithBlankLine(buffer)) {
+ postData++;
+ postDataLength--;
+ } else {
+ int location = locationAfterFirstBlankLine(buffer);
+ if (location != -1) {
+ // If the blank line is somewhere in the middle of the buffer, everything before is the header
+ headerFields = parseRFC822HeaderFields(buffer, location);
+ unsigned dataLength = buffer.size() - location;
+
+ // Sometimes plugins like to set Content-Length themselves when they post,
+ // but WebFoundation does not like that. So we will remove the header
+ // and instead truncate the data to the requested length.
+ String contentLength = headerFields.get("Content-Length");
+
+ if (!contentLength.isNull())
+ dataLength = min(contentLength.toInt(), (int)dataLength);
+ headerFields.remove("Content-Length");
+
+ postData += location;
+ postDataLength = dataLength;
+ }
+ }
+ }
+
+ frameLoadRequest.resourceRequest().setHTTPMethod("POST");
+ frameLoadRequest.resourceRequest().setURL(makeURL(m_baseURL, url));
+ frameLoadRequest.resourceRequest().addHTTPHeaderFields(headerFields);
+ frameLoadRequest.resourceRequest().setHTTPBody(FormData::create(postData, postDataLength));
+ frameLoadRequest.setFrameName(target);
+
+ return load(frameLoadRequest, sendNotification, notifyData);
+}
+
+void PluginView::invalidateWindowlessPluginRect(const IntRect& rect)
+{
+ if (!isVisible())
+ return;
+
+ RenderObject* renderer = m_element->renderer();
+ if (!renderer)
+ return;
+
+ IntRect dirtyRect = rect;
+ dirtyRect.move(renderer->borderLeft() + renderer->paddingLeft(), renderer->borderTop() + renderer->paddingTop());
+ renderer->repaintRectangle(dirtyRect);
+}
+
+void PluginView::paintMissingPluginIcon(GraphicsContext* context, const IntRect& rect)
+{
+ static RefPtr<Image> nullPluginImage;
+ if (!nullPluginImage)
+ nullPluginImage = Image::loadPlatformResource("nullPlugin");
+
+ IntRect imageRect(frameRect().x(), frameRect().y(), nullPluginImage->width(), nullPluginImage->height());
+
+ int xOffset = (frameRect().width() - imageRect.width()) / 2;
+ int yOffset = (frameRect().height() - imageRect.height()) / 2;
+
+ imageRect.move(xOffset, yOffset);
+
+ if (!rect.intersects(imageRect))
+ return;
+
+ context->save();
+ context->clip(windowClipRect());
+ context->drawImage(nullPluginImage.get(), imageRect.location());
+ context->restore();
+}
+
+} // namespace WebCore
diff --git a/src/3rdparty/webkit/WebCore/plugins/PluginView.h b/src/3rdparty/webkit/WebCore/plugins/PluginView.h
new file mode 100644
index 0000000000..44f2146c33
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/PluginView.h
@@ -0,0 +1,302 @@
+/*
+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Collabora Ltd. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef PluginView_H
+#define PluginView_H
+
+#include "CString.h"
+#include "FrameLoadRequest.h"
+#include "IntRect.h"
+#include "KURL.h"
+#include "PlatformString.h"
+#include "PluginStream.h"
+#include "ResourceRequest.h"
+#include "Timer.h"
+#include "Widget.h"
+#include "npruntime_internal.h"
+#include <wtf/HashMap.h>
+#include <wtf/HashSet.h>
+#include <wtf/OwnPtr.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+#include <wtf/Vector.h>
+
+#if PLATFORM(WIN_OS) && PLATFORM(QT)
+typedef struct HWND__* HWND;
+typedef HWND PlatformPluginWidget;
+#else
+typedef PlatformWidget PlatformPluginWidget;
+#endif
+
+namespace JSC {
+ namespace Bindings {
+ class Instance;
+ }
+}
+
+namespace WebCore {
+ class Element;
+ class Frame;
+ class KeyboardEvent;
+ class MouseEvent;
+ class KURL;
+#if PLATFORM(WIN_OS) && !PLATFORM(WX) && ENABLE(NETSCAPE_PLUGIN_API)
+ class PluginMessageThrottlerWin;
+#endif
+ class PluginPackage;
+ class PluginRequest;
+ class PluginStream;
+ class ResourceError;
+ class ResourceResponse;
+
+ enum PluginStatus {
+ PluginStatusCanNotFindPlugin,
+ PluginStatusCanNotLoadPlugin,
+ PluginStatusLoadedSuccessfully
+ };
+
+ class PluginRequest {
+ public:
+ PluginRequest(const FrameLoadRequest& frameLoadRequest, bool sendNotification, void* notifyData, bool shouldAllowPopups)
+ : m_frameLoadRequest(frameLoadRequest)
+ , m_notifyData(notifyData)
+ , m_sendNotification(sendNotification)
+ , m_shouldAllowPopups(shouldAllowPopups) { }
+ public:
+ const FrameLoadRequest& frameLoadRequest() const { return m_frameLoadRequest; }
+ void* notifyData() const { return m_notifyData; }
+ bool sendNotification() const { return m_sendNotification; }
+ bool shouldAllowPopups() const { return m_shouldAllowPopups; }
+ private:
+ FrameLoadRequest m_frameLoadRequest;
+ void* m_notifyData;
+ bool m_sendNotification;
+ bool m_shouldAllowPopups;
+ };
+
+ class PluginManualLoader {
+ public:
+ virtual ~PluginManualLoader() {}
+ virtual void didReceiveResponse(const ResourceResponse&) = 0;
+ virtual void didReceiveData(const char*, int) = 0;
+ virtual void didFinishLoading() = 0;
+ virtual void didFail(const ResourceError&) = 0;
+ };
+
+ class PluginView : public Widget, private PluginStreamClient, public PluginManualLoader {
+ public:
+ static PluginView* create(Frame* parentFrame, const IntSize&, Element*, const KURL&, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually);
+ virtual ~PluginView();
+
+ PluginPackage* plugin() const { return m_plugin.get(); }
+ NPP instance() const { return m_instance; }
+
+ void setNPWindowRect(const IntRect&);
+ static PluginView* currentPluginView();
+
+ PassRefPtr<JSC::Bindings::Instance> bindingInstance();
+
+ PluginStatus status() const { return m_status; }
+
+ // NPN functions
+ NPError getURLNotify(const char* url, const char* target, void* notifyData);
+ NPError getURL(const char* url, const char* target);
+ NPError postURLNotify(const char* url, const char* target, uint32 len, const char* but, NPBool file, void* notifyData);
+ NPError postURL(const char* url, const char* target, uint32 len, const char* but, NPBool file);
+ NPError newStream(NPMIMEType type, const char* target, NPStream** stream);
+ int32 write(NPStream* stream, int32 len, void* buffer);
+ NPError destroyStream(NPStream* stream, NPReason reason);
+ const char* userAgent();
+#if ENABLE(NETSCAPE_PLUGIN_API)
+ static const char* userAgentStatic();
+#endif
+ void status(const char* message);
+ NPError getValue(NPNVariable variable, void* value);
+#if ENABLE(NETSCAPE_PLUGIN_API)
+ static NPError getValueStatic(NPNVariable variable, void* value);
+#endif
+ NPError setValue(NPPVariable variable, void* value);
+ void invalidateRect(NPRect*);
+ void invalidateRegion(NPRegion);
+ void forceRedraw();
+ void pushPopupsEnabledState(bool state);
+ void popPopupsEnabledState();
+
+ virtual void invalidateRect(const IntRect&);
+
+ bool arePopupsAllowed() const;
+
+ void setJavaScriptPaused(bool);
+
+ void disconnectStream(PluginStream*);
+ void streamDidFinishLoading(PluginStream* stream) { disconnectStream(stream); }
+
+ // Widget functions
+ virtual void setFrameRect(const IntRect&);
+ virtual void frameRectsChanged();
+ virtual void setFocus();
+ virtual void show();
+ virtual void hide();
+ virtual void paint(GraphicsContext*, const IntRect&);
+
+ // This method is used by plugins on all platforms to obtain a clip rect that includes clips set by WebCore,
+ // e.g., in overflow:auto sections. The clip rects coordinates are in the containing window's coordinate space.
+ // This clip includes any clips that the widget itself sets up for its children.
+ IntRect windowClipRect() const;
+
+ virtual void handleEvent(Event*);
+ virtual void setParent(ScrollView*);
+ virtual void setParentVisible(bool);
+
+ virtual bool isPluginView() const { return true; }
+
+#if PLATFORM(WIN_OS) && !PLATFORM(WX) && ENABLE(NETSCAPE_PLUGIN_API)
+ static LRESULT CALLBACK PluginViewWndProc(HWND, UINT, WPARAM, LPARAM);
+ LRESULT wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
+ WNDPROC pluginWndProc() const { return m_pluginWndProc; }
+#endif
+
+ // Used for manual loading
+ void didReceiveResponse(const ResourceResponse&);
+ void didReceiveData(const char*, int);
+ void didFinishLoading();
+ void didFail(const ResourceError&);
+
+ static bool isCallingPlugin();
+
+ private:
+ PluginView(Frame* parentFrame, const IntSize&, PluginPackage*, Element*, const KURL&, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually);
+
+ void setParameters(const Vector<String>& paramNames, const Vector<String>& paramValues);
+ void init();
+ bool start();
+ void stop();
+ static void setCurrentPluginView(PluginView*);
+ NPError load(const FrameLoadRequest&, bool sendNotification, void* notifyData);
+ NPError handlePost(const char* url, const char* target, uint32 len, const char* buf, bool file, void* notifyData, bool sendNotification, bool allowHeaders);
+ NPError handlePostReadFile(Vector<char>& buffer, uint32 len, const char* buf);
+ static void freeStringArray(char** stringArray, int length);
+ void setCallingPlugin(bool) const;
+
+ void invalidateWindowlessPluginRect(const IntRect&);
+
+ Frame* m_parentFrame;
+ RefPtr<PluginPackage> m_plugin;
+ Element* m_element;
+ bool m_isStarted;
+ KURL m_url;
+ KURL m_baseURL;
+ PluginStatus m_status;
+ Vector<IntRect> m_invalidRects;
+
+ void performRequest(PluginRequest*);
+ void scheduleRequest(PluginRequest*);
+ void requestTimerFired(Timer<PluginView>*);
+ void invalidateTimerFired(Timer<PluginView>*);
+ Timer<PluginView> m_requestTimer;
+ Timer<PluginView> m_invalidateTimer;
+
+ void popPopupsStateTimerFired(Timer<PluginView>*);
+ Timer<PluginView> m_popPopupsStateTimer;
+
+#ifndef NP_NO_CARBON
+ bool dispatchNPEvent(NPEvent&);
+#endif
+ void updatePluginWidget();
+ void paintMissingPluginIcon(GraphicsContext*, const IntRect&);
+
+ void handleKeyboardEvent(KeyboardEvent*);
+ void handleMouseEvent(MouseEvent*);
+
+ int m_mode;
+ int m_paramCount;
+ char** m_paramNames;
+ char** m_paramValues;
+
+ CString m_mimeType;
+ CString m_userAgent;
+
+ NPP m_instance;
+ NPP_t m_instanceStruct;
+ NPWindow m_npWindow;
+
+ Vector<bool, 4> m_popupStateStack;
+
+ HashSet<RefPtr<PluginStream> > m_streams;
+ Vector<PluginRequest*> m_requests;
+
+ bool m_isWindowed;
+ bool m_isTransparent;
+ bool m_haveInitialized;
+
+#if PLATFORM(GTK) || defined(Q_WS_X11)
+ bool m_needsXEmbed;
+#endif
+
+#if PLATFORM(WIN_OS) && !PLATFORM(WX) && ENABLE(NETSCAPE_PLUGIN_API)
+ OwnPtr<PluginMessageThrottlerWin> m_messageThrottler;
+ WNDPROC m_pluginWndProc;
+ unsigned m_lastMessage;
+ bool m_isCallingPluginWndProc;
+#endif
+
+#if (PLATFORM(QT) && PLATFORM(WIN_OS)) || defined(XP_MACOSX)
+ // On Mac OSX and Qt/Windows the plugin does not have its own native widget,
+ // but is using the containing window as its reference for positioning/painting.
+ PlatformPluginWidget m_window;
+public:
+ PlatformPluginWidget platformPluginWidget() const { return m_window; }
+ void setPlatformPluginWidget(PlatformPluginWidget widget) { m_window = widget; }
+#else
+public:
+ PlatformPluginWidget platformPluginWidget() const { return platformWidget(); }
+#endif
+
+private:
+
+#if defined(XP_MACOSX)
+ NP_CGContext m_npCgContext;
+ OwnPtr<Timer<PluginView> > m_nullEventTimer;
+
+ void setNPWindowIfNeeded();
+ void nullEventTimerFired(Timer<PluginView>*);
+ Point globalMousePosForPlugin() const;
+#endif
+
+ IntRect m_clipRect; // The clip rect to apply to a windowed plug-in
+ IntRect m_windowRect; // Our window rect.
+
+ bool m_loadManually;
+ RefPtr<PluginStream> m_manualStream;
+
+ bool m_isJavaScriptPaused;
+
+ static PluginView* s_currentPluginView;
+ };
+
+} // namespace WebCore
+
+#endif
diff --git a/src/3rdparty/webkit/WebCore/plugins/mac/PluginDataMac.mm b/src/3rdparty/webkit/WebCore/plugins/mac/PluginDataMac.mm
new file mode 100644
index 0000000000..ec76c37224
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/mac/PluginDataMac.mm
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * 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.
+ */
+
+#import "config.h"
+#import "PluginData.h"
+
+#import "BlockExceptions.h"
+#import "Logging.h"
+#import "WebCoreViewFactory.h"
+
+namespace WebCore {
+
+void PluginData::initPlugins()
+{
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+ NSArray* plugins = [[WebCoreViewFactory sharedFactory] pluginsInfo];
+ for (unsigned int i = 0; i < [plugins count]; ++i) {
+ PluginInfo* pluginInfo = new PluginInfo;
+
+ id <WebCorePluginInfo> plugin = [plugins objectAtIndex:i];
+
+ pluginInfo->name = [plugin name];
+ pluginInfo->file = [plugin filename];
+ pluginInfo->desc = [plugin pluginDescription];
+
+ NSEnumerator* MIMETypeEnumerator = [plugin MIMETypeEnumerator];
+ while (NSString* MIME = [MIMETypeEnumerator nextObject]) {
+ MimeClassInfo* mime = new MimeClassInfo;
+ pluginInfo->mimes.append(mime);
+ mime->type = String(MIME).lower();
+ mime->suffixes = [[plugin extensionsForMIMEType:MIME] componentsJoinedByString:@","];
+ mime->desc = [plugin descriptionForMIMEType:MIME];
+ mime->plugin = pluginInfo;
+ }
+
+ m_plugins.append(pluginInfo);
+ }
+
+ END_BLOCK_OBJC_EXCEPTIONS;
+
+ return;
+}
+
+void PluginData::refresh()
+{
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
+ [[WebCoreViewFactory sharedFactory] refreshPlugins];
+ END_BLOCK_OBJC_EXCEPTIONS;
+}
+
+}
+
diff --git a/src/3rdparty/webkit/WebCore/plugins/mac/PluginPackageMac.cpp b/src/3rdparty/webkit/WebCore/plugins/mac/PluginPackageMac.cpp
new file mode 100644
index 0000000000..0af94b03df
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/mac/PluginPackageMac.cpp
@@ -0,0 +1,378 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Collabora Ltd. All rights reserved.
+ * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * 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.
+ */
+
+#ifndef __LP64__
+
+#include "config.h"
+#include "PluginPackage.h"
+
+#include <wtf/RetainPtr.h>
+#include "CString.h"
+#include "MIMETypeRegistry.h"
+#include "NotImplemented.h"
+#include "npruntime_impl.h"
+#include "PluginDatabase.h"
+#include "PluginDebug.h"
+#include "WebCoreNSStringExtras.h"
+
+#include <CoreFoundation/CoreFoundation.h>
+
+#define PluginNameOrDescriptionStringNumber 126
+#define MIMEDescriptionStringNumber 127
+#define MIMEListStringStringNumber 128
+
+namespace WebCore {
+
+void PluginPackage::determineQuirks(const String& mimeType)
+{
+ if (MIMETypeRegistry::isJavaAppletMIMEType(mimeType)) {
+ // Because a single process cannot create multiple VMs, and we cannot reliably unload a
+ // Java VM, we cannot unload the Java plugin, or we'll lose reference to our only VM
+ m_quirks.add(PluginQuirkDontUnloadPlugin);
+
+ // Setting the window region to an empty region causes bad scrolling repaint problems
+ // with the Java plug-in.
+ m_quirks.add(PluginQuirkDontClipToZeroRectWhenScrolling);
+ }
+
+ if (mimeType == "application/x-shockwave-flash") {
+ // The flash plugin only requests windowless plugins if we return a mozilla user agent
+ m_quirks.add(PluginQuirkWantsMozillaUserAgent);
+ m_quirks.add(PluginQuirkThrottleInvalidate);
+ m_quirks.add(PluginQuirkThrottleWMUserPlusOneMessages);
+ m_quirks.add(PluginQuirkFlashURLNotifyBug);
+ }
+
+}
+
+typedef void (*BP_CreatePluginMIMETypesPreferencesFuncPtr)(void);
+
+static WTF::RetainPtr<CFDictionaryRef> readPListFile(CFStringRef fileName, bool createFile, CFBundleRef bundle)
+{
+ if (createFile) {
+ BP_CreatePluginMIMETypesPreferencesFuncPtr funcPtr =
+ (BP_CreatePluginMIMETypesPreferencesFuncPtr)CFBundleGetFunctionPointerForName(bundle, CFSTR("BP_CreatePluginMIMETypesPreferences"));
+ if (funcPtr)
+ funcPtr();
+ }
+
+ WTF::RetainPtr<CFDictionaryRef> map;
+ WTF::RetainPtr<CFURLRef> url =
+ CFURLCreateWithFileSystemPath(kCFAllocatorDefault, fileName, kCFURLPOSIXPathStyle, false);
+
+ CFDataRef resource = 0;
+ SInt32 code;
+ if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, url.get(), &resource, 0, 0, &code))
+ return map;
+
+ WTF::RetainPtr<CFPropertyListRef> propertyList =
+ CFPropertyListCreateFromXMLData(kCFAllocatorDefault, resource, kCFPropertyListImmutable, 0);
+
+ CFRelease(resource);
+
+ if (!propertyList)
+ return map;
+
+ if (CFGetTypeID(propertyList.get()) != CFDictionaryGetTypeID())
+ return map;
+
+ map = static_cast<CFDictionaryRef>(static_cast<CFPropertyListRef>(propertyList.get()));
+ return map;
+}
+
+static Vector<String> stringListFromResourceId(SInt16 id)
+{
+ Vector<String> list;
+
+ Handle handle = Get1Resource('STR#', id);
+ if (!handle)
+ return list;
+
+ CFStringEncoding encoding = stringEncodingForResource(handle);
+
+ unsigned char* p = (unsigned char*)*handle;
+ if (!p)
+ return list;
+
+ SInt16 count = *(SInt16*)p;
+ p += sizeof(SInt16);
+
+ for (SInt16 i = 0; i < count; ++i) {
+ unsigned char length = *p;
+ WTF::RetainPtr<CFStringRef> str = CFStringCreateWithPascalString(0, p, encoding);
+ list.append(str.get());
+ p += 1 + length;
+ }
+
+ return list;
+}
+
+bool PluginPackage::fetchInfo()
+{
+ if (!load())
+ return false;
+
+ WTF::RetainPtr<CFDictionaryRef> mimeDict;
+
+ WTF::RetainPtr<CFTypeRef> mimeTypesFileName = CFBundleGetValueForInfoDictionaryKey(m_module, CFSTR("WebPluginMIMETypesFilename"));
+ if (mimeTypesFileName && CFGetTypeID(mimeTypesFileName.get()) == CFStringGetTypeID()) {
+
+ WTF::RetainPtr<CFStringRef> fileName = (CFStringRef)mimeTypesFileName.get();
+ WTF::RetainPtr<CFStringRef> homeDir = homeDirectoryPath().createCFString();
+ WTF::RetainPtr<CFStringRef> path = CFStringCreateWithFormat(0, 0, CFSTR("%@/Library/Preferences/%@"), homeDir.get(), fileName.get());
+
+ WTF::RetainPtr<CFDictionaryRef> plist = readPListFile(path.get(), /*createFile*/ false, m_module);
+ if (plist) {
+ // If the plist isn't localized, have the plug-in recreate it in the preferred language.
+ WTF::RetainPtr<CFStringRef> localizationName =
+ (CFStringRef)CFDictionaryGetValue(plist.get(), CFSTR("WebPluginLocalizationName"));
+ CFLocaleRef locale = CFLocaleCopyCurrent();
+ if (localizationName != CFLocaleGetIdentifier(locale))
+ plist = readPListFile(path.get(), /*createFile*/ true, m_module);
+
+ CFRelease(locale);
+ } else {
+ // Plist doesn't exist, ask the plug-in to create it.
+ plist = readPListFile(path.get(), /*createFile*/ true, m_module);
+ }
+
+ mimeDict = (CFDictionaryRef)CFDictionaryGetValue(plist.get(), CFSTR("WebPluginMIMETypes"));
+ }
+
+ if (!mimeDict)
+ mimeDict = (CFDictionaryRef)CFBundleGetValueForInfoDictionaryKey(m_module, CFSTR("WebPluginMIMETypes"));
+
+ if (mimeDict) {
+ CFIndex propCount = CFDictionaryGetCount(mimeDict.get());
+ Vector<const void*, 128> keys(propCount);
+ Vector<const void*, 128> values(propCount);
+ CFDictionaryGetKeysAndValues(mimeDict.get(), keys.data(), values.data());
+ for (int i = 0; i < propCount; ++i) {
+ String mimeType = (CFStringRef)keys[i];
+ mimeType = mimeType.lower();
+
+ WTF::RetainPtr<CFDictionaryRef> extensionsDict = (CFDictionaryRef)values[i];
+
+ WTF:RetainPtr<CFNumberRef> enabled = (CFNumberRef)CFDictionaryGetValue(extensionsDict.get(), CFSTR("WebPluginTypeEnabled"));
+ if (enabled) {
+ int enabledValue = 0;
+ if (CFNumberGetValue(enabled.get(), kCFNumberIntType, &enabledValue) && enabledValue == 0)
+ continue;
+ }
+
+ Vector<String> mimeExtensions;
+ WTF::RetainPtr<CFArrayRef> extensions = (CFArrayRef)CFDictionaryGetValue(extensionsDict.get(), CFSTR("WebPluginExtensions"));
+ if (extensions) {
+ CFIndex extensionCount = CFArrayGetCount(extensions.get());
+ for (CFIndex i = 0; i < extensionCount; ++i) {
+ String extension =(CFStringRef)CFArrayGetValueAtIndex(extensions.get(), i);
+ extension = extension.lower();
+ mimeExtensions.append(extension);
+ }
+ }
+ m_mimeToExtensions.set(mimeType, mimeExtensions);
+
+ String description = (CFStringRef)CFDictionaryGetValue(extensionsDict.get(), CFSTR("WebPluginTypeDescription"));
+ m_mimeToDescriptions.set(mimeType, description);
+ }
+
+ m_name = (CFStringRef)CFBundleGetValueForInfoDictionaryKey(m_module, CFSTR("WebPluginName"));
+ m_description = (CFStringRef)CFBundleGetValueForInfoDictionaryKey(m_module, CFSTR("WebPluginDescription"));
+
+ } else {
+ int resFile = CFBundleOpenBundleResourceMap(m_module);
+
+ UseResFile(resFile);
+
+ Vector<String> mimes = stringListFromResourceId(MIMEListStringStringNumber);
+
+ if (mimes.size() % 2 != 0)
+ return false;
+
+ Vector<String> descriptions = stringListFromResourceId(MIMEDescriptionStringNumber);
+ if (descriptions.size() != mimes.size() / 2)
+ return false;
+
+ for (size_t i = 0; i < mimes.size(); i += 2) {
+ String mime = mimes[i].lower();
+ Vector<String> extensions;
+ mimes[i + 1].lower().split(UChar(','), extensions);
+
+ m_mimeToExtensions.set(mime, extensions);
+
+ m_mimeToDescriptions.set(mime, descriptions[i / 2]);
+ }
+
+ Vector<String> names = stringListFromResourceId(PluginNameOrDescriptionStringNumber);
+ if (names.size() == 2) {
+ m_description = names[0];
+ m_name = names[1];
+ }
+
+ CFBundleCloseBundleResourceMap(m_module, resFile);
+ }
+
+ LOG(Plugin, "PluginPackage::fetchInfo(): Found plug-in '%s'", m_name.utf8().data());
+ if (isPluginBlacklisted()) {
+ LOG(Plugin, "\tPlug-in is blacklisted!");
+ return false;
+ }
+
+ return true;
+}
+
+bool PluginPackage::isPluginBlacklisted()
+{
+ if (name() == "Silverlight Plug-In" || name().startsWith("QuickTime Plug-in"))
+ return true;
+
+ return false;
+}
+
+bool PluginPackage::load()
+{
+ if (m_isLoaded) {
+ m_loadCount++;
+ return true;
+ }
+
+ WTF::RetainPtr<CFStringRef> path(AdoptCF, m_path.createCFString());
+ WTF::RetainPtr<CFURLRef> url(AdoptCF, CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path.get(),
+ kCFURLPOSIXPathStyle, false));
+ m_module = CFBundleCreate(NULL, url.get());
+ if (!m_module || !CFBundleLoadExecutable(m_module)) {
+ LOG(Plugin, "%s not loaded", m_path.utf8().data());
+ return false;
+ }
+
+ m_isLoaded = true;
+
+ NP_GetEntryPointsFuncPtr NP_GetEntryPoints = 0;
+ NP_InitializeFuncPtr NP_Initialize;
+ NPError npErr;
+
+ NP_Initialize = (NP_InitializeFuncPtr)CFBundleGetFunctionPointerForName(m_module, CFSTR("NP_Initialize"));
+ NP_GetEntryPoints = (NP_GetEntryPointsFuncPtr)CFBundleGetFunctionPointerForName(m_module, CFSTR("NP_GetEntryPoints"));
+ m_NPP_Shutdown = (NPP_ShutdownProcPtr)CFBundleGetFunctionPointerForName(m_module, CFSTR("NP_Shutdown"));
+
+ if (!NP_Initialize || !NP_GetEntryPoints || !m_NPP_Shutdown)
+ goto abort;
+
+ memset(&m_pluginFuncs, 0, sizeof(m_pluginFuncs));
+ m_pluginFuncs.size = sizeof(m_pluginFuncs);
+
+ m_browserFuncs.size = sizeof(m_browserFuncs);
+ m_browserFuncs.version = NP_VERSION_MINOR;
+ m_browserFuncs.geturl = NPN_GetURL;
+ m_browserFuncs.posturl = NPN_PostURL;
+ m_browserFuncs.requestread = NPN_RequestRead;
+ m_browserFuncs.newstream = NPN_NewStream;
+ m_browserFuncs.write = NPN_Write;
+ m_browserFuncs.destroystream = NPN_DestroyStream;
+ m_browserFuncs.status = NPN_Status;
+ m_browserFuncs.uagent = NPN_UserAgent;
+ m_browserFuncs.memalloc = NPN_MemAlloc;
+ m_browserFuncs.memfree = NPN_MemFree;
+ m_browserFuncs.memflush = NPN_MemFlush;
+ m_browserFuncs.reloadplugins = NPN_ReloadPlugins;
+ m_browserFuncs.geturlnotify = NPN_GetURLNotify;
+ m_browserFuncs.posturlnotify = NPN_PostURLNotify;
+ m_browserFuncs.getvalue = NPN_GetValue;
+ m_browserFuncs.setvalue = NPN_SetValue;
+ m_browserFuncs.invalidaterect = NPN_InvalidateRect;
+ m_browserFuncs.invalidateregion = NPN_InvalidateRegion;
+ m_browserFuncs.forceredraw = NPN_ForceRedraw;
+ m_browserFuncs.getJavaEnv = NPN_GetJavaEnv;
+ m_browserFuncs.getJavaPeer = NPN_GetJavaPeer;
+ m_browserFuncs.pushpopupsenabledstate = NPN_PushPopupsEnabledState;
+ m_browserFuncs.poppopupsenabledstate = NPN_PopPopupsEnabledState;
+
+ m_browserFuncs.releasevariantvalue = _NPN_ReleaseVariantValue;
+ m_browserFuncs.getstringidentifier = _NPN_GetStringIdentifier;
+ m_browserFuncs.getstringidentifiers = _NPN_GetStringIdentifiers;
+ m_browserFuncs.getintidentifier = _NPN_GetIntIdentifier;
+ m_browserFuncs.identifierisstring = _NPN_IdentifierIsString;
+ m_browserFuncs.utf8fromidentifier = _NPN_UTF8FromIdentifier;
+ m_browserFuncs.createobject = _NPN_CreateObject;
+ m_browserFuncs.retainobject = _NPN_RetainObject;
+ m_browserFuncs.releaseobject = _NPN_ReleaseObject;
+ m_browserFuncs.invoke = _NPN_Invoke;
+ m_browserFuncs.invokeDefault = _NPN_InvokeDefault;
+ m_browserFuncs.evaluate = _NPN_Evaluate;
+ m_browserFuncs.getproperty = _NPN_GetProperty;
+ m_browserFuncs.setproperty = _NPN_SetProperty;
+ m_browserFuncs.removeproperty = _NPN_RemoveProperty;
+ m_browserFuncs.hasproperty = _NPN_HasMethod;
+ m_browserFuncs.hasmethod = _NPN_HasProperty;
+ m_browserFuncs.setexception = _NPN_SetException;
+ m_browserFuncs.enumerate = _NPN_Enumerate;
+
+ npErr = NP_Initialize(&m_browserFuncs);
+ LOG_NPERROR(npErr);
+ if (npErr != NPERR_NO_ERROR)
+ goto abort;
+
+ npErr = NP_GetEntryPoints(&m_pluginFuncs);
+ LOG_NPERROR(npErr);
+ if (npErr != NPERR_NO_ERROR)
+ goto abort;
+
+ m_loadCount++;
+ return true;
+
+abort:
+ unloadWithoutShutdown();
+ return false;
+}
+
+unsigned PluginPackage::hash() const
+{
+ unsigned hashCodes[2] = {
+ m_path.impl()->hash(),
+ m_lastModified
+ };
+
+ return StringImpl::computeHash(reinterpret_cast<UChar*>(hashCodes), 2 * sizeof(unsigned) / sizeof(UChar));
+}
+
+bool PluginPackage::equal(const PluginPackage& a, const PluginPackage& b)
+{
+ return a.m_description == b.m_description;
+}
+
+int PluginPackage::compareFileVersion(const PlatformModuleVersion& compareVersion) const
+{
+ // return -1, 0, or 1 if plug-in version is less than, equal to, or greater than
+ // the passed version
+ if (m_moduleVersion != compareVersion)
+ return m_moduleVersion > compareVersion ? 1 : -1;
+ return 0;
+}
+
+} // namespace WebCore
+
+#endif // !__LP64__
diff --git a/src/3rdparty/webkit/WebCore/plugins/mac/PluginViewMac.cpp b/src/3rdparty/webkit/WebCore/plugins/mac/PluginViewMac.cpp
new file mode 100644
index 0000000000..e0e178bff2
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/mac/PluginViewMac.cpp
@@ -0,0 +1,704 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Collabora Ltd. All rights reserved.
+ * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * 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.
+ */
+
+#ifndef __LP64__
+
+#include "config.h"
+#include "PluginView.h"
+
+#include <runtime/JSLock.h>
+#include <runtime/JSValue.h>
+#include "wtf/RetainPtr.h"
+
+#include "Document.h"
+#include "DocumentLoader.h"
+#include "Element.h"
+#include "EventNames.h"
+#include "FocusController.h"
+#include "FrameLoader.h"
+#include "FrameLoadRequest.h"
+#include "FrameTree.h"
+#include "Frame.h"
+#include "FrameView.h"
+#include "GraphicsContext.h"
+#include "HTMLNames.h"
+#include "HTMLPlugInElement.h"
+#include "Image.h"
+#include "JSDOMBinding.h"
+#include "KeyboardEvent.h"
+#include "MouseEvent.h"
+#include "NotImplemented.h"
+#include "npruntime_impl.h"
+#include "Page.h"
+#include "PlatformMouseEvent.h"
+#include "PlatformKeyboardEvent.h"
+#include "PluginDebug.h"
+#include "PluginPackage.h"
+#include "PluginMainThreadScheduler.h"
+#include "RenderLayer.h"
+#include "runtime.h"
+#include "runtime_root.h"
+#include "ScriptController.h"
+#include "Settings.h"
+
+using JSC::ExecState;
+using JSC::Interpreter;
+using JSC::JSLock;
+using JSC::JSObject;
+using JSC::JSValue;
+using JSC::UString;
+
+#if PLATFORM(QT)
+#include <QWidget>
+#include <QKeyEvent>
+QT_BEGIN_NAMESPACE
+extern Q_GUI_EXPORT OSWindowRef qt_mac_window_for(const QWidget *w);
+QT_END_NAMESPACE
+#endif
+
+using std::min;
+
+using namespace WTF;
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+static int modifiersForEvent(UIEventWithKeyState *event);
+
+static inline WindowRef nativeWindowFor(PlatformWidget widget)
+{
+#if PLATFORM(QT)
+ if (widget)
+ return static_cast<WindowRef>(qt_mac_window_for(widget));
+#endif
+ return 0;
+}
+
+static inline CGContextRef cgHandleFor(PlatformWidget widget)
+{
+#if PLATFORM(QT)
+ if (widget)
+ return (CGContextRef)widget->macCGHandle();
+#endif
+ return 0;
+}
+
+static inline IntPoint topLevelOffsetFor(PlatformWidget widget)
+{
+#if PLATFORM(QT)
+ if (widget) {
+ PlatformWidget topLevel = widget->window();
+ return widget->mapTo(topLevel, QPoint(0, 0)) + topLevel->geometry().topLeft() - topLevel->pos();
+ }
+#endif
+ return IntPoint();
+}
+
+// --------------- Lifetime management -----------------
+
+void PluginView::init()
+{
+ if (m_haveInitialized)
+ return;
+ m_haveInitialized = true;
+
+ if (!m_plugin) {
+ ASSERT(m_status == PluginStatusCanNotFindPlugin);
+ return;
+ }
+
+ if (!m_plugin->load()) {
+ m_plugin = 0;
+ m_status = PluginStatusCanNotLoadPlugin;
+ return;
+ }
+
+ if (!start()) {
+ m_status = PluginStatusCanNotLoadPlugin;
+ return;
+ }
+
+ setPlatformPluginWidget(m_parentFrame->view()->hostWindow()->platformWindow());
+
+ m_npCgContext.window = 0;
+ m_npCgContext.context = 0;
+ m_npWindow.window = (void*)&m_npCgContext;
+ m_npWindow.type = NPWindowTypeWindow;
+ m_npWindow.x = 0;
+ m_npWindow.y = 0;
+ m_npWindow.width = 0;
+ m_npWindow.height = 0;
+ m_npWindow.clipRect.left = 0;
+ m_npWindow.clipRect.top = 0;
+ m_npWindow.clipRect.right = 0;
+ m_npWindow.clipRect.bottom = 0;
+
+ show();
+
+ m_status = PluginStatusLoadedSuccessfully;
+
+ // TODO: Implement null timer throttling depending on plugin activation
+ m_nullEventTimer.set(new Timer<PluginView>(this, &PluginView::nullEventTimerFired));
+ m_nullEventTimer->startRepeating(0.02);
+}
+
+PluginView::~PluginView()
+{
+ stop();
+
+ deleteAllValues(m_requests);
+
+ freeStringArray(m_paramNames, m_paramCount);
+ freeStringArray(m_paramValues, m_paramCount);
+
+ m_parentFrame->script()->cleanupScriptObjectsForPlugin(this);
+
+ if (m_plugin && !(m_plugin->quirks().contains(PluginQuirkDontUnloadPlugin)))
+ m_plugin->unload();
+
+ m_window = 0;
+}
+
+void PluginView::stop()
+{
+ if (!m_isStarted)
+ return;
+
+ HashSet<RefPtr<PluginStream> > streams = m_streams;
+ HashSet<RefPtr<PluginStream> >::iterator end = streams.end();
+ for (HashSet<RefPtr<PluginStream> >::iterator it = streams.begin(); it != end; ++it) {
+ (*it)->stop();
+ disconnectStream((*it).get());
+ }
+
+ ASSERT(m_streams.isEmpty());
+
+ m_isStarted = false;
+
+ JSC::JSLock::DropAllLocks dropAllLocks(false);
+
+ PluginMainThreadScheduler::scheduler().unregisterPlugin(m_instance);
+
+ // Destroy the plugin
+ PluginView::setCurrentPluginView(this);
+ setCallingPlugin(true);
+ m_plugin->pluginFuncs()->destroy(m_instance, 0);
+ setCallingPlugin(false);
+ PluginView::setCurrentPluginView(0);
+
+ m_instance->pdata = 0;
+}
+
+NPError PluginView::getValueStatic(NPNVariable variable, void* value)
+{
+ LOG(Plugin, "PluginView::getValueStatic(%d)", variable);
+
+ switch (variable) {
+ case NPNVToolkit:
+ *((uint32 *)value) = 0;
+ return NPERR_NO_ERROR;
+
+ case NPNVjavascriptEnabledBool:
+ *((uint32 *)value) = true;
+ return NPERR_NO_ERROR;
+
+ default:
+ return NPERR_GENERIC_ERROR;
+ }
+}
+
+NPError PluginView::getValue(NPNVariable variable, void* value)
+{
+ LOG(Plugin, "PluginView::getValue(%d)", variable);
+
+ switch (variable) {
+ case NPNVWindowNPObject: {
+ if (m_isJavaScriptPaused)
+ return NPERR_GENERIC_ERROR;
+
+ NPObject* windowScriptObject = m_parentFrame->script()->windowScriptNPObject();
+
+ // Return value is expected to be retained, as described in
+ // <http://www.mozilla.org/projects/plugin/npruntime.html>
+ if (windowScriptObject)
+ _NPN_RetainObject(windowScriptObject);
+
+ void** v = (void**)value;
+ *v = windowScriptObject;
+
+ return NPERR_NO_ERROR;
+ }
+
+ case NPNVPluginElementNPObject: {
+ if (m_isJavaScriptPaused)
+ return NPERR_GENERIC_ERROR;
+
+ 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 in
+ // <http://www.mozilla.org/projects/plugin/npruntime.html>
+ if (pluginScriptObject)
+ _NPN_RetainObject(pluginScriptObject);
+
+ void** v = (void**)value;
+ *v = pluginScriptObject;
+
+ return NPERR_NO_ERROR;
+ }
+
+ case NPNVsupportsCoreGraphicsBool:
+ *((uint32 *)value) = true;
+ return NPERR_NO_ERROR;
+
+ default:
+ return getValueStatic(variable, value);
+ }
+
+}
+void PluginView::setParent(ScrollView* parent)
+{
+ Widget::setParent(parent);
+
+ if (parent)
+ init();
+}
+
+// -------------- Geometry and painting ----------------
+
+void PluginView::show()
+{
+ LOG(Plugin, "PluginView::show()");
+
+ setSelfVisible(true);
+
+ if (isParentVisible() && platformPluginWidget())
+ platformPluginWidget()->setVisible(true);
+
+ Widget::show();
+}
+
+void PluginView::hide()
+{
+ LOG(Plugin, "PluginView::hide()");
+
+ setSelfVisible(false);
+
+ if (isParentVisible() && platformPluginWidget())
+ platformPluginWidget()->setVisible(false);
+
+ Widget::hide();
+}
+
+void PluginView::setFocus()
+{
+ LOG(Plugin, "PluginView::setFocus()");
+
+ if (platformPluginWidget())
+ platformPluginWidget()->setFocus(Qt::OtherFocusReason);
+ else
+ Widget::setFocus();
+
+ // TODO: Also handle and pass on blur events (focus lost)
+
+ EventRecord record;
+ record.what = getFocusEvent;
+ record.message = 0;
+ record.when = TickCount();
+ record.where = globalMousePosForPlugin();
+ record.modifiers = GetCurrentKeyModifiers();
+
+ if (!dispatchNPEvent(record))
+ LOG(Events, "PluginView::setFocus(): Get-focus event not accepted");
+}
+
+void PluginView::setParentVisible(bool visible)
+{
+ if (isParentVisible() == visible)
+ return;
+
+ Widget::setParentVisible(visible);
+
+ if (isSelfVisible() && platformPluginWidget())
+ platformPluginWidget()->setVisible(visible);
+}
+
+void PluginView::setNPWindowRect(const IntRect&)
+{
+ setNPWindowIfNeeded();
+}
+
+void PluginView::setNPWindowIfNeeded()
+{
+ if (!m_isStarted || !parent() || !m_plugin->pluginFuncs()->setwindow)
+ return;
+
+ CGContextRef newContextRef = cgHandleFor(platformPluginWidget());
+ if (!newContextRef)
+ return;
+
+ WindowRef newWindowRef = nativeWindowFor(platformPluginWidget());
+ if (!newWindowRef)
+ return;
+
+ m_npWindow.window = (void*)&m_npCgContext;
+ m_npCgContext.window = newWindowRef;
+ m_npCgContext.context = newContextRef;
+
+ m_npWindow.x = m_windowRect.x();
+ m_npWindow.y = m_windowRect.y();
+ m_npWindow.width = m_windowRect.width();
+ m_npWindow.height = m_windowRect.height();
+
+ // TODO: (also clip against scrollbars, etc.)
+ m_npWindow.clipRect.left = 0;
+ m_npWindow.clipRect.top = 0;
+ m_npWindow.clipRect.right = m_windowRect.width();
+ m_npWindow.clipRect.bottom = m_windowRect.height();
+
+ PluginView::setCurrentPluginView(this);
+ JSC::JSLock::DropAllLocks dropAllLocks(false);
+ setCallingPlugin(true);
+ m_plugin->pluginFuncs()->setwindow(m_instance, &m_npWindow);
+ setCallingPlugin(false);
+ PluginView::setCurrentPluginView(0);
+}
+
+void PluginView::updatePluginWidget()
+{
+ if (!parent())
+ return;
+
+ ASSERT(parent()->isFrameView());
+ FrameView* frameView = static_cast<FrameView*>(parent());
+
+ IntRect oldWindowRect = m_windowRect;
+ IntRect oldClipRect = m_clipRect;
+
+ m_windowRect = IntRect(frameView->contentsToWindow(frameRect().location()), frameRect().size());
+ m_clipRect = windowClipRect();
+ m_clipRect.move(-m_windowRect.x(), -m_windowRect.y());
+
+ if (platformPluginWidget() && (m_windowRect != oldWindowRect || m_clipRect != oldClipRect))
+ setNPWindowIfNeeded();
+}
+
+void PluginView::paint(GraphicsContext* context, const IntRect& rect)
+{
+ if (!m_isStarted) {
+ paintMissingPluginIcon(context, rect);
+ return;
+ }
+
+ if (context->paintingDisabled())
+ return;
+
+ setNPWindowIfNeeded();
+
+ EventRecord event;
+ event.what = updateEvt;
+ event.message = (long unsigned int)m_npCgContext.window;
+ event.when = TickCount();
+ event.where.h = 0;
+ event.where.v = 0;
+ event.modifiers = GetCurrentKeyModifiers();
+
+ CGContextRef cg = m_npCgContext.context;
+ CGContextSaveGState(cg);
+ IntPoint offset = frameRect().location();
+ CGContextTranslateCTM(cg, offset.x(), offset.y());
+
+ if (!dispatchNPEvent(event))
+ LOG(Events, "PluginView::paint(): Paint event not accepted");
+
+ CGContextRestoreGState(cg);
+}
+
+void PluginView::invalidateRect(const IntRect& rect)
+{
+ if (platformPluginWidget())
+ platformPluginWidget()->update(convertToContainingWindow(rect));
+}
+
+void PluginView::invalidateRect(NPRect* rect)
+{
+ // TODO: optimize
+ invalidate();
+}
+
+void PluginView::invalidateRegion(NPRegion region)
+{
+ // TODO: optimize
+ invalidate();
+}
+
+void PluginView::forceRedraw()
+{
+ notImplemented();
+}
+
+
+// ----------------- Event handling --------------------
+
+void PluginView::handleMouseEvent(MouseEvent* event)
+{
+ EventRecord record;
+
+ if (event->type() == eventNames().mousemoveEvent) {
+ // Mouse movement is handled by null timer events
+ return;
+ } else if (event->type() == eventNames().mouseoverEvent) {
+ record.what = adjustCursorEvent;
+ } else if (event->type() == eventNames().mouseoutEvent) {
+ record.what = adjustCursorEvent;
+ } else if (event->type() == eventNames().mousedownEvent) {
+ record.what = mouseDown;
+ // The plugin needs focus to receive keyboard events
+ if (Page* page = m_parentFrame->page())
+ page->focusController()->setFocusedFrame(m_parentFrame);
+ m_parentFrame->document()->setFocusedNode(m_element);
+ } else if (event->type() == eventNames().mouseupEvent) {
+ record.what = mouseUp;
+ } else {
+ return;
+ }
+
+ record.where = globalMousePosForPlugin();
+ record.modifiers = modifiersForEvent(event);
+
+ if (!event->buttonDown())
+ record.modifiers |= btnState;
+
+ if (event->button() == 2)
+ record.modifiers |= controlKey;
+
+ if (!dispatchNPEvent(record)) {
+ if (record.what == adjustCursorEvent)
+ return; // Signals that the plugin wants a normal cursor
+
+ LOG(Events, "PluginView::handleMouseEvent(): Mouse event type %d at %d,%d not accepted",
+ record.what, record.where.h, record.where.v);
+ } else {
+ event->setDefaultHandled();
+ }
+}
+
+void PluginView::handleKeyboardEvent(KeyboardEvent* event)
+{
+ LOG(Plugin, "PluginView::handleKeyboardEvent() ----------------- ");
+
+ LOG(Plugin, "PV::hKE(): KE.keyCode: 0x%02X, KE.charCode: %d",
+ event->keyCode(), event->charCode());
+
+ EventRecord record;
+
+ if (event->type() == eventNames().keydownEvent) {
+ // This event is the result of a PlatformKeyboardEvent::KeyDown which
+ // was disambiguated into a PlatformKeyboardEvent::RawKeyDown. Since
+ // we don't have access to the text here, we return, and wait for the
+ // corresponding event based on PlatformKeyboardEvent::Char.
+ return;
+ } else if (event->type() == eventNames().keypressEvent) {
+ // Which would be this one. This event was disambiguated from the same
+ // PlatformKeyboardEvent::KeyDown, but to a PlatformKeyboardEvent::Char,
+ // which retains the text from the original event. So, we can safely pass
+ // on the event as a key-down event to the plugin.
+ record.what = keyDown;
+ } else if (event->type() == eventNames().keyupEvent) {
+ // PlatformKeyboardEvent::KeyUp events always have the text, so nothing
+ // fancy here.
+ record.what = keyUp;
+ } else {
+ return;
+ }
+
+ const PlatformKeyboardEvent* platformEvent = event->keyEvent();
+ int keyCode = platformEvent->nativeVirtualKeyCode();
+
+ const String text = platformEvent->text();
+ if (text.length() < 1) {
+ event->setDefaultHandled();
+ return;
+ }
+
+ WTF::RetainPtr<CFStringRef> cfText(WTF::AdoptCF, text.createCFString());
+
+ LOG(Plugin, "PV::hKE(): PKE.text: %s, PKE.unmodifiedText: %s, PKE.keyIdentifier: %s",
+ text.ascii().data(), platformEvent->unmodifiedText().ascii().data(),
+ platformEvent->keyIdentifier().ascii().data());
+
+ char charCodes[2] = { 0, 0 };
+ if (!CFStringGetCString(cfText.get(), charCodes, 2, CFStringGetSystemEncoding())) {
+ LOG_ERROR("Could not resolve character code using system encoding.");
+ event->setDefaultHandled();
+ return;
+ }
+
+ record.where = globalMousePosForPlugin();
+ record.modifiers = modifiersForEvent(event);
+ record.message = ((keyCode & 0xFF) << 8) | (charCodes[0] & 0xFF);
+ record.when = TickCount();
+
+ LOG(Plugin, "PV::hKE(): record.modifiers: %d", record.modifiers);
+
+ LOG(Plugin, "PV::hKE(): PKE.qtEvent()->nativeVirtualKey: 0x%02X, charCode: %d",
+ keyCode, int(uchar(charCodes[0])));
+
+ if (!dispatchNPEvent(record))
+ LOG(Events, "PluginView::handleKeyboardEvent(): Keyboard event type %d not accepted", record.what);
+ else
+ event->setDefaultHandled();
+}
+
+void PluginView::nullEventTimerFired(Timer<PluginView>*)
+{
+ EventRecord record;
+
+ record.what = nullEvent;
+ record.message = 0;
+ record.when = TickCount();
+ record.where = globalMousePosForPlugin();
+ record.modifiers = GetCurrentKeyModifiers();
+ if (!Button())
+ record.modifiers |= btnState;
+
+ if (!dispatchNPEvent(record))
+ LOG(Events, "PluginView::nullEventTimerFired(): Null event not accepted");
+}
+
+static int modifiersForEvent(UIEventWithKeyState* event)
+{
+ int modifiers = 0;
+
+ if (event->ctrlKey())
+ modifiers |= controlKey;
+
+ if (event->altKey())
+ modifiers |= optionKey;
+
+ if (event->metaKey())
+ modifiers |= cmdKey;
+
+ if (event->shiftKey())
+ modifiers |= shiftKey;
+
+ return modifiers;
+}
+
+static bool tigerOrBetter()
+{
+ static SInt32 systemVersion = 0;
+
+ if (!systemVersion) {
+ if (Gestalt(gestaltSystemVersion, &systemVersion) != noErr)
+ return false;
+ }
+
+ return systemVersion >= 0x1040;
+}
+
+Point PluginView::globalMousePosForPlugin() const
+{
+ Point pos;
+ GetGlobalMouse(&pos);
+
+ IntPoint offset = topLevelOffsetFor(platformPluginWidget());
+ pos.h -= offset.x();
+ pos.v -= offset.y();
+
+ float scaleFactor = tigerOrBetter() ? HIGetScaleFactor() : 1;
+
+ pos.h = short(pos.h * scaleFactor);
+ pos.v = short(pos.v * scaleFactor);
+
+ return pos;
+}
+
+bool PluginView::dispatchNPEvent(NPEvent& event)
+{
+ PluginView::setCurrentPluginView(this);
+ JSC::JSLock::DropAllLocks dropAllLocks(false);
+ setCallingPlugin(true);
+
+ bool accepted = m_plugin->pluginFuncs()->event(m_instance, &event);
+
+ setCallingPlugin(false);
+ PluginView::setCurrentPluginView(0);
+ return accepted;
+}
+
+// ------------------- Miscellaneous ------------------
+
+static const char* MozillaUserAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0";
+
+const char* PluginView::userAgent()
+{
+ if (m_plugin->quirks().contains(PluginQuirkWantsMozillaUserAgent))
+ return MozillaUserAgent;
+
+ if (m_userAgent.isNull())
+ m_userAgent = m_parentFrame->loader()->userAgent(m_url).utf8();
+
+ return m_userAgent.data();
+}
+
+const char* PluginView::userAgentStatic()
+{
+ return MozillaUserAgent;
+}
+
+NPError PluginView::handlePostReadFile(Vector<char>& buffer, uint32 len, const char* buf)
+{
+ String filename(buf, len);
+
+ if (filename.startsWith("file:///"))
+ filename = filename.substring(8);
+
+ if (!fileExists(filename))
+ return NPERR_FILE_NOT_FOUND;
+
+ FILE* fileHandle = fopen((filename.utf8()).data(), "r");
+
+ if (fileHandle == 0)
+ return NPERR_FILE_NOT_FOUND;
+
+ int bytesRead = fread(buffer.data(), 1, 0, fileHandle);
+
+ fclose(fileHandle);
+
+ if (bytesRead <= 0)
+ return NPERR_FILE_NOT_FOUND;
+
+ return NPERR_NO_ERROR;
+}
+
+} // namespace WebCore
+
+#endif // !__LP64__
diff --git a/src/3rdparty/webkit/WebCore/plugins/npapi.cpp b/src/3rdparty/webkit/WebCore/plugins/npapi.cpp
new file mode 100644
index 0000000000..4135b64203
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/npapi.cpp
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ *
+ * 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 "PluginInfoStore.h"
+#include "PluginMainThreadScheduler.h"
+#include "PluginView.h"
+#include "npruntime_internal.h"
+
+using namespace WebCore;
+
+// The plugin view is always the ndata of the instance,. Sometimes, plug-ins will call an instance-specific function
+// with a NULL instance. To workaround this, call the last plug-in view that made a call to a plug-in.
+// Currently, the current plug-in view is only set before NPP_New in PluginView::start.
+// This specifically works around Flash and Shockwave. When we call NPP_New, they call NPN_Useragent with a NULL instance.
+static PluginView* pluginViewForInstance(NPP instance)
+{
+ if (instance && instance->ndata)
+ return static_cast<PluginView*>(instance->ndata);
+ return PluginView::currentPluginView();
+}
+
+void* NPN_MemAlloc(uint32 size)
+{
+ return malloc(size);
+}
+
+void NPN_MemFree(void* ptr)
+{
+ free(ptr);
+}
+
+uint32 NPN_MemFlush(uint32 size)
+{
+ // Do nothing
+ return 0;
+}
+
+void NPN_ReloadPlugins(NPBool reloadPages)
+{
+ refreshPlugins(reloadPages);
+}
+
+NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
+{
+ return NPERR_STREAM_NOT_SEEKABLE;
+}
+
+NPError NPN_GetURLNotify(NPP instance, const char* url, const char* target, void* notifyData)
+{
+ return pluginViewForInstance(instance)->getURLNotify(url, target, notifyData);
+}
+
+NPError NPN_GetURL(NPP instance, const char* url, const char* target)
+{
+ return pluginViewForInstance(instance)->getURL(url, target);
+}
+
+NPError NPN_PostURLNotify(NPP instance, const char* url, const char* target, uint32 len, const char* buf, NPBool file, void* notifyData)
+{
+ return pluginViewForInstance(instance)->postURLNotify(url, target, len, buf, file, notifyData);
+}
+
+NPError NPN_PostURL(NPP instance, const char* url, const char* target, uint32 len, const char* buf, NPBool file)
+{
+ return pluginViewForInstance(instance)->postURL(url, target, len, buf, file);
+}
+
+NPError NPN_NewStream(NPP instance, NPMIMEType type, const char* target, NPStream** stream)
+{
+ return pluginViewForInstance(instance)->newStream(type, target, stream);
+}
+
+int32 NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer)
+{
+ return pluginViewForInstance(instance)->write(stream, len, buffer);
+}
+
+NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPReason reason)
+{
+ return pluginViewForInstance(instance)->destroyStream(stream, reason);
+}
+
+const char* NPN_UserAgent(NPP instance)
+{
+ PluginView* view = pluginViewForInstance(instance);
+
+ if (!view)
+ return PluginView::userAgentStatic();
+
+ return view->userAgent();
+}
+
+void NPN_Status(NPP instance, const char* message)
+{
+ pluginViewForInstance(instance)->status(message);
+}
+
+void NPN_InvalidateRect(NPP instance, NPRect* invalidRect)
+{
+ pluginViewForInstance(instance)->invalidateRect(invalidRect);
+}
+
+void NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
+{
+ pluginViewForInstance(instance)->invalidateRegion(invalidRegion);
+}
+
+void NPN_ForceRedraw(NPP instance)
+{
+ pluginViewForInstance(instance)->forceRedraw();
+}
+
+NPError NPN_GetValue(NPP instance, NPNVariable variable, void* value)
+{
+ PluginView* view = pluginViewForInstance(instance);
+
+ if (!view)
+ return PluginView::getValueStatic(variable, value);
+
+ return pluginViewForInstance(instance)->getValue(variable, value);
+}
+
+NPError NPN_SetValue(NPP instance, NPPVariable variable, void* value)
+{
+ return pluginViewForInstance(instance)->setValue(variable, value);
+}
+
+void* NPN_GetJavaEnv()
+{
+ // Unsupported
+ return 0;
+}
+
+void* NPN_GetJavaPeer(NPP instance)
+{
+ // Unsupported
+ return 0;
+}
+
+void NPN_PushPopupsEnabledState(NPP instance, NPBool enabled)
+{
+ pluginViewForInstance(instance)->pushPopupsEnabledState(enabled);
+}
+
+void NPN_PopPopupsEnabledState(NPP instance)
+{
+ pluginViewForInstance(instance)->popPopupsEnabledState();
+}
+
+void NPN_PluginThreadAsyncCall(NPP instance, void (*func) (void *), void *userData)
+{
+ PluginMainThreadScheduler::scheduler().scheduleCall(instance, func, userData);
+}
diff --git a/src/3rdparty/webkit/WebCore/plugins/npfunctions.h b/src/3rdparty/webkit/WebCore/plugins/npfunctions.h
new file mode 100644
index 0000000000..509430f72f
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/npfunctions.h
@@ -0,0 +1,204 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ *
+ * 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.
+ */
+#ifndef NPFUNCTIONS_H
+#define NPFUNCTIONS_H
+
+
+#include "npruntime.h"
+#include "npapi.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(XP_WIN)
+#define EXPORTED_CALLBACK(_type, _name) _type (__stdcall * _name)
+#else
+#define EXPORTED_CALLBACK(_type, _name) _type (* _name)
+#endif
+
+typedef NPError (*NPN_GetURLNotifyProcPtr)(NPP instance, const char* URL, const char* window, void* notifyData);
+typedef NPError (*NPN_PostURLNotifyProcPtr)(NPP instance, const char* URL, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData);
+typedef NPError (*NPN_RequestReadProcPtr)(NPStream* stream, NPByteRange* rangeList);
+typedef NPError (*NPN_NewStreamProcPtr)(NPP instance, NPMIMEType type, const char* window, NPStream** stream);
+typedef int32 (*NPN_WriteProcPtr)(NPP instance, NPStream* stream, int32 len, void* buffer);
+typedef NPError (*NPN_DestroyStreamProcPtr)(NPP instance, NPStream* stream, NPReason reason);
+typedef void (*NPN_StatusProcPtr)(NPP instance, const char* message);
+typedef const char*(*NPN_UserAgentProcPtr)(NPP instance);
+typedef void* (*NPN_MemAllocProcPtr)(uint32 size);
+typedef void (*NPN_MemFreeProcPtr)(void* ptr);
+typedef uint32 (*NPN_MemFlushProcPtr)(uint32 size);
+typedef void (*NPN_ReloadPluginsProcPtr)(NPBool reloadPages);
+typedef NPError (*NPN_GetValueProcPtr)(NPP instance, NPNVariable variable, void *ret_value);
+typedef NPError (*NPN_SetValueProcPtr)(NPP instance, NPPVariable variable, void *value);
+typedef void (*NPN_InvalidateRectProcPtr)(NPP instance, NPRect *rect);
+typedef void (*NPN_InvalidateRegionProcPtr)(NPP instance, NPRegion region);
+typedef void (*NPN_ForceRedrawProcPtr)(NPP instance);
+typedef NPError (*NPN_GetURLProcPtr)(NPP instance, const char* URL, const char* window);
+typedef NPError (*NPN_PostURLProcPtr)(NPP instance, const char* URL, const char* window, uint32 len, const char* buf, NPBool file);
+typedef void* (*NPN_GetJavaEnvProcPtr)(void);
+typedef void* (*NPN_GetJavaPeerProcPtr)(NPP instance);
+typedef void (*NPN_PushPopupsEnabledStateProcPtr)(NPP instance, NPBool enabled);
+typedef void (*NPN_PopPopupsEnabledStateProcPtr)(NPP instance);
+typedef void (*NPN_PluginThreadAsyncCallProcPtr)(NPP npp, void (*func)(void *), void *userData);
+typedef uint32 (*NPN_ScheduleTimerProcPtr)(NPP npp, uint32 interval, NPBool repeat, void (*timerFunc)(NPP npp, uint32 timerID));
+typedef void (*NPN_UnscheduleTimerProcPtr)(NPP npp, uint32 timerID);
+typedef NPError (*NPN_PopUpContextMenuProcPtr)(NPP instance, NPMenu* menu);
+
+typedef void (*NPN_ReleaseVariantValueProcPtr) (NPVariant *variant);
+
+typedef NPIdentifier (*NPN_GetStringIdentifierProcPtr) (const NPUTF8 *name);
+typedef void (*NPN_GetStringIdentifiersProcPtr) (const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers);
+typedef NPIdentifier (*NPN_GetIntIdentifierProcPtr) (int32_t intid);
+typedef int32_t (*NPN_IntFromIdentifierProcPtr) (NPIdentifier identifier);
+typedef bool (*NPN_IdentifierIsStringProcPtr) (NPIdentifier identifier);
+typedef NPUTF8 *(*NPN_UTF8FromIdentifierProcPtr) (NPIdentifier identifier);
+
+typedef NPObject* (*NPN_CreateObjectProcPtr) (NPP, NPClass *aClass);
+typedef NPObject* (*NPN_RetainObjectProcPtr) (NPObject *obj);
+typedef void (*NPN_ReleaseObjectProcPtr) (NPObject *obj);
+typedef bool (*NPN_InvokeProcPtr) (NPP npp, NPObject *obj, NPIdentifier methodName, const NPVariant *args, unsigned argCount, NPVariant *result);
+typedef bool (*NPN_InvokeDefaultProcPtr) (NPP npp, NPObject *obj, const NPVariant *args, unsigned argCount, NPVariant *result);
+typedef bool (*NPN_EvaluateProcPtr) (NPP npp, NPObject *obj, NPString *script, NPVariant *result);
+typedef bool (*NPN_GetPropertyProcPtr) (NPP npp, NPObject *obj, NPIdentifier propertyName, NPVariant *result);
+typedef bool (*NPN_SetPropertyProcPtr) (NPP npp, NPObject *obj, NPIdentifier propertyName, const NPVariant *value);
+typedef bool (*NPN_HasPropertyProcPtr) (NPP, NPObject *npobj, NPIdentifier propertyName);
+typedef bool (*NPN_HasMethodProcPtr) (NPP npp, NPObject *npobj, NPIdentifier methodName);
+typedef bool (*NPN_RemovePropertyProcPtr) (NPP npp, NPObject *obj, NPIdentifier propertyName);
+typedef void (*NPN_SetExceptionProcPtr) (NPObject *obj, const NPUTF8 *message);
+typedef bool (*NPN_EnumerateProcPtr) (NPP npp, NPObject *npobj, NPIdentifier **identifier, uint32_t *count);
+typedef bool (*NPN_ConstructProcPtr)(NPP npp, NPObject* obj, const NPVariant *args, uint32_t argCount, NPVariant *result);
+
+typedef NPError (*NPP_NewProcPtr)(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved);
+typedef NPError (*NPP_DestroyProcPtr)(NPP instance, NPSavedData** save);
+typedef NPError (*NPP_SetWindowProcPtr)(NPP instance, NPWindow* window);
+typedef NPError (*NPP_NewStreamProcPtr)(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype);
+typedef NPError (*NPP_DestroyStreamProcPtr)(NPP instance, NPStream* stream, NPReason reason);
+typedef void (*NPP_StreamAsFileProcPtr)(NPP instance, NPStream* stream, const char* fname);
+typedef int32 (*NPP_WriteReadyProcPtr)(NPP instance, NPStream* stream);
+typedef int32 (*NPP_WriteProcPtr)(NPP instance, NPStream* stream, int32_t offset, int32_t len, void* buffer);
+typedef void (*NPP_PrintProcPtr)(NPP instance, NPPrint* platformPrint);
+typedef int16 (*NPP_HandleEventProcPtr)(NPP instance, void* event);
+typedef void (*NPP_URLNotifyProcPtr)(NPP instance, const char* URL, NPReason reason, void* notifyData);
+typedef NPError (*NPP_GetValueProcPtr)(NPP instance, NPPVariable variable, void *ret_value);
+typedef NPError (*NPP_SetValueProcPtr)(NPP instance, NPNVariable variable, void *value);
+
+typedef void *(*NPP_GetJavaClassProcPtr)(void);
+typedef void* JRIGlobalRef; //not using this right now
+
+typedef struct _NPNetscapeFuncs {
+ uint16 size;
+ uint16 version;
+
+ NPN_GetURLProcPtr geturl;
+ NPN_PostURLProcPtr posturl;
+ NPN_RequestReadProcPtr requestread;
+ NPN_NewStreamProcPtr newstream;
+ NPN_WriteProcPtr write;
+ NPN_DestroyStreamProcPtr destroystream;
+ NPN_StatusProcPtr status;
+ NPN_UserAgentProcPtr uagent;
+ NPN_MemAllocProcPtr memalloc;
+ NPN_MemFreeProcPtr memfree;
+ NPN_MemFlushProcPtr memflush;
+ NPN_ReloadPluginsProcPtr reloadplugins;
+ NPN_GetJavaEnvProcPtr getJavaEnv;
+ NPN_GetJavaPeerProcPtr getJavaPeer;
+ NPN_GetURLNotifyProcPtr geturlnotify;
+ NPN_PostURLNotifyProcPtr posturlnotify;
+ NPN_GetValueProcPtr getvalue;
+ NPN_SetValueProcPtr setvalue;
+ NPN_InvalidateRectProcPtr invalidaterect;
+ NPN_InvalidateRegionProcPtr invalidateregion;
+ NPN_ForceRedrawProcPtr forceredraw;
+
+ NPN_GetStringIdentifierProcPtr getstringidentifier;
+ NPN_GetStringIdentifiersProcPtr getstringidentifiers;
+ NPN_GetIntIdentifierProcPtr getintidentifier;
+ NPN_IdentifierIsStringProcPtr identifierisstring;
+ NPN_UTF8FromIdentifierProcPtr utf8fromidentifier;
+ NPN_IntFromIdentifierProcPtr intfromidentifier;
+ NPN_CreateObjectProcPtr createobject;
+ NPN_RetainObjectProcPtr retainobject;
+ NPN_ReleaseObjectProcPtr releaseobject;
+ NPN_InvokeProcPtr invoke;
+ NPN_InvokeDefaultProcPtr invokeDefault;
+ NPN_EvaluateProcPtr evaluate;
+ NPN_GetPropertyProcPtr getproperty;
+ NPN_SetPropertyProcPtr setproperty;
+ NPN_RemovePropertyProcPtr removeproperty;
+ NPN_HasPropertyProcPtr hasproperty;
+ NPN_HasMethodProcPtr hasmethod;
+ NPN_ReleaseVariantValueProcPtr releasevariantvalue;
+ NPN_SetExceptionProcPtr setexception;
+ NPN_PushPopupsEnabledStateProcPtr pushpopupsenabledstate;
+ NPN_PopPopupsEnabledStateProcPtr poppopupsenabledstate;
+ NPN_EnumerateProcPtr enumerate;
+ NPN_PluginThreadAsyncCallProcPtr pluginthreadasynccall;
+ NPN_ConstructProcPtr construct;
+ NPN_ScheduleTimerProcPtr scheduletimer;
+ NPN_UnscheduleTimerProcPtr unscheduletimer;
+ NPN_PopUpContextMenuProcPtr popupcontextmenu;
+} NPNetscapeFuncs;
+
+typedef struct _NPPluginFuncs {
+ uint16 size;
+ uint16 version;
+ NPP_NewProcPtr newp;
+ NPP_DestroyProcPtr destroy;
+ NPP_SetWindowProcPtr setwindow;
+ NPP_NewStreamProcPtr newstream;
+ NPP_DestroyStreamProcPtr destroystream;
+ NPP_StreamAsFileProcPtr asfile;
+ NPP_WriteReadyProcPtr writeready;
+ NPP_WriteProcPtr write;
+ NPP_PrintProcPtr print;
+ NPP_HandleEventProcPtr event;
+ NPP_URLNotifyProcPtr urlnotify;
+ JRIGlobalRef javaClass;
+ NPP_GetValueProcPtr getvalue;
+ NPP_SetValueProcPtr setvalue;
+} NPPluginFuncs;
+
+typedef EXPORTED_CALLBACK(NPError, NP_GetEntryPointsFuncPtr)(NPPluginFuncs*);
+typedef EXPORTED_CALLBACK(void, NPP_ShutdownProcPtr)(void);
+
+#if defined(XP_MACOSX)
+typedef void (*BP_CreatePluginMIMETypesPreferencesFuncPtr)(void);
+typedef NPError (*MainFuncPtr)(NPNetscapeFuncs*, NPPluginFuncs*, NPP_ShutdownProcPtr*);
+#endif
+
+#if defined(XP_UNIX)
+typedef EXPORTED_CALLBACK(NPError, NP_InitializeFuncPtr)(NPNetscapeFuncs*, NPPluginFuncs*);
+typedef EXPORTED_CALLBACK(char*, NP_GetMIMEDescriptionFuncPtr)(void);
+#else
+typedef EXPORTED_CALLBACK(NPError, NP_InitializeFuncPtr)(NPNetscapeFuncs*);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/3rdparty/webkit/WebCore/plugins/qt/PluginDataQt.cpp b/src/3rdparty/webkit/WebCore/plugins/qt/PluginDataQt.cpp
new file mode 100644
index 0000000000..5478d38671
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/qt/PluginDataQt.cpp
@@ -0,0 +1,108 @@
+/*
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ Copyright (C) 2008 Collabora Ltd. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+#include "PluginData.h"
+
+#include "PluginDatabase.h"
+#include "PluginPackage.h"
+
+#if QT_VERSION >= 0x040400
+#include "ChromeClientQt.h"
+#include "Page.h"
+#include <qwebpage.h>
+#include <qwebpluginfactory.h>
+#endif
+
+namespace WebCore {
+
+void PluginData::initPlugins()
+{
+#if QT_VERSION >= 0x040400
+ QWebPage* webPage = static_cast<ChromeClientQt*>(m_page->chrome()->client())->m_webPage;
+ QWebPluginFactory* factory = webPage->pluginFactory();
+ if (factory) {
+
+ QList<QWebPluginFactory::Plugin> qplugins = factory->plugins();
+ for (int i = 0; i < qplugins.count(); ++i) {
+ const QWebPluginFactory::Plugin& qplugin = qplugins.at(i);
+
+ PluginInfo* info = new PluginInfo;
+ info->name = qplugin.name;
+ info->desc = qplugin.description;
+
+ for (int j = 0; j < qplugin.mimeTypes.count(); ++j) {
+ const QWebPluginFactory::MimeType& mimeType = qplugin.mimeTypes.at(j);
+
+ MimeClassInfo* mimeInfo = new MimeClassInfo;
+ mimeInfo->type = mimeType.name;
+ mimeInfo->desc = mimeType.description;
+ mimeInfo->suffixes = mimeType.fileExtensions.join(QLatin1String("; "));
+
+ info->mimes.append(mimeInfo);
+ }
+
+ m_plugins.append(info);
+ }
+ }
+#endif
+
+ PluginDatabase *db = PluginDatabase::installedPlugins();
+ const Vector<PluginPackage*> &plugins = db->plugins();
+
+ for (unsigned int i = 0; i < plugins.size(); ++i) {
+ PluginInfo* info = new PluginInfo;
+ PluginPackage* package = plugins[i];
+
+ info->name = package->name();
+ info->file = package->fileName();
+ info->desc = package->description();
+
+ const MIMEToDescriptionsMap& mimeToDescriptions = package->mimeToDescriptions();
+ MIMEToDescriptionsMap::const_iterator end = mimeToDescriptions.end();
+ for (MIMEToDescriptionsMap::const_iterator it = mimeToDescriptions.begin(); it != end; ++it) {
+ MimeClassInfo* mime = new MimeClassInfo;
+ info->mimes.append(mime);
+
+ mime->type = it->first;
+ mime->desc = it->second;
+ mime->plugin = info;
+
+ Vector<String> extensions = package->mimeToExtensions().get(mime->type);
+
+ for (unsigned i = 0; i < extensions.size(); i++) {
+ if (i > 0)
+ mime->suffixes += ",";
+
+ mime->suffixes += extensions[i];
+ }
+ }
+
+ m_plugins.append(info);
+ }
+}
+
+void PluginData::refresh()
+{
+ PluginDatabase *db = PluginDatabase::installedPlugins();
+ db->refresh();
+}
+
+};
diff --git a/src/3rdparty/webkit/WebCore/plugins/qt/PluginPackageQt.cpp b/src/3rdparty/webkit/WebCore/plugins/qt/PluginPackageQt.cpp
new file mode 100644
index 0000000000..438781304c
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/qt/PluginPackageQt.cpp
@@ -0,0 +1,200 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Collabora Ltd. All rights reserved.
+ *
+ * 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 "PluginPackage.h"
+
+#include "CString.h"
+#include "MIMETypeRegistry.h"
+#include "NotImplemented.h"
+#include "npruntime_impl.h"
+#include "PluginDatabase.h"
+#include "PluginDebug.h"
+
+namespace WebCore {
+
+bool PluginPackage::fetchInfo()
+{
+ if (!load())
+ return false;
+
+ NPP_GetValueProcPtr gv = (NPP_GetValueProcPtr)m_module->resolve("NP_GetValue");
+ typedef char *(*NPP_GetMIMEDescriptionProcPtr)();
+ NPP_GetMIMEDescriptionProcPtr gm =
+ (NPP_GetMIMEDescriptionProcPtr)m_module->resolve("NP_GetMIMEDescription");
+ if (!gm || !gv) {
+ return false;
+ }
+ char *buf = 0;
+ NPError err = gv(0, NPPVpluginNameString, (void *)&buf);
+ if (err != NPERR_NO_ERROR) {
+ return false;
+ }
+ m_name = buf;
+ err = gv(0, NPPVpluginDescriptionString, (void *)&buf);
+ if (err != NPERR_NO_ERROR) {
+ return false;
+ }
+ m_description = buf;
+ determineModuleVersionFromDescription();
+
+ String s = gm();
+ Vector<String> types;
+ s.split(UChar(';'), false, types);
+ for (int i = 0; i < types.size(); ++i) {
+ Vector<String> mime;
+ types[i].split(UChar(':'), true, mime);
+ if (mime.size() > 0) {
+ Vector<String> exts;
+ if (mime.size() > 1)
+ mime[1].split(UChar(','), false, exts);
+ determineQuirks(mime[0]);
+ m_mimeToExtensions.add(mime[0], exts);
+ if (mime.size() > 2)
+ m_mimeToDescriptions.add(mime[0], mime[2]);
+ }
+ }
+
+ return true;
+}
+
+bool PluginPackage::load()
+{
+ if (m_isLoaded) {
+ m_loadCount++;
+ return true;
+ }
+
+ m_module = new QLibrary((QString)m_path);
+ m_module->setLoadHints(QLibrary::ResolveAllSymbolsHint);
+ if (!m_module->load()) {
+ LOG(Plugin, "%s not loaded (%s)", m_path.utf8().data(),
+ m_module->errorString().toLatin1().constData());
+ return false;
+ }
+
+ m_isLoaded = true;
+
+ NP_InitializeFuncPtr NP_Initialize;
+ NPError npErr;
+
+ NP_Initialize = (NP_InitializeFuncPtr)m_module->resolve("NP_Initialize");
+ m_NPP_Shutdown = (NPP_ShutdownProcPtr)m_module->resolve("NP_Shutdown");
+
+ if (!NP_Initialize || !m_NPP_Shutdown)
+ goto abort;
+
+ memset(&m_pluginFuncs, 0, sizeof(m_pluginFuncs));
+ m_pluginFuncs.size = sizeof(m_pluginFuncs);
+
+ m_browserFuncs.size = sizeof (m_browserFuncs);
+ m_browserFuncs.version = NP_VERSION_MINOR;
+ m_browserFuncs.geturl = NPN_GetURL;
+ m_browserFuncs.posturl = NPN_PostURL;
+ m_browserFuncs.requestread = NPN_RequestRead;
+ m_browserFuncs.newstream = NPN_NewStream;
+ m_browserFuncs.write = NPN_Write;
+ m_browserFuncs.destroystream = NPN_DestroyStream;
+ m_browserFuncs.status = NPN_Status;
+ m_browserFuncs.uagent = NPN_UserAgent;
+ m_browserFuncs.memalloc = NPN_MemAlloc;
+ m_browserFuncs.memfree = NPN_MemFree;
+ m_browserFuncs.memflush = NPN_MemFlush;
+ m_browserFuncs.reloadplugins = NPN_ReloadPlugins;
+ m_browserFuncs.geturlnotify = NPN_GetURLNotify;
+ m_browserFuncs.posturlnotify = NPN_PostURLNotify;
+ m_browserFuncs.getvalue = NPN_GetValue;
+ m_browserFuncs.setvalue = NPN_SetValue;
+ m_browserFuncs.invalidaterect = NPN_InvalidateRect;
+ m_browserFuncs.invalidateregion = NPN_InvalidateRegion;
+ m_browserFuncs.forceredraw = NPN_ForceRedraw;
+ m_browserFuncs.getJavaEnv = NPN_GetJavaEnv;
+ m_browserFuncs.getJavaPeer = NPN_GetJavaPeer;
+ m_browserFuncs.pushpopupsenabledstate = NPN_PushPopupsEnabledState;
+ m_browserFuncs.poppopupsenabledstate = NPN_PopPopupsEnabledState;
+
+ m_browserFuncs.releasevariantvalue = _NPN_ReleaseVariantValue;
+ m_browserFuncs.getstringidentifier = _NPN_GetStringIdentifier;
+ m_browserFuncs.getstringidentifiers = _NPN_GetStringIdentifiers;
+ m_browserFuncs.getintidentifier = _NPN_GetIntIdentifier;
+ m_browserFuncs.identifierisstring = _NPN_IdentifierIsString;
+ m_browserFuncs.utf8fromidentifier = _NPN_UTF8FromIdentifier;
+ m_browserFuncs.createobject = _NPN_CreateObject;
+ m_browserFuncs.retainobject = _NPN_RetainObject;
+ m_browserFuncs.releaseobject = _NPN_ReleaseObject;
+ m_browserFuncs.invoke = _NPN_Invoke;
+ m_browserFuncs.invokeDefault = _NPN_InvokeDefault;
+ m_browserFuncs.evaluate = _NPN_Evaluate;
+ m_browserFuncs.getproperty = _NPN_GetProperty;
+ m_browserFuncs.setproperty = _NPN_SetProperty;
+ m_browserFuncs.removeproperty = _NPN_RemoveProperty;
+ m_browserFuncs.hasproperty = _NPN_HasMethod;
+ m_browserFuncs.hasmethod = _NPN_HasProperty;
+ m_browserFuncs.setexception = _NPN_SetException;
+ m_browserFuncs.enumerate = _NPN_Enumerate;
+ m_browserFuncs.construct = _NPN_Construct;
+
+#if defined(XP_UNIX)
+ npErr = NP_Initialize(&m_browserFuncs, &m_pluginFuncs);
+#else
+ npErr = NP_Initialize(&m_browserFuncs);
+#endif
+ if (npErr != NPERR_NO_ERROR)
+ goto abort;
+
+ m_loadCount++;
+ return true;
+
+abort:
+ unloadWithoutShutdown();
+ return false;
+}
+
+unsigned PluginPackage::hash() const
+{
+ unsigned hashCodes[2] = {
+ m_path.impl()->hash(),
+ m_lastModified
+ };
+
+ return StringImpl::computeHash(reinterpret_cast<UChar*>(hashCodes), 2 * sizeof(unsigned) / sizeof(UChar));
+}
+
+bool PluginPackage::equal(const PluginPackage& a, const PluginPackage& b)
+{
+ return a.m_description == b.m_description;
+}
+
+int PluginPackage::compareFileVersion(const PlatformModuleVersion& compareVersion) const
+{
+ // return -1, 0, or 1 if plug-in version is less than, equal to, or greater than
+ // the passed version
+ if (m_moduleVersion != compareVersion)
+ return m_moduleVersion > compareVersion ? 1 : -1;
+ return 0;
+}
+
+}
diff --git a/src/3rdparty/webkit/WebCore/plugins/qt/PluginViewQt.cpp b/src/3rdparty/webkit/WebCore/plugins/qt/PluginViewQt.cpp
new file mode 100644
index 0000000000..5aa89331f7
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/qt/PluginViewQt.cpp
@@ -0,0 +1,488 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Collabora Ltd. All rights reserved.
+ *
+ * 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 <QWidget>
+#include <QX11EmbedContainer>
+#include <QX11Info>
+
+#include "NotImplemented.h"
+#include "PluginDebug.h"
+#include "PluginPackage.h"
+#include "npruntime_impl.h"
+#include "runtime.h"
+#include "runtime_root.h"
+#include <runtime/JSLock.h>
+#include <runtime/JSValue.h>
+#include "JSDOMBinding.h"
+#include "ScriptController.h"
+
+#include "Document.h"
+#include "DocumentLoader.h"
+#include "Element.h"
+#include "FrameLoader.h"
+#include "FrameLoadRequest.h"
+#include "FrameTree.h"
+#include "Frame.h"
+#include "FrameView.h"
+#include "GraphicsContext.h"
+#include "Image.h"
+#include "HTMLNames.h"
+#include "HTMLPlugInElement.h"
+#include "KeyboardEvent.h"
+#include "MouseEvent.h"
+#include "Page.h"
+#include "PlatformMouseEvent.h"
+#include "RenderLayer.h"
+#include "Settings.h"
+
+using JSC::ExecState;
+using JSC::Interpreter;
+using JSC::JSLock;
+using JSC::JSObject;
+using JSC::UString;
+
+using std::min;
+
+using namespace WTF;
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+void PluginView::updatePluginWidget()
+{
+ if (!parent() || !m_isWindowed)
+ return;
+
+ ASSERT(parent()->isFrameView());
+ FrameView* frameView = static_cast<FrameView*>(parent());
+
+ IntRect oldWindowRect = m_windowRect;
+ IntRect oldClipRect = m_clipRect;
+
+ m_windowRect = IntRect(frameView->contentsToWindow(frameRect().location()), frameRect().size());
+ m_clipRect = windowClipRect();
+ m_clipRect.move(-m_windowRect.x(), -m_windowRect.y());
+
+ if (platformPluginWidget()) {
+ platformPluginWidget()->move(m_windowRect.x(), m_windowRect.y());
+ platformPluginWidget()->resize(m_windowRect.width(), m_windowRect.height());
+ platformPluginWidget()->setMask(QRegion(m_clipRect.x(), m_clipRect.y(), m_clipRect.width(), m_clipRect.height()));
+ }
+}
+
+void PluginView::setFocus()
+{
+ if (platformPluginWidget())
+ platformPluginWidget()->setFocus(Qt::OtherFocusReason);
+ else
+ Widget::setFocus();
+}
+
+void PluginView::show()
+{
+ setSelfVisible(true);
+
+ if (isParentVisible() && platformPluginWidget())
+ platformPluginWidget()->setVisible(true);
+
+ Widget::show();
+}
+
+void PluginView::hide()
+{
+ setSelfVisible(false);
+
+ if (isParentVisible() && platformPluginWidget())
+ platformPluginWidget()->setVisible(false);
+
+ Widget::hide();
+}
+
+void PluginView::paint(GraphicsContext* context, const IntRect& rect)
+{
+ if (!m_isStarted) {
+ paintMissingPluginIcon(context, rect);
+ return;
+ }
+
+ if (m_isWindowed || context->paintingDisabled())
+ return;
+
+ notImplemented();
+}
+
+void PluginView::handleKeyboardEvent(KeyboardEvent* event)
+{
+ notImplemented();
+}
+
+void PluginView::handleMouseEvent(MouseEvent* event)
+{
+ notImplemented();
+}
+
+void PluginView::setParent(ScrollView* parent)
+{
+ Widget::setParent(parent);
+
+ if (parent)
+ init();
+ else {
+ if (!platformPluginWidget())
+ return;
+ }
+}
+
+void PluginView::setNPWindowRect(const IntRect& rect)
+{
+ if (!m_isStarted || !parent())
+ return;
+
+ IntPoint p = static_cast<FrameView*>(parent())->contentsToWindow(rect.location());
+ m_npWindow.x = p.x();
+ m_npWindow.y = p.y();
+
+ m_npWindow.width = rect.width();
+ m_npWindow.height = rect.height();
+
+ m_npWindow.clipRect.left = 0;
+ m_npWindow.clipRect.top = 0;
+ m_npWindow.clipRect.right = rect.width();
+ m_npWindow.clipRect.bottom = rect.height();
+
+ if (m_npWindow.x < 0 || m_npWindow.y < 0 ||
+ m_npWindow.width <= 0 || m_npWindow.height <= 0)
+ return;
+
+ if (m_plugin->pluginFuncs()->setwindow) {
+ PluginView::setCurrentPluginView(this);
+ JSC::JSLock::DropAllLocks dropAllLocks(false);
+ setCallingPlugin(true);
+ m_plugin->pluginFuncs()->setwindow(m_instance, &m_npWindow);
+ setCallingPlugin(false);
+ PluginView::setCurrentPluginView(0);
+
+ if (!m_isWindowed)
+ return;
+
+ ASSERT(platformPluginWidget());
+ }
+}
+
+void PluginView::setParentVisible(bool visible)
+{
+ if (isParentVisible() == visible)
+ return;
+
+ Widget::setParentVisible(visible);
+
+ if (isSelfVisible() && platformPluginWidget())
+ platformPluginWidget()->setVisible(visible);
+}
+
+void PluginView::stop()
+{
+ if (!m_isStarted)
+ return;
+
+ HashSet<RefPtr<PluginStream> > streams = m_streams;
+ HashSet<RefPtr<PluginStream> >::iterator end = streams.end();
+ for (HashSet<RefPtr<PluginStream> >::iterator it = streams.begin(); it != end; ++it) {
+ (*it)->stop();
+ disconnectStream((*it).get());
+ }
+
+ ASSERT(m_streams.isEmpty());
+
+ m_isStarted = false;
+
+ JSC::JSLock::DropAllLocks dropAllLocks(false);
+
+ // Clear the window
+ m_npWindow.window = 0;
+ if (m_plugin->pluginFuncs()->setwindow && !m_plugin->quirks().contains(PluginQuirkDontSetNullWindowHandleOnDestroy)) {
+ PluginView::setCurrentPluginView(this);
+ setCallingPlugin(true);
+ m_plugin->pluginFuncs()->setwindow(m_instance, &m_npWindow);
+ setCallingPlugin(false);
+ PluginView::setCurrentPluginView(0);
+ }
+
+ delete (NPSetWindowCallbackStruct *)m_npWindow.ws_info;
+ m_npWindow.ws_info = 0;
+
+ // Destroy the plugin
+ {
+ PluginView::setCurrentPluginView(this);
+ setCallingPlugin(true);
+ m_plugin->pluginFuncs()->destroy(m_instance, 0);
+ setCallingPlugin(false);
+ PluginView::setCurrentPluginView(0);
+ }
+
+ m_instance->pdata = 0;
+}
+
+static const char* MozillaUserAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0";
+
+const char* PluginView::userAgent()
+{
+ if (m_plugin->quirks().contains(PluginQuirkWantsMozillaUserAgent))
+ return MozillaUserAgent;
+
+ if (m_userAgent.isNull())
+ m_userAgent = m_parentFrame->loader()->userAgent(m_url).utf8();
+
+ return m_userAgent.data();
+}
+
+const char* PluginView::userAgentStatic()
+{
+ //FIXME - Just say we are Mozilla
+ return MozillaUserAgent;
+}
+
+NPError PluginView::handlePostReadFile(Vector<char>& buffer, uint32 len, const char* buf)
+{
+ String filename(buf, len);
+
+ if (filename.startsWith("file:///"))
+ filename = filename.substring(8);
+
+ if (!fileExists(filename))
+ return NPERR_FILE_NOT_FOUND;
+
+ //FIXME - read the file data into buffer
+ FILE* fileHandle = fopen((filename.utf8()).data(), "r");
+
+ if (fileHandle == 0)
+ return NPERR_FILE_NOT_FOUND;
+
+ //buffer.resize();
+
+ int bytesRead = fread(buffer.data(), 1, 0, fileHandle);
+
+ fclose(fileHandle);
+
+ if (bytesRead <= 0)
+ return NPERR_FILE_NOT_FOUND;
+
+ return NPERR_NO_ERROR;
+}
+
+NPError PluginView::getValueStatic(NPNVariable variable, void* value)
+{
+ switch (variable) {
+ case NPNVToolkit:
+ *((uint32 *)value) = 0;
+ return NPERR_NO_ERROR;
+
+ case NPNVSupportsXEmbedBool:
+ *((uint32 *)value) = true;
+ return NPERR_NO_ERROR;
+
+ case NPNVjavascriptEnabledBool:
+ *((uint32 *)value) = true;
+ return NPERR_NO_ERROR;
+
+ default:
+ return NPERR_GENERIC_ERROR;
+ }
+}
+
+NPError PluginView::getValue(NPNVariable variable, void* value)
+{
+ switch (variable) {
+ case NPNVxDisplay:
+ if (platformPluginWidget())
+ *(void **)value = platformPluginWidget()->x11Info().display();
+ else
+ *(void **)value = m_parentFrame->view()->hostWindow()->platformWindow()->x11Info().display();
+ return NPERR_NO_ERROR;
+
+ case NPNVxtAppContext:
+ return NPERR_GENERIC_ERROR;
+
+#if ENABLE(NETSCAPE_PLUGIN_API)
+ case NPNVWindowNPObject: {
+ if (m_isJavaScriptPaused)
+ return NPERR_GENERIC_ERROR;
+
+ 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);
+
+ void** v = (void**)value;
+ *v = windowScriptObject;
+
+ return NPERR_NO_ERROR;
+ }
+
+ case NPNVPluginElementNPObject: {
+ if (m_isJavaScriptPaused)
+ return NPERR_GENERIC_ERROR;
+
+ 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);
+
+ void** v = (void**)value;
+ *v = pluginScriptObject;
+
+ return NPERR_NO_ERROR;
+ }
+#endif
+
+ case NPNVnetscapeWindow: {
+ void* w = reinterpret_cast<void*>(value);
+ *((XID *)w) = m_parentFrame->view()->hostWindow()->platformWindow()->winId();
+ return NPERR_NO_ERROR;
+ }
+
+ case NPNVToolkit:
+ if (m_plugin->quirks().contains(PluginQuirkRequiresGtkToolKit)) {
+ *((uint32 *)value) = 2;
+ return NPERR_NO_ERROR;
+ }
+ // fall through
+ default:
+ return getValueStatic(variable, value);
+ }
+}
+
+void PluginView::invalidateRect(const IntRect& rect)
+{
+ if (platformWidget()) {
+ platformWidget()->update(rect);
+ return;
+ }
+
+ invalidateWindowlessPluginRect(rect);
+}
+
+void PluginView::invalidateRect(NPRect* rect)
+{
+ notImplemented();
+}
+
+void PluginView::invalidateRegion(NPRegion region)
+{
+ notImplemented();
+}
+
+void PluginView::forceRedraw()
+{
+ notImplemented();
+}
+
+PluginView::~PluginView()
+{
+ stop();
+
+ deleteAllValues(m_requests);
+
+ freeStringArray(m_paramNames, m_paramCount);
+ freeStringArray(m_paramValues, m_paramCount);
+
+ m_parentFrame->script()->cleanupScriptObjectsForPlugin(this);
+
+ if (m_plugin && !(m_plugin->quirks().contains(PluginQuirkDontUnloadPlugin)))
+ m_plugin->unload();
+
+ delete platformPluginWidget();
+}
+
+void PluginView::init()
+{
+ if (m_haveInitialized)
+ return;
+ m_haveInitialized = true;
+
+ if (!m_plugin) {
+ ASSERT(m_status == PluginStatusCanNotFindPlugin);
+ return;
+ }
+
+ if (!m_plugin->load()) {
+ m_plugin = 0;
+ m_status = PluginStatusCanNotLoadPlugin;
+ return;
+ }
+
+ if (!start()) {
+ m_status = PluginStatusCanNotLoadPlugin;
+ return;
+ }
+
+ if (m_plugin->pluginFuncs()->getvalue) {
+ PluginView::setCurrentPluginView(this);
+ JSC::JSLock::DropAllLocks dropAllLocks(false);
+ setCallingPlugin(true);
+ m_plugin->pluginFuncs()->getvalue(m_instance, NPPVpluginNeedsXEmbed, &m_needsXEmbed);
+ setCallingPlugin(false);
+ PluginView::setCurrentPluginView(0);
+ }
+
+ if (m_needsXEmbed) {
+ setPlatformWidget(new QX11EmbedContainer(m_parentFrame->view()->hostWindow()->platformWindow()));
+ } else {
+ notImplemented();
+ m_status = PluginStatusCanNotLoadPlugin;
+ return;
+ }
+ show ();
+
+ NPSetWindowCallbackStruct *wsi = new NPSetWindowCallbackStruct();
+
+ wsi->type = 0;
+
+ wsi->display = platformPluginWidget()->x11Info().display();
+ wsi->visual = (Visual*)platformPluginWidget()->x11Info().visual();
+ wsi->depth = platformPluginWidget()->x11Info().depth();
+ wsi->colormap = platformPluginWidget()->x11Info().colormap();
+ m_npWindow.ws_info = wsi;
+
+ m_npWindow.type = NPWindowTypeWindow;
+ m_npWindow.window = (void*)platformPluginWidget()->winId();
+
+ if (!(m_plugin->quirks().contains(PluginQuirkDeferFirstSetWindowCall)))
+ setNPWindowRect(frameRect());
+
+ m_status = PluginStatusLoadedSuccessfully;
+}
+
+} // namespace WebCore
diff --git a/src/3rdparty/webkit/WebCore/plugins/win/PluginDataWin.cpp b/src/3rdparty/webkit/WebCore/plugins/win/PluginDataWin.cpp
new file mode 100644
index 0000000000..4ec4b6daac
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/win/PluginDataWin.cpp
@@ -0,0 +1,72 @@
+/*
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+#include "PluginData.h"
+
+#include "PluginDatabase.h"
+#include "PluginPackage.h"
+
+namespace WebCore {
+
+void PluginData::initPlugins()
+{
+ PluginDatabase *db = PluginDatabase::installedPlugins();
+ const Vector<PluginPackage*> &plugins = db->plugins();
+
+ for (unsigned int i = 0; i < plugins.size(); ++i) {
+ PluginInfo* info = new PluginInfo;
+ PluginPackage* package = plugins[i];
+
+ info->name = package->name();
+ info->file = package->fileName();
+ info->desc = package->description();
+
+ const MIMEToDescriptionsMap& mimeToDescriptions = package->mimeToDescriptions();
+ MIMEToDescriptionsMap::const_iterator end = mimeToDescriptions.end();
+ for (MIMEToDescriptionsMap::const_iterator it = mimeToDescriptions.begin(); it != end; ++it) {
+ MimeClassInfo* mime = new MimeClassInfo;
+ info->mimes.append(mime);
+
+ mime->type = it->first;
+ mime->desc = it->second;
+ mime->plugin = info;
+
+ Vector<String> extensions = package->mimeToExtensions().get(mime->type);
+
+ for (unsigned i = 0; i < extensions.size(); i++) {
+ if (i > 0)
+ mime->suffixes += ",";
+
+ mime->suffixes += extensions[i];
+ }
+ }
+
+ m_plugins.append(info);
+ }
+}
+
+void PluginData::refresh()
+{
+ PluginDatabase *db = PluginDatabase::installedPlugins();
+ db->refresh();
+}
+
+};
diff --git a/src/3rdparty/webkit/WebCore/plugins/win/PluginDatabaseWin.cpp b/src/3rdparty/webkit/WebCore/plugins/win/PluginDatabaseWin.cpp
new file mode 100644
index 0000000000..c59f133e5f
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/win/PluginDatabaseWin.cpp
@@ -0,0 +1,354 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
+ *
+ * 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 "PluginDatabase.h"
+
+#include "Frame.h"
+#include "KURL.h"
+#include "PluginPackage.h"
+#include <windows.h>
+#include <shlwapi.h>
+
+#if COMPILER(MINGW)
+#define _countof(x) (sizeof(x)/sizeof(x[0]))
+#endif
+
+namespace WebCore {
+
+static inline void addPluginPathsFromRegistry(HKEY rootKey, HashSet<String>& paths)
+{
+ HKEY key;
+ HRESULT result = RegOpenKeyExW(rootKey, L"Software\\MozillaPlugins", 0, KEY_ENUMERATE_SUB_KEYS, &key);
+
+ if (result != ERROR_SUCCESS)
+ return;
+
+ wchar_t name[128];
+ FILETIME lastModified;
+
+ // Enumerate subkeys
+ for (int i = 0;; i++) {
+ DWORD nameLen = _countof(name);
+ result = RegEnumKeyExW(key, i, name, &nameLen, 0, 0, 0, &lastModified);
+
+ if (result != ERROR_SUCCESS)
+ break;
+
+ WCHAR pathStr[_MAX_PATH];
+ DWORD pathStrSize = sizeof(pathStr);
+ DWORD type;
+
+ result = SHGetValue(key, name, TEXT("Path"), &type, (LPBYTE)pathStr, &pathStrSize);
+ if (result != ERROR_SUCCESS || type != REG_SZ)
+ continue;
+
+ paths.add(String(pathStr, pathStrSize / sizeof(WCHAR) - 1));
+ }
+
+ RegCloseKey(key);
+}
+
+void PluginDatabase::getPluginPathsInDirectories(HashSet<String>& paths) const
+{
+ // FIXME: This should be a case insensitive set.
+ HashSet<String> uniqueFilenames;
+
+ HANDLE hFind = INVALID_HANDLE_VALUE;
+ WIN32_FIND_DATAW findFileData;
+
+ String oldWMPPluginPath;
+ String newWMPPluginPath;
+
+ Vector<String>::const_iterator end = m_pluginDirectories.end();
+ for (Vector<String>::const_iterator it = m_pluginDirectories.begin(); it != end; ++it) {
+ String pattern = *it + "\\*";
+
+ hFind = FindFirstFileW(pattern.charactersWithNullTermination(), &findFileData);
+
+ if (hFind == INVALID_HANDLE_VALUE)
+ continue;
+
+ do {
+ if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ continue;
+
+ String filename = String(findFileData.cFileName, wcslen(findFileData.cFileName));
+ if ((!filename.startsWith("np", false) || !filename.endsWith("dll", false)) &&
+ (!equalIgnoringCase(filename, "Plugin.dll") || !it->endsWith("Shockwave 10", false)))
+ continue;
+
+ String fullPath = *it + "\\" + filename;
+ if (!uniqueFilenames.add(fullPath).second)
+ continue;
+
+ paths.add(fullPath);
+
+ if (equalIgnoringCase(filename, "npdsplay.dll"))
+ oldWMPPluginPath = fullPath;
+ else if (equalIgnoringCase(filename, "np-mswmp.dll"))
+ newWMPPluginPath = fullPath;
+
+ } while (FindNextFileW(hFind, &findFileData) != 0);
+
+ FindClose(hFind);
+ }
+
+ addPluginPathsFromRegistry(HKEY_LOCAL_MACHINE, paths);
+ addPluginPathsFromRegistry(HKEY_CURRENT_USER, paths);
+
+ // If both the old and new WMP plugin are present in the plugins set,
+ // we remove the old one so we don't end up choosing the old one.
+ if (!oldWMPPluginPath.isEmpty() && !newWMPPluginPath.isEmpty())
+ paths.remove(oldWMPPluginPath);
+}
+
+static inline Vector<int> parseVersionString(const String& versionString)
+{
+ Vector<int> version;
+
+ unsigned startPos = 0;
+ unsigned endPos;
+
+ while (startPos < versionString.length()) {
+ for (endPos = startPos; endPos < versionString.length(); ++endPos)
+ if (versionString[endPos] == '.' || versionString[endPos] == '_')
+ break;
+
+ int versionComponent = versionString.substring(startPos, endPos - startPos).toInt();
+ version.append(versionComponent);
+
+ startPos = endPos + 1;
+ }
+
+ return version;
+}
+
+// This returns whether versionA is higher than versionB
+static inline bool compareVersions(const Vector<int>& versionA, const Vector<int>& versionB)
+{
+ for (unsigned i = 0; i < versionA.size(); i++) {
+ if (i >= versionB.size())
+ return true;
+
+ if (versionA[i] > versionB[i])
+ return true;
+ else if (versionA[i] < versionB[i])
+ return false;
+ }
+
+ // If we come here, the versions are either the same or versionB has an extra component, just return false
+ return false;
+}
+
+static inline void addMozillaPluginDirectories(Vector<String>& directories)
+{
+ // Enumerate all Mozilla plugin directories in the registry
+ HKEY key;
+ LONG result;
+
+ result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\Mozilla"), 0, KEY_READ, &key);
+ if (result == ERROR_SUCCESS) {
+ WCHAR name[128];
+ FILETIME lastModified;
+
+ // Enumerate subkeys
+ for (int i = 0;; i++) {
+ DWORD nameLen = sizeof(name) / sizeof(WCHAR);
+ result = RegEnumKeyExW(key, i, name, &nameLen, 0, 0, 0, &lastModified);
+
+ if (result != ERROR_SUCCESS)
+ break;
+
+ String extensionsPath = String(name, nameLen) + "\\Extensions";
+ HKEY extensionsKey;
+
+ // Try opening the key
+ result = RegOpenKeyEx(key, extensionsPath.charactersWithNullTermination(), 0, KEY_READ, &extensionsKey);
+
+ if (result == ERROR_SUCCESS) {
+ // Now get the plugins directory
+ WCHAR pluginsDirectoryStr[_MAX_PATH];
+ DWORD pluginsDirectorySize = sizeof(pluginsDirectoryStr);
+ DWORD type;
+
+ result = RegQueryValueEx(extensionsKey, TEXT("Plugins"), 0, &type, (LPBYTE)&pluginsDirectoryStr, &pluginsDirectorySize);
+
+ if (result == ERROR_SUCCESS && type == REG_SZ)
+ directories.append(String(pluginsDirectoryStr, pluginsDirectorySize / sizeof(WCHAR) - 1));
+
+ RegCloseKey(extensionsKey);
+ }
+ }
+
+ RegCloseKey(key);
+ }
+}
+
+static inline void addWindowsMediaPlayerPluginDirectory(Vector<String>& directories)
+{
+ // The new WMP Firefox plugin is installed in \PFiles\Plugins if it can't find any Firefox installs
+ WCHAR pluginDirectoryStr[_MAX_PATH + 1];
+ DWORD pluginDirectorySize = ::ExpandEnvironmentStringsW(TEXT("%SYSTEMDRIVE%\\PFiles\\Plugins"), pluginDirectoryStr, _countof(pluginDirectoryStr));
+
+ if (pluginDirectorySize > 0 && pluginDirectorySize <= _countof(pluginDirectoryStr))
+ directories.append(String(pluginDirectoryStr, pluginDirectorySize - 1));
+
+ DWORD type;
+ WCHAR installationDirectoryStr[_MAX_PATH];
+ DWORD installationDirectorySize = sizeof(installationDirectoryStr);
+
+ HRESULT result = SHGetValue(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\MediaPlayer"), TEXT("Installation Directory"), &type, (LPBYTE)&installationDirectoryStr, &installationDirectorySize);
+
+ if (result == ERROR_SUCCESS && type == REG_SZ)
+ directories.append(String(installationDirectoryStr, installationDirectorySize / sizeof(WCHAR) - 1));
+}
+
+static inline void addQuickTimePluginDirectory(Vector<String>& directories)
+{
+ DWORD type;
+ WCHAR installationDirectoryStr[_MAX_PATH];
+ DWORD installationDirectorySize = sizeof(installationDirectoryStr);
+
+ HRESULT result = SHGetValue(HKEY_LOCAL_MACHINE, TEXT("Software\\Apple Computer, Inc.\\QuickTime"), TEXT("InstallDir"), &type, (LPBYTE)&installationDirectoryStr, &installationDirectorySize);
+
+ if (result == ERROR_SUCCESS && type == REG_SZ) {
+ String pluginDir = String(installationDirectoryStr, installationDirectorySize / sizeof(WCHAR) - 1) + "\\plugins";
+ directories.append(pluginDir);
+ }
+}
+
+static inline void addAdobeAcrobatPluginDirectory(Vector<String>& directories)
+{
+ HKEY key;
+ HRESULT result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\Adobe\\Acrobat Reader"), 0, KEY_READ, &key);
+ if (result != ERROR_SUCCESS)
+ return;
+
+ WCHAR name[128];
+ FILETIME lastModified;
+
+ Vector<int> latestAcrobatVersion;
+ String latestAcrobatVersionString;
+
+ // Enumerate subkeys
+ for (int i = 0;; i++) {
+ DWORD nameLen = sizeof(name) / sizeof(WCHAR);
+ result = RegEnumKeyExW(key, i, name, &nameLen, 0, 0, 0, &lastModified);
+
+ if (result != ERROR_SUCCESS)
+ break;
+
+ Vector<int> acrobatVersion = parseVersionString(String(name, nameLen));
+ if (compareVersions(acrobatVersion, latestAcrobatVersion)) {
+ latestAcrobatVersion = acrobatVersion;
+ latestAcrobatVersionString = String(name, nameLen);
+ }
+ }
+
+ if (!latestAcrobatVersionString.isNull()) {
+ DWORD type;
+ WCHAR acrobatInstallPathStr[_MAX_PATH];
+ DWORD acrobatInstallPathSize = sizeof(acrobatInstallPathStr);
+
+ String acrobatPluginKeyPath = "Software\\Adobe\\Acrobat Reader\\" + latestAcrobatVersionString + "\\InstallPath";
+ result = SHGetValue(HKEY_LOCAL_MACHINE, acrobatPluginKeyPath.charactersWithNullTermination(), 0, &type, (LPBYTE)acrobatInstallPathStr, &acrobatInstallPathSize);
+
+ if (result == ERROR_SUCCESS) {
+ String acrobatPluginDirectory = String(acrobatInstallPathStr, acrobatInstallPathSize / sizeof(WCHAR) - 1) + "\\browser";
+ directories.append(acrobatPluginDirectory);
+ }
+ }
+
+ RegCloseKey(key);
+}
+
+static inline String safariPluginsDirectory()
+{
+ WCHAR moduleFileNameStr[_MAX_PATH];
+ static String pluginsDirectory;
+ static bool cachedPluginDirectory = false;
+
+ if (!cachedPluginDirectory) {
+ cachedPluginDirectory = true;
+
+ int moduleFileNameLen = GetModuleFileName(0, moduleFileNameStr, _MAX_PATH);
+
+ if (!moduleFileNameLen || moduleFileNameLen == _MAX_PATH)
+ goto exit;
+
+ if (!PathRemoveFileSpec(moduleFileNameStr))
+ goto exit;
+
+ pluginsDirectory = String(moduleFileNameStr) + "\\Plugins";
+ }
+exit:
+ return pluginsDirectory;
+}
+
+static inline void addMacromediaPluginDirectories(Vector<String>& directories)
+{
+ WCHAR systemDirectoryStr[MAX_PATH];
+
+ if (GetSystemDirectory(systemDirectoryStr, _countof(systemDirectoryStr)) == 0)
+ return;
+
+ WCHAR macromediaDirectoryStr[MAX_PATH];
+
+ PathCombine(macromediaDirectoryStr, systemDirectoryStr, TEXT("macromed\\Flash"));
+ directories.append(macromediaDirectoryStr);
+
+ PathCombine(macromediaDirectoryStr, systemDirectoryStr, TEXT("macromed\\Shockwave 10"));
+ directories.append(macromediaDirectoryStr);
+}
+
+Vector<String> PluginDatabase::defaultPluginDirectories()
+{
+ Vector<String> directories;
+ String ourDirectory = safariPluginsDirectory();
+
+ if (!ourDirectory.isNull())
+ directories.append(ourDirectory);
+ addQuickTimePluginDirectory(directories);
+ addAdobeAcrobatPluginDirectory(directories);
+ addMozillaPluginDirectories(directories);
+ addWindowsMediaPlayerPluginDirectory(directories);
+ addMacromediaPluginDirectories(directories);
+
+ return directories;
+}
+
+bool PluginDatabase::isPreferredPluginDirectory(const String& directory)
+{
+ String ourDirectory = safariPluginsDirectory();
+
+ if (!ourDirectory.isNull() && !directory.isNull())
+ return ourDirectory == directory;
+
+ return false;
+}
+
+}
diff --git a/src/3rdparty/webkit/WebCore/plugins/win/PluginMessageThrottlerWin.cpp b/src/3rdparty/webkit/WebCore/plugins/win/PluginMessageThrottlerWin.cpp
new file mode 100644
index 0000000000..27bf5b9684
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/win/PluginMessageThrottlerWin.cpp
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
+ *
+ * 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 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 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 "PluginMessageThrottlerWin.h"
+
+#include "PluginView.h"
+#include <wtf/ASCIICType.h>
+
+using namespace WTF;
+
+namespace WebCore {
+
+static const double MessageThrottleTimeInterval = 0.001;
+
+PluginMessageThrottlerWin::PluginMessageThrottlerWin(PluginView* pluginView)
+ : m_back(0), m_front(0)
+ , m_pluginView(pluginView)
+ , m_messageThrottleTimer(this, &PluginMessageThrottlerWin::messageThrottleTimerFired)
+{
+ // Initialize the free list with our inline messages
+ for (unsigned i = 0; i < NumInlineMessages - 1; i++)
+ m_inlineMessages[i].next = &m_inlineMessages[i + 1];
+ m_inlineMessages[NumInlineMessages - 1].next = 0;
+ m_freeInlineMessages = &m_inlineMessages[0];
+}
+
+PluginMessageThrottlerWin::~PluginMessageThrottlerWin()
+{
+ PluginMessage* next;
+
+ for (PluginMessage* message = m_front; message; message = next) {
+ next = message->next;
+ freeMessage(message);
+ }
+}
+
+void PluginMessageThrottlerWin::appendMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ PluginMessage* message = allocateMessage();
+
+ message->hWnd = hWnd;
+ message->msg = msg;
+ message->wParam = wParam;
+ message->lParam = lParam;
+ message->next = 0;
+
+ if (m_back)
+ m_back->next = message;
+ m_back = message;
+ if (!m_front)
+ m_front = message;
+
+ if (!m_messageThrottleTimer.isActive())
+ m_messageThrottleTimer.startOneShot(MessageThrottleTimeInterval);
+}
+
+void PluginMessageThrottlerWin::messageThrottleTimerFired(Timer<PluginMessageThrottlerWin>*)
+{
+ PluginMessage* message = m_front;
+ m_front = m_front->next;
+ if (message == m_back)
+ m_back = 0;
+
+ ::CallWindowProc(m_pluginView->pluginWndProc(), message->hWnd, message->msg, message->wParam, message->lParam);
+
+ freeMessage(message);
+
+ if (m_front)
+ m_messageThrottleTimer.startOneShot(MessageThrottleTimeInterval);
+}
+
+PluginMessage* PluginMessageThrottlerWin::allocateMessage()
+{
+ PluginMessage *message;
+
+ if (m_freeInlineMessages) {
+ message = m_freeInlineMessages;
+ m_freeInlineMessages = message->next;
+ } else
+ message = new PluginMessage;
+
+ return message;
+}
+
+bool PluginMessageThrottlerWin::isInlineMessage(PluginMessage* message)
+{
+ return message >= &m_inlineMessages[0] && message <= &m_inlineMessages[NumInlineMessages - 1];
+}
+
+void PluginMessageThrottlerWin::freeMessage(PluginMessage* message)
+{
+ if (isInlineMessage(message)) {
+ message->next = m_freeInlineMessages;
+ m_freeInlineMessages = message;
+ } else
+ delete message;
+}
+
+} // namespace WebCore
diff --git a/src/3rdparty/webkit/WebCore/plugins/win/PluginMessageThrottlerWin.h b/src/3rdparty/webkit/WebCore/plugins/win/PluginMessageThrottlerWin.h
new file mode 100644
index 0000000000..c74beab8fa
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/win/PluginMessageThrottlerWin.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
+ *
+ * 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 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 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.
+ */
+
+#ifndef PluginMessageThrottlerWin_h
+#define PluginMessageThrottlerWin_h
+
+#include "Timer.h"
+
+#include <windows.h>
+
+namespace WebCore {
+ class PluginView;
+
+ struct PluginMessage {
+ HWND hWnd;
+ UINT msg;
+ WPARAM wParam;
+ LPARAM lParam;
+
+ struct PluginMessage* next;
+ };
+
+ class PluginMessageThrottlerWin {
+ public:
+ PluginMessageThrottlerWin(PluginView*);
+ ~PluginMessageThrottlerWin();
+
+ void appendMessage(HWND, UINT msg, WPARAM, LPARAM);
+
+ private:
+ void messageThrottleTimerFired(Timer<PluginMessageThrottlerWin>*);
+ PluginMessage* allocateMessage();
+ bool isInlineMessage(PluginMessage* message);
+ void freeMessage(PluginMessage* message);
+
+ PluginView* m_pluginView;
+ PluginMessage* m_back;
+ PluginMessage* m_front;
+
+ static const int NumInlineMessages = 4;
+ PluginMessage m_inlineMessages[NumInlineMessages];
+ PluginMessage* m_freeInlineMessages;
+
+ Timer<PluginMessageThrottlerWin> m_messageThrottleTimer;
+ };
+
+} // namespace WebCore
+
+#endif // PluginMessageThrottlerWin_h
diff --git a/src/3rdparty/webkit/WebCore/plugins/win/PluginPackageWin.cpp b/src/3rdparty/webkit/WebCore/plugins/win/PluginPackageWin.cpp
new file mode 100644
index 0000000000..fe9b544831
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/win/PluginPackageWin.cpp
@@ -0,0 +1,375 @@
+/*
+ * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
+ *
+ * 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 "PluginPackage.h"
+
+#include "CString.h"
+#include "MIMETypeRegistry.h"
+#include "PluginDatabase.h"
+#include "PluginDebug.h"
+#include "Timer.h"
+#include "npruntime_impl.h"
+#include <string.h>
+#include <wtf/OwnArrayPtr.h>
+#include <shlwapi.h>
+
+namespace WebCore {
+
+static String getVersionInfo(const LPVOID versionInfoData, const String& info)
+{
+ LPVOID buffer;
+ UINT bufferLength;
+ String subInfo = "\\StringfileInfo\\040904E4\\" + info;
+ bool retval = VerQueryValueW(versionInfoData,
+ const_cast<UChar*>(subInfo.charactersWithNullTermination()),
+ &buffer, &bufferLength);
+ if (!retval || bufferLength == 0)
+ return String();
+
+ // Subtract 1 from the length; we don't want the trailing null character.
+ return String(reinterpret_cast<UChar*>(buffer), bufferLength - 1);
+}
+
+int PluginPackage::compareFileVersion(const PlatformModuleVersion& compareVersion) const
+{
+ // return -1, 0, or 1 if plug-in version is less than, equal to, or greater than
+ // the passed version
+ if (m_moduleVersion.mostSig != compareVersion.mostSig)
+ return m_moduleVersion.mostSig > compareVersion.mostSig ? 1 : -1;
+ if (m_moduleVersion.leastSig != compareVersion.leastSig)
+ return m_moduleVersion.leastSig > compareVersion.leastSig ? 1 : -1;
+ return 0;
+}
+
+bool PluginPackage::isPluginBlacklisted()
+{
+ if (name() == "Silverlight Plug-In") {
+ // workaround for <rdar://5557379> Crash in Silverlight when opening microsoft.com.
+ // the latest 1.0 version of Silverlight does not reproduce this crash, so allow it
+ // and any newer versions
+ static const PlatformModuleVersion slPluginMinRequired(0x51BE0000, 0x00010000);
+
+ if (compareFileVersion(slPluginMinRequired) < 0)
+ return true;
+ } else if (fileName() == "npmozax.dll")
+ // Bug 15217: Mozilla ActiveX control complains about missing xpcom_core.dll
+ return true;
+
+ return false;
+}
+
+void PluginPackage::determineQuirks(const String& mimeType)
+{
+ if (mimeType == "application/x-shockwave-flash") {
+ static const PlatformModuleVersion flashTenVersion(0x00000000, 0x000a0000);
+
+ // Pre 10 Flash only requests windowless plugins if we return a mozilla user agent
+ if (compareFileVersion(flashTenVersion) < 0)
+ m_quirks.add(PluginQuirkWantsMozillaUserAgent);
+
+ m_quirks.add(PluginQuirkThrottleInvalidate);
+ m_quirks.add(PluginQuirkThrottleWMUserPlusOneMessages);
+ m_quirks.add(PluginQuirkFlashURLNotifyBug);
+ }
+
+ if (name().contains("Microsoft") && name().contains("Windows Media")) {
+ // The WMP plugin sets its size on the first NPP_SetWindow call and never updates its size, so
+ // call SetWindow when the plugin view has a correct size
+ m_quirks.add(PluginQuirkDeferFirstSetWindowCall);
+
+ // Windowless mode does not work at all with the WMP plugin so just remove that parameter
+ // and don't pass it to the plug-in.
+ m_quirks.add(PluginQuirkRemoveWindowlessVideoParam);
+
+ // WMP has a modal message loop that it enters whenever we call it or
+ // ask it to paint. This modal loop can deliver messages to other
+ // windows in WebKit at times when they are not expecting them (for
+ // example, delivering a WM_PAINT message during a layout), and these
+ // can cause crashes.
+ m_quirks.add(PluginQuirkHasModalMessageLoop);
+ }
+
+ if (name() == "VLC Multimedia Plugin") {
+ // VLC hangs on NPP_Destroy if we call NPP_SetWindow with a null window handle
+ m_quirks.add(PluginQuirkDontSetNullWindowHandleOnDestroy);
+
+ // VLC 0.8.6d and 0.8.6e crash if multiple instances are created.
+ // <rdar://problem/5773070> tracks allowing multiple instances when this
+ // bug is fixed.
+ m_quirks.add(PluginQuirkDontAllowMultipleInstances);
+ }
+
+ // The DivX plugin sets its size on the first NPP_SetWindow call and never updates its size, so
+ // call SetWindow when the plugin view has a correct size
+ if (mimeType == "video/divx")
+ m_quirks.add(PluginQuirkDeferFirstSetWindowCall);
+
+ // FIXME: This is a workaround for a problem in our NPRuntime bindings; if a plug-in creates an
+ // NPObject and passes it to a function it's not possible to see what root object that NPObject belongs to.
+ // Thus, we don't know that the object should be invalidated when the plug-in instance goes away.
+ // See <rdar://problem/5487742>.
+ if (mimeType == "application/x-silverlight")
+ m_quirks.add(PluginQuirkDontUnloadPlugin);
+
+ if (MIMETypeRegistry::isJavaAppletMIMEType(mimeType)) {
+ // Because a single process cannot create multiple VMs, and we cannot reliably unload a
+ // Java VM, we cannot unload the Java plugin, or we'll lose reference to our only VM
+ m_quirks.add(PluginQuirkDontUnloadPlugin);
+
+ // Setting the window region to an empty region causes bad scrolling repaint problems
+ // with the Java plug-in.
+ m_quirks.add(PluginQuirkDontClipToZeroRectWhenScrolling);
+ }
+
+ if (mimeType == "audio/x-pn-realaudio-plugin") {
+ // Prevent the Real plugin from calling the Window Proc recursively, causing the stack to overflow.
+ m_quirks.add(PluginQuirkDontCallWndProcForSameMessageRecursively);
+
+ static const PlatformModuleVersion lastKnownUnloadableRealPlayerVersion(0x000B0B24, 0x00060000);
+
+ // Unloading RealPlayer versions newer than 10.5 can cause a hang; see rdar://5669317.
+ // FIXME: Resume unloading when this bug in the RealPlayer Plug-In is fixed (rdar://5713147)
+ if (compareFileVersion(lastKnownUnloadableRealPlayerVersion) > 0)
+ m_quirks.add(PluginQuirkDontUnloadPlugin);
+ }
+}
+
+bool PluginPackage::fetchInfo()
+{
+ DWORD versionInfoSize, zeroHandle;
+ versionInfoSize = GetFileVersionInfoSizeW(const_cast<UChar*>(m_path.charactersWithNullTermination()), &zeroHandle);
+ if (versionInfoSize == 0)
+ return false;
+
+ OwnArrayPtr<char> versionInfoData(new char[versionInfoSize]);
+
+ if (!GetFileVersionInfoW(const_cast<UChar*>(m_path.charactersWithNullTermination()),
+ 0, versionInfoSize, versionInfoData.get()))
+ return false;
+
+ m_name = getVersionInfo(versionInfoData.get(), "ProductName");
+ m_description = getVersionInfo(versionInfoData.get(), "FileDescription");
+ if (m_name.isNull() || m_description.isNull())
+ return false;
+
+ VS_FIXEDFILEINFO* info;
+ UINT infoSize;
+ if (!VerQueryValue(versionInfoData.get(), TEXT("\\"), (LPVOID*) &info, &infoSize) || infoSize < sizeof(VS_FIXEDFILEINFO))
+ return false;
+ m_moduleVersion.leastSig = info->dwFileVersionLS;
+ m_moduleVersion.mostSig = info->dwFileVersionMS;
+
+ if (isPluginBlacklisted())
+ return false;
+
+ Vector<String> types;
+ getVersionInfo(versionInfoData.get(), "MIMEType").split('|', types);
+ Vector<String> extensionLists;
+ getVersionInfo(versionInfoData.get(), "FileExtents").split('|', extensionLists);
+ Vector<String> descriptions;
+ getVersionInfo(versionInfoData.get(), "FileOpenName").split('|', descriptions);
+
+ for (unsigned i = 0; i < types.size(); i++) {
+ String type = types[i].lower();
+ String description = i < descriptions.size() ? descriptions[i] : "";
+ String extensionList = i < extensionLists.size() ? extensionLists[i] : "";
+
+ Vector<String> extensionsVector;
+ extensionList.split(',', extensionsVector);
+
+ // Get rid of the extension list that may be at the end of the description string.
+ int pos = description.find("(*");
+ if (pos != -1) {
+ // There might be a space that we need to get rid of.
+ if (pos > 1 && description[pos - 1] == ' ')
+ pos--;
+ description = description.left(pos);
+ }
+
+ // Determine the quirks for the MIME types this plug-in supports
+ determineQuirks(type);
+
+ m_mimeToExtensions.add(type, extensionsVector);
+ m_mimeToDescriptions.add(type, description);
+ }
+
+ return true;
+}
+
+bool PluginPackage::load()
+{
+ if (m_freeLibraryTimer.isActive()) {
+ ASSERT(m_module);
+ m_freeLibraryTimer.stop();
+ } else if (m_isLoaded) {
+ if (m_quirks.contains(PluginQuirkDontAllowMultipleInstances))
+ return false;
+ m_loadCount++;
+ return true;
+ } else {
+ WCHAR currentPath[MAX_PATH];
+
+ if (!::GetCurrentDirectoryW(MAX_PATH, currentPath))
+ return false;
+
+ String path = m_path.substring(0, m_path.reverseFind('\\'));
+
+ if (!::SetCurrentDirectoryW(path.charactersWithNullTermination()))
+ return false;
+
+ // Load the library
+ m_module = ::LoadLibraryW(m_path.charactersWithNullTermination());
+
+ if (!::SetCurrentDirectoryW(currentPath)) {
+ if (m_module)
+ ::FreeLibrary(m_module);
+ return false;
+ }
+ }
+
+ if (!m_module)
+ return false;
+
+ m_isLoaded = true;
+
+ NP_GetEntryPointsFuncPtr NP_GetEntryPoints = 0;
+ NP_InitializeFuncPtr NP_Initialize = 0;
+ NPError npErr;
+
+ NP_Initialize = (NP_InitializeFuncPtr)GetProcAddress(m_module, "NP_Initialize");
+ NP_GetEntryPoints = (NP_GetEntryPointsFuncPtr)GetProcAddress(m_module, "NP_GetEntryPoints");
+ m_NPP_Shutdown = (NPP_ShutdownProcPtr)GetProcAddress(m_module, "NP_Shutdown");
+
+ if (!NP_Initialize || !NP_GetEntryPoints || !m_NPP_Shutdown)
+ goto abort;
+
+ memset(&m_pluginFuncs, 0, sizeof(m_pluginFuncs));
+ m_pluginFuncs.size = sizeof(m_pluginFuncs);
+
+ npErr = NP_GetEntryPoints(&m_pluginFuncs);
+ LOG_NPERROR(npErr);
+ if (npErr != NPERR_NO_ERROR)
+ goto abort;
+
+ memset(&m_browserFuncs, 0, sizeof(m_browserFuncs));
+ m_browserFuncs.size = sizeof (m_browserFuncs);
+ m_browserFuncs.version = NP_VERSION_MINOR;
+
+ m_browserFuncs.geturl = NPN_GetURL;
+ m_browserFuncs.posturl = NPN_PostURL;
+ m_browserFuncs.requestread = NPN_RequestRead;
+ m_browserFuncs.newstream = NPN_NewStream;
+ m_browserFuncs.write = NPN_Write;
+ m_browserFuncs.destroystream = NPN_DestroyStream;
+ m_browserFuncs.status = NPN_Status;
+ m_browserFuncs.uagent = NPN_UserAgent;
+ m_browserFuncs.memalloc = NPN_MemAlloc;
+ m_browserFuncs.memfree = NPN_MemFree;
+ m_browserFuncs.memflush = NPN_MemFlush;
+ m_browserFuncs.reloadplugins = NPN_ReloadPlugins;
+ m_browserFuncs.geturlnotify = NPN_GetURLNotify;
+ m_browserFuncs.posturlnotify = NPN_PostURLNotify;
+ m_browserFuncs.getvalue = NPN_GetValue;
+ m_browserFuncs.setvalue = NPN_SetValue;
+ m_browserFuncs.invalidaterect = NPN_InvalidateRect;
+ m_browserFuncs.invalidateregion = NPN_InvalidateRegion;
+ m_browserFuncs.forceredraw = NPN_ForceRedraw;
+ m_browserFuncs.getJavaEnv = NPN_GetJavaEnv;
+ m_browserFuncs.getJavaPeer = NPN_GetJavaPeer;
+ m_browserFuncs.pushpopupsenabledstate = NPN_PushPopupsEnabledState;
+ m_browserFuncs.poppopupsenabledstate = NPN_PopPopupsEnabledState;
+ m_browserFuncs.pluginthreadasynccall = NPN_PluginThreadAsyncCall;
+
+ m_browserFuncs.releasevariantvalue = _NPN_ReleaseVariantValue;
+ m_browserFuncs.getstringidentifier = _NPN_GetStringIdentifier;
+ m_browserFuncs.getstringidentifiers = _NPN_GetStringIdentifiers;
+ m_browserFuncs.getintidentifier = _NPN_GetIntIdentifier;
+ m_browserFuncs.identifierisstring = _NPN_IdentifierIsString;
+ m_browserFuncs.utf8fromidentifier = _NPN_UTF8FromIdentifier;
+ m_browserFuncs.intfromidentifier = _NPN_IntFromIdentifier;
+ m_browserFuncs.createobject = _NPN_CreateObject;
+ m_browserFuncs.retainobject = _NPN_RetainObject;
+ m_browserFuncs.releaseobject = _NPN_ReleaseObject;
+ m_browserFuncs.invoke = _NPN_Invoke;
+ m_browserFuncs.invokeDefault = _NPN_InvokeDefault;
+ m_browserFuncs.evaluate = _NPN_Evaluate;
+ m_browserFuncs.getproperty = _NPN_GetProperty;
+ m_browserFuncs.setproperty = _NPN_SetProperty;
+ m_browserFuncs.removeproperty = _NPN_RemoveProperty;
+ m_browserFuncs.hasproperty = _NPN_HasProperty;
+ m_browserFuncs.hasmethod = _NPN_HasMethod;
+ m_browserFuncs.setexception = _NPN_SetException;
+ m_browserFuncs.enumerate = _NPN_Enumerate;
+ m_browserFuncs.construct = _NPN_Construct;
+
+ npErr = NP_Initialize(&m_browserFuncs);
+ LOG_NPERROR(npErr);
+
+ if (npErr != NPERR_NO_ERROR)
+ goto abort;
+
+ m_loadCount++;
+ return true;
+
+abort:
+ unloadWithoutShutdown();
+ return false;
+}
+
+unsigned PluginPackage::hash() const
+{
+ const unsigned hashCodes[] = {
+ m_name.impl()->hash(),
+ m_description.impl()->hash(),
+ m_mimeToExtensions.size()
+ };
+
+ return StringImpl::computeHash(reinterpret_cast<const UChar*>(hashCodes), sizeof(hashCodes) / sizeof(UChar));
+}
+
+bool PluginPackage::equal(const PluginPackage& a, const PluginPackage& b)
+{
+ if (a.m_name != b.m_name)
+ return false;
+
+ if (a.m_description != b.m_description)
+ return false;
+
+ if (a.m_mimeToExtensions.size() != b.m_mimeToExtensions.size())
+ return false;
+
+ MIMEToExtensionsMap::const_iterator::Keys end = a.m_mimeToExtensions.end().keys();
+ for (MIMEToExtensionsMap::const_iterator::Keys it = a.m_mimeToExtensions.begin().keys(); it != end; ++it) {
+ if (!b.m_mimeToExtensions.contains(*it))
+ return false;
+ }
+
+ return true;
+}
+
+}
diff --git a/src/3rdparty/webkit/WebCore/plugins/win/PluginViewWin.cpp b/src/3rdparty/webkit/WebCore/plugins/win/PluginViewWin.cpp
new file mode 100644
index 0000000000..722262bb0f
--- /dev/null
+++ b/src/3rdparty/webkit/WebCore/plugins/win/PluginViewWin.cpp
@@ -0,0 +1,841 @@
+/*
+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Collabora Ltd. All rights reserved.
+ *
+ * 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 "Document.h"
+#include "DocumentLoader.h"
+#include "Element.h"
+#include "EventNames.h"
+#include "FrameLoader.h"
+#include "FrameLoadRequest.h"
+#include "FrameTree.h"
+#include "Frame.h"
+#include "FrameView.h"
+#include "GraphicsContext.h"
+#include "Image.h"
+#include "HTMLNames.h"
+#include "HTMLPlugInElement.h"
+#include "JSDOMWindow.h"
+#include "KeyboardEvent.h"
+#include "MIMETypeRegistry.h"
+#include "MouseEvent.h"
+#include "NotImplemented.h"
+#include "Page.h"
+#include "FocusController.h"
+#include "PlatformMouseEvent.h"
+#include "PluginMessageThrottlerWin.h"
+#include "PluginPackage.h"
+#include "PluginMainThreadScheduler.h"
+#include "JSDOMBinding.h"
+#include "ScriptController.h"
+#include "PluginDatabase.h"
+#include "PluginDebug.h"
+#include "PluginPackage.h"
+#include "c_instance.h"
+#include "npruntime_impl.h"
+#include "runtime_root.h"
+#include "Settings.h"
+#include "runtime.h"
+#include <runtime/JSLock.h>
+#include <runtime/JSValue.h>
+#include <wtf/ASCIICType.h>
+
+#if PLATFORM(QT)
+#include <QWidget.h>
+#endif
+
+static inline HWND windowHandleForPlatformWidget(PlatformWidget widget)
+{
+#if PLATFORM(QT)
+ if (!widget)
+ return 0;
+ return widget->winId();
+#else
+ return widget;
+#endif
+}
+
+using JSC::ExecState;
+using JSC::JSLock;
+using JSC::JSObject;
+using JSC::UString;
+
+using std::min;
+
+using namespace WTF;
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+const LPCWSTR kWebPluginViewdowClassName = L"WebPluginView";
+const LPCWSTR kWebPluginViewProperty = L"WebPluginViewProperty";
+
+static const char* MozillaUserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0";
+
+static bool registerPluginView()
+{
+ static bool haveRegisteredWindowClass = false;
+ if (haveRegisteredWindowClass)
+ return true;
+
+ haveRegisteredWindowClass = true;
+
+#if PLATFORM(QT)
+ Page::setInstanceHandle((HINSTANCE)(qWinAppInst()));
+#endif
+
+ ASSERT(Page::instanceHandle());
+
+ WNDCLASSEX wcex;
+
+ wcex.cbSize = sizeof(WNDCLASSEX);
+
+ wcex.style = CS_DBLCLKS;
+ wcex.lpfnWndProc = DefWindowProc;
+ wcex.cbClsExtra = 0;
+ wcex.cbWndExtra = 0;
+ wcex.hInstance = Page::instanceHandle();
+ wcex.hIcon = 0;
+ wcex.hCursor = LoadCursor(0, IDC_ARROW);
+ wcex.hbrBackground = (HBRUSH)COLOR_WINDOW;
+ wcex.lpszMenuName = 0;
+ wcex.lpszClassName = kWebPluginViewdowClassName;
+ wcex.hIconSm = 0;
+
+ return !!RegisterClassEx(&wcex);
+}
+
+LRESULT CALLBACK PluginView::PluginViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ PluginView* pluginView = reinterpret_cast<PluginView*>(GetProp(hWnd, kWebPluginViewProperty));
+
+ return pluginView->wndProc(hWnd, message, wParam, lParam);
+}
+
+static bool isWindowsMessageUserGesture(UINT message)
+{
+ switch (message) {
+ case WM_LBUTTONUP:
+ case WM_MBUTTONUP:
+ case WM_RBUTTONUP:
+ case WM_KEYUP:
+ return true;
+ default:
+ return false;
+ }
+}
+
+LRESULT
+PluginView::wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ // <rdar://5711136> Sometimes Flash will call SetCapture before creating
+ // a full-screen window and will not release it, which causes the
+ // full-screen window to never receive mouse events. We set/release capture
+ // on mouse down/up before sending the event to the plug-in to prevent that.
+ switch (message) {
+ case WM_LBUTTONDOWN:
+ case WM_MBUTTONDOWN:
+ case WM_RBUTTONDOWN:
+ ::SetCapture(hWnd);
+ break;
+ case WM_LBUTTONUP:
+ case WM_MBUTTONUP:
+ case WM_RBUTTONUP:
+ ::ReleaseCapture();
+ break;
+ }
+
+ if (message == m_lastMessage &&
+ m_plugin->quirks().contains(PluginQuirkDontCallWndProcForSameMessageRecursively) &&
+ m_isCallingPluginWndProc)
+ return 1;
+
+ if (message == WM_USER + 1 &&
+ m_plugin->quirks().contains(PluginQuirkThrottleWMUserPlusOneMessages)) {
+ if (!m_messageThrottler)
+ m_messageThrottler.set(new PluginMessageThrottlerWin(this));
+
+ m_messageThrottler->appendMessage(hWnd, message, wParam, lParam);
+ return 0;
+ }
+
+ m_lastMessage = message;
+ m_isCallingPluginWndProc = true;
+
+ // If the plug-in doesn't explicitly support changing the pop-up state, we enable
+ // popups for all user gestures.
+ // Note that we need to pop the state in a timer, because the Flash plug-in
+ // pops up windows in response to a posted message.
+ if (m_plugin->pluginFuncs()->version < NPVERS_HAS_POPUPS_ENABLED_STATE &&
+ isWindowsMessageUserGesture(message) && !m_popPopupsStateTimer.isActive()) {
+
+ pushPopupsEnabledState(true);
+
+ m_popPopupsStateTimer.startOneShot(0);
+ }
+
+ // Call the plug-in's window proc.
+ LRESULT result = ::CallWindowProc(m_pluginWndProc, hWnd, message, wParam, lParam);
+
+ m_isCallingPluginWndProc = false;
+
+ return result;
+}
+
+void PluginView::updatePluginWidget()
+{
+ if (!parent())
+ return;
+
+ ASSERT(parent()->isFrameView());
+ FrameView* frameView = static_cast<FrameView*>(parent());
+
+ IntRect oldWindowRect = m_windowRect;
+ IntRect oldClipRect = m_clipRect;
+
+ m_windowRect = IntRect(frameView->contentsToWindow(frameRect().location()), frameRect().size());
+ m_clipRect = windowClipRect();
+ m_clipRect.move(-m_windowRect.x(), -m_windowRect.y());
+
+ if (platformPluginWidget() && (m_windowRect != oldWindowRect || m_clipRect != oldClipRect)) {
+ HRGN rgn;
+
+ setCallingPlugin(true);
+
+ // To prevent flashes while scrolling, we disable drawing during the window
+ // update process by clipping the window to the zero rect.
+
+ bool clipToZeroRect = !m_plugin->quirks().contains(PluginQuirkDontClipToZeroRectWhenScrolling);
+
+ if (clipToZeroRect) {
+ rgn = ::CreateRectRgn(0, 0, 0, 0);
+ ::SetWindowRgn(platformPluginWidget(), rgn, FALSE);
+ } else {
+ rgn = ::CreateRectRgn(m_clipRect.x(), m_clipRect.y(), m_clipRect.right(), m_clipRect.bottom());
+ ::SetWindowRgn(platformPluginWidget(), rgn, TRUE);
+ }
+
+ if (m_windowRect != oldWindowRect)
+ ::MoveWindow(platformPluginWidget(), m_windowRect.x(), m_windowRect.y(), m_windowRect.width(), m_windowRect.height(), TRUE);
+
+ if (clipToZeroRect) {
+ rgn = ::CreateRectRgn(m_clipRect.x(), m_clipRect.y(), m_clipRect.right(), m_clipRect.bottom());
+ ::SetWindowRgn(platformPluginWidget(), rgn, TRUE);
+ }
+
+ setCallingPlugin(false);
+ }
+}
+
+void PluginView::setFocus()
+{
+ if (platformPluginWidget())
+ SetFocus(platformPluginWidget());
+
+ Widget::setFocus();
+}
+
+void PluginView::show()
+{
+ setSelfVisible(true);
+
+ if (isParentVisible() && platformPluginWidget())
+ ShowWindow(platformPluginWidget(), SW_SHOWNA);
+
+ Widget::show();
+}
+
+void PluginView::hide()
+{
+ setSelfVisible(false);
+
+ if (isParentVisible() && platformPluginWidget())
+ ShowWindow(platformPluginWidget(), SW_HIDE);
+
+ Widget::hide();
+}
+
+bool PluginView::dispatchNPEvent(NPEvent& npEvent)
+{
+ if (!m_plugin->pluginFuncs()->event)
+ return true;
+
+ bool shouldPop = false;
+
+ if (m_plugin->pluginFuncs()->version < NPVERS_HAS_POPUPS_ENABLED_STATE && isWindowsMessageUserGesture(npEvent.event)) {
+ pushPopupsEnabledState(true);
+ shouldPop = true;
+ }
+
+ JSC::JSLock::DropAllLocks dropAllLocks(false);
+ setCallingPlugin(true);
+ bool result = m_plugin->pluginFuncs()->event(m_instance, &npEvent);
+ setCallingPlugin(false);
+
+ if (shouldPop)
+ popPopupsEnabledState();
+
+ return result;
+}
+
+void PluginView::paint(GraphicsContext* context, const IntRect& rect)
+{
+ if (!m_isStarted) {
+ // Draw the "missing plugin" image
+ paintMissingPluginIcon(context, rect);
+ return;
+ }
+
+ if (m_isWindowed || context->paintingDisabled())
+ return;
+
+ ASSERT(parent()->isFrameView());
+ IntRect rectInWindow = static_cast<FrameView*>(parent())->contentsToWindow(frameRect());
+ HDC hdc = context->getWindowsContext(rectInWindow, m_isTransparent);
+ NPEvent npEvent;
+
+ // On Safari/Windows without transparency layers the GraphicsContext returns the HDC
+ // of the window and the plugin expects that the passed in DC has window coordinates.
+ // In the Qt port we always draw in an offscreen buffer and therefore need to preserve
+ // the translation set in getWindowsContext.
+#if !PLATFORM(QT)
+ if (!context->inTransparencyLayer()) {
+ XFORM transform;
+ GetWorldTransform(hdc, &transform);
+ transform.eDx = 0;
+ transform.eDy = 0;
+ SetWorldTransform(hdc, &transform);
+ }
+#endif
+
+ m_npWindow.type = NPWindowTypeDrawable;
+ m_npWindow.window = hdc;
+
+ IntPoint p = static_cast<FrameView*>(parent())->contentsToWindow(frameRect().location());
+
+ WINDOWPOS windowpos;
+ memset(&windowpos, 0, sizeof(windowpos));
+
+ windowpos.x = p.x();
+ windowpos.y = p.y();
+ windowpos.cx = frameRect().width();
+ windowpos.cy = frameRect().height();
+
+ npEvent.event = WM_WINDOWPOSCHANGED;
+ npEvent.lParam = reinterpret_cast<uint32>(&windowpos);
+ npEvent.wParam = 0;
+
+ dispatchNPEvent(npEvent);
+
+ setNPWindowRect(frameRect());
+
+ npEvent.event = WM_PAINT;
+ npEvent.wParam = reinterpret_cast<uint32>(hdc);
+
+ // This is supposed to be a pointer to the dirty rect, but it seems that the Flash plugin
+ // ignores it so we just pass null.
+ npEvent.lParam = 0;
+
+ dispatchNPEvent(npEvent);
+
+ context->releaseWindowsContext(hdc, frameRect(), m_isTransparent);
+}
+
+void PluginView::handleKeyboardEvent(KeyboardEvent* event)
+{
+ NPEvent npEvent;
+
+ npEvent.wParam = event->keyCode();
+
+ if (event->type() == eventNames().keydownEvent) {
+ npEvent.event = WM_KEYDOWN;
+ npEvent.lParam = 0;
+ } else if (event->type() == eventNames().keyupEvent) {
+ npEvent.event = WM_KEYUP;
+ npEvent.lParam = 0x8000;
+ }
+
+ JSC::JSLock::DropAllLocks dropAllLocks(false);
+ if (!dispatchNPEvent(npEvent))
+ event->setDefaultHandled();
+}
+
+extern HCURSOR lastSetCursor;
+extern bool ignoreNextSetCursor;
+
+void PluginView::handleMouseEvent(MouseEvent* event)
+{
+ NPEvent npEvent;
+
+ IntPoint p = static_cast<FrameView*>(parent())->contentsToWindow(IntPoint(event->pageX(), event->pageY()));
+
+ npEvent.lParam = MAKELPARAM(p.x(), p.y());
+ npEvent.wParam = 0;
+
+ if (event->ctrlKey())
+ npEvent.wParam |= MK_CONTROL;
+ if (event->shiftKey())
+ npEvent.wParam |= MK_SHIFT;
+
+ if (event->type() == eventNames().mousemoveEvent ||
+ event->type() == eventNames().mouseoutEvent ||
+ event->type() == eventNames().mouseoverEvent) {
+ npEvent.event = WM_MOUSEMOVE;
+ if (event->buttonDown())
+ switch (event->button()) {
+ case LeftButton:
+ npEvent.wParam |= MK_LBUTTON;
+ break;
+ case MiddleButton:
+ npEvent.wParam |= MK_MBUTTON;
+ break;
+ case RightButton:
+ npEvent.wParam |= MK_RBUTTON;
+ break;
+ }
+ }
+ else if (event->type() == eventNames().mousedownEvent) {
+ // Focus the plugin
+ if (Page* page = m_parentFrame->page())
+ page->focusController()->setFocusedFrame(m_parentFrame);
+ m_parentFrame->document()->setFocusedNode(m_element);
+ switch (event->button()) {
+ case 0:
+ npEvent.event = WM_LBUTTONDOWN;
+ break;
+ case 1:
+ npEvent.event = WM_MBUTTONDOWN;
+ break;
+ case 2:
+ npEvent.event = WM_RBUTTONDOWN;
+ break;
+ }
+ } else if (event->type() == eventNames().mouseupEvent) {
+ switch (event->button()) {
+ case 0:
+ npEvent.event = WM_LBUTTONUP;
+ break;
+ case 1:
+ npEvent.event = WM_MBUTTONUP;
+ break;
+ case 2:
+ npEvent.event = WM_RBUTTONUP;
+ break;
+ }
+ } else
+ return;
+
+ HCURSOR currentCursor = ::GetCursor();
+
+ JSC::JSLock::DropAllLocks dropAllLocks(false);
+ if (!dispatchNPEvent(npEvent))
+ event->setDefaultHandled();
+
+#if !PLATFORM(QT)
+ // Currently, Widget::setCursor is always called after this function in EventHandler.cpp
+ // and since we don't want that we set ignoreNextSetCursor to true here to prevent that.
+ ignoreNextSetCursor = true;
+ lastSetCursor = ::GetCursor();
+#endif
+}
+
+void PluginView::setParent(ScrollView* parent)
+{
+ Widget::setParent(parent);
+
+ if (parent)
+ init();
+ else {
+ if (!platformPluginWidget())
+ return;
+
+ // If the plug-in window or one of its children have the focus, we need to
+ // clear it to prevent the web view window from being focused because that can
+ // trigger a layout while the plugin element is being detached.
+ HWND focusedWindow = ::GetFocus();
+ if (platformPluginWidget() == focusedWindow || ::IsChild(platformPluginWidget(), focusedWindow))
+ ::SetFocus(0);
+ }
+
+}
+
+void PluginView::setParentVisible(bool visible)
+{
+ if (isParentVisible() == visible)
+ return;
+
+ Widget::setParentVisible(visible);
+
+ if (isSelfVisible() && platformPluginWidget()) {
+ if (visible)
+ ShowWindow(platformPluginWidget(), SW_SHOWNA);
+ else
+ ShowWindow(platformPluginWidget(), SW_HIDE);
+ }
+}
+
+void PluginView::setNPWindowRect(const IntRect& rect)
+{
+ if (!m_isStarted)
+ return;
+
+ IntPoint p = static_cast<FrameView*>(parent())->contentsToWindow(rect.location());
+ m_npWindow.x = p.x();
+ m_npWindow.y = p.y();
+
+ m_npWindow.width = rect.width();
+ m_npWindow.height = rect.height();
+
+ m_npWindow.clipRect.left = 0;
+ m_npWindow.clipRect.top = 0;
+ m_npWindow.clipRect.right = rect.width();
+ m_npWindow.clipRect.bottom = rect.height();
+
+ if (m_plugin->pluginFuncs()->setwindow) {
+ JSC::JSLock::DropAllLocks dropAllLocks(false);
+ setCallingPlugin(true);
+ m_plugin->pluginFuncs()->setwindow(m_instance, &m_npWindow);
+ setCallingPlugin(false);
+
+ if (!m_isWindowed)
+ return;
+
+ ASSERT(platformPluginWidget());
+
+ WNDPROC currentWndProc = (WNDPROC)GetWindowLongPtr(platformPluginWidget(), GWLP_WNDPROC);
+ if (currentWndProc != PluginViewWndProc)
+ m_pluginWndProc = (WNDPROC)SetWindowLongPtr(platformPluginWidget(), GWLP_WNDPROC, (LONG)PluginViewWndProc);
+ }
+}
+
+void PluginView::stop()
+{
+ if (!m_isStarted)
+ return;
+
+ HashSet<RefPtr<PluginStream> > streams = m_streams;
+ HashSet<RefPtr<PluginStream> >::iterator end = streams.end();
+ for (HashSet<RefPtr<PluginStream> >::iterator it = streams.begin(); it != end; ++it) {
+ (*it)->stop();
+ disconnectStream((*it).get());
+ }
+
+ ASSERT(m_streams.isEmpty());
+
+ m_isStarted = false;
+
+ // Unsubclass the window
+ if (m_isWindowed) {
+ WNDPROC currentWndProc = (WNDPROC)GetWindowLongPtr(platformPluginWidget(), GWLP_WNDPROC);
+
+ if (currentWndProc == PluginViewWndProc)
+ SetWindowLongPtr(platformPluginWidget(), GWLP_WNDPROC, (LONG)m_pluginWndProc);
+ }
+
+ JSC::JSLock::DropAllLocks dropAllLocks(false);
+
+ // Clear the window
+ m_npWindow.window = 0;
+ if (m_plugin->pluginFuncs()->setwindow && !m_plugin->quirks().contains(PluginQuirkDontSetNullWindowHandleOnDestroy)) {
+ setCallingPlugin(true);
+ m_plugin->pluginFuncs()->setwindow(m_instance, &m_npWindow);
+ setCallingPlugin(false);
+ }
+
+ PluginMainThreadScheduler::scheduler().unregisterPlugin(m_instance);
+
+ // Destroy the plugin
+ NPSavedData* savedData = 0;
+ setCallingPlugin(true);
+ NPError npErr = m_plugin->pluginFuncs()->destroy(m_instance, &savedData);
+ setCallingPlugin(false);
+ LOG_NPERROR(npErr);
+
+ if (savedData) {
+ if (savedData->buf)
+ NPN_MemFree(savedData->buf);
+ NPN_MemFree(savedData);
+ }
+
+ m_instance->pdata = 0;
+}
+
+const char* PluginView::userAgentStatic()
+{
+ return 0;
+}
+
+const char* PluginView::userAgent()
+{
+ if (m_plugin->quirks().contains(PluginQuirkWantsMozillaUserAgent))
+ return MozillaUserAgent;
+
+ if (m_userAgent.isNull())
+ m_userAgent = m_parentFrame->loader()->userAgent(m_url).utf8();
+ return m_userAgent.data();
+}
+
+NPError PluginView::handlePostReadFile(Vector<char>& buffer, uint32 len, const char* buf)
+{
+ String filename(buf, len);
+
+ if (filename.startsWith("file:///"))
+ filename = filename.substring(8);
+
+ // Get file info
+ WIN32_FILE_ATTRIBUTE_DATA attrs;
+ if (GetFileAttributesExW(filename.charactersWithNullTermination(), GetFileExInfoStandard, &attrs) == 0)
+ return NPERR_FILE_NOT_FOUND;
+
+ if (attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ return NPERR_FILE_NOT_FOUND;
+
+ HANDLE fileHandle = CreateFileW(filename.charactersWithNullTermination(), FILE_READ_DATA, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
+
+ if (fileHandle == INVALID_HANDLE_VALUE)
+ return NPERR_FILE_NOT_FOUND;
+
+ buffer.resize(attrs.nFileSizeLow);
+
+ DWORD bytesRead;
+ int retval = ReadFile(fileHandle, buffer.data(), attrs.nFileSizeLow, &bytesRead, 0);
+
+ CloseHandle(fileHandle);
+
+ if (retval == 0 || bytesRead != attrs.nFileSizeLow)
+ return NPERR_FILE_NOT_FOUND;
+
+ return NPERR_NO_ERROR;
+}
+
+NPError PluginView::getValueStatic(NPNVariable variable, void* value)
+{
+ return NPERR_GENERIC_ERROR;
+}
+
+NPError PluginView::getValue(NPNVariable variable, void* value)
+{
+ switch (variable) {
+#if ENABLE(NETSCAPE_PLUGIN_API)
+ case NPNVWindowNPObject: {
+ if (m_isJavaScriptPaused)
+ return NPERR_GENERIC_ERROR;
+
+ 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);
+
+ void** v = (void**)value;
+ *v = windowScriptObject;
+
+ return NPERR_NO_ERROR;
+ }
+
+ case NPNVPluginElementNPObject: {
+ if (m_isJavaScriptPaused)
+ return NPERR_GENERIC_ERROR;
+
+ 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);
+
+ void** v = (void**)value;
+ *v = pluginScriptObject;
+
+ return NPERR_NO_ERROR;
+ }
+#endif
+
+ case NPNVnetscapeWindow: {
+ HWND* w = reinterpret_cast<HWND*>(value);
+
+ *w = windowHandleForPlatformWidget(parent() ? parent()->hostWindow()->platformWindow() : 0);
+
+ return NPERR_NO_ERROR;
+ }
+
+ case NPNVSupportsWindowless: {
+ NPBool *result = reinterpret_cast<NPBool*>(value);
+
+ *result = TRUE;
+
+ return NPERR_NO_ERROR;
+ }
+
+ default:
+ return NPERR_GENERIC_ERROR;
+ }
+}
+
+void PluginView::invalidateRect(const IntRect& rect)
+{
+ if (m_isWindowed) {
+ RECT invalidRect = { rect.x(), rect.y(), rect.right(), rect.bottom() };
+ ::InvalidateRect(platformPluginWidget(), &invalidRect, false);
+ return;
+ }
+
+ invalidateWindowlessPluginRect(rect);
+}
+
+void PluginView::invalidateRect(NPRect* rect)
+{
+ if (!rect) {
+ invalidate();
+ return;
+ }
+
+ IntRect r(rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top);
+
+ if (m_isWindowed) {
+ RECT invalidRect = { r.x(), r.y(), r.right(), r.bottom() };
+ InvalidateRect(platformPluginWidget(), &invalidRect, FALSE);
+ } else {
+ if (m_plugin->quirks().contains(PluginQuirkThrottleInvalidate)) {
+ m_invalidRects.append(r);
+ if (!m_invalidateTimer.isActive())
+ m_invalidateTimer.startOneShot(0.001);
+ } else
+ invalidateRect(r);
+ }
+}
+
+void PluginView::invalidateRegion(NPRegion region)
+{
+ if (m_isWindowed)
+ return;
+
+ RECT r;
+
+ if (GetRgnBox(region, &r) == 0) {
+ invalidate();
+ return;
+ }
+
+ IntRect rect(IntPoint(r.left, r.top), IntSize(r.right-r.left, r.bottom-r.top));
+ invalidateRect(rect);
+}
+
+void PluginView::forceRedraw()
+{
+ if (m_isWindowed)
+ ::UpdateWindow(platformPluginWidget());
+ else
+ ::UpdateWindow(windowHandleForPlatformWidget(parent() ? parent()->hostWindow()->platformWindow() : 0));
+}
+
+PluginView::~PluginView()
+{
+ if (m_instance)
+ m_instance->ndata = 0;
+ stop();
+
+ deleteAllValues(m_requests);
+
+ freeStringArray(m_paramNames, m_paramCount);
+ freeStringArray(m_paramValues, m_paramCount);
+
+ if (platformPluginWidget())
+ DestroyWindow(platformPluginWidget());
+
+ m_parentFrame->script()->cleanupScriptObjectsForPlugin(this);
+
+ if (m_plugin && !m_plugin->quirks().contains(PluginQuirkDontUnloadPlugin))
+ m_plugin->unload();
+}
+
+void PluginView::init()
+{
+ if (m_haveInitialized)
+ return;
+ m_haveInitialized = true;
+
+ if (!m_plugin) {
+ ASSERT(m_status == PluginStatusCanNotFindPlugin);
+ return;
+ }
+
+ if (!m_plugin->load()) {
+ m_plugin = 0;
+ m_status = PluginStatusCanNotLoadPlugin;
+ return;
+ }
+
+ if (!start()) {
+ m_status = PluginStatusCanNotLoadPlugin;
+ return;
+ }
+
+ if (m_isWindowed) {
+ registerPluginView();
+
+ DWORD flags = WS_CHILD;
+ if (isSelfVisible())
+ flags |= WS_VISIBLE;
+
+ HWND parentWindowHandle = windowHandleForPlatformWidget(m_parentFrame->view()->hostWindow()->platformWindow());
+ HWND window = ::CreateWindowEx(0, kWebPluginViewdowClassName, 0, flags,
+ 0, 0, 0, 0, parentWindowHandle, 0, Page::instanceHandle(), 0);
+#if PLATFORM(WIN_OS) && PLATFORM(QT)
+ m_window = window;
+#else
+ setPlatformWidget(window);
+#endif
+
+ // Calling SetWindowLongPtrA here makes the window proc ASCII, which is required by at least
+ // the Shockwave Director plug-in.
+#if PLATFORM(WIN_OS) && PLATFORM(X86_64) && COMPILER(MSVC)
+ ::SetWindowLongPtrA(platformPluginWidget(), GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
+#else
+ ::SetWindowLongPtrA(platformPluginWidget(), GWL_WNDPROC, (LONG)DefWindowProcA);
+#endif
+ SetProp(platformPluginWidget(), kWebPluginViewProperty, this);
+
+ m_npWindow.type = NPWindowTypeWindow;
+ m_npWindow.window = platformPluginWidget();
+ } else {
+ m_npWindow.type = NPWindowTypeDrawable;
+ m_npWindow.window = 0;
+ }
+
+ if (!m_plugin->quirks().contains(PluginQuirkDeferFirstSetWindowCall))
+ setNPWindowRect(frameRect());
+
+ m_status = PluginStatusLoadedSuccessfully;
+}
+
+} // namespace WebCore