gecko/js/xpconnect/wrappers/WrapperFactory.cpp

685 lines
27 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=4 sw=4 et tw=99 ft=cpp:
*
2012-05-21 04:12:37 -07:00
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "WaiveXrayWrapper.h"
#include "FilteringWrapper.h"
#include "XrayWrapper.h"
#include "AccessCheck.h"
#include "XPCWrapper.h"
#include "ChromeObjectWrapper.h"
#include "xpcprivate.h"
#include "dombindings.h"
Bug 691411 - Move js/src/xpconnect to js/xpconnect and rename source files while we're at it. r=khuey, sr=mrbkap --HG-- rename : js/src/xpconnect/Makefile.in => js/xpconnect/Makefile.in rename : js/src/xpconnect/crashtests/117307-1.html => js/xpconnect/crashtests/117307-1.html rename : js/src/xpconnect/crashtests/193710.html => js/xpconnect/crashtests/193710.html rename : js/src/xpconnect/crashtests/290162-1.html => js/xpconnect/crashtests/290162-1.html rename : js/src/xpconnect/crashtests/326615-1.html => js/xpconnect/crashtests/326615-1.html rename : js/src/xpconnect/crashtests/328553-1.html => js/xpconnect/crashtests/328553-1.html rename : js/src/xpconnect/crashtests/346258-1.html => js/xpconnect/crashtests/346258-1.html rename : js/src/xpconnect/crashtests/346512-1-frame1.xhtml => js/xpconnect/crashtests/346512-1-frame1.xhtml rename : js/src/xpconnect/crashtests/346512-1-frame2.xhtml => js/xpconnect/crashtests/346512-1-frame2.xhtml rename : js/src/xpconnect/crashtests/346512-1.xhtml => js/xpconnect/crashtests/346512-1.xhtml rename : js/src/xpconnect/crashtests/382133-1.html => js/xpconnect/crashtests/382133-1.html rename : js/src/xpconnect/crashtests/386680-1.html => js/xpconnect/crashtests/386680-1.html rename : js/src/xpconnect/crashtests/394810-1.html => js/xpconnect/crashtests/394810-1.html rename : js/src/xpconnect/crashtests/400349-1.html => js/xpconnect/crashtests/400349-1.html rename : js/src/xpconnect/crashtests/403356-1.html => js/xpconnect/crashtests/403356-1.html rename : js/src/xpconnect/crashtests/418139-1.svg => js/xpconnect/crashtests/418139-1.svg rename : js/src/xpconnect/crashtests/420513-1.html => js/xpconnect/crashtests/420513-1.html rename : js/src/xpconnect/crashtests/453935-1.html => js/xpconnect/crashtests/453935-1.html rename : js/src/xpconnect/crashtests/462926.html => js/xpconnect/crashtests/462926.html rename : js/src/xpconnect/crashtests/467693-1.html => js/xpconnect/crashtests/467693-1.html rename : js/src/xpconnect/crashtests/468552-1.html => js/xpconnect/crashtests/468552-1.html rename : js/src/xpconnect/crashtests/471366-1.html => js/xpconnect/crashtests/471366-1.html rename : js/src/xpconnect/crashtests/475185-1.html => js/xpconnect/crashtests/475185-1.html rename : js/src/xpconnect/crashtests/475291-1.html => js/xpconnect/crashtests/475291-1.html rename : js/src/xpconnect/crashtests/503286-1.html => js/xpconnect/crashtests/503286-1.html rename : js/src/xpconnect/crashtests/504000-1.html => js/xpconnect/crashtests/504000-1.html rename : js/src/xpconnect/crashtests/509075-1.html => js/xpconnect/crashtests/509075-1.html rename : js/src/xpconnect/crashtests/512815-1.html => js/xpconnect/crashtests/512815-1.html rename : js/src/xpconnect/crashtests/515726-1.html => js/xpconnect/crashtests/515726-1.html rename : js/src/xpconnect/crashtests/545291-1.html => js/xpconnect/crashtests/545291-1.html rename : js/src/xpconnect/crashtests/558979.html => js/xpconnect/crashtests/558979.html rename : js/src/xpconnect/crashtests/582649.html => js/xpconnect/crashtests/582649.html rename : js/src/xpconnect/crashtests/601284-1.html => js/xpconnect/crashtests/601284-1.html rename : js/src/xpconnect/crashtests/603146-1.html => js/xpconnect/crashtests/603146-1.html rename : js/src/xpconnect/crashtests/603858-1.html => js/xpconnect/crashtests/603858-1.html rename : js/src/xpconnect/crashtests/608963.html => js/xpconnect/crashtests/608963.html rename : js/src/xpconnect/crashtests/616930-1.html => js/xpconnect/crashtests/616930-1.html rename : js/src/xpconnect/crashtests/639737-1.html => js/xpconnect/crashtests/639737-1.html rename : js/src/xpconnect/crashtests/648206-1.html => js/xpconnect/crashtests/648206-1.html rename : js/src/xpconnect/crashtests/crashtests.list => js/xpconnect/crashtests/crashtests.list rename : js/src/xpconnect/idl/Makefile.in => js/xpconnect/idl/Makefile.in rename : js/src/xpconnect/idl/mozIJSSubScriptLoader.idl => js/xpconnect/idl/mozIJSSubScriptLoader.idl rename : js/src/xpconnect/idl/nsIJSContextStack.idl => js/xpconnect/idl/nsIJSContextStack.idl rename : js/src/xpconnect/idl/nsIJSEngineTelemetryStats.idl => js/xpconnect/idl/nsIJSEngineTelemetryStats.idl rename : js/src/xpconnect/idl/nsIJSRuntimeService.idl => js/xpconnect/idl/nsIJSRuntimeService.idl rename : js/src/xpconnect/idl/nsIScriptError.idl => js/xpconnect/idl/nsIScriptError.idl rename : js/src/xpconnect/idl/nsIXPCScriptNotify.idl => js/xpconnect/idl/nsIXPCScriptNotify.idl rename : js/src/xpconnect/idl/nsIXPCScriptable.idl => js/xpconnect/idl/nsIXPCScriptable.idl rename : js/src/xpconnect/idl/nsIXPCSecurityManager.idl => js/xpconnect/idl/nsIXPCSecurityManager.idl rename : js/src/xpconnect/idl/nsIXPConnect.idl => js/xpconnect/idl/nsIXPConnect.idl rename : js/src/xpconnect/idl/xpcIJSGetFactory.idl => js/xpconnect/idl/xpcIJSGetFactory.idl rename : js/src/xpconnect/idl/xpcIJSModuleLoader.idl => js/xpconnect/idl/xpcIJSModuleLoader.idl rename : js/src/xpconnect/idl/xpcIJSWeakReference.idl => js/xpconnect/idl/xpcIJSWeakReference.idl rename : js/src/xpconnect/idl/xpccomponents.idl => js/xpconnect/idl/xpccomponents.idl rename : js/src/xpconnect/idl/xpcexception.idl => js/xpconnect/idl/xpcexception.idl rename : js/src/xpconnect/idl/xpcjsid.idl => js/xpconnect/idl/xpcjsid.idl rename : js/src/xpconnect/loader/Makefile.in => js/xpconnect/loader/Makefile.in rename : js/src/xpconnect/loader/XPCOMUtils.jsm => js/xpconnect/loader/XPCOMUtils.jsm rename : js/src/xpconnect/loader/mozJSComponentLoader.cpp => js/xpconnect/loader/mozJSComponentLoader.cpp rename : js/src/xpconnect/loader/mozJSComponentLoader.h => js/xpconnect/loader/mozJSComponentLoader.h rename : js/src/xpconnect/loader/mozJSLoaderUtils.cpp => js/xpconnect/loader/mozJSLoaderUtils.cpp rename : js/src/xpconnect/loader/mozJSLoaderUtils.h => js/xpconnect/loader/mozJSLoaderUtils.h rename : js/src/xpconnect/loader/mozJSSubScriptLoader.cpp => js/xpconnect/loader/mozJSSubScriptLoader.cpp rename : js/src/xpconnect/loader/mozJSSubScriptLoader.h => js/xpconnect/loader/mozJSSubScriptLoader.h rename : js/src/xpconnect/public/Makefile.in => js/xpconnect/public/Makefile.in rename : js/src/xpconnect/public/nsAXPCNativeCallContext.h => js/xpconnect/public/nsAXPCNativeCallContext.h rename : js/src/xpconnect/public/nsAutoJSValHolder.h => js/xpconnect/public/nsAutoJSValHolder.h rename : js/src/xpconnect/public/xpc_map_end.h => js/xpconnect/public/xpc_map_end.h rename : js/src/xpconnect/shell/Makefile.in => js/xpconnect/shell/Makefile.in rename : js/src/xpconnect/shell/jsshell.msg => js/xpconnect/shell/jsshell.msg rename : js/src/xpconnect/shell/xpcshell.cpp => js/xpconnect/shell/xpcshell.cpp rename : js/src/xpconnect/shell/xpcshellMacUtils.h => js/xpconnect/shell/xpcshellMacUtils.h rename : js/src/xpconnect/shell/xpcshellMacUtils.mm => js/xpconnect/shell/xpcshellMacUtils.mm rename : js/src/xpconnect/src/Makefile.in => js/xpconnect/src/Makefile.in rename : js/src/xpconnect/src/README => js/xpconnect/src/README rename : js/src/xpconnect/src/xpccallcontext.cpp => js/xpconnect/src/XPCCallContext.cpp rename : js/src/xpconnect/src/xpccomponents.cpp => js/xpconnect/src/XPCComponents.cpp rename : js/src/xpconnect/src/xpccontext.cpp => js/xpconnect/src/XPCContext.cpp rename : js/src/xpconnect/src/xpcconvert.cpp => js/xpconnect/src/XPCConvert.cpp rename : js/src/xpconnect/src/xpcdebug.cpp => js/xpconnect/src/XPCDebug.cpp rename : js/src/xpconnect/src/xpcexception.cpp => js/xpconnect/src/XPCException.cpp rename : js/src/xpconnect/src/xpcforwards.h => js/xpconnect/src/XPCForwards.h rename : js/src/xpconnect/src/xpcinlines.h => js/xpconnect/src/XPCInlines.h rename : js/src/xpconnect/src/xpcjsid.cpp => js/xpconnect/src/XPCJSID.cpp rename : js/src/xpconnect/src/xpcjsruntime.cpp => js/xpconnect/src/XPCJSRuntime.cpp rename : js/src/xpconnect/src/xpcJSWeakReference.cpp => js/xpconnect/src/XPCJSWeakReference.cpp rename : js/src/xpconnect/src/xpcJSWeakReference.h => js/xpconnect/src/XPCJSWeakReference.h rename : js/src/xpconnect/src/xpclocale.cpp => js/xpconnect/src/XPCLocale.cpp rename : js/src/xpconnect/src/xpclog.cpp => js/xpconnect/src/XPCLog.cpp rename : js/src/xpconnect/src/xpclog.h => js/xpconnect/src/XPCLog.h rename : js/src/xpconnect/src/xpcmaps.cpp => js/xpconnect/src/XPCMaps.cpp rename : js/src/xpconnect/src/xpcmaps.h => js/xpconnect/src/XPCMaps.h rename : js/src/xpconnect/src/xpcmodule.cpp => js/xpconnect/src/XPCModule.cpp rename : js/src/xpconnect/src/xpcmodule.h => js/xpconnect/src/XPCModule.h rename : js/src/xpconnect/src/xpcquickstubs.cpp => js/xpconnect/src/XPCQuickStubs.cpp rename : js/src/xpconnect/src/xpcquickstubs.h => js/xpconnect/src/XPCQuickStubs.h rename : js/src/xpconnect/src/xpcruntimesvc.cpp => js/xpconnect/src/XPCRuntimeService.cpp rename : js/src/xpconnect/src/xpcstack.cpp => js/xpconnect/src/XPCStack.cpp rename : js/src/xpconnect/src/xpcstring.cpp => js/xpconnect/src/XPCString.cpp rename : js/src/xpconnect/src/xpcthreadcontext.cpp => js/xpconnect/src/XPCThreadContext.cpp rename : js/src/xpconnect/src/xpcthrower.cpp => js/xpconnect/src/XPCThrower.cpp rename : js/src/xpconnect/src/xpcvariant.cpp => js/xpconnect/src/XPCVariant.cpp rename : js/src/xpconnect/src/xpcwrappedjs.cpp => js/xpconnect/src/XPCWrappedJS.cpp rename : js/src/xpconnect/src/xpcwrappedjsclass.cpp => js/xpconnect/src/XPCWrappedJSClass.cpp rename : js/src/xpconnect/src/xpcwrappednative.cpp => js/xpconnect/src/XPCWrappedNative.cpp rename : js/src/xpconnect/src/xpcwrappednativeinfo.cpp => js/xpconnect/src/XPCWrappedNativeInfo.cpp rename : js/src/xpconnect/src/xpcwrappednativejsops.cpp => js/xpconnect/src/XPCWrappedNativeJSOps.cpp rename : js/src/xpconnect/src/xpcwrappednativeproto.cpp => js/xpconnect/src/XPCWrappedNativeProto.cpp rename : js/src/xpconnect/src/xpcwrappednativescope.cpp => js/xpconnect/src/XPCWrappedNativeScope.cpp rename : js/src/xpconnect/src/XPCWrapper.cpp => js/xpconnect/src/XPCWrapper.cpp rename : js/src/xpconnect/src/XPCWrapper.h => js/xpconnect/src/XPCWrapper.h rename : js/src/xpconnect/src/codegen.py => js/xpconnect/src/codegen.py rename : js/src/xpconnect/src/dom_quickstubs.qsconf => js/xpconnect/src/dom_quickstubs.qsconf rename : js/src/xpconnect/src/dombindings.conf => js/xpconnect/src/dombindings.conf rename : js/src/xpconnect/src/dombindings.cpp => js/xpconnect/src/dombindings.cpp rename : js/src/xpconnect/src/dombindings.h => js/xpconnect/src/dombindings.h rename : js/src/xpconnect/src/dombindingsgen.py => js/xpconnect/src/dombindingsgen.py rename : js/src/xpconnect/src/nsCSSPropertiesQS.h => js/xpconnect/src/nsCSSPropertiesQS.h rename : js/src/xpconnect/src/nsDOMQS.h => js/xpconnect/src/nsDOMQS.h rename : js/src/xpconnect/src/nsScriptError.cpp => js/xpconnect/src/nsScriptError.cpp rename : js/src/xpconnect/src/nsXPConnect.cpp => js/xpconnect/src/nsXPConnect.cpp rename : js/src/xpconnect/src/qsWinUndefs.h => js/xpconnect/src/qsWinUndefs.h rename : js/src/xpconnect/src/qsgen.py => js/xpconnect/src/qsgen.py rename : js/src/xpconnect/src/xpc.msg => js/xpconnect/src/xpc.msg rename : js/src/xpconnect/src/xpcprivate.h => js/xpconnect/src/xpcprivate.h rename : js/src/xpconnect/src/xpcpublic.h => js/xpconnect/src/xpcpublic.h rename : js/src/xpconnect/tests/Makefile.in => js/xpconnect/tests/Makefile.in rename : js/src/xpconnect/tests/chrome/Makefile.in => js/xpconnect/tests/chrome/Makefile.in rename : js/src/xpconnect/tests/chrome/bug503926.xul => js/xpconnect/tests/chrome/bug503926.xul rename : js/src/xpconnect/tests/chrome/file_bug618176.xul => js/xpconnect/tests/chrome/file_bug618176.xul rename : js/src/xpconnect/tests/chrome/file_evalInSandbox.html => js/xpconnect/tests/chrome/file_evalInSandbox.html rename : js/src/xpconnect/tests/chrome/test_APIExposer.xul => js/xpconnect/tests/chrome/test_APIExposer.xul rename : js/src/xpconnect/tests/chrome/test_bug448587.xul => js/xpconnect/tests/chrome/test_bug448587.xul rename : js/src/xpconnect/tests/chrome/test_bug484459.xul => js/xpconnect/tests/chrome/test_bug484459.xul rename : js/src/xpconnect/tests/chrome/test_bug500931.xul => js/xpconnect/tests/chrome/test_bug500931.xul rename : js/src/xpconnect/tests/chrome/test_bug503926.xul => js/xpconnect/tests/chrome/test_bug503926.xul rename : js/src/xpconnect/tests/chrome/test_bug517163.xul => js/xpconnect/tests/chrome/test_bug517163.xul rename : js/src/xpconnect/tests/chrome/test_bug533596.xul => js/xpconnect/tests/chrome/test_bug533596.xul rename : js/src/xpconnect/tests/chrome/test_bug571849.xul => js/xpconnect/tests/chrome/test_bug571849.xul rename : js/src/xpconnect/tests/chrome/test_bug596580.xul => js/xpconnect/tests/chrome/test_bug596580.xul rename : js/src/xpconnect/tests/chrome/test_bug601803.xul => js/xpconnect/tests/chrome/test_bug601803.xul rename : js/src/xpconnect/tests/chrome/test_bug610390.xul => js/xpconnect/tests/chrome/test_bug610390.xul rename : js/src/xpconnect/tests/chrome/test_bug614757.xul => js/xpconnect/tests/chrome/test_bug614757.xul rename : js/src/xpconnect/tests/chrome/test_bug616992.xul => js/xpconnect/tests/chrome/test_bug616992.xul rename : js/src/xpconnect/tests/chrome/test_bug618176.xul => js/xpconnect/tests/chrome/test_bug618176.xul rename : js/src/xpconnect/tests/chrome/test_bug654370.xul => js/xpconnect/tests/chrome/test_bug654370.xul rename : js/src/xpconnect/tests/chrome/test_bug658560.xul => js/xpconnect/tests/chrome/test_bug658560.xul rename : js/src/xpconnect/tests/chrome/test_bug664689.xul => js/xpconnect/tests/chrome/test_bug664689.xul rename : js/src/xpconnect/tests/chrome/test_bug679861.xul => js/xpconnect/tests/chrome/test_bug679861.xul rename : js/src/xpconnect/tests/chrome/test_cows.xul => js/xpconnect/tests/chrome/test_cows.xul rename : js/src/xpconnect/tests/chrome/test_doublewrappedcompartments.xul => js/xpconnect/tests/chrome/test_doublewrappedcompartments.xul rename : js/src/xpconnect/tests/chrome/test_evalInSandbox.xul => js/xpconnect/tests/chrome/test_evalInSandbox.xul rename : js/src/xpconnect/tests/chrome/test_getweakmapkeys.xul => js/xpconnect/tests/chrome/test_getweakmapkeys.xul rename : js/src/xpconnect/tests/chrome/test_nodelists.xul => js/xpconnect/tests/chrome/test_nodelists.xul rename : js/src/xpconnect/tests/chrome/test_precisegc.xul => js/xpconnect/tests/chrome/test_precisegc.xul rename : js/src/xpconnect/tests/chrome/test_sandboxImport.xul => js/xpconnect/tests/chrome/test_sandboxImport.xul rename : js/src/xpconnect/tests/chrome/test_wrappers-2.xul => js/xpconnect/tests/chrome/test_wrappers-2.xul rename : js/src/xpconnect/tests/chrome/test_wrappers.xul => js/xpconnect/tests/chrome/test_wrappers.xul rename : js/src/xpconnect/tests/components/js/Makefile.in => js/xpconnect/tests/components/js/Makefile.in rename : js/src/xpconnect/tests/components/js/xpctest.manifest => js/xpconnect/tests/components/js/xpctest.manifest rename : js/src/xpconnect/tests/components/js/xpctest_attributes.js => js/xpconnect/tests/components/js/xpctest_attributes.js rename : js/src/xpconnect/tests/components/js/xpctest_params.js => js/xpconnect/tests/components/js/xpctest_params.js rename : js/src/xpconnect/tests/components/native/Makefile.in => js/xpconnect/tests/components/native/Makefile.in rename : js/src/xpconnect/tests/components/native/xpctest.manifest => js/xpconnect/tests/components/native/xpctest.manifest rename : js/src/xpconnect/tests/components/native/xpctest_attributes.cpp => js/xpconnect/tests/components/native/xpctest_attributes.cpp rename : js/src/xpconnect/tests/components/native/xpctest_module.cpp => js/xpconnect/tests/components/native/xpctest_module.cpp rename : js/src/xpconnect/tests/components/native/xpctest_params.cpp => js/xpconnect/tests/components/native/xpctest_params.cpp rename : js/src/xpconnect/tests/components/native/xpctest_private.h => js/xpconnect/tests/components/native/xpctest_private.h rename : js/src/xpconnect/tests/idl/Makefile.in => js/xpconnect/tests/idl/Makefile.in rename : js/src/xpconnect/tests/idl/xpctest_attributes.idl => js/xpconnect/tests/idl/xpctest_attributes.idl rename : js/src/xpconnect/tests/idl/xpctest_params.idl => js/xpconnect/tests/idl/xpctest_params.idl rename : js/src/xpconnect/tests/mochitest/Makefile.in => js/xpconnect/tests/mochitest/Makefile.in rename : js/src/xpconnect/tests/mochitest/bug500931_helper.html => js/xpconnect/tests/mochitest/bug500931_helper.html rename : js/src/xpconnect/tests/mochitest/bug504877_helper.html => js/xpconnect/tests/mochitest/bug504877_helper.html rename : js/src/xpconnect/tests/mochitest/bug571849_helper.html => js/xpconnect/tests/mochitest/bug571849_helper.html rename : js/src/xpconnect/tests/mochitest/bug589028_helper.html => js/xpconnect/tests/mochitest/bug589028_helper.html rename : js/src/xpconnect/tests/mochitest/bug657267.jar => js/xpconnect/tests/mochitest/bug657267.jar rename : js/src/xpconnect/tests/mochitest/bug92773_helper.html => js/xpconnect/tests/mochitest/bug92773_helper.html rename : js/src/xpconnect/tests/mochitest/chrome_wrappers_helper.html => js/xpconnect/tests/mochitest/chrome_wrappers_helper.html rename : js/src/xpconnect/tests/mochitest/file1_bug629227.html => js/xpconnect/tests/mochitest/file1_bug629227.html rename : js/src/xpconnect/tests/mochitest/file2_bug629227.html => js/xpconnect/tests/mochitest/file2_bug629227.html rename : js/src/xpconnect/tests/mochitest/file_bug505915.html => js/xpconnect/tests/mochitest/file_bug505915.html rename : js/src/xpconnect/tests/mochitest/file_bug650273.html => js/xpconnect/tests/mochitest/file_bug650273.html rename : js/src/xpconnect/tests/mochitest/file_bug658560.html => js/xpconnect/tests/mochitest/file_bug658560.html rename : js/src/xpconnect/tests/mochitest/file_doublewrappedcompartments.html => js/xpconnect/tests/mochitest/file_doublewrappedcompartments.html rename : js/src/xpconnect/tests/mochitest/file_evalInSandbox.html => js/xpconnect/tests/mochitest/file_evalInSandbox.html rename : js/src/xpconnect/tests/mochitest/file_nodelists.html => js/xpconnect/tests/mochitest/file_nodelists.html rename : js/src/xpconnect/tests/mochitest/file_wrappers-2.html => js/xpconnect/tests/mochitest/file_wrappers-2.html rename : js/src/xpconnect/tests/mochitest/inner.html => js/xpconnect/tests/mochitest/inner.html rename : js/src/xpconnect/tests/mochitest/test1_bug629331.html => js/xpconnect/tests/mochitest/test1_bug629331.html rename : js/src/xpconnect/tests/mochitest/test2_bug629331.html => js/xpconnect/tests/mochitest/test2_bug629331.html rename : js/src/xpconnect/tests/mochitest/test_bug361111.xul => js/xpconnect/tests/mochitest/test_bug361111.xul rename : js/src/xpconnect/tests/mochitest/test_bug384632.html => js/xpconnect/tests/mochitest/test_bug384632.html rename : js/src/xpconnect/tests/mochitest/test_bug390488.html => js/xpconnect/tests/mochitest/test_bug390488.html rename : js/src/xpconnect/tests/mochitest/test_bug393269.html => js/xpconnect/tests/mochitest/test_bug393269.html rename : js/src/xpconnect/tests/mochitest/test_bug396851.html => js/xpconnect/tests/mochitest/test_bug396851.html rename : js/src/xpconnect/tests/mochitest/test_bug428021.html => js/xpconnect/tests/mochitest/test_bug428021.html rename : js/src/xpconnect/tests/mochitest/test_bug446584.html => js/xpconnect/tests/mochitest/test_bug446584.html rename : js/src/xpconnect/tests/mochitest/test_bug462428.html => js/xpconnect/tests/mochitest/test_bug462428.html rename : js/src/xpconnect/tests/mochitest/test_bug478438.html => js/xpconnect/tests/mochitest/test_bug478438.html rename : js/src/xpconnect/tests/mochitest/test_bug484107.html => js/xpconnect/tests/mochitest/test_bug484107.html rename : js/src/xpconnect/tests/mochitest/test_bug500691.html => js/xpconnect/tests/mochitest/test_bug500691.html rename : js/src/xpconnect/tests/mochitest/test_bug502959.html => js/xpconnect/tests/mochitest/test_bug502959.html rename : js/src/xpconnect/tests/mochitest/test_bug503926.html => js/xpconnect/tests/mochitest/test_bug503926.html rename : js/src/xpconnect/tests/mochitest/test_bug504877.html => js/xpconnect/tests/mochitest/test_bug504877.html rename : js/src/xpconnect/tests/mochitest/test_bug505915.html => js/xpconnect/tests/mochitest/test_bug505915.html rename : js/src/xpconnect/tests/mochitest/test_bug553407.html => js/xpconnect/tests/mochitest/test_bug553407.html rename : js/src/xpconnect/tests/mochitest/test_bug560351.html => js/xpconnect/tests/mochitest/test_bug560351.html rename : js/src/xpconnect/tests/mochitest/test_bug564330.html => js/xpconnect/tests/mochitest/test_bug564330.html rename : js/src/xpconnect/tests/mochitest/test_bug585745.html => js/xpconnect/tests/mochitest/test_bug585745.html rename : js/src/xpconnect/tests/mochitest/test_bug589028.html => js/xpconnect/tests/mochitest/test_bug589028.html rename : js/src/xpconnect/tests/mochitest/test_bug601299.html => js/xpconnect/tests/mochitest/test_bug601299.html rename : js/src/xpconnect/tests/mochitest/test_bug605167.html => js/xpconnect/tests/mochitest/test_bug605167.html rename : js/src/xpconnect/tests/mochitest/test_bug618017.html => js/xpconnect/tests/mochitest/test_bug618017.html rename : js/src/xpconnect/tests/mochitest/test_bug623437.html => js/xpconnect/tests/mochitest/test_bug623437.html rename : js/src/xpconnect/tests/mochitest/test_bug628410.html => js/xpconnect/tests/mochitest/test_bug628410.html rename : js/src/xpconnect/tests/mochitest/test_bug628794.html => js/xpconnect/tests/mochitest/test_bug628794.html rename : js/src/xpconnect/tests/mochitest/test_bug629227.html => js/xpconnect/tests/mochitest/test_bug629227.html rename : js/src/xpconnect/tests/mochitest/test_bug629331.html => js/xpconnect/tests/mochitest/test_bug629331.html rename : js/src/xpconnect/tests/mochitest/test_bug636097.html => js/xpconnect/tests/mochitest/test_bug636097.html rename : js/src/xpconnect/tests/mochitest/test_bug650273.html => js/xpconnect/tests/mochitest/test_bug650273.html rename : js/src/xpconnect/tests/mochitest/test_bug655297.html => js/xpconnect/tests/mochitest/test_bug655297.html rename : js/src/xpconnect/tests/mochitest/test_bug657267.html => js/xpconnect/tests/mochitest/test_bug657267.html rename : js/src/xpconnect/tests/mochitest/test_bug661980.html => js/xpconnect/tests/mochitest/test_bug661980.html rename : js/src/xpconnect/tests/mochitest/test_bug691059.html => js/xpconnect/tests/mochitest/test_bug691059.html rename : js/src/xpconnect/tests/mochitest/test_bug92773.html => js/xpconnect/tests/mochitest/test_bug92773.html rename : js/src/xpconnect/tests/mochitest/test_frameWrapping.html => js/xpconnect/tests/mochitest/test_frameWrapping.html rename : js/src/xpconnect/tests/unit/CatRegistrationComponents.manifest => js/xpconnect/tests/unit/CatRegistrationComponents.manifest rename : js/src/xpconnect/tests/unit/bogus_element_type.jsm => js/xpconnect/tests/unit/bogus_element_type.jsm rename : js/src/xpconnect/tests/unit/bogus_exports_type.jsm => js/xpconnect/tests/unit/bogus_exports_type.jsm rename : js/src/xpconnect/tests/unit/bug451678_subscript.js => js/xpconnect/tests/unit/bug451678_subscript.js rename : js/src/xpconnect/tests/unit/bug596580_versioned.js => js/xpconnect/tests/unit/bug596580_versioned.js rename : js/src/xpconnect/tests/unit/component-file.js => js/xpconnect/tests/unit/component-file.js rename : js/src/xpconnect/tests/unit/component-file.manifest => js/xpconnect/tests/unit/component-file.manifest rename : js/src/xpconnect/tests/unit/component_import.js => js/xpconnect/tests/unit/component_import.js rename : js/src/xpconnect/tests/unit/component_import.manifest => js/xpconnect/tests/unit/component_import.manifest rename : js/src/xpconnect/tests/unit/recursive_importA.jsm => js/xpconnect/tests/unit/recursive_importA.jsm rename : js/src/xpconnect/tests/unit/recursive_importB.jsm => js/xpconnect/tests/unit/recursive_importB.jsm rename : js/src/xpconnect/tests/unit/syntax_error.jsm => js/xpconnect/tests/unit/syntax_error.jsm rename : js/src/xpconnect/tests/unit/test_attributes.js => js/xpconnect/tests/unit/test_attributes.js rename : js/src/xpconnect/tests/unit/test_bogus_files.js => js/xpconnect/tests/unit/test_bogus_files.js rename : js/src/xpconnect/tests/unit/test_bug408412.js => js/xpconnect/tests/unit/test_bug408412.js rename : js/src/xpconnect/tests/unit/test_bug451678.js => js/xpconnect/tests/unit/test_bug451678.js rename : js/src/xpconnect/tests/unit/test_bug596580.js => js/xpconnect/tests/unit/test_bug596580.js rename : js/src/xpconnect/tests/unit/test_bug604362.js => js/xpconnect/tests/unit/test_bug604362.js rename : js/src/xpconnect/tests/unit/test_bug608142.js => js/xpconnect/tests/unit/test_bug608142.js rename : js/src/xpconnect/tests/unit/test_bug641378.js => js/xpconnect/tests/unit/test_bug641378.js rename : js/src/xpconnect/tests/unit/test_bug677864.js => js/xpconnect/tests/unit/test_bug677864.js rename : js/src/xpconnect/tests/unit/test_bug_442086.js => js/xpconnect/tests/unit/test_bug_442086.js rename : js/src/xpconnect/tests/unit/test_file.js => js/xpconnect/tests/unit/test_file.js rename : js/src/xpconnect/tests/unit/test_import.js => js/xpconnect/tests/unit/test_import.js rename : js/src/xpconnect/tests/unit/test_js_weak_references.js => js/xpconnect/tests/unit/test_js_weak_references.js rename : js/src/xpconnect/tests/unit/test_localeCompare.js => js/xpconnect/tests/unit/test_localeCompare.js rename : js/src/xpconnect/tests/unit/test_params.js => js/xpconnect/tests/unit/test_params.js rename : js/src/xpconnect/tests/unit/test_recursive_import.js => js/xpconnect/tests/unit/test_recursive_import.js rename : js/src/xpconnect/tests/unit/test_reflect_parse.js => js/xpconnect/tests/unit/test_reflect_parse.js rename : js/src/xpconnect/tests/unit/test_unload.js => js/xpconnect/tests/unit/test_unload.js rename : js/src/xpconnect/tests/unit/test_xpcomutils.js => js/xpconnect/tests/unit/test_xpcomutils.js rename : js/src/xpconnect/tests/unit/xpcshell.ini => js/xpconnect/tests/unit/xpcshell.ini rename : js/src/xpconnect/wrappers/AccessCheck.cpp => js/xpconnect/wrappers/AccessCheck.cpp rename : js/src/xpconnect/wrappers/AccessCheck.h => js/xpconnect/wrappers/AccessCheck.h rename : js/src/xpconnect/wrappers/CrossOriginWrapper.cpp => js/xpconnect/wrappers/CrossOriginWrapper.cpp rename : js/src/xpconnect/wrappers/CrossOriginWrapper.h => js/xpconnect/wrappers/CrossOriginWrapper.h rename : js/src/xpconnect/wrappers/FilteringWrapper.cpp => js/xpconnect/wrappers/FilteringWrapper.cpp rename : js/src/xpconnect/wrappers/FilteringWrapper.h => js/xpconnect/wrappers/FilteringWrapper.h rename : js/src/xpconnect/wrappers/Makefile.in => js/xpconnect/wrappers/Makefile.in rename : js/src/xpconnect/wrappers/WrapperFactory.cpp => js/xpconnect/wrappers/WrapperFactory.cpp rename : js/src/xpconnect/wrappers/WrapperFactory.h => js/xpconnect/wrappers/WrapperFactory.h rename : js/src/xpconnect/wrappers/XrayWrapper.cpp => js/xpconnect/wrappers/XrayWrapper.cpp rename : js/src/xpconnect/wrappers/XrayWrapper.h => js/xpconnect/wrappers/XrayWrapper.h
2011-10-14 10:52:47 -07:00
#include "XPCMaps.h"
Bug 742217. Reduce the use of nested namespaces in our binding code. r=peterv,bent In the new setup, all per-interface DOM binding files are exported into mozilla/dom. General files not specific to an interface are also exported into mozilla/dom. In terms of namespaces, most things now live in mozilla::dom. Each interface Foo that has generated code has a mozilla::dom::FooBinding namespace for said generated code (and possibly a mozilla::bindings::FooBinding_workers if there's separate codegen for workers). IDL enums are a bit weird: since the name of the enum and the names of its entries all end up in the same namespace, we still generate a C++ namespace with the name of the IDL enum type with "Values" appended to it, with a ::valuelist inside for the actual C++ enum. We then typedef EnumFooValues::valuelist to EnumFoo. That makes it a bit more difficult to refer to the values, but means that values from different enums don't collide with each other. The enums with the proto and constructor IDs in them now live under the mozilla::dom::prototypes and mozilla::dom::constructors namespaces respectively. Again, this lets us deal sanely with the whole "enum value names are flattened into the namespace the enum is in" deal. The main benefit of this setup (and the reason "Binding" got appended to the per-interface namespaces) is that this way "using mozilla::dom" should Just Work for consumers and still allow C++ code to sanely use the IDL interface names for concrete classes, which is fairly desirable. --HG-- rename : dom/bindings/Utils.cpp => dom/bindings/BindingUtils.cpp rename : dom/bindings/Utils.h => dom/bindings/BindingUtils.h
2012-05-02 21:35:38 -07:00
#include "mozilla/dom/BindingUtils.h"
#include "jsfriendapi.h"
#include "mozilla/Likely.h"
using namespace js;
namespace xpc {
// When chrome pulls a naked property across the membrane using
// .wrappedJSObject, we want it to cross the membrane into the
// chrome compartment without automatically being wrapped into an
// X-ray wrapper. We achieve this by wrapping it into a special
// transparent wrapper in the origin (non-chrome) compartment. When
// an object with that special wrapper applied crosses into chrome,
// we know to not apply an X-ray wrapper.
DirectWrapper XrayWaiver(WrapperFactory::WAIVE_XRAY_WRAPPER_FLAG);
// When objects for which we waived the X-ray wrapper cross into
// chrome, we wrap them into a special cross-compartment wrapper
// that transitively extends the waiver to all properties we get
// off it.
WaiveXrayWrapper WaiveXrayWrapper::singleton(0);
2010-10-18 15:21:50 -07:00
static JSObject *
GetCurrentOuter(JSContext *cx, JSObject *obj)
{
obj = JS_ObjectToOuterObject(cx, obj);
if (!obj)
return nullptr;
if (IsWrapper(obj) && !js::GetObjectClass(obj)->ext.innerObject) {
obj = UnwrapObject(obj);
NS_ASSERTION(js::GetObjectClass(obj)->ext.innerObject,
2010-10-18 15:21:50 -07:00
"weird object, expecting an outer window proxy");
}
return obj;
}
JSObject *
WrapperFactory::GetXrayWaiver(JSObject *obj)
{
// Object should come fully unwrapped but outerized.
MOZ_ASSERT(obj == UnwrapObject(obj));
MOZ_ASSERT(!js::GetObjectClass(obj)->ext.outerObject);
CompartmentPrivate *priv = GetCompartmentPrivate(obj);
MOZ_ASSERT(priv);
if (!priv->waiverWrapperMap)
return NULL;
return xpc_UnmarkGrayObject(priv->waiverWrapperMap->Find(obj));
}
JSObject *
WrapperFactory::CreateXrayWaiver(JSContext *cx, JSObject *obj)
{
// The caller is required to have already done a lookup.
// NB: This implictly performs the assertions of GetXrayWaiver.
MOZ_ASSERT(!GetXrayWaiver(obj));
CompartmentPrivate *priv = GetCompartmentPrivate(obj);
// Get a waiver for the proto.
JSObject *proto = js::GetObjectProto(obj);
if (proto && !(proto = WaiveXray(cx, proto)))
return nullptr;
// Create the waiver.
JSAutoCompartment ac(cx, obj);
if (!JS_WrapObject(cx, &proto))
return nullptr;
JSObject *waiver = Wrapper::New(cx, obj, proto,
JS_GetGlobalForObject(cx, obj),
&XrayWaiver);
if (!waiver)
return nullptr;
// Add the new waiver to the map. It's important that we only ever have
// one waiver for the lifetime of the target object.
if (!priv->waiverWrapperMap) {
priv->waiverWrapperMap = JSObject2JSObjectMap::
newMap(XPC_WRAPPER_MAP_SIZE);
MOZ_ASSERT(priv->waiverWrapperMap);
}
if (!priv->waiverWrapperMap->Add(obj, waiver))
return nullptr;
return waiver;
}
JSObject *
WrapperFactory::WaiveXray(JSContext *cx, JSObject *obj)
{
obj = UnwrapObject(obj);
// We have to make sure that if we're wrapping an outer window, that
// the .wrappedJSObject also wraps the outer window.
obj = GetCurrentOuter(cx, obj);
JSObject *waiver = GetXrayWaiver(obj);
if (waiver)
return waiver;
return CreateXrayWaiver(cx, obj);
}
// DoubleWrap is called from PrepareForWrapping to maintain the state that
// we're supposed to waive Xray wrappers for the given on. On entrance, it
// expects |cx->compartment != obj->compartment()|. The returned object will
// be in the same compartment as |obj|.
JSObject *
WrapperFactory::DoubleWrap(JSContext *cx, JSObject *obj, unsigned flags)
{
if (flags & WrapperFactory::WAIVE_XRAY_WRAPPER_FLAG) {
JSAutoCompartment ac(cx, obj);
return WaiveXray(cx, obj);
}
return obj;
}
JSObject *
WrapperFactory::PrepareForWrapping(JSContext *cx, JSObject *scope, JSObject *obj, unsigned flags)
{
// Don't unwrap an outer window, just double wrap it if needed.
if (js::GetObjectClass(obj)->ext.innerObject)
return DoubleWrap(cx, obj, flags);
// Here are the rules for wrapping:
// We should never get a proxy here (the JS engine unwraps those for us).
JS_ASSERT(!IsWrapper(obj));
// As soon as an object is wrapped in a security wrapper, it morphs to be
// a fat wrapper. (see also: bug XXX).
if (IS_SLIM_WRAPPER(obj) && !MorphSlimWrapper(cx, obj))
return nullptr;
// We only hand out outer objects to script.
obj = GetCurrentOuter(cx, obj);
if (!obj)
return nullptr;
if (js::GetObjectClass(obj)->ext.innerObject)
2010-10-18 15:21:50 -07:00
return DoubleWrap(cx, obj, flags);
// Now, our object is ready to be wrapped, but several objects (notably
// nsJSIIDs) have a wrapper per scope. If we are about to wrap one of
// those objects in a security wrapper, then we need to hand back the
// wrapper for the new scope instead. Also, global objects don't move
// between scopes so for those we also want to return the wrapper. So...
if (!IS_WN_WRAPPER(obj) || !js::GetObjectParent(obj))
return DoubleWrap(cx, obj, flags);
XPCWrappedNative *wn = static_cast<XPCWrappedNative *>(xpc_GetJSPrivate(obj));
JSAutoCompartment ac(cx, obj);
XPCCallContext ccx(JS_CALLER, cx, obj);
{
if (NATIVE_HAS_FLAG(&ccx, WantPreCreate)) {
// We have a precreate hook. This object might enforce that we only
// ever create JS object for it.
// Note: this penalizes objects that only have one wrapper, but are
// being accessed across compartments. We would really prefer to
// replace the above code with a test that says "do you only have one
// wrapper?"
JSObject *originalScope = scope;
nsresult rv = wn->GetScriptableInfo()->GetCallback()->
PreCreate(wn->Native(), cx, scope, &scope);
NS_ENSURE_SUCCESS(rv, DoubleWrap(cx, obj, flags));
// If the handed back scope differs from the passed-in scope and is in
// a separate compartment, then this object is explicitly requesting
// that we don't create a second JS object for it: create a security
// wrapper.
if (js::GetObjectCompartment(originalScope) != js::GetObjectCompartment(scope))
return DoubleWrap(cx, obj, flags);
JSObject *currentScope = JS_GetGlobalForObject(cx, obj);
if (MOZ_UNLIKELY(scope != currentScope)) {
// The wrapper claims it wants to be in the new scope, but
// currently has a reflection that lives in the old scope. This
// can mean one of two things, both of which are rare:
//
// 1 - The object has a PreCreate hook (we checked for it above),
// but is deciding to request one-wrapper-per-scope (rather than
// one-wrapper-per-native) for some reason. Usually, a PreCreate
// hook indicates one-wrapper-per-native. In this case we want to
// make a new wrapper in the new scope.
//
// 2 - We're midway through wrapper reparenting. The document has
// moved to a new scope, but |wn| hasn't been moved yet, and
// we ended up calling JS_WrapObject() on its JS object. In this
// case, we want to return the existing wrapper.
//
// So we do a trick: call PreCreate _again_, but say that we're
// wrapping for the old scope, rather than the new one. If (1) is
// the case, then PreCreate will return the scope we pass to it
// (the old scope). If (2) is the case, PreCreate will return the
// scope of the document (the new scope).
JSObject *probe;
rv = wn->GetScriptableInfo()->GetCallback()->
PreCreate(wn->Native(), cx, currentScope, &probe);
// Check for case (2).
if (probe != currentScope) {
MOZ_ASSERT(probe == scope);
return DoubleWrap(cx, obj, flags);
}
// Ok, must be case (1). Fall through and create a new wrapper.
}
// Nasty hack for late-breaking bug 781476. This will confuse identity checks,
// but it's probably better than any of our alternatives.
if (!AccessCheck::isChrome(js::GetObjectCompartment(scope)) &&
AccessCheck::subsumes(js::GetObjectCompartment(scope),
js::GetObjectCompartment(obj)))
{
return DoubleWrap(cx, obj, flags);
}
}
}
// NB: Passing a holder here inhibits slim wrappers under
// WrapNativeToJSVal.
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
// This public WrapNativeToJSVal API enters the compartment of 'scope'
// so we don't have to.
jsval v;
nsresult rv =
nsXPConnect::FastGetXPConnect()->WrapNativeToJSVal(cx, scope, wn->Native(), nullptr,
&NS_GET_IID(nsISupports), false,
&v, getter_AddRefs(holder));
if (NS_SUCCEEDED(rv)) {
obj = JSVAL_TO_OBJECT(v);
NS_ASSERTION(IS_WN_WRAPPER(obj), "bad object");
// Because the underlying native didn't have a PreCreate hook, we had
// to a new (or possibly pre-existing) XPCWN in our compartment.
// This could be a problem for chrome code that passes XPCOM objects
// across compartments, because the effects of QI would disappear across
// compartments.
//
// So whenever we pull an XPCWN across compartments in this manner, we
// give the destination object the union of the two native sets. We try
// to do this cleverly in the common case to avoid too much overhead.
XPCWrappedNative *newwn = static_cast<XPCWrappedNative *>(xpc_GetJSPrivate(obj));
XPCNativeSet *unionSet = XPCNativeSet::GetNewOrUsed(ccx, newwn->GetSet(),
wn->GetSet(), false);
if (!unionSet)
return nullptr;
newwn->SetSet(unionSet);
}
return DoubleWrap(cx, obj, flags);
}
static XPCWrappedNative *
GetWrappedNative(JSContext *cx, JSObject *obj)
{
obj = JS_ObjectToInnerObject(cx, obj);
return IS_WN_WRAPPER(obj)
? static_cast<XPCWrappedNative *>(js::GetObjectPrivate(obj))
: nullptr;
}
enum XrayType {
XrayForDOMObject,
XrayForDOMProxyObject,
XrayForWrappedNative,
NotXray
};
static XrayType
GetXrayType(JSObject *obj)
{
if (mozilla::dom::IsDOMObject(obj))
return XrayForDOMObject;
if (mozilla::dom::oldproxybindings::instanceIsProxy(obj))
return XrayForDOMProxyObject;
js::Class* clasp = js::GetObjectClass(obj);
if (IS_WRAPPER_CLASS(clasp) || clasp->ext.innerObject) {
NS_ASSERTION(clasp->ext.innerObject || IS_WN_WRAPPER_OBJECT(obj),
"We forgot to Morph a slim wrapper!");
return XrayForWrappedNative;
}
return NotXray;
}
JSObject *
WrapperFactory::Rewrap(JSContext *cx, JSObject *obj, JSObject *wrappedProto, JSObject *parent,
unsigned flags)
{
NS_ASSERTION(!IsWrapper(obj) ||
GetProxyHandler(obj) == &XrayWaiver ||
js::GetObjectClass(obj)->ext.innerObject,
"wrapped object passed to rewrap");
NS_ASSERTION(JS_GetClass(obj) != &XrayUtils::HolderClass, "trying to wrap a holder");
JSCompartment *origin = js::GetObjectCompartment(obj);
JSCompartment *target = js::GetContextCompartment(cx);
bool usingXray = false;
// By default we use the wrapped proto of the underlying object as the
// prototype for our wrapper, but we may select something different below.
JSObject *proxyProto = wrappedProto;
Wrapper *wrapper;
CompartmentPrivate *targetdata = GetCompartmentPrivate(target);
if (AccessCheck::isChrome(target)) {
if (AccessCheck::isChrome(origin)) {
wrapper = &CrossCompartmentWrapper::singleton;
} else {
if (flags & WAIVE_XRAY_WRAPPER_FLAG) {
// If we waived the X-ray wrapper for this object, wrap it into a
// special wrapper to transitively maintain the X-ray waiver.
wrapper = &WaiveXrayWrapper::singleton;
} else {
// Native objects must be wrapped into an X-ray wrapper.
XrayType type = GetXrayType(obj);
if (type == XrayForDOMObject) {
wrapper = &XrayDOM::singleton;
} else if (type == XrayForDOMProxyObject) {
wrapper = &XrayProxy::singleton;
} else if (type == XrayForWrappedNative) {
typedef XrayWrapper<CrossCompartmentWrapper> Xray;
usingXray = true;
wrapper = &Xray::singleton;
} else {
wrapper = &CrossCompartmentWrapper::singleton;
}
}
}
} else if (AccessCheck::isChrome(origin)) {
JSFunction *fun = JS_GetObjectFunction(obj);
if (fun) {
if (JS_IsBuiltinEvalFunction(fun) || JS_IsBuiltinFunctionConstructor(fun)) {
JS_ReportError(cx, "Not allowed to access chrome eval or Function from content");
return nullptr;
}
}
XPCWrappedNative *wn;
if (targetdata &&
(wn = GetWrappedNative(cx, obj)) &&
wn->HasProto() && wn->GetProto()->ClassIsDOMObject()) {
typedef XrayWrapper<CrossCompartmentSecurityWrapper> Xray;
usingXray = true;
if (IsLocationObject(obj))
wrapper = &FilteringWrapper<Xray, LocationPolicy>::singleton;
else
wrapper = &FilteringWrapper<Xray, CrossOriginAccessiblePropertiesOnly>::singleton;
} else if (mozilla::dom::IsDOMObject(obj)) {
wrapper = &FilteringWrapper<XrayDOM, CrossOriginAccessiblePropertiesOnly>::singleton;
} else if (mozilla::dom::oldproxybindings::instanceIsProxy(obj)) {
wrapper = &FilteringWrapper<XrayProxy, CrossOriginAccessiblePropertiesOnly>::singleton;
} else if (IsComponentsObject(obj)) {
wrapper = &FilteringWrapper<CrossCompartmentSecurityWrapper,
ComponentsObjectPolicy>::singleton;
} else {
wrapper = &ChromeObjectWrapper::singleton;
// If the prototype of the chrome object being wrapped is a prototype
// for a standard class, use the one from the content compartment so
// that we can safely take advantage of things like .forEach().
//
// If the prototype chain of chrome object |obj| looks like this:
//
// obj => foo => bar => chromeWin.StandardClass.prototype
//
// The prototype chain of COW(obj) looks lke this:
//
// COW(obj) => COW(foo) => COW(bar) => contentWin.StandardClass.prototype
JSProtoKey key = JSProto_Null;
JSObject *unwrappedProto = NULL;
if (wrappedProto && IsCrossCompartmentWrapper(wrappedProto) &&
(unwrappedProto = Wrapper::wrappedObject(wrappedProto))) {
JSAutoCompartment ac(cx, unwrappedProto);
key = JS_IdentifyClassPrototype(cx, unwrappedProto);
}
if (key != JSProto_Null) {
JSObject *homeProto;
if (!JS_GetClassPrototype(cx, key, &homeProto))
return NULL;
MOZ_ASSERT(homeProto);
proxyProto = homeProto;
}
}
} else if (AccessCheck::subsumes(target, origin)) {
// For the same-origin case we use a transparent wrapper, unless one
// of the following is true:
// * The object is flagged as needing a SOW.
// * The object is a Location object.
// * The object is a Components object.
// * The context compartment specifically requested Xray vision into
// same-origin compartments.
//
// The first two cases always require a security wrapper for non-chrome
// access, regardless of the origin of the object.
XrayType type;
if (AccessCheck::needsSystemOnlyWrapper(obj)) {
wrapper = &FilteringWrapper<CrossCompartmentSecurityWrapper,
OnlyIfSubjectIsSystem>::singleton;
} else if (IsLocationObject(obj)) {
typedef XrayWrapper<CrossCompartmentSecurityWrapper> Xray;
usingXray = true;
wrapper = &FilteringWrapper<Xray, LocationPolicy>::singleton;
} else if (IsComponentsObject(obj)) {
wrapper = &FilteringWrapper<CrossCompartmentSecurityWrapper,
ComponentsObjectPolicy>::singleton;
} else if (!targetdata || !targetdata->wantXrays ||
(type = GetXrayType(obj)) == NotXray) {
wrapper = &CrossCompartmentWrapper::singleton;
} else if (type == XrayForDOMObject) {
wrapper = &XrayDOM::singleton;
} else if (type == XrayForDOMProxyObject) {
wrapper = &XrayProxy::singleton;
} else {
typedef XrayWrapper<CrossCompartmentWrapper> Xray;
usingXray = true;
wrapper = &Xray::singleton;
}
} else {
NS_ASSERTION(!AccessCheck::needsSystemOnlyWrapper(obj),
"bad object exposed across origins");
// Cross origin we want to disallow scripting and limit access to
// a predefined set of properties. XrayWrapper adds a property
// (.wrappedJSObject) which allows bypassing the XrayWrapper, but
// we filter out access to that property.
XrayType type = GetXrayType(obj);
if (type == NotXray) {
wrapper = &FilteringWrapper<CrossCompartmentSecurityWrapper,
CrossOriginAccessiblePropertiesOnly>::singleton;
} else if (type == XrayForDOMObject) {
wrapper = &FilteringWrapper<XrayDOM,
CrossOriginAccessiblePropertiesOnly>::singleton;
} else if (type == XrayForDOMProxyObject) {
wrapper = &FilteringWrapper<XrayProxy,
CrossOriginAccessiblePropertiesOnly>::singleton;
} else {
typedef XrayWrapper<CrossCompartmentSecurityWrapper> Xray;
usingXray = true;
// Location objects can become same origin after navigation, so we might
// have to grant transparent access later on.
if (IsLocationObject(obj)) {
wrapper = &FilteringWrapper<Xray, LocationPolicy>::singleton;
} else {
wrapper = &FilteringWrapper<Xray,
CrossOriginAccessiblePropertiesOnly>::singleton;
}
}
}
JSObject *wrapperObj = Wrapper::New(cx, obj, proxyProto, parent, wrapper);
if (!wrapperObj || !usingXray)
return wrapperObj;
JSObject *xrayHolder = XrayUtils::createHolder(cx, obj, parent);
if (!xrayHolder)
return nullptr;
js::SetProxyExtra(wrapperObj, 0, js::ObjectValue(*xrayHolder));
return wrapperObj;
}
JSObject *
WrapperFactory::WrapForSameCompartment(JSContext *cx, JSObject *obj)
{
// Only WNs have same-compartment wrappers.
//
// NB: The contract of WrapForSameCompartment says that |obj| may or may not
// be a security wrapper. This check implicitly handles the security wrapper
// case.
if (!IS_WN_WRAPPER(obj))
return obj;
// Extract the WN. It should exist.
XPCWrappedNative *wn = static_cast<XPCWrappedNative *>(xpc_GetJSPrivate(obj));
MOZ_ASSERT(wn, "Trying to wrap a dead WN!");
// The WN knows what to do.
return wn->GetSameCompartmentSecurityWrapper(cx);
}
typedef FilteringWrapper<XrayWrapper<SameCompartmentSecurityWrapper>, LocationPolicy> LW;
bool
WrapperFactory::IsLocationObject(JSObject *obj)
{
const char *name = js::GetObjectClass(obj)->name;
return name[0] == 'L' && !strcmp(name, "Location");
}
JSObject *
WrapperFactory::WrapLocationObject(JSContext *cx, JSObject *obj)
{
JSObject *xrayHolder = XrayUtils::createHolder(cx, obj, js::GetObjectParent(obj));
if (!xrayHolder)
return nullptr;
JSObject *wrapperObj = Wrapper::New(cx, obj, js::GetObjectProto(obj), js::GetObjectParent(obj),
&LW::singleton);
if (!wrapperObj)
return nullptr;
js::SetProxyExtra(wrapperObj, 0, js::ObjectValue(*xrayHolder));
return wrapperObj;
}
// Call WaiveXrayAndWrap when you have a JS object that you don't want to be
// wrapped in an Xray wrapper. cx->compartment is the compartment that will be
// using the returned object. If the object to be wrapped is already in the
// correct compartment, then this returns the unwrapped object.
bool
WrapperFactory::WaiveXrayAndWrap(JSContext *cx, jsval *vp)
{
if (JSVAL_IS_PRIMITIVE(*vp))
return JS_WrapValue(cx, vp);
JSObject *obj = js::UnwrapObject(JSVAL_TO_OBJECT(*vp));
obj = GetCurrentOuter(cx, obj);
if (js::IsObjectInContextCompartment(obj, cx)) {
*vp = OBJECT_TO_JSVAL(obj);
return true;
}
obj = WaiveXray(cx, obj);
if (!obj)
return false;
*vp = OBJECT_TO_JSVAL(obj);
return JS_WrapValue(cx, vp);
}
JSObject *
WrapperFactory::WrapSOWObject(JSContext *cx, JSObject *obj)
{
JSObject *wrapperObj =
Wrapper::New(cx, obj, JS_GetPrototype(obj), JS_GetGlobalForObject(cx, obj),
&FilteringWrapper<SameCompartmentSecurityWrapper,
OnlyIfSubjectIsSystem>::singleton);
return wrapperObj;
}
bool
WrapperFactory::IsComponentsObject(JSObject *obj)
{
const char *name = js::GetObjectClass(obj)->name;
return name[0] == 'n' && !strcmp(name, "nsXPCComponents");
}
JSObject *
WrapperFactory::WrapComponentsObject(JSContext *cx, JSObject *obj)
{
JSObject *wrapperObj =
Wrapper::New(cx, obj, JS_GetPrototype(obj), JS_GetGlobalForObject(cx, obj),
&FilteringWrapper<SameCompartmentSecurityWrapper, ComponentsObjectPolicy>::singleton);
return wrapperObj;
}
JSObject *
WrapperFactory::WrapForSameCompartmentXray(JSContext *cx, JSObject *obj)
{
// We should be same-compartment here.
MOZ_ASSERT(js::IsObjectInContextCompartment(obj, cx));
// Sort out what kind of Xray we can do. If we can't Xray, bail.
XrayType type = GetXrayType(obj);
if (type == NotXray)
return NULL;
// Select the appropriate proxy handler.
Wrapper *wrapper = NULL;
if (type == XrayForWrappedNative)
wrapper = &XrayWrapper<DirectWrapper>::singleton;
else if (type == XrayForDOMProxyObject)
wrapper = &XrayWrapper<DirectWrapper, ProxyXrayTraits>::singleton;
else if (type == XrayForDOMObject)
wrapper = &XrayWrapper<DirectWrapper, DOMXrayTraits>::singleton;
else
MOZ_NOT_REACHED("Bad Xray type");
// Make the Xray.
JSObject *parent = JS_GetGlobalForObject(cx, obj);
JSObject *wrapperObj = Wrapper::New(cx, obj, NULL, parent, wrapper);
if (!wrapperObj)
return NULL;
// Make the holder. Note that this is currently for WNs only until we fix
// bug 761704.
if (type == XrayForWrappedNative) {
JSObject *xrayHolder = XrayUtils::createHolder(cx, obj, parent);
if (!xrayHolder)
return nullptr;
js::SetProxyExtra(wrapperObj, 0, js::ObjectValue(*xrayHolder));
}
return wrapperObj;
}
/*
* Calls to JS_TransplantObject* should go through these helpers here so that
* waivers get fixed up properly.
*/
static bool
FixWaiverAfterTransplant(JSContext *cx, JSObject *oldWaiver, JSObject *newobj)
{
MOZ_ASSERT(Wrapper::wrapperHandler(oldWaiver) == &XrayWaiver);
MOZ_ASSERT(!js::IsCrossCompartmentWrapper(newobj));
// Create a waiver in the new compartment. We know there's not one already
// because we _just_ transplanted, which means that |newobj| was either
// created from scratch, or was previously cross-compartment wrapper (which
// should have no waiver). CreateXrayWaiver asserts this.
JSObject *newWaiver = WrapperFactory::CreateXrayWaiver(cx, newobj);
if (!newWaiver)
return false;
// Update all the cross-compartment references to oldWaiver to point to
// newWaiver.
if (!js::RemapAllWrappersForObject(cx, oldWaiver, newWaiver))
return false;
// There should be no same-compartment references to oldWaiver, and we
// just remapped all cross-compartment references. It's dead, so we can
// remove it from the map.
CompartmentPrivate *priv = GetCompartmentPrivate(oldWaiver);
JSObject *key = Wrapper::wrappedObject(oldWaiver);
MOZ_ASSERT(priv->waiverWrapperMap->Find(key));
priv->waiverWrapperMap->Remove(key);
return true;
}
JSObject *
TransplantObject(JSContext *cx, JSObject *origobj, JSObject *target)
{
JSObject *oldWaiver = WrapperFactory::GetXrayWaiver(origobj);
JSObject *newIdentity = JS_TransplantObject(cx, origobj, target);
if (!newIdentity || !oldWaiver)
return newIdentity;
if (!FixWaiverAfterTransplant(cx, oldWaiver, newIdentity))
return NULL;
return newIdentity;
}
JSObject *
TransplantObjectWithWrapper(JSContext *cx,
JSObject *origobj, JSObject *origwrapper,
JSObject *targetobj, JSObject *targetwrapper)
{
JSObject *oldWaiver = WrapperFactory::GetXrayWaiver(origobj);
JSObject *newSameCompartmentWrapper =
js_TransplantObjectWithWrapper(cx, origobj, origwrapper, targetobj,
targetwrapper);
if (!newSameCompartmentWrapper || !oldWaiver)
return newSameCompartmentWrapper;
JSObject *newIdentity = Wrapper::wrappedObject(newSameCompartmentWrapper);
JS_ASSERT(js::IsWrapper(newIdentity));
if (!FixWaiverAfterTransplant(cx, oldWaiver, newIdentity))
return NULL;
return newSameCompartmentWrapper;
}
}