This commit is contained in:
Ben Turner 2009-09-23 13:14:34 -07:00
Родитель 4a23a8bc9d 662fb82f1e
Коммит 9914a675f3
1054 изменённых файлов: 243012 добавлений и 78 удалений

Просмотреть файл

@ -32,4 +32,6 @@ fb32f6e1859c07846a01b4478a7b1678019e0b45 UPDATE_PACKAGING_R7
f817a4378f32b1ad0a7c4b5a9949586dba816da5 FENNEC_M11
5c1e7c779b6edc8ff912001990edc579f80597f4 FENNEC_B1
fe9cc55b8db7f56f7e68a246acba363743854979 UPDATE_PACKAGING_R8
6fd4bb500d425c406c1b52f66e5b195b20ae5e0a chromium-import-r15462
6fd4bb500d425c406c1b52f66e5b195b20ae5e0a chromium-import-latest
376b78fc72230aaf2ca4e279a8f4ef1efd4a1d9f GECKO_1_9_2_BASE

Просмотреть файл

@ -896,3 +896,6 @@ pref("toolbar.customization.usesheet", true);
#else
pref("toolbar.customization.usesheet", false);
#endif
pref("dom.ipc.plugins.enabled", false);
pref("dom.ipc.tabs.enabled", false);

Просмотреть файл

@ -103,6 +103,7 @@ MOZ_EXTENSIONS = @MOZ_EXTENSIONS@
MOZ_IMG_DECODERS= @MOZ_IMG_DECODERS@
MOZ_IMG_ENCODERS= @MOZ_IMG_ENCODERS@
MOZ_JSDEBUGGER = @MOZ_JSDEBUGGER@
MOZ_IPC = @MOZ_IPC@
MOZ_LEAKY = @MOZ_LEAKY@
MOZ_MEMORY = @MOZ_MEMORY@
MOZ_JPROF = @MOZ_JPROF@

Просмотреть файл

@ -462,11 +462,7 @@ case "$target" in
WINVER=500
;;
*)
if test -n "$GNU_CC"; then
WINVER=501
else
WINVER=500
fi
WINVER=502
;;
esac
@ -4150,7 +4146,7 @@ dnl =
dnl ========================================================
MOZ_ARG_HEADER(External Packages)
MOZ_ENABLE_LIBXUL=
MOZ_ENABLE_LIBXUL=1
MOZ_ARG_WITH_STRING(libxul-sdk,
[ --with-libxul-sdk=PFX Use the libXUL SDK at <PFX>],
@ -5195,6 +5191,32 @@ MOZ_ARG_DISABLE_BOOL(jsd,
MOZ_JSDEBUGGER=1)
dnl ========================================================
dnl = Disable IPC support for tabs and plugins
dnl ========================================================
MOZ_IPC=1
case "${target}" in
powerpc-apple-darwin*)
MOZ_IPC=
;;
esac
MOZ_ARG_DISABLE_BOOL(ipc,
[ --disable-ipc Disable IPC supports for tabs and plugins],
MOZ_IPC=,
MOZ_IPC=1)
if test -n "$MOZ_IPC" -a -z "$MOZ_ENABLE_LIBXUL"; then
AC_MSG_ERROR([--enable-ipc requires --enable-libxul])
fi
if test -n "$MOZ_IPC"; then
AC_DEFINE(MOZ_IPC)
fi
AC_SUBST(MOZ_IPC)
dnl ========================================================
dnl = Disable plugin support
dnl ========================================================
@ -7043,6 +7065,10 @@ dnl ========================================================
dnl C++ rtti
dnl Should be smarter and check that the compiler does indeed have rtti
dnl ========================================================
if test -n "$GNU_CC"; then
_MOZ_USE_RTTI=1
fi
MOZ_ARG_ENABLE_BOOL(cpp-rtti,
[ --enable-cpp-rtti Enable C++ RTTI ],
[ _MOZ_USE_RTTI=1 ],
@ -7154,11 +7180,6 @@ MOZ_ARG_ENABLE_BOOL(static,
BUILD_STATIC_LIBS=1,
BUILD_STATIC_LIBS=)
dnl Disable libxul in debug builds, but not for xulrunner.
if test -n "$MOZ_DEBUG" -a "$MOZ_BUILD_APP" != "xulrunner"; then
MOZ_ENABLE_LIBXUL=
fi
MOZ_ARG_ENABLE_BOOL(libxul,
[ --enable-libxul Enable building of libxul],
MOZ_ENABLE_LIBXUL=1,

Просмотреть файл

@ -141,6 +141,8 @@ FORCE_STATIC_LIB = 1
EXTRA_COMPONENTS = $(srcdir)/nsBadCertHandler.js
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk
include $(topsrcdir)/config/rules.mk
INCLUDES += \
@ -156,6 +158,7 @@ INCLUDES += \
-I$(srcdir)/../../../dom/base \
-I$(srcdir)/../../xml/document/src \
-I$(topsrcdir)/xpcom/io \
-I$(topsrcdir)/dom/ipc \
$(NULL)
DEFINES += -D_IMPL_NS_LAYOUT

Просмотреть файл

@ -43,6 +43,8 @@
* handling of loads in it, recursion-checking).
*/
#include "prenv.h"
#include "nsIDOMHTMLIFrameElement.h"
#include "nsIDOMHTMLFrameElement.h"
#include "nsIDOMWindow.h"
@ -83,6 +85,22 @@
#include "nsINameSpaceManager.h"
#include "nsThreadUtils.h"
#include "nsIView.h"
#ifdef MOZ_IPC
#include "ContentProcessParent.h"
#include "TabParent.h"
using namespace mozilla;
using namespace mozilla::dom;
#endif
#ifdef MOZ_WIDGET_GTK2
#include "mozcontainer.h"
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#endif
class nsAsyncDocShellDestroyer : public nsRunnable
{
@ -204,6 +222,20 @@ nsresult
nsFrameLoader::ReallyStartLoading()
{
NS_ENSURE_STATE(mURIToLoad && mOwnerContent && mOwnerContent->IsInDoc());
#ifdef MOZ_IPC
if (!mTriedNewProcess) {
TryNewProcess();
mTriedNewProcess = PR_TRUE;
}
if (mChildProcess) {
// FIXME get error codes from child
mChildProcess->LoadURL(mURIToLoad);
return NS_OK;
}
#endif
// Just to be safe, recheck uri.
nsresult rv = CheckURILoad(mURIToLoad);
NS_ENSURE_SUCCESS(rv, rv);
@ -1018,3 +1050,135 @@ nsFrameLoader::CheckForRecursiveLoad(nsIURI* aURI)
return NS_OK;
}
#ifdef MOZ_IPC
PRBool
nsFrameLoader::TryNewProcess()
{
if (PR_GetEnv("MOZ_DISABLE_OOP_TABS")) {
return PR_FALSE;
}
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (!prefs) {
return PR_FALSE;
}
PRBool oopTabsEnabled = PR_FALSE;
prefs->GetBoolPref("dom.ipc.tabs.enabled", &oopTabsEnabled);
if (!oopTabsEnabled) {
return PR_FALSE;
}
nsIDocument* doc = mOwnerContent->GetDocument();
if (!doc) {
return PR_FALSE;
}
if (doc->GetDisplayDocument()) {
// Don't allow subframe loads in external reference documents
return PR_FALSE;
}
nsCOMPtr<nsIWebNavigation> parentAsWebNav =
do_GetInterface(doc->GetScriptGlobalObject());
if (!parentAsWebNav) {
return PR_FALSE;
}
nsCOMPtr<nsIDocShellTreeItem> parentAsItem(do_QueryInterface(parentAsWebNav));
PRInt32 parentType;
parentAsItem->GetItemType(&parentType);
if (parentType != nsIDocShellTreeItem::typeChrome) {
return PR_FALSE;
}
if (!mOwnerContent->IsNodeOfType(nsINode::eXUL)) {
return PR_FALSE;
}
nsAutoString value;
mOwnerContent->GetAttr(kNameSpaceID_None, nsGkAtoms::type, value);
if (!value.LowerCaseEqualsLiteral("content") &&
!StringBeginsWith(value, NS_LITERAL_STRING("content-"),
nsCaseInsensitiveStringComparator())) {
return PR_FALSE;
}
// FIXME shouldn't need to launch a new process every time get here
// XXXnasty hack get our (parent) widget
doc->FlushPendingNotifications(Flush_Layout);
nsIFrame* ourFrame =
doc->GetPrimaryShell()->GetPrimaryFrameFor(mOwnerContent);
nsIView* ancestorView = ourFrame->GetView();
nsIView* firstChild = ancestorView->GetFirstChild();
if (!firstChild) {
NS_ERROR("no first child");
return PR_FALSE;
}
nsIWidget* w = firstChild->GetWidget();
if (!w) {
NS_ERROR("we're stuffed!");
return PR_FALSE;
}
// FIXME check that this widget has the size and position we expect for
// this iframe?
nsPresContext* presContext = ourFrame->PresContext();
#ifdef XP_WIN
HWND parentwin =
static_cast<HWND>(w->GetNativeData(NS_NATIVE_WINDOW));
mChildProcess = ContentProcessParent::GetSingleton()->CreateTab(parentwin);
mChildProcess->Move(0, 0,
presContext->AppUnitsToDevPixels(ourFrame->GetSize().width),
presContext->AppUnitsToDevPixels(ourFrame->GetSize().height));
#elif defined(MOZ_WIDGET_GTK2)
GdkWindow* parent_win =
static_cast<GdkWindow*>(w->GetNativeData(NS_NATIVE_WINDOW));
gpointer user_data = nsnull;
gdk_window_get_user_data(parent_win, &user_data);
MozContainer* parentMozContainer = MOZ_CONTAINER(user_data);
GtkContainer* container = GTK_CONTAINER(parentMozContainer);
// create the widget for the child and add it to the parent's window
GtkWidget* socket = gtk_socket_new();
gtk_widget_set_parent_window(socket, parent_win);
gtk_container_add(container, socket);
gtk_widget_realize(socket);
// set the child window's size and position
GtkAllocation alloc;
alloc.x = 0; // setting position doesn't look necessary
alloc.y = 0;
alloc.width = presContext->AppUnitsToDevPixels(ourFrame->GetSize().width);
alloc.height = presContext->AppUnitsToDevPixels(ourFrame->GetSize().height);
gtk_widget_size_allocate(socket, &alloc);
gtk_widget_show(socket);
GdkNativeWindow id = gtk_socket_get_id((GtkSocket*)socket);
mChildProcess = ContentProcessParent::GetSingleton()->CreateTab(id);
mChildProcess->Move(0, 0, alloc.width, alloc.height);
#else
#error TODO for this platform
#endif
return PR_TRUE;
}
#endif

Просмотреть файл

@ -48,10 +48,19 @@
#include "nsStringFwd.h"
#include "nsIFrameLoader.h"
#include "nsIURI.h"
#include "nsAutoPtr.h"
class nsIContent;
class nsIURI;
#ifdef MOZ_IPC
namespace mozilla {
namespace dom {
class TabParent;
}
}
#endif
class nsFrameLoader : public nsIFrameLoader
{
protected:
@ -62,6 +71,10 @@ protected:
mDestroyCalled(PR_FALSE),
mNeedsAsyncDestroy(PR_FALSE),
mInSwap(PR_FALSE)
#ifdef MOZ_IPC
, mChildProcess(nsnull)
, mTriedNewProcess(PR_FALSE)
#endif
{}
public:
@ -92,6 +105,11 @@ private:
NS_HIDDEN_(void) GetURL(nsString& aURL);
nsresult CheckURILoad(nsIURI* aURI);
#ifdef MOZ_IPC
// True means new process started; nothing else to do
PRBool TryNewProcess();
#endif
nsCOMPtr<nsIDocShell> mDocShell;
nsCOMPtr<nsIURI> mURIToLoad;
nsIContent *mOwnerContent; // WEAK
@ -100,6 +118,12 @@ private:
PRPackedBool mDestroyCalled : 1;
PRPackedBool mNeedsAsyncDestroy : 1;
PRPackedBool mInSwap : 1;
#ifdef MOZ_IPC
// XXX leaking
mozilla::dom::TabParent* mChildProcess;
PRBool mTriedNewProcess;
#endif
};
#endif

Просмотреть файл

@ -9876,10 +9876,13 @@ nsDocShell::EnsureScriptEnvironment()
NS_ENSURE_TRUE(factory, NS_ERROR_FAILURE);
nsCOMPtr<nsIWebBrowserChrome> browserChrome(do_GetInterface(mTreeOwner));
NS_ENSURE_TRUE(browserChrome, NS_ERROR_NOT_AVAILABLE);
PRUint32 chromeFlags;
browserChrome->GetChromeFlags(&chromeFlags);
if (browserChrome) {
browserChrome->GetChromeFlags(&chromeFlags);
} else {
chromeFlags = 0;
}
PRBool isModalContentWindow =
(chromeFlags & nsIWebBrowserChrome::CHROME_MODAL) &&

Просмотреть файл

@ -79,8 +79,15 @@ DIRS += \
base \
src \
locales \
plugins \
$(NULL)
ifdef MOZ_IPC
DIRS += \
ipc \
$(NULL)
endif
ifdef ENABLE_TESTS
DIRS += tests
endif

Просмотреть файл

@ -0,0 +1,155 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set sw=4 ts=8 et tw=80 : */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Content App.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "ContentProcessChild.h"
#include "TabChild.h"
#include "mozilla/ipc/TestShellChild.h"
#include "mozilla/net/NeckoChild.h"
#include "nsXULAppAPI.h"
#include "base/message_loop.h"
#include "base/task.h"
using namespace mozilla::ipc;
using namespace mozilla::net;
namespace mozilla {
namespace dom {
ContentProcessChild* ContentProcessChild::sSingleton;
ContentProcessChild::ContentProcessChild()
: mQuit(PR_FALSE)
{
}
ContentProcessChild::~ContentProcessChild()
{
}
bool
ContentProcessChild::Init(MessageLoop* aIOLoop, IPC::Channel* aChannel)
{
NS_ASSERTION(!sSingleton, "only one ContentProcessChild per child");
Open(aChannel, aIOLoop);
sSingleton = this;
return true;
}
PIFrameEmbeddingChild*
ContentProcessChild::AllocPIFrameEmbedding(const MagicWindowHandle& hwnd)
{
PIFrameEmbeddingChild* iframe = new TabChild(hwnd);
if (iframe && mIFrames.AppendElement(iframe)) {
return iframe;
}
delete iframe;
return nsnull;
}
bool
ContentProcessChild::DeallocPIFrameEmbedding(PIFrameEmbeddingChild* iframe)
{
mIFrames.RemoveElement(iframe);
return true;
}
PTestShellChild*
ContentProcessChild::AllocPTestShell()
{
PTestShellChild* testshell = new TestShellChild();
if (testshell && mTestShells.AppendElement(testshell)) {
return testshell;
}
delete testshell;
return nsnull;
}
bool
ContentProcessChild::DeallocPTestShell(PTestShellChild* shell)
{
mTestShells.RemoveElement(shell);
return true;
}
PNeckoChild*
ContentProcessChild::AllocPNecko()
{
return new NeckoChild();
}
bool
ContentProcessChild::DeallocPNecko(PNeckoChild* necko)
{
delete necko;
return true;
}
void
ContentProcessChild::Quit()
{
NS_ASSERTION(mQuit, "Exiting uncleanly!");
mIFrames.Clear();
mTestShells.Clear();
}
static void
QuitIOLoop()
{
MessageLoop::current()->Quit();
}
bool
ContentProcessChild::RecvQuit()
{
mQuit = PR_TRUE;
Quit();
XRE_GetIOMessageLoop()->PostTask(FROM_HERE,
NewRunnableFunction(&QuitIOLoop));
return true;
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,90 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set sw=4 ts=8 et tw=80 : */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Content App.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef mozilla_dom_ContentProcessChild_h
#define mozilla_dom_ContentProcessChild_h
#include "mozilla/dom/PContentProcessChild.h"
#include "nsTArray.h"
#include "nsAutoPtr.h"
namespace mozilla {
namespace dom {
class ContentProcessChild : public PContentProcessChild
{
public:
ContentProcessChild();
virtual ~ContentProcessChild();
bool Init(MessageLoop* aIOLoop, IPC::Channel* aChannel);
static ContentProcessChild* GetSingleton() {
NS_ASSERTION(sSingleton, "not initialized");
return sSingleton;
}
virtual PIFrameEmbeddingChild* AllocPIFrameEmbedding(
const MagicWindowHandle& hwnd);
virtual bool DeallocPIFrameEmbedding(PIFrameEmbeddingChild*);
virtual PTestShellChild* AllocPTestShell();
virtual bool DeallocPTestShell(PTestShellChild*);
virtual PNeckoChild* AllocPNecko();
virtual bool DeallocPNecko(PNeckoChild*);
void Quit();
virtual bool RecvQuit();
private:
static ContentProcessChild* sSingleton;
nsTArray<nsAutoPtr<PIFrameEmbeddingChild> > mIFrames;
nsTArray<nsAutoPtr<PTestShellChild> > mTestShells;
PRBool mQuit;
DISALLOW_EVIL_CONSTRUCTORS(ContentProcessChild);
};
} // namespace dom
} // namespace mozilla
#endif

Просмотреть файл

@ -0,0 +1,186 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set sw=4 ts=8 et tw=80 : */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Content App.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "ContentProcessParent.h"
#include "mozilla/ipc/GeckoThread.h"
#include "TabParent.h"
#include "mozilla/ipc/TestShellParent.h"
#include "mozilla/net/NeckoParent.h"
#include "nsIObserverService.h"
#include "nsAutoPtr.h"
#include "nsCOMPtr.h"
#include "nsServiceManagerUtils.h"
#include "nsThreadUtils.h"
using namespace mozilla::ipc;
using namespace mozilla::net;
using mozilla::MonitorAutoEnter;
namespace {
PRBool gSingletonDied = PR_FALSE;
}
namespace mozilla {
namespace dom {
ContentProcessParent* ContentProcessParent::gSingleton;
ContentProcessParent*
ContentProcessParent::GetSingleton()
{
if (!gSingleton && !gSingletonDied) {
nsRefPtr<ContentProcessParent> parent = new ContentProcessParent();
if (parent) {
nsCOMPtr<nsIObserverService> obs =
do_GetService("@mozilla.org/observer-service;1");
if (obs) {
if (NS_SUCCEEDED(obs->AddObserver(parent, "xpcom-shutdown",
PR_FALSE))) {
gSingleton = parent;
}
}
}
}
return gSingleton;
}
TabParent*
ContentProcessParent::CreateTab(const MagicWindowHandle& hwnd)
{
return static_cast<TabParent*>(SendPIFrameEmbeddingConstructor(hwnd));
}
TestShellParent*
ContentProcessParent::CreateTestShell()
{
return static_cast<TestShellParent*>(SendPTestShellConstructor());
}
ContentProcessParent::ContentProcessParent()
: mMonitor("ContentProcessParent::mMonitor")
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
// TODO: async launching!
mSubprocess = new GeckoChildProcessHost(GeckoProcessType_Content, this);
mSubprocess->SyncLaunch();
Open(mSubprocess->GetChannel());
}
ContentProcessParent::~ContentProcessParent()
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
NS_ASSERTION(gSingleton == this, "More than one singleton?!");
gSingletonDied = PR_TRUE;
gSingleton = nsnull;
}
NS_IMPL_ISUPPORTS1(ContentProcessParent, nsIObserver)
NS_IMETHODIMP
ContentProcessParent::Observe(nsISupports* aSubject,
const char* aTopic,
const PRUnichar* aData)
{
if (!strcmp(aTopic, "xpcom-shutdown") && mSubprocess) {
SendQuit();
#ifdef OS_WIN
MonitorAutoEnter mon(mMonitor);
while (mSubprocess) {
mon.Wait();
}
#endif
}
return NS_OK;
}
void
ContentProcessParent::OnWaitableEventSignaled(base::WaitableEvent *event)
{
// The child process has died! Sadly we're on the wrong thread to do much.
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
MonitorAutoEnter mon(mMonitor);
mSubprocess = nsnull;
mon.Notify();
}
PIFrameEmbeddingParent*
ContentProcessParent::AllocPIFrameEmbedding(
const MagicWindowHandle& parentWidget)
{
return new TabParent();
}
bool
ContentProcessParent::DeallocPIFrameEmbedding(PIFrameEmbeddingParent* frame)
{
delete frame;
return true;
}
PTestShellParent*
ContentProcessParent::AllocPTestShell()
{
return new TestShellParent();
}
bool
ContentProcessParent::DeallocPTestShell(PTestShellParent* shell)
{
delete shell;
return true;
}
PNeckoParent*
ContentProcessParent::AllocPNecko()
{
return new NeckoParent();
}
bool
ContentProcessParent::DeallocPNecko(PNeckoParent* necko)
{
delete necko;
return true;
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,112 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set sw=4 ts=8 et tw=80 : */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Content App.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef mozilla_dom_ContentProcessParent_h
#define mozilla_dom_ContentProcessParent_h
#include "base/waitable_event_watcher.h"
#include "mozilla/dom/PContentProcessParent.h"
#include "mozilla/ipc/GeckoChildProcessHost.h"
#include "nsIObserver.h"
#include "mozilla/Monitor.h"
namespace mozilla {
namespace ipc {
class TestShellParent;
}
namespace dom {
class TabParent;
class ContentProcessParent : private PContentProcessParent,
public base::WaitableEventWatcher::Delegate,
public nsIObserver
{
private:
typedef mozilla::ipc::GeckoChildProcessHost GeckoChildProcessHost;
public:
static ContentProcessParent* GetSingleton();
#if 0
// TODO: implement this somewhere!
static ContentProcessParent* FreeSingleton();
#endif
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
virtual void OnWaitableEventSignaled(base::WaitableEvent *event);
TabParent* CreateTab(const MagicWindowHandle& hwnd);
mozilla::ipc::TestShellParent* CreateTestShell();
private:
static ContentProcessParent* gSingleton;
// Hide the raw constructor methods since we don't want client code
// using them.
using PContentProcessParent::SendPIFrameEmbeddingConstructor;
using PContentProcessParent::SendPTestShellConstructor;
ContentProcessParent();
virtual ~ContentProcessParent();
virtual PIFrameEmbeddingParent* AllocPIFrameEmbedding(
const MagicWindowHandle& parentWidget);
virtual bool DeallocPIFrameEmbedding(PIFrameEmbeddingParent* frame);
virtual PTestShellParent* AllocPTestShell();
virtual bool DeallocPTestShell(PTestShellParent* shell);
virtual PNeckoParent* AllocPNecko();
virtual bool DeallocPNecko(PNeckoParent* necko);
mozilla::Monitor mMonitor;
GeckoChildProcessHost* mSubprocess;
};
} // namespace dom
} // namespace mozilla
#endif

Просмотреть файл

@ -0,0 +1,82 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set sw=4 ts=8 et tw=80 :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Ben Turner <bent.mozilla@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chris Jones <jones.chris.g@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "ContentProcessThread.h"
#include "prlink.h"
#include "base/command_line.h"
#include "base/string_util.h"
#include "chrome/common/child_process.h"
#include "chrome/common/chrome_switches.h"
using mozilla::ipc::GeckoThread;
namespace mozilla {
namespace dom {
ContentProcessThread::ContentProcessThread() :
GeckoThread(),
mContentProcess()
{
}
ContentProcessThread::~ContentProcessThread()
{
}
void
ContentProcessThread::Init()
{
GeckoThread::Init();
// FIXME/cjones: set up channel stuff, etc.
// FIXME owner_loop() is bad here
mContentProcess.Init(owner_loop(), channel());
}
void
ContentProcessThread::CleanUp()
{
GeckoThread::CleanUp();
}
} // namespace tabs
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,79 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set sw=4 ts=8 et tw=80 :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Ben Turner <bent.mozilla@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chris Jones <jones.chris.g@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef dom_tabs_ContentProcessThread_h
#define dom_tabs_ContentProcessThread_h 1
#include "chrome/common/child_thread.h"
#include "base/file_path.h"
#include "mozilla/ipc/GeckoThread.h"
#include "ContentProcessChild.h"
#undef _MOZ_LOG
#define _MOZ_LOG(s) printf("[ContentProcessThread] %s", s)
namespace mozilla {
namespace dom {
/**
* ContentProcessThread is a singleton on the content process which represents
* a background thread where tab instances live.
*/
class ContentProcessThread : public mozilla::ipc::GeckoThread
{
public:
ContentProcessThread();
~ContentProcessThread();
private:
// Thread implementation:
virtual void Init();
virtual void CleanUp();
ContentProcessChild mContentProcess;
IPC::Channel* mChannel;
DISALLOW_EVIL_CONSTRUCTORS(ContentProcessThread);
};
} // namespace dom
} // namespace mozilla
#endif // ifndef dom_tabs_ContentProcessThread_h

74
dom/ipc/Makefile.in Normal file
Просмотреть файл

@ -0,0 +1,74 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Firefox.
#
# The Initial Developer of the Original Code is
# The Mozilla Foundation <http://www.mozilla.org/>.
# Portions created by the Initial Developer are Copyright (C) 2009
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = dom
LIBRARY_NAME = domipc_s
LIBXUL_LIBRARY = 1
FORCE_STATIC_LIB = 1
EXPORT_LIBRARY = 1
EXPORTS_NAMESPACES = mozilla mozilla/dom
EXPORTS_mozilla = \
TabTypes.h \
$(NULL)
EXPORTS_mozilla/dom = \
ContentProcessChild.h \
ContentProcessParent.h \
ContentProcessThread.h \
$(NULL)
CPPSRCS = \
ContentProcessThread.cpp \
ContentProcessParent.cpp \
ContentProcessChild.cpp \
TabParent.cpp \
TabChild.cpp \
$(NULL)
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk
include $(topsrcdir)/config/rules.mk
DEFINES += -DBIN_SUFFIX='"$(BIN_SUFFIX)"'

Просмотреть файл

@ -0,0 +1,71 @@
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8 -*- */
/* vim: set sw=4 ts=8 et tw=80 ft=cpp : */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Content App.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
include protocol "PIFrameEmbedding.ipdl";
include protocol "PTestShell.ipdl";
include protocol "PNecko.ipdl";
include "mozilla/TabTypes.h";
using MagicWindowHandle;
namespace mozilla {
namespace dom {
sync protocol PContentProcess
{
manages PIFrameEmbedding;
manages PTestShell;
manages PNecko;
child:
PIFrameEmbedding(MagicWindowHandle parentWidget);
~PIFrameEmbedding();
PTestShell();
~PTestShell();
Quit();
parent:
PNecko();
~PNecko();
};
}
}

Просмотреть файл

@ -0,0 +1,61 @@
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8 -*- */
/* vim: set sw=4 ts=8 et tw=80 ft=cpp : */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Content App.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
include protocol "PContentProcess.ipdl";
using PRUint32;
namespace mozilla {
namespace dom {
async protocol PIFrameEmbedding
{
manager PContentProcess;
child:
loadURL(nsCString uri);
move(PRUint32 x,
PRUint32 y,
PRUint32 width,
PRUint32 height);
};
}
}

116
dom/ipc/TabChild.cpp Normal file
Просмотреть файл

@ -0,0 +1,116 @@
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*- */
/* vim: set sw=4 ts=8 et tw=80 : */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Content App.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "TabChild.h"
#include "nsIWebBrowser.h"
#include "nsEmbedCID.h"
#include "nsComponentManagerUtils.h"
#include "nsIBaseWindow.h"
#include "nsIDocShellTreeItem.h"
#include "nsThreadUtils.h"
#ifdef MOZ_WIDGET_GTK2
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#endif
using namespace mozilla::dom;
TabChild::TabChild(const MagicWindowHandle& parentWidget)
{
printf("creating %d!\n", NS_IsMainThread());
#ifdef MOZ_WIDGET_GTK2
gtk_init(NULL, NULL);
#endif
nsCOMPtr<nsIWebBrowser> webBrowser(do_CreateInstance(NS_WEBBROWSER_CONTRACTID));
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(webBrowser);
#ifdef MOZ_WIDGET_GTK2
GtkWidget* win = gtk_plug_new((GdkNativeWindow)parentWidget);
gtk_widget_show(win);
#elif defined(XP_WIN)
HWND win = parentWidget;
#else
#error You lose!
#endif
baseWindow->InitWindow(win, 0, 0, 0, 0, 0);
nsCOMPtr<nsIDocShellTreeItem> docShellItem(do_QueryInterface(baseWindow));
docShellItem->SetItemType(nsIDocShellTreeItem::typeContentWrapper);
baseWindow->Create();
baseWindow->SetVisibility(PR_TRUE);
mWebNav = do_QueryInterface(webBrowser);
}
TabChild::~TabChild()
{
// TODObsmedberg: destroy the window!
}
bool
TabChild::RecvloadURL(const nsCString& uri)
{
printf("loading %s, %d\n", uri.get(), NS_IsMainThread());
return mWebNav->LoadURI(NS_ConvertUTF8toUTF16(uri).get(),
nsIWebNavigation::LOAD_FLAGS_NONE,
NULL, NULL, NULL);
}
bool
TabChild::Recvmove(const PRUint32& x,
const PRUint32& y,
const PRUint32& width,
const PRUint32& height)
{
printf("[TabChild] MOVE to (x,y)=(%ud, %ud), (w,h)= (%ud, %ud)\n",
x, y, width, height);
nsCOMPtr<nsIBaseWindow> baseWin = do_QueryInterface(mWebNav);
baseWin->SetPositionAndSize(x, y, width, height, PR_TRUE);
return true;
}

70
dom/ipc/TabChild.h Normal file
Просмотреть файл

@ -0,0 +1,70 @@
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*- */
/* vim: set sw=4 ts=8 et tw=80 : */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Content App.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef mozilla_tabs_TabChild_h
#define mozilla_tabs_TabChild_h
#include "mozilla/dom/PIFrameEmbeddingChild.h"
#include "nsIWebNavigation.h"
#include "nsCOMPtr.h"
namespace mozilla {
namespace dom {
class TabChild : public PIFrameEmbeddingChild
{
public:
TabChild(const MagicWindowHandle& parentWidget);
virtual ~TabChild();
virtual bool RecvloadURL(const nsCString& uri);
virtual bool Recvmove(const PRUint32& x,
const PRUint32& y,
const PRUint32& width,
const PRUint32& height);
private:
nsCOMPtr<nsIWebNavigation> mWebNav;
DISALLOW_EVIL_CONSTRUCTORS(TabChild);
};
}
}
#endif // mozilla_tabs_TabChild_h

74
dom/ipc/TabParent.cpp Normal file
Просмотреть файл

@ -0,0 +1,74 @@
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*- */
/* vim: set sw=4 ts=8 et tw=80 : */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Content App.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "TabParent.h"
#include "mozilla/ipc/GeckoThread.h"
#include "nsIURI.h"
using mozilla::ipc::BrowserProcessSubThread;
namespace mozilla {
namespace dom {
TabParent::TabParent()
{
}
TabParent::~TabParent()
{
}
void
TabParent::LoadURL(nsIURI* aURI)
{
nsCString spec;
aURI->GetSpec(spec);
SendloadURL(spec);
}
void
TabParent::Move(PRUint32 x, PRUint32 y, PRUint32 width, PRUint32 height)
{
Sendmove(x, y, width, height);
}
} // namespace tabs
} // namespace mozilla

64
dom/ipc/TabParent.h Normal file
Просмотреть файл

@ -0,0 +1,64 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set sw=4 ts=8 et tw=80 : */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Content App.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef mozilla_tabs_TabParent_h
#define mozilla_tabs_TabParent_h
#include "mozilla/dom/PIFrameEmbeddingParent.h"
#include "mozilla/ipc/GeckoChildProcessHost.h"
class nsIURI;
namespace mozilla {
namespace dom {
class TabParent : public PIFrameEmbeddingParent
{
public:
TabParent();
virtual ~TabParent();
void LoadURL(nsIURI* aURI);
void Move(PRUint32 x, PRUint32 y, PRUint32 width, PRUint32 height);
};
} // namespace dom
} // namespace mozilla
#endif

21
dom/ipc/TabTypes.h Normal file
Просмотреть файл

@ -0,0 +1,21 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set sw=4 ts=8 et tw=80 : */
#ifndef mozilla_tabs_TabTypes_h
#define mozilla_tabs_TabTypes_h
#include "base/basictypes.h"
#ifdef XP_WIN
#include <windows.h>
typedef HWND MagicWindowHandle;
#elif defined(MOZ_WIDGET_GTK2)
#include <X11/X.h>
typedef XID MagicWindowHandle;
#else
#error Not implemented, stooge
#endif
#endif

40
dom/ipc/ipdl.mk Normal file
Просмотреть файл

@ -0,0 +1,40 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Content App.
#
# The Initial Developer of the Original Code is
# The Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2009
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
IPDLSRCS = \
PContentProcess.ipdl \
PIFrameEmbedding.ipdl \
$(NULL)

2
dom/ipc/jar.mn Normal file
Просмотреть файл

@ -0,0 +1,2 @@
toolkit.jar:
content/global/test-ipc.xul (test.xul)

26
dom/ipc/test.xul Normal file
Просмотреть файл

@ -0,0 +1,26 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
width="800" height="800" onload="setTimeout(restart, 0)" orient="vertical">
<script>
function restart() {
var y = document.getElementById('page');
var p = y.parentNode;
p.removeChild(y);
p.appendChild(y);
}
function loadURL(url) {
document.getElementById('page').setAttribute('src', url);
}
</script>
<toolbar id="controls">
<toolbarbutton label="Back"/>
<toolbarbutton label="Forward"/>
<textbox onchange="loadURL(this.value)" flex="1" id="URL"/>
<toolbarbutton onclick="restart()" label="Recover"/>
</toolbar>
<iframe type="content" src="http://www.google.com/" flex="1" id="page"/>
</window>

59
dom/plugins/AStream.h Normal file
Просмотреть файл

@ -0,0 +1,59 @@
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugins.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation <http://www.mozilla.org/>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef mozilla_plugins_AStream_h
#define mozilla_plugins_AStream_h
namespace mozilla {
namespace plugins {
/**
* When we are passed NPStream->{ndata,pdata} in {NPN,NPP}_DestroyStream, we
* don't know whether it's a plugin stream or a browser stream. This abstract
* class lets us cast to the right type of object and send the appropriate
* message.
*/
class AStream
{
public:
virtual bool IsBrowserStream() = 0;
};
} // namespace plugins
} // namespace mozilla
#endif

Просмотреть файл

@ -0,0 +1,148 @@
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Benjamin Smedberg <benjamin@smedbergs.us>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "BrowserStreamChild.h"
#include "PluginInstanceChild.h"
namespace mozilla {
namespace plugins {
BrowserStreamChild::BrowserStreamChild(PluginInstanceChild* instance,
const nsCString& url,
const uint32_t& length,
const uint32_t& lastmodified,
const nsCString& headers,
const nsCString& mimeType,
const bool& seekable,
NPError* rv,
uint16_t* stype)
: mInstance(instance)
, mClosed(false)
, mURL(url)
, mHeaders(headers)
{
memset(&mStream, 0, sizeof(mStream));
mStream.ndata = static_cast<AStream*>(this);
if (!mURL.IsEmpty())
mStream.url = mURL.get();
mStream.end = length;
mStream.lastmodified = lastmodified;
if (!mHeaders.IsEmpty())
mStream.headers = mHeaders.get();
*rv = mInstance->mPluginIface->newstream(&mInstance->mData,
const_cast<char*>(mimeType.get()),
&mStream, seekable, stype);
if (*rv != NPERR_NO_ERROR)
mClosed = true;
}
bool
BrowserStreamChild::AnswerNPP_WriteReady(const int32_t& newlength,
int32_t *size)
{
if (mClosed) {
*size = 0;
return true;
}
mStream.end = newlength;
*size = mInstance->mPluginIface->writeready(&mInstance->mData, &mStream);
return true;
}
bool
BrowserStreamChild::AnswerNPP_Write(const int32_t& offset,
const Buffer& data,
int32_t* consumed)
{
if (mClosed) {
*consumed = -1;
return true;
}
*consumed = mInstance->mPluginIface->write(&mInstance->mData, &mStream,
offset, data.Length(),
const_cast<char*>(data.get()));
if (*consumed < 0)
mClosed = true;
return true;
}
bool
BrowserStreamChild::AnswerNPP_StreamAsFile(const nsCString& fname)
{
_MOZ_LOG(__FUNCTION__);
printf("mClosed: %i\n", mClosed);
if (mClosed)
return true;
mInstance->mPluginIface->asfile(&mInstance->mData, &mStream,
fname.get());
return true;
}
NPError
BrowserStreamChild::NPN_RequestRead(NPByteRange* aRangeList)
{
IPCByteRanges ranges;
for (; aRangeList; aRangeList = aRangeList->next) {
IPCByteRange br = {aRangeList->offset, aRangeList->length};
ranges.push_back(br);
}
NPError result;
CallNPN_RequestRead(ranges, &result);
// TODO: does failure in NPN_RequestRead affect stream state at all?
return result;
}
void
BrowserStreamChild::NPP_DestroyStream(NPError reason)
{
if (mClosed)
return;
mInstance->mPluginIface->destroystream(&mInstance->mData, &mStream, reason);
mClosed = true;
}
} /* namespace plugins */
} /* namespace mozilla */

Просмотреть файл

@ -0,0 +1,98 @@
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Benjamin Smedberg <benjamin@smedbergs.us>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef mozilla_plugins_BrowserStreamChild_h
#define mozilla_plugins_BrowserStreamChild_h 1
#include "mozilla/plugins/PBrowserStreamChild.h"
#include "mozilla/plugins/AStream.h"
namespace mozilla {
namespace plugins {
class PluginInstanceChild;
class BrowserStreamChild : public PBrowserStreamChild, public AStream
{
public:
BrowserStreamChild(PluginInstanceChild* instance,
const nsCString& url,
const uint32_t& length,
const uint32_t& lastmodified,
const nsCString& headers,
const nsCString& mimeType,
const bool& seekable,
NPError* rv,
uint16_t* stype);
virtual ~BrowserStreamChild() { }
NS_OVERRIDE virtual bool IsBrowserStream() { return true; }
virtual bool AnswerNPP_WriteReady(const int32_t& newlength,
int32_t *size);
virtual bool AnswerNPP_Write(const int32_t& offset,
const Buffer& data,
int32_t* consumed);
virtual bool AnswerNPP_StreamAsFile(const nsCString& fname);
void EnsureCorrectInstance(PluginInstanceChild* i)
{
if (i != mInstance)
NS_RUNTIMEABORT("Incorrect stream instance");
}
void EnsureCorrectStream(NPStream* s)
{
if (s != &mStream)
NS_RUNTIMEABORT("Incorrect stream data");
}
NPError NPN_RequestRead(NPByteRange* aRangeList);
void NPP_DestroyStream(NPError reason);
private:
PluginInstanceChild* mInstance;
NPStream mStream;
bool mClosed;
nsCString mURL;
nsCString mHeaders;
};
} // namespace plugins
} // namespace mozilla
#endif /* mozilla_plugins_BrowserStreamChild_h */

Просмотреть файл

@ -0,0 +1,93 @@
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
#include "BrowserStreamParent.h"
#include "PluginInstanceParent.h"
namespace mozilla {
namespace plugins {
BrowserStreamParent::BrowserStreamParent(PluginInstanceParent* npp,
NPStream* stream)
: mNPP(npp)
, mStream(stream)
{
mStream->pdata = static_cast<AStream*>(this);
}
bool
BrowserStreamParent::AnswerNPN_RequestRead(const IPCByteRanges& ranges,
NPError* result)
{
_MOZ_LOG(__FUNCTION__);
if (!mStream)
return false;
if (ranges.size() > PR_INT32_MAX) {
// TODO: abort all processing!
return false;
}
nsAutoArrayPtr<NPByteRange> rp(new NPByteRange[ranges.size()]);
for (PRUint32 i = 0; i < ranges.size(); ++i) {
rp[i].offset = ranges[i].offset;
rp[i].length = ranges[i].length;
rp[i].next = &rp[i + 1];
}
rp[ranges.size() - 1].next = NULL;
*result = mNPP->mNPNIface->requestread(mStream, rp);
return true;
}
int32_t
BrowserStreamParent::WriteReady()
{
_MOZ_LOG(__FUNCTION__);
int32_t result;
if (!CallNPP_WriteReady(mStream->end, &result)) {
mNPP->mNPNIface->destroystream(mNPP->mNPP, mStream, NPRES_NETWORK_ERR);
// XXX is this right?
return -1;
}
return result;
}
int32_t
BrowserStreamParent::Write(int32_t offset,
int32_t len,
void* buffer)
{
_MOZ_LOG(__FUNCTION__);
int32_t result;
if (!CallNPP_Write(offset,
nsCString(static_cast<char*>(buffer), len),
&result)) {
return -1;
}
if (result == -1)
mNPP->CallPBrowserStreamDestructor(this, NPRES_USER_BREAK, true);
return result;
}
void
BrowserStreamParent::StreamAsFile(const char* fname)
{
_MOZ_LOG(__FUNCTION__);
CallNPP_StreamAsFile(nsCString(fname));
}
NPError
BrowserStreamParent::NPN_DestroyStream(NPReason reason)
{
_MOZ_LOG(__FUNCTION__);
return mNPP->mNPNIface->destroystream(mNPP->mNPP, mStream, reason);
}
} // namespace plugins
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,77 @@
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugins.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation <http://www.mozilla.org/>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef mozilla_plugins_BrowserStreamParent_h
#define mozilla_plugins_BrowserStreamParent_h
#include "mozilla/plugins/PBrowserStreamParent.h"
#include "mozilla/plugins/AStream.h"
namespace mozilla {
namespace plugins {
class PluginInstanceParent;
class BrowserStreamParent : public PBrowserStreamParent, public AStream
{
friend class PluginModuleParent;
friend class PluginInstanceParent;
public:
BrowserStreamParent(PluginInstanceParent* npp,
NPStream* stream);
virtual ~BrowserStreamParent() { }
NS_OVERRIDE virtual bool IsBrowserStream() { return true; }
virtual bool AnswerNPN_RequestRead(const IPCByteRanges& ranges,
NPError* result);
int32_t WriteReady();
int32_t Write(int32_t offset, int32_t len, void* buffer);
void StreamAsFile(const char* fname);
NPError NPN_DestroyStream(NPError reason);
private:
PluginInstanceParent* mNPP;
NPStream* mStream;
};
} // namespace plugins
} // namespace mozilla
#endif

119
dom/plugins/Makefile.in Normal file
Просмотреть файл

@ -0,0 +1,119 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Plugins.
#
# The Initial Developer of the Original Code is
# Ben Turner <bent.mozilla@gmail.com>.
# Portions created by the Initial Developer are Copyright (C) 2009
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Chris Jones <jones.chris.g@gmail.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = dom
DIRS += testplugin
EXPORTS_NAMESPACES = mozilla
EXPORTS_mozilla = \
SharedLibrary.h \
SharedPRLibrary.h \
$(NULL)
ifdef MOZ_IPC
EXPORTS_NAMESPACES = mozilla mozilla/plugins
EXPORTS_mozilla/plugins = \
BrowserStreamChild.h \
BrowserStreamParent.h \
NPEventOSX.h \
NPEventWindows.h \
NPEventX11.h \
PluginInstanceChild.h \
PluginInstanceParent.h \
PluginMessageUtils.h \
PluginModuleChild.h \
PluginModuleParent.h \
PluginProcessParent.h \
PluginScriptableObjectChild.h \
PluginScriptableObjectParent.h \
PluginInstanceChild.h \
PluginInstanceParent.h \
AStream.h \
BrowserStreamChild.h \
BrowserStreamParent.h \
PluginStreamChild.h \
PluginStreamParent.h \
PluginMessageUtils.h \
PluginProcessParent.h \
PluginThreadChild.h \
StreamNotifyChild.h \
StreamNotifyParent.h \
$(NULL)
MODULE = dom
LIBRARY_NAME = domplugins_s
LIBXUL_LIBRARY = 1
FORCE_STATIC_LIB = 1
EXPORT_LIBRARY = 1
ENABLE_CXX_EXCEPTIONS = 1
CPPSRCS = \
PluginInstanceChild.cpp \
PluginInstanceParent.cpp \
PluginModuleChild.cpp \
PluginModuleParent.cpp \
PluginProcessParent.cpp \
PluginScriptableObjectChild.cpp \
PluginScriptableObjectParent.cpp \
BrowserStreamChild.cpp \
BrowserStreamParent.cpp \
PluginStreamChild.cpp \
PluginStreamParent.cpp \
PluginThreadChild.cpp \
$(NULL)
LOCAL_INCLUDES = \
-I$(topsrcdir)/modules/plugin/base/public/ \
-I$(topsrcdir)/modules/plugin/base/src/ \
$(NULL)
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk
endif
include $(topsrcdir)/config/rules.mk

67
dom/plugins/NPEventOSX.h Normal file
Просмотреть файл

@ -0,0 +1,67 @@
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8 -*- */
/* vim: set sw=4 ts=8 et tw=80 ft=cpp : */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef mozilla_dom_plugins_NPEventOSX_h
#define mozilla_dom_plugins_NPEventOSX_h 1
#include "npapi.h"
#warning This is only a stub implementation IMPLEMENT ME
template <>
struct ParamTraits<NPEvent>
{
typedef NPEvent paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
return true;
}
static void Log(const paramType& aParam, std::wstring* aLog)
{
}
};
#endif // ifndef mozilla_dom_plugins_NPEventOSX_h

Просмотреть файл

@ -0,0 +1,70 @@
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8 -*- */
/* vim: set sw=4 ts=8 et tw=80 ft=cpp : */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef mozilla_dom_plugins_NPEventWindows_h
#define mozilla_dom_plugins_NPEventWindows_h 1
#include "npapi.h"
#pragma message(__FILE__ ": This is only a stub implementation IMPLEMENT ME")
namespace IPC {
template <>
struct ParamTraits<NPEvent>
{
typedef NPEvent paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
return true;
}
static void Log(const paramType& aParam, std::wstring* aLog)
{
}
};
} // namespace IPC
#endif // ifndef mozilla_dom_plugins_NPEventWindows_h

134
dom/plugins/NPEventX11.h Normal file
Просмотреть файл

@ -0,0 +1,134 @@
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8 -*- */
/* vim: set sw=4 ts=8 et tw=80 ft=cpp : */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chris Jones <jones.chris.g@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef mozilla_dom_plugins_NPEventX11_h
#define mozilla_dom_plugins_NPEventX11_h 1
#if defined(MOZ_WIDGET_GTK2)
# include <gdk/gdkx.h>
#else
# error Implement me for your toolkit
#endif
#include "npapi.h"
//
// XEvent is defined as a union of all more specific X*Events.
// Luckily, as of xorg 1.6.0 / X protocol 11 rev 0, the only pointer
// field contained in any of these specific X*Event structs is a
// |Display*|. So to simplify serializing these XEvents, we make the
//
// ********** XXX ASSUMPTION XXX **********
//
// that the process to which the event is forwarded shares the same
// display as the process on which the event originated.
//
// With this simplification, serialization becomes a simple memcpy to
// the output stream. Deserialization starts as just a memcpy from
// the input stream, BUT we then have to write the correct |Display*|
// into the right field of each X*Event that contains one.
//
namespace IPC {
template <>
struct ParamTraits<NPEvent> // synonym for XEvent
{
typedef NPEvent paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
aMsg->WriteBytes(&aParam, sizeof(paramType));
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
const char* bytes = 0;
if (!aMsg->ReadBytes(aIter, &bytes, sizeof(paramType))) {
return false;
}
memcpy(aResult, bytes, sizeof(paramType));
SetXDisplay(*aResult);
return true;
}
static void Log(const paramType& aParam, std::wstring* aLog)
{
// TODO
aLog->append(L"(XEvent)");
}
private:
static Display* GetXDisplay(const XAnyEvent& ev)
{
// TODO: get Display* from Window in |ev|
// FIXME: do this using Xlib, don't use Gdk
return GDK_DISPLAY();
}
static Display* GetXDisplay(const XErrorEvent& ev)
{
// TODO: get Display* from Window in |ev|
// FIXME: do this using Xlib, don't use Gdk
return GDK_DISPLAY();
}
static void SetXDisplay(XEvent& ev)
{
if (ev.type >= KeyPress) {
ev.xany.display = GetXDisplay(ev.xany);
}
else {
// XXX assuming that this is an error event
// (type == 0? not clear from Xlib.h)
ev.xerror.display = GetXDisplay(ev.xerror);
}
}
};
} // namespace IPC
#endif // ifndef mozilla_dom_plugins_NPEventX11_h

Просмотреть файл

@ -0,0 +1,72 @@
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugins.
*
* The Initial Developer of the Original Code is
* Benjamin Smedberg <benjamin@smedbergs.us>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
include protocol "PPluginInstance.ipdl";
using mozilla::plugins::Buffer;
using mozilla::plugins::IPCByteRanges;
using NPError;
namespace mozilla {
namespace plugins {
/**
* NPBrowserStream represents a NPStream sent from the browser to the plugin.
*/
rpc protocol PBrowserStream
{
manager PPluginInstance;
child:
rpc NPP_WriteReady(int32_t newlength)
returns (int32_t size);
rpc NPP_Write(int32_t offset,
Buffer data)
returns (int32_t consumed);
rpc NPP_StreamAsFile(nsCString fname);
parent:
rpc NPN_RequestRead(IPCByteRanges ranges)
returns (NPError result);
};
} // namespace plugins
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,148 @@
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugins.
*
* The Initial Developer of the Original Code is
* Chris Jones <jones.chris.g@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Benjamin Smedberg <benjamin@smedbergs.us>
* Ben Turner <bent.mozilla@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
include protocol "PPluginModule.ipdl";
include protocol "PPluginScriptableObject.ipdl";
include protocol "PBrowserStream.ipdl";
include protocol "PPluginStream.ipdl";
include protocol "PStreamNotify.ipdl";
include "mozilla/plugins/PluginMessageUtils.h";
using NPError;
using NPEvent;
using NPWindow;
using NPReason;
namespace mozilla {
namespace plugins {
rpc protocol PPluginInstance
{
manager PPluginModule;
manages PPluginScriptableObject;
manages PBrowserStream;
manages PPluginStream;
manages PStreamNotify;
child:
rpc NPP_SetWindow(NPWindow window)
returns (NPError rv);
rpc NPP_GetValue_NPPVpluginScriptableNPObject()
returns (PPluginScriptableObject value, NPError result);
rpc NPP_HandleEvent(NPEvent event)
returns (int16_t handled);
parent:
rpc NPN_GetValue_NPNVjavascriptEnabledBool()
returns (bool value, NPError result);
rpc NPN_GetValue_NPNVisOfflineBool()
returns (bool value, NPError result);
rpc NPN_GetValue_NPNVWindowNPObject()
returns (PPluginScriptableObject value, NPError result);
rpc NPN_GetValue_NPNVPluginElementNPObject()
returns (PPluginScriptableObject value, NPError result);
rpc NPN_GetValue_NPNVprivateModeBool()
returns (bool value, NPError result);
rpc NPN_GetURL(nsCString url, nsCString target)
returns (NPError result);
rpc NPN_PostURL(nsCString url, nsCString target, nsCString buffer, bool file)
returns (NPError result);
/**
* Covers both NPN_GetURLNotify and NPN_PostURLNotify.
* @TODO This would be more readable as an overloaded method,
* but IPDL doesn't allow that for constructors (or any method?).
*/
rpc PStreamNotify(nsCString url, nsCString target, bool post,
nsCString buffer, bool file)
returns (NPError result);
child:
/**
* Represents NPP_URLNotify
*/
rpc ~PStreamNotify(NPReason reason);
both:
rpc PPluginScriptableObject();
rpc ~PPluginScriptableObject();
child:
/* NPP_NewStream */
rpc PBrowserStream(nsCString url,
uint32_t length,
uint32_t lastmodified,
PStreamNotify notifyData,
nsCString headers,
nsCString mimeType,
bool seekable)
returns (NPError rv,
uint16_t stype);
both:
/**
* ~PBrowserStream is for both NPN_DestroyStream and NPP_DestroyStream.
* @param artificial True when the stream is closed as a by-product of
* some other call (such as a failure in NPP_Write).
*/
rpc ~PBrowserStream(NPReason reason,
bool artificial);
parent:
/* NPN_NewStream */
rpc PPluginStream(nsCString mimeType,
nsCString target)
returns (NPError result);
both:
/**
* ~PPluginStream is for both NPN_DestroyStream and NPP_DestroyStream.
* @param artificial True when the stream is closed as a by-product of
* some other call (such as a failure in NPN_Write).
*/
rpc ~PPluginStream(NPReason reason, bool artificial);
};
} // namespace plugins
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,95 @@
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugins.
*
* The Initial Developer of the Original Code is
* Chris Jones <jones.chris.g@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Benjamin Smedberg <benjamin@smedbergs.us>
* Ben Turner <bent.mozilla@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
include protocol "PPluginInstance.ipdl";
include "npapi.h";
include "nsTArray.h";
include "mozilla/plugins/PluginMessageUtils.h";
using NPError;
using nsTArray<nsCString>;
using nsTArray<intptr_t>;
using mozilla::ipc::NPRemoteIdentifier;
using nsTArray<NPRemoteIdentifier>;
namespace mozilla {
namespace plugins {
rpc protocol PPluginModule
{
manages PPluginInstance;
child:
rpc NP_Initialize()
returns (NPError rv);
rpc PPluginInstance(nsCString aMimeType,
uint16_t aMode,
nsTArray<nsCString> aNames,
nsTArray<nsCString> aValues)
returns (NPError rv);
rpc ~PPluginInstance()
returns (NPError rv);
parent:
sync NPN_GetStringIdentifier(nsCString aString)
returns (NPRemoteIdentifier aId);
sync NPN_GetIntIdentifier(int32_t aInt)
returns (NPRemoteIdentifier aId);
// for the following two methods, the returned value is valid iff
// |err == NPERR_NO_ERROR|
sync NPN_UTF8FromIdentifier(NPRemoteIdentifier aId)
returns (NPError err, nsCString aString);
// technically |aInt| is undefined when |aId| is invalid. but it's
// nice to let the other side know that |aId| was invalid
sync NPN_IntFromIdentifier(NPRemoteIdentifier aId)
returns (NPError err, int32_t aInt);
sync NPN_IdentifierIsString(NPRemoteIdentifier aId)
returns (bool aIsString);
sync NPN_GetStringIdentifiers(nsTArray<nsCString> aNames)
returns (nsTArray<NPRemoteIdentifier> aIds);
};
} // namespace plugins
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,111 @@
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugins.
*
* The Initial Developer of the Original Code is
* Chris Jones <jones.chris.g@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Benjamin Smedberg <benjamin@smedbergs.us>
* Ben Turner <bent.mozilla@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
include protocol "PPluginInstance.ipdl";
include "npapi.h";
include "npruntime.h";
include "nsTArray.h";
include "mozilla/plugins/PluginMessageUtils.h";
using mozilla::ipc::NPRemoteIdentifier;
using nsTArray<NPRemoteIdentifier>;
using mozilla::void_t;
using mozilla::null_t;
using mozilla::ipc::NPRemoteVariant;
using nsTArray<NPRemoteVariant>;
namespace mozilla {
namespace plugins {
union Variant {
void_t;
null_t;
bool;
int;
double;
nsCString;
PPluginScriptableObject;
};
rpc protocol PPluginScriptableObject
{
manager PPluginInstance;
child:
// NPClass methods
rpc Invalidate();
rpc HasMethod(NPRemoteIdentifier aId)
returns (bool aHasMethod);
rpc Invoke(NPRemoteIdentifier aId,
nsTArray<NPRemoteVariant> aArgs)
returns (NPRemoteVariant aResult,
bool aSuccess);
rpc InvokeDefault(nsTArray<NPRemoteVariant> aArgs)
returns (NPRemoteVariant aResult,
bool aSuccess);
rpc HasProperty(NPRemoteIdentifier aId)
returns (bool aHasProperty);
rpc GetProperty(NPRemoteIdentifier aId)
returns (NPRemoteVariant aResult,
bool aSuccess);
rpc SetProperty(NPRemoteIdentifier aId,
NPRemoteVariant aValue)
returns (bool aSuccess);
rpc RemoveProperty(NPRemoteIdentifier aId)
returns (bool aSuccess);
rpc Enumerate()
returns (nsTArray<NPRemoteIdentifier> aProperties,
bool aSuccess);
rpc Construct(nsTArray<NPRemoteVariant> aArgs)
returns (NPRemoteVariant aResult,
bool aSuccess);
};
} // namespace plugins
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,59 @@
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugins.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation <http://www.mozilla.org/>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
include protocol "PPluginInstance.ipdl";
using mozilla::plugins::Buffer;
using NPError;
namespace mozilla {
namespace plugins {
/**
* PPluginStream represents an NPStream sent from the plugin to the browser.
*/
rpc protocol PPluginStream
{
manager PPluginInstance;
parent:
rpc NPN_Write(Buffer data) returns (int32_t written);
};
} // namespace plugins
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,17 @@
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
include protocol "PPluginInstance.ipdl";
namespace mozilla {
namespace plugins {
/**
* This empty protocol exists only to be constructed and destroyed.
*/
rpc protocol PStreamNotify
{
manager PPluginInstance;
};
} // namespace plugins
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,585 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Chris Jones <jones.chris.g@gmail.com>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "PluginInstanceChild.h"
#include "PluginModuleChild.h"
#include "BrowserStreamChild.h"
#include "PluginStreamChild.h"
#include "StreamNotifyChild.h"
using namespace mozilla::plugins;
#if defined(OS_LINUX)
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <gdk/gdk.h>
#include "gtk2xtbin.h"
#elif defined(OS_WIN)
#include <windows.h>
#endif
namespace {
static const char*
NPNVariableToString(NPNVariable aVar)
{
#define VARSTR(v_) case v_: return #v_
switch(aVar) {
VARSTR(NPNVxDisplay);
VARSTR(NPNVxtAppContext);
VARSTR(NPNVnetscapeWindow);
VARSTR(NPNVjavascriptEnabledBool);
VARSTR(NPNVasdEnabledBool);
VARSTR(NPNVisOfflineBool);
VARSTR(NPNVserviceManager);
VARSTR(NPNVDOMElement);
VARSTR(NPNVDOMWindow);
VARSTR(NPNVToolkit);
VARSTR(NPNVSupportsXEmbedBool);
VARSTR(NPNVWindowNPObject);
VARSTR(NPNVPluginElementNPObject);
VARSTR(NPNVSupportsWindowless);
VARSTR(NPNVprivateModeBool);
default: return "???";
}
#undef VARSTR
}
} /* anonymous namespace */
PluginInstanceChild::~PluginInstanceChild()
{
#if defined(OS_WIN)
DestroyPluginWindow();
#endif
}
NPError
PluginInstanceChild::NPN_GetValue(NPNVariable aVar,
void* aValue)
{
printf ("[PluginInstanceChild] NPN_GetValue(%s)\n",
NPNVariableToString(aVar));
switch(aVar) {
case NPNVSupportsWindowless:
// FIXME/cjones report true here and use XComposite + child
// surface to implement windowless plugins
*((NPBool*)aValue) = false;
return NPERR_NO_ERROR;
#if defined(OS_LINUX)
case NPNVSupportsXEmbedBool:
*((NPBool*)aValue) = true;
return NPERR_NO_ERROR;
case NPNVToolkit:
*((NPNToolkitType*)aValue) = NPNVGtk2;
return NPERR_NO_ERROR;
#elif defined(OS_WIN)
case NPNVToolkit:
return NPERR_GENERIC_ERROR;
#endif
case NPNVjavascriptEnabledBool: {
bool v = false;
NPError result;
if (!CallNPN_GetValue_NPNVjavascriptEnabledBool(&v, &result)) {
return NPERR_GENERIC_ERROR;
}
*static_cast<NPBool*>(aValue) = v;
return result;
}
case NPNVisOfflineBool: {
bool v = false;
NPError result;
if (!CallNPN_GetValue_NPNVisOfflineBool(&v, &result)) {
return NPERR_GENERIC_ERROR;
}
*static_cast<NPBool*>(aValue) = v;
return result;
}
case NPNVprivateModeBool: {
bool v = false;
NPError result;
if (!CallNPN_GetValue_NPNVprivateModeBool(&v, &result)) {
return NPERR_GENERIC_ERROR;
}
*static_cast<NPBool*>(aValue) = v;
return result;
}
default:
printf(" unhandled var %s\n", NPNVariableToString(aVar));
return NPERR_GENERIC_ERROR;
}
}
bool
PluginInstanceChild::AnswerNPP_GetValue_NPPVpluginScriptableNPObject(
PPluginScriptableObjectChild** value,
NPError* result)
{
NPObject* object;
*result = mPluginIface->getvalue(GetNPP(), NPPVpluginScriptableNPObject,
&object);
if (*result != NPERR_NO_ERROR) {
return true;
}
PluginScriptableObjectChild* actor = GetActorForNPObject(object);
if (!actor) {
PluginModuleChild::sBrowserFuncs.releaseobject(object);
*result = NPERR_GENERIC_ERROR;
return true;
}
PluginModuleChild::sBrowserFuncs.releaseobject(object);
*value = actor;
return true;
}
bool
PluginInstanceChild::AnswerNPP_HandleEvent(const NPEvent& event,
int16_t* handled)
{
// plugins might be fooling with these, make a copy
NPEvent evcopy = event;
*handled = mPluginIface->event(&mData, reinterpret_cast<void*>(&evcopy));
return true;
}
bool
PluginInstanceChild::AnswerNPP_SetWindow(const NPWindow& aWindow,
NPError* rv)
{
printf("[PluginInstanceChild] NPP_SetWindow(%lx, %d, %d)\n",
reinterpret_cast<unsigned long>(aWindow.window),
aWindow.width, aWindow.height);
#if defined(OS_LINUX)
// XXX/cjones: the minimum info is sent over IPC to allow this
// code to determine the rest. this code is possibly wrong on
// some systems, in some conditions
GdkNativeWindow handle = reinterpret_cast<uintptr_t>(aWindow.window);
mWindow.window = (void*) handle;
mWindow.width = aWindow.width;
mWindow.height = aWindow.height;
mWindow.type = NPWindowTypeWindow;
mWsInfo.display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
// FIXME/cjones: the code below is correct, but apparently to get
// a valid GdkWindow*, one needs to create the gtk_plug. but if we
// do that, then the plugin can't plug in to plug. a hacky solution
// may be to create the plug, then create another socket within that
// plug. yuck.
#if 0
mWsInfo.display = GDK_WINDOW_XDISPLAY(gdkWindow);
mWsInfo.colormap =
GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(gdkWindow));
GdkVisual* gdkVisual = gdk_drawable_get_visual(gdkWindow);
mWsInfo.visual = GDK_VISUAL_XVISUAL(gdkVisual);
mWsInfo.depth = gdkVisual->depth;
#endif
mWindow.ws_info = (void*) &mWsInfo;
*rv = mPluginIface->setwindow(&mData, &mWindow);
#elif defined(OS_WIN)
ReparentPluginWindow((HWND)aWindow.window);
SizePluginWindow(aWindow.width, aWindow.height);
mWindow.window = (void*)mPluginWindowHWND;
mWindow.width = aWindow.width;
mWindow.height = aWindow.height;
mWindow.type = NPWindowTypeWindow;
*rv = mPluginIface->setwindow(&mData, &mWindow);
if (*rv == NPERR_NO_ERROR) {
WNDPROC wndProc = reinterpret_cast<WNDPROC>(
GetWindowLongPtr(mPluginWindowHWND, GWLP_WNDPROC));
if (wndProc != PluginWindowProc) {
mPluginWndProc = reinterpret_cast<WNDPROC>(
SetWindowLongPtr(mPluginWindowHWND, GWLP_WNDPROC,
reinterpret_cast<LONG>(PluginWindowProc)));
}
}
#else
# error Implement me for your OS
#endif
return true;
}
bool
PluginInstanceChild::Initialize()
{
#if defined(OS_WIN)
if (!CreatePluginWindow())
return false;
#endif
return true;
}
#if defined(OS_WIN)
static const TCHAR kWindowClassName[] = TEXT("GeckoPluginWindow");
static const TCHAR kPluginInstanceChildProperty[] = TEXT("PluginInstanceChildProperty");
// static
bool
PluginInstanceChild::RegisterWindowClass()
{
static bool alreadyRegistered = false;
if (alreadyRegistered)
return true;
alreadyRegistered = true;
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_DBLCLKS;
wcex.lpfnWndProc = DummyWindowProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = GetModuleHandle(NULL);
wcex.hIcon = 0;
wcex.hCursor = 0;
wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW + 1);
wcex.lpszMenuName = 0;
wcex.lpszClassName = kWindowClassName;
wcex.hIconSm = 0;
return RegisterClassEx(&wcex) ? true : false;
}
bool
PluginInstanceChild::CreatePluginWindow()
{
if (!RegisterWindowClass())
return false;
if (!mPluginWindowHWND) {
mPluginWindowHWND =
CreateWindowEx(WS_EX_LEFT | WS_EX_LTRREADING |
WS_EX_NOPARENTNOTIFY | // XXXbent Get rid of this!
WS_EX_RIGHTSCROLLBAR,
kWindowClassName, 0,
WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0,
0, 0, NULL, 0, GetModuleHandle(NULL), 0);
if (!mPluginWindowHWND)
return false;
if (!SetProp(mPluginWindowHWND, kPluginInstanceChildProperty, this))
return false;
// Apparently some plugins require an ASCII WndProc.
SetWindowLongPtrA(mPluginWindowHWND, GWLP_WNDPROC,
reinterpret_cast<LONG>(DefWindowProcA));
}
return true;
}
void
PluginInstanceChild::DestroyPluginWindow()
{
if (mPluginWindowHWND) {
// Unsubclass the window.
WNDPROC wndProc = reinterpret_cast<WNDPROC>(
GetWindowLongPtr(mPluginWindowHWND, GWLP_WNDPROC));
if (wndProc == PluginWindowProc) {
NS_ASSERTION(mPluginWndProc, "Should have old proc here!");
SetWindowLongPtr(mPluginWindowHWND, GWLP_WNDPROC,
reinterpret_cast<LONG>(mPluginWndProc));
mPluginWndProc = 0;
}
RemoveProp(mPluginWindowHWND, kPluginInstanceChildProperty);
DestroyWindow(mPluginWindowHWND);
mPluginWindowHWND = 0;
}
}
void
PluginInstanceChild::ReparentPluginWindow(HWND hWndParent)
{
if (hWndParent != mPluginParentHWND && IsWindow(hWndParent)) {
LONG style = GetWindowLongPtr(mPluginWindowHWND, GWL_STYLE);
style |= WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
SetWindowLongPtr(mPluginWindowHWND, GWL_STYLE, style);
SetParent(mPluginWindowHWND, hWndParent);
ShowWindow(mPluginWindowHWND, SW_SHOWNA);
}
mPluginParentHWND = hWndParent;
}
void
PluginInstanceChild::SizePluginWindow(int width,
int height)
{
if (mPluginWindowHWND) {
SetWindowPos(mPluginWindowHWND, NULL, 0, 0, width, height,
SWP_NOZORDER | SWP_NOREPOSITION);
}
}
// See chromium's webplugin_delegate_impl.cc for explanation of this function.
// static
LRESULT CALLBACK
PluginInstanceChild::DummyWindowProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
return CallWindowProc(DefWindowProc, hWnd, message, wParam, lParam);
}
// static
LRESULT CALLBACK
PluginInstanceChild::PluginWindowProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
PluginInstanceChild* self = reinterpret_cast<PluginInstanceChild*>(
GetProp(hWnd, kPluginInstanceChildProperty));
if (!self) {
NS_NOTREACHED("Badness!");
return 0;
}
NS_ASSERTION(self->mPluginWindowHWND == hWnd, "Wrong window!");
LRESULT res = CallWindowProc(self->mPluginWndProc, hWnd, message, wParam,
lParam);
if (message == WM_CLOSE)
self->DestroyPluginWindow();
if (message == WM_NCDESTROY)
RemoveProp(hWnd, kPluginInstanceChildProperty);
return res;
}
#endif // OS_WIN
PPluginScriptableObjectChild*
PluginInstanceChild::AllocPPluginScriptableObject()
{
nsAutoPtr<PluginScriptableObjectChild>* object =
mScriptableObjects.AppendElement();
NS_ENSURE_TRUE(object, nsnull);
*object = new PluginScriptableObjectChild();
NS_ENSURE_TRUE(*object, nsnull);
return object->get();
}
bool
PluginInstanceChild::DeallocPPluginScriptableObject(PPluginScriptableObjectChild* aObject)
{
PluginScriptableObjectChild* object =
reinterpret_cast<PluginScriptableObjectChild*>(aObject);
PRUint32 count = mScriptableObjects.Length();
for (PRUint32 index = 0; index < count; index++) {
if (mScriptableObjects[index] == object) {
mScriptableObjects.RemoveElementAt(index);
return true;
}
}
NS_NOTREACHED("An actor we don't know about?!");
return false;
}
PBrowserStreamChild*
PluginInstanceChild::AllocPBrowserStream(const nsCString& url,
const uint32_t& length,
const uint32_t& lastmodified,
const PStreamNotifyChild* notifyData,
const nsCString& headers,
const nsCString& mimeType,
const bool& seekable,
NPError* rv,
uint16_t *stype)
{
return new BrowserStreamChild(this, url, length, lastmodified, headers,
mimeType, seekable, rv, stype);
}
bool
PluginInstanceChild::AnswerPBrowserStreamDestructor(PBrowserStreamChild* stream,
const NPError& reason,
const bool& artificial)
{
if (!artificial)
static_cast<BrowserStreamChild*>(stream)->NPP_DestroyStream(reason);
return true;
}
bool
PluginInstanceChild::DeallocPBrowserStream(PBrowserStreamChild* stream,
const NPError& reason,
const bool& artificial)
{
delete stream;
return true;
}
PPluginStreamChild*
PluginInstanceChild::AllocPPluginStream(const nsCString& mimeType,
const nsCString& target,
NPError* result)
{
NS_RUNTIMEABORT("not callable");
return NULL;
}
bool
PluginInstanceChild::AnswerPPluginStreamDestructor(PPluginStreamChild* stream,
const NPReason& reason,
const bool& artificial)
{
if (!artificial) {
static_cast<PluginStreamChild*>(stream)->NPP_DestroyStream(reason);
}
return true;
}
bool
PluginInstanceChild::DeallocPPluginStream(PPluginStreamChild* stream,
const NPError& reason,
const bool& artificial)
{
delete stream;
return true;
}
PStreamNotifyChild*
PluginInstanceChild::AllocPStreamNotify(const nsCString& url,
const nsCString& target,
const bool& post,
const nsCString& buffer,
const bool& file,
NPError* result)
{
NS_RUNTIMEABORT("not reached");
return NULL;
}
bool
PluginInstanceChild::DeallocPStreamNotify(PStreamNotifyChild* notifyData,
const NPReason& reason)
{
StreamNotifyChild* sn = static_cast<StreamNotifyChild*>(notifyData);
mPluginIface->urlnotify(&mData, sn->mURL.get(), reason, sn->mClosure);
delete sn;
return true;
}
PluginScriptableObjectChild*
PluginInstanceChild::GetActorForNPObject(NPObject* aObject)
{
NS_ASSERTION(aObject, "Null pointer!");
PluginScriptableObjectChild* actor =
PluginModuleChild::current()->GetActorForNPObject(aObject);
if (actor) {
PluginModuleChild::sBrowserFuncs.retainobject(aObject);
return actor;
}
actor = reinterpret_cast<PluginScriptableObjectChild*>(
CallPPluginScriptableObjectConstructor());
NS_ENSURE_TRUE(actor, nsnull);
actor->Initialize(this, aObject);
#ifdef DEBUG
bool ok =
#endif
PluginModuleChild::current()->RegisterNPObject(aObject, actor);
NS_ASSERTION(ok, "Out of memory?");
return actor;
}
NPError
PluginInstanceChild::NPN_NewStream(NPMIMEType aMIMEType, const char* aWindow,
NPStream** aStream)
{
PluginStreamChild* ps = new PluginStreamChild(this);
NPError result;
CallPPluginStreamConstructor(ps, nsDependentCString(aMIMEType),
NullableString(aWindow), &result);
if (NPERR_NO_ERROR != result) {
*aStream = NULL;
CallPPluginStreamDestructor(ps, NPERR_GENERIC_ERROR, true);
return result;
}
*aStream = &ps->mStream;
return NPERR_NO_ERROR;
}

Просмотреть файл

@ -0,0 +1,208 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Chris Jones <jones.chris.g@gmail.com>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef dom_plugins_PluginInstanceChild_h
#define dom_plugins_PluginInstanceChild_h 1
#include "mozilla/plugins/PPluginInstanceChild.h"
#include "mozilla/plugins/PluginScriptableObjectChild.h"
#include "npfunctions.h"
#include "nsAutoPtr.h"
#include "nsTArray.h"
#undef _MOZ_LOG
#define _MOZ_LOG(s) printf("[PluginInstanceChild] %s\n", s)
namespace mozilla {
namespace plugins {
class PBrowserStreamChild;
class BrowserStreamChild;
class PluginInstanceChild : public PPluginInstanceChild
{
friend class BrowserStreamChild;
friend class PluginStreamChild;
#ifdef OS_WIN
friend LRESULT CALLBACK PluginWindowProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam);
#endif
protected:
virtual bool AnswerNPP_SetWindow(const NPWindow& window, NPError* rv);
virtual bool
AnswerNPP_GetValue_NPPVpluginScriptableNPObject(PPluginScriptableObjectChild** value,
NPError* result);
virtual bool
AnswerNPP_HandleEvent(const NPEvent& event, int16_t* handled);
virtual PPluginScriptableObjectChild*
AllocPPluginScriptableObject();
virtual bool
DeallocPPluginScriptableObject(PPluginScriptableObjectChild* aObject);
virtual PBrowserStreamChild*
AllocPBrowserStream(const nsCString& url,
const uint32_t& length,
const uint32_t& lastmodified,
const PStreamNotifyChild* notifyData,
const nsCString& headers,
const nsCString& mimeType,
const bool& seekable,
NPError* rv,
uint16_t *stype);
virtual bool
AnswerPBrowserStreamDestructor(PBrowserStreamChild* stream,
const NPError& reason,
const bool& artificial);
virtual bool
DeallocPBrowserStream(PBrowserStreamChild* stream,
const NPError& reason,
const bool& artificial);
virtual PPluginStreamChild*
AllocPPluginStream(const nsCString& mimeType,
const nsCString& target,
NPError* result);
virtual bool
AnswerPPluginStreamDestructor(PPluginStreamChild* stream,
const NPReason& reason,
const bool& artificial);
virtual bool
DeallocPPluginStream(PPluginStreamChild* stream,
const NPReason& reason,
const bool& artificial);
virtual PStreamNotifyChild*
AllocPStreamNotify(const nsCString& url, const nsCString& target,
const bool& post, const nsCString& buffer,
const bool& file,
NPError* result);
virtual bool
DeallocPStreamNotify(PStreamNotifyChild* notifyData,
const NPReason& reason);
public:
PluginInstanceChild(const NPPluginFuncs* aPluginIface) :
mPluginIface(aPluginIface)
#if defined(OS_LINUX)
, mPlug(0)
#elif defined(OS_WIN)
, mPluginWindowHWND(0)
, mPluginWndProc(0)
, mPluginParentHWND(0)
#endif
{
memset(&mWindow, 0, sizeof(mWindow));
mData.ndata = (void*) this;
#if defined(OS_LINUX)
memset(&mWsInfo, 0, sizeof(mWsInfo));
#endif
}
virtual ~PluginInstanceChild();
bool Initialize();
NPP GetNPP()
{
return &mData;
}
NPError
NPN_GetValue(NPNVariable aVariable,
void* aValue);
PluginScriptableObjectChild*
GetActorForNPObject(NPObject* aObject);
NPError
NPN_NewStream(NPMIMEType aMIMEType, const char* aWindow,
NPStream** aStream);
private:
#if defined(OS_WIN)
static bool RegisterWindowClass();
bool CreatePluginWindow();
void DestroyPluginWindow();
void ReparentPluginWindow(HWND hWndParent);
void SizePluginWindow(int width, int height);
static LRESULT CALLBACK DummyWindowProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam);
static LRESULT CALLBACK PluginWindowProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam);
#endif
const NPPluginFuncs* mPluginIface;
NPP_t mData;
#ifdef OS_LINUX
GtkWidget* mPlug;
#endif
NPWindow mWindow;
#ifdef OS_LINUX
NPSetWindowCallbackStruct mWsInfo;
#elif defined(OS_WIN)
HWND mPluginWindowHWND;
WNDPROC mPluginWndProc;
HWND mPluginParentHWND;
#endif
nsTArray<nsAutoPtr<PluginScriptableObjectChild> > mScriptableObjects;
};
} // namespace plugins
} // namespace mozilla
#endif // ifndef dom_plugins_PluginInstanceChild_h

Просмотреть файл

@ -0,0 +1,415 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Chris Jones <jones.chris.g@gmail.com>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "PluginInstanceParent.h"
#include "BrowserStreamParent.h"
#include "PluginModuleParent.h"
#include "PluginStreamParent.h"
#include "StreamNotifyParent.h"
#include "npfunctions.h"
#include "nsAutoPtr.h"
using namespace mozilla::plugins;
PluginInstanceParent::PluginInstanceParent(PluginModuleParent* parent,
NPP npp,
const NPNetscapeFuncs* npniface)
: mParent(parent),
mNPP(npp),
mNPNIface(npniface)
{
}
PluginInstanceParent::~PluginInstanceParent()
{
}
PBrowserStreamParent*
PluginInstanceParent::AllocPBrowserStream(const nsCString& url,
const uint32_t& length,
const uint32_t& lastmodified,
const PStreamNotifyParent* notifyData,
const nsCString& headers,
const nsCString& mimeType,
const bool& seekable,
NPError* rv,
uint16_t *stype)
{
NS_RUNTIMEABORT("Not reachable");
return NULL;
}
bool
PluginInstanceParent::AnswerPBrowserStreamDestructor(PBrowserStreamParent* stream,
const NPError& reason,
const bool& artificial)
{
if (!artificial) {
static_cast<BrowserStreamParent*>(stream)->NPN_DestroyStream(reason);
}
return true;
}
bool
PluginInstanceParent::DeallocPBrowserStream(PBrowserStreamParent* stream,
const NPError& reason,
const bool& artificial)
{
delete stream;
return true;
}
PPluginStreamParent*
PluginInstanceParent::AllocPPluginStream(const nsCString& mimeType,
const nsCString& target,
NPError* result)
{
return new PluginStreamParent(this, mimeType, target, result);
}
bool
PluginInstanceParent::DeallocPPluginStream(PPluginStreamParent* stream,
const NPError& reason,
const bool& artificial)
{
if (!artificial) {
static_cast<PluginStreamParent*>(stream)->NPN_DestroyStream(reason);
}
delete stream;
return true;
}
bool
PluginInstanceParent::AnswerNPN_GetValue_NPNVjavascriptEnabledBool(
bool* value,
NPError* result)
{
NPBool v;
*result = mNPNIface->getvalue(mNPP, NPNVjavascriptEnabledBool, &v);
*value = v;
return true;
}
bool
PluginInstanceParent::AnswerNPN_GetValue_NPNVisOfflineBool(bool* value,
NPError* result)
{
NPBool v;
*result = mNPNIface->getvalue(mNPP, NPNVisOfflineBool, &v);
*value = v;
return true;
}
bool
PluginInstanceParent::AnswerNPN_GetValue_NPNVWindowNPObject(
PPluginScriptableObjectParent** value,
NPError* result)
{
// TODO NPRuntime
*value = NULL;
*result = NPERR_GENERIC_ERROR;
return true;
}
bool
PluginInstanceParent::AnswerNPN_GetValue_NPNVPluginElementNPObject(
PPluginScriptableObjectParent** value,
NPError* result)
{
// TODO NPRuntime
*value = NULL;
*result = NPERR_GENERIC_ERROR;
return true;
}
bool
PluginInstanceParent::AnswerNPN_GetValue_NPNVprivateModeBool(bool* value,
NPError* result)
{
NPBool v;
*result = mNPNIface->getvalue(mNPP, NPNVprivateModeBool, &v);
*value = v;
return true;
}
bool
PluginInstanceParent::AnswerNPN_GetURL(const nsCString& url,
const nsCString& target,
NPError* result)
{
*result = mNPNIface->geturl(mNPP,
NullableStringGet(url),
NullableStringGet(target));
return true;
}
bool
PluginInstanceParent::AnswerNPN_PostURL(const nsCString& url,
const nsCString& target,
const nsCString& buffer,
const bool& file,
NPError* result)
{
*result = mNPNIface->posturl(mNPP, url.get(), NullableStringGet(target),
buffer.Length(), buffer.get(), file);
return true;
}
PStreamNotifyParent*
PluginInstanceParent::AllocPStreamNotify(const nsCString& url,
const nsCString& target,
const bool& post,
const nsCString& buffer,
const bool& file,
NPError* result)
{
StreamNotifyParent* notifyData = new StreamNotifyParent();
if (!post) {
*result = mNPNIface->geturlnotify(mNPP,
NullableStringGet(url),
NullableStringGet(target),
notifyData);
}
else {
*result = mNPNIface->posturlnotify(mNPP,
NullableStringGet(url),
NullableStringGet(target),
buffer.Length(), buffer.get(),
file, notifyData);
}
// TODO: what if this method fails?
return notifyData;
}
bool
PluginInstanceParent::DeallocPStreamNotify(PStreamNotifyParent* notifyData,
const NPReason& reason)
{
delete notifyData;
return true;
}
NPError
PluginInstanceParent::NPP_SetWindow(NPWindow* aWindow)
{
_MOZ_LOG(__FUNCTION__);
NS_ENSURE_TRUE(aWindow, NPERR_GENERIC_ERROR);
NPError prv;
if (!CallNPP_SetWindow(*aWindow, &prv))
return NPERR_GENERIC_ERROR;
return prv;
}
NPError
PluginInstanceParent::NPP_GetValue(NPPVariable aVariable,
void* _retval)
{
_MOZ_LOG(__FUNCTION__);
switch (aVariable) {
#ifdef OS_LINUX
// FIXME/cjones: HACK ALERT! should forward to child
case NPPVpluginNeedsXEmbed:
(*(PRBool*)_retval) = PR_TRUE;
return NPERR_NO_ERROR;
#endif
case NPPVpluginScriptableNPObject: {
PPluginScriptableObjectParent* actor;
NPError rv;
if (!CallNPP_GetValue_NPPVpluginScriptableNPObject(&actor, &rv)) {
return NPERR_GENERIC_ERROR;
}
if (NPERR_NO_ERROR != rv) {
return rv;
}
const NPNetscapeFuncs* npn = mParent->GetNetscapeFuncs();
if (!npn) {
NS_WARNING("No netscape functions?!");
return NPERR_GENERIC_ERROR;
}
NPObject* object =
reinterpret_cast<PluginScriptableObjectParent*>(actor)->
GetObject();
NS_ASSERTION(object, "This shouldn't ever be null!");
(*(NPObject**)_retval) = npn->retainobject(object);
return NPERR_NO_ERROR;
}
// TODO: more values
default:
return NPERR_GENERIC_ERROR;
}
}
int16_t
PluginInstanceParent::NPP_HandleEvent(void* event)
{
_MOZ_LOG(__FUNCTION__);
int16_t handled;
if (!CallNPP_HandleEvent(*reinterpret_cast<NPEvent*>(event),
&handled)) {
return 0; // no good way to handle errors here...
}
return handled;
}
NPError
PluginInstanceParent::NPP_NewStream(NPMIMEType type, NPStream* stream,
NPBool seekable, uint16_t* stype)
{
_MOZ_LOG(__FUNCTION__);
BrowserStreamParent* bs = new BrowserStreamParent(this, stream);
NPError err;
// TODO are any of these strings nullable?
if (!CallPBrowserStreamConstructor(bs,
nsCString(stream->url),
stream->end,
stream->lastmodified,
static_cast<PStreamNotifyParent*>(stream->notifyData),
nsCString(stream->headers),
nsCString(type), seekable, &err, stype))
return NPERR_GENERIC_ERROR;
if (NPERR_NO_ERROR != err)
CallPBrowserStreamDestructor(bs, NPERR_GENERIC_ERROR, true);
return err;
}
NPError
PluginInstanceParent::NPP_DestroyStream(NPStream* stream, NPReason reason)
{
_MOZ_LOG(__FUNCTION__);
AStream* s = static_cast<AStream*>(stream->pdata);
if (s->IsBrowserStream()) {
BrowserStreamParent* sp =
static_cast<BrowserStreamParent*>(s);
if (sp->mNPP != this)
NS_RUNTIMEABORT("Mismatched plugin data");
CallPBrowserStreamDestructor(sp, reason, false);
return NPERR_NO_ERROR;
}
else {
PluginStreamParent* sp =
static_cast<PluginStreamParent*>(s);
if (sp->mInstance != this)
NS_RUNTIMEABORT("Mismatched plugin data");
CallPPluginStreamDestructor(sp, reason, false);
return NPERR_NO_ERROR;
}
}
PPluginScriptableObjectParent*
PluginInstanceParent::AllocPPluginScriptableObject()
{
nsAutoPtr<PluginScriptableObjectParent>* object =
mScriptableObjects.AppendElement();
NS_ENSURE_TRUE(object, nsnull);
*object = new PluginScriptableObjectParent();
NS_ENSURE_TRUE(*object, nsnull);
return object->get();
}
bool
PluginInstanceParent::DeallocPPluginScriptableObject(
PPluginScriptableObjectParent* aObject)
{
PluginScriptableObjectParent* object =
reinterpret_cast<PluginScriptableObjectParent*>(aObject);
PRUint32 count = mScriptableObjects.Length();
for (PRUint32 index = 0; index < count; index++) {
if (mScriptableObjects[index] == object) {
mScriptableObjects.RemoveElementAt(index);
return true;
}
}
NS_NOTREACHED("An actor we don't know about?!");
return false;
}
bool
PluginInstanceParent::AnswerPPluginScriptableObjectConstructor(
PPluginScriptableObjectParent* aActor)
{
const NPNetscapeFuncs* npn = mParent->GetNetscapeFuncs();
if (!npn) {
NS_WARNING("No netscape function pointers?!");
return false;
}
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(
npn->createobject(mNPP, PluginScriptableObjectParent::GetClass()));
if (!object) {
return false;
}
reinterpret_cast<PluginScriptableObjectParent*>(aActor)->Initialize(
const_cast<PluginInstanceParent*>(this), object);
return true;
}
void
PluginInstanceParent::NPP_URLNotify(const char* url, NPReason reason,
void* notifyData)
{
_MOZ_LOG(__FUNCTION__);
PStreamNotifyParent* streamNotify =
static_cast<PStreamNotifyParent*>(notifyData);
CallPStreamNotifyDestructor(streamNotify, reason);
}

Просмотреть файл

@ -0,0 +1,185 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Chris Jones <jones.chris.g@gmail.com>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef dom_plugins_PluginInstanceParent_h
#define dom_plugins_PluginInstanceParent_h 1
#include "mozilla/plugins/PPluginInstanceParent.h"
#include "mozilla/plugins/PluginScriptableObjectParent.h"
#include "npfunctions.h"
#include "nsAutoPtr.h"
#include "nsTArray.h"
#undef _MOZ_LOG
#define _MOZ_LOG(s) printf("[PluginInstanceParent] %s\n", s)
namespace mozilla {
namespace plugins {
class PBrowserStreamParent;
class BrowserStreamParent;
class PluginModuleParent;
class PluginInstanceParent : public PPluginInstanceParent
{
friend class PluginModuleParent;
friend class BrowserStreamParent;
friend class PluginStreamParent;
public:
PluginInstanceParent(PluginModuleParent* parent,
NPP npp,
const NPNetscapeFuncs* npniface);
virtual ~PluginInstanceParent();
virtual PPluginScriptableObjectParent*
AllocPPluginScriptableObject();
virtual bool
AnswerPPluginScriptableObjectConstructor(PPluginScriptableObjectParent* aActor);
virtual bool
DeallocPPluginScriptableObject(PPluginScriptableObjectParent* aObject);
virtual PBrowserStreamParent*
AllocPBrowserStream(const nsCString& url,
const uint32_t& length,
const uint32_t& lastmodified,
const PStreamNotifyParent* notifyData,
const nsCString& headers,
const nsCString& mimeType,
const bool& seekable,
NPError* rv,
uint16_t *stype);
virtual bool
AnswerPBrowserStreamDestructor(PBrowserStreamParent* stream,
const NPError& reason,
const bool& artificial);
virtual bool
DeallocPBrowserStream(PBrowserStreamParent* stream,
const NPError& reason,
const bool& artificial);
virtual PPluginStreamParent*
AllocPPluginStream(const nsCString& mimeType,
const nsCString& target,
NPError* result);
virtual bool
DeallocPPluginStream(PPluginStreamParent* stream,
const NPError& reason,
const bool& artificial);
virtual bool
AnswerNPN_GetValue_NPNVjavascriptEnabledBool(bool* value, NPError* result);
virtual bool
AnswerNPN_GetValue_NPNVisOfflineBool(bool* value, NPError* result);
virtual bool
AnswerNPN_GetValue_NPNVWindowNPObject(
PPluginScriptableObjectParent** value,
NPError* result);
virtual bool
AnswerNPN_GetValue_NPNVPluginElementNPObject(
PPluginScriptableObjectParent** value,
NPError* result);
virtual bool
AnswerNPN_GetValue_NPNVprivateModeBool(bool* value, NPError* result);
virtual bool
AnswerNPN_GetURL(const nsCString& url, const nsCString& target,
NPError *result);
virtual bool
AnswerNPN_PostURL(const nsCString& url, const nsCString& target,
const nsCString& buffer, const bool& file,
NPError* result);
virtual PStreamNotifyParent*
AllocPStreamNotify(const nsCString& url, const nsCString& target,
const bool& post, const nsCString& buffer,
const bool& file,
NPError* result);
virtual bool
DeallocPStreamNotify(PStreamNotifyParent* notifyData,
const NPReason& reason);
NPError NPP_SetWindow(NPWindow* aWindow);
NPError NPP_GetValue(NPPVariable variable, void *ret_value);
NPError NPP_SetValue(NPNVariable variable, void *value)
{
_MOZ_LOG(__FUNCTION__);
return 1;
}
NPError NPP_NewStream(NPMIMEType type, NPStream* stream,
NPBool seekable, uint16_t* stype);
NPError NPP_DestroyStream(NPStream* stream, NPReason reason);
void NPP_Print(NPPrint* platformPrint)
{
_MOZ_LOG(__FUNCTION__);
}
int16_t NPP_HandleEvent(void* event);
void NPP_URLNotify(const char* url, NPReason reason, void* notifyData);
PluginModuleParent* GetModule()
{
return mParent;
}
private:
PluginModuleParent* mParent;
NPP mNPP;
const NPNetscapeFuncs* mNPNIface;
nsTArray<nsAutoPtr<PluginScriptableObjectParent> > mScriptableObjects;
};
} // namespace plugins
} // namespace mozilla
#endif // ifndef dom_plugins_PluginInstanceParent_h

Просмотреть файл

@ -0,0 +1,474 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Chris Jones <jones.chris.g@gmail.com>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef DOM_PLUGINS_PLUGINMESSAGEUTILS_H
#define DOM_PLUGINS_PLUGINMESSAGEUTILS_H
#include "IPC/IPCMessageUtils.h"
#include "npapi.h"
#include "npruntime.h"
#include "nsAutoPtr.h"
#include "nsStringGlue.h"
namespace mozilla {
// XXX might want to move these to nscore.h or something, they can be
// generally useful
struct void_t { };
struct null_t { };
// XXX Uberhack, remove this typedef and forward decl.
namespace plugins {
class Variant;
}
namespace ipc {
typedef intptr_t NPRemoteIdentifier;
typedef mozilla::plugins::Variant NPRemoteVariant;
} /* namespace ipc */
namespace plugins {
/**
* This is NPByteRange without the linked list.
*/
struct IPCByteRange
{
int32_t offset;
uint32_t length;
};
typedef std::vector<IPCByteRange> IPCByteRanges;
typedef nsCString Buffer;
} /* namespace plugins */
} /* namespace mozilla */
namespace {
// in NPAPI, char* == NULL is sometimes meaningful. the following is
// helper code for dealing with nullable nsCString's
nsCString
NullableString(const char* aString)
{
if (!aString) {
nsCString str;
str.SetIsVoid(PR_TRUE);
return str;
}
return nsCString(aString);
}
} // namespace <anon>
// TODO is there any safe way for this to be a function?
#define NullableStringGet(__string) \
( __string.IsVoid() ? NULL : __string.get())
namespace IPC {
template <>
struct ParamTraits<NPRect>
{
typedef NPRect paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
WriteParam(aMsg, aParam.top);
WriteParam(aMsg, aParam.left);
WriteParam(aMsg, aParam.bottom);
WriteParam(aMsg, aParam.right);
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
uint16_t top, left, bottom, right;
if (ReadParam(aMsg, aIter, &top) &&
ReadParam(aMsg, aIter, &left) &&
ReadParam(aMsg, aIter, &bottom) &&
ReadParam(aMsg, aIter, &right)) {
aResult->top = top;
aResult->left = left;
aResult->bottom = bottom;
aResult->right = right;
return true;
}
return false;
}
static void Log(const paramType& aParam, std::wstring* aLog)
{
aLog->append(StringPrintf(L"[%u, %u, %u, %u]", aParam.top, aParam.left,
aParam.bottom, aParam.right));
}
};
template <>
struct ParamTraits<NPWindowType>
{
typedef NPWindowType paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
aMsg->WriteInt16(int16(aParam));
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
int16 result;
if (aMsg->ReadInt16(aIter, &result)) {
*aResult = paramType(result);
return true;
}
return false;
}
static void Log(const paramType& aParam, std::wstring* aLog)
{
aLog->append(StringPrintf(L"%d", int16(aParam)));
}
};
template <>
struct ParamTraits<NPWindow>
{
typedef NPWindow paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
aMsg->WriteULong(reinterpret_cast<unsigned long>(aParam.window));
WriteParam(aMsg, aParam.x);
WriteParam(aMsg, aParam.y);
WriteParam(aMsg, aParam.width);
WriteParam(aMsg, aParam.height);
WriteParam(aMsg, aParam.clipRect);
// we don't serialize ws_info because it stores pointers to this
// process's address space. it is reconstructed for each process
// using the window ID
WriteParam(aMsg, aParam.type);
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
unsigned long window;
int32_t x, y;
uint32_t width, height;
NPWindowType type;
if (aMsg->ReadULong(aIter, &window) &&
ReadParam(aMsg, aIter, &x) &&
ReadParam(aMsg, aIter, &y) &&
ReadParam(aMsg, aIter, &width) &&
ReadParam(aMsg, aIter, &height) &&
ReadParam(aMsg, aIter, &type)) {
aResult->window = (void*)window;
aResult->x = x;
aResult->y = y;
aResult->width = width;
aResult->height = height;
#if defined(XP_UNIX) && !defined(XP_MACOSX)
aResult->ws_info = 0; // graphics code fills this in
#endif
aResult->type = type;
return true;
}
return false;
}
static void Log(const paramType& aParam, std::wstring* aLog)
{
aLog->append(StringPrintf(L"[%u, %d, %d, %u, %u, %d",
(unsigned long)aParam.window,
aParam.x, aParam.y, aParam.width,
aParam.height, (long)aParam.type));
}
};
template <>
struct ParamTraits<NPString>
{
typedef NPString paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
WriteParam(aMsg, aParam.UTF8Length);
aMsg->WriteBytes(aParam.UTF8Characters,
aParam.UTF8Length * sizeof(NPUTF8));
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
if (ReadParam(aMsg, aIter, &aResult->UTF8Length)) {
int byteCount = aResult->UTF8Length * sizeof(NPUTF8);
if (!byteCount) {
aResult->UTF8Characters = "\0";
return true;
}
const char* messageBuffer = nsnull;
nsAutoArrayPtr<char> newBuffer(new char[byteCount]);
if (newBuffer && aMsg->ReadBytes(aIter, &messageBuffer, byteCount )) {
memcpy((void*)messageBuffer, newBuffer.get(), byteCount);
aResult->UTF8Characters = newBuffer.forget();
return true;
}
}
return false;
}
static void Log(const paramType& aParam, std::wstring* aLog)
{
aLog->append(StringPrintf(L"%s", aParam.UTF8Characters));
}
};
template <>
struct ParamTraits<NPVariant>
{
typedef NPVariant paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
if (NPVARIANT_IS_VOID(aParam)) {
aMsg->WriteInt(0);
return;
}
if (NPVARIANT_IS_NULL(aParam)) {
aMsg->WriteInt(1);
return;
}
if (NPVARIANT_IS_BOOLEAN(aParam)) {
aMsg->WriteInt(2);
WriteParam(aMsg, NPVARIANT_TO_BOOLEAN(aParam));
return;
}
if (NPVARIANT_IS_INT32(aParam)) {
aMsg->WriteInt(3);
WriteParam(aMsg, NPVARIANT_TO_INT32(aParam));
return;
}
if (NPVARIANT_IS_DOUBLE(aParam)) {
aMsg->WriteInt(4);
WriteParam(aMsg, NPVARIANT_TO_DOUBLE(aParam));
return;
}
if (NPVARIANT_IS_STRING(aParam)) {
aMsg->WriteInt(5);
WriteParam(aMsg, NPVARIANT_TO_STRING(aParam));
return;
}
NS_ERROR("Unsupported type!");
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
int type;
if (!aMsg->ReadInt(aIter, &type)) {
return false;
}
switch (type) {
case 0:
VOID_TO_NPVARIANT(*aResult);
return true;
case 1:
NULL_TO_NPVARIANT(*aResult);
return true;
case 2: {
bool value;
if (ReadParam(aMsg, aIter, &value)) {
BOOLEAN_TO_NPVARIANT(value, *aResult);
return true;
}
} break;
case 3: {
int32 value;
if (ReadParam(aMsg, aIter, &value)) {
INT32_TO_NPVARIANT(value, *aResult);
return true;
}
} break;
case 4: {
double value;
if (ReadParam(aMsg, aIter, &value)) {
DOUBLE_TO_NPVARIANT(value, *aResult);
return true;
}
} break;
case 5: {
NPString value;
if (ReadParam(aMsg, aIter, &value)) {
STRINGN_TO_NPVARIANT(value.UTF8Characters, value.UTF8Length,
*aResult);
return true;
}
} break;
default:
NS_ERROR("Unsupported type!");
}
return false;
}
static void Log(const paramType& aParam, std::wstring* aLog)
{
if (NPVARIANT_IS_VOID(aParam)) {
aLog->append(L"[void]");
return;
}
if (NPVARIANT_IS_NULL(aParam)) {
aLog->append(L"[null]");
return;
}
if (NPVARIANT_IS_BOOLEAN(aParam)) {
LogParam(NPVARIANT_TO_BOOLEAN(aParam), aLog);
return;
}
if (NPVARIANT_IS_INT32(aParam)) {
LogParam(NPVARIANT_TO_INT32(aParam), aLog);
return;
}
if (NPVARIANT_IS_DOUBLE(aParam)) {
LogParam(NPVARIANT_TO_DOUBLE(aParam), aLog);
return;
}
if (NPVARIANT_IS_STRING(aParam)) {
LogParam(NPVARIANT_TO_STRING(aParam), aLog);
return;
}
NS_ERROR("Unsupported type!");
}
};
template<>
struct ParamTraits<mozilla::void_t>
{
typedef mozilla::void_t paramType;
static void Write(Message* aMsg, const paramType& aParam) { }
static bool
Read(const Message* aMsg, void** aIter, paramType* aResult)
{
*aResult = paramType();
return true;
}
};
template<>
struct ParamTraits<mozilla::null_t>
{
typedef mozilla::null_t paramType;
static void Write(Message* aMsg, const paramType& aParam) { }
static bool
Read(const Message* aMsg, void** aIter, paramType* aResult)
{
*aResult = paramType();
return true;
}
};
template <>
struct ParamTraits<mozilla::plugins::IPCByteRange>
{
typedef mozilla::plugins::IPCByteRange paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
WriteParam(aMsg, aParam.offset);
WriteParam(aMsg, aParam.length);
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
paramType p;
if (ReadParam(aMsg, aIter, &p.offset) &&
ReadParam(aMsg, aIter, &p.length)) {
*aResult = p;
return true;
}
return false;
}
};
} /* namespace IPC */
// Serializing NPEvents is completely platform-specific and can be rather
// intricate depending on the platform. So for readability we split it
// into separate files and have the only macro crud live here.
//
// NB: these guards are based on those where struct NPEvent is defined
// in npapi.h. They should be kept in sync.
#if defined(XP_MACOSX)
# include "mozilla/plugins/NPEventOSX.h"
#elif defined(XP_WIN)
# include "mozilla/plugins/NPEventWindows.h"
#elif defined(XP_OS2)
# error Sorry, OS/2 is not supported
#elif defined(XP_UNIX) && defined(MOZ_X11)
# include "mozilla/plugins/NPEventX11.h"
#else
# error Unsupported platform
#endif
#endif /* DOM_PLUGINS_PLUGINMESSAGEUTILS_H */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,167 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Ben Turner <bent.mozilla@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chris Jones <jones.chris.g@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef dom_plugins_PluginModuleChild_h
#define dom_plugins_PluginModuleChild_h 1
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "prlink.h"
#include "npapi.h"
#include "npfunctions.h"
#include "nsAutoPtr.h"
#include "nsDataHashtable.h"
#include "nsHashKeys.h"
#include "mozilla/plugins/PPluginModuleChild.h"
#include "mozilla/plugins/PluginInstanceChild.h"
// NOTE: stolen from nsNPAPIPlugin.h
/*
* Use this macro before each exported function
* (between the return address and the function
* itself), to ensure that the function has the
* right calling conventions on OS/2.
*/
#ifdef XP_OS2
#define NP_CALLBACK _System
#else
#define NP_CALLBACK
#endif
#if defined(XP_WIN)
#define NS_NPAPIPLUGIN_CALLBACK(_type, _name) _type (__stdcall * _name)
#elif defined(XP_OS2)
#define NS_NPAPIPLUGIN_CALLBACK(_type, _name) _type (_System * _name)
#else
#define NS_NPAPIPLUGIN_CALLBACK(_type, _name) _type (* _name)
#endif
typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_GETENTRYPOINTS) (NPPluginFuncs* pCallbacks);
typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_PLUGININIT) (const NPNetscapeFuncs* pCallbacks);
typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_PLUGINUNIXINIT) (const NPNetscapeFuncs* pCallbacks, NPPluginFuncs* fCallbacks);
typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_PLUGINSHUTDOWN) (void);
#ifdef XP_MACOSX
typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_MAIN) (NPNetscapeFuncs* nCallbacks, NPPluginFuncs* pCallbacks, NPP_ShutdownProcPtr* unloadProcPtr);
#endif
#undef _MOZ_LOG
#define _MOZ_LOG(s) printf("[NPAPIPluginChild] %s\n", s)
namespace mozilla {
namespace plugins {
class PluginScriptableObjectChild;
class PluginModuleChild : public PPluginModuleChild
{
protected:
// Implement the PPluginModuleChild interface
virtual bool AnswerNP_Initialize(NPError* rv);
virtual PPluginInstanceChild*
AllocPPluginInstance(const nsCString& aMimeType,
const uint16_t& aMode,
const nsTArray<nsCString>& aNames,
const nsTArray<nsCString>& aValues,
NPError* rv);
virtual bool
DeallocPPluginInstance(PPluginInstanceChild* aActor,
NPError* rv);
virtual bool
AnswerPPluginInstanceConstructor(PPluginInstanceChild* aActor,
const nsCString& aMimeType,
const uint16_t& aMode,
const nsTArray<nsCString>& aNames,
const nsTArray<nsCString>& aValues,
NPError* rv);
public:
PluginModuleChild();
virtual ~PluginModuleChild();
bool Init(const std::string& aPluginFilename,
MessageLoop* aIOLoop,
IPC::Channel* aChannel);
void CleanUp();
static const NPNetscapeFuncs sBrowserFuncs;
static PluginModuleChild* current();
bool RegisterNPObject(NPObject* aObject,
PluginScriptableObjectChild* aActor);
void UnregisterNPObject(NPObject* aObject);
PluginScriptableObjectChild* GetActorForNPObject(NPObject* aObject);
private:
bool InitGraphics();
std::string mPluginFilename;
PRLibrary* mLibrary;
// we get this from the plugin
#ifdef OS_LINUX
NP_PLUGINUNIXINIT mInitializeFunc;
#elif OS_WIN
NP_PLUGININIT mInitializeFunc;
NP_GETENTRYPOINTS mGetEntryPointsFunc;
#endif
NP_PLUGINSHUTDOWN mShutdownFunc;
NPPluginFuncs mFunctions;
NPSavedData mSavedData;
nsDataHashtable<nsVoidPtrHashKey, PluginScriptableObjectChild*> mObjectMap;
};
} /* namespace plugins */
} /* namespace mozilla */
#endif // ifndef dom_plugins_PluginModuleChild_h

Просмотреть файл

@ -0,0 +1,504 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Chris Jones <jones.chris.g@gmail.com>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/plugins/PluginModuleParent.h"
#include "mozilla/plugins/BrowserStreamParent.h"
#include "nsNPAPIPlugin.h"
using mozilla::SharedLibrary;
using mozilla::ipc::NPRemoteIdentifier;
using namespace mozilla::plugins;
PR_STATIC_ASSERT(sizeof(NPIdentifier) == sizeof(void*));
// HACKS
PluginModuleParent* PluginModuleParent::Shim::HACK_target;
SharedLibrary*
PluginModuleParent::LoadModule(const char* aFilePath, PRLibrary* aLibrary)
{
_MOZ_LOG(__FUNCTION__);
// Block on the child process being launched and initialized.
PluginModuleParent* parent = new PluginModuleParent(aFilePath);
parent->mSubprocess.Launch();
parent->Open(parent->mSubprocess.GetChannel());
// FIXME/cjones: leaking PluginModuleParents ...
return parent->mShim;
}
PluginModuleParent::PluginModuleParent(const char* aFilePath) :
mFilePath(aFilePath),
mSubprocess(aFilePath),
ALLOW_THIS_IN_INITIALIZER_LIST(mShim(new Shim(this)))
{
#ifdef DEBUG
PRBool ok =
#endif
mValidIdentifiers.Init();
NS_ASSERTION(ok, "Out of memory!");
}
PluginModuleParent::~PluginModuleParent()
{
_MOZ_LOG(" (closing Shim ...)");
delete mShim;
}
PPluginInstanceParent*
PluginModuleParent::AllocPPluginInstance(const nsCString& aMimeType,
const uint16_t& aMode,
const nsTArray<nsCString>& aNames,
const nsTArray<nsCString>& aValues,
NPError* rv)
{
NS_ERROR("Not reachable!");
return NULL;
}
bool
PluginModuleParent::DeallocPPluginInstance(PPluginInstanceParent* aActor,
NPError* _retval)
{
_MOZ_LOG(__FUNCTION__);
delete aActor;
return true;
}
void
PluginModuleParent::SetPluginFuncs(NPPluginFuncs* aFuncs)
{
aFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
aFuncs->javaClass = nsnull;
// FIXME/cjones: /should/ dynamically allocate shim trampoline.
// but here we just HACK
aFuncs->newp = Shim::NPP_New;
aFuncs->destroy = NPP_Destroy;
aFuncs->setwindow = NPP_SetWindow;
aFuncs->newstream = NPP_NewStream;
aFuncs->destroystream = NPP_DestroyStream;
aFuncs->asfile = NPP_StreamAsFile;
aFuncs->writeready = NPP_WriteReady;
aFuncs->write = NPP_Write;
aFuncs->print = NPP_Print;
aFuncs->event = NPP_HandleEvent;
aFuncs->urlnotify = NPP_URLNotify;
aFuncs->getvalue = NPP_GetValue;
aFuncs->setvalue = NPP_SetValue;
}
#ifdef OS_LINUX
NPError
PluginModuleParent::NP_Initialize(const NPNetscapeFuncs* npnIface,
NPPluginFuncs* nppIface)
{
_MOZ_LOG(__FUNCTION__);
mNPNIface = npnIface;
NPError prv;
if (!CallNP_Initialize(&prv))
return NPERR_GENERIC_ERROR;
else if (NPERR_NO_ERROR != prv)
return prv;
SetPluginFuncs(nppIface);
return NPERR_NO_ERROR;
}
#else
NPError
PluginModuleParent::NP_Initialize(const NPNetscapeFuncs* npnIface)
{
_MOZ_LOG(__FUNCTION__);
mNPNIface = npnIface;
NPError prv;
if (!CallNP_Initialize(&prv))
return NPERR_GENERIC_ERROR;
return prv;
}
NPError
PluginModuleParent::NP_GetEntryPoints(NPPluginFuncs* nppIface)
{
NS_ASSERTION(nppIface, "Null pointer!");
SetPluginFuncs(nppIface);
return NPERR_NO_ERROR;
}
#endif
NPError
PluginModuleParent::NPP_New(NPMIMEType pluginType,
NPP instance,
uint16_t mode,
int16_t argc,
char* argn[],
char* argv[],
NPSavedData* saved)
{
_MOZ_LOG(__FUNCTION__);
// create the instance on the other side
nsTArray<nsCString> names;
nsTArray<nsCString> values;
for (int i = 0; i < argc; ++i) {
names.AppendElement(nsDependentCString(argn[i]));
values.AppendElement(nsDependentCString(argv[i]));
}
NPError prv = NPERR_GENERIC_ERROR;
nsAutoPtr<PluginInstanceParent> parentInstance(
new PluginInstanceParent(this, instance, mNPNIface));
instance->pdata = parentInstance.get();
if (!CallPPluginInstanceConstructor(parentInstance,
nsDependentCString(pluginType), mode,
names,values, &prv))
return NPERR_GENERIC_ERROR;
printf ("[PluginModuleParent] %s: got return value %hd\n", __FUNCTION__,
prv);
if (NPERR_NO_ERROR == prv)
parentInstance.forget();
return prv;
}
NPError
PluginModuleParent::NPP_Destroy(NPP instance,
NPSavedData** save)
{
// FIXME/cjones:
// (1) send a "destroy" message to the child
// (2) the child shuts down its instance
// (3) remove both parent and child IDs from map
// (4) free parent
_MOZ_LOG(__FUNCTION__);
PluginInstanceParent* parentInstance =
static_cast<PluginInstanceParent*>(instance->pdata);
NPError prv;
if (!Shim::HACK_target->CallPPluginInstanceDestructor(parentInstance, &prv)) {
prv = NPERR_GENERIC_ERROR;
}
instance->pdata = nsnull;
return prv;
}
bool
PluginModuleParent::EnsureValidNPIdentifier(NPIdentifier aIdentifier)
{
if (!mValidIdentifiers.GetEntry(aIdentifier)) {
nsVoidPtrHashKey* newEntry = mValidIdentifiers.PutEntry(aIdentifier);
if (!newEntry) {
NS_ERROR("Out of memory?");
return false;
}
}
return true;
}
NPIdentifier
PluginModuleParent::GetValidNPIdentifier(NPRemoteIdentifier aRemoteIdentifier)
{
NS_ASSERTION(mValidIdentifiers.IsInitialized(), "Not initialized!");
if (aRemoteIdentifier &&
mValidIdentifiers.GetEntry((NPIdentifier)aRemoteIdentifier)) {
return (NPIdentifier)aRemoteIdentifier;
}
return 0;
}
NPError
PluginModuleParent::NPP_NewStream(NPP instance, NPMIMEType type,
NPStream* stream, NPBool seekable,
uint16_t* stype)
{
return InstCast(instance)->NPP_NewStream(type, stream, seekable,
stype);
}
NPError
PluginModuleParent::NPP_SetWindow(NPP instance, NPWindow* window)
{
return InstCast(instance)->NPP_SetWindow(window);
}
NPError
PluginModuleParent::NPP_DestroyStream(NPP instance,
NPStream* stream,
NPReason reason)
{
return InstCast(instance)->NPP_DestroyStream(stream, reason);
}
int32_t
PluginModuleParent::NPP_WriteReady(NPP instance,
NPStream* stream)
{
return StreamCast(instance, stream)->WriteReady();
}
int32_t
PluginModuleParent::NPP_Write(NPP instance,
NPStream* stream,
int32_t offset,
int32_t len,
void* buffer)
{
return StreamCast(instance, stream)->Write(offset, len, buffer);
}
void
PluginModuleParent::NPP_StreamAsFile(NPP instance,
NPStream* stream,
const char* fname)
{
StreamCast(instance, stream)->StreamAsFile(fname);
}
void
PluginModuleParent::NPP_Print(NPP instance, NPPrint* platformPrint)
{
InstCast(instance)->NPP_Print(platformPrint);
}
int16_t
PluginModuleParent::NPP_HandleEvent(NPP instance, void* event)
{
return InstCast(instance)->NPP_HandleEvent(event);
}
void
PluginModuleParent::NPP_URLNotify(NPP instance, const char* url,
NPReason reason, void* notifyData)
{
return InstCast(instance)->NPP_URLNotify(url, reason, notifyData);
}
NPError
PluginModuleParent::NPP_GetValue(NPP instance,
NPPVariable variable, void *ret_value)
{
return InstCast(instance)->NPP_GetValue(variable, ret_value);
}
NPError
PluginModuleParent::NPP_SetValue(NPP instance, NPNVariable variable,
void *value)
{
return InstCast(instance)->NPP_SetValue(variable, value);
}
bool
PluginModuleParent::RecvNPN_GetStringIdentifier(const nsCString& aString,
NPRemoteIdentifier* aId)
{
if (aString.IsVoid()) {
NS_ERROR("Someone sent over a void string?!");
return false;
}
NPIdentifier ident = _getstringidentifier(aString.BeginReading());
if (!ident) {
*aId = 0;
return true;
}
if (!EnsureValidNPIdentifier(ident)) {
NS_ERROR("Out of memory?");
return false;
}
*aId = (NPRemoteIdentifier)ident;
return true;
}
bool
PluginModuleParent::RecvNPN_GetIntIdentifier(const int32_t& aInt,
NPRemoteIdentifier* aId)
{
NPIdentifier ident = _getintidentifier(aInt);
if (!ident) {
*aId = 0;
return true;
}
if (!EnsureValidNPIdentifier(ident)) {
NS_ERROR("Out of memory?");
return false;
}
*aId = (NPRemoteIdentifier)ident;
return true;
}
bool
PluginModuleParent::RecvNPN_UTF8FromIdentifier(const NPRemoteIdentifier& aId,
NPError *err,
nsCString* aString)
{
NPIdentifier ident = GetValidNPIdentifier(aId);
if (!ident) {
*err = NPERR_INVALID_PARAM;
return true;
}
NPUTF8* val = _utf8fromidentifier(ident);
if (!val) {
*err = NPERR_INVALID_PARAM;
return true;
}
aString->Assign(val);
*err = NPERR_NO_ERROR;
return true;
}
bool
PluginModuleParent::RecvNPN_IntFromIdentifier(const NPRemoteIdentifier& aId,
NPError* err,
int32_t* aInt)
{
NPIdentifier ident = GetValidNPIdentifier(aId);
if (!ident) {
*err = NPERR_INVALID_PARAM;
return true;
}
*aInt = _intfromidentifier(ident);
*err = NPERR_NO_ERROR;
return true;
}
bool
PluginModuleParent::RecvNPN_IdentifierIsString(const NPRemoteIdentifier& aId,
bool* aIsString)
{
NPIdentifier ident = GetValidNPIdentifier(aId);
if (!ident) {
*aIsString = false;
return true;
}
*aIsString = _identifierisstring(ident);
return true;
}
bool
PluginModuleParent::RecvNPN_GetStringIdentifiers(const nsTArray<nsCString>& aNames,
nsTArray<NPRemoteIdentifier>* aIds)
{
NS_ASSERTION(aIds->IsEmpty(), "Non-empty array!");
PRUint32 count = aNames.Length();
if (!count) {
NS_ERROR("No names to get!");
return false;
}
nsAutoTArray<NPUTF8*, 10> buffers;
nsAutoTArray<NPIdentifier, 10> ids;
if (!(buffers.SetLength(count) &&
ids.SetLength(count) &&
aIds->SetCapacity(count))) {
NS_ERROR("Out of memory?");
return false;
}
for (PRUint32 index = 0; index < count; index++) {
buffers[index] = const_cast<NPUTF8*>(aNames[index].BeginReading());
NS_ASSERTION(buffers[index], "Null pointer should be impossible!");
}
_getstringidentifiers(const_cast<const NPUTF8**>(buffers.Elements()),
count, ids.Elements());
for (PRUint32 index = 0; index < count; index++) {
NPIdentifier& id = ids[index];
if (id) {
if (!EnsureValidNPIdentifier(id)) {
NS_ERROR("Out of memory?");
return false;
}
}
aIds->AppendElement((NPRemoteIdentifier)id);
}
return true;
}
PluginInstanceParent*
PluginModuleParent::InstCast(NPP instance)
{
PluginInstanceParent* ip =
static_cast<PluginInstanceParent*>(instance->pdata);
if (instance != ip->mNPP) {
NS_RUNTIMEABORT("Corrupted plugin data.");
}
return ip;
}
BrowserStreamParent*
PluginModuleParent::StreamCast(NPP instance,
NPStream* s)
{
PluginInstanceParent* ip = InstCast(instance);
BrowserStreamParent* sp =
static_cast<BrowserStreamParent*>(static_cast<AStream*>(s->pdata));
if (sp->mNPP != ip || s != sp->mStream) {
NS_RUNTIMEABORT("Corrupted plugin stream data.");
}
return sp;
}

Просмотреть файл

@ -0,0 +1,362 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Chris Jones <jones.chris.g@gmail.com>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef dom_plugins_PluginModuleParent_h
#define dom_plugins_PluginModuleParent_h 1
#include <cstring>
#include "base/basictypes.h"
#include "prlink.h"
#include "npapi.h"
#include "npfunctions.h"
#include "base/string_util.h"
#include "mozilla/SharedLibrary.h"
#include "mozilla/plugins/PPluginModuleParent.h"
#include "mozilla/plugins/PluginInstanceParent.h"
#include "mozilla/plugins/PluginProcessParent.h"
#include "nsAutoPtr.h"
#include "nsTHashtable.h"
#include "nsHashKeys.h"
#undef _MOZ_LOG
#define _MOZ_LOG(s) printf("[PluginModuleParent] %s\n", s)
namespace mozilla {
namespace plugins {
//-----------------------------------------------------------------------------
/**
* PluginModuleParent
*
* This class implements the NPP API from the perspective of the rest
* of Gecko, forwarding NPP calls along to the child process that is
* actually running the plugin.
*
* This class /also/ implements a version of the NPN API, because the
* child process needs to make these calls back into Gecko proper.
* This class is responsible for "actually" making those function calls.
*/
class PluginModuleParent : public PPluginModuleParent
{
private:
typedef mozilla::SharedLibrary SharedLibrary;
protected:
PPluginInstanceParent*
AllocPPluginInstance(const nsCString& aMimeType,
const uint16_t& aMode,
const nsTArray<nsCString>& aNames,
const nsTArray<nsCString>& aValues,
NPError* rv);
virtual bool
DeallocPPluginInstance(PPluginInstanceParent* aActor,
NPError* _retval);
public:
PluginModuleParent(const char* aFilePath);
virtual ~PluginModuleParent();
/**
* LoadModule
*
* Returns a SharedLibrary from which plugin symbols should be
* resolved. This may or may not launch a plugin child process,
* and may or may not be very expensive.
*/
static SharedLibrary* LoadModule(const char* aFilePath,
PRLibrary* aLibrary);
// NPRemoteIdentifier funcs
virtual bool
RecvNPN_GetStringIdentifier(const nsCString& aString,
NPRemoteIdentifier* aId);
virtual bool
RecvNPN_GetIntIdentifier(const int32_t& aInt,
NPRemoteIdentifier* aId);
virtual bool
RecvNPN_UTF8FromIdentifier(const NPRemoteIdentifier& aId,
NPError* err,
nsCString* aString);
virtual bool
RecvNPN_IntFromIdentifier(const NPRemoteIdentifier& aId,
NPError* err,
int32_t* aInt);
virtual bool
RecvNPN_IdentifierIsString(const NPRemoteIdentifier& aId,
bool* aIsString);
virtual bool
RecvNPN_GetStringIdentifiers(const nsTArray<nsCString>& aNames,
nsTArray<NPRemoteIdentifier>* aIds);
const NPNetscapeFuncs* GetNetscapeFuncs() {
return mNPNIface;
}
static PluginInstanceParent* InstCast(NPP instance);
static BrowserStreamParent* StreamCast(NPP instance, NPStream* s);
bool EnsureValidNPIdentifier(NPIdentifier aIdentifier);
private:
void SetPluginFuncs(NPPluginFuncs* aFuncs);
// Implement the module-level functions from NPAPI; these are
// normally resolved directly from the DSO.
#ifdef OS_LINUX
NPError NP_Initialize(const NPNetscapeFuncs* npnIface,
NPPluginFuncs* nppIface);
#else
NPError NP_Initialize(const NPNetscapeFuncs* npnIface);
NPError NP_GetEntryPoints(NPPluginFuncs* nppIface);
#endif
NPError NP_Shutdown()
{
// FIXME/cjones: shut down all our instances, and kill
// off the child process
_MOZ_LOG(__FUNCTION__);
return 1;
}
char* NP_GetPluginVersion()
{
_MOZ_LOG(__FUNCTION__);
return (char*) "0.0";
}
char* NP_GetMIMEDescription()
{
_MOZ_LOG(__FUNCTION__);
return (char*) "application/x-foobar";
}
NPError NP_GetValue(void *future,
NPPVariable aVariable, void *aValue)
{
_MOZ_LOG(__FUNCTION__);
return 1;
}
// NPP-like API that Gecko calls are trampolined into. These
// messages then get forwarded along to the plugin instance,
// and then eventually the child process.
NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode,
int16_t argc, char* argn[], char* argv[],
NPSavedData* saved);
static NPError NPP_Destroy(NPP instance, NPSavedData** save);
static NPError NPP_SetWindow(NPP instance, NPWindow* window);
static NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
NPBool seekable, uint16_t* stype);
static NPError NPP_DestroyStream(NPP instance,
NPStream* stream, NPReason reason);
static int32_t NPP_WriteReady(NPP instance, NPStream* stream);
static int32_t NPP_Write(NPP instance, NPStream* stream,
int32_t offset, int32_t len, void* buffer);
static void NPP_StreamAsFile(NPP instance,
NPStream* stream, const char* fname);
static void NPP_Print(NPP instance, NPPrint* platformPrint);
static int16_t NPP_HandleEvent(NPP instance, void* event);
static void NPP_URLNotify(NPP instance, const char* url,
NPReason reason, void* notifyData);
static NPError NPP_GetValue(NPP instance,
NPPVariable variable, void *ret_value);
static NPError NPP_SetValue(NPP instance, NPNVariable variable,
void *value);
NPIdentifier GetValidNPIdentifier(NPRemoteIdentifier aRemoteIdentifier);
private:
const char* mFilePath;
PluginProcessParent mSubprocess;
const NPNetscapeFuncs* mNPNIface;
// NPObject interface
/**
* I look like a shared library, but return functions that trampoline
* into my parent class.
*/
/************************************************************************
* HACK!!!
*
* TODO/cjones: I want this class to "look" just like a DSO, so as to
* need to change as few lines of modules/plugin/ as possible. Ideally,
* we would fill the NPPLuginFuncs interface with pointers to
* dynamically-allocated functions that trampoline into member functions
* of this class; this leaves the NPP interface completely unchanged.
* For example:
* NP_GetEntryPoints() {
* return { .newi = new TrampolineFunc(this, ::New); }
* }
* NPPluginFuncs nppIface = pluginShim->NP_GetEntryPoints();
* ...
* nppIface->newp(...); // trampolines to this->New()
*
* But there doesn't seem to be a way to do this in C++ without falling
* back on assembly language. So for now, we limit ourselves to one
* plugin DSO open at a time.
************************************************************************/
class Shim : public SharedLibrary
{
public:
Shim(PluginModuleParent* aTarget) :
mTarget(aTarget)
{
HACK_target = mTarget;
}
virtual ~Shim()
{
mTarget = 0;
}
virtual symbol_type
FindSymbol(const char* aSymbolName)
{
if (!strcmp("NP_Shutdown", aSymbolName))
return (symbol_type) NP_Shutdown;
if (!strcmp("NP_Initialize", aSymbolName))
return (symbol_type) NP_Initialize;
if (!strcmp("NP_GetMIMEDescription", aSymbolName))
return (symbol_type) NP_GetMIMEDescription;
if (!strcmp("NP_GetValue", aSymbolName))
return (symbol_type) NP_GetValue;
#ifdef OS_WIN
if (!strcmp("NP_GetEntryPoints", aSymbolName))
return (symbol_type) NP_GetEntryPoints;
#endif
_MOZ_LOG("WARNING! FAILED TO FIND SYMBOL");
return 0;
}
virtual function_type
FindFunctionSymbol(const char* aSymbolName)
{
if (!strcmp("NP_Shutdown", aSymbolName))
return (function_type) NP_Shutdown;
if (!strcmp("NP_Initialize", aSymbolName))
return (function_type) NP_Initialize;
if (!strcmp("NP_GetMIMEDescription", aSymbolName))
return (function_type) NP_GetMIMEDescription;
if (!strcmp("NP_GetValue", aSymbolName))
return (function_type) NP_GetValue;
#ifdef OS_WINDOWS
if (!strcmp("NP_GetEntryPoints", aSymbolName))
return (function_type) NP_GetEntryPoints;
#endif
_MOZ_LOG("WARNING! FAILED TO FIND SYMBOL");
return 0;
}
private:
PluginModuleParent* mTarget;
// HACKS HACKS HACKS! from here on down
#ifdef OS_LINUX
static NPError NP_Initialize(const NPNetscapeFuncs* npnIface,
NPPluginFuncs* nppIface)
{
return HACK_target->NP_Initialize(npnIface, nppIface);
}
#else
static NPError NP_Initialize(const NPNetscapeFuncs* npnIface)
{
return HACK_target->NP_Initialize(npnIface);
}
static NPError NP_GetEntryPoints(NPPluginFuncs* nppIface)
{
return HACK_target->NP_GetEntryPoints(nppIface);
}
#endif
static NPError NP_Shutdown()
{
return HACK_target->NP_Shutdown();
}
static char* NP_GetPluginVersion()
{
return HACK_target->NP_GetPluginVersion();
}
static char* NP_GetMIMEDescription()
{
return HACK_target->NP_GetMIMEDescription();
}
static NPError NP_GetValue(void *future,
NPPVariable aVariable, void *aValue)
{
return HACK_target->NP_GetValue(future, aVariable, aValue);
}
static NPError NPP_New(NPMIMEType pluginType, NPP instance,
uint16_t mode,
int16_t argc, char* argn[], char* argv[],
NPSavedData* saved)
{
return HACK_target->NPP_New(pluginType, instance, mode,
argc, argn, argv,
saved);
}
static PluginModuleParent* HACK_target;
friend class PluginModuleParent;
};
friend class Shim;
Shim* mShim;
nsTHashtable<nsVoidPtrHashKey> mValidIdentifiers;
};
} // namespace plugins
} // namespace mozilla
#endif // ifndef dom_plugins_PluginModuleParent_h

Просмотреть файл

@ -0,0 +1,71 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Ben Turner <bent.mozilla@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chris Jones <jones.chris.g@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/plugins/PluginProcessParent.h"
#include "base/string_util.h"
using mozilla::ipc::GeckoChildProcessHost;
namespace mozilla {
namespace plugins {
PluginProcessParent::PluginProcessParent(const std::string& aPluginFilePath) :
GeckoChildProcessHost(GeckoProcessType_Plugin),
mPluginFilePath(aPluginFilePath)
{
// XXXbent Need to catch crashing plugins by watching the process event!
}
PluginProcessParent::~PluginProcessParent()
{
}
bool
PluginProcessParent::Launch()
{
std::vector<std::wstring> args;
args.push_back(UTF8ToWide(mPluginFilePath));
return SyncLaunch(args);
}
} // namespace plugins
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,95 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Ben Turner <bent.mozilla@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chris Jones <jones.chris.g@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef dom_plugins_PluginProcessParent_h
#define dom_plugins_PluginProcessParent_h 1
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/scoped_ptr.h"
#include "base/thread.h"
#include "base/waitable_event.h"
#include "chrome/common/child_process_host.h"
#include "mozilla/ipc/GeckoChildProcessHost.h"
#undef _MOZ_LOG
#define _MOZ_LOG(s) printf("[PluginProcessParent] %s\n", s)
namespace mozilla {
namespace plugins {
//-----------------------------------------------------------------------------
class PluginProcessParent : mozilla::ipc::GeckoChildProcessHost
{
public:
PluginProcessParent(const std::string& aPluginFilePath);
~PluginProcessParent();
/**
* Asynchronously launch the plugin process.
*/
bool Launch();
IPC::Channel* GetChannel() {
return channelp();
}
virtual bool CanShutdown()
{
return true;
}
base::WaitableEvent* GetShutDownEvent()
{
return GetProcessEvent();
}
private:
std::string mPluginFilePath;
DISALLOW_EVIL_CONSTRUCTORS(PluginProcessParent);
};
} // namespace plugins
} // namespace mozilla
#endif // ifndef dom_plugins_PluginProcessParent_h

Просмотреть файл

@ -0,0 +1,512 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Ben Turner <bent.mozilla@gmail.com>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "PluginScriptableObjectChild.h"
#include "npapi.h"
#include "npruntime.h"
#include "nsDebug.h"
#include "PluginModuleChild.h"
#include "PluginInstanceChild.h"
using namespace mozilla::plugins;
using mozilla::ipc::NPRemoteVariant;
namespace {
inline NPObject*
NPObjectFromVariant(const NPRemoteVariant& aRemoteVariant) {
NS_ASSERTION(aRemoteVariant.type() ==
NPRemoteVariant::TPPluginScriptableObjectChild,
"Wrong variant type!");
PluginScriptableObjectChild* actor =
const_cast<PluginScriptableObjectChild*>(
reinterpret_cast<const PluginScriptableObjectChild*>(
aRemoteVariant.get_PPluginScriptableObjectChild()));
return actor->GetObject();
}
inline NPObject*
NPObjectFromVariant(const NPVariant& aVariant) {
NS_ASSERTION(NPVARIANT_IS_OBJECT(aVariant), "Wrong variant type!");
return NPVARIANT_TO_OBJECT(aVariant);
}
bool
ConvertToVariant(const NPRemoteVariant& aRemoteVariant,
NPVariant& aVariant)
{
switch (aRemoteVariant.type()) {
case NPRemoteVariant::Tvoid_t: {
VOID_TO_NPVARIANT(aVariant);
break;
}
case NPRemoteVariant::Tnull_t: {
NULL_TO_NPVARIANT(aVariant);
break;
}
case NPRemoteVariant::Tbool: {
BOOLEAN_TO_NPVARIANT(aRemoteVariant.get_bool(), aVariant);
break;
}
case NPRemoteVariant::Tint: {
INT32_TO_NPVARIANT(aRemoteVariant.get_int(), aVariant);
break;
}
case NPRemoteVariant::Tdouble: {
DOUBLE_TO_NPVARIANT(aRemoteVariant.get_double(), aVariant);
break;
}
case NPRemoteVariant::TnsCString: {
const nsCString& string = aRemoteVariant.get_nsCString();
NPUTF8* buffer = reinterpret_cast<NPUTF8*>(strdup(string.get()));
if (!buffer) {
NS_ERROR("Out of memory!");
return false;
}
STRINGN_TO_NPVARIANT(buffer, string.Length(), aVariant);
break;
}
case NPRemoteVariant::TPPluginScriptableObjectChild: {
NPObject* object = NPObjectFromVariant(aRemoteVariant);
if (!object) {
NS_ERROR("Er, this shouldn't fail!");
return false;
}
OBJECT_TO_NPVARIANT(object, aVariant);
break;
}
default:
NS_NOTREACHED("Shouldn't get here!");
return false;
}
return true;
}
bool
ConvertToRemoteVariant(const NPVariant& aVariant,
NPRemoteVariant& aRemoteVariant,
PluginInstanceChild* aInstance)
{
if (NPVARIANT_IS_VOID(aVariant)) {
aRemoteVariant = mozilla::void_t();
}
else if (NPVARIANT_IS_NULL(aVariant)) {
aRemoteVariant = mozilla::null_t();
}
else if (NPVARIANT_IS_BOOLEAN(aVariant)) {
aRemoteVariant = NPVARIANT_TO_BOOLEAN(aVariant);
}
else if (NPVARIANT_IS_INT32(aVariant)) {
aRemoteVariant = NPVARIANT_TO_INT32(aVariant);
}
else if (NPVARIANT_IS_DOUBLE(aVariant)) {
aRemoteVariant = NPVARIANT_TO_DOUBLE(aVariant);
}
else if (NPVARIANT_IS_STRING(aVariant)) {
NPString str = NPVARIANT_TO_STRING(aVariant);
nsCString string(str.UTF8Characters, str.UTF8Length);
aRemoteVariant = string;
}
else if (NPVARIANT_IS_OBJECT(aVariant)) {
NS_ASSERTION(aInstance, "Must have an instance to wrap!");
PluginScriptableObjectChild* actor =
aInstance->GetActorForNPObject(NPVARIANT_TO_OBJECT(aVariant));
if (!actor) {
NS_ERROR("Failed to create actor!");
return false;
}
aRemoteVariant = actor;
}
else {
NS_NOTREACHED("Shouldn't get here!");
return false;
}
return true;
}
} // anonymous namespace
PluginScriptableObjectChild::PluginScriptableObjectChild()
: mInstance(nsnull),
mObject(nsnull)
{
}
PluginScriptableObjectChild::~PluginScriptableObjectChild()
{
if (mObject) {
PluginModuleChild::sBrowserFuncs.releaseobject(mObject);
}
}
void
PluginScriptableObjectChild::Initialize(PluginInstanceChild* aInstance,
NPObject* aObject)
{
NS_ASSERTION(!(mInstance && mObject), "Calling Initialize class twice!");
mInstance = aInstance;
mObject = PluginModuleChild::sBrowserFuncs.retainobject(aObject);
}
bool
PluginScriptableObjectChild::AnswerInvalidate()
{
if (mObject) {
PluginModuleChild::sBrowserFuncs.releaseobject(mObject);
mObject = nsnull;
}
return true;
}
bool
PluginScriptableObjectChild::AnswerHasMethod(const NPRemoteIdentifier& aId,
bool* aHasMethod)
{
if (!mObject) {
NS_WARNING("Calling PluginScriptableObjectChild::AnswerHasMethod with an invalidated object!");
*aHasMethod = false;
return true;
}
if (!(mObject->_class && mObject->_class->hasMethod)) {
*aHasMethod = false;
return true;
}
*aHasMethod = mObject->_class->hasMethod(mObject, (NPIdentifier)aId);
return true;
}
bool
PluginScriptableObjectChild::AnswerInvoke(const NPRemoteIdentifier& aId,
const nsTArray<NPRemoteVariant>& aArgs,
NPRemoteVariant* aResult,
bool* aSuccess)
{
if (!mObject) {
NS_WARNING("Calling PluginScriptableObjectChild::AnswerInvoke with an invalidated object!");
*aSuccess = false;
return true;
}
if (!(mObject->_class && mObject->_class->invoke)) {
*aSuccess = false;
return true;
}
nsAutoTArray<NPVariant, 10> convertedArgs;
PRUint32 argCount = aArgs.Length();
if (!convertedArgs.SetLength(argCount)) {
*aSuccess = false;
return true;
}
for (PRUint32 index = 0; index < argCount; index++) {
if (!ConvertToVariant(aArgs[index], convertedArgs[index])) {
*aSuccess = false;
return true;
}
}
NPVariant result;
bool success = mObject->_class->invoke(mObject, (NPIdentifier)aId,
convertedArgs.Elements(), argCount,
&result);
if (!success) {
*aSuccess = false;
return true;
}
NPRemoteVariant convertedResult;
if (!ConvertToRemoteVariant(result, convertedResult, mInstance)) {
*aSuccess = false;
return true;
}
*aSuccess = true;
*aResult = convertedResult;
return true;
}
bool
PluginScriptableObjectChild::AnswerInvokeDefault(const nsTArray<NPRemoteVariant>& aArgs,
NPRemoteVariant* aResult,
bool* aSuccess)
{
if (!mObject) {
NS_WARNING("Calling PluginScriptableObjectChild::AnswerInvokeDefault with an invalidated object!");
*aSuccess = false;
return true;
}
if (!(mObject->_class && mObject->_class->invokeDefault)) {
*aSuccess = false;
return true;
}
nsAutoTArray<NPVariant, 10> convertedArgs;
PRUint32 argCount = aArgs.Length();
if (!convertedArgs.SetLength(argCount)) {
*aSuccess = false;
return true;
}
for (PRUint32 index = 0; index < argCount; index++) {
if (!ConvertToVariant(aArgs[index], convertedArgs[index])) {
*aSuccess = false;
return true;
}
}
NPVariant result;
bool success = mObject->_class->invokeDefault(mObject,
convertedArgs.Elements(),
argCount, &result);
if (!success) {
*aSuccess = false;
return true;
}
NPRemoteVariant convertedResult;
if (!ConvertToRemoteVariant(result, convertedResult, mInstance)) {
*aSuccess = false;
return true;
}
*aSuccess = true;
*aResult = convertedResult;
return true;
}
bool
PluginScriptableObjectChild::AnswerHasProperty(const NPRemoteIdentifier& aId,
bool* aHasProperty)
{
if (!mObject) {
NS_WARNING("Calling PluginScriptableObjectChild::AnswerHasProperty with an invalidated object!");
*aHasProperty = false;
return true;
}
if (!(mObject->_class && mObject->_class->hasProperty)) {
*aHasProperty = false;
return true;
}
*aHasProperty = mObject->_class->hasProperty(mObject, (NPIdentifier)aId);
return true;
}
bool
PluginScriptableObjectChild::AnswerGetProperty(const NPRemoteIdentifier& aId,
NPRemoteVariant* aResult,
bool* aSuccess)
{
if (!mObject) {
NS_WARNING("Calling PluginScriptableObjectChild::AnswerGetProperty with an invalidated object!");
*aSuccess = false;
return true;
}
if (!(mObject->_class && mObject->_class->getProperty)) {
*aSuccess = false;
return true;
}
NPVariant result;
if (!mObject->_class->getProperty(mObject, (NPIdentifier)aId, &result)) {
*aSuccess = false;
return true;
}
NPRemoteVariant converted;
if ((*aSuccess = ConvertToRemoteVariant(result, converted, mInstance))) {
*aResult = converted;
}
return true;
}
bool
PluginScriptableObjectChild::AnswerSetProperty(const NPRemoteIdentifier& aId,
const NPRemoteVariant& aValue,
bool* aSuccess)
{
if (!mObject) {
NS_WARNING("Calling PluginScriptableObjectChild::AnswerSetProperty with an invalidated object!");
*aSuccess = false;
return true;
}
if (!(mObject->_class && mObject->_class->setProperty)) {
*aSuccess = false;
return true;
}
NPVariant converted;
if (!ConvertToVariant(aValue, converted)) {
*aSuccess = false;
return true;
}
*aSuccess = mObject->_class->setProperty(mObject, (NPIdentifier)aId,
&converted);
return true;
}
bool
PluginScriptableObjectChild::AnswerRemoveProperty(const NPRemoteIdentifier& aId,
bool* aSuccess)
{
if (!mObject) {
NS_WARNING("Calling PluginScriptableObjectChild::AnswerRemoveProperty with an invalidated object!");
*aSuccess = false;
return true;
}
if (!(mObject->_class && mObject->_class->removeProperty)) {
*aSuccess = false;
return true;
}
*aSuccess = mObject->_class->removeProperty(mObject, (NPIdentifier)aId);
return true;
}
bool
PluginScriptableObjectChild::AnswerEnumerate(nsTArray<NPRemoteIdentifier>* aProperties,
bool* aSuccess)
{
if (!mObject) {
NS_WARNING("Calling PluginScriptableObjectChild::AnswerEnumerate with an invalidated object!");
*aSuccess = false;
return true;
}
if (!(mObject->_class && mObject->_class->enumerate)) {
*aSuccess = false;
return true;
}
NPIdentifier* ids;
uint32_t idCount;
if (!mObject->_class->enumerate(mObject, &ids, &idCount)) {
*aSuccess = false;
return true;
}
if (!aProperties->SetCapacity(idCount)) {
PluginModuleChild::sBrowserFuncs.memfree(ids);
*aSuccess = false;
return true;
}
for (uint32_t index = 0; index < idCount; index++) {
#ifdef DEBUG
NPRemoteIdentifier* remoteId =
#endif
aProperties->AppendElement((NPRemoteIdentifier)ids[index]);
NS_ASSERTION(remoteId, "Shouldn't fail if SetCapacity above succeeded!");
}
PluginModuleChild::sBrowserFuncs.memfree(ids);
*aSuccess = true;
return true;
}
bool
PluginScriptableObjectChild::AnswerConstruct(const nsTArray<NPRemoteVariant>& aArgs,
NPRemoteVariant* aResult,
bool* aSuccess)
{
if (!mObject) {
NS_WARNING("Calling PluginScriptableObjectChild::AnswerConstruct with an invalidated object!");
*aSuccess = false;
return true;
}
if (!(mObject->_class && mObject->_class->construct)) {
*aSuccess = false;
return true;
}
nsAutoTArray<NPVariant, 10> convertedArgs;
PRUint32 argCount = aArgs.Length();
if (!convertedArgs.SetLength(argCount)) {
*aSuccess = false;
return true;
}
for (PRUint32 index = 0; index < argCount; index++) {
if (!ConvertToVariant(aArgs[index], convertedArgs[index])) {
*aSuccess = false;
return true;
}
}
NPVariant result;
bool success = mObject->_class->construct(mObject, convertedArgs.Elements(),
argCount, &result);
if (!success) {
*aSuccess = false;
return true;
}
NPRemoteVariant convertedResult;
if (!ConvertToRemoteVariant(result, convertedResult, mInstance)) {
*aSuccess = false;
return true;
}
*aSuccess = true;
*aResult = convertedResult;
return true;
}

Просмотреть файл

@ -0,0 +1,120 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Ben Turner <bent.mozilla@gmail.com>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef dom_plugins_PluginScriptableObjectChild_h
#define dom_plugins_PluginScriptableObjectChild_h 1
#include "mozilla/plugins/PPluginScriptableObjectChild.h"
struct NPObject;
namespace mozilla {
namespace plugins {
class PluginInstanceChild;
class PluginScriptableObjectChild : public PPluginScriptableObjectChild
{
public:
PluginScriptableObjectChild();
virtual ~PluginScriptableObjectChild();
virtual bool
AnswerInvalidate();
virtual bool
AnswerHasMethod(const NPRemoteIdentifier& aId,
bool* aHasMethod);
virtual bool
AnswerInvoke(const NPRemoteIdentifier& aId,
const nsTArray<NPRemoteVariant>& aArgs,
NPRemoteVariant* aResult,
bool* aSuccess);
virtual bool
AnswerInvokeDefault(const nsTArray<NPRemoteVariant>& aArgs,
NPRemoteVariant* aResult,
bool* aSuccess);
virtual bool
AnswerHasProperty(const NPRemoteIdentifier& aId,
bool* aHasProperty);
virtual bool
AnswerGetProperty(const NPRemoteIdentifier& aId,
NPRemoteVariant* aResult,
bool* aSuccess);
virtual bool
AnswerSetProperty(const NPRemoteIdentifier& aId,
const NPRemoteVariant& aValue,
bool* aSuccess);
virtual bool
AnswerRemoveProperty(const NPRemoteIdentifier& aId,
bool* aSuccess);
virtual bool
AnswerEnumerate(nsTArray<NPRemoteIdentifier>* aProperties,
bool* aSuccess);
virtual bool
AnswerConstruct(const nsTArray<NPRemoteVariant>& aArgs,
NPRemoteVariant* aResult,
bool* aSuccess);
void
Initialize(PluginInstanceChild* aInstance,
NPObject* aObject);
NPObject*
GetObject()
{
return mObject;
}
private:
PluginInstanceChild* mInstance;
NPObject* mObject;
};
} /* namespace plugins */
} /* namespace mozilla */
#endif /* dom_plugins_PluginScriptableObjectChild_h */

Просмотреть файл

@ -0,0 +1,745 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Ben Turner <bent.mozilla@gmail.com>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "PluginScriptableObjectParent.h"
#include "PluginInstanceParent.h"
#include "PluginModuleParent.h"
#include "npapi.h"
#include "npfunctions.h"
#include "nsDebug.h"
using namespace mozilla::plugins;
using mozilla::ipc::NPRemoteIdentifier;
using mozilla::ipc::NPRemoteVariant;
namespace {
inline PluginInstanceParent*
GetInstance(NPObject* aObject)
{
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling method on an invalidated object!");
return nsnull;
}
return object->parent->GetInstance();
}
inline const NPNetscapeFuncs*
GetNetscapeFuncs(PluginInstanceParent* aInstance)
{
PluginModuleParent* module = aInstance->GetModule();
if (!module) {
NS_WARNING("Null module?!");
return nsnull;
}
return module->GetNetscapeFuncs();
}
inline const NPNetscapeFuncs*
GetNetscapeFuncs(NPObject* aObject)
{
PluginInstanceParent* instance = GetInstance(aObject);
if (!instance) {
return nsnull;
}
return GetNetscapeFuncs(instance);
}
inline NPObject*
NPObjectFromVariant(const NPRemoteVariant& aRemoteVariant) {
NS_ASSERTION(aRemoteVariant.type() ==
NPRemoteVariant::TPPluginScriptableObjectParent,
"Wrong variant type!");
PluginScriptableObjectParent* actor =
const_cast<PluginScriptableObjectParent*>(
reinterpret_cast<const PluginScriptableObjectParent*>(
aRemoteVariant.get_PPluginScriptableObjectParent()));
return actor->GetObject();
}
inline NPObject*
NPObjectFromVariant(const NPVariant& aVariant) {
NS_ASSERTION(NPVARIANT_IS_OBJECT(aVariant), "Wrong variant type!");
return NPVARIANT_TO_OBJECT(aVariant);
}
inline bool
EnsureValidIdentifier(NPObject* aObject,
NPIdentifier aIdentifier)
{
PluginInstanceParent* instance = GetInstance(aObject);
if (!instance) {
NS_WARNING("Huh?!");
return false;
}
PluginModuleParent* module = instance->GetModule();
if (!module) {
NS_WARNING("Huh?!");
return false;
}
return module->EnsureValidNPIdentifier(aIdentifier);
}
bool
ConvertToVariant(const NPRemoteVariant& aRemoteVariant,
NPVariant& aVariant)
{
switch (aRemoteVariant.type()) {
case NPRemoteVariant::Tvoid_t: {
VOID_TO_NPVARIANT(aVariant);
break;
}
case NPRemoteVariant::Tnull_t: {
NULL_TO_NPVARIANT(aVariant);
break;
}
case NPRemoteVariant::Tbool: {
BOOLEAN_TO_NPVARIANT(aRemoteVariant.get_bool(), aVariant);
break;
}
case NPRemoteVariant::Tint: {
INT32_TO_NPVARIANT(aRemoteVariant.get_int(), aVariant);
break;
}
case NPRemoteVariant::Tdouble: {
DOUBLE_TO_NPVARIANT(aRemoteVariant.get_double(), aVariant);
break;
}
case NPRemoteVariant::TnsCString: {
const nsCString& string = aRemoteVariant.get_nsCString();
NPUTF8* buffer = reinterpret_cast<NPUTF8*>(strdup(string.get()));
if (!buffer) {
NS_ERROR("Out of memory!");
return false;
}
STRINGN_TO_NPVARIANT(buffer, string.Length(), aVariant);
break;
}
case NPRemoteVariant::TPPluginScriptableObjectParent: {
NPObject* object = NPObjectFromVariant(aRemoteVariant);
if (!object) {
NS_ERROR("Er, this shouldn't fail!");
return false;
}
OBJECT_TO_NPVARIANT(object, aVariant);
break;
}
default:
NS_NOTREACHED("Shouldn't get here!");
return false;
}
return true;
}
bool
ConvertToRemoteVariant(const NPVariant& aVariant,
NPRemoteVariant& aRemoteVariant)
{
if (NPVARIANT_IS_VOID(aVariant)) {
aRemoteVariant = mozilla::void_t();
}
else if (NPVARIANT_IS_NULL(aVariant)) {
aRemoteVariant = mozilla::null_t();
}
else if (NPVARIANT_IS_BOOLEAN(aVariant)) {
aRemoteVariant = NPVARIANT_TO_BOOLEAN(aVariant);
}
else if (NPVARIANT_IS_INT32(aVariant)) {
aRemoteVariant = NPVARIANT_TO_INT32(aVariant);
}
else if (NPVARIANT_IS_DOUBLE(aVariant)) {
aRemoteVariant = NPVARIANT_TO_DOUBLE(aVariant);
}
else if (NPVARIANT_IS_STRING(aVariant)) {
NPString str = NPVARIANT_TO_STRING(aVariant);
nsCString string(str.UTF8Characters, str.UTF8Length);
aRemoteVariant = string;
}
else if (NPVARIANT_IS_OBJECT(aVariant)) {
NPObject* object = NPVARIANT_TO_OBJECT(aVariant);
NS_ASSERTION(object->_class == PluginScriptableObjectParent::GetClass(),
"Don't know anything about this object!");
PluginScriptableObjectParent* actor =
static_cast<ParentNPObject*>(object)->parent;
if (!actor) {
NS_ERROR("Failed to create actor!");
return false;
}
aRemoteVariant = actor;
}
else {
NS_NOTREACHED("Shouldn't get here!");
return false;
}
return true;
}
NPObject*
ScriptableAllocate(NPP aInstance,
NPClass* aClass)
{
NS_ASSERTION(aClass == PluginScriptableObjectParent::GetClass(),
"Huh?! Wrong class!");
PluginInstanceParent* instance = PluginModuleParent::InstCast(aInstance);
NS_ASSERTION(instance, "This should never be null!");
const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
if (!npn) {
NS_WARNING("Can't allocate!");
return nsnull;
}
ParentNPObject* object =
reinterpret_cast<ParentNPObject*>(npn->memalloc(sizeof(ParentNPObject)));
if (object) {
memset(object, 0, sizeof(ParentNPObject));
}
return object;
}
void
ScriptableInvalidate(NPObject* aObject)
{
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
NS_WARNING("Don't know what kind of object this is!");
return;
}
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling invalidate more than once!");
return;
}
PluginInstanceParent* instance = GetInstance(aObject);
if (instance) {
if (!instance->CallPPluginScriptableObjectDestructor(object->parent)) {
NS_WARNING("Failed to send message!");
}
}
object->invalidated = true;
}
void
ScriptableDeallocate(NPObject* aObject)
{
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
NS_WARNING("Don't know what kind of object this is!");
return;
}
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
if (!object->invalidated) {
NS_WARNING("Object wasn't previously invalidated!");
ScriptableInvalidate(aObject);
}
NS_ASSERTION(object->invalidated, "Should be invalidated!");
const NPNetscapeFuncs* npn = GetNetscapeFuncs(aObject);
if (npn) {
npn->memfree(aObject);
}
}
bool
ScriptableHasMethod(NPObject* aObject,
NPIdentifier aName)
{
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
NS_WARNING("Don't know what kind of object this is!");
return false;
}
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling method on an invalidated object!");
return false;
}
if (!EnsureValidIdentifier(aObject, aName)) {
return false;
}
PluginScriptableObjectParent* actor = object->parent;
NS_ASSERTION(actor, "This shouldn't ever be null!");
bool result;
if (!actor->CallHasMethod((NPRemoteIdentifier)aName, &result)) {
NS_WARNING("Failed to send message!");
return false;
}
return result;
}
bool
ScriptableInvoke(NPObject* aObject,
NPIdentifier aName,
const NPVariant* aArgs,
uint32_t aArgCount,
NPVariant* aResult)
{
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
NS_WARNING("Don't know what kind of object this is!");
return false;
}
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling method on an invalidated object!");
return false;
}
if (!EnsureValidIdentifier(aObject, aName)) {
return false;
}
PluginScriptableObjectParent* actor = object->parent;
NS_ASSERTION(actor, "This shouldn't ever be null!");
nsAutoTArray<NPRemoteVariant, 10> args;
if (!args.SetLength(aArgCount)) {
NS_ERROR("Out of memory?!");
return false;
}
for (PRUint32 index = 0; index < aArgCount; index++) {
NPRemoteVariant& arg = args[index];
if (!ConvertToRemoteVariant(aArgs[index], arg)) {
NS_WARNING("Failed to convert argument!");
return false;
}
}
NPRemoteVariant remoteResult;
bool success;
if (!actor->CallInvoke((NPRemoteIdentifier)aName, args, &remoteResult,
&success)) {
NS_WARNING("Failed to send message!");
return false;
}
if (!success) {
return false;
}
NPVariant result;
if (!ConvertToVariant(remoteResult, result)) {
NS_WARNING("Failed to convert result!");
return false;
}
*aResult = result;
return true;
}
bool
ScriptableInvokeDefault(NPObject* aObject,
const NPVariant* aArgs,
uint32_t aArgCount,
NPVariant* aResult)
{
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
NS_WARNING("Don't know what kind of object this is!");
return false;
}
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling method on an invalidated object!");
return false;
}
PluginScriptableObjectParent* actor = object->parent;
NS_ASSERTION(actor, "This shouldn't ever be null!");
nsAutoTArray<NPRemoteVariant, 10> args;
if (!args.SetLength(aArgCount)) {
NS_ERROR("Out of memory?!");
return false;
}
for (PRUint32 index = 0; index < aArgCount; index++) {
NPRemoteVariant& arg = args[index];
if (!ConvertToRemoteVariant(aArgs[index], arg)) {
NS_WARNING("Failed to convert argument!");
return false;
}
}
NPRemoteVariant remoteResult;
bool success;
if (!actor->CallInvokeDefault(args, &remoteResult, &success)) {
NS_WARNING("Failed to send message!");
return false;
}
if (!success) {
return false;
}
NPVariant result;
if (!ConvertToVariant(remoteResult, result)) {
NS_WARNING("Failed to convert result!");
return false;
}
*aResult = result;
return true;
}
bool
ScriptableHasProperty(NPObject* aObject,
NPIdentifier aName)
{
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
NS_WARNING("Don't know what kind of object this is!");
return false;
}
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling method on an invalidated object!");
return false;
}
if (!EnsureValidIdentifier(aObject, aName)) {
return false;
}
PluginScriptableObjectParent* actor = object->parent;
NS_ASSERTION(actor, "This shouldn't ever be null!");
bool result;
if (!actor->CallHasProperty((NPRemoteIdentifier)aName, &result)) {
NS_WARNING("Failed to send message!");
return false;
}
return result;
}
bool
ScriptableGetProperty(NPObject* aObject,
NPIdentifier aName,
NPVariant* aResult)
{
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
NS_WARNING("Don't know what kind of object this is!");
return false;
}
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling method on an invalidated object!");
return false;
}
if (!EnsureValidIdentifier(aObject, aName)) {
return false;
}
PluginScriptableObjectParent* actor = object->parent;
NS_ASSERTION(actor, "This shouldn't ever be null!");
NPRemoteVariant result;
bool success;
if (!actor->CallGetProperty((NPRemoteIdentifier)aName, &result, &success)) {
NS_WARNING("Failed to send message!");
return false;
}
if (!success) {
return false;
}
if (!ConvertToVariant(result, *aResult)) {
NS_WARNING("Failed to convert result!");
return false;
}
return true;
}
bool
ScriptableSetProperty(NPObject* aObject,
NPIdentifier aName,
const NPVariant* aValue)
{
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
NS_WARNING("Don't know what kind of object this is!");
return false;
}
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling method on an invalidated object!");
return false;
}
if (!EnsureValidIdentifier(aObject, aName)) {
return false;
}
PluginScriptableObjectParent* actor = object->parent;
NS_ASSERTION(actor, "This shouldn't ever be null!");
NPRemoteVariant value;
if (!ConvertToRemoteVariant(*aValue, value)) {
NS_WARNING("Failed to convert variant!");
return false;
}
bool success;
if (!actor->CallSetProperty((NPRemoteIdentifier)aName, value, &success)) {
NS_WARNING("Failed to send message!");
return false;
}
return success;
}
bool
ScriptableRemoveProperty(NPObject* aObject,
NPIdentifier aName)
{
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
NS_WARNING("Don't know what kind of object this is!");
return false;
}
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling method on an invalidated object!");
return false;
}
if (!EnsureValidIdentifier(aObject, aName)) {
return false;
}
PluginScriptableObjectParent* actor = object->parent;
NS_ASSERTION(actor, "This shouldn't ever be null!");
bool success;
if (!actor->CallRemoveProperty((NPRemoteIdentifier)aName, &success)) {
NS_WARNING("Failed to send message!");
return false;
}
return success;
}
bool
ScriptableEnumerate(NPObject* aObject,
NPIdentifier** aIdentifiers,
uint32_t* aCount)
{
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
NS_WARNING("Don't know what kind of object this is!");
return false;
}
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling method on an invalidated object!");
return false;
}
PluginScriptableObjectParent* actor = object->parent;
NS_ASSERTION(actor, "This shouldn't ever be null!");
const NPNetscapeFuncs* npn = GetNetscapeFuncs(aObject);
if (!npn) {
NS_ERROR("No netscape funcs!");
return false;
}
nsAutoTArray<NPRemoteIdentifier, 10> identifiers;
bool success;
if (!actor->CallEnumerate(&identifiers, &success)) {
NS_WARNING("Failed to send message!");
return false;
}
if (!success) {
return false;
}
*aCount = identifiers.Length();
if (!*aCount) {
*aIdentifiers = nsnull;
return true;
}
*aIdentifiers = (NPIdentifier*)npn->memalloc(*aCount * sizeof(NPIdentifier));
if (!*aIdentifiers) {
NS_ERROR("Out of memory!");
return false;
}
for (PRUint32 index = 0; index < *aCount; index++) {
NPIdentifier& id = *aIdentifiers[index];
id = (NPIdentifier)identifiers[index];
if (!EnsureValidIdentifier(aObject, id)) {
return false;
}
}
return true;
}
bool
ScriptableConstruct(NPObject* aObject,
const NPVariant* aArgs,
uint32_t aArgCount,
NPVariant* aResult)
{
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
NS_WARNING("Don't know what kind of object this is!");
return false;
}
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling method on an invalidated object!");
return false;
}
PluginScriptableObjectParent* actor = object->parent;
NS_ASSERTION(actor, "This shouldn't ever be null!");
nsAutoTArray<NPRemoteVariant, 10> args;
if (!args.SetLength(aArgCount)) {
NS_ERROR("Out of memory?!");
return false;
}
for (PRUint32 index = 0; index < aArgCount; index++) {
NPRemoteVariant& arg = args[index];
if (!ConvertToRemoteVariant(aArgs[index], arg)) {
NS_WARNING("Failed to convert argument!");
return false;
}
}
NPRemoteVariant remoteResult;
bool success;
if (!actor->CallConstruct(args, &remoteResult, &success)) {
NS_WARNING("Failed to send message!");
return false;
}
if (!success) {
return false;
}
NPVariant result;
if (!ConvertToVariant(remoteResult, result)) {
NS_WARNING("Failed to convert result!");
return false;
}
*aResult = result;
return true;
}
} // anonymous namespace
NPClass PluginScriptableObjectParent::sNPClass = {
NP_CLASS_STRUCT_VERSION,
ScriptableAllocate,
ScriptableDeallocate,
ScriptableInvalidate,
ScriptableHasMethod,
ScriptableInvoke,
ScriptableInvokeDefault,
ScriptableHasProperty,
ScriptableGetProperty,
ScriptableSetProperty,
ScriptableRemoveProperty,
ScriptableEnumerate,
ScriptableConstruct
};
PluginScriptableObjectParent::PluginScriptableObjectParent()
: mInstance(nsnull),
mObject(nsnull)
{
}
PluginScriptableObjectParent::~PluginScriptableObjectParent()
{
if (mObject && !mObject->invalidated) {
ScriptableInvalidate(mObject);
}
}
void
PluginScriptableObjectParent::Initialize(PluginInstanceParent* aInstance,
ParentNPObject* aObject)
{
NS_ASSERTION(aInstance && aObject, "Null pointers!");
NS_ASSERTION(!(mInstance && mObject), "Calling Initialize more than once!");
NS_ASSERTION(aObject->_class == &sNPClass && !aObject->parent, "Bad object!");
mInstance = aInstance;
mObject = aObject;
mObject->parent = const_cast<PluginScriptableObjectParent*>(this);
// XXX UGLY HACK, we let NPP_GetValue mess with the refcount, start at 0 here
mObject->referenceCount = 0;
}

Просмотреть файл

@ -0,0 +1,96 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Ben Turner <bent.mozilla@gmail.com>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef dom_plugins_PluginScriptableObjectParent_h
#define dom_plugins_PluginScriptableObjectParent_h 1
#include "mozilla/plugins/PPluginScriptableObjectParent.h"
#include "npruntime.h"
namespace mozilla {
namespace plugins {
class PluginInstanceParent;
class PluginScriptableObjectParent;
struct ParentNPObject : NPObject
{
PluginScriptableObjectParent* parent;
bool invalidated;
};
class PluginScriptableObjectParent : public PPluginScriptableObjectParent
{
public:
PluginScriptableObjectParent();
virtual ~PluginScriptableObjectParent();
void
Initialize(PluginInstanceParent* aInstance,
ParentNPObject* aObject);
static NPClass*
GetClass()
{
return &sNPClass;
}
PluginInstanceParent*
GetInstance()
{
return mInstance;
}
NPObject*
GetObject()
{
return mObject;
}
private:
PluginInstanceParent* mInstance;
ParentNPObject* mObject;
static NPClass sNPClass;
};
} /* namespace plugins */
} /* namespace mozilla */
#endif /* dom_plugins_PluginScriptableObjectParent_h */

Просмотреть файл

@ -0,0 +1,74 @@
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugins.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation <http://www.mozilla.org/>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "PluginStreamChild.h"
#include "mozilla/plugins/PluginInstanceChild.h"
namespace mozilla {
namespace plugins {
PluginStreamChild::PluginStreamChild(PluginInstanceChild* instance)
: mInstance(instance)
{
memset(&mStream, 0, sizeof(mStream));
mStream.ndata = static_cast<AStream*>(this);
}
int32_t
PluginStreamChild::NPN_Write(int32_t length, void* buffer)
{
int32_t written = 0;
CallNPN_Write(nsCString(static_cast<char*>(buffer), length),
&written);
if (written < 0)
mInstance->CallPPluginStreamDestructor(this, NPERR_GENERIC_ERROR, true);
return written;
}
void
PluginStreamChild::NPP_DestroyStream(NPError reason)
{
if (mClosed)
return;
mClosed = true;
mInstance->mPluginIface->destroystream(&mInstance->mData, &mStream, reason);
}
} // namespace plugins
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,83 @@
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugins.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation <http://www.mozilla.org/>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef mozilla_plugins_PluginStreamChild_h
#define mozilla_plugins_PluginStreamChild_h
#include "mozilla/plugins/PPluginStreamChild.h"
#include "mozilla/plugins/AStream.h"
namespace mozilla {
namespace plugins {
class PluginInstanceChild;
class PluginStreamChild : public PPluginStreamChild, public AStream
{
friend class PluginInstanceChild;
public:
PluginStreamChild(PluginInstanceChild* instance);
virtual ~PluginStreamChild() { }
NS_OVERRIDE virtual bool IsBrowserStream() { return false; }
int32_t NPN_Write(int32_t length, void* buffer);
void NPP_DestroyStream(NPError reason);
void EnsureCorrectInstance(PluginInstanceChild* i)
{
if (i != mInstance)
NS_RUNTIMEABORT("Incorrect stream instance");
}
void EnsureCorrectStream(NPStream* s)
{
if (s != &mStream)
NS_RUNTIMEABORT("Incorrect stream data");
}
private:
PluginInstanceChild* mInstance;
NPStream mStream;
bool mClosed;
};
} // namespace plugins
} // namespace mozilla
#endif

Просмотреть файл

@ -0,0 +1,89 @@
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugins.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation <http://www.mozilla.org/>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "PluginStreamParent.h"
#include "PluginInstanceParent.h"
namespace mozilla {
namespace plugins {
PluginStreamParent::PluginStreamParent(PluginInstanceParent* npp,
const nsCString& mimeType,
const nsCString& target,
NPError* result)
: mInstance(npp)
, mClosed(false)
{
*result = mInstance->mNPNIface->newstream(mInstance->mNPP,
const_cast<char*>(mimeType.get()),
NullableStringGet(target),
&mStream);
if (*result == NPERR_NO_ERROR)
mStream->pdata = static_cast<AStream*>(this);
else
mStream = NULL;
}
bool
PluginStreamParent::AnswerNPN_Write(const Buffer& data, int32_t* written)
{
if (mClosed) {
*written = -1;
return true;
}
*written = mInstance->mNPNIface->write(mInstance->mNPP, mStream,
data.Length(),
const_cast<char*>(data.get()));
if (*written < 0)
mClosed = true;
return true;
}
void
PluginStreamParent::NPN_DestroyStream(NPReason reason)
{
if (mClosed)
return;
mInstance->mNPNIface->destroystream(mInstance->mNPP, mStream, reason);
mClosed = true;
}
} // namespace plugins
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,74 @@
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugins.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation <http://www.mozilla.org/>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef mozilla_plugins_PluginStreamParent_h
#define mozilla_plugins_PluginStreamParent_h
#include "mozilla/plugins/PPluginStreamParent.h"
#include "mozilla/plugins/AStream.h"
namespace mozilla {
namespace plugins {
class PluginInstanceParent;
class PluginStreamParent : public PPluginStreamParent, public AStream
{
friend class PluginModuleParent;
friend class PluginInstanceParent;
public:
PluginStreamParent(PluginInstanceParent* npp, const nsCString& mimeType,
const nsCString& target, NPError* result);
virtual ~PluginStreamParent() { }
NS_OVERRIDE virtual bool IsBrowserStream() { return false; }
virtual bool AnswerNPN_Write(const Buffer& data, int32_t* written);
void NPN_DestroyStream(NPReason reason);
private:
PluginInstanceParent* mInstance;
NPStream* mStream;
bool mClosed;
};
} // namespace plugins
} // namespace mozilla
#endif

Просмотреть файл

@ -0,0 +1,91 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Ben Turner <bent.mozilla@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chris Jones <jones.chris.g@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/plugins/PluginThreadChild.h"
#include "prlink.h"
#include "base/command_line.h"
#include "base/string_util.h"
#include "chrome/common/child_process.h"
#include "chrome/common/chrome_switches.h"
using mozilla::ipc::GeckoThread;
namespace mozilla {
namespace plugins {
PluginThreadChild::PluginThreadChild() :
GeckoThread(),
mPlugin()
{
}
PluginThreadChild::~PluginThreadChild()
{
}
void
PluginThreadChild::Init()
{
GeckoThread::Init();
// FIXME/cjones: set up channel stuff, etc.
std::vector<std::wstring> values =
CommandLine::ForCurrentProcess()->GetLooseValues();
// XXX need to handle plugin args!
DCHECK(values.size() >= 1);
std::string pluginFilename = WideToUTF8(values[0]);
// FIXME owner_loop() is bad here
mPlugin.Init(pluginFilename, owner_loop(), channel());
}
void
PluginThreadChild::CleanUp()
{
mPlugin.CleanUp();
GeckoThread::CleanUp();
}
} // namespace plugins
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,83 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Ben Turner <bent.mozilla@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chris Jones <jones.chris.g@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef dom_plugins_PluginThreadChild_h
#define dom_plugins_PluginThreadChild_h 1
#include "base/basictypes.h"
#include "chrome/common/child_thread.h"
#include "base/file_path.h"
#include "mozilla/ipc/GeckoThread.h"
#include "mozilla/plugins/PluginModuleChild.h"
#undef _MOZ_LOG
#define _MOZ_LOG(s) printf("[PluginThreadChild] %s", s)
namespace mozilla {
namespace plugins {
//-----------------------------------------------------------------------------
// The PluginThreadChild class represents a background thread where plugin instances
// live.
class PluginThreadChild : public mozilla::ipc::GeckoThread {
public:
PluginThreadChild();
~PluginThreadChild();
private:
// Thread implementation:
virtual void Init();
virtual void CleanUp();
// FIXME/cjones: this is kinda broken; this thread is generic,
// not NPAPI-specific, but there's not really another good
// place to store this reference. and there's no need to make
// a generic |Plugin| class yet
PluginModuleChild mPlugin;
IPC::Channel* mChannel;
DISALLOW_EVIL_CONSTRUCTORS(PluginThreadChild);
};
} // namespace plugins
} // namespace mozilla
#endif // ifndef dom_plugins_PluginThreadChild_h

Просмотреть файл

@ -0,0 +1,62 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Chris Jones <jones.chris.g@gmail.com>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef SharedLibrary_h
#define SharedLibrary_h 1
namespace mozilla {
class SharedLibrary
{
public:
typedef void* symbol_type;
typedef void (*function_type)();
virtual ~SharedLibrary() { }
// purposely copying the PRLibrary interface
virtual symbol_type FindSymbol(const char* aSymbolName) = 0;
virtual function_type FindFunctionSymbol(const char* aSymbolName) = 0;
};
} // namespace mozilla
#endif // ifndef SharedLibrary_h

Просмотреть файл

@ -0,0 +1,83 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Chris Jones <jones.chris.g@gmail.com>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef SharedPRLibrary_h
#define SharedPRLibrary_h 1
#include "prlink.h"
#include "mozilla/SharedLibrary.h"
namespace mozilla {
class SharedPRLibrary : public SharedLibrary
{
public:
SharedPRLibrary(const char* aFilePath, PRLibrary* aLibrary) :
mLibrary(aLibrary)
{
NS_ASSERTION(mLibrary, "need non-null lib");
// addref here??
}
virtual ~SharedPRLibrary()
{
// unref here??
}
virtual symbol_type
FindSymbol(const char* aSymbolName)
{
return PR_FindSymbol(mLibrary, aSymbolName);
}
virtual function_type
FindFunctionSymbol(const char* aSymbolName)
{
return PR_FindFunctionSymbol(mLibrary, aSymbolName);
}
private:
PRLibrary* mLibrary;
};
} // namespace mozilla
#endif // ifndef SharedPRLibrary_h

Просмотреть файл

@ -0,0 +1,65 @@
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
/* vim: set sw=2 ts=2 et : */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Chris Jones <jones.chris.g@gmail.com>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef mozilla_plugins_StreamNotifyChild_h
#define mozilla_plugins_StreamNotifyChild_h
#include "mozilla/plugins/PStreamNotifyChild.h"
namespace mozilla {
namespace plugins {
class StreamNotifyChild : public PStreamNotifyChild
{
friend class PluginInstanceChild;
public:
StreamNotifyChild(const nsCString& aURL, void* aClosure)
: mURL(aURL)
, mClosure(aClosure)
{ }
private:
nsCString mURL;
void* mClosure;
};
} // namespace plugins
} // namespace mozilla
#endif

Просмотреть файл

@ -0,0 +1,57 @@
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
/* vim: set sw=2 ts=2 et : */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Chris Jones <jones.chris.g@gmail.com>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef mozilla_plugins_StreamNotifyParent_h
#define mozilla_plugins_StreamNotifyParent_h
#include "mozilla/plugins/PStreamNotifyParent.h"
namespace mozilla {
namespace plugins {
class StreamNotifyParent : public PStreamNotifyParent
{
friend class PluginInstanceParent;
StreamNotifyParent() { }
};
} // namespace plugins
} // namespace mozilla
#endif

44
dom/plugins/ipdl.mk Normal file
Просмотреть файл

@ -0,0 +1,44 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Plugins.
#
# The Initial Developer of the Original Code is
# Benjamin Smedberg<benjamin@smedbergs.us>.
# Portions created by the Initial Developer are Copyright (C) 2009
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
IPDLSRCS = \
PPluginModule.ipdl \
PPluginInstance.ipdl \
PPluginScriptableObject.ipdl \
PBrowserStream.ipdl \
PPluginStream.ipdl \
PStreamNotify.ipdl \
$(NULL)

Просмотреть файл

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>libnpipctest.dylib</string>
<key>CFBundleIdentifier</key>
<string>org.mozilla.TestIPCPlugin</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BRPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0.0</string>
<key>CFBundleSignature</key>
<string>TEST</string>
<key>CFBundleVersion</key>
<string>1.0.0.0</string>
<key>WebPluginName</key>
<string>Test Plug-in for IPC</string>
<key>WebPluginDescription</key>
<string>Plug-in for IPC testing purposes.</string>
<key>WebPluginMIMETypes</key>
<dict>
<key>application/x-test-ipc</key>
<dict>
<key>WebPluginExtensions</key>
<array>
<string>tstipc</string>
</array>
<key>WebPluginTypeDescription</key>
<string>Test IPC mimetype</string>
</dict>
</dict>
</dict>
</plist>

Просмотреть файл

@ -0,0 +1,99 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is mozilla.org
# Portions created by the Initial Developer are Copyright (C) 2008
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Dave Townsend <dtownsend@oxymoronical.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = npipctest
LIBRARY_NAME = npipctest
MODULE_NAME = TestIPCPlugin
# Need to custom install plugins
NO_DIST_INSTALL = 1
NO_INSTALL = 1
CPPSRCS = \
npipctest.cpp \
npipctest_utils.cpp \
$(NULL)
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
CMMSRCS = npipctest_macosx.mm
endif
ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
CPPSRCS += npipctest_gtk2.cpp
endif
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
CPPSRCS += npipctest_os2.cpp
endif
ifeq ($(MOZ_WIDGET_TOOLKIT),qt)
CPPSRCS += npipctest_qt.cpp
endif
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
CPPSRCS += npipctest_windows.cpp
RCFILE = npipctest.rc
RESFILE = npipctest.res
DEFFILE = $(win_srcdir)/npipctest.def
endif
include $(topsrcdir)/config/rules.mk
ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
CXXFLAGS += $(MOZ_GTK2_CFLAGS)
CFLAGS += $(MOZ_GTK2_CFLAGS)
EXTRA_DSO_LDOPTS += $(MOZ_GTK2_LIBS) $(XLDFLAGS) $(XLIBS) $(XEXT_LIBS)
endif
install-plugin: $(SHARED_LIBRARY)
ifdef SHARED_LIBRARY
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
$(INSTALL) $(srcdir)/Info.plist $(DIST)/bin/plugins/Test.plugin/Contents
$(INSTALL) $(SHARED_LIBRARY) $(DIST)/bin/plugins/Test.plugin/Contents/MacOS
else
$(INSTALL) $(SHARED_LIBRARY) $(DIST)/bin/plugins
endif
endif
libs:: install-plugin

Просмотреть файл

@ -0,0 +1,571 @@
/* ***** BEGIN LICENSE BLOCK *****
*
* Copyright (c) 2008, Mozilla Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * 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.
* * Neither the name of the Mozilla Corporation 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT OWNER 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.
*
* Contributor(s):
* Dave Townsend <dtownsend@oxymoronical.com>
* Josh Aas <josh@mozilla.com>
*
* ***** END LICENSE BLOCK ***** */
#include "npipctest.h"
#include "npipctest_utils.h"
#include "npipctest_platform.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define PLUGIN_NAME "Test IPC Plug-in"
#define PLUGIN_DESCRIPTION "Plug-in for IPC testing purposes."
#define PLUGIN_VERSION "1.0.0.0"
//
// static data
//
static NPNetscapeFuncs* sBrowserFuncs = NULL;
static NPClass sNPClass;
//
// function signatures
//
NPObject* scriptableAllocate(NPP npp, NPClass* aClass);
void scriptableDeallocate(NPObject* npobj);
void scriptableInvalidate(NPObject* npobj);
bool scriptableHasMethod(NPObject* npobj, NPIdentifier name);
bool scriptableInvoke(NPObject* npobj, NPIdentifier name, const NPVariant* args, uint32_t argCount, NPVariant* result);
bool scriptableInvokeDefault(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
bool scriptableHasProperty(NPObject* npobj, NPIdentifier name);
bool scriptableGetProperty(NPObject* npobj, NPIdentifier name, NPVariant* result);
bool scriptableSetProperty(NPObject* npobj, NPIdentifier name, const NPVariant* value);
bool scriptableRemoveProperty(NPObject* npobj, NPIdentifier name);
bool scriptableEnumerate(NPObject* npobj, NPIdentifier** identifier, uint32_t* count);
bool scriptableConstruct(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
//
// npapi plugin functions
//
#ifdef XP_UNIX
NP_EXPORT(char*)
NP_GetPluginVersion()
{
return PLUGIN_VERSION;
}
#endif
#if defined(XP_UNIX)
NP_EXPORT(char*) NP_GetMIMEDescription()
#elif defined(XP_WIN) || defined(XP_OS2)
char* NP_GetMIMEDescription()
#endif
{
return "application/x-test-ipc:tstipc:Test IPC mimetype";
}
#ifdef XP_UNIX
NP_EXPORT(NPError)
NP_GetValue(void* future, NPPVariable aVariable, void* aValue) {
switch (aVariable) {
case NPPVpluginNameString:
*((char**)aValue) = PLUGIN_NAME;
break;
case NPPVpluginDescriptionString:
*((char**)aValue) = PLUGIN_DESCRIPTION;
break;
default:
return NPERR_INVALID_PARAM;
break;
}
return NPERR_NO_ERROR;
}
#endif
static void fillPluginFunctionTable(NPPluginFuncs* pFuncs)
{
pFuncs->version = 11;
pFuncs->size = sizeof(*pFuncs);
pFuncs->newp = NPP_New;
pFuncs->destroy = NPP_Destroy;
pFuncs->setwindow = NPP_SetWindow;
pFuncs->newstream = NPP_NewStream;
pFuncs->destroystream = NPP_DestroyStream;
pFuncs->asfile = NPP_StreamAsFile;
pFuncs->writeready = NPP_WriteReady;
pFuncs->write = NPP_Write;
pFuncs->print = NPP_Print;
pFuncs->event = NPP_HandleEvent;
pFuncs->urlnotify = NPP_URLNotify;
pFuncs->getvalue = NPP_GetValue;
pFuncs->setvalue = NPP_SetValue;
}
#if defined(XP_MACOSX)
NP_EXPORT(NPError) NP_Initialize(NPNetscapeFuncs* bFuncs)
#elif defined(XP_WIN) || defined(XP_OS2)
NPError OSCALL NP_Initialize(NPNetscapeFuncs* bFuncs)
#elif defined(XP_UNIX)
NP_EXPORT(NPError) NP_Initialize(NPNetscapeFuncs* bFuncs, NPPluginFuncs* pFuncs)
#endif
{
sBrowserFuncs = bFuncs;
memset(&sNPClass, 0, sizeof(NPClass));
sNPClass.structVersion = NP_CLASS_STRUCT_VERSION;
sNPClass.allocate = (NPAllocateFunctionPtr)scriptableAllocate;
sNPClass.deallocate = (NPDeallocateFunctionPtr)scriptableDeallocate;
sNPClass.invalidate = (NPInvalidateFunctionPtr)scriptableInvalidate;
sNPClass.hasMethod = (NPHasMethodFunctionPtr)scriptableHasMethod;
sNPClass.invoke = (NPInvokeFunctionPtr)scriptableInvoke;
sNPClass.invokeDefault = (NPInvokeDefaultFunctionPtr)scriptableInvokeDefault;
sNPClass.hasProperty = (NPHasPropertyFunctionPtr)scriptableHasProperty;
sNPClass.getProperty = (NPGetPropertyFunctionPtr)scriptableGetProperty;
sNPClass.setProperty = (NPSetPropertyFunctionPtr)scriptableSetProperty;
sNPClass.removeProperty = (NPRemovePropertyFunctionPtr)scriptableRemoveProperty;
sNPClass.enumerate = (NPEnumerationFunctionPtr)scriptableEnumerate;
sNPClass.construct = (NPConstructFunctionPtr)scriptableConstruct;
#if defined(XP_UNIX) && !defined(XP_MACOSX)
fillPluginFunctionTable(pFuncs);
#endif
return NPERR_NO_ERROR;
}
#if defined(XP_MACOSX)
NP_EXPORT(NPError) NP_GetEntryPoints(NPPluginFuncs* pFuncs)
#elif defined(XP_WIN) || defined(XP_OS2)
NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* pFuncs)
#endif
#if defined(XP_MACOSX) || defined(XP_WIN) || defined(XP_OS2)
{
fillPluginFunctionTable(pFuncs);
return NPERR_NO_ERROR;
}
#endif
#if defined(XP_UNIX)
NP_EXPORT(NPError) NP_Shutdown()
#elif defined(XP_WIN) || defined(XP_OS2)
NPError OSCALL NP_Shutdown()
#endif
{
return NPERR_NO_ERROR;
}
NPError
NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData* saved)
{
const char kFoo[] = "foo";
NPIdentifier ident = NPN_GetStringIdentifier(kFoo);
if (!ident) {
return NPERR_GENERIC_ERROR;
}
NPUTF8* buf = NPN_UTF8FromIdentifier(ident);
if (!(buf && !strcmp(buf, kFoo))) {
return NPERR_GENERIC_ERROR;
}
free(buf);
bool isString = NPN_IdentifierIsString(ident);
if (!isString) {
return NPERR_GENERIC_ERROR;
}
const NPUTF8* names[] = { kFoo, "bar", "baz" };
const int32_t count = sizeof(names) / sizeof(names[0]);
NPIdentifier identifiers[count] = { 0 };
NPN_GetStringIdentifiers(names, count, identifiers);
for (int32_t index = 0; index < count; index++) {
if (!identifiers[index]) {
return NPERR_GENERIC_ERROR;
}
}
if (identifiers[0] != ident) {
return NPERR_GENERIC_ERROR;
}
buf = NPN_UTF8FromIdentifier((NPIdentifier)0x7774392);
if (buf) {
return NPERR_GENERIC_ERROR;
}
// Make sure we can render this plugin
NPBool browserSupportsWindowless = false;
NPN_GetValue(instance, NPNVSupportsWindowless, &browserSupportsWindowless);
if (!browserSupportsWindowless && !pluginSupportsWindowMode()) {
printf("Windowless mode not supported by the browser, windowed mode not supported by the plugin!\n");
return NPERR_GENERIC_ERROR;
}
// set up our our instance data
InstanceData* instanceData = (InstanceData*)malloc(sizeof(InstanceData));
if (!instanceData)
return NPERR_OUT_OF_MEMORY_ERROR;
memset(instanceData, 0, sizeof(InstanceData));
instanceData->npp = instance;
instance->pdata = instanceData;
TestNPObject* scriptableObject = (TestNPObject*)NPN_CreateObject(instance, &sNPClass);
if (!scriptableObject) {
printf("NPN_CreateObject failed to create an object, can't create a plugin instance\n");
free(instanceData);
return NPERR_GENERIC_ERROR;
}
scriptableObject->npp = instance;
scriptableObject->drawMode = DM_DEFAULT;
scriptableObject->drawColor = 0;
bool requestWindow = true;
if (!browserSupportsWindowless || !pluginSupportsWindowlessMode()) {
requestWindow = true;
} else if (!pluginSupportsWindowMode()) {
requestWindow = false;
}
if (requestWindow) {
instanceData->hasWidget = true;
} else {
// NPPVpluginWindowBool should default to true, so we may as well
// test that by not setting it in the window case
NPN_SetValue(instance, NPPVpluginWindowBool, (void*)false);
}
instanceData->lastReportedPrivateModeState = false;
// do platform-specific initialization
NPError err = pluginInstanceInit(instanceData);
if (err != NPERR_NO_ERROR) {
free(instanceData);
return err;
}
return NPERR_NO_ERROR;
}
NPError
NPP_Destroy(NPP instance, NPSavedData** save)
{
InstanceData* instanceData = (InstanceData*)(instance->pdata);
pluginInstanceShutdown(instanceData);
free(instanceData);
return NPERR_NO_ERROR;
}
NPError
NPP_SetWindow(NPP instance, NPWindow* window)
{
InstanceData* instanceData = (InstanceData*)(instance->pdata);
void* oldWindow = instanceData->window.window;
pluginDoSetWindow(instanceData, window);
if (instanceData->hasWidget && oldWindow != instanceData->window.window) {
pluginWidgetInit(instanceData, oldWindow);
}
return NPERR_NO_ERROR;
}
NPError
NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype)
{
*stype = NP_ASFILEONLY;
return NPERR_NO_ERROR;
}
NPError
NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason)
{
return NPERR_NO_ERROR;
}
int32_t
NPP_WriteReady(NPP instance, NPStream* stream)
{
return 0;
}
int32_t
NPP_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len, void* buffer)
{
return 0;
}
void
NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
{
}
void
NPP_Print(NPP instance, NPPrint* platformPrint)
{
}
int16_t
NPP_HandleEvent(NPP instance, void* event)
{
InstanceData* instanceData = (InstanceData*)(instance->pdata);
return pluginHandleEvent(instanceData, event);
}
void
NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
{
}
NPError
NPP_GetValue(NPP instance, NPPVariable variable, void* value)
{
InstanceData* instanceData = (InstanceData*)instance->pdata;
if (variable == NPPVpluginNeedsXEmbed) {
// Only relevant for X plugins
*(NPBool*)value = instanceData->hasWidget;
return NPERR_NO_ERROR;
}
return NPERR_GENERIC_ERROR;
}
NPError
NPP_SetValue(NPP instance, NPNVariable variable, void* value)
{
if (variable == NPNVprivateModeBool) {
InstanceData* instanceData = (InstanceData*)(instance->pdata);
instanceData->lastReportedPrivateModeState = bool(*static_cast<NPBool*>(value));
return NPERR_NO_ERROR;
}
return NPERR_GENERIC_ERROR;
}
//
// npapi browser functions
//
bool
NPN_SetProperty(NPP instance, NPObject* obj, NPIdentifier propertyName, const NPVariant* value)
{
return sBrowserFuncs->setproperty(instance, obj, propertyName, value);
}
NPIdentifier
NPN_GetIntIdentifier(int32_t intid)
{
return sBrowserFuncs->getintidentifier(intid);
}
NPIdentifier
NPN_GetStringIdentifier(const NPUTF8* name)
{
return sBrowserFuncs->getstringidentifier(name);
}
void
NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers)
{
return sBrowserFuncs->getstringidentifiers(names, nameCount, identifiers);
}
NPUTF8*
NPN_UTF8FromIdentifier(NPIdentifier identifier)
{
return sBrowserFuncs->utf8fromidentifier(identifier);
}
int32_t
NPN_IntFromIdentifier(NPIdentifier identifier)
{
return sBrowserFuncs->intfromidentifier(identifier);
}
bool
NPN_IdentifierIsString(NPIdentifier identifier)
{
return sBrowserFuncs->identifierisstring(identifier);
}
NPError
NPN_GetValue(NPP instance, NPNVariable variable, void* value)
{
return sBrowserFuncs->getvalue(instance, variable, value);
}
NPError
NPN_SetValue(NPP instance, NPPVariable variable, void* value)
{
return sBrowserFuncs->setvalue(instance, variable, value);
}
bool
NPN_HasProperty(NPP instance, NPObject* obj, NPIdentifier propertyName)
{
return sBrowserFuncs->hasproperty(instance, obj, propertyName);
}
NPObject*
NPN_CreateObject(NPP instance, NPClass* aClass)
{
return sBrowserFuncs->createobject(instance, aClass);
}
bool
NPN_Invoke(NPP npp, NPObject* obj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result)
{
return sBrowserFuncs->invoke(npp, obj, methodName, args, argCount, result);
}
const char*
NPN_UserAgent(NPP instance)
{
return sBrowserFuncs->uagent(instance);
}
NPObject*
NPN_RetainObject(NPObject* obj)
{
return sBrowserFuncs->retainobject(obj);
}
void
NPN_ReleaseObject(NPObject* obj)
{
return sBrowserFuncs->releaseobject(obj);
}
void*
NPN_MemAlloc(uint32_t size)
{
return sBrowserFuncs->memalloc(size);
}
void
NPN_MemFree(void* ptr)
{
return sBrowserFuncs->memfree(ptr);
}
uint32_t
NPN_ScheduleTimer(NPP instance, uint32_t interval, NPBool repeat, void (*timerFunc)(NPP npp, uint32_t timerID))
{
return sBrowserFuncs->scheduletimer(instance, interval, repeat, timerFunc);
}
void
NPN_UnscheduleTimer(NPP instance, uint32_t timerID)
{
return sBrowserFuncs->unscheduletimer(instance, timerID);
}
void
NPN_ReleaseVariantValue(NPVariant *variant)
{
return sBrowserFuncs->releasevariantvalue(variant);
}
//
// npruntime object functions
//
NPObject*
scriptableAllocate(NPP npp, NPClass* aClass)
{
TestNPObject* object = (TestNPObject*)NPN_MemAlloc(sizeof(TestNPObject));
if (!object)
return NULL;
memset(object, 0, sizeof(TestNPObject));
return object;
}
void
scriptableDeallocate(NPObject* npobj)
{
NPN_MemFree(npobj);
}
void
scriptableInvalidate(NPObject* npobj)
{
}
bool
scriptableHasMethod(NPObject* npobj, NPIdentifier name)
{
return false;
}
bool
scriptableInvoke(NPObject* npobj, NPIdentifier name, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
return false;
}
bool
scriptableInvokeDefault(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
return false;
}
bool
scriptableHasProperty(NPObject* npobj, NPIdentifier name)
{
return false;
}
bool
scriptableGetProperty(NPObject* npobj, NPIdentifier name, NPVariant* result)
{
return false;
}
bool
scriptableSetProperty(NPObject* npobj, NPIdentifier name, const NPVariant* value)
{
return false;
}
bool
scriptableRemoveProperty(NPObject* npobj, NPIdentifier name)
{
return false;
}
bool
scriptableEnumerate(NPObject* npobj, NPIdentifier** identifier, uint32_t* count)
{
return false;
}
bool
scriptableConstruct(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
return false;
}

Просмотреть файл

@ -0,0 +1,7 @@
LIBRARY NPIPCTEST
EXPORTS
NP_GetEntryPoints @1
NP_Initialize @2
NP_Shutdown @3
NP_GetMIMEDescription @4

Просмотреть файл

@ -0,0 +1,68 @@
/* ***** BEGIN LICENSE BLOCK *****
*
* Copyright (c) 2008, Mozilla Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * 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.
* * Neither the name of the Mozilla Corporation 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT OWNER 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.
*
* Contributor(s):
* Josh Aas <josh@mozilla.com>
*
* ***** END LICENSE BLOCK ***** */
#ifndef nptest_h_
#define nptest_h_
#include "mozilla-config.h"
#include "npapi.h"
#include "npfunctions.h"
#include "npruntime.h"
#include "prtypes.h"
typedef enum {
DM_DEFAULT,
DM_SOLID_COLOR
} DrawMode;
typedef struct TestNPObject : NPObject {
NPP npp;
DrawMode drawMode;
PRUint32 drawColor; // 0xAARRGGBB
} TestNPObject;
typedef struct _PlatformData PlatformData;
typedef struct InstanceData {
NPP npp;
NPWindow window;
PlatformData* platformData;
uint32_t instanceCountWatchGeneration;
bool lastReportedPrivateModeState;
bool hasWidget;
uint32_t timerID1;
uint32_t timerID2;
} InstanceData;
#endif // nptest_h_

Просмотреть файл

@ -0,0 +1,42 @@
#include<winver.h>
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904e4"
BEGIN
VALUE "CompanyName", "mozilla.org"
VALUE "FileDescription", "Plug-in for IPC testing purposes."
VALUE "FileExtents", "tstipc"
VALUE "FileOpenName", "Test IPC mimetype"
VALUE "FileVersion", "1.0"
VALUE "InternalName", "npipctest"
VALUE "MIMEType", "application/x-test-ipc"
VALUE "OriginalFilename", "npipctest.dll"
VALUE "ProductName", "Test IPC Plug-in"
VALUE "ProductVersion", "1.0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1252
END
END

Просмотреть файл

@ -0,0 +1,498 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
*
* Copyright (c) 2008, Mozilla Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * 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.
* * Neither the name of the Mozilla Corporation 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT OWNER 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.
*
* Contributor(s):
* Josh Aas <josh@mozilla.com>
* Michael Ventnor <mventnor@mozilla.com>
*
* ***** END LICENSE BLOCK ***** */
#include "npipctest_platform.h"
#include "npapi.h"
#include <gdk/gdk.h>
#ifdef MOZ_X11
#include <gdk/gdkx.h>
#include <X11/extensions/shape.h>
#endif
#include <gtk/gtk.h>
/**
* XXX In various places in this file we use GDK APIs to inspect the
* window ancestors of the plugin. These APIs will not work properly if
* this plugin is used in a browser that does not use GDK for all its
* widgets. They would also fail for out-of-process plugins. These should
* be fixed to use raw X APIs instead.
*/
struct _PlatformData {
Display* display;
GtkWidget* plug;
};
bool
pluginSupportsWindowMode()
{
return true;
}
bool
pluginSupportsWindowlessMode()
{
return true;
}
NPError
pluginInstanceInit(InstanceData* instanceData)
{
#ifdef MOZ_X11
instanceData->platformData = static_cast<PlatformData*>
(NPN_MemAlloc(sizeof(PlatformData)));
if (!instanceData->platformData)
return NPERR_OUT_OF_MEMORY_ERROR;
instanceData->platformData->display = 0;
instanceData->platformData->plug = 0;
return NPERR_NO_ERROR;
#else
// we only support X11 here, since thats what the plugin system uses
return NPERR_INCOMPATIBLE_VERSION_ERROR;
#endif
}
void
pluginInstanceShutdown(InstanceData* instanceData)
{
if (instanceData->hasWidget) {
Window window = reinterpret_cast<XID>(instanceData->window.window);
if (window != None) {
// This window XID should still be valid.
// See bug 429604 and bug 454756.
XWindowAttributes attributes;
if (!XGetWindowAttributes(instanceData->platformData->display, window,
&attributes))
g_error("XGetWindowAttributes failed at plugin instance shutdown");
}
}
GtkWidget* plug = instanceData->platformData->plug;
if (plug) {
instanceData->platformData->plug = 0;
gtk_widget_destroy(plug);
}
NPN_MemFree(instanceData->platformData);
instanceData->platformData = 0;
}
static void
SetCairoRGBA(cairo_t* cairoWindow, PRUint32 rgba)
{
float b = (rgba & 0xFF) / 255.0;
float g = ((rgba & 0xFF00) >> 8) / 255.0;
float r = ((rgba & 0xFF0000) >> 16) / 255.0;
float a = ((rgba & 0xFF000000) >> 24) / 255.0;
cairo_set_source_rgba(cairoWindow, r, g, b, a);
}
static void
pluginDrawSolid(InstanceData* instanceData, GdkDrawable* gdkWindow,
int x, int y, int width, int height)
{
cairo_t* cairoWindow = gdk_cairo_create(gdkWindow);
if (!instanceData->hasWidget) {
NPRect* clip = &instanceData->window.clipRect;
cairo_rectangle(cairoWindow, clip->left, clip->top,
clip->right - clip->left, clip->bottom - clip->top);
cairo_clip(cairoWindow);
}
GdkRectangle windowRect = { x, y, width, height };
gdk_cairo_rectangle(cairoWindow, &windowRect);
SetCairoRGBA(cairoWindow, 0xFF000000);
cairo_fill(cairoWindow);
cairo_destroy(cairoWindow);
}
static void
pluginDrawWindow(InstanceData* instanceData, GdkDrawable* gdkWindow)
{
NPWindow& window = instanceData->window;
// When we have a widget, window.x/y are meaningless since our
// widget is always positioned correctly and we just draw into it at 0,0
int x = instanceData->hasWidget ? 0 : window.x;
int y = instanceData->hasWidget ? 0 : window.y;
int width = window.width;
int height = window.height;
NPP npp = instanceData->npp;
if (!npp)
return;
const char* uaString = NPN_UserAgent(npp);
if (!uaString)
return;
GdkGC* gdkContext = gdk_gc_new(gdkWindow);
if (!gdkContext)
return;
if (!instanceData->hasWidget) {
NPRect* clip = &window.clipRect;
GdkRectangle gdkClip = { clip->left, clip->top, clip->right - clip->left,
clip->bottom - clip->top };
gdk_gc_set_clip_rectangle(gdkContext, &gdkClip);
}
// draw a grey background for the plugin frame
GdkColor grey;
grey.red = grey.blue = grey.green = 32767;
gdk_gc_set_rgb_fg_color(gdkContext, &grey);
gdk_draw_rectangle(gdkWindow, gdkContext, TRUE, x, y, width, height);
// draw a 3-pixel-thick black frame around the plugin
GdkColor black;
black.red = black.green = black.blue = 0;
gdk_gc_set_rgb_fg_color(gdkContext, &black);
gdk_gc_set_line_attributes(gdkContext, 3, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER);
gdk_draw_rectangle(gdkWindow, gdkContext, FALSE, x + 1, y + 1,
width - 3, height - 3);
// paint the UA string
PangoContext* pangoContext = gdk_pango_context_get();
PangoLayout* pangoTextLayout = pango_layout_new(pangoContext);
pango_layout_set_width(pangoTextLayout, (width - 10) * PANGO_SCALE);
pango_layout_set_text(pangoTextLayout, uaString, -1);
gdk_draw_layout(gdkWindow, gdkContext, x + 5, y + 5, pangoTextLayout);
g_object_unref(pangoTextLayout);
g_object_unref(gdkContext);
}
static gboolean
ExposeWidget(GtkWidget* widget, GdkEventExpose* event,
gpointer user_data)
{
InstanceData* instanceData = static_cast<InstanceData*>(user_data);
pluginDrawWindow(instanceData, event->window);
return TRUE;
}
static gboolean
DeleteWidget(GtkWidget* widget, GdkEvent* event, gpointer user_data)
{
InstanceData* instanceData = static_cast<InstanceData*>(user_data);
// Some plugins do not expect the plug to be removed from the socket before
// the plugin instance is destroyed. e.g. bug 485125
if (instanceData->platformData->plug)
g_error("plug removed"); // this aborts
return FALSE;
}
void
pluginDoSetWindow(InstanceData* instanceData, NPWindow* newWindow)
{
instanceData->window = *newWindow;
NPSetWindowCallbackStruct *ws_info =
static_cast<NPSetWindowCallbackStruct*>(newWindow->ws_info);
instanceData->platformData->display = ws_info->display;
}
void
pluginWidgetInit(InstanceData* instanceData, void* oldWindow)
{
#ifdef MOZ_X11
GtkWidget* oldPlug = instanceData->platformData->plug;
if (oldPlug) {
instanceData->platformData->plug = 0;
gtk_widget_destroy(oldPlug);
}
GdkNativeWindow nativeWinId =
reinterpret_cast<XID>(instanceData->window.window);
/* create a GtkPlug container */
GtkWidget* plug = gtk_plug_new(nativeWinId);
/* make sure the widget is capable of receiving focus */
GTK_WIDGET_SET_FLAGS (GTK_WIDGET(plug), GTK_CAN_FOCUS);
/* all the events that our widget wants to receive */
gtk_widget_add_events(plug, GDK_EXPOSURE_MASK);
g_signal_connect(G_OBJECT(plug), "expose-event", G_CALLBACK(ExposeWidget),
instanceData);
g_signal_connect(G_OBJECT(plug), "delete-event", G_CALLBACK(DeleteWidget),
instanceData);
gtk_widget_show(plug);
instanceData->platformData->plug = plug;
#endif
}
int16_t
pluginHandleEvent(InstanceData* instanceData, void* event)
{
#ifdef MOZ_X11
XEvent *nsEvent = (XEvent *)event;
if (nsEvent->type != GraphicsExpose)
return 0;
XGraphicsExposeEvent *expose = &nsEvent->xgraphicsexpose;
instanceData->window.window = (void*)(expose->drawable);
GdkNativeWindow nativeWinId =
reinterpret_cast<XID>(instanceData->window.window);
GdkDrawable* gdkWindow = GDK_DRAWABLE(gdk_window_foreign_new(nativeWinId));
pluginDrawWindow(instanceData, gdkWindow);
g_object_unref(gdkWindow);
#endif
return 0;
}
int32_t pluginGetEdge(InstanceData* instanceData, RectEdge edge)
{
if (!instanceData->hasWidget)
return NPTEST_INT32_ERROR;
GtkWidget* plug = instanceData->platformData->plug;
if (!plug)
return NPTEST_INT32_ERROR;
GdkWindow* plugWnd = plug->window;
if (!plugWnd)
return NPTEST_INT32_ERROR;
GdkWindow* toplevelGdk = 0;
#ifdef MOZ_X11
Window toplevel = 0;
NPN_GetValue(instanceData->npp, NPNVnetscapeWindow, &toplevel);
if (!toplevel)
return NPTEST_INT32_ERROR;
toplevelGdk = gdk_window_foreign_new(toplevel);
#endif
if (!toplevelGdk)
return NPTEST_INT32_ERROR;
GdkRectangle toplevelFrameExtents;
gdk_window_get_frame_extents(toplevelGdk, &toplevelFrameExtents);
g_object_unref(toplevelGdk);
gint pluginWidth, pluginHeight;
gdk_drawable_get_size(GDK_DRAWABLE(plugWnd), &pluginWidth, &pluginHeight);
gint pluginOriginX, pluginOriginY;
gdk_window_get_origin(plugWnd, &pluginOriginX, &pluginOriginY);
gint pluginX = pluginOriginX - toplevelFrameExtents.x;
gint pluginY = pluginOriginY - toplevelFrameExtents.y;
switch (edge) {
case EDGE_LEFT:
return pluginX;
case EDGE_TOP:
return pluginY;
case EDGE_RIGHT:
return pluginX + pluginWidth;
case EDGE_BOTTOM:
return pluginY + pluginHeight;
}
return NPTEST_INT32_ERROR;
}
#ifdef MOZ_X11
static void intersectWithShapeRects(Display* display, Window window,
int kind, GdkRegion* region)
{
int count = -1, order;
XRectangle* shapeRects =
XShapeGetRectangles(display, window, kind, &count, &order);
// The documentation says that shapeRects will be NULL when the
// extension is not supported. Unfortunately XShapeGetRectangles
// also returns NULL when the region is empty, so we can't treat
// NULL as failure. I hope this way is OK.
if (count < 0)
return;
GdkRegion* shapeRegion = gdk_region_new();
if (!shapeRegion) {
XFree(shapeRects);
return;
}
for (int i = 0; i < count; ++i) {
XRectangle* r = &shapeRects[i];
GdkRectangle rect = { r->x, r->y, r->width, r->height };
gdk_region_union_with_rect(shapeRegion, &rect);
}
XFree(shapeRects);
gdk_region_intersect(region, shapeRegion);
gdk_region_destroy(shapeRegion);
}
#endif
static GdkRegion* computeClipRegion(InstanceData* instanceData)
{
if (!instanceData->hasWidget)
return 0;
GtkWidget* plug = instanceData->platformData->plug;
if (!plug)
return 0;
GdkWindow* plugWnd = plug->window;
if (!plugWnd)
return 0;
gint plugWidth, plugHeight;
gdk_drawable_get_size(GDK_DRAWABLE(plugWnd), &plugWidth, &plugHeight);
GdkRectangle pluginRect = { 0, 0, plugWidth, plugHeight };
GdkRegion* region = gdk_region_rectangle(&pluginRect);
if (!region)
return 0;
int pluginX = 0, pluginY = 0;
#ifdef MOZ_X11
Display* display = GDK_WINDOW_XDISPLAY(plugWnd);
Window window = GDK_WINDOW_XWINDOW(plugWnd);
Window toplevel = 0;
NPN_GetValue(instanceData->npp, NPNVnetscapeWindow, &toplevel);
if (!toplevel)
return 0;
for (;;) {
Window root;
int x, y;
unsigned int width, height, border_width, depth;
if (!XGetGeometry(display, window, &root, &x, &y, &width, &height,
&border_width, &depth)) {
gdk_region_destroy(region);
return 0;
}
GdkRectangle windowRect = { 0, 0, width, height };
GdkRegion* windowRgn = gdk_region_rectangle(&windowRect);
if (!windowRgn) {
gdk_region_destroy(region);
return 0;
}
intersectWithShapeRects(display, window, ShapeBounding, windowRgn);
intersectWithShapeRects(display, window, ShapeClip, windowRgn);
gdk_region_offset(windowRgn, -pluginX, -pluginY);
gdk_region_intersect(region, windowRgn);
gdk_region_destroy(windowRgn);
// Stop now if we've reached the toplevel. Stopping here means
// clipping performed by the toplevel window is taken into account.
if (window == toplevel)
break;
Window parent;
Window* children;
unsigned int nchildren;
if (!XQueryTree(display, window, &root, &parent, &children, &nchildren)) {
gdk_region_destroy(region);
return 0;
}
XFree(children);
pluginX += x;
pluginY += y;
window = parent;
}
#endif
// pluginX and pluginY are now relative to the toplevel. Make them
// relative to the window frame top-left.
GdkWindow* toplevelGdk = gdk_window_foreign_new(window);
if (!toplevelGdk)
return 0;
GdkRectangle toplevelFrameExtents;
gdk_window_get_frame_extents(toplevelGdk, &toplevelFrameExtents);
gint toplevelOriginX, toplevelOriginY;
gdk_window_get_origin(toplevelGdk, &toplevelOriginX, &toplevelOriginY);
g_object_unref(toplevelGdk);
pluginX += toplevelOriginX - toplevelFrameExtents.x;
pluginY += toplevelOriginY - toplevelFrameExtents.y;
gdk_region_offset(region, pluginX, pluginY);
return region;
}
int32_t pluginGetClipRegionRectCount(InstanceData* instanceData)
{
GdkRegion* region = computeClipRegion(instanceData);
if (!region)
return NPTEST_INT32_ERROR;
GdkRectangle* rects;
gint nrects;
gdk_region_get_rectangles(region, &rects, &nrects);
gdk_region_destroy(region);
g_free(rects);
return nrects;
}
int32_t pluginGetClipRegionRectEdge(InstanceData* instanceData,
int32_t rectIndex, RectEdge edge)
{
GdkRegion* region = computeClipRegion(instanceData);
if (!region)
return NPTEST_INT32_ERROR;
GdkRectangle* rects;
gint nrects;
gdk_region_get_rectangles(region, &rects, &nrects);
gdk_region_destroy(region);
if (rectIndex >= nrects) {
g_free(rects);
return NPTEST_INT32_ERROR;
}
GdkRectangle rect = rects[rectIndex];
g_free(rects);
switch (edge) {
case EDGE_LEFT:
return rect.x;
case EDGE_TOP:
return rect.y;
case EDGE_RIGHT:
return rect.x + rect.width;
case EDGE_BOTTOM:
return rect.y + rect.height;
}
return NPTEST_INT32_ERROR;
}

Просмотреть файл

@ -0,0 +1,290 @@
/* ***** BEGIN LICENSE BLOCK *****
*
* Copyright (c) 2008, Mozilla Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * 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.
* * Neither the name of the Mozilla Corporation 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT OWNER 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.
*
* Contributor(s):
* Josh Aas <josh@mozilla.com>
*
* ***** END LICENSE BLOCK ***** */
#include "npipctest_platform.h"
#include <CoreServices/CoreServices.h>
bool
pluginSupportsWindowMode()
{
return false;
}
bool
pluginSupportsWindowlessMode()
{
return true;
}
NPError
pluginInstanceInit(InstanceData* instanceData)
{
NPP npp = instanceData->npp;
// select the right drawing model if necessary
NPBool supportsCoreGraphics = false;
if (NPN_GetValue(npp, NPNVsupportsCoreGraphicsBool, &supportsCoreGraphics) == NPERR_NO_ERROR && supportsCoreGraphics) {
NPN_SetValue(npp, NPPVpluginDrawingModel, (void*)NPDrawingModelCoreGraphics);
} else {
printf("CoreGraphics drawing model not supported, can't create a plugin instance.\n");
return NPERR_INCOMPATIBLE_VERSION_ERROR;
}
return NPERR_NO_ERROR;
}
void
pluginInstanceShutdown(InstanceData* instanceData)
{
}
static bool
RectEquals(const NPRect& r1, const NPRect& r2)
{
return r1.left == r2.left && r1.top == r2.top &&
r1.right == r2.right && r1.bottom == r2.bottom;
}
void
pluginDoSetWindow(InstanceData* instanceData, NPWindow* newWindow)
{
// Ugh. Due to a terrible Gecko bug, we have to ignore position changes
// when the clip rect doesn't change; the position can be wrong
// when set by a path other than nsObjectFrame::FixUpPluginWindow.
int32_t oldX = instanceData->window.x;
int32_t oldY = instanceData->window.y;
bool clipChanged =
!RectEquals(instanceData->window.clipRect, newWindow->clipRect);
instanceData->window = *newWindow;
if (!clipChanged) {
instanceData->window.x = oldX;
instanceData->window.y = oldY;
}
}
void
pluginWidgetInit(InstanceData* instanceData, void* oldWindow)
{
// Should never be called since we don't support window mode
}
static void
GetColorsFromRGBA(PRUint32 rgba, float* r, float* g, float* b, float* a)
{
*b = (rgba & 0xFF) / 255.0;
*g = ((rgba & 0xFF00) >> 8) / 255.0;
*r = ((rgba & 0xFF0000) >> 16) / 255.0;
*a = ((rgba & 0xFF000000) >> 24) / 255.0;
}
static void
pluginDraw(InstanceData* instanceData)
{
if (!instanceData)
return;
NPP npp = instanceData->npp;
if (!npp)
return;
const char* uaString = NPN_UserAgent(npp);
if (!uaString)
return;
NPWindow window = instanceData->window;
CGContextRef cgContext = ((NP_CGContext*)(window.window))->context;
float windowWidth = window.width;
float windowHeight = window.height;
switch(instanceData->scriptableObject->drawMode) {
case DM_DEFAULT: {
CFStringRef uaCFString = CFStringCreateWithCString(kCFAllocatorDefault, uaString, kCFStringEncodingASCII);
// save the cgcontext gstate
CGContextSaveGState(cgContext);
// we get a flipped context
CGContextTranslateCTM(cgContext, 0.0, windowHeight);
CGContextScaleCTM(cgContext, 1.0, -1.0);
// draw a gray background for the plugin
CGContextAddRect(cgContext, CGRectMake(0, 0, windowWidth, windowHeight));
CGContextSetGrayFillColor(cgContext, 0.5, 1.0);
CGContextDrawPath(cgContext, kCGPathFill);
// draw a black frame around the plugin
CGContextAddRect(cgContext, CGRectMake(0, 0, windowWidth, windowHeight));
CGContextSetGrayStrokeColor(cgContext, 0.0, 1.0);
CGContextSetLineWidth(cgContext, 6.0);
CGContextStrokePath(cgContext);
// draw the UA string using ATSUI
CGContextSetGrayFillColor(cgContext, 0.0, 1.0);
ATSUStyle atsuStyle;
ATSUCreateStyle(&atsuStyle);
CFIndex stringLength = CFStringGetLength(uaCFString);
UniChar* unicharBuffer = (UniChar*)malloc((stringLength + 1) * sizeof(UniChar));
CFStringGetCharacters(uaCFString, CFRangeMake(0, stringLength), unicharBuffer);
UniCharCount runLengths = kATSUToTextEnd;
ATSUTextLayout atsuLayout;
ATSUCreateTextLayoutWithTextPtr(unicharBuffer,
kATSUFromTextBeginning,
kATSUToTextEnd,
stringLength,
1,
&runLengths,
&atsuStyle,
&atsuLayout);
ATSUAttributeTag contextTag = kATSUCGContextTag;
ByteCount byteSize = sizeof(CGContextRef);
ATSUAttributeValuePtr contextATSUPtr = &cgContext;
ATSUSetLayoutControls(atsuLayout, 1, &contextTag, &byteSize, &contextATSUPtr);
ATSUTextMeasurement lineAscent, lineDescent;
ATSUGetLineControl(atsuLayout,
kATSUFromTextBeginning,
kATSULineAscentTag,
sizeof(ATSUTextMeasurement),
&lineAscent,
&byteSize);
ATSUGetLineControl(atsuLayout,
kATSUFromTextBeginning,
kATSULineDescentTag,
sizeof(ATSUTextMeasurement),
&lineDescent,
&byteSize);
float lineHeight = FixedToFloat(lineAscent) + FixedToFloat(lineDescent);
ItemCount softBreakCount;
ATSUBatchBreakLines(atsuLayout,
kATSUFromTextBeginning,
stringLength,
FloatToFixed(windowWidth - 10.0),
&softBreakCount);
ATSUGetSoftLineBreaks(atsuLayout,
kATSUFromTextBeginning,
kATSUToTextEnd,
0, NULL, &softBreakCount);
UniCharArrayOffset* softBreaks = (UniCharArrayOffset*)malloc(softBreakCount * sizeof(UniCharArrayOffset));
ATSUGetSoftLineBreaks(atsuLayout,
kATSUFromTextBeginning,
kATSUToTextEnd,
softBreakCount, softBreaks, &softBreakCount);
UniCharArrayOffset currentDrawOffset = kATSUFromTextBeginning;
unsigned int i = 0;
while (i < softBreakCount) {
ATSUDrawText(atsuLayout, currentDrawOffset, softBreaks[i], FloatToFixed(5.0), FloatToFixed(windowHeight - 5.0 - (lineHeight * (i + 1.0))));
currentDrawOffset = softBreaks[i];
i++;
}
ATSUDrawText(atsuLayout, currentDrawOffset, kATSUToTextEnd, FloatToFixed(5.0), FloatToFixed(windowHeight - 5.0 - (lineHeight * (i + 1.0))));
free(unicharBuffer);
free(softBreaks);
// restore the cgcontext gstate
CGContextRestoreGState(cgContext);
}
case DM_SOLID_COLOR: {
// save the cgcontext gstate
CGContextSaveGState(cgContext);
// we get a flipped context
CGContextTranslateCTM(cgContext, 0.0, windowHeight);
CGContextScaleCTM(cgContext, 1.0, -1.0);
// draw a solid background for the plugin
CGContextAddRect(cgContext, CGRectMake(0, 0, windowWidth, windowHeight));
float r,g,b,a;
GetColorsFromRGBA(instanceData->scriptableObject->drawColor, &r, &g, &b, &a);
CGContextSetRGBFillColor(cgContext, r, g, b, a);
CGContextDrawPath(cgContext, kCGPathFill);
// restore the cgcontext gstate
CGContextRestoreGState(cgContext);
break;
}
}
}
int16_t
pluginHandleEvent(InstanceData* instanceData, void* event)
{
EventRecord* carbonEvent = (EventRecord*)event;
if (carbonEvent && (carbonEvent->what == updateEvt)) {
pluginDraw(instanceData);
return 1;
}
return 0;
}
int32_t pluginGetEdge(InstanceData* instanceData, RectEdge edge)
{
NPWindow* w = &instanceData->window;
switch (edge) {
case EDGE_LEFT:
return w->x;
case EDGE_TOP:
return w->y;
case EDGE_RIGHT:
return w->x + w->width;
case EDGE_BOTTOM:
return w->y + w->height;
}
return NPTEST_INT32_ERROR;
}
int32_t pluginGetClipRegionRectCount(InstanceData* instanceData)
{
return 1;
}
int32_t pluginGetClipRegionRectEdge(InstanceData* instanceData,
int32_t rectIndex, RectEdge edge)
{
if (rectIndex != 0)
return NPTEST_INT32_ERROR;
// We have to add the Cocoa titlebar height here since the clip rect
// is being returned relative to that
static const int COCOA_TITLEBAR_HEIGHT = 22;
NPWindow* w = &instanceData->window;
switch (edge) {
case EDGE_LEFT:
return w->clipRect.left;
case EDGE_TOP:
return w->clipRect.top + COCOA_TITLEBAR_HEIGHT;
case EDGE_RIGHT:
return w->clipRect.right;
case EDGE_BOTTOM:
return w->clipRect.bottom + COCOA_TITLEBAR_HEIGHT;
}
return NPTEST_INT32_ERROR;
}

Просмотреть файл

@ -0,0 +1,93 @@
/* ***** BEGIN LICENSE BLOCK *****
*
* Copyright (c) 2008, Mozilla Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * 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.
* * Neither the name of the Mozilla Corporation 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT OWNER 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.
*
* Contributor(s):
* Josh Aas <josh@mozilla.com>
*
* ***** END LICENSE BLOCK ***** */
#include "npipctest_platform.h"
bool
pluginSupportsWindowMode()
{
return false;
}
bool
pluginSupportsWindowlessMode()
{
return true;
}
NPError
pluginInstanceInit(InstanceData* instanceData)
{
return NPERR_NO_ERROR;
}
void
pluginInstanceShutdown(InstanceData* instanceData)
{
}
void
pluginDoSetWindow(InstanceData* instanceData, NPWindow* newWindow)
{
instanceData->window = *newWindow;
}
void
pluginWidgetInit(InstanceData* instanceData, void* oldWindow)
{
}
int16_t
pluginHandleEvent(InstanceData* instanceData, void* event)
{
return 0;
}
int32_t pluginGetEdge(InstanceData* instanceData, RectEdge edge)
{
// XXX nothing here yet since we don't support windowed plugins
return NPTEST_INT32_ERROR;
}
int32_t pluginGetClipRegionRectCount(InstanceData* instanceData)
{
// XXX nothing here yet since we don't support windowed plugins
return NPTEST_INT32_ERROR;
}
int32_t pluginGetClipRegionRectEdge(InstanceData* instanceData,
int32_t rectIndex, RectEdge edge)
{
// XXX nothing here yet since we don't support windowed plugins
return NPTEST_INT32_ERROR;
}

Просмотреть файл

@ -0,0 +1,116 @@
/* ***** BEGIN LICENSE BLOCK *****
*
* Copyright (c) 2008, Mozilla Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * 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.
* * Neither the name of the Mozilla Corporation 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT OWNER 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.
*
* Contributor(s):
* Josh Aas <josh@mozilla.com>
*
* ***** END LICENSE BLOCK ***** */
#ifndef nptest_platform_h_
#define nptest_platform_h_
#include "npipctest.h"
/**
* Returns true if the plugin supports windowed mode
*/
bool pluginSupportsWindowMode();
/**
* Returns true if the plugin supports windowless mode. At least one of
* "pluginSupportsWindowMode" and "pluginSupportsWindowlessMode" must
* return true.
*/
bool pluginSupportsWindowlessMode();
/**
* Initialize the plugin instance. Returning an error here will cause the
* plugin instantiation to fail.
*/
NPError pluginInstanceInit(InstanceData* instanceData);
/**
* Shutdown the plugin instance.
*/
void pluginInstanceShutdown(InstanceData* instanceData);
/**
* Set the instanceData's window to newWindow.
*/
void pluginDoSetWindow(InstanceData* instanceData, NPWindow* newWindow);
/**
* Initialize the window for a windowed plugin. oldWindow is the old
* native window value. This will never be called for windowless plugins.
*/
void pluginWidgetInit(InstanceData* instanceData, void* oldWindow);
/**
* Handle an event for a windowless plugin. (Windowed plugins are
* responsible for listening for their own events.)
*/
int16_t pluginHandleEvent(InstanceData* instanceData, void* event);
enum RectEdge {
EDGE_LEFT = 0,
EDGE_TOP = 1,
EDGE_RIGHT = 2,
EDGE_BOTTOM = 3
};
enum {
NPTEST_INT32_ERROR = 0x7FFFFFFF
};
/**
* Return the coordinate of the given edge of the plugin's area, relative
* to the top-left corner of the toplevel window containing the plugin,
* including window decorations. Only works for window-mode plugins
* and Mac plugins.
* Returns NPTEST_ERROR on error.
*/
int32_t pluginGetEdge(InstanceData* instanceData, RectEdge edge);
/**
* Return the number of rectangles in the plugin's clip region. Only
* works for window-mode plugins and Mac plugins.
* Returns NPTEST_ERROR on error.
*/
int32_t pluginGetClipRegionRectCount(InstanceData* instanceData);
/**
* Return the coordinate of the given edge of a rectangle in the plugin's
* clip region, relative to the top-left corner of the toplevel window
* containing the plugin, including window decorations. Only works for
* window-mode plugins and Mac plugins.
* Returns NPTEST_ERROR on error.
*/
int32_t pluginGetClipRegionRectEdge(InstanceData* instanceData,
int32_t rectIndex, RectEdge edge);
#endif // nptest_platform_h_

Просмотреть файл

@ -0,0 +1,93 @@
/* ***** BEGIN LICENSE BLOCK *****
*
* Copyright (c) 2008, Mozilla Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * 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.
* * Neither the name of the Mozilla Corporation 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT OWNER 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.
*
* Contributor(s):
* Josh Aas <josh@mozilla.com>
*
* ***** END LICENSE BLOCK ***** */
#include "npipctest_platform.h"
bool
pluginSupportsWindowMode()
{
return false;
}
bool
pluginSupportsWindowlessMode()
{
return true;
}
NPError
pluginInstanceInit(InstanceData* instanceData)
{
return NPERR_NO_ERROR;
}
void
pluginInstanceShutdown(InstanceData* instanceData)
{
}
void
pluginDoSetWindow(InstanceData* instanceData, NPWindow* newWindow)
{
instanceData->window = *newWindow;
}
void
pluginWidgetInit(InstanceData* instanceData, void* oldWindow)
{
}
int16_t
pluginHandleEvent(InstanceData* instanceData, void* event)
{
return 0;
}
int32_t pluginGetEdge(InstanceData* instanceData, RectEdge edge)
{
// XXX nothing here yet since we don't support windowed plugins
return NPTEST_INT32_ERROR;
}
int32_t pluginGetClipRegionRectCount(InstanceData* instanceData)
{
// XXX nothing here yet since we don't support windowed plugins
return NPTEST_INT32_ERROR;
}
int32_t pluginGetClipRegionRectEdge(InstanceData* instanceData,
int32_t rectIndex, RectEdge edge)
{
// XXX nothing here yet since we don't support windowed plugins
return NPTEST_INT32_ERROR;
}

Просмотреть файл

@ -0,0 +1,119 @@
/* ***** BEGIN LICENSE BLOCK *****
*
* Copyright (C) 2006, 2007, 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.
*
* Contributor(s):
* Josh Aas <josh@mozilla.com>
*
* ***** END LICENSE BLOCK ***** */
#include "npipctest_utils.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
NPUTF8*
createCStringFromNPVariant(const NPVariant* variant)
{
size_t length = NPVARIANT_TO_STRING(*variant).UTF8Length;
NPUTF8* result = (NPUTF8*)malloc(length + 1);
memcpy(result, NPVARIANT_TO_STRING(*variant).UTF8Characters, length);
result[length] = '\0';
return result;
}
NPIdentifier
variantToIdentifier(NPVariant variant)
{
if (NPVARIANT_IS_STRING(variant))
return stringVariantToIdentifier(variant);
else if (NPVARIANT_IS_INT32(variant))
return int32VariantToIdentifier(variant);
else if (NPVARIANT_IS_DOUBLE(variant))
return doubleVariantToIdentifier(variant);
return 0;
}
NPIdentifier
stringVariantToIdentifier(NPVariant variant)
{
assert(NPVARIANT_IS_STRING(variant));
NPUTF8* utf8String = createCStringFromNPVariant(&variant);
NPIdentifier identifier = NPN_GetStringIdentifier(utf8String);
free(utf8String);
return identifier;
}
NPIdentifier
int32VariantToIdentifier(NPVariant variant)
{
assert(NPVARIANT_IS_INT32(variant));
int32_t integer = NPVARIANT_TO_INT32(variant);
return NPN_GetIntIdentifier(integer);
}
NPIdentifier
doubleVariantToIdentifier(NPVariant variant)
{
assert(NPVARIANT_IS_DOUBLE(variant));
double value = NPVARIANT_TO_DOUBLE(variant);
// sadly there is no "getdoubleidentifier"
int32_t integer = static_cast<int32_t>(value);
return NPN_GetIntIdentifier(integer);
}
/*
* Parse a color in hex format, like AARRGGBB
* If the string is short, portions to the left are assumed omitted.
* R G B default to 0, A defaults to 0xFF
*/
PRUint32
parseHexColor(char* color)
{
int len = strlen(color);
PRUint8 bgra[4] = { 0, 0, 0, 0xFF };
int i = 0;
// start from the right and work to the left
while (len > 0) {
char byte[3];
if (len > 1) {
// parse two hex digits
byte[0] = color[len - 2];
byte[1] = color[len - 1];
}
else {
// only one digit left
byte[0] = '0';
byte[1] = color[len - 1];
}
byte[2] = '\0';
bgra[i] = (PRUint8)(strtoul(byte, NULL, 16) & 0xFF);
i++;
len -= 2;
}
return (bgra[3] << 24) | (bgra[2] << 16) | (bgra[1] << 8) | bgra[0];
}

Просмотреть файл

@ -0,0 +1,45 @@
/* ***** BEGIN LICENSE BLOCK *****
*
* Copyright (C) 2006, 2007, 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.
*
* Contributor(s):
* Josh Aas <josh@mozilla.com>
*
* ***** END LICENSE BLOCK ***** */
#ifndef nptest_utils_h_
#define nptest_utils_h_
#include "npipctest.h"
NPUTF8* createCStringFromNPVariant(const NPVariant* variant);
NPIdentifier variantToIdentifier(NPVariant variant);
NPIdentifier stringVariantToIdentifier(NPVariant variant);
NPIdentifier int32VariantToIdentifier(NPVariant variant);
NPIdentifier doubleVariantToIdentifier(NPVariant variant);
PRUint32 parseHexColor(char* color);
#endif // nptest_utils_h_

Просмотреть файл

@ -0,0 +1,406 @@
/* ***** BEGIN LICENSE BLOCK *****
*
* Copyright (c) 2008, Mozilla Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * 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.
* * Neither the name of the Mozilla Corporation 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT OWNER 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.
*
* Contributor(s):
* Josh Aas <josh@mozilla.com>
* Jim Mathies <jmathies@mozilla.com>
*
* ***** END LICENSE BLOCK ***** */
#include "npipctest_platform.h"
#include <windows.h>
#pragma comment(lib, "msimg32.lib")
void SetSubclass(HWND hWnd, InstanceData* instanceData);
void ClearSubclass(HWND hWnd);
LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
bool
pluginSupportsWindowMode()
{
return true;
}
bool
pluginSupportsWindowlessMode()
{
return true;
}
NPError
pluginInstanceInit(InstanceData* instanceData)
{
return NPERR_NO_ERROR;
}
void
pluginInstanceShutdown(InstanceData* instanceData)
{
}
void
pluginDoSetWindow(InstanceData* instanceData, NPWindow* newWindow)
{
instanceData->window = *newWindow;
}
void
pluginWidgetInit(InstanceData* instanceData, void* oldWindow)
{
HWND hWnd = (HWND)instanceData->window.window;
if (oldWindow) {
HWND hWndOld = (HWND)oldWindow;
ClearSubclass(hWndOld);
}
SetSubclass(hWnd, instanceData);
}
static void
drawToDC(InstanceData* instanceData, HDC dc,
int x, int y, int width, int height)
{
HBITMAP offscreenBitmap = ::CreateCompatibleBitmap(dc, width, height);
if (!offscreenBitmap)
return;
HDC offscreenDC = ::CreateCompatibleDC(dc);
if (!offscreenDC) {
::DeleteObject(offscreenBitmap);
return;
}
HBITMAP oldOffscreenBitmap =
(HBITMAP)::SelectObject(offscreenDC, offscreenBitmap);
::SetBkMode(offscreenDC, TRANSPARENT);
BYTE alpha = 255;
RECT fill = { 0, 0, width, height };
HBRUSH brush = ::CreateSolidBrush(RGB(0, 0, 0));
if (brush) {
::FillRect(offscreenDC, &fill, brush);
::DeleteObject(brush);
}
if (width > 6 && height > 6) {
brush = ::CreateSolidBrush(RGB(192, 192, 192));
if (brush) {
RECT inset = { 3, 3, width - 3, height - 3 };
::FillRect(offscreenDC, &inset, brush);
::DeleteObject(brush);
}
}
const char* uaString = NPN_UserAgent(instanceData->npp);
if (uaString && width > 10 && height > 10) {
HFONT font =
::CreateFontA(20, 0, 0, 0, 400, FALSE, FALSE, FALSE,
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, 5, // CLEARTYPE_QUALITY
DEFAULT_PITCH, "Arial");
if (font) {
HFONT oldFont = (HFONT)::SelectObject(offscreenDC, font);
RECT inset = { 5, 5, width - 5, height - 5 };
::DrawTextA(offscreenDC, uaString, -1, &inset,
DT_LEFT | DT_TOP | DT_NOPREFIX | DT_WORDBREAK);
::SelectObject(offscreenDC, oldFont);
::DeleteObject(font);
}
}
BLENDFUNCTION blendFunc;
blendFunc.BlendOp = AC_SRC_OVER;
blendFunc.BlendFlags = 0;
blendFunc.SourceConstantAlpha = alpha;
blendFunc.AlphaFormat = 0;
::AlphaBlend(dc, x, y, width, height, offscreenDC, 0, 0, width, height,
blendFunc);
::SelectObject(offscreenDC, oldOffscreenBitmap);
::DeleteObject(offscreenDC);
::DeleteObject(offscreenBitmap);
}
void
pluginDraw(InstanceData* instanceData)
{
NPP npp = instanceData->npp;
if (!npp)
return;
HDC hdc = NULL;
PAINTSTRUCT ps;
if (instanceData->hasWidget)
hdc = ::BeginPaint((HWND)instanceData->window.window, &ps);
else
hdc = (HDC)instanceData->window.window;
if (hdc == NULL)
return;
// Push the browser's hdc on the resource stack. If this test plugin is windowless,
// we share the drawing surface with the rest of the browser.
int savedDCID = SaveDC(hdc);
// When we have a widget, window.x/y are meaningless since our widget
// is always positioned correctly and we just draw into it at 0,0.
int x = instanceData->hasWidget ? 0 : instanceData->window.x;
int y = instanceData->hasWidget ? 0 : instanceData->window.y;
int width = instanceData->window.width;
int height = instanceData->window.height;
drawToDC(instanceData, hdc, x, y, width, height);
// Pop our hdc changes off the resource stack
RestoreDC(hdc, savedDCID);
if (instanceData->hasWidget)
::EndPaint((HWND)instanceData->window.window, &ps);
}
/* script interface */
int32_t
pluginGetEdge(InstanceData* instanceData, RectEdge edge)
{
if (!instanceData || !instanceData->hasWidget)
return NPTEST_INT32_ERROR;
// Get the plugin client rect in screen coordinates
RECT rect = {0};
if (!::GetClientRect((HWND)instanceData->window.window, &rect))
return NPTEST_INT32_ERROR;
::MapWindowPoints((HWND)instanceData->window.window, NULL, (LPPOINT)&rect, 2);
// Get the toplevel window frame rect in screen coordinates
HWND rootWnd = ::GetAncestor((HWND)instanceData->window.window, GA_ROOT);
if (!rootWnd)
return NPTEST_INT32_ERROR;
RECT rootRect;
if (!::GetWindowRect(rootWnd, &rootRect))
return NPTEST_INT32_ERROR;
switch (edge) {
case EDGE_LEFT:
return rect.left - rootRect.left;
case EDGE_TOP:
return rect.top - rootRect.top;
case EDGE_RIGHT:
return rect.right - rootRect.left;
case EDGE_BOTTOM:
return rect.bottom - rootRect.top;
}
return NPTEST_INT32_ERROR;
}
static BOOL
getWindowRegion(HWND wnd, HRGN rgn)
{
if (::GetWindowRgn(wnd, rgn) != ERROR)
return TRUE;
RECT clientRect;
if (!::GetClientRect(wnd, &clientRect))
return FALSE;
return ::SetRectRgn(rgn, 0, 0, clientRect.right, clientRect.bottom);
}
static RGNDATA*
computeClipRegion(InstanceData* instanceData)
{
HWND wnd = (HWND)instanceData->window.window;
HRGN rgn = ::CreateRectRgn(0, 0, 0, 0);
if (!rgn)
return NULL;
HRGN ancestorRgn = ::CreateRectRgn(0, 0, 0, 0);
if (!ancestorRgn) {
::DeleteObject(rgn);
return NULL;
}
if (!getWindowRegion(wnd, rgn)) {
::DeleteObject(ancestorRgn);
::DeleteObject(rgn);
return NULL;
}
HWND ancestor = wnd;
for (;;) {
ancestor = ::GetAncestor(ancestor, GA_PARENT);
if (!ancestor || ancestor == ::GetDesktopWindow()) {
::DeleteObject(ancestorRgn);
DWORD size = ::GetRegionData(rgn, 0, NULL);
if (!size) {
::DeleteObject(rgn);
return NULL;
}
HANDLE heap = ::GetProcessHeap();
RGNDATA* data = static_cast<RGNDATA*>(::HeapAlloc(heap, 0, size));
if (!data) {
::DeleteObject(rgn);
return NULL;
}
DWORD result = ::GetRegionData(rgn, size, data);
::DeleteObject(rgn);
if (!result) {
::HeapFree(heap, 0, data);
return NULL;
}
return data;
}
if (!getWindowRegion(ancestor, ancestorRgn)) {
::DeleteObject(ancestorRgn);
::DeleteObject(rgn);
return 0;
}
POINT pt = { 0, 0 };
::MapWindowPoints(ancestor, wnd, &pt, 1);
if (::OffsetRgn(ancestorRgn, pt.x, pt.y) == ERROR ||
::CombineRgn(rgn, rgn, ancestorRgn, RGN_AND) == ERROR) {
::DeleteObject(ancestorRgn);
::DeleteObject(rgn);
return 0;
}
}
}
int32_t
pluginGetClipRegionRectCount(InstanceData* instanceData)
{
RGNDATA* data = computeClipRegion(instanceData);
if (!data)
return NPTEST_INT32_ERROR;
int32_t result = data->rdh.nCount;
::HeapFree(::GetProcessHeap(), 0, data);
return result;
}
static int32_t
addOffset(LONG coord, int32_t offset)
{
if (offset == NPTEST_INT32_ERROR)
return NPTEST_INT32_ERROR;
return coord + offset;
}
int32_t
pluginGetClipRegionRectEdge(InstanceData* instanceData,
int32_t rectIndex, RectEdge edge)
{
RGNDATA* data = computeClipRegion(instanceData);
if (!data)
return NPTEST_INT32_ERROR;
HANDLE heap = ::GetProcessHeap();
if (rectIndex >= int32_t(data->rdh.nCount)) {
::HeapFree(heap, 0, data);
return NPTEST_INT32_ERROR;
}
RECT rect = reinterpret_cast<RECT*>(data->Buffer)[rectIndex];
::HeapFree(heap, 0, data);
switch (edge) {
case EDGE_LEFT:
return addOffset(rect.left, pluginGetEdge(instanceData, EDGE_LEFT));
case EDGE_TOP:
return addOffset(rect.top, pluginGetEdge(instanceData, EDGE_TOP));
case EDGE_RIGHT:
return addOffset(rect.right, pluginGetEdge(instanceData, EDGE_LEFT));
case EDGE_BOTTOM:
return addOffset(rect.bottom, pluginGetEdge(instanceData, EDGE_TOP));
}
return NPTEST_INT32_ERROR;
}
/* windowless plugin events */
int16_t
pluginHandleEvent(InstanceData* instanceData, void* event)
{
NPEvent * pe = (NPEvent*) event;
if (pe == NULL || instanceData == NULL ||
instanceData->window.type != NPWindowTypeDrawable)
return 0;
switch((UINT)pe->event) {
case WM_PAINT:
pluginDraw(instanceData);
return 1;
}
return 0;
}
/* windowed plugin events */
LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
WNDPROC wndProc = (WNDPROC)GetProp(hWnd, "MozillaWndProc");
if (!wndProc)
return 0;
InstanceData* pInstance = (InstanceData*)GetProp(hWnd, "InstanceData");
if (!pInstance)
return 0;
if (uMsg == WM_PAINT) {
pluginDraw(pInstance);
return 0;
}
if (uMsg == WM_CLOSE) {
ClearSubclass((HWND)pInstance->window.window);
}
return CallWindowProc(wndProc, hWnd, uMsg, wParam, lParam);
}
void
ClearSubclass(HWND hWnd)
{
if (GetProp(hWnd, "MozillaWndProc")) {
::SetWindowLong(hWnd, GWL_WNDPROC, (long)GetProp(hWnd, "MozillaWndProc"));
RemoveProp(hWnd, "MozillaWndProc");
RemoveProp(hWnd, "InstanceData");
}
}
void
SetSubclass(HWND hWnd, InstanceData* instanceData)
{
// Subclass the plugin window so we can handle our own windows events.
SetProp(hWnd, "InstanceData", (HANDLE)instanceData);
WNDPROC origProc = (WNDPROC)::SetWindowLong(hWnd, GWL_WNDPROC, (long)PluginWndProc);
SetProp(hWnd, "MozillaWndProc", (HANDLE)origProc);
}

47
ipc/Makefile.in Normal file
Просмотреть файл

@ -0,0 +1,47 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is the Mozilla platform.
#
# The Initial Developer of the Original Code is
# the Mozilla Foundation <http://www.mozilla.org/>.
# Portions created by the Initial Developer are Copyright (C) 2009
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS += test-harness testshell
TOOL_DIRS = app
include $(topsrcdir)/config/rules.mk

111
ipc/app/Makefile.in Normal file
Просмотреть файл

@ -0,0 +1,111 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Plugin App.
#
# The Initial Developer of the Original Code is
# Ben Turner <bent.mozilla@gmail.com>.
# Portions created by the Initial Developer are Copyright (C) 2009
# the Initial Developer. All Rights Reserved.
# Chris Jones <jones.chris.g@gmail.com>
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = ipc
include $(topsrcdir)/ipc/app/defs.mk
PROGRAM = $(MOZ_CHILD_PROCESS_NAME)
CPPSRCS = \
MozillaRuntimeMain.cpp \
$(NULL)
LIBS += \
$(XPCOM_LIBS) \
$(NSPR_LIBS) \
$(NULL)
LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre
ifndef MOZ_WINCONSOLE
ifdef MOZ_DEBUG
MOZ_WINCONSOLE = 1
else
MOZ_WINCONSOLE = 0
endif
endif
# This switches $(INSTALL) to copy mode, like $(SYSINSTALL), so things that
# shouldn't get 755 perms need $(IFLAGS1) for either way of calling nsinstall.
NSDISTMODE = copy
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk
ifdef _MSC_VER
# Always enter a Windows program through wmain, whether or not we're
# a console application.
ifdef WINCE
WIN32_EXE_LDFLAGS += -ENTRY:mainWCRTStartup
else
WIN32_EXE_LDFLAGS += -ENTRY:wmainCRTStartup
endif
endif
ifdef WINCE
EXTRA_DSO_LDOPTS += $(call EXPAND_LIBNAME,corelibc)
endif
ifeq ($(OS_ARCH),WINNT)
OS_LIBS += $(call EXPAND_LIBNAME,comctl32 comdlg32 uuid shell32 ole32 oleaut32 version winspool)
OS_LIBS += $(call EXPAND_LIBNAME,usp10 msimg32)
endif
include $(topsrcdir)/config/rules.mk
ifeq ($(OS_ARCH),WINNT)
#
# Control the default heap size.
# This is the heap returned by GetProcessHeap().
# As we use the CRT heap, the default size is too large and wastes VM.
#
# The default heap size is 1MB on Win32.
# The heap will grow if need be.
#
# Set it to 256k. See bug 127069.
#
ifndef GNU_CC
LDFLAGS += /HEAP:0x40000
endif
endif

Просмотреть файл

@ -0,0 +1,68 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Ben Turner <bent.mozilla@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chris Jones <jones.chris.g@gmail.com>.
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsXPCOM.h"
#include "nsXULAppAPI.h"
// FIXME/cjones testing
#if !defined(OS_WIN)
#include <unistd.h>
#endif
#ifdef XP_WIN
#include <windows.h>
// we want a wmain entry point
#include "nsWindowsWMain.cpp"
#endif
int
main(int argc, char* argv[])
{
#if defined(XP_WIN) && defined(DEBUG_bent)
MessageBox(NULL, L"Hi", L"Hi", MB_OK);
#endif
GeckoProcessType proctype =
XRE_StringToChildProcessType(argv[argc - 1]);
nsresult rv = XRE_InitChildProcess(argc - 1, argv, proctype);
NS_ENSURE_SUCCESS(rv, 1);
return 0;
}

37
ipc/app/defs.mk Normal file
Просмотреть файл

@ -0,0 +1,37 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla IPC.
#
# The Initial Developer of the Original Code is
# Chris Jones <jones.chris.g@gmail.com>.
# Portions created by the Initial Developer are Copyright (C) 2009
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
MOZ_CHILD_PROCESS_NAME := mozilla-runtime$(BIN_SUFFIX)

299
ipc/chromium/Makefile.in Normal file
Просмотреть файл

@ -0,0 +1,299 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is the Mozilla platform.
#
# The Initial Developer of the Original Code is
# the Mozilla Foundation <http://www.mozilla.org/>.
# Portions created by the Initial Developer are Copyright (C) 2009
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
OS_CXXFLAGS := $(filter-out -fshort-wchar,$(OS_CXXFLAGS))
LIBRARY_NAME = chromium_s
FORCE_STATIC_LIB = 1
LIBXUL_LIBRARY = 1
EXPORT_LIBRARY = 1
ENABLE_CXX_EXCEPTIONS = 1
ACDEFINES =
vpath %.c \
$(srcdir)/src/third_party/libevent \
$(NULL)
vpath %.cc \
$(srcdir)/src/base \
$(srcdir)/src/base/third_party/dmg_fp \
$(srcdir)/src/base/third_party/nspr \
$(srcdir)/src/base/third_party/nss \
$(srcdir)/src/chrome/common \
$(NULL)
vpath %.mm \
$(srcdir)/src/base \
$(srcdir)/src/chrome/common \
$(NULL)
# TODO: remove this hack when we switch to GCC 4.3! GCC 4.1
# instantiates template declarations in wrapped system headers with
# the wrong visibility, which is causing the Linux tinderboxen to die in
# std::string internals.
VISIBILITY_FLAGS=
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk
CPPSRCS += \
dtoa.cc \
g_fmt.cc \
prtime.cc \
at_exit.cc \
base_paths.cc \
base_switches.cc \
command_line.cc \
debug_util.cc \
file_path.cc \
file_util.cc \
histogram.cc \
lazy_instance.cc \
lock.cc \
logging.cc \
memory_debug.cc \
message_loop.cc \
message_pump_default.cc \
non_thread_safe.cc \
path_service.cc \
pickle.cc \
rand_util.cc \
ref_counted.cc \
revocable_store.cc \
scoped_temp_dir.cc \
sha2.cc \
simple_thread.cc \
stats_table.cc \
string_escape.cc \
string_piece.cc \
string_util.cc \
system_monitor.cc \
thread.cc \
thread_collision_warner.cc \
time.cc \
timer.cc \
trace_event.cc \
tracked.cc \
tracked_objects.cc \
child_process.cc \
child_process_host.cc \
child_process_info.cc \
child_thread.cc \
chrome_counters.cc \
chrome_paths.cc \
chrome_switches.cc \
debug_flags.cc \
env_vars.cc \
ipc_channel_proxy.cc \
ipc_logging.cc \
ipc_message.cc \
ipc_message_utils.cc \
ipc_sync_channel.cc \
ipc_sync_message.cc \
message_router.cc \
notification_service.cc \
task_queue.cc \
$(NULL)
ifdef OS_WIN # {
CPPSRCS += \
base_paths_win.cc \
cpu.cc \
condition_variable_win.cc \
debug_on_start.cc \
debug_util_win.cc \
event_recorder.cc \
file_util_win.cc \
file_version_info.cc \
lock_impl_win.cc \
idle_timer.cc \
message_pump_win.cc \
object_watcher.cc \
platform_file_win.cc \
platform_thread_win.cc \
process_util_win.cc \
process_win.cc \
rand_util_win.cc \
registry.cc \
shared_memory_win.cc \
sys_info_win.cc \
sys_string_conversions_win.cc \
system_monitor_win.cc \
thread_local_storage_win.cc \
thread_local_win.cc \
time_win.cc \
waitable_event_watcher_win.cc \
waitable_event_win.cc \
win_util.cc \
chrome_paths_win.cc \
ipc_channel_win.cc \
process_watcher_win.cc \
transport_dib_win.cc \
$(NULL)
endif # } OS_WIN
ifdef OS_POSIX # {
CPPSRCS += \
sha512.cc \
condition_variable_posix.cc \
debug_util_posix.cc \
event_recorder_stubs.cc \
file_descriptor_shuffle.cc \
file_util_posix.cc \
lock_impl_posix.cc \
message_pump_libevent.cc \
platform_file_posix.cc \
platform_thread_posix.cc \
process_posix.cc \
process_util_posix.cc \
rand_util_posix.cc \
shared_memory_posix.cc \
string16.cc \
system_monitor_posix.cc \
sys_info_posix.cc \
thread_local_posix.cc \
thread_local_storage_posix.cc \
waitable_event_posix.cc \
waitable_event_watcher_posix.cc \
file_descriptor_set_posix.cc \
ipc_channel_posix.cc \
process_watcher_posix.cc \
$(NULL)
endif # } OS_POSIX
ifdef OS_MACOSX # {
CMMSRCS += \
base_paths_mac.mm \
file_util_mac.mm \
file_version_info_mac.mm \
mac_util.mm \
message_pump_mac.mm \
platform_thread_mac.mm \
process_util_mac.mm \
scoped_nsautorelease_pool.mm \
sys_string_conversions_mac.mm \
worker_pool_mac.mm \
chrome_paths_mac.mm \
mach_ipc_mac.mm \
platform_util_mac.mm \
$(NULL)
CPPSRCS += \
data_pack.cc \
debug_util_mac.cc \
hmac_mac.cc \
idle_timer.cc \
sys_info_mac.cc \
time_mac.cc \
mach_message_source_mac.cc \
transport_dib_mac.cc \
$(NULL)
endif # } OS_MACOSX
ifdef OS_LINUX # {
CPPSRCS += \
atomicops_internals_x86_gcc.cc \
base_paths_linux.cc \
data_pack.cc \
file_util_linux.cc \
file_version_info_linux.cc \
idle_timer_none.cc \
message_pump_glib.cc \
process_util_linux.cc \
time_posix.cc \
chrome_paths_linux.cc \
owned_widget_gtk.cc \
platform_util_linux.cc \
transport_dib_linux.cc \
x11_util.cc \
$(NULL)
endif # } OS_LINUX
# libevent
ifdef OS_POSIX # {
LOCAL_INCLUDES += -I$(srcdir)/src/third_party/libevent
DEFINES += -DHAVE_CONFIG_H
CSRCS += \
buffer.c \
evbuffer.c \
evdns.c \
event.c \
event_tagging.c \
evrpc.c \
evutil.c \
http.c \
log.c \
poll.c \
select.c \
signal.c \
strlcpy.c \
$(NULL)
ifdef OS_MACOSX # {
LOCAL_INCLUDES += -I$(srcdir)/src/third_party/libevent/mac
CSRCS += kqueue.c
endif # }
ifdef OS_LINUX # {
LOCAL_INCLUDES += -I$(srcdir)/src/third_party/libevent/linux
CSRCS += \
epoll.c \
epoll_sub.c \
$(NULL)
endif # }
endif # }
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,26 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_FILE_VERSION_INFO_LINUX_H_
#define BASE_FILE_VERSION_INFO_LINUX_H_
#define COMPANY_NAME L"@COMPANY_FULLNAME@"
#define FILE_DESCRIPTION L"@PRODUCT_FULLNAME@"
#define FILE_VERSION L"@MAJOR@.@MINOR@.@BUILD@.@PATCH@"
#define LEGAL_COPYRIGHT L"@COPYRIGHT@"
#define PRODUCT_NAME L"@PRODUCT_FULLNAME@"
#define PRODUCT_VERSION L"@MAJOR@.@MINOR@.@BUILD@.@PATCH@"
#define COMPANY_SHORT_NAME L"@COMPANY_SHORTNAME@"
#define PRODUCT_SHORT_NAME L"@PRODUCT_SHORTNAME@"
#define LAST_CHANGE L"@LASTCHANGE@"
#define OFFICIAL_BUILD 1
// TODO(mmoss) Do these have values for Linux?
#define INTERNAL_NAME L""
#define ORIGINAL_FILENAME L""
#define PRIVATE_BUILD L""
#define SPECIAL_BUILD L""
#define COMMENTS L""
#define LEGAL_TRADEMARKS L""
#endif // BASE_FILE_VERSION_INFO_LINUX_H_

Просмотреть файл

@ -0,0 +1,116 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is the Mozilla platform.
#
# The Initial Developer of the Original Code is
# the Mozilla Foundation <http://www.mozilla.org/>.
# Portions created by the Initial Developer are Copyright (C) 2009
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
ifndef INCLUDED_CONFIG_MK
$(error Must include config.mk before this file.)
endif
ifdef CHROMIUM_CONFIG_INCLUDED
$(error Must not include chromium-config.mk twice.)
endif
CHROMIUM_CONFIG_INCLUDED = 1
EXTRA_DEPS += $(topsrcdir)/ipc/chromium/chromium-config.mk
ifdef MOZ_IPC # {
DEFINES += \
-DEXCLUDE_SKIA_DEPENDENCIES \
-DCHROMIUM_MOZILLA_BUILD \
$(NULL)
LOCAL_INCLUDES += \
-I$(topsrcdir)/ipc/chromium/src \
-I$(topsrcdir)/ipc/glue \
-I$(DEPTH)/ipc/ipdl/_ipdlheaders \
$(NULL)
ifeq ($(OS_ARCH),Darwin) # {
OS_MACOSX = 1
OS_POSIX = 1
DEFINES += \
-DOS_MACOSX=1 \
-DOS_POSIX=1 \
$(NULL)
else # } {
ifeq ($(OS_ARCH),WINNT) # {
OS_LIBS += $(call EXPAND_LIBNAME,psapi shell32 dbghelp)
OS_WIN = 1
DEFINES += \
-DUNICODE \
-D_UNICODE \
-DNOMINMAX \
-D_CRT_RAND_S \
-DCERT_CHAIN_PARA_HAS_EXTRA_FIELDS \
-D_SECURE_ATL \
-D_HAS_TR1=0 \
-DCHROMIUM_BUILD \
-DU_STATIC_IMPLEMENTATION \
-DCOMPILER_MSVC \
-DOS_WIN=1 \
-DWIN32 \
-D_WIN32 \
-D_WINDOWS \
-DWIN32_LEAN_AND_MEAN \
$(NULL)
else # } {
OS_LINUX = 1
OS_POSIX = 1
DEFINES += \
-DOS_LINUX=1 \
-DOS_POSIX=1 \
$(NULL)
# NB: to stop gcc warnings about exporting template instantiation
OS_CXXFLAGS := $(filter-out -pedantic,$(OS_CXXFLAGS))
# TODO support !GTK
OS_CXXFLAGS += $(MOZ_GTK2_CFLAGS)
OS_CFLAGS += $(MOZ_GTK2_CFLAGS)
endif # }
endif # }
endif # }

Просмотреть файл

@ -0,0 +1,6 @@
include_rules = [
"+third_party/zlib",
"+third_party/libevent",
"+third_party/libjpeg",
"+third_party/dmg_fp",
]

Просмотреть файл

@ -0,0 +1,74 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/at_exit.h"
#include "base/logging.h"
namespace base {
// Keep a stack of registered AtExitManagers. We always operate on the most
// recent, and we should never have more than one outside of testing, when we
// use the shadow version of the constructor. We don't protect this for
// thread-safe access, since it will only be modified in testing.
static AtExitManager* g_top_manager = NULL;
AtExitManager::AtExitManager() : next_manager_(NULL) {
DCHECK(!g_top_manager);
g_top_manager = this;
}
AtExitManager::AtExitManager(bool shadow) : next_manager_(g_top_manager) {
DCHECK(shadow || !g_top_manager);
g_top_manager = this;
}
AtExitManager::~AtExitManager() {
if (!g_top_manager) {
NOTREACHED() << "Tried to ~AtExitManager without an AtExitManager";
return;
}
DCHECK(g_top_manager == this);
ProcessCallbacksNow();
g_top_manager = next_manager_;
}
// static
void AtExitManager::RegisterCallback(AtExitCallbackType func, void* param) {
if (!g_top_manager) {
NOTREACHED() << "Tried to RegisterCallback without an AtExitManager";
return;
}
DCHECK(func);
AutoLock lock(g_top_manager->lock_);
g_top_manager->stack_.push(CallbackAndParam(func, param));
}
// static
void AtExitManager::ProcessCallbacksNow() {
if (!g_top_manager) {
NOTREACHED() << "Tried to ProcessCallbacksNow without an AtExitManager";
return;
}
AutoLock lock(g_top_manager->lock_);
while (!g_top_manager->stack_.empty()) {
CallbackAndParam callback_and_param = g_top_manager->stack_.top();
g_top_manager->stack_.pop();
callback_and_param.func_(callback_and_param.param_);
}
}
#ifdef CHROMIUM_MOZILLA_BUILD
// static
bool AtExitManager::AlreadyRegistered() {
return !!g_top_manager;
}
#endif
} // namespace base

Просмотреть файл

@ -0,0 +1,75 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_AT_EXIT_H_
#define BASE_AT_EXIT_H_
#include <stack>
#include "base/basictypes.h"
#include "base/lock.h"
namespace base {
// This class provides a facility similar to the CRT atexit(), except that
// we control when the callbacks are executed. Under Windows for a DLL they
// happen at a really bad time and under the loader lock. This facility is
// mostly used by base::Singleton.
//
// The usage is simple. Early in the main() or WinMain() scope create an
// AtExitManager object on the stack:
// int main(...) {
// base::AtExitManager exit_manager;
//
// }
// When the exit_manager object goes out of scope, all the registered
// callbacks and singleton destructors will be called.
class AtExitManager {
protected:
// This constructor will allow this instance of AtExitManager to be created
// even if one already exists. This should only be used for testing!
// AtExitManagers are kept on a global stack, and it will be removed during
// destruction. This allows you to shadow another AtExitManager.
AtExitManager(bool shadow);
public:
typedef void (*AtExitCallbackType)(void*);
AtExitManager();
// The dtor calls all the registered callbacks. Do not try to register more
// callbacks after this point.
~AtExitManager();
// Registers the specified function to be called at exit. The prototype of
// the callback function is void func().
static void RegisterCallback(AtExitCallbackType func, void* param);
// Calls the functions registered with RegisterCallback in LIFO order. It
// is possible to register new callbacks after calling this function.
static void ProcessCallbacksNow();
#ifdef CHROMIUM_MOZILLA_BUILD
static bool AlreadyRegistered();
#endif
private:
struct CallbackAndParam {
CallbackAndParam(AtExitCallbackType func, void* param)
: func_(func), param_(param) { }
AtExitCallbackType func_;
void* param_;
};
Lock lock_;
std::stack<CallbackAndParam> stack_;
AtExitManager* next_manager_; // Stack of managers to allow shadowing.
DISALLOW_COPY_AND_ASSIGN(AtExitManager);
};
} // namespace base
#endif // BASE_AT_EXIT_H_

Просмотреть файл

@ -0,0 +1,85 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/at_exit.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
// Don't test the global AtExitManager, because asking it to process its
// AtExit callbacks can ruin the global state that other tests may depend on.
class ShadowingAtExitManager : public base::AtExitManager {
public:
ShadowingAtExitManager() : AtExitManager(true) {}
};
int g_test_counter_1 = 0;
int g_test_counter_2 = 0;
void IncrementTestCounter1(void* unused) {
++g_test_counter_1;
}
void IncrementTestCounter2(void* unused) {
++g_test_counter_2;
}
void ZeroTestCounters() {
g_test_counter_1 = 0;
g_test_counter_2 = 0;
}
void ExpectCounter1IsZero(void* unused) {
EXPECT_EQ(0, g_test_counter_1);
}
void ExpectParamIsNull(void* param) {
EXPECT_EQ(static_cast<void*>(NULL), param);
}
void ExpectParamIsCounter(void* param) {
EXPECT_EQ(&g_test_counter_1, param);
}
} // namespace
TEST(AtExitTest, Basic) {
ShadowingAtExitManager shadowing_at_exit_manager;
ZeroTestCounters();
base::AtExitManager::RegisterCallback(&IncrementTestCounter1, NULL);
base::AtExitManager::RegisterCallback(&IncrementTestCounter2, NULL);
base::AtExitManager::RegisterCallback(&IncrementTestCounter1, NULL);
EXPECT_EQ(0, g_test_counter_1);
EXPECT_EQ(0, g_test_counter_2);
base::AtExitManager::ProcessCallbacksNow();
EXPECT_EQ(2, g_test_counter_1);
EXPECT_EQ(1, g_test_counter_2);
}
TEST(AtExitTest, LIFOOrder) {
ShadowingAtExitManager shadowing_at_exit_manager;
ZeroTestCounters();
base::AtExitManager::RegisterCallback(&IncrementTestCounter1, NULL);
base::AtExitManager::RegisterCallback(&ExpectCounter1IsZero, NULL);
base::AtExitManager::RegisterCallback(&IncrementTestCounter2, NULL);
EXPECT_EQ(0, g_test_counter_1);
EXPECT_EQ(0, g_test_counter_2);
base::AtExitManager::ProcessCallbacksNow();
EXPECT_EQ(1, g_test_counter_1);
EXPECT_EQ(1, g_test_counter_2);
}
TEST(AtExitTest, Param) {
ShadowingAtExitManager shadowing_at_exit_manager;
base::AtExitManager::RegisterCallback(&ExpectParamIsNull, NULL);
base::AtExitManager::RegisterCallback(&ExpectParamIsCounter,
&g_test_counter_1);
base::AtExitManager::ProcessCallbacksNow();
}

Просмотреть файл

@ -0,0 +1,63 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This is a low level implementation of atomic semantics for reference
// counting. Please use base/ref_counted.h directly instead.
#ifndef BASE_ATOMIC_REF_COUNT_H_
#define BASE_ATOMIC_REF_COUNT_H_
#include "base/atomicops.h"
namespace base {
typedef subtle::Atomic32 AtomicRefCount;
// Increment a reference count by "increment", which must exceed 0.
inline void AtomicRefCountIncN(volatile AtomicRefCount *ptr,
AtomicRefCount increment) {
subtle::NoBarrier_AtomicIncrement(ptr, increment);
}
// Decrement a reference count by "decrement", which must exceed 0,
// and return whether the result is non-zero.
// Insert barriers to ensure that state written before the reference count
// became zero will be visible to a thread that has just made the count zero.
inline bool AtomicRefCountDecN(volatile AtomicRefCount *ptr,
AtomicRefCount decrement) {
return subtle::Barrier_AtomicIncrement(ptr, -decrement) != 0;
}
// Increment a reference count by 1.
inline void AtomicRefCountInc(volatile AtomicRefCount *ptr) {
base::AtomicRefCountIncN(ptr, 1);
}
// Decrement a reference count by 1 and return whether the result is non-zero.
// Insert barriers to ensure that state written before the reference count
// became zero will be visible to a thread that has just made the count zero.
inline bool AtomicRefCountDec(volatile AtomicRefCount *ptr) {
return base::AtomicRefCountDecN(ptr, 1);
}
// Return whether the reference count is one. If the reference count is used
// in the conventional way, a refrerence count of 1 implies that the current
// thread owns the reference and no other thread shares it. This call performs
// the test for a reference count of one, and performs the memory barrier
// needed for the owning thread to act on the object, knowing that it has
// exclusive access to the object.
inline bool AtomicRefCountIsOne(volatile AtomicRefCount *ptr) {
return subtle::Acquire_Load(ptr) == 1;
}
// Return whether the reference count is zero. With conventional object
// referencing counting, the object will be destroyed, so the reference count
// should never be zero. Hence this is generally used for a debug check.
inline bool AtomicRefCountIsZero(volatile AtomicRefCount *ptr) {
return subtle::Acquire_Load(ptr) == 0;
}
} // namespace base
#endif // BASE_ATOMIC_REF_COUNT_H_

Просмотреть файл

@ -0,0 +1,30 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_ATOMIC_SEQUENCE_NUM_H_
#define BASE_ATOMIC_SEQUENCE_NUM_H_
#include "base/atomicops.h"
#include "base/basictypes.h"
namespace base {
class AtomicSequenceNumber {
public:
AtomicSequenceNumber() : seq_(0) { }
explicit AtomicSequenceNumber(base::LinkerInitialized x) { /* seq_ is 0 */ }
int GetNext() {
return static_cast<int>(
base::subtle::NoBarrier_AtomicIncrement(&seq_, 1) - 1);
}
private:
base::subtle::Atomic32 seq_;
DISALLOW_COPY_AND_ASSIGN(AtomicSequenceNumber);
};
} // namespace base
#endif // BASE_ATOMIC_SEQUENCE_NUM_H_

Просмотреть файл

@ -0,0 +1,139 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// For atomic operations on reference counts, see atomic_refcount.h.
// For atomic operations on sequence numbers, see atomic_sequence_num.h.
// The routines exported by this module are subtle. If you use them, even if
// you get the code right, it will depend on careful reasoning about atomicity
// and memory ordering; it will be less readable, and harder to maintain. If
// you plan to use these routines, you should have a good reason, such as solid
// evidence that performance would otherwise suffer, or there being no
// alternative. You should assume only properties explicitly guaranteed by the
// specifications in this file. You are almost certainly _not_ writing code
// just for the x86; if you assume x86 semantics, x86 hardware bugs and
// implementations on other archtectures will cause your code to break. If you
// do not know what you are doing, avoid these routines, and use a Mutex.
//
// It is incorrect to make direct assignments to/from an atomic variable.
// You should use one of the Load or Store routines. The NoBarrier
// versions are provided when no barriers are needed:
// NoBarrier_Store()
// NoBarrier_Load()
// Although there are currently no compiler enforcement, you are encouraged
// to use these.
//
#ifndef BASE_ATOMICOPS_H_
#define BASE_ATOMICOPS_H_
#include "base/basictypes.h"
#include "base/port.h"
namespace base {
namespace subtle {
// Bug 1308991. We need this for /Wp64, to mark it safe for AtomicWord casting.
#ifndef OS_WIN
#define __w64
#endif
typedef __w64 int32 Atomic32;
#ifdef ARCH_CPU_64_BITS
typedef int64 Atomic64;
#endif
// Use AtomicWord for a machine-sized pointer. It will use the Atomic32 or
// Atomic64 routines below, depending on your architecture.
typedef intptr_t AtomicWord;
// Atomically execute:
// result = *ptr;
// if (*ptr == old_value)
// *ptr = new_value;
// return result;
//
// I.e., replace "*ptr" with "new_value" if "*ptr" used to be "old_value".
// Always return the old value of "*ptr"
//
// This routine implies no memory barriers.
Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value);
// Atomically store new_value into *ptr, returning the previous value held in
// *ptr. This routine implies no memory barriers.
Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, Atomic32 new_value);
// Atomically increment *ptr by "increment". Returns the new value of
// *ptr with the increment applied. This routine implies no memory barriers.
Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, Atomic32 increment);
Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
Atomic32 increment);
// These following lower-level operations are typically useful only to people
// implementing higher-level synchronization operations like spinlocks,
// mutexes, and condition-variables. They combine CompareAndSwap(), a load, or
// a store with appropriate memory-ordering instructions. "Acquire" operations
// ensure that no later memory access can be reordered ahead of the operation.
// "Release" operations ensure that no previous memory access can be reordered
// after the operation. "Barrier" operations have both "Acquire" and "Release"
// semantics. A MemoryBarrier() has "Barrier" semantics, but does no memory
// access.
Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value);
Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value);
void MemoryBarrier();
void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value);
void Acquire_Store(volatile Atomic32* ptr, Atomic32 value);
void Release_Store(volatile Atomic32* ptr, Atomic32 value);
Atomic32 NoBarrier_Load(volatile const Atomic32* ptr);
Atomic32 Acquire_Load(volatile const Atomic32* ptr);
Atomic32 Release_Load(volatile const Atomic32* ptr);
// 64-bit atomic operations (only available on 64-bit processors).
#ifdef ARCH_CPU_64_BITS
Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value);
Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr, Atomic64 new_value);
Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment);
Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment);
Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value);
Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value);
void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value);
void Acquire_Store(volatile Atomic64* ptr, Atomic64 value);
void Release_Store(volatile Atomic64* ptr, Atomic64 value);
Atomic64 NoBarrier_Load(volatile const Atomic64* ptr);
Atomic64 Acquire_Load(volatile const Atomic64* ptr);
Atomic64 Release_Load(volatile const Atomic64* ptr);
#endif // CPU_ARCH_64_BITS
} // namespace base::subtle
} // namespace base
// Include our platform specific implementation.
#if defined(OS_WIN) && defined(COMPILER_MSVC) && defined(ARCH_CPU_X86_FAMILY)
#include "base/atomicops_internals_x86_msvc.h"
#elif defined(OS_MACOSX) && defined(ARCH_CPU_X86_FAMILY)
#include "base/atomicops_internals_x86_macosx.h"
#elif defined(COMPILER_GCC) && defined(ARCH_CPU_X86_FAMILY)
#include "base/atomicops_internals_x86_gcc.h"
#elif defined(COMPILER_GCC) && defined(ARCH_CPU_ARM_FAMILY)
#include "base/atomicops_internals_arm_gcc.h"
#else
#error "Atomic operations are not supported on your platform"
#endif
#endif // BASE_ATOMICOPS_H_

Просмотреть файл

@ -0,0 +1,124 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file is an internal atomic implementation, use base/atomicops.h instead.
//
// LinuxKernelCmpxchg and Barrier_AtomicIncrement are from Google Gears.
#ifndef BASE_ATOMICOPS_INTERNALS_ARM_GCC_H_
#define BASE_ATOMICOPS_INTERNALS_ARM_GCC_H_
namespace base {
namespace subtle {
// 0xffff0fc0 is the hard coded address of a function provided by
// the kernel which implements an atomic compare-exchange. On older
// ARM architecture revisions (pre-v6) this may be implemented using
// a syscall. This address is stable, and in active use (hard coded)
// by at least glibc-2.7 and the Android C library.
typedef Atomic32 (*LinuxKernelCmpxchgFunc)(Atomic32 old_value,
Atomic32 new_value,
volatile Atomic32* ptr);
LinuxKernelCmpxchgFunc pLinuxKernelCmpxchg __attribute__((weak)) =
(LinuxKernelCmpxchgFunc) 0xffff0fc0;
typedef void (*LinuxKernelMemoryBarrierFunc)(void);
LinuxKernelMemoryBarrierFunc pLinuxKernelMemoryBarrier __attribute__((weak)) =
(LinuxKernelMemoryBarrierFunc) 0xffff0fa0;
inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
Atomic32 prev_value = *ptr;
do {
if (!pLinuxKernelCmpxchg(old_value, new_value,
const_cast<Atomic32*>(ptr))) {
return old_value;
}
prev_value = *ptr;
} while (prev_value == old_value);
return prev_value;
}
inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr,
Atomic32 new_value) {
Atomic32 old_value;
do {
old_value = *ptr;
} while (pLinuxKernelCmpxchg(old_value, new_value,
const_cast<Atomic32*>(ptr)));
return old_value;
}
inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
Atomic32 increment) {
return Barrier_AtomicIncrement(ptr, increment);
}
inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
Atomic32 increment) {
for (;;) {
// Atomic exchange the old value with an incremented one.
Atomic32 old_value = *ptr;
Atomic32 new_value = old_value + increment;
if (pLinuxKernelCmpxchg(old_value, new_value,
const_cast<Atomic32*>(ptr)) == 0) {
// The exchange took place as expected.
return new_value;
}
// Otherwise, *ptr changed mid-loop and we need to retry.
}
}
inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
}
inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
}
inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
}
inline void MemoryBarrier() {
pLinuxKernelMemoryBarrier();
}
inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
MemoryBarrier();
}
inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
MemoryBarrier();
*ptr = value;
}
inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
return *ptr;
}
inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
Atomic32 value = *ptr;
MemoryBarrier();
return value;
}
inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
MemoryBarrier();
return *ptr;
}
} // namespace base::subtle
} // namespace base
#endif // BASE_ATOMICOPS_INTERNALS_ARM_GCC_H_

Просмотреть файл

@ -0,0 +1,104 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This module gets enough CPU information to optimize the
// atomicops module on x86.
#include <string.h>
#include "base/atomicops.h"
#include "base/basictypes.h"
// This file only makes sense with atomicops_internals_x86_gcc.h -- it
// depends on structs that are defined in that file. If atomicops.h
// doesn't sub-include that file, then we aren't needed, and shouldn't
// try to do anything.
#ifdef BASE_ATOMICOPS_INTERNALS_X86_GCC_H_
// Inline cpuid instruction. In PIC compilations, %ebx contains the address
// of the global offset table. To avoid breaking such executables, this code
// must preserve that register's value across cpuid instructions.
#if defined(__i386__)
#define cpuid(a, b, c, d, inp) \
asm ("mov %%ebx, %%edi\n" \
"cpuid\n" \
"xchg %%edi, %%ebx\n" \
: "=a" (a), "=D" (b), "=c" (c), "=d" (d) : "a" (inp))
#elif defined (__x86_64__)
#define cpuid(a, b, c, d, inp) \
asm ("mov %%rbx, %%rdi\n" \
"cpuid\n" \
"xchg %%rdi, %%rbx\n" \
: "=a" (a), "=D" (b), "=c" (c), "=d" (d) : "a" (inp))
#endif
#if defined(cpuid) // initialize the struct only on x86
// Set the flags so that code will run correctly and conservatively, so even
// if we haven't been initialized yet, we're probably single threaded, and our
// default values should hopefully be pretty safe.
struct AtomicOps_x86CPUFeatureStruct AtomicOps_Internalx86CPUFeatures = {
false, // bug can't exist before process spawns multiple threads
false, // no SSE2
};
// Initialize the AtomicOps_Internalx86CPUFeatures struct.
static void AtomicOps_Internalx86CPUFeaturesInit() {
uint32 eax;
uint32 ebx;
uint32 ecx;
uint32 edx;
// Get vendor string (issue CPUID with eax = 0)
cpuid(eax, ebx, ecx, edx, 0);
char vendor[13];
memcpy(vendor, &ebx, 4);
memcpy(vendor + 4, &edx, 4);
memcpy(vendor + 8, &ecx, 4);
vendor[12] = 0;
// get feature flags in ecx/edx, and family/model in eax
cpuid(eax, ebx, ecx, edx, 1);
int family = (eax >> 8) & 0xf; // family and model fields
int model = (eax >> 4) & 0xf;
if (family == 0xf) { // use extended family and model fields
family += (eax >> 20) & 0xff;
model += ((eax >> 16) & 0xf) << 4;
}
// Opteron Rev E has a bug in which on very rare occasions a locked
// instruction doesn't act as a read-acquire barrier if followed by a
// non-locked read-modify-write instruction. Rev F has this bug in
// pre-release versions, but not in versions released to customers,
// so we test only for Rev E, which is family 15, model 32..63 inclusive.
if (strcmp(vendor, "AuthenticAMD") == 0 && // AMD
family == 15 &&
32 <= model && model <= 63) {
AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug = true;
} else {
AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug = false;
}
// edx bit 26 is SSE2 which we use to tell use whether we can use mfence
AtomicOps_Internalx86CPUFeatures.has_sse2 = ((edx >> 26) & 1);
}
namespace {
class AtomicOpsx86Initializer {
public:
AtomicOpsx86Initializer() {
AtomicOps_Internalx86CPUFeaturesInit();
}
};
// A global to get use initialized on startup via static initialization :/
AtomicOpsx86Initializer g_initer;
} // namespace
#endif // if x86
#endif // ifdef BASE_ATOMICOPS_INTERNALS_X86_GCC_H_

Просмотреть файл

@ -0,0 +1,261 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file is an internal atomic implementation, use base/atomicops.h instead.
#ifndef BASE_ATOMICOPS_INTERNALS_X86_GCC_H_
#define BASE_ATOMICOPS_INTERNALS_X86_GCC_H_
// This struct is not part of the public API of this module; clients may not
// use it.
// Features of this x86. Values may not be correct before main() is run,
// but are set conservatively.
struct AtomicOps_x86CPUFeatureStruct {
bool has_amd_lock_mb_bug; // Processor has AMD memory-barrier bug; do lfence
// after acquire compare-and-swap.
bool has_sse2; // Processor has SSE2.
};
extern struct AtomicOps_x86CPUFeatureStruct AtomicOps_Internalx86CPUFeatures;
#define ATOMICOPS_COMPILER_BARRIER() __asm__ __volatile__("" : : : "memory")
namespace base {
namespace subtle {
// 32-bit low-level operations on any platform.
inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
Atomic32 prev;
__asm__ __volatile__("lock; cmpxchgl %1,%2"
: "=a" (prev)
: "q" (new_value), "m" (*ptr), "0" (old_value)
: "memory");
return prev;
}
inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr,
Atomic32 new_value) {
__asm__ __volatile__("xchgl %1,%0" // The lock prefix is implicit for xchg.
: "=r" (new_value)
: "m" (*ptr), "0" (new_value)
: "memory");
return new_value; // Now it's the previous value.
}
inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
Atomic32 increment) {
Atomic32 temp = increment;
__asm__ __volatile__("lock; xaddl %0,%1"
: "+r" (temp), "+m" (*ptr)
: : "memory");
// temp now holds the old value of *ptr
return temp + increment;
}
inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
Atomic32 increment) {
Atomic32 temp = increment;
__asm__ __volatile__("lock; xaddl %0,%1"
: "+r" (temp), "+m" (*ptr)
: : "memory");
// temp now holds the old value of *ptr
if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
__asm__ __volatile__("lfence" : : : "memory");
}
return temp + increment;
}
inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
Atomic32 x = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
__asm__ __volatile__("lfence" : : : "memory");
}
return x;
}
inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
}
inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
}
#if defined(__x86_64__)
// 64-bit implementations of memory barrier can be simpler, because it
// "mfence" is guaranteed to exist.
inline void MemoryBarrier() {
__asm__ __volatile__("mfence" : : : "memory");
}
inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
MemoryBarrier();
}
#else
inline void MemoryBarrier() {
if (AtomicOps_Internalx86CPUFeatures.has_sse2) {
__asm__ __volatile__("mfence" : : : "memory");
} else { // mfence is faster but not present on PIII
Atomic32 x = 0;
NoBarrier_AtomicExchange(&x, 0); // acts as a barrier on PIII
}
}
inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
if (AtomicOps_Internalx86CPUFeatures.has_sse2) {
*ptr = value;
__asm__ __volatile__("mfence" : : : "memory");
} else {
NoBarrier_AtomicExchange(ptr, value);
// acts as a barrier on PIII
}
}
#endif
inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
ATOMICOPS_COMPILER_BARRIER();
*ptr = value; // An x86 store acts as a release barrier.
// See comments in Atomic64 version of Release_Store(), below.
}
inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
return *ptr;
}
inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
Atomic32 value = *ptr; // An x86 load acts as a acquire barrier.
// See comments in Atomic64 version of Release_Store(), below.
ATOMICOPS_COMPILER_BARRIER();
return value;
}
inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
MemoryBarrier();
return *ptr;
}
#if defined(__x86_64__)
// 64-bit low-level operations on 64-bit platform.
inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
Atomic64 prev;
__asm__ __volatile__("lock; cmpxchgq %1,%2"
: "=a" (prev)
: "q" (new_value), "m" (*ptr), "0" (old_value)
: "memory");
return prev;
}
inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr,
Atomic64 new_value) {
__asm__ __volatile__("xchgq %1,%0" // The lock prefix is implicit for xchg.
: "=r" (new_value)
: "m" (*ptr), "0" (new_value)
: "memory");
return new_value; // Now it's the previous value.
}
inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr,
Atomic64 increment) {
Atomic64 temp = increment;
__asm__ __volatile__("lock; xaddq %0,%1"
: "+r" (temp), "+m" (*ptr)
: : "memory");
// temp now contains the previous value of *ptr
return temp + increment;
}
inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
Atomic64 increment) {
Atomic64 temp = increment;
__asm__ __volatile__("lock; xaddq %0,%1"
: "+r" (temp), "+m" (*ptr)
: : "memory");
// temp now contains the previous value of *ptr
if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
__asm__ __volatile__("lfence" : : : "memory");
}
return temp + increment;
}
inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
*ptr = value;
}
#if defined(CHROMIUM_MOZILLA_BUILD)
inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
Atomic64 x = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
/* XXX/cjones: no idea if this is necessary... */
if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
__asm__ __volatile__("lfence" : : : "memory");
}
return x;
}
#endif
inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) {
*ptr = value;
MemoryBarrier();
}
inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
ATOMICOPS_COMPILER_BARRIER();
*ptr = value; // An x86 store acts as a release barrier
// for current AMD/Intel chips as of Jan 2008.
// See also Acquire_Load(), below.
// When new chips come out, check:
// IA-32 Intel Architecture Software Developer's Manual, Volume 3:
// System Programming Guide, Chatper 7: Multiple-processor management,
// Section 7.2, Memory Ordering.
// Last seen at:
// http://developer.intel.com/design/pentium4/manuals/index_new.htm
//
// x86 stores/loads fail to act as barriers for a few instructions (clflush
// maskmovdqu maskmovq movntdq movnti movntpd movntps movntq) but these are
// not generated by the compiler, and are rare. Users of these instructions
// need to know about cache behaviour in any case since all of these involve
// either flushing cache lines or non-temporal cache hints.
}
inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
return *ptr;
}
inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
Atomic64 value = *ptr; // An x86 load acts as a acquire barrier,
// for current AMD/Intel chips as of Jan 2008.
// See also Release_Store(), above.
ATOMICOPS_COMPILER_BARRIER();
return value;
}
inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
MemoryBarrier();
return *ptr;
}
#endif // defined(__x86_64__)
} // namespace base::subtle
} // namespace base
#undef ATOMICOPS_COMPILER_BARRIER
#endif // BASE_ATOMICOPS_INTERNALS_X86_GCC_H_

Просмотреть файл

@ -0,0 +1,279 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file is an internal atomic implementation, use base/atomicops.h instead.
#ifndef BASE_ATOMICOPS_INTERNALS_X86_MACOSX_H_
#define BASE_ATOMICOPS_INTERNALS_X86_MACOSX_H_
#include <libkern/OSAtomic.h>
namespace base {
namespace subtle {
inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32 *ptr,
Atomic32 old_value,
Atomic32 new_value) {
Atomic32 prev_value;
do {
if (OSAtomicCompareAndSwap32(old_value, new_value,
const_cast<Atomic32*>(ptr))) {
return old_value;
}
prev_value = *ptr;
} while (prev_value == old_value);
return prev_value;
}
inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32 *ptr,
Atomic32 new_value) {
Atomic32 old_value;
do {
old_value = *ptr;
} while (!OSAtomicCompareAndSwap32(old_value, new_value,
const_cast<Atomic32*>(ptr)));
return old_value;
}
inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32 *ptr,
Atomic32 increment) {
return OSAtomicAdd32(increment, const_cast<Atomic32*>(ptr));
}
inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32 *ptr,
Atomic32 increment) {
return OSAtomicAdd32Barrier(increment, const_cast<Atomic32*>(ptr));
}
inline void MemoryBarrier() {
OSMemoryBarrier();
}
inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32 *ptr,
Atomic32 old_value,
Atomic32 new_value) {
Atomic32 prev_value;
do {
if (OSAtomicCompareAndSwap32Barrier(old_value, new_value,
const_cast<Atomic32*>(ptr))) {
return old_value;
}
prev_value = *ptr;
} while (prev_value == old_value);
return prev_value;
}
inline Atomic32 Release_CompareAndSwap(volatile Atomic32 *ptr,
Atomic32 old_value,
Atomic32 new_value) {
return Acquire_CompareAndSwap(ptr, old_value, new_value);
}
inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
}
inline void Acquire_Store(volatile Atomic32 *ptr, Atomic32 value) {
*ptr = value;
MemoryBarrier();
}
inline void Release_Store(volatile Atomic32 *ptr, Atomic32 value) {
MemoryBarrier();
*ptr = value;
}
inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
return *ptr;
}
inline Atomic32 Acquire_Load(volatile const Atomic32 *ptr) {
Atomic32 value = *ptr;
MemoryBarrier();
return value;
}
inline Atomic32 Release_Load(volatile const Atomic32 *ptr) {
MemoryBarrier();
return *ptr;
}
#ifdef __LP64__
// 64-bit implementation on 64-bit platform
inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64 *ptr,
Atomic64 old_value,
Atomic64 new_value) {
Atomic64 prev_value;
do {
if (OSAtomicCompareAndSwap64(old_value, new_value,
const_cast<Atomic64*>(ptr))) {
return old_value;
}
prev_value = *ptr;
} while (prev_value == old_value);
return prev_value;
}
inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64 *ptr,
Atomic64 new_value) {
Atomic64 old_value;
do {
old_value = *ptr;
} while (!OSAtomicCompareAndSwap64(old_value, new_value,
const_cast<Atomic64*>(ptr)));
return old_value;
}
inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64 *ptr,
Atomic64 increment) {
return OSAtomicAdd64(increment, const_cast<Atomic64*>(ptr));
}
inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64 *ptr,
Atomic64 increment) {
return OSAtomicAdd64Barrier(increment, const_cast<Atomic64*>(ptr));
}
inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64 *ptr,
Atomic64 old_value,
Atomic64 new_value) {
Atomic64 prev_value;
do {
if (OSAtomicCompareAndSwap64Barrier(old_value, new_value,
const_cast<Atomic64*>(ptr))) {
return old_value;
}
prev_value = *ptr;
} while (prev_value == old_value);
return prev_value;
}
inline Atomic64 Release_CompareAndSwap(volatile Atomic64 *ptr,
Atomic64 old_value,
Atomic64 new_value) {
// The lib kern interface does not distinguish between
// Acquire and Release memory barriers; they are equivalent.
return Acquire_CompareAndSwap(ptr, old_value, new_value);
}
inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
*ptr = value;
}
inline void Acquire_Store(volatile Atomic64 *ptr, Atomic64 value) {
*ptr = value;
MemoryBarrier();
}
inline void Release_Store(volatile Atomic64 *ptr, Atomic64 value) {
MemoryBarrier();
*ptr = value;
}
inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
return *ptr;
}
inline Atomic64 Acquire_Load(volatile const Atomic64 *ptr) {
Atomic64 value = *ptr;
MemoryBarrier();
return value;
}
inline Atomic64 Release_Load(volatile const Atomic64 *ptr) {
MemoryBarrier();
return *ptr;
}
#endif // defined(__LP64__)
// MacOS uses long for intptr_t, AtomicWord and Atomic32 are always different
// on the Mac, even when they are the same size. We need to explicitly cast
// from AtomicWord to Atomic32/64 to implement the AtomicWord interface.
#ifdef __LP64__
#define AtomicWordCastType Atomic64
#else
#define AtomicWordCastType Atomic32
#endif
inline AtomicWord NoBarrier_CompareAndSwap(volatile AtomicWord* ptr,
AtomicWord old_value,
AtomicWord new_value) {
return NoBarrier_CompareAndSwap(
reinterpret_cast<volatile AtomicWordCastType*>(ptr),
old_value, new_value);
}
inline AtomicWord NoBarrier_AtomicExchange(volatile AtomicWord* ptr,
AtomicWord new_value) {
return NoBarrier_AtomicExchange(
reinterpret_cast<volatile AtomicWordCastType*>(ptr), new_value);
}
inline AtomicWord NoBarrier_AtomicIncrement(volatile AtomicWord* ptr,
AtomicWord increment) {
return NoBarrier_AtomicIncrement(
reinterpret_cast<volatile AtomicWordCastType*>(ptr), increment);
}
inline AtomicWord Barrier_AtomicIncrement(volatile AtomicWord* ptr,
AtomicWord increment) {
return Barrier_AtomicIncrement(
reinterpret_cast<volatile AtomicWordCastType*>(ptr), increment);
}
inline AtomicWord Acquire_CompareAndSwap(volatile AtomicWord* ptr,
AtomicWord old_value,
AtomicWord new_value) {
return base::subtle::Acquire_CompareAndSwap(
reinterpret_cast<volatile AtomicWordCastType*>(ptr),
old_value, new_value);
}
inline AtomicWord Release_CompareAndSwap(volatile AtomicWord* ptr,
AtomicWord old_value,
AtomicWord new_value) {
return base::subtle::Release_CompareAndSwap(
reinterpret_cast<volatile AtomicWordCastType*>(ptr),
old_value, new_value);
}
inline void NoBarrier_Store(volatile AtomicWord *ptr, AtomicWord value) {
NoBarrier_Store(
reinterpret_cast<volatile AtomicWordCastType*>(ptr), value);
}
inline void Acquire_Store(volatile AtomicWord* ptr, AtomicWord value) {
return base::subtle::Acquire_Store(
reinterpret_cast<volatile AtomicWordCastType*>(ptr), value);
}
inline void Release_Store(volatile AtomicWord* ptr, AtomicWord value) {
return base::subtle::Release_Store(
reinterpret_cast<volatile AtomicWordCastType*>(ptr), value);
}
inline AtomicWord NoBarrier_Load(volatile const AtomicWord *ptr) {
return NoBarrier_Load(
reinterpret_cast<volatile const AtomicWordCastType*>(ptr));
}
inline AtomicWord Acquire_Load(volatile const AtomicWord* ptr) {
return base::subtle::Acquire_Load(
reinterpret_cast<volatile const AtomicWordCastType*>(ptr));
}
inline AtomicWord Release_Load(volatile const AtomicWord* ptr) {
return base::subtle::Release_Load(
reinterpret_cast<volatile const AtomicWordCastType*>(ptr));
}
#undef AtomicWordCastType
} // namespace base::subtle
} // namespace base
#endif // BASE_ATOMICOPS_INTERNALS_X86_MACOSX_H_

Просмотреть файл

@ -0,0 +1,167 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file is an internal atomic implementation, use base/atomicops.h instead.
#ifndef BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_
#define BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_
#include <windows.h>
namespace base {
namespace subtle {
inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
LONG result = InterlockedCompareExchange(
reinterpret_cast<volatile LONG*>(ptr),
static_cast<LONG>(new_value),
static_cast<LONG>(old_value));
return static_cast<Atomic32>(result);
}
inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr,
Atomic32 new_value) {
LONG result = InterlockedExchange(
reinterpret_cast<volatile LONG*>(ptr),
static_cast<LONG>(new_value));
return static_cast<Atomic32>(result);
}
inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
Atomic32 increment) {
return InterlockedExchangeAdd(
reinterpret_cast<volatile LONG*>(ptr),
static_cast<LONG>(increment)) + increment;
}
inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
Atomic32 increment) {
return Barrier_AtomicIncrement(ptr, increment);
}
#if !(defined(_MSC_VER) && _MSC_VER >= 1400)
#error "We require at least vs2005 for MemoryBarrier"
#endif
inline void MemoryBarrier() {
// We use MemoryBarrier from WinNT.h
::MemoryBarrier();
}
inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
}
inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
}
inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
}
inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
NoBarrier_AtomicExchange(ptr, value);
// acts as a barrier in this implementation
}
inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value; // works w/o barrier for current Intel chips as of June 2005
// See comments in Atomic64 version of Release_Store() below.
}
inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
return *ptr;
}
inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
Atomic32 value = *ptr;
return value;
}
inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
MemoryBarrier();
return *ptr;
}
#if defined(_WIN64)
// 64-bit low-level operations on 64-bit platform.
COMPILE_ASSERT(sizeof(Atomic64) == sizeof(PVOID), atomic_word_is_atomic);
inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
PVOID result = InterlockedCompareExchangePointer(
reinterpret_cast<volatile PVOID*>(ptr),
reinterpret_cast<PVOID>(new_value), reinterpret_cast<PVOID>(old_value));
return reinterpret_cast<Atomic64>(result);
}
inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr,
Atomic64 new_value) {
PVOID result = InterlockedExchangePointer(
reinterpret_cast<volatile PVOID*>(ptr),
reinterpret_cast<PVOID>(new_value));
return reinterpret_cast<Atomic64>(result);
}
inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
Atomic64 increment) {
return InterlockedExchangeAdd64(
reinterpret_cast<volatile LONGLONG*>(ptr),
static_cast<LONGLONG>(increment)) + increment;
}
inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr,
Atomic64 increment) {
return Barrier_AtomicIncrement(ptr, increment);
}
inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
*ptr = value;
}
inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) {
NoBarrier_AtomicExchange(ptr, value);
// acts as a barrier in this implementation
}
inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
*ptr = value; // works w/o barrier for current Intel chips as of June 2005
// When new chips come out, check:
// IA-32 Intel Architecture Software Developer's Manual, Volume 3:
// System Programming Guide, Chatper 7: Multiple-processor management,
// Section 7.2, Memory Ordering.
// Last seen at:
// http://developer.intel.com/design/pentium4/manuals/index_new.htm
}
inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
return *ptr;
}
inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
Atomic64 value = *ptr;
return value;
}
inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
MemoryBarrier();
return *ptr;
}
#endif // defined(_WIN64)
} // namespace base::subtle
} // namespace base
#endif // BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше