<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: registerservices.cxx,v $
 *
 *  $Revision: 1.33 $
 *
 *  last change: $Author: hr $ $Date: 2006-01-24 15:12:33 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
//_________________________________________________________________________________________________________________
//  includes of my own project
//_________________________________________________________________________________________________________________

#ifndef __FRAMEWORK_MACROS_REGISTRATION_HXX_
#include <macros/registration.hxx>
#endif

/*=================================================================================================================
    Add new include and new register info to for new services.

    Example:

        #ifndef __YOUR_SERVICE_1_HXX_
        #include <service1.hxx>
        #endif

        #ifndef __YOUR_SERVICE_2_HXX_
        #include <service2.hxx>
        #endif

        COMPONENTGETIMPLEMENTATIONENVIRONMENT

        COMPONENTWRITEINFO  (   COMPONENTINFO( Service1 )
                                 COMPONENTINFO( Service2 )
                            )

        COMPONENTGETFACTORY (   IFFACTORIE( Service1 )
                                 else
                                IFFACTORIE( Service2 )
                             )
=================================================================================================================*/

#ifndef __FRAMEWORK_SERVICES_URLTRANSFORMER_HXX_
#include <services/urltransformer.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_DESKTOP_HXX_
#include <services/desktop.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_DOCUMENTPROPERTIES_HXX_
#include <services/documentproperties.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_FRAME_HXX_
#include <services/frame.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_MODULEMANAGER_HXX_
#include <services/modulemanager.hxx>
#endif

#ifndef __FRAMEWORK_JOBS_JOBEXECUTOR_HXX_
#include <jobs/jobexecutor.hxx>
#endif

#ifndef __FRAMEWORK_DISPATCH_SOUNDHANDLER_HXX_
#include <dispatch/soundhandler.hxx>
#endif

#ifndef __FRAMEWORK_RECORDING_DISPATCHRECORDERSUPPLIER_HXX_
#include <recording/dispatchrecordersupplier.hxx>
#endif

#ifndef __FRAMEWORK_RECORDING_DISPATCHRECORDER_HXX_
#include <recording/dispatchrecorder.hxx>
#endif

#ifndef __FRAMEWORK_DISPATCH_MAILTODISPATCHER_HXX_
#include <dispatch/mailtodispatcher.hxx>
#endif

#ifndef __FRAMEWORK_DISPATCH_SERVICEHANDLER_HXX_
#include <dispatch/servicehandler.hxx>
#endif

#ifndef __FRAMEWORK_JOBS_JOBDISPATCH_HXX_
#include <jobs/jobdispatch.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_BACKINGCOMP_HXX_
#include <services/backingcomp.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_DISPATCHHELPER_HXX_
#include <services/dispatchhelper.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_LAYOUTMANAGER_HXX_
#include <services/layoutmanager.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_LICENSE_HXX_
#include <services/license.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_UIELEMENTFACTORYMANAGER_HXX_
#include <uifactory/uielementfactorymanager.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_POPUPMENUCONTROLLERFACTORY_HXX_
#include <uifactory/popupmenucontrollerfactory.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_FONTMENUCONTROLLER_HXX_
#include <uielement/fontmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_FONTSIZEMENUCONTROLLER_HXX_
#include <uielement/fontsizemenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_OBJECTMENUCONTROLLER_HXX_
#include <uielement/objectmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_HEADERMENUCONTROLLER_HXX_
#include <uielement/headermenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_FOOTERMENUCONTROLLER_HXX_
#include <uielement/footermenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_CONTROLMENUCONTROLLER_HXX_
#include <uielement/controlmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_MACROSMENUCONTROLLER_HXX_
#include <uielement/macrosmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_UICOMMANDDESCRIPTION_HXX_
#include <uielement/uicommanddescription.hxx>
#endif

#ifndef __FRAMEWORK_UICONFIGURATION_UICONFIGMANAGER_HXX_
#include <uiconfiguration/uiconfigurationmanager.hxx>
#endif

#ifndef __FRAMEWORK_UICONFIGURATION_MODULEUICFGSUPPLIER_HXX_
#include <uiconfiguration/moduleuicfgsupplier.hxx>
#endif

#ifndef __FRAMEWORK_UICONFIGURATION_MODULEUICONFIGMANAGER_HXX_
#include <uiconfiguration/moduleuiconfigurationmanager.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_MENUBARFACTORY_HXX_
#include <uifactory/menubarfactory.hxx>
#endif

#ifndef __FRAMEWORK_ACCELERATORS_GLOBALACCELERATORCONFIGURATION_HXX_
#include <accelerators/globalacceleratorconfiguration.hxx>
#endif

#ifndef __FRAMEWORK_ACCELERATORS_MODULEACCELERATORCONFIGURATION_HXX_
#include <accelerators/moduleacceleratorconfiguration.hxx>
#endif

#ifndef __FRAMEWORK_ACCELERATORS_DOCUMENTACCELERATORCONFIGURATION_HXX_
#include <accelerators/documentacceleratorconfiguration.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_TOOLBOXFACTORY_HXX_
#include <uifactory/toolboxfactory.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_ADDONSTOOLBOXFACTORY_HXX_
#include <uifactory/addonstoolboxfactory.hxx>
#endif

#ifndef __FRAMEWORK_UICONFIGURATION_WINDOWSTATECONFIGURATION_HXX_
#include "uiconfiguration/windowstateconfiguration.hxx"
#endif

#ifndef __FRAMEWORK_UIELEMENT_TOOLBARSMENUCONTROLLER_HXX_
#include <uielement/toolbarsmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_TOOLBARCONTROLLERFACTORY_HXX_
#include "uifactory/toolbarcontrollerfactory.hxx"
#endif

#ifndef __FRAMEWORK_UIFACTORY_STATUSBARCONTROLLERFACTORY_HXX_
#include "uifactory/statusbarcontrollerfactory.hxx"
#endif

#ifndef __FRAMEWORK_UIELEMENT_TOOLBARSMENUCONTROLLER_HXX_
#include <uielement/toolbarsmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_AUTORECOVERY_HXX_
#include <services/autorecovery.hxx>
#endif

#ifndef __FRAMEWORK_HELPER_STATUSINDICATORFACTORY_HXX_
#include <helper/statusindicatorfactory.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_RECENTFILESMENUCONTROLLER_HXX_
#include <uielement/recentfilesmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_STATUSBARFACTORY_HXX_
#include <uifactory/statusbarfactory.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_UICATEGORYDESCRPTION_HXX_
#include <uiconfiguration/uicategorydescription.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_SESSIONLISTENER_HXX_
#include <services/sessionlistener.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_LOGOIMAGESTATUSBARCONTROLLER_HXX_
#include <uielement/logoimagestatusbarcontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_LOGOTEXTSTATUSBARCONTROLLER_HXX_
#include <uielement/logotextstatusbarcontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_NEWMENUCONTROLLER_HXX_
#include <uielement/newmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_SIMPLETEXTSTATUSBARCONTROLLER_HXX_
#include <uielement/simpletextstatusbarcontroller.hxx>
#endif

COMPONENTGETIMPLEMENTATIONENVIRONMENT

COMPONENTWRITEINFO  (   COMPONENTINFO( ::framework::URLTransformer                          )
                        COMPONENTINFO( ::framework::Desktop                                 )
                        COMPONENTINFO( ::framework::Frame                                   )
                        COMPONENTINFO( ::framework::DocumentProperties                      )
                        COMPONENTINFO( ::framework::SoundHandler                            )
                        COMPONENTINFO( ::framework::JobExecutor                             )
                        COMPONENTINFO( ::framework::DispatchRecorderSupplier                )
                        COMPONENTINFO( ::framework::DispatchRecorder                        )
                        COMPONENTINFO( ::framework::MailToDispatcher                        )
                        COMPONENTINFO( ::framework::ServiceHandler                          )
                        COMPONENTINFO( ::framework::JobDispatch                             )
                        COMPONENTINFO( ::framework::BackingComp                             )
                        COMPONENTINFO( ::framework::DispatchHelper                          )
                        COMPONENTINFO( ::framework::LayoutManager                           )
                        COMPONENTINFO( ::framework::License                                 )
                        COMPONENTINFO( ::framework::UIElementFactoryManager                 )
                        COMPONENTINFO( ::framework::PopupMenuControllerFactory              )
                        COMPONENTINFO( ::framework::FontMenuController                      )
                        COMPONENTINFO( ::framework::FontSizeMenuController                  )
                        COMPONENTINFO( ::framework::ObjectMenuController                    )
                        COMPONENTINFO( ::framework::HeaderMenuController                    )
                        COMPONENTINFO( ::framework::FooterMenuController                    )
                        COMPONENTINFO( ::framework::ControlMenuController                   )
                        COMPONENTINFO( ::framework::MacrosMenuController                    )
                        COMPONENTINFO( ::framework::UICommandDescription                    )
                        COMPONENTINFO( ::framework::ModuleManager                           )
                        COMPONENTINFO( ::framework::UIConfigurationManager                  )
                        COMPONENTINFO( ::framework::ModuleUIConfigurationManagerSupplier    )
                        COMPONENTINFO( ::framework::ModuleUIConfigurationManager            )
                        COMPONENTINFO( ::framework::MenuBarFactory                          )
                        COMPONENTINFO( ::framework::GlobalAcceleratorConfiguration          )
                        COMPONENTINFO( ::framework::ModuleAcceleratorConfiguration          )
                        COMPONENTINFO( ::framework::DocumentAcceleratorConfiguration        )
                        COMPONENTINFO( ::framework::ToolBoxFactory                          )
                        COMPONENTINFO( ::framework::AddonsToolBoxFactory                    )
                        COMPONENTINFO( ::framework::WindowStateConfiguration                )
                        COMPONENTINFO( ::framework::ToolbarControllerFactory                )
                        COMPONENTINFO( ::framework::ToolbarsMenuController                  )
                        COMPONENTINFO( ::framework::AutoRecovery                            )
                        COMPONENTINFO( ::framework::StatusIndicatorFactory                  )
                        COMPONENTINFO( ::framework::RecentFilesMenuController               )
                        COMPONENTINFO( ::framework::StatusBarFactory                        )
                        COMPONENTINFO( ::framework::UICategoryDescription                   )
                        COMPONENTINFO( ::framework::StatusbarControllerFactory              )
                        COMPONENTINFO( ::framework::SessionListener                         )
                        COMPONENTINFO( ::framework::LogoImageStatusbarController            )
                        COMPONENTINFO( ::framework::LogoTextStatusbarController             )
                        COMPONENTINFO( ::framework::NewMenuController                       )
                        COMPONENTINFO( ::framework::SimpleTextStatusbarController           )
                    )

COMPONENTGETFACTORY (   IFFACTORY( ::framework::URLTransformer                          )   else
                        IFFACTORY( ::framework::Desktop                                 )   else
                        IFFACTORY( ::framework::Frame                                   )   else
                        IFFACTORY( ::framework::DocumentProperties                      )   else
                        IFFACTORY( ::framework::SoundHandler                            )   else
                        IFFACTORY( ::framework::JobExecutor                             )   else
                        IFFACTORY( ::framework::DispatchRecorderSupplier                )   else
                        IFFACTORY( ::framework::DispatchRecorder                        )   else
                        IFFACTORY( ::framework::MailToDispatcher                        )   else
                        IFFACTORY( ::framework::ServiceHandler                          )   else
                        IFFACTORY( ::framework::JobDispatch                             )   else
                        IFFACTORY( ::framework::BackingComp                             )   else
                        IFFACTORY( ::framework::DispatchHelper                          )   else
                        IFFACTORY( ::framework::LayoutManager                           )   else
                        IFFACTORY( ::framework::License                                 )   else
                        IFFACTORY( ::framework::UIElementFactoryManager                 )   else
                        IFFACTORY( ::framework::PopupMenuControllerFactory              )   else
                        IFFACTORY( ::framework::FontMenuController                      )   else
                        IFFACTORY( ::framework::FontSizeMenuController                  )   else
                        IFFACTORY( ::framework::ObjectMenuController                    )   else
                        IFFACTORY( ::framework::HeaderMenuController                    )   else
                        IFFACTORY( ::framework::FooterMenuController                    )   else
                        IFFACTORY( ::framework::ControlMenuController                   )   else
                        IFFACTORY( ::framework::MacrosMenuController                    )   else
                        IFFACTORY( ::framework::UICommandDescription                    )   else
                        IFFACTORY( ::framework::ModuleManager                           )   else
                        IFFACTORY( ::framework::UIConfigurationManager                  )   else
                        IFFACTORY( ::framework::ModuleUIConfigurationManagerSupplier    )   else
                        IFFACTORY( ::framework::ModuleUIConfigurationManager            )   else
                        IFFACTORY( ::framework::MenuBarFactory                          )   else
                        IFFACTORY( ::framework::GlobalAcceleratorConfiguration          )   else
                        IFFACTORY( ::framework::ModuleAcceleratorConfiguration          )   else
                        IFFACTORY( ::framework::DocumentAcceleratorConfiguration        )   else
                        IFFACTORY( ::framework::ToolBoxFactory                          )   else
                        IFFACTORY( ::framework::AddonsToolBoxFactory                    )   else
                        IFFACTORY( ::framework::WindowStateConfiguration                )   else
                        IFFACTORY( ::framework::ToolbarControllerFactory                )   else
                        IFFACTORY( ::framework::ToolbarsMenuController                  )   else
                        IFFACTORY( ::framework::AutoRecovery                            )   else
                        IFFACTORY( ::framework::StatusIndicatorFactory                  )   else
                        IFFACTORY( ::framework::RecentFilesMenuController               )   else
                        IFFACTORY( ::framework::StatusBarFactory                        )   else
                        IFFACTORY( ::framework::UICategoryDescription                   )   else
                        IFFACTORY( ::framework::SessionListener                         )   else
                        IFFACTORY( ::framework::StatusbarControllerFactory              )   else
                        IFFACTORY( ::framework::SessionListener                         )   else
                        IFFACTORY( ::framework::LogoImageStatusbarController            )   else
                        IFFACTORY( ::framework::LogoTextStatusbarController             )   else
                        IFFACTORY( ::framework::NewMenuController                       )   else
                        IFFACTORY( ::framework::SimpleTextStatusbarController           )
            )

<commit_msg>INTEGRATION: CWS gsoc (1.32.6); FILE MERGED 2006/02/07 10:14:08 as 1.32.6.2: RESYNC: (1.32-1.33); FILE MERGED resolve merge conflicts 2005/09/20 10:22:31 as 1.32.6.1: #i54847# first revision of 'TabBrowse' feature<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: registerservices.cxx,v $
 *
 *  $Revision: 1.34 $
 *
 *  last change: $Author: vg $ $Date: 2006-09-08 08:32:57 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
//_________________________________________________________________________________________________________________
//  includes of my own project
//_________________________________________________________________________________________________________________

#ifndef __FRAMEWORK_MACROS_REGISTRATION_HXX_
#include <macros/registration.hxx>
#endif

/*=================================================================================================================
    Add new include and new register info to for new services.

    Example:

        #ifndef __YOUR_SERVICE_1_HXX_
        #include <service1.hxx>
        #endif

        #ifndef __YOUR_SERVICE_2_HXX_
        #include <service2.hxx>
        #endif

        COMPONENTGETIMPLEMENTATIONENVIRONMENT

        COMPONENTWRITEINFO  (   COMPONENTINFO( Service1 )
                                 COMPONENTINFO( Service2 )
                            )

        COMPONENTGETFACTORY (   IFFACTORIE( Service1 )
                                 else
                                IFFACTORIE( Service2 )
                             )
=================================================================================================================*/

#ifndef __FRAMEWORK_SERVICES_URLTRANSFORMER_HXX_
#include <services/urltransformer.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_DESKTOP_HXX_
#include <services/desktop.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_DOCUMENTPROPERTIES_HXX_
#include <services/documentproperties.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_FRAME_HXX_
#include <services/frame.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_MODULEMANAGER_HXX_
#include <services/modulemanager.hxx>
#endif

#ifndef __FRAMEWORK_JOBS_JOBEXECUTOR_HXX_
#include <jobs/jobexecutor.hxx>
#endif

#ifndef __FRAMEWORK_DISPATCH_SOUNDHANDLER_HXX_
#include <dispatch/soundhandler.hxx>
#endif

#ifndef __FRAMEWORK_RECORDING_DISPATCHRECORDERSUPPLIER_HXX_
#include <recording/dispatchrecordersupplier.hxx>
#endif

#ifndef __FRAMEWORK_RECORDING_DISPATCHRECORDER_HXX_
#include <recording/dispatchrecorder.hxx>
#endif

#ifndef __FRAMEWORK_DISPATCH_MAILTODISPATCHER_HXX_
#include <dispatch/mailtodispatcher.hxx>
#endif

#ifndef __FRAMEWORK_DISPATCH_SERVICEHANDLER_HXX_
#include <dispatch/servicehandler.hxx>
#endif

#ifndef __FRAMEWORK_JOBS_JOBDISPATCH_HXX_
#include <jobs/jobdispatch.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_BACKINGCOMP_HXX_
#include <services/backingcomp.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_DISPATCHHELPER_HXX_
#include <services/dispatchhelper.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_LAYOUTMANAGER_HXX_
#include <services/layoutmanager.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_LICENSE_HXX_
#include <services/license.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_UIELEMENTFACTORYMANAGER_HXX_
#include <uifactory/uielementfactorymanager.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_POPUPMENUCONTROLLERFACTORY_HXX_
#include <uifactory/popupmenucontrollerfactory.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_FONTMENUCONTROLLER_HXX_
#include <uielement/fontmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_FONTSIZEMENUCONTROLLER_HXX_
#include <uielement/fontsizemenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_OBJECTMENUCONTROLLER_HXX_
#include <uielement/objectmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_HEADERMENUCONTROLLER_HXX_
#include <uielement/headermenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_FOOTERMENUCONTROLLER_HXX_
#include <uielement/footermenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_CONTROLMENUCONTROLLER_HXX_
#include <uielement/controlmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_MACROSMENUCONTROLLER_HXX_
#include <uielement/macrosmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_UICOMMANDDESCRIPTION_HXX_
#include <uielement/uicommanddescription.hxx>
#endif

#ifndef __FRAMEWORK_UICONFIGURATION_UICONFIGMANAGER_HXX_
#include <uiconfiguration/uiconfigurationmanager.hxx>
#endif

#ifndef __FRAMEWORK_UICONFIGURATION_MODULEUICFGSUPPLIER_HXX_
#include <uiconfiguration/moduleuicfgsupplier.hxx>
#endif

#ifndef __FRAMEWORK_UICONFIGURATION_MODULEUICONFIGMANAGER_HXX_
#include <uiconfiguration/moduleuiconfigurationmanager.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_MENUBARFACTORY_HXX_
#include <uifactory/menubarfactory.hxx>
#endif

#ifndef __FRAMEWORK_ACCELERATORS_GLOBALACCELERATORCONFIGURATION_HXX_
#include <accelerators/globalacceleratorconfiguration.hxx>
#endif

#ifndef __FRAMEWORK_ACCELERATORS_MODULEACCELERATORCONFIGURATION_HXX_
#include <accelerators/moduleacceleratorconfiguration.hxx>
#endif

#ifndef __FRAMEWORK_ACCELERATORS_DOCUMENTACCELERATORCONFIGURATION_HXX_
#include <accelerators/documentacceleratorconfiguration.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_TOOLBOXFACTORY_HXX_
#include <uifactory/toolboxfactory.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_ADDONSTOOLBOXFACTORY_HXX_
#include <uifactory/addonstoolboxfactory.hxx>
#endif

#ifndef __FRAMEWORK_UICONFIGURATION_WINDOWSTATECONFIGURATION_HXX_
#include "uiconfiguration/windowstateconfiguration.hxx"
#endif

#ifndef __FRAMEWORK_UIELEMENT_TOOLBARSMENUCONTROLLER_HXX_
#include <uielement/toolbarsmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_TOOLBARCONTROLLERFACTORY_HXX_
#include "uifactory/toolbarcontrollerfactory.hxx"
#endif

#ifndef __FRAMEWORK_UIFACTORY_STATUSBARCONTROLLERFACTORY_HXX_
#include "uifactory/statusbarcontrollerfactory.hxx"
#endif

#ifndef __FRAMEWORK_UIELEMENT_TOOLBARSMENUCONTROLLER_HXX_
#include <uielement/toolbarsmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_AUTORECOVERY_HXX_
#include <services/autorecovery.hxx>
#endif

#ifndef __FRAMEWORK_HELPER_STATUSINDICATORFACTORY_HXX_
#include <helper/statusindicatorfactory.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_RECENTFILESMENUCONTROLLER_HXX_
#include <uielement/recentfilesmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_STATUSBARFACTORY_HXX_
#include <uifactory/statusbarfactory.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_UICATEGORYDESCRPTION_HXX_
#include <uiconfiguration/uicategorydescription.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_SESSIONLISTENER_HXX_
#include <services/sessionlistener.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_LOGOIMAGESTATUSBARCONTROLLER_HXX_
#include <uielement/logoimagestatusbarcontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_LOGOTEXTSTATUSBARCONTROLLER_HXX_
#include <uielement/logotextstatusbarcontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_NEWMENUCONTROLLER_HXX_
#include <uielement/newmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_TASKCREATORSRV_HXX_
#include <services/taskcreatorsrv.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_SIMPLETEXTSTATUSBARCONTROLLER_HXX_
#include <uielement/simpletextstatusbarcontroller.hxx>
#endif

COMPONENTGETIMPLEMENTATIONENVIRONMENT

COMPONENTWRITEINFO  (   COMPONENTINFO( ::framework::URLTransformer                          )
                        COMPONENTINFO( ::framework::Desktop                                 )
                        COMPONENTINFO( ::framework::Frame                                   )
                        COMPONENTINFO( ::framework::DocumentProperties                      )
                        COMPONENTINFO( ::framework::SoundHandler                            )
                        COMPONENTINFO( ::framework::JobExecutor                             )
                        COMPONENTINFO( ::framework::DispatchRecorderSupplier                )
                        COMPONENTINFO( ::framework::DispatchRecorder                        )
                        COMPONENTINFO( ::framework::MailToDispatcher                        )
                        COMPONENTINFO( ::framework::ServiceHandler                          )
                        COMPONENTINFO( ::framework::JobDispatch                             )
                        COMPONENTINFO( ::framework::BackingComp                             )
                        COMPONENTINFO( ::framework::DispatchHelper                          )
                        COMPONENTINFO( ::framework::LayoutManager                           )
                        COMPONENTINFO( ::framework::License                                 )
                        COMPONENTINFO( ::framework::UIElementFactoryManager                 )
                        COMPONENTINFO( ::framework::PopupMenuControllerFactory              )
                        COMPONENTINFO( ::framework::FontMenuController                      )
                        COMPONENTINFO( ::framework::FontSizeMenuController                  )
                        COMPONENTINFO( ::framework::ObjectMenuController                    )
                        COMPONENTINFO( ::framework::HeaderMenuController                    )
                        COMPONENTINFO( ::framework::FooterMenuController                    )
                        COMPONENTINFO( ::framework::ControlMenuController                   )
                        COMPONENTINFO( ::framework::MacrosMenuController                    )
                        COMPONENTINFO( ::framework::UICommandDescription                    )
                        COMPONENTINFO( ::framework::ModuleManager                           )
                        COMPONENTINFO( ::framework::UIConfigurationManager                  )
                        COMPONENTINFO( ::framework::ModuleUIConfigurationManagerSupplier    )
                        COMPONENTINFO( ::framework::ModuleUIConfigurationManager            )
                        COMPONENTINFO( ::framework::MenuBarFactory                          )
                        COMPONENTINFO( ::framework::GlobalAcceleratorConfiguration          )
                        COMPONENTINFO( ::framework::ModuleAcceleratorConfiguration          )
                        COMPONENTINFO( ::framework::DocumentAcceleratorConfiguration        )
                        COMPONENTINFO( ::framework::ToolBoxFactory                          )
                        COMPONENTINFO( ::framework::AddonsToolBoxFactory                    )
                        COMPONENTINFO( ::framework::WindowStateConfiguration                )
                        COMPONENTINFO( ::framework::ToolbarControllerFactory                )
                        COMPONENTINFO( ::framework::ToolbarsMenuController                  )
                        COMPONENTINFO( ::framework::AutoRecovery                            )
                        COMPONENTINFO( ::framework::StatusIndicatorFactory                  )
                        COMPONENTINFO( ::framework::RecentFilesMenuController               )
                        COMPONENTINFO( ::framework::StatusBarFactory                        )
                        COMPONENTINFO( ::framework::UICategoryDescription                   )
                        COMPONENTINFO( ::framework::StatusbarControllerFactory              )
                        COMPONENTINFO( ::framework::SessionListener                         )
                        COMPONENTINFO( ::framework::LogoImageStatusbarController            )
                        COMPONENTINFO( ::framework::LogoTextStatusbarController             )
                        COMPONENTINFO( ::framework::NewMenuController                       )
                        COMPONENTINFO( ::framework::TaskCreatorService                      )
                        COMPONENTINFO( ::framework::SimpleTextStatusbarController           )
                    )

COMPONENTGETFACTORY (   IFFACTORY( ::framework::URLTransformer                          )   else
                        IFFACTORY( ::framework::Desktop                                 )   else
                        IFFACTORY( ::framework::Frame                                   )   else
                        IFFACTORY( ::framework::DocumentProperties                      )   else
                        IFFACTORY( ::framework::SoundHandler                            )   else
                        IFFACTORY( ::framework::JobExecutor                             )   else
                        IFFACTORY( ::framework::DispatchRecorderSupplier                )   else
                        IFFACTORY( ::framework::DispatchRecorder                        )   else
                        IFFACTORY( ::framework::MailToDispatcher                        )   else
                        IFFACTORY( ::framework::ServiceHandler                          )   else
                        IFFACTORY( ::framework::JobDispatch                             )   else
                        IFFACTORY( ::framework::BackingComp                             )   else
                        IFFACTORY( ::framework::DispatchHelper                          )   else
                        IFFACTORY( ::framework::LayoutManager                           )   else
                        IFFACTORY( ::framework::License                                 )   else
                        IFFACTORY( ::framework::UIElementFactoryManager                 )   else
                        IFFACTORY( ::framework::PopupMenuControllerFactory              )   else
                        IFFACTORY( ::framework::FontMenuController                      )   else
                        IFFACTORY( ::framework::FontSizeMenuController                  )   else
                        IFFACTORY( ::framework::ObjectMenuController                    )   else
                        IFFACTORY( ::framework::HeaderMenuController                    )   else
                        IFFACTORY( ::framework::FooterMenuController                    )   else
                        IFFACTORY( ::framework::ControlMenuController                   )   else
                        IFFACTORY( ::framework::MacrosMenuController                    )   else
                        IFFACTORY( ::framework::UICommandDescription                    )   else
                        IFFACTORY( ::framework::ModuleManager                           )   else
                        IFFACTORY( ::framework::UIConfigurationManager                  )   else
                        IFFACTORY( ::framework::ModuleUIConfigurationManagerSupplier    )   else
                        IFFACTORY( ::framework::ModuleUIConfigurationManager            )   else
                        IFFACTORY( ::framework::MenuBarFactory                          )   else
                        IFFACTORY( ::framework::GlobalAcceleratorConfiguration          )   else
                        IFFACTORY( ::framework::ModuleAcceleratorConfiguration          )   else
                        IFFACTORY( ::framework::DocumentAcceleratorConfiguration        )   else
                        IFFACTORY( ::framework::ToolBoxFactory                          )   else
                        IFFACTORY( ::framework::AddonsToolBoxFactory                    )   else
                        IFFACTORY( ::framework::WindowStateConfiguration                )   else
                        IFFACTORY( ::framework::ToolbarControllerFactory                )   else
                        IFFACTORY( ::framework::ToolbarsMenuController                  )   else
                        IFFACTORY( ::framework::AutoRecovery                            )   else
                        IFFACTORY( ::framework::StatusIndicatorFactory                  )   else
                        IFFACTORY( ::framework::RecentFilesMenuController               )   else
                        IFFACTORY( ::framework::StatusBarFactory                        )   else
                        IFFACTORY( ::framework::UICategoryDescription                   )   else
                        IFFACTORY( ::framework::SessionListener                         )   else
                        IFFACTORY( ::framework::StatusbarControllerFactory              )   else
                        IFFACTORY( ::framework::SessionListener                         )   else
                        IFFACTORY( ::framework::LogoImageStatusbarController            )   else
                        IFFACTORY( ::framework::LogoTextStatusbarController             )   else
                        IFFACTORY( ::framework::TaskCreatorService                      )   else
                        IFFACTORY( ::framework::NewMenuController                       )   else
                        IFFACTORY( ::framework::SimpleTextStatusbarController           )
            )

<|endoftext|>


<commit_before>// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2020 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <consensus/validation.h>
#include <net.h>
#include <net_processing.h>
#include <node/context.h>
#include <validation.h>
#include <validationinterface.h>
#include <node/transaction.h>

#include <future>

static TransactionError HandleATMPError(const TxValidationState& state, std::string& err_string_out)
{
    err_string_out = state.ToString();
    if (state.IsInvalid()) {
        if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) {
            return TransactionError::MISSING_INPUTS;
        }
        return TransactionError::MEMPOOL_REJECTED;
    } else {
        return TransactionError::MEMPOOL_ERROR;
    }
}

TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback)
{
    // BroadcastTransaction can be called by either sendrawtransaction RPC or wallet RPCs.
    // node.peerman is assigned both before chain clients and before RPC server is accepting calls,
    // and reset after chain clients and RPC sever are stopped. node.peerman should never be null here.
    assert(node.peerman);
    assert(node.mempool);
    std::promise<void> promise;
    uint256 hashTx = tx->GetHash();
    bool callback_set = false;

    { // cs_main scope
    assert(node.chainman);
    LOCK(cs_main);
    // If the transaction is already confirmed in the chain, don't do anything
    // and return early.
    CCoinsViewCache &view = node.chainman->ActiveChainstate().CoinsTip();
    for (size_t o = 0; o < tx->vout.size(); o++) {
        const Coin& existingCoin = view.AccessCoin(COutPoint(hashTx, o));
        // IsSpent doesn't mean the coin is spent, it means the output doesn't exist.
        // So if the output does exist, then this transaction exists in the chain.
        if (!existingCoin.IsSpent()) return TransactionError::ALREADY_IN_CHAIN;
    }
    if (!node.mempool->exists(hashTx)) {
        // Transaction is not already in the mempool.
        if (max_tx_fee > 0) {
            // First, call ATMP with test_accept and check the fee. If ATMP
            // fails here, return error immediately.
            const MempoolAcceptResult result = AcceptToMemoryPool(node.chainman->ActiveChainstate(), *node.mempool, tx, false /* bypass_limits */,
                                                                  true /* test_accept */);
            if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
                return HandleATMPError(result.m_state, err_string);
            } else if (result.m_base_fees.value() > max_tx_fee) {
                return TransactionError::MAX_FEE_EXCEEDED;
            }
        }
        // Try to submit the transaction to the mempool.
        const MempoolAcceptResult result = AcceptToMemoryPool(node.chainman->ActiveChainstate(), *node.mempool, tx, false /* bypass_limits */,
                                                              false /* test_accept */);
        if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
            return HandleATMPError(result.m_state, err_string);
        }

        // Transaction was accepted to the mempool.

        if (relay) {
            // the mempool tracks locally submitted transactions to make a
            // best-effort of initial broadcast
            node.mempool->AddUnbroadcastTx(hashTx);
        }

        if (wait_callback) {
            // For transactions broadcast from outside the wallet, make sure
            // that the wallet has been notified of the transaction before
            // continuing.
            //
            // This prevents a race where a user might call sendrawtransaction
            // with a transaction to/from their wallet, immediately call some
            // wallet RPC, and get a stale result because callbacks have not
            // yet been processed.
            CallFunctionInValidationInterfaceQueue([&promise] {
                promise.set_value();
            });
            callback_set = true;
        }
    }

    } // cs_main

    if (callback_set) {
        // Wait until Validation Interface clients have been notified of the
        // transaction entering the mempool.
        promise.get_future().wait();
    }

    if (relay) {
        node.peerman->RelayTransaction(hashTx, tx->GetWitnessHash());
    }

    return TransactionError::OK;
}
<commit_msg>[mempool] Allow rebroadcast for same-txid-different-wtxid transactions<commit_after>// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2020 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <consensus/validation.h>
#include <net.h>
#include <net_processing.h>
#include <node/context.h>
#include <validation.h>
#include <validationinterface.h>
#include <node/transaction.h>

#include <future>

static TransactionError HandleATMPError(const TxValidationState& state, std::string& err_string_out)
{
    err_string_out = state.ToString();
    if (state.IsInvalid()) {
        if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) {
            return TransactionError::MISSING_INPUTS;
        }
        return TransactionError::MEMPOOL_REJECTED;
    } else {
        return TransactionError::MEMPOOL_ERROR;
    }
}

TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback)
{
    // BroadcastTransaction can be called by either sendrawtransaction RPC or wallet RPCs.
    // node.peerman is assigned both before chain clients and before RPC server is accepting calls,
    // and reset after chain clients and RPC sever are stopped. node.peerman should never be null here.
    assert(node.peerman);
    assert(node.mempool);
    std::promise<void> promise;
    uint256 txid = tx->GetHash();
    uint256 wtxid = tx->GetWitnessHash();
    bool callback_set = false;

    { // cs_main scope
    assert(node.chainman);
    LOCK(cs_main);
    // If the transaction is already confirmed in the chain, don't do anything
    // and return early.
    CCoinsViewCache &view = node.chainman->ActiveChainstate().CoinsTip();
    for (size_t o = 0; o < tx->vout.size(); o++) {
        const Coin& existingCoin = view.AccessCoin(COutPoint(txid, o));
        // IsSpent doesn't mean the coin is spent, it means the output doesn't exist.
        // So if the output does exist, then this transaction exists in the chain.
        if (!existingCoin.IsSpent()) return TransactionError::ALREADY_IN_CHAIN;
    }
    if (auto mempool_tx = node.mempool->get(txid); mempool_tx) {
        // There's already a transaction in the mempool with this txid. Don't
        // try to submit this transaction to the mempool (since it'll be
        // rejected as a TX_CONFLICT), but do attempt to reannounce the mempool
        // transaction if relay=true.
        //
        // The mempool transaction may have the same or different witness (and
        // wtxid) as this transaction. Use the mempool's wtxid for reannouncement.
        wtxid = mempool_tx->GetWitnessHash();
    } else {
        // Transaction is not already in the mempool.
        if (max_tx_fee > 0) {
            // First, call ATMP with test_accept and check the fee. If ATMP
            // fails here, return error immediately.
            const MempoolAcceptResult result = AcceptToMemoryPool(node.chainman->ActiveChainstate(), *node.mempool, tx, false /* bypass_limits */,
                                                                  true /* test_accept */);
            if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
                return HandleATMPError(result.m_state, err_string);
            } else if (result.m_base_fees.value() > max_tx_fee) {
                return TransactionError::MAX_FEE_EXCEEDED;
            }
        }
        // Try to submit the transaction to the mempool.
        const MempoolAcceptResult result = AcceptToMemoryPool(node.chainman->ActiveChainstate(), *node.mempool, tx, false /* bypass_limits */,
                                                              false /* test_accept */);
        if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
            return HandleATMPError(result.m_state, err_string);
        }

        // Transaction was accepted to the mempool.

        if (relay) {
            // the mempool tracks locally submitted transactions to make a
            // best-effort of initial broadcast
            node.mempool->AddUnbroadcastTx(txid);
        }

        if (wait_callback) {
            // For transactions broadcast from outside the wallet, make sure
            // that the wallet has been notified of the transaction before
            // continuing.
            //
            // This prevents a race where a user might call sendrawtransaction
            // with a transaction to/from their wallet, immediately call some
            // wallet RPC, and get a stale result because callbacks have not
            // yet been processed.
            CallFunctionInValidationInterfaceQueue([&promise] {
                promise.set_value();
            });
            callback_set = true;
        }
    }

    } // cs_main

    if (callback_set) {
        // Wait until Validation Interface clients have been notified of the
        // transaction entering the mempool.
        promise.get_future().wait();
    }

    if (relay) {
        node.peerman->RelayTransaction(txid, wtxid);
    }

    return TransactionError::OK;
}
<|endoftext|>


<commit_before><commit_msg>Update All_combines<commit_after><|endoftext|>


<commit_before>#include "ofxNDIRecvStream.h"

template<>
bool ofxNDIRecvVideoBlocking::captureFrame(ofxNDI::VideoFrame &frame) {
	return NDIlib_recv_capture_v2(instance_, &frame, nullptr, nullptr, timeout_ms_) == NDIlib_frame_type_video;
}
template<>
void ofxNDIRecvVideoBlocking::freeFrame(ofxNDI::VideoFrame &frame) {
	NDIlib_recv_free_video_v2(instance_, &frame);
}
template<>
bool ofxNDIRecvVideoThreading::captureFrame(ofxNDI::VideoFrame &frame) {
	return NDIlib_recv_capture_v2(instance_, &frame, nullptr, nullptr, timeout_ms_) == NDIlib_frame_type_video;
}
template<>
void ofxNDIRecvVideoThreading::freeFrame(ofxNDI::VideoFrame &frame) {
	NDIlib_recv_free_video_v2(instance_, &frame);
}
bool ofxNDIRecvVideoFrameSync::captureFrame(ofxNDI::VideoFrame &frame) {
	NDIlib_framesync_capture_video(sync_, &frame, field_type_);
	return true;
}
void ofxNDIRecvVideoFrameSync::freeFrame(ofxNDI::VideoFrame &frame) {
	NDIlib_framesync_free_video(sync_, &frame);
}

#pragma mark Audio Stream
template<>
bool ofxNDIRecvAudioBlocking::captureFrame(ofxNDI::AudioFrame &frame) {
	return NDIlib_recv_capture_v2(instance_, nullptr, &frame, nullptr, timeout_ms_) == NDIlib_frame_type_audio;
}
template<>
void ofxNDIRecvAudioBlocking::freeFrame(ofxNDI::AudioFrame &frame) {
	NDIlib_recv_free_audio_v2(instance_, &frame);
}
template<>
bool ofxNDIRecvAudioThreading::captureFrame(ofxNDI::AudioFrame &frame) {
	return NDIlib_recv_capture_v2(instance_, nullptr, &frame, nullptr, timeout_ms_) == NDIlib_frame_type_audio;
}
template<>
void ofxNDIRecvAudioThreading::freeFrame(ofxNDI::AudioFrame &frame) {
	NDIlib_recv_free_audio_v2(instance_, &frame);
}
bool ofxNDIRecvAudioFrameSync::captureFrame(ofxNDI::AudioFrame &frame) {
	NDIlib_framesync_capture_audio(sync_, &frame, sample_rate_, num_channels_, num_samples_);
	return true;
}
void ofxNDIRecvAudioFrameSync::freeFrame(ofxNDI::AudioFrame &frame) {
	NDIlib_framesync_free_audio(sync_, &frame);
}
int ofxNDIRecvAudioFrameSync::getNumQueuedSamples() const {
	return NDIlib_framesync_audio_queue_depth(sync_);
}

#pragma mark Metadata Stream

template<>
bool ofxNDIRecvMetadata::captureFrame(ofxNDI::MetadataFrame &frame) {
	return NDIlib_recv_capture_v2(instance_, nullptr, nullptr, &frame, timeout_ms_) == NDIlib_frame_type_metadata;
}
template<>
void ofxNDIRecvMetadata::freeFrame(ofxNDI::MetadataFrame &frame) {
	NDIlib_recv_free_metadata(instance_, &frame);
}

<commit_msg>handle errors when received empty data<commit_after>#include "ofxNDIRecvStream.h"

template<>
bool ofxNDIRecvVideoBlocking::captureFrame(ofxNDI::VideoFrame &frame) {
	return NDIlib_recv_capture_v2(instance_, &frame, nullptr, nullptr, timeout_ms_) == NDIlib_frame_type_video;
}
template<>
void ofxNDIRecvVideoBlocking::freeFrame(ofxNDI::VideoFrame &frame) {
	NDIlib_recv_free_video_v2(instance_, &frame);
}
template<>
bool ofxNDIRecvVideoThreading::captureFrame(ofxNDI::VideoFrame &frame) {
	return NDIlib_recv_capture_v2(instance_, &frame, nullptr, nullptr, timeout_ms_) == NDIlib_frame_type_video;
}
template<>
void ofxNDIRecvVideoThreading::freeFrame(ofxNDI::VideoFrame &frame) {
	NDIlib_recv_free_video_v2(instance_, &frame);
}
bool ofxNDIRecvVideoFrameSync::captureFrame(ofxNDI::VideoFrame &frame) {
	NDIlib_framesync_capture_video(sync_, &frame, field_type_);
	return frame.p_data != nullptr;
}
void ofxNDIRecvVideoFrameSync::freeFrame(ofxNDI::VideoFrame &frame) {
	NDIlib_framesync_free_video(sync_, &frame);
}

#pragma mark Audio Stream
template<>
bool ofxNDIRecvAudioBlocking::captureFrame(ofxNDI::AudioFrame &frame) {
	return NDIlib_recv_capture_v2(instance_, nullptr, &frame, nullptr, timeout_ms_) == NDIlib_frame_type_audio;
}
template<>
void ofxNDIRecvAudioBlocking::freeFrame(ofxNDI::AudioFrame &frame) {
	NDIlib_recv_free_audio_v2(instance_, &frame);
}
template<>
bool ofxNDIRecvAudioThreading::captureFrame(ofxNDI::AudioFrame &frame) {
	return NDIlib_recv_capture_v2(instance_, nullptr, &frame, nullptr, timeout_ms_) == NDIlib_frame_type_audio;
}
template<>
void ofxNDIRecvAudioThreading::freeFrame(ofxNDI::AudioFrame &frame) {
	NDIlib_recv_free_audio_v2(instance_, &frame);
}
bool ofxNDIRecvAudioFrameSync::captureFrame(ofxNDI::AudioFrame &frame) {
	NDIlib_framesync_capture_audio(sync_, &frame, sample_rate_, num_channels_, num_samples_);
	return frame.no_channels != 0;
}
void ofxNDIRecvAudioFrameSync::freeFrame(ofxNDI::AudioFrame &frame) {
	NDIlib_framesync_free_audio(sync_, &frame);
}
int ofxNDIRecvAudioFrameSync::getNumQueuedSamples() const {
	return NDIlib_framesync_audio_queue_depth(sync_);
}

#pragma mark Metadata Stream

template<>
bool ofxNDIRecvMetadata::captureFrame(ofxNDI::MetadataFrame &frame) {
	return NDIlib_recv_capture_v2(instance_, nullptr, nullptr, &frame, timeout_ms_) == NDIlib_frame_type_metadata;
}
template<>
void ofxNDIRecvMetadata::freeFrame(ofxNDI::MetadataFrame &frame) {
	NDIlib_recv_free_metadata(instance_, &frame);
}

<|endoftext|>


<commit_before>// 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 "config.h"

#include "base/compiler_specific.h"

MSVC_PUSH_WARNING_LEVEL(0);
#include "ContextMenu.h"
#include "Document.h"
#include "DocumentLoader.h"
#include "Editor.h"
#include "EventHandler.h"
#include "FrameLoader.h"
#include "FrameView.h"
#include "HitTestResult.h"
#include "KURL.h"
#include "Widget.h"
MSVC_POP_WARNING();
#undef LOG

#include "webkit/glue/context_menu_client_impl.h"

#include "base/string_util.h"
#include "webkit/glue/context_menu.h"
#include "webkit/glue/glue_util.h"
#include "webkit/glue/webdocumentloader_impl.h"
#include "webkit/glue/webview_impl.h"

#include "base/word_iterator.h"

namespace {

// Helper function to determine whether text is a single word or a sentence.
bool IsASingleWord(const std::wstring& text) {
  WordIterator iter(text, WordIterator::BREAK_WORD);
  int word_count = 0;
  if (!iter.Init()) return false;
  while (iter.Advance()) {
    if (iter.IsWord()) {
      word_count++;
      if (word_count > 1) // More than one word.
        return false;
    }
  }

  // Check for 0 words.
  if (!word_count)
    return false;

  // Has a single word.
  return true;
}

// Helper function to get misspelled word on which context menu
// is to be evolked. This function also sets the word on which context menu
// has been evoked to be the selected word, as required.
std::wstring GetMisspelledWord(const WebCore::ContextMenu* default_menu,
                               WebCore::Frame* selected_frame) {
  std::wstring misspelled_word_string;

  // First select from selectedText to check for multiple word selection.
  misspelled_word_string = CollapseWhitespace(
      webkit_glue::StringToStdWString(selected_frame->selectedText()),
      false);

  // Don't provide suggestions for multiple words.
  if (!misspelled_word_string.empty() &&
      !IsASingleWord(misspelled_word_string))
    return L"";

  WebCore::HitTestResult hit_test_result = selected_frame->eventHandler()->
      hitTestResultAtPoint(default_menu->hitTestResult().point(), true);
  WebCore::Node* inner_node = hit_test_result.innerNode();
  WebCore::VisiblePosition pos(inner_node->renderer()->positionForPoint(
      hit_test_result.localPoint()));

  WebCore::Selection selection;
  if (pos.isNotNull()) {
    selection = WebCore::Selection(pos);
    selection.expandUsingGranularity(WebCore::WordGranularity);
  }

  if (selection.isRange()) {
    selected_frame->setSelectionGranularity(WebCore::WordGranularity);
  }

  if (selected_frame->shouldChangeSelection(selection))
    selected_frame->selection()->setSelection(selection);

  misspelled_word_string = CollapseWhitespace(
      webkit_glue::StringToStdWString(selected_frame->selectedText()),
                                      false);

  return misspelled_word_string;
}

}  // namespace

ContextMenuClientImpl::~ContextMenuClientImpl() {
}

void ContextMenuClientImpl::contextMenuDestroyed() {
  delete this;
}

// Figure out the URL of a page or subframe. Returns |page_type| as the type,
// which indicates page or subframe, or ContextNode::NONE if the URL could not
// be determined for some reason.
static ContextNode GetTypeAndURLFromFrame(WebCore::Frame* frame,
                                          GURL* url,
                                          ContextNode page_node) {
  ContextNode node;
  if (frame) {
    WebCore::DocumentLoader* dl = frame->loader()->documentLoader();
    if (dl) {
      WebDataSource* ds = static_cast<WebDocumentLoaderImpl*>(dl)->
          GetDataSource();
      if (ds) {
        node = page_node;
        *url = ds->HasUnreachableURL() ? ds->GetUnreachableURL()
                                       : ds->GetRequest().GetURL();
      }
    }
  }
  return node;
}

WebCore::PlatformMenuDescription
    ContextMenuClientImpl::getCustomMenuFromDefaultItems(
        WebCore::ContextMenu* default_menu) {
  // Displaying the context menu in this function is a big hack as we don't
  // have context, i.e. whether this is being invoked via a script or in
  // response to user input (Mouse event WM_RBUTTONDOWN,
  // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked
  // in response to the above input events before popping up the context menu.
  if (!webview_->context_menu_allowed())
    return NULL;

  WebCore::HitTestResult r = default_menu->hitTestResult();
  WebCore::Frame* selected_frame = r.innerNonSharedNode()->document()->frame();

  WebCore::IntPoint menu_point =
      selected_frame->view()->contentsToWindow(r.point());

  ContextNode node;

  // Links, Images and Image-Links take preference over all else.
  WebCore::KURL link_url = r.absoluteLinkURL();
  if (!link_url.isEmpty()) {
    node.type |= ContextNode::LINK;
  }
  WebCore::KURL image_url = r.absoluteImageURL();
  if (!image_url.isEmpty()) {
    node.type |= ContextNode::IMAGE;
  }

  // If it's not a link, an image or an image link, show a selection menu or a
  // more generic page menu.
  std::wstring selection_text_string;
  std::wstring misspelled_word_string;
  GURL frame_url;
  GURL page_url;
  std::string security_info;

  std::wstring frame_encoding;
  // Send the frame and page URLs in any case.
  ContextNode frame_node = ContextNode(ContextNode::NONE);
  ContextNode page_node =
      GetTypeAndURLFromFrame(webview_->main_frame()->frame(),
                             &page_url,
                             ContextNode(ContextNode::PAGE));
  if (selected_frame != webview_->main_frame()->frame()) {
    frame_node = GetTypeAndURLFromFrame(selected_frame,
                                        &frame_url,
                                        ContextNode(ContextNode::FRAME));
    frame_encoding = webkit_glue::StringToStdWString(
        selected_frame->loader()->encoding());
  }

  if (r.isSelected()) {
    node.type |= ContextNode::SELECTION;
    selection_text_string = CollapseWhitespace(
      webkit_glue::StringToStdWString(selected_frame->selectedText()),
      false);
  }

  if (r.isContentEditable()) {
    node.type |= ContextNode::EDITABLE;
    if (webview_->GetFocusedWebCoreFrame()->editor()->
        isContinuousSpellCheckingEnabled()) {
      misspelled_word_string = GetMisspelledWord(default_menu,
                                                 selected_frame);
    }
  }

  if (node.type == ContextNode::NONE) {
    if (selected_frame != webview_->main_frame()->frame()) {
      node = frame_node;
    } else {
      node = page_node;
    }
  }

  // Now retrieve the security info.
  WebCore::DocumentLoader* dl = selected_frame->loader()->documentLoader();
  if (dl) {
    WebDataSource* ds = static_cast<WebDocumentLoaderImpl*>(dl)->
        GetDataSource();
    if (ds) {
      const WebResponse& response = ds->GetResponse();
      security_info = response.GetSecurityInfo();
    }
  }

  int edit_flags = ContextNode::CAN_DO_NONE;
  if (webview_->GetFocusedWebCoreFrame()->editor()->canUndo())
    edit_flags |= ContextNode::CAN_UNDO;
  if (webview_->GetFocusedWebCoreFrame()->editor()->canRedo())
    edit_flags |= ContextNode::CAN_REDO;
  if (webview_->GetFocusedWebCoreFrame()->editor()->canCut())
    edit_flags |= ContextNode::CAN_CUT;
  if (webview_->GetFocusedWebCoreFrame()->editor()->canCopy())
    edit_flags |= ContextNode::CAN_COPY;
  if (webview_->GetFocusedWebCoreFrame()->editor()->canPaste())
    edit_flags |= ContextNode::CAN_PASTE;
  if (webview_->GetFocusedWebCoreFrame()->editor()->canDelete())
    edit_flags |= ContextNode::CAN_DELETE;
  // We can always select all...
  edit_flags |= ContextNode::CAN_SELECT_ALL;

  WebViewDelegate* d = webview_->delegate();
  if (d) {
    d->ShowContextMenu(webview_,
                       node,
                       menu_point.x(),
                       menu_point.y(),
                       webkit_glue::KURLToGURL(link_url),
                       webkit_glue::KURLToGURL(image_url),
                       page_url,
                       frame_url,
                       selection_text_string,
                       misspelled_word_string,
                       edit_flags,
                       security_info);
  }
  return NULL;
}

void ContextMenuClientImpl::contextMenuItemSelected(
    WebCore::ContextMenuItem*, const WebCore::ContextMenu*) {
}

void ContextMenuClientImpl::downloadURL(const WebCore::KURL&) {
}

void ContextMenuClientImpl::copyImageToClipboard(const WebCore::HitTestResult&) {
}

void ContextMenuClientImpl::searchWithGoogle(const WebCore::Frame*) {
}

void ContextMenuClientImpl::lookUpInDictionary(WebCore::Frame*) {
}

void ContextMenuClientImpl::speak(const WebCore::String&) {
}

void ContextMenuClientImpl::stopSpeaking() {
}

bool ContextMenuClientImpl::shouldIncludeInspectElementItem() {
    return false;  // TODO(jackson): Eventually include the inspector context menu item
}

#if defined(OS_MACOSX)
void ContextMenuClientImpl::searchWithSpotlight() {
  // TODO(pinkerton): write this
}
#endif
<commit_msg>Fix bug where right click in a text area selects empty space.<commit_after>// 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 "config.h"

#include "base/compiler_specific.h"

MSVC_PUSH_WARNING_LEVEL(0);
#include "ContextMenu.h"
#include "Document.h"
#include "DocumentLoader.h"
#include "Editor.h"
#include "EventHandler.h"
#include "FrameLoader.h"
#include "FrameView.h"
#include "HitTestResult.h"
#include "KURL.h"
#include "Widget.h"
MSVC_POP_WARNING();
#undef LOG

#include "webkit/glue/context_menu_client_impl.h"

#include "base/string_util.h"
#include "webkit/glue/context_menu.h"
#include "webkit/glue/glue_util.h"
#include "webkit/glue/webdocumentloader_impl.h"
#include "webkit/glue/webview_impl.h"

#include "base/word_iterator.h"

namespace {

// Helper function to determine whether text is a single word or a sentence.
bool IsASingleWord(const std::wstring& text) {
  WordIterator iter(text, WordIterator::BREAK_WORD);
  int word_count = 0;
  if (!iter.Init()) return false;
  while (iter.Advance()) {
    if (iter.IsWord()) {
      word_count++;
      if (word_count > 1) // More than one word.
        return false;
    }
  }

  // Check for 0 words.
  if (!word_count)
    return false;

  // Has a single word.
  return true;
}

// Helper function to get misspelled word on which context menu
// is to be evolked. This function also sets the word on which context menu
// has been evoked to be the selected word, as required.
std::wstring GetMisspelledWord(const WebCore::ContextMenu* default_menu,
                               WebCore::Frame* selected_frame) {
  std::wstring misspelled_word_string;

  // First select from selectedText to check for multiple word selection.
  misspelled_word_string = CollapseWhitespace(
      webkit_glue::StringToStdWString(selected_frame->selectedText()),
      false);

  // Don't provide suggestions for multiple words.
  if (!misspelled_word_string.empty() &&
      !IsASingleWord(misspelled_word_string))
    return L"";

  WebCore::HitTestResult hit_test_result = selected_frame->eventHandler()->
      hitTestResultAtPoint(default_menu->hitTestResult().point(), true);
  WebCore::Node* inner_node = hit_test_result.innerNode();
  WebCore::VisiblePosition pos(inner_node->renderer()->positionForPoint(
      hit_test_result.localPoint()));

  WebCore::Selection selection;
  if (pos.isNotNull()) {
    selection = WebCore::Selection(pos);
    selection.expandUsingGranularity(WebCore::WordGranularity);
  }

  if (selection.isRange()) {
    selected_frame->setSelectionGranularity(WebCore::WordGranularity);
  }

  if (selected_frame->shouldChangeSelection(selection))
    selected_frame->selection()->setSelection(selection);

  misspelled_word_string = CollapseWhitespace(
      webkit_glue::StringToStdWString(selected_frame->selectedText()),
                                      false);

  // If misspelled word is empty, then that portion should not be selected.
  // Set the selection to that position only, and do not expand.
  if (misspelled_word_string.empty()) {
    selection = WebCore::Selection(pos);
    selected_frame->selection()->setSelection(selection);
  }

  return misspelled_word_string;
}

}  // namespace

ContextMenuClientImpl::~ContextMenuClientImpl() {
}

void ContextMenuClientImpl::contextMenuDestroyed() {
  delete this;
}

// Figure out the URL of a page or subframe. Returns |page_type| as the type,
// which indicates page or subframe, or ContextNode::NONE if the URL could not
// be determined for some reason.
static ContextNode GetTypeAndURLFromFrame(WebCore::Frame* frame,
                                          GURL* url,
                                          ContextNode page_node) {
  ContextNode node;
  if (frame) {
    WebCore::DocumentLoader* dl = frame->loader()->documentLoader();
    if (dl) {
      WebDataSource* ds = static_cast<WebDocumentLoaderImpl*>(dl)->
          GetDataSource();
      if (ds) {
        node = page_node;
        *url = ds->HasUnreachableURL() ? ds->GetUnreachableURL()
                                       : ds->GetRequest().GetURL();
      }
    }
  }
  return node;
}

WebCore::PlatformMenuDescription
    ContextMenuClientImpl::getCustomMenuFromDefaultItems(
        WebCore::ContextMenu* default_menu) {
  // Displaying the context menu in this function is a big hack as we don't
  // have context, i.e. whether this is being invoked via a script or in
  // response to user input (Mouse event WM_RBUTTONDOWN,
  // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked
  // in response to the above input events before popping up the context menu.
  if (!webview_->context_menu_allowed())
    return NULL;

  WebCore::HitTestResult r = default_menu->hitTestResult();
  WebCore::Frame* selected_frame = r.innerNonSharedNode()->document()->frame();

  WebCore::IntPoint menu_point =
      selected_frame->view()->contentsToWindow(r.point());

  ContextNode node;

  // Links, Images and Image-Links take preference over all else.
  WebCore::KURL link_url = r.absoluteLinkURL();
  if (!link_url.isEmpty()) {
    node.type |= ContextNode::LINK;
  }
  WebCore::KURL image_url = r.absoluteImageURL();
  if (!image_url.isEmpty()) {
    node.type |= ContextNode::IMAGE;
  }

  // If it's not a link, an image or an image link, show a selection menu or a
  // more generic page menu.
  std::wstring selection_text_string;
  std::wstring misspelled_word_string;
  GURL frame_url;
  GURL page_url;
  std::string security_info;

  std::wstring frame_encoding;
  // Send the frame and page URLs in any case.
  ContextNode frame_node = ContextNode(ContextNode::NONE);
  ContextNode page_node =
      GetTypeAndURLFromFrame(webview_->main_frame()->frame(),
                             &page_url,
                             ContextNode(ContextNode::PAGE));
  if (selected_frame != webview_->main_frame()->frame()) {
    frame_node = GetTypeAndURLFromFrame(selected_frame,
                                        &frame_url,
                                        ContextNode(ContextNode::FRAME));
    frame_encoding = webkit_glue::StringToStdWString(
        selected_frame->loader()->encoding());
  }

  if (r.isSelected()) {
    node.type |= ContextNode::SELECTION;
    selection_text_string = CollapseWhitespace(
      webkit_glue::StringToStdWString(selected_frame->selectedText()),
      false);
  }

  if (r.isContentEditable()) {
    node.type |= ContextNode::EDITABLE;
    if (webview_->GetFocusedWebCoreFrame()->editor()->
        isContinuousSpellCheckingEnabled()) {
      misspelled_word_string = GetMisspelledWord(default_menu,
                                                 selected_frame);
    }
  }

  if (node.type == ContextNode::NONE) {
    if (selected_frame != webview_->main_frame()->frame()) {
      node = frame_node;
    } else {
      node = page_node;
    }
  }

  // Now retrieve the security info.
  WebCore::DocumentLoader* dl = selected_frame->loader()->documentLoader();
  if (dl) {
    WebDataSource* ds = static_cast<WebDocumentLoaderImpl*>(dl)->
        GetDataSource();
    if (ds) {
      const WebResponse& response = ds->GetResponse();
      security_info = response.GetSecurityInfo();
    }
  }

  int edit_flags = ContextNode::CAN_DO_NONE;
  if (webview_->GetFocusedWebCoreFrame()->editor()->canUndo())
    edit_flags |= ContextNode::CAN_UNDO;
  if (webview_->GetFocusedWebCoreFrame()->editor()->canRedo())
    edit_flags |= ContextNode::CAN_REDO;
  if (webview_->GetFocusedWebCoreFrame()->editor()->canCut())
    edit_flags |= ContextNode::CAN_CUT;
  if (webview_->GetFocusedWebCoreFrame()->editor()->canCopy())
    edit_flags |= ContextNode::CAN_COPY;
  if (webview_->GetFocusedWebCoreFrame()->editor()->canPaste())
    edit_flags |= ContextNode::CAN_PASTE;
  if (webview_->GetFocusedWebCoreFrame()->editor()->canDelete())
    edit_flags |= ContextNode::CAN_DELETE;
  // We can always select all...
  edit_flags |= ContextNode::CAN_SELECT_ALL;

  WebViewDelegate* d = webview_->delegate();
  if (d) {
    d->ShowContextMenu(webview_,
                       node,
                       menu_point.x(),
                       menu_point.y(),
                       webkit_glue::KURLToGURL(link_url),
                       webkit_glue::KURLToGURL(image_url),
                       page_url,
                       frame_url,
                       selection_text_string,
                       misspelled_word_string,
                       edit_flags,
                       security_info);
  }
  return NULL;
}

void ContextMenuClientImpl::contextMenuItemSelected(
    WebCore::ContextMenuItem*, const WebCore::ContextMenu*) {
}

void ContextMenuClientImpl::downloadURL(const WebCore::KURL&) {
}

void ContextMenuClientImpl::copyImageToClipboard(const WebCore::HitTestResult&) {
}

void ContextMenuClientImpl::searchWithGoogle(const WebCore::Frame*) {
}

void ContextMenuClientImpl::lookUpInDictionary(WebCore::Frame*) {
}

void ContextMenuClientImpl::speak(const WebCore::String&) {
}

void ContextMenuClientImpl::stopSpeaking() {
}

bool ContextMenuClientImpl::shouldIncludeInspectElementItem() {
    return false;  // TODO(jackson): Eventually include the inspector context menu item
}

#if defined(OS_MACOSX)
void ContextMenuClientImpl::searchWithSpotlight() {
  // TODO(pinkerton): write this
}
#endif
<|endoftext|>


<commit_before>// Copyright (c) 2008, Google 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:
//
//     * 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 Google Inc. 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.

#include "config.h"

#include "v8_helpers.h"
#include "v8_npobject.h"
#include "v8_np_utils.h"
#include "np_v8object.h"
#include "npruntime_priv.h"
#include "v8_proxy.h"
#include "dom_wrapper_map.h"
#include "HTMLPlugInElement.h"
#include "V8HTMLAppletElement.h"
#include "V8HTMLEmbedElement.h"
#include "V8HTMLObjectElement.h"

using namespace WebCore;

enum InvokeFunctionType {
  INVOKE_METHOD = 1,
  INVOKE_DEFAULT = 2
};

// TODO(mbelshe): need comments.
// Params: holder could be HTMLEmbedElement or NPObject
static v8::Handle<v8::Value> NPObjectInvokeImpl(
    const v8::Arguments& args, InvokeFunctionType func_id) {
  NPObject* npobject;

  // These three types are subtypes of HTMLPlugInElement.
  if (V8HTMLAppletElement::HasInstance(args.Holder()) ||
    V8HTMLEmbedElement::HasInstance(args.Holder()) ||
    V8HTMLObjectElement::HasInstance(args.Holder())) {
    // The holder object is a subtype of HTMLPlugInElement.
    HTMLPlugInElement* imp =
        V8Proxy::DOMWrapperToNode<HTMLPlugInElement>(args.Holder());
    v8::Handle<v8::Object> instance = imp->getInstance();
    npobject = V8Proxy::ToNativeObject<NPObject>(
        V8ClassIndex::NPOBJECT, instance);

  } else {
    // The holder object is not a subtype of HTMLPlugInElement, it
    // must be an NPObject which has three internal fields.
    ASSERT(args.Holder()->InternalFieldCount() == 3);
    npobject = V8Proxy::ToNativeObject<NPObject>(
        V8ClassIndex::NPOBJECT, args.Holder());
  }

  // Verify that our wrapper wasn't using a NPObject which
  // has already been deleted.
  if (!npobject || !_NPN_IsAlive(npobject)) {
    V8Proxy::ThrowError(V8Proxy::REFERENCE_ERROR, "NPObject deleted");
    return v8::Undefined();
  }

  // wrap up parameters
  int argc = args.Length();
  NPVariant* np_args = new NPVariant[argc];

  for (int i = 0; i < argc; i++) {
    ConvertV8ObjectToNPVariant(args[i], npobject, &np_args[i]);
  }

  NPVariant result;
  VOID_TO_NPVARIANT(result);

  switch (func_id) {
    case INVOKE_METHOD:
      if (npobject->_class->invoke) {
        v8::Handle<v8::String> function_name(v8::String::Cast(*args.Data()));
        NPIdentifier ident = GetStringIdentifier(function_name);
        npobject->_class->invoke(npobject, ident, np_args, argc, &result);
      }
      break;
    case INVOKE_DEFAULT:
      if (npobject->_class->invokeDefault) {
        npobject->_class->invokeDefault(npobject, np_args, argc, &result);
      }
      break;
    default:
      break;
  }

  for (int i=0; i < argc; i++) {
    NPN_ReleaseVariantValue(&np_args[i]);
  }
  delete[] np_args;

  // unwrap return values
  v8::Handle<v8::Value> rv = ConvertNPVariantToV8Object(&result, npobject);
  NPN_ReleaseVariantValue(&result);

  return rv;
}

v8::Handle<v8::Value> NPObjectMethodHandler(const v8::Arguments& args) {
  return NPObjectInvokeImpl(args, INVOKE_METHOD);
}

v8::Handle<v8::Value> NPObjectInvokeDefaultHandler(const v8::Arguments& args) {
  return NPObjectInvokeImpl(args, INVOKE_DEFAULT);
}

static void WeakTemplateCallback(v8::Persistent<v8::Value> obj, void* param);

// NPIdentifier is PrivateIdentifier*.
static WeakReferenceMap<PrivateIdentifier, v8::FunctionTemplate> \
    static_template_map(&WeakTemplateCallback);

static void WeakTemplateCallback(v8::Persistent<v8::Value> obj,
                                 void* param) {
  PrivateIdentifier* iden = static_cast<PrivateIdentifier*>(param);
  ASSERT(iden != NULL);
  ASSERT(static_template_map.contains(iden));

  static_template_map.forget(iden);
}

static v8::Handle<v8::Value> NPObjectGetProperty(v8::Local<v8::Object> self,
                                                 NPIdentifier ident,
                                                 v8::Local<v8::Value> key) {
  NPObject* npobject = V8Proxy::ToNativeObject<NPObject>(V8ClassIndex::NPOBJECT,
                                                         self);

  // Verify that our wrapper wasn't using a NPObject which
  // has already been deleted.
  if (!npobject || !_NPN_IsAlive(npobject)) {
    V8Proxy::ThrowError(V8Proxy::REFERENCE_ERROR, "NPObject deleted");
    return v8::Handle<v8::Value>();
  }

  if (npobject->_class->hasProperty &&
      npobject->_class->hasProperty(npobject, ident) &&
      npobject->_class->getProperty) {
    NPVariant result;
    VOID_TO_NPVARIANT(result);
    if (!npobject->_class->getProperty(npobject, ident, &result)) {
      return v8::Handle<v8::Value>();
    }

    v8::Handle<v8::Value> rv = ConvertNPVariantToV8Object(&result, npobject);
    NPN_ReleaseVariantValue(&result);
    return rv;

  } else if (key->IsString() &&
             npobject->_class->hasMethod &&
             npobject->_class->hasMethod(npobject, ident)) {
    PrivateIdentifier* id = static_cast<PrivateIdentifier*>(ident);
    v8::Persistent<v8::FunctionTemplate> desc = static_template_map.get(id);
    // Cache templates using identifier as the key.
    if (desc.IsEmpty()) {
      // Create a new template
      v8::Local<v8::FunctionTemplate> temp = v8::FunctionTemplate::New();
      temp->SetCallHandler(NPObjectMethodHandler, key);
      desc = v8::Persistent<v8::FunctionTemplate>::New(temp);
      static_template_map.set(id, desc);
    }

    // FunctionTemplate caches function for each context.
    v8::Local<v8::Function> func = desc->GetFunction();
    func->SetName(v8::Handle<v8::String>::Cast(key));
    return func;
  }

  return v8::Handle<v8::Value>();
}

v8::Handle<v8::Value> NPObjectNamedPropertyGetter(v8::Local<v8::String> name,
                                                  const v8::AccessorInfo& info) {
  NPIdentifier ident = GetStringIdentifier(name);
  return NPObjectGetProperty(info.Holder(), ident, name);
}

v8::Handle<v8::Value> NPObjectIndexedPropertyGetter(uint32_t index,
                                                    const v8::AccessorInfo& info) {
  NPIdentifier ident = NPN_GetIntIdentifier(index);
  return NPObjectGetProperty(info.Holder(), ident, v8::Number::New(index));
}

v8::Handle<v8::Value> NPObjectGetNamedProperty(v8::Local<v8::Object> self,
                                               v8::Local<v8::String> name) {
  NPIdentifier ident = GetStringIdentifier(name);
  return NPObjectGetProperty(self, ident, name);
}

v8::Handle<v8::Value> NPObjectGetIndexedProperty(v8::Local<v8::Object> self,
                                                 uint32_t index) {
  NPIdentifier ident = NPN_GetIntIdentifier(index);
  return NPObjectGetProperty(self, ident, v8::Number::New(index));
}

static v8::Handle<v8::Value> NPObjectSetProperty(v8::Local<v8::Object> self,
                                                 NPIdentifier ident,
                                                 v8::Local<v8::Value> value) {
  NPObject* npobject =
    V8Proxy::ToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, self);

  // Verify that our wrapper wasn't using a NPObject which
  // has already been deleted.
  if (!npobject || !_NPN_IsAlive(npobject)) {
    V8Proxy::ThrowError(V8Proxy::REFERENCE_ERROR, "NPObject deleted");
    return value;  // intercepted, but an exception was thrown
  }

  if (npobject->_class->hasProperty &&
      npobject->_class->hasProperty(npobject, ident) &&
      npobject->_class->setProperty) {
    NPVariant npvalue;
    VOID_TO_NPVARIANT(npvalue);
    ConvertV8ObjectToNPVariant(value, npobject, &npvalue);
    bool succ = npobject->_class->setProperty(npobject, ident, &npvalue);
    NPN_ReleaseVariantValue(&npvalue);
    if (succ) return value;  // intercept the call
  }
  return v8::Local<v8::Value>();  // do not intercept the call
}

v8::Handle<v8::Value> NPObjectNamedPropertySetter(v8::Local<v8::String> name,
                                                  v8::Local<v8::Value> value,
                                                  const v8::AccessorInfo& info) {
  NPIdentifier ident = GetStringIdentifier(name);
  return NPObjectSetProperty(info.Holder(), ident, value);
}

v8::Handle<v8::Value> NPObjectIndexedPropertySetter(uint32_t index,
                                                    v8::Local<v8::Value> value,
                                                    const v8::AccessorInfo& info) {
  NPIdentifier ident = NPN_GetIntIdentifier(index);
  return NPObjectSetProperty(info.Holder(), ident, value);
}

v8::Handle<v8::Value> NPObjectSetNamedProperty(v8::Local<v8::Object> self,
                                               v8::Local<v8::String> name,
                                               v8::Local<v8::Value> value) {
  NPIdentifier ident = GetStringIdentifier(name);
  return NPObjectSetProperty(self, ident, value);
}

v8::Handle<v8::Value> NPObjectSetIndexedProperty(v8::Local<v8::Object> self,
                                                 uint32_t index,
                                                 v8::Local<v8::Value> value) {
  NPIdentifier ident = NPN_GetIntIdentifier(index);
  return NPObjectSetProperty(self, ident, value);
}

static void WeakNPObjectCallback(v8::Persistent<v8::Value> obj, void* param);

static DOMWrapperMap<NPObject> static_npobject_map(&WeakNPObjectCallback);

static void WeakNPObjectCallback(v8::Persistent<v8::Value> obj,
                                 void* param) {
  NPObject* npobject = static_cast<NPObject*>(param);
  ASSERT(static_npobject_map.contains(npobject));
  ASSERT(npobject != NULL);

  // Must remove from our map before calling NPN_ReleaseObject().
  // NPN_ReleaseObject can call ForgetV8ObjectForNPObject, which
  // uses the table as well.
  static_npobject_map.forget(npobject);

  if (_NPN_IsAlive(npobject))
    NPN_ReleaseObject(npobject);
}

v8::Local<v8::Object> CreateV8ObjectForNPObject(NPObject* object,
                                                NPObject* root) {
  static v8::Persistent<v8::FunctionTemplate> np_object_desc;

  ASSERT(v8::Context::InContext());

  // If this is a v8 object, just return it.
  if (object->_class == NPScriptObjectClass) {
    V8NPObject* v8npobject = reinterpret_cast<V8NPObject*>(object);
    return v8::Local<v8::Object>::New(v8npobject->v8_object);
  }

  // If we've already wrapped this object, just return it.
  if (static_npobject_map.contains(object))
    return v8::Local<v8::Object>::New(static_npobject_map.get(object));

  // TODO: we should create a Wrapper type as a subclass of JSObject.
  // It has two internal fields, field 0 is the wrapped pointer,
  // and field 1 is the type. There should be an api function that
  // returns unused type id.
  // The same Wrapper type can be used by DOM bindings.
  if (np_object_desc.IsEmpty()) {
    np_object_desc =
        v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New());
    np_object_desc->InstanceTemplate()->SetInternalFieldCount(3);
    np_object_desc->InstanceTemplate()->SetNamedPropertyHandler(
        NPObjectNamedPropertyGetter, NPObjectNamedPropertySetter);
    np_object_desc->InstanceTemplate()->SetIndexedPropertyHandler(
        NPObjectIndexedPropertyGetter, NPObjectIndexedPropertySetter);
    np_object_desc->InstanceTemplate()->SetCallAsFunctionHandler(
        NPObjectInvokeDefaultHandler);
  }

  v8::Handle<v8::Function> func = np_object_desc->GetFunction();
  v8::Local<v8::Object> value = SafeAllocation::NewInstance(func);

  // If we were unable to allocate the instance we avoid wrapping
  // and registering the NP object.
  if (value.IsEmpty())
      return value;

  WrapNPObject(value, object);

  // KJS retains the object as part of its wrapper (see Bindings::CInstance)
  NPN_RetainObject(object);

  _NPN_RegisterObject(object, root);

  // Maintain a weak pointer for v8 so we can cleanup the object.
  v8::Persistent<v8::Object> weak_ref = v8::Persistent<v8::Object>::New(value);
  static_npobject_map.set(object, weak_ref);

  return value;
}

void ForgetV8ObjectForNPObject(NPObject* object) {
  if (static_npobject_map.contains(object)) {
    v8::HandleScope scope;
    v8::Persistent<v8::Object> handle(static_npobject_map.get(object));
    WebCore::V8Proxy::SetDOMWrapper(handle,
        WebCore::V8ClassIndex::NPOBJECT, NULL);
    static_npobject_map.forget(object);
    NPN_ReleaseObject(object);
  }
}
<commit_msg>Fix a renderer crashing bug with NPObject method references. http://www.corp.google.com/~michaeln/flash_crash/crash.html<commit_after>// Copyright (c) 2008, Google 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:
//
//     * 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 Google Inc. 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.

#include "config.h"

#include "v8_helpers.h"
#include "v8_npobject.h"
#include "v8_np_utils.h"
#include "np_v8object.h"
#include "npruntime_priv.h"
#include "v8_proxy.h"
#include "dom_wrapper_map.h"
#include "HTMLPlugInElement.h"
#include "V8HTMLAppletElement.h"
#include "V8HTMLEmbedElement.h"
#include "V8HTMLObjectElement.h"

using namespace WebCore;

enum InvokeFunctionType {
  INVOKE_METHOD = 1,
  INVOKE_DEFAULT = 2
};

// TODO(mbelshe): need comments.
// Params: holder could be HTMLEmbedElement or NPObject
static v8::Handle<v8::Value> NPObjectInvokeImpl(
    const v8::Arguments& args, InvokeFunctionType func_id) {
  NPObject* npobject;

  // These three types are subtypes of HTMLPlugInElement.
  if (V8HTMLAppletElement::HasInstance(args.Holder()) ||
      V8HTMLEmbedElement::HasInstance(args.Holder()) ||
      V8HTMLObjectElement::HasInstance(args.Holder())) {
    // The holder object is a subtype of HTMLPlugInElement.
    HTMLPlugInElement* imp =
        V8Proxy::DOMWrapperToNode<HTMLPlugInElement>(args.Holder());
    v8::Handle<v8::Object> instance = imp->getInstance();
    npobject = V8Proxy::ToNativeObject<NPObject>(
        V8ClassIndex::NPOBJECT, instance);

  } else {
    // The holder object is not a subtype of HTMLPlugInElement, it
    // must be an NPObject which has three internal fields.
    if (args.Holder()->InternalFieldCount() != 3) {
      V8Proxy::ThrowError(V8Proxy::REFERENCE_ERROR,
                          "NPMethod called on non-NPObject");
      return v8::Undefined();
    }
    npobject = V8Proxy::ToNativeObject<NPObject>(
        V8ClassIndex::NPOBJECT, args.Holder());
  }

  // Verify that our wrapper wasn't using a NPObject which
  // has already been deleted.
  if (!npobject || !_NPN_IsAlive(npobject)) {
    V8Proxy::ThrowError(V8Proxy::REFERENCE_ERROR, "NPObject deleted");
    return v8::Undefined();
  }

  // wrap up parameters
  int argc = args.Length();
  NPVariant* np_args = new NPVariant[argc];

  for (int i = 0; i < argc; i++) {
    ConvertV8ObjectToNPVariant(args[i], npobject, &np_args[i]);
  }

  NPVariant result;
  VOID_TO_NPVARIANT(result);

  switch (func_id) {
    case INVOKE_METHOD:
      if (npobject->_class->invoke) {
        v8::Handle<v8::String> function_name(v8::String::Cast(*args.Data()));
        NPIdentifier ident = GetStringIdentifier(function_name);
        npobject->_class->invoke(npobject, ident, np_args, argc, &result);
      }
      break;
    case INVOKE_DEFAULT:
      if (npobject->_class->invokeDefault) {
        npobject->_class->invokeDefault(npobject, np_args, argc, &result);
      }
      break;
    default:
      break;
  }

  for (int i=0; i < argc; i++) {
    NPN_ReleaseVariantValue(&np_args[i]);
  }
  delete[] np_args;

  // unwrap return values
  v8::Handle<v8::Value> rv = ConvertNPVariantToV8Object(&result, npobject);
  NPN_ReleaseVariantValue(&result);

  return rv;
}

v8::Handle<v8::Value> NPObjectMethodHandler(const v8::Arguments& args) {
  return NPObjectInvokeImpl(args, INVOKE_METHOD);
}

v8::Handle<v8::Value> NPObjectInvokeDefaultHandler(const v8::Arguments& args) {
  return NPObjectInvokeImpl(args, INVOKE_DEFAULT);
}

static void WeakTemplateCallback(v8::Persistent<v8::Value> obj, void* param);

// NPIdentifier is PrivateIdentifier*.
static WeakReferenceMap<PrivateIdentifier, v8::FunctionTemplate> \
    static_template_map(&WeakTemplateCallback);

static void WeakTemplateCallback(v8::Persistent<v8::Value> obj,
                                 void* param) {
  PrivateIdentifier* iden = static_cast<PrivateIdentifier*>(param);
  ASSERT(iden != NULL);
  ASSERT(static_template_map.contains(iden));

  static_template_map.forget(iden);
}

static v8::Handle<v8::Value> NPObjectGetProperty(v8::Local<v8::Object> self,
                                                 NPIdentifier ident,
                                                 v8::Local<v8::Value> key) {
  NPObject* npobject = V8Proxy::ToNativeObject<NPObject>(V8ClassIndex::NPOBJECT,
                                                         self);

  // Verify that our wrapper wasn't using a NPObject which
  // has already been deleted.
  if (!npobject || !_NPN_IsAlive(npobject)) {
    V8Proxy::ThrowError(V8Proxy::REFERENCE_ERROR, "NPObject deleted");
    return v8::Handle<v8::Value>();
  }

  if (npobject->_class->hasProperty &&
      npobject->_class->hasProperty(npobject, ident) &&
      npobject->_class->getProperty) {
    NPVariant result;
    VOID_TO_NPVARIANT(result);
    if (!npobject->_class->getProperty(npobject, ident, &result)) {
      return v8::Handle<v8::Value>();
    }

    v8::Handle<v8::Value> rv = ConvertNPVariantToV8Object(&result, npobject);
    NPN_ReleaseVariantValue(&result);
    return rv;

  } else if (key->IsString() &&
             npobject->_class->hasMethod &&
             npobject->_class->hasMethod(npobject, ident)) {
    PrivateIdentifier* id = static_cast<PrivateIdentifier*>(ident);
    v8::Persistent<v8::FunctionTemplate> desc = static_template_map.get(id);
    // Cache templates using identifier as the key.
    if (desc.IsEmpty()) {
      // Create a new template
      v8::Local<v8::FunctionTemplate> temp = v8::FunctionTemplate::New();
      temp->SetCallHandler(NPObjectMethodHandler, key);
      desc = v8::Persistent<v8::FunctionTemplate>::New(temp);
      static_template_map.set(id, desc);
    }

    // FunctionTemplate caches function for each context.
    v8::Local<v8::Function> func = desc->GetFunction();
    func->SetName(v8::Handle<v8::String>::Cast(key));
    return func;
  }

  return v8::Handle<v8::Value>();
}

v8::Handle<v8::Value> NPObjectNamedPropertyGetter(v8::Local<v8::String> name,
                                                  const v8::AccessorInfo& info) {
  NPIdentifier ident = GetStringIdentifier(name);
  return NPObjectGetProperty(info.Holder(), ident, name);
}

v8::Handle<v8::Value> NPObjectIndexedPropertyGetter(uint32_t index,
                                                    const v8::AccessorInfo& info) {
  NPIdentifier ident = NPN_GetIntIdentifier(index);
  return NPObjectGetProperty(info.Holder(), ident, v8::Number::New(index));
}

v8::Handle<v8::Value> NPObjectGetNamedProperty(v8::Local<v8::Object> self,
                                               v8::Local<v8::String> name) {
  NPIdentifier ident = GetStringIdentifier(name);
  return NPObjectGetProperty(self, ident, name);
}

v8::Handle<v8::Value> NPObjectGetIndexedProperty(v8::Local<v8::Object> self,
                                                 uint32_t index) {
  NPIdentifier ident = NPN_GetIntIdentifier(index);
  return NPObjectGetProperty(self, ident, v8::Number::New(index));
}

static v8::Handle<v8::Value> NPObjectSetProperty(v8::Local<v8::Object> self,
                                                 NPIdentifier ident,
                                                 v8::Local<v8::Value> value) {
  NPObject* npobject =
    V8Proxy::ToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, self);

  // Verify that our wrapper wasn't using a NPObject which
  // has already been deleted.
  if (!npobject || !_NPN_IsAlive(npobject)) {
    V8Proxy::ThrowError(V8Proxy::REFERENCE_ERROR, "NPObject deleted");
    return value;  // intercepted, but an exception was thrown
  }

  if (npobject->_class->hasProperty &&
      npobject->_class->hasProperty(npobject, ident) &&
      npobject->_class->setProperty) {
    NPVariant npvalue;
    VOID_TO_NPVARIANT(npvalue);
    ConvertV8ObjectToNPVariant(value, npobject, &npvalue);
    bool succ = npobject->_class->setProperty(npobject, ident, &npvalue);
    NPN_ReleaseVariantValue(&npvalue);
    if (succ) return value;  // intercept the call
  }
  return v8::Local<v8::Value>();  // do not intercept the call
}

v8::Handle<v8::Value> NPObjectNamedPropertySetter(v8::Local<v8::String> name,
                                                  v8::Local<v8::Value> value,
                                                  const v8::AccessorInfo& info) {
  NPIdentifier ident = GetStringIdentifier(name);
  return NPObjectSetProperty(info.Holder(), ident, value);
}

v8::Handle<v8::Value> NPObjectIndexedPropertySetter(uint32_t index,
                                                    v8::Local<v8::Value> value,
                                                    const v8::AccessorInfo& info) {
  NPIdentifier ident = NPN_GetIntIdentifier(index);
  return NPObjectSetProperty(info.Holder(), ident, value);
}

v8::Handle<v8::Value> NPObjectSetNamedProperty(v8::Local<v8::Object> self,
                                               v8::Local<v8::String> name,
                                               v8::Local<v8::Value> value) {
  NPIdentifier ident = GetStringIdentifier(name);
  return NPObjectSetProperty(self, ident, value);
}

v8::Handle<v8::Value> NPObjectSetIndexedProperty(v8::Local<v8::Object> self,
                                                 uint32_t index,
                                                 v8::Local<v8::Value> value) {
  NPIdentifier ident = NPN_GetIntIdentifier(index);
  return NPObjectSetProperty(self, ident, value);
}

static void WeakNPObjectCallback(v8::Persistent<v8::Value> obj, void* param);

static DOMWrapperMap<NPObject> static_npobject_map(&WeakNPObjectCallback);

static void WeakNPObjectCallback(v8::Persistent<v8::Value> obj,
                                 void* param) {
  NPObject* npobject = static_cast<NPObject*>(param);
  ASSERT(static_npobject_map.contains(npobject));
  ASSERT(npobject != NULL);

  // Must remove from our map before calling NPN_ReleaseObject().
  // NPN_ReleaseObject can call ForgetV8ObjectForNPObject, which
  // uses the table as well.
  static_npobject_map.forget(npobject);

  if (_NPN_IsAlive(npobject))
    NPN_ReleaseObject(npobject);
}

v8::Local<v8::Object> CreateV8ObjectForNPObject(NPObject* object,
                                                NPObject* root) {
  static v8::Persistent<v8::FunctionTemplate> np_object_desc;

  ASSERT(v8::Context::InContext());

  // If this is a v8 object, just return it.
  if (object->_class == NPScriptObjectClass) {
    V8NPObject* v8npobject = reinterpret_cast<V8NPObject*>(object);
    return v8::Local<v8::Object>::New(v8npobject->v8_object);
  }

  // If we've already wrapped this object, just return it.
  if (static_npobject_map.contains(object))
    return v8::Local<v8::Object>::New(static_npobject_map.get(object));

  // TODO: we should create a Wrapper type as a subclass of JSObject.
  // It has two internal fields, field 0 is the wrapped pointer,
  // and field 1 is the type. There should be an api function that
  // returns unused type id.
  // The same Wrapper type can be used by DOM bindings.
  if (np_object_desc.IsEmpty()) {
    np_object_desc =
        v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New());
    np_object_desc->InstanceTemplate()->SetInternalFieldCount(3);
    np_object_desc->InstanceTemplate()->SetNamedPropertyHandler(
        NPObjectNamedPropertyGetter, NPObjectNamedPropertySetter);
    np_object_desc->InstanceTemplate()->SetIndexedPropertyHandler(
        NPObjectIndexedPropertyGetter, NPObjectIndexedPropertySetter);
    np_object_desc->InstanceTemplate()->SetCallAsFunctionHandler(
        NPObjectInvokeDefaultHandler);
  }

  v8::Handle<v8::Function> func = np_object_desc->GetFunction();
  v8::Local<v8::Object> value = SafeAllocation::NewInstance(func);

  // If we were unable to allocate the instance we avoid wrapping
  // and registering the NP object.
  if (value.IsEmpty())
      return value;

  WrapNPObject(value, object);

  // KJS retains the object as part of its wrapper (see Bindings::CInstance)
  NPN_RetainObject(object);

  _NPN_RegisterObject(object, root);

  // Maintain a weak pointer for v8 so we can cleanup the object.
  v8::Persistent<v8::Object> weak_ref = v8::Persistent<v8::Object>::New(value);
  static_npobject_map.set(object, weak_ref);

  return value;
}

void ForgetV8ObjectForNPObject(NPObject* object) {
  if (static_npobject_map.contains(object)) {
    v8::HandleScope scope;
    v8::Persistent<v8::Object> handle(static_npobject_map.get(object));
    WebCore::V8Proxy::SetDOMWrapper(handle,
        WebCore::V8ClassIndex::NPOBJECT, NULL);
    static_npobject_map.forget(object);
    NPN_ReleaseObject(object);
  }
}
<|endoftext|>