2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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/. */
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2012-01-17 22:48:58 +04:00
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#undef GetClassName
|
|
|
|
#endif
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2010-03-13 22:35:27 +03:00
|
|
|
// JavaScript includes
|
|
|
|
#include "jsapi.h"
|
2012-01-15 12:13:09 +04:00
|
|
|
#include "jsfriendapi.h"
|
2010-10-11 02:41:27 +04:00
|
|
|
#include "WrapperFactory.h"
|
2010-10-11 02:42:15 +04:00
|
|
|
#include "AccessCheck.h"
|
2012-04-14 17:05:17 +04:00
|
|
|
#include "XrayWrapper.h"
|
2010-03-13 22:35:27 +03:00
|
|
|
|
2012-04-14 17:05:17 +04:00
|
|
|
#include "xpcpublic.h"
|
2011-05-20 21:23:49 +04:00
|
|
|
#include "xpcprivate.h"
|
2011-09-01 02:10:16 +04:00
|
|
|
#include "XPCWrapper.h"
|
2011-05-20 21:23:49 +04:00
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2012-05-03 08:35:38 +04:00
|
|
|
#include "mozilla/dom/RegisterBindings.h"
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2001-09-01 07:30:51 +04:00
|
|
|
#include "nscore.h"
|
2001-04-01 05:10:59 +04:00
|
|
|
#include "nsDOMClassInfo.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
#include "nsCRT.h"
|
2006-11-12 18:15:37 +03:00
|
|
|
#include "nsCRTGlue.h"
|
2002-03-04 05:25:08 +03:00
|
|
|
#include "nsICategoryManager.h"
|
2002-04-16 15:57:17 +04:00
|
|
|
#include "nsIComponentRegistrar.h"
|
2002-09-04 03:36:13 +04:00
|
|
|
#include "nsXPCOM.h"
|
2015-09-29 07:31:56 +03:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2002-03-04 05:25:08 +03:00
|
|
|
#include "nsISupportsPrimitives.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
#include "nsIXPConnect.h"
|
2001-07-11 13:09:30 +04:00
|
|
|
#include "xptcall.h"
|
2006-05-19 09:57:36 +04:00
|
|
|
#include "nsTArray.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
// General helper includes
|
2005-07-31 00:57:07 +04:00
|
|
|
#include "nsGlobalWindow.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
2001-07-16 06:40:48 +04:00
|
|
|
#include "nsIDOMEvent.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
#include "nsIDOMEventListener.h"
|
2004-07-23 04:26:02 +04:00
|
|
|
#include "nsContentUtils.h"
|
2010-11-10 02:00:01 +03:00
|
|
|
#include "nsIDOMGlobalPropertyInitializer.h"
|
2012-06-15 06:31:55 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-03-04 23:08:23 +04:00
|
|
|
#include "mozilla/Telemetry.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
// Window scriptable helper includes
|
|
|
|
#include "nsScriptNameSpaceManager.h"
|
|
|
|
|
|
|
|
// DOM base includes
|
2011-07-15 14:31:34 +04:00
|
|
|
#include "nsIDOMWindow.h"
|
2004-08-26 07:49:17 +04:00
|
|
|
#include "nsPIDOMWindow.h"
|
2005-12-09 22:08:45 +03:00
|
|
|
#include "nsIDOMConstructor.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
// DOM core includes
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2013-07-30 17:26:27 +04:00
|
|
|
#include "nsIDOMXULButtonElement.h"
|
|
|
|
#include "nsIDOMXULCheckboxElement.h"
|
|
|
|
#include "nsIDOMXULPopupElement.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
// Event related includes
|
2007-05-14 13:11:38 +04:00
|
|
|
#include "nsIDOMEventTarget.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
// CSS related includes
|
2012-08-02 04:32:12 +04:00
|
|
|
#include "nsCSSRules.h"
|
2001-05-14 02:16:45 +04:00
|
|
|
#include "nsIDOMCSSRule.h"
|
2004-07-27 01:49:49 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2005-11-18 16:39:43 +03:00
|
|
|
#include "nsMemory.h"
|
|
|
|
|
2001-07-11 13:09:30 +04:00
|
|
|
// includes needed for the prototype chain interfaces
|
|
|
|
#include "nsIDOMCSSImportRule.h"
|
|
|
|
#include "nsIDOMCSSMediaRule.h"
|
2008-08-11 01:13:49 +04:00
|
|
|
#include "nsIDOMCSSFontFaceRule.h"
|
2004-08-05 22:26:14 +04:00
|
|
|
#include "nsIDOMCSSMozDocumentRule.h"
|
2012-08-02 04:32:12 +04:00
|
|
|
#include "nsIDOMCSSSupportsRule.h"
|
2011-04-12 10:18:43 +04:00
|
|
|
#include "nsIDOMMozCSSKeyframeRule.h"
|
|
|
|
#include "nsIDOMMozCSSKeyframesRule.h"
|
2014-06-12 05:10:00 +04:00
|
|
|
#include "nsIDOMCSSCounterStyleRule.h"
|
2012-09-01 01:21:28 +04:00
|
|
|
#include "nsIDOMCSSPageRule.h"
|
2001-07-11 13:09:30 +04:00
|
|
|
#include "nsIDOMCSSStyleRule.h"
|
|
|
|
#include "nsIDOMXULCommandDispatcher.h"
|
|
|
|
#include "nsIControllers.h"
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2002-03-29 05:46:01 +03:00
|
|
|
#include "nsITreeSelection.h"
|
|
|
|
#include "nsITreeContentView.h"
|
|
|
|
#include "nsITreeView.h"
|
2003-07-09 01:10:52 +04:00
|
|
|
#include "nsIXULTemplateBuilder.h"
|
2003-04-11 04:56:27 +04:00
|
|
|
#endif
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2009-10-16 12:57:32 +04:00
|
|
|
#include "nsIEventListenerService.h"
|
2012-08-27 18:13:02 +04:00
|
|
|
#include "nsIMessageManager.h"
|
2011-04-22 07:17:31 +04:00
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
#include "mozilla/dom/TouchEvent.h"
|
2011-04-26 16:30:17 +04:00
|
|
|
|
2011-05-26 23:58:35 +04:00
|
|
|
#include "nsWrapperCacheInlines.h"
|
2012-09-06 00:49:53 +04:00
|
|
|
#include "mozilla/dom/HTMLCollectionBinding.h"
|
2011-05-26 23:58:35 +04:00
|
|
|
|
2012-09-19 19:23:33 +04:00
|
|
|
#ifdef MOZ_B2G_FM
|
|
|
|
#include "FMRadio.h"
|
|
|
|
#endif
|
|
|
|
|
2012-08-13 07:52:21 +04:00
|
|
|
#include "nsDebug.h"
|
2012-04-27 12:38:14 +04:00
|
|
|
|
2012-05-22 17:46:20 +04:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2013-09-06 21:50:24 +04:00
|
|
|
#include "nsIInterfaceInfoManager.h"
|
2012-03-26 22:59:04 +04:00
|
|
|
|
2012-12-22 12:17:05 +04:00
|
|
|
#ifdef MOZ_TIME_MANAGER
|
|
|
|
#include "TimeManager.h"
|
|
|
|
#endif
|
|
|
|
|
2011-05-25 10:31:59 +04:00
|
|
|
using namespace mozilla;
|
2011-04-08 02:44:03 +04:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
static NS_DEFINE_CID(kDOMSOF_CID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
// NOTE: DEFAULT_SCRIPTABLE_FLAGS and DOM_DEFAULT_SCRIPTABLE_FLAGS
|
|
|
|
// are defined in nsIDOMClassInfo.h.
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
#define ARRAY_SCRIPTABLE_FLAGS \
|
2005-10-04 09:50:42 +04:00
|
|
|
(DOM_DEFAULT_SCRIPTABLE_FLAGS | \
|
2003-09-19 12:43:14 +04:00
|
|
|
nsIXPCScriptable::WANT_GETPROPERTY | \
|
|
|
|
nsIXPCScriptable::WANT_ENUMERATE)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2008-11-13 19:54:52 +03:00
|
|
|
#define EVENTTARGET_SCRIPTABLE_FLAGS \
|
|
|
|
(DOM_DEFAULT_SCRIPTABLE_FLAGS | \
|
2009-03-24 14:02:23 +03:00
|
|
|
nsIXPCScriptable::WANT_ADDPROPERTY)
|
2008-11-13 19:54:52 +03:00
|
|
|
|
2002-08-29 08:05:39 +04:00
|
|
|
#define DOMCLASSINFO_STANDARD_FLAGS \
|
2012-07-13 16:33:25 +04:00
|
|
|
(nsIClassInfo::MAIN_THREAD_ONLY | \
|
|
|
|
nsIClassInfo::DOM_OBJECT | \
|
|
|
|
nsIClassInfo::SINGLETON_CLASSINFO)
|
2002-08-29 08:05:39 +04:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2012-06-25 23:59:42 +04:00
|
|
|
#ifdef DEBUG
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
#define NS_DEFINE_CLASSINFO_DATA_DEBUG(_class) \
|
|
|
|
eDOMClassInfo_##_class##_id,
|
|
|
|
#else
|
|
|
|
#define NS_DEFINE_CLASSINFO_DATA_DEBUG(_class) \
|
|
|
|
// nothing
|
|
|
|
#endif
|
|
|
|
|
2013-08-09 18:35:53 +04:00
|
|
|
#define NS_DEFINE_CLASSINFO_DATA_HELPER(_class, _helper, _flags, \
|
|
|
|
_chromeOnly, _allowXBL) \
|
|
|
|
{ #_class, \
|
|
|
|
nullptr, \
|
2002-03-04 06:42:57 +03:00
|
|
|
{ _helper::doCreate }, \
|
2013-08-09 18:35:53 +04:00
|
|
|
nullptr, \
|
|
|
|
nullptr, \
|
|
|
|
nullptr, \
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
_flags, \
|
2013-08-09 18:35:53 +04:00
|
|
|
true, \
|
|
|
|
_chromeOnly, \
|
|
|
|
_allowXBL, \
|
|
|
|
false, \
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
NS_DEFINE_CLASSINFO_DATA_DEBUG(_class) \
|
|
|
|
},
|
|
|
|
|
2001-07-11 13:09:30 +04:00
|
|
|
#define NS_DEFINE_CLASSINFO_DATA(_class, _helper, _flags) \
|
2013-08-09 18:35:53 +04:00
|
|
|
NS_DEFINE_CLASSINFO_DATA_HELPER(_class, _helper, _flags, false, false)
|
|
|
|
|
|
|
|
#define NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(_class, _helper, _flags) \
|
|
|
|
NS_DEFINE_CLASSINFO_DATA_HELPER(_class, _helper, _flags, true, false)
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2013-08-09 18:35:53 +04:00
|
|
|
#define NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(_class, _helper, _flags) \
|
|
|
|
NS_DEFINE_CLASSINFO_DATA_HELPER(_class, _helper, _flags, true, true)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2012-06-04 23:41:51 +04:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
// This list of NS_DEFINE_CLASSINFO_DATA macros is what gives the DOM
|
|
|
|
// classes their correct behavior when used through XPConnect. The
|
|
|
|
// arguments that are passed to NS_DEFINE_CLASSINFO_DATA are
|
|
|
|
//
|
|
|
|
// 1. Class name as it should appear in JavaScript, this name is also
|
|
|
|
// used to find the id of the class in nsDOMClassInfo
|
|
|
|
// (i.e. e<classname>_id)
|
2001-05-10 13:45:46 +04:00
|
|
|
// 2. Scriptable helper class
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
// 3. nsIClassInfo/nsIXPCScriptable flags (i.e. for GetScriptableFlags)
|
|
|
|
|
2001-07-11 13:09:30 +04:00
|
|
|
static nsDOMClassInfoData sClassInfoData[] = {
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
// Base classes
|
2001-07-25 02:39:11 +04:00
|
|
|
|
2007-11-12 09:43:14 +03:00
|
|
|
NS_DEFINE_CLASSINFO_DATA(DOMPrototype, nsDOMConstructorSH,
|
2007-05-09 16:04:59 +04:00
|
|
|
DOM_BASE_SCRIPTABLE_FLAGS |
|
2011-01-11 23:15:52 +03:00
|
|
|
nsIXPCScriptable::WANT_PRECREATE |
|
2014-11-08 03:07:12 +03:00
|
|
|
nsIXPCScriptable::WANT_RESOLVE |
|
2007-06-14 14:03:44 +04:00
|
|
|
nsIXPCScriptable::WANT_HASINSTANCE |
|
|
|
|
nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE)
|
2007-11-12 09:43:14 +03:00
|
|
|
NS_DEFINE_CLASSINFO_DATA(DOMConstructor, nsDOMConstructorSH,
|
2007-05-09 16:04:59 +04:00
|
|
|
DOM_BASE_SCRIPTABLE_FLAGS |
|
2011-01-11 23:15:52 +03:00
|
|
|
nsIXPCScriptable::WANT_PRECREATE |
|
2014-11-08 03:07:12 +03:00
|
|
|
nsIXPCScriptable::WANT_RESOLVE |
|
2007-05-09 16:04:59 +04:00
|
|
|
nsIXPCScriptable::WANT_HASINSTANCE |
|
|
|
|
nsIXPCScriptable::WANT_CALL |
|
2007-06-14 14:03:44 +04:00
|
|
|
nsIXPCScriptable::WANT_CONSTRUCT |
|
|
|
|
nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
// Misc Core related classes
|
|
|
|
|
|
|
|
// CSS classes
|
2001-05-09 05:39:02 +04:00
|
|
|
NS_DEFINE_CLASSINFO_DATA(CSSStyleRule, nsDOMGenericSH,
|
2001-05-15 12:26:13 +04:00
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
|
|
|
NS_DEFINE_CLASSINFO_DATA(CSSImportRule, nsDOMGenericSH,
|
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
|
|
|
NS_DEFINE_CLASSINFO_DATA(CSSMediaRule, nsDOMGenericSH,
|
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
|
|
|
NS_DEFINE_CLASSINFO_DATA(CSSNameSpaceRule, nsDOMGenericSH,
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
|
|
|
|
|
|
|
// XUL classes
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2013-08-09 18:35:54 +04:00
|
|
|
NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULCommandDispatcher, nsDOMGenericSH,
|
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
2003-04-11 04:56:27 +04:00
|
|
|
#endif
|
2013-08-09 18:35:54 +04:00
|
|
|
NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULControllers, nsNonDOMObjectSH,
|
|
|
|
DEFAULT_SCRIPTABLE_FLAGS)
|
2008-01-16 04:27:53 +03:00
|
|
|
#ifdef MOZ_XUL
|
2013-08-09 18:35:54 +04:00
|
|
|
NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(TreeSelection, nsDOMGenericSH,
|
|
|
|
DEFAULT_SCRIPTABLE_FLAGS)
|
|
|
|
NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(TreeContentView, nsDOMGenericSH,
|
|
|
|
DEFAULT_SCRIPTABLE_FLAGS)
|
2003-04-11 04:56:27 +04:00
|
|
|
#endif
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 15:39:26 +03:00
|
|
|
#ifdef MOZ_XUL
|
2013-08-09 18:35:54 +04:00
|
|
|
NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULTemplateBuilder, nsDOMGenericSH,
|
|
|
|
DEFAULT_SCRIPTABLE_FLAGS)
|
2005-01-17 12:24:56 +03:00
|
|
|
|
2013-08-09 18:35:54 +04:00
|
|
|
NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULTreeBuilder, nsDOMGenericSH,
|
|
|
|
DEFAULT_SCRIPTABLE_FLAGS)
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 15:39:26 +03:00
|
|
|
#endif
|
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
NS_DEFINE_CLASSINFO_DATA(CSSMozDocumentRule, nsDOMGenericSH,
|
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
|
|
|
|
2012-08-02 04:32:12 +04:00
|
|
|
NS_DEFINE_CLASSINFO_DATA(CSSSupportsRule, nsDOMGenericSH,
|
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
|
|
|
|
2008-08-11 01:13:49 +04:00
|
|
|
NS_DEFINE_CLASSINFO_DATA(CSSFontFaceRule, nsDOMGenericSH,
|
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
|
|
|
|
2015-03-06 09:08:06 +03:00
|
|
|
NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ContentFrameMessageManager,
|
|
|
|
nsMessageManagerSH<nsEventTargetSH>,
|
2012-08-27 18:13:02 +04:00
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS |
|
2015-03-06 09:08:06 +03:00
|
|
|
nsIXPCScriptable::WANT_ENUMERATE |
|
2012-08-27 18:13:02 +04:00
|
|
|
nsIXPCScriptable::IS_GLOBAL_OBJECT)
|
2015-03-06 09:08:06 +03:00
|
|
|
NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ContentProcessMessageManager,
|
|
|
|
nsMessageManagerSH<nsDOMGenericSH>,
|
2015-02-20 04:13:02 +03:00
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS |
|
2015-03-06 09:08:06 +03:00
|
|
|
nsIXPCScriptable::WANT_ENUMERATE |
|
2015-02-20 04:13:02 +03:00
|
|
|
nsIXPCScriptable::IS_GLOBAL_OBJECT)
|
2012-08-27 18:13:02 +04:00
|
|
|
NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ChromeMessageBroadcaster, nsDOMGenericSH,
|
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
|
|
|
NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ChromeMessageSender, nsDOMGenericSH,
|
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
2010-02-25 08:58:18 +03:00
|
|
|
|
2013-08-02 13:38:49 +04:00
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
NS_DEFINE_CLASSINFO_DATA(MozCSSKeyframeRule, nsDOMGenericSH,
|
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
|
|
|
NS_DEFINE_CLASSINFO_DATA(MozCSSKeyframesRule, nsDOMGenericSH,
|
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
2011-04-22 07:17:31 +04:00
|
|
|
|
2014-06-12 05:10:00 +04:00
|
|
|
NS_DEFINE_CLASSINFO_DATA(CSSCounterStyleRule, nsDOMGenericSH,
|
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
|
|
|
|
2012-09-01 01:21:28 +04:00
|
|
|
NS_DEFINE_CLASSINFO_DATA(CSSPageRule, nsDOMGenericSH,
|
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
|
|
|
|
2013-05-20 06:59:20 +04:00
|
|
|
NS_DEFINE_CLASSINFO_DATA(CSSFontFeatureValuesRule, nsDOMGenericSH,
|
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
2013-07-30 17:26:27 +04:00
|
|
|
|
2013-08-09 18:35:54 +04:00
|
|
|
NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULControlElement, nsDOMGenericSH,
|
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
|
|
|
NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULLabeledControlElement, nsDOMGenericSH,
|
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
|
|
|
NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULButtonElement, nsDOMGenericSH,
|
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
|
|
|
NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULCheckboxElement, nsDOMGenericSH,
|
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
|
|
|
NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULPopupElement, nsDOMGenericSH,
|
|
|
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
};
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIXPConnect *nsDOMClassInfo::sXPConnect = nullptr;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsDOMClassInfo::sIsInitialized = false;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
|
2013-12-17 06:27:43 +04:00
|
|
|
jsid nsDOMClassInfo::sConstructor_id = JSID_VOID;
|
|
|
|
jsid nsDOMClassInfo::sWrappedJSObject_id = JSID_VOID;
|
2011-06-29 02:37:31 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
static const JSClass *sObjectClass = nullptr;
|
2011-12-29 01:22:05 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set our JSClass pointer for the Object class
|
|
|
|
*/
|
|
|
|
static void
|
2012-09-04 03:42:10 +04:00
|
|
|
FindObjectClass(JSContext* cx, JSObject* aGlobalObject)
|
2011-12-29 01:22:05 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!sObjectClass,
|
|
|
|
"Double set of sObjectClass");
|
2013-05-03 22:53:32 +04:00
|
|
|
JS::Rooted<JSObject*> obj(cx), proto(cx, aGlobalObject);
|
2011-12-29 01:22:05 +04:00
|
|
|
do {
|
|
|
|
obj = proto;
|
2013-05-05 11:03:14 +04:00
|
|
|
js::GetObjectProto(cx, obj, &proto);
|
2011-12-29 01:22:05 +04:00
|
|
|
} while (proto);
|
|
|
|
|
|
|
|
sObjectClass = js::GetObjectJSClass(obj);
|
|
|
|
}
|
|
|
|
|
2012-04-27 12:38:14 +04:00
|
|
|
// Helper to handle torn-down inner windows.
|
|
|
|
static inline nsresult
|
|
|
|
SetParentToWindow(nsGlobalWindow *win, JSObject **parent)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(win);
|
|
|
|
MOZ_ASSERT(win->IsInnerWindow());
|
|
|
|
*parent = win->FastGetGlobalJSObject();
|
|
|
|
|
|
|
|
if (MOZ_UNLIKELY(!*parent)) {
|
2012-09-11 21:23:31 +04:00
|
|
|
// The inner window has been torn down. The scope is dying, so don't create
|
|
|
|
// any new wrappers.
|
2012-04-27 12:38:14 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
// static
|
2010-03-05 03:17:05 +03:00
|
|
|
|
|
|
|
nsISupports *
|
|
|
|
nsDOMClassInfo::GetNative(nsIXPConnectWrappedNative *wrapper, JSObject *obj)
|
|
|
|
{
|
2011-10-04 18:06:54 +04:00
|
|
|
return wrapper ? wrapper->Native() : static_cast<nsISupports*>(js::GetObjectPrivate(obj));
|
2010-03-05 03:17:05 +03:00
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
nsresult
|
2002-08-16 01:18:20 +04:00
|
|
|
nsDOMClassInfo::DefineStaticJSVals(JSContext *cx)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
{
|
2010-07-15 10:19:36 +04:00
|
|
|
#define SET_JSID_TO_STRING(_id, _cx, _str) \
|
2015-06-30 17:58:31 +03:00
|
|
|
if (JSString *str = ::JS_AtomizeAndPinString(_cx, _str)) \
|
2011-05-17 23:15:12 +04:00
|
|
|
_id = INTERNED_STRING_TO_JSID(_cx, str); \
|
2010-07-15 10:19:36 +04:00
|
|
|
else \
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-08-16 01:18:20 +04:00
|
|
|
|
2010-07-15 10:19:36 +04:00
|
|
|
SET_JSID_TO_STRING(sConstructor_id, cx, "constructor");
|
2010-09-18 01:54:40 +04:00
|
|
|
SET_JSID_TO_STRING(sWrappedJSObject_id, cx, "wrappedJSObject");
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-03 00:54:53 +04:00
|
|
|
// static
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-07-03 00:54:53 +04:00
|
|
|
nsDOMClassInfo::ObjectIsNativeWrapper(JSContext* cx, JSObject* obj)
|
|
|
|
{
|
2011-02-17 07:29:14 +03:00
|
|
|
return xpc::WrapperFactory::IsXrayWrapper(obj) &&
|
2012-09-11 12:05:10 +04:00
|
|
|
xpc::AccessCheck::wrapperSubsumes(obj);
|
2010-07-03 00:54:53 +04:00
|
|
|
}
|
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
nsDOMClassInfo::nsDOMClassInfo(nsDOMClassInfoData* aData) : mData(aData)
|
2001-04-01 05:10:59 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMClassInfo::~nsDOMClassInfo()
|
|
|
|
{
|
2002-03-04 05:25:08 +03:00
|
|
|
if (IS_EXTERNAL(mData->mCachedClassInfo)) {
|
|
|
|
// Some compilers don't like delete'ing a const nsDOMClassInfo*
|
2007-07-08 11:08:04 +04:00
|
|
|
nsDOMClassInfoData* data = const_cast<nsDOMClassInfoData*>(mData);
|
|
|
|
delete static_cast<nsExternalDOMClassInfoData*>(data);
|
2002-03-04 05:25:08 +03:00
|
|
|
}
|
2001-04-01 05:10:59 +04:00
|
|
|
}
|
|
|
|
|
2003-09-08 02:05:34 +04:00
|
|
|
NS_IMPL_ADDREF(nsDOMClassInfo)
|
|
|
|
NS_IMPL_RELEASE(nsDOMClassInfo)
|
2001-04-01 05:10:59 +04:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDOMClassInfo)
|
2009-09-29 01:00:35 +04:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsXPCClassInfo)))
|
|
|
|
foundInterface = static_cast<nsIClassInfo*>(
|
|
|
|
static_cast<nsXPCClassInfo*>(this));
|
|
|
|
else
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
|
2001-04-01 05:10:59 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
|
2009-09-29 01:00:35 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIClassInfo)
|
2001-04-01 05:10:59 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2013-09-11 16:49:05 +04:00
|
|
|
static const JSClass sDOMConstructorProtoClass = {
|
2014-11-22 21:23:39 +03:00
|
|
|
"DOM Constructor.prototype", 0
|
2001-07-11 13:09:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
CutPrefix(const char *aName) {
|
|
|
|
static const char prefix_nsIDOM[] = "nsIDOM";
|
|
|
|
static const char prefix_nsI[] = "nsI";
|
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
if (strncmp(aName, prefix_nsIDOM, sizeof(prefix_nsIDOM) - 1) == 0) {
|
2001-07-11 13:09:30 +04:00
|
|
|
return aName + sizeof(prefix_nsIDOM) - 1;
|
|
|
|
}
|
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
if (strncmp(aName, prefix_nsI, sizeof(prefix_nsI) - 1) == 0) {
|
2001-07-11 13:09:30 +04:00
|
|
|
return aName + sizeof(prefix_nsI) - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsDOMClassInfo::RegisterClassProtos(int32_t aClassInfoID)
|
2001-07-11 13:09:30 +04:00
|
|
|
{
|
2013-08-20 03:24:29 +04:00
|
|
|
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
|
2007-11-13 13:35:49 +03:00
|
|
|
NS_ENSURE_TRUE(nameSpaceManager, NS_ERROR_NOT_INITIALIZED);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool found_old;
|
2001-07-11 13:09:30 +04:00
|
|
|
|
|
|
|
const nsIID *primary_iid = sClassInfoData[aClassInfoID].mProtoChainInterface;
|
|
|
|
|
|
|
|
if (!primary_iid || primary_iid == &NS_GET_IID(nsISupports)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-11-10 19:19:44 +03:00
|
|
|
nsCOMPtr<nsIInterfaceInfoManager>
|
|
|
|
iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID));
|
2001-07-11 13:09:30 +04:00
|
|
|
NS_ENSURE_TRUE(iim, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInterfaceInfo> if_info;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool first = true;
|
2001-07-11 13:09:30 +04:00
|
|
|
|
|
|
|
iim->GetInfoForIID(primary_iid, getter_AddRefs(if_info));
|
|
|
|
|
|
|
|
while (if_info) {
|
2012-07-30 18:20:58 +04:00
|
|
|
const nsIID *iid = nullptr;
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2008-01-12 07:30:42 +03:00
|
|
|
if_info->GetIIDShared(&iid);
|
2001-07-11 13:09:30 +04:00
|
|
|
NS_ENSURE_TRUE(iid, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
if (iid->Equals(NS_GET_IID(nsISupports))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
const char *name = nullptr;
|
2008-01-12 07:30:42 +03:00
|
|
|
if_info->GetNameShared(&name);
|
|
|
|
NS_ENSURE_TRUE(name, NS_ERROR_UNEXPECTED);
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2007-11-13 13:35:49 +03:00
|
|
|
nameSpaceManager->RegisterClassProto(CutPrefix(name), iid, &found_old);
|
2001-07-11 13:09:30 +04:00
|
|
|
|
|
|
|
if (first) {
|
2011-10-17 18:59:28 +04:00
|
|
|
first = false;
|
2001-07-11 13:09:30 +04:00
|
|
|
} else if (found_old) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-01-11 02:45:06 +03:00
|
|
|
nsCOMPtr<nsIInterfaceInfo> tmp(if_info);
|
2001-07-11 13:09:30 +04:00
|
|
|
tmp->GetParent(getter_AddRefs(if_info));
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
// static
|
|
|
|
nsresult
|
|
|
|
nsDOMClassInfo::RegisterExternalClasses()
|
|
|
|
{
|
2013-08-20 03:24:29 +04:00
|
|
|
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
|
2007-11-13 13:35:49 +03:00
|
|
|
NS_ENSURE_TRUE(nameSpaceManager, NS_ERROR_NOT_INITIALIZED);
|
2002-03-04 05:25:08 +03:00
|
|
|
|
2004-11-01 21:50:36 +03:00
|
|
|
nsCOMPtr<nsIComponentRegistrar> registrar;
|
2007-11-13 13:35:49 +03:00
|
|
|
nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(registrar));
|
2004-11-01 21:50:36 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
nsCOMPtr<nsICategoryManager> cm =
|
|
|
|
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> e;
|
|
|
|
rv = cm->EnumerateCategory(JAVASCRIPT_DOM_CLASS, getter_AddRefs(e));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-08-27 01:20:34 +04:00
|
|
|
nsXPIDLCString contractId;
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString categoryEntry;
|
2002-03-04 05:25:08 +03:00
|
|
|
nsCOMPtr<nsISupports> entry;
|
|
|
|
|
|
|
|
while (NS_SUCCEEDED(e->GetNext(getter_AddRefs(entry)))) {
|
2002-08-06 04:53:19 +04:00
|
|
|
nsCOMPtr<nsISupportsCString> category(do_QueryInterface(entry));
|
2002-03-04 05:25:08 +03:00
|
|
|
|
|
|
|
if (!category) {
|
2002-08-06 04:53:19 +04:00
|
|
|
NS_WARNING("Category entry not an nsISupportsCString!");
|
2002-03-04 05:25:08 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-08-27 01:20:34 +04:00
|
|
|
rv = category->GetData(categoryEntry);
|
2002-03-04 05:25:08 +03:00
|
|
|
|
2002-08-27 01:20:34 +04:00
|
|
|
cm->GetCategoryEntry(JAVASCRIPT_DOM_CLASS, categoryEntry.get(),
|
2002-03-04 05:25:08 +03:00
|
|
|
getter_Copies(contractId));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2004-11-01 21:50:36 +03:00
|
|
|
nsCID *cid;
|
|
|
|
rv = registrar->ContractIDToCID(contractId, &cid);
|
2002-03-04 05:25:08 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Bad contract id registered with the script namespace manager");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-11-13 13:35:49 +03:00
|
|
|
rv = nameSpaceManager->RegisterExternalClassName(categoryEntry.get(), *cid);
|
2015-03-27 03:01:12 +03:00
|
|
|
free(cid);
|
2002-03-04 05:25:08 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return nameSpaceManager->RegisterExternalInterfaces(true);
|
2002-03-04 05:25:08 +03:00
|
|
|
}
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2014-02-16 01:12:34 +04:00
|
|
|
#define _DOM_CLASSINFO_MAP_BEGIN(_class, _ifptr, _has_class_if) \
|
2001-07-11 13:09:30 +04:00
|
|
|
{ \
|
|
|
|
nsDOMClassInfoData &d = sClassInfoData[eDOMClassInfo_##_class##_id]; \
|
|
|
|
d.mProtoChainInterface = _ifptr; \
|
2001-11-02 07:49:07 +03:00
|
|
|
d.mHasClassInterface = _has_class_if; \
|
2001-07-11 13:09:30 +04:00
|
|
|
static const nsIID *interface_list[] = {
|
|
|
|
|
|
|
|
#define DOM_CLASSINFO_MAP_BEGIN(_class, _interface) \
|
2014-02-16 01:12:34 +04:00
|
|
|
_DOM_CLASSINFO_MAP_BEGIN(_class, &NS_GET_IID(_interface), true)
|
2013-02-09 00:25:37 +04:00
|
|
|
|
2001-11-02 07:49:07 +03:00
|
|
|
#define DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(_class, _interface) \
|
2014-02-16 01:12:34 +04:00
|
|
|
_DOM_CLASSINFO_MAP_BEGIN(_class, &NS_GET_IID(_interface), false)
|
2001-07-11 13:09:30 +04:00
|
|
|
|
|
|
|
#define DOM_CLASSINFO_MAP_ENTRY(_if) \
|
|
|
|
&NS_GET_IID(_if),
|
|
|
|
|
2011-08-24 23:49:25 +04:00
|
|
|
#define DOM_CLASSINFO_MAP_CONDITIONAL_ENTRY(_if, _cond) \
|
2012-07-30 18:20:58 +04:00
|
|
|
(_cond) ? &NS_GET_IID(_if) : nullptr,
|
2011-08-24 23:49:25 +04:00
|
|
|
|
2001-07-11 13:09:30 +04:00
|
|
|
#define DOM_CLASSINFO_MAP_END \
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr \
|
2001-07-11 13:09:30 +04:00
|
|
|
}; \
|
|
|
|
\
|
2011-08-24 23:49:25 +04:00
|
|
|
/* Compact the interface list */ \
|
2011-10-11 09:50:08 +04:00
|
|
|
size_t count = ArrayLength(interface_list); \
|
2011-08-24 23:49:25 +04:00
|
|
|
/* count is the number of array entries, which is one greater than the */ \
|
|
|
|
/* number of interfaces due to the terminating null */ \
|
|
|
|
for (size_t i = 0; i < count - 1; ++i) { \
|
|
|
|
if (!interface_list[i]) { \
|
2011-12-15 08:42:15 +04:00
|
|
|
/* We are moving the element at index i+1 and successors, */ \
|
|
|
|
/* so we must move only count - (i+1) elements total. */ \
|
2011-08-24 23:49:25 +04:00
|
|
|
memmove(&interface_list[i], &interface_list[i+1], \
|
2011-12-15 08:42:15 +04:00
|
|
|
sizeof(nsIID*) * (count - (i+1))); \
|
2011-08-24 23:49:25 +04:00
|
|
|
/* Make sure to examine the new pointer we ended up with at this */ \
|
|
|
|
/* slot, since it may be null too */ \
|
|
|
|
--i; \
|
|
|
|
--count; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2001-07-11 13:09:30 +04:00
|
|
|
d.mInterfaces = interface_list; \
|
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
nsresult
|
|
|
|
nsDOMClassInfo::Init()
|
|
|
|
{
|
2003-01-22 06:18:41 +03:00
|
|
|
/* Errors that can trigger early returns are done first,
|
|
|
|
otherwise nsDOMClassInfo is left in a half inited state. */
|
2013-07-18 21:59:53 +04:00
|
|
|
static_assert(sizeof(uintptr_t) == sizeof(void*),
|
|
|
|
"BAD! You'll need to adjust the size of uintptr_t to the "
|
|
|
|
"size of a pointer on your platform.");
|
2002-03-04 05:25:08 +03:00
|
|
|
|
2003-01-22 06:18:41 +03:00
|
|
|
NS_ENSURE_TRUE(!sIsInitialized, NS_ERROR_ALREADY_INITIALIZED);
|
|
|
|
|
2013-08-20 03:24:29 +04:00
|
|
|
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
|
2007-11-13 13:35:49 +03:00
|
|
|
NS_ENSURE_TRUE(nameSpaceManager, NS_ERROR_NOT_INITIALIZED);
|
2003-01-22 06:18:41 +03:00
|
|
|
|
2014-08-08 17:03:29 +04:00
|
|
|
NS_ADDREF(sXPConnect = nsContentUtils::XPConnect());
|
2003-01-22 06:18:41 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIXPCFunctionThisTranslator> elt = new nsEventListenerThisTranslator();
|
2012-10-02 12:24:08 +04:00
|
|
|
sXPConnect->SetFunctionThisTranslator(NS_GET_IID(nsIDOMEventListener), elt);
|
2003-01-22 06:18:41 +03:00
|
|
|
|
2013-05-06 17:04:17 +04:00
|
|
|
AutoSafeJSContext cx;
|
2003-01-22 06:18:41 +03:00
|
|
|
|
2009-03-24 14:02:30 +03:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(DOMPrototype, nsIDOMDOMConstructor)
|
2007-11-12 09:43:14 +03:00
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMConstructor)
|
2007-05-09 16:04:59 +04:00
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
2007-11-12 09:43:14 +03:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN(DOMConstructor, nsIDOMDOMConstructor)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMConstructor)
|
2005-12-09 22:08:45 +03:00
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
2001-07-11 13:09:30 +04:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN(CSSStyleRule, nsIDOMCSSStyleRule)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSStyleRule)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
|
|
|
DOM_CLASSINFO_MAP_BEGIN(CSSImportRule, nsIDOMCSSImportRule)
|
2001-08-05 01:19:53 +04:00
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSImportRule)
|
2001-07-11 13:09:30 +04:00
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
|
|
|
DOM_CLASSINFO_MAP_BEGIN(CSSMediaRule, nsIDOMCSSMediaRule)
|
2001-09-05 04:00:18 +04:00
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSMediaRule)
|
2001-07-11 13:09:30 +04:00
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
2001-11-07 10:52:41 +03:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(CSSNameSpaceRule, nsIDOMCSSRule)
|
2001-07-11 13:09:30 +04:00
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2001-07-11 13:09:30 +04:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN(XULCommandDispatcher, nsIDOMXULCommandDispatcher)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMXULCommandDispatcher)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
2003-04-11 04:56:27 +04:00
|
|
|
#endif
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2006-02-23 06:17:11 +03:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(XULControllers, nsIControllers)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIControllers)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
2008-01-16 04:27:53 +03:00
|
|
|
#ifdef MOZ_XUL
|
2002-03-29 05:46:01 +03:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN(TreeSelection, nsITreeSelection)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsITreeSelection)
|
2001-07-11 13:09:30 +04:00
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN(TreeContentView, nsITreeContentView)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsITreeContentView)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsITreeView)
|
2002-01-05 10:17:10 +03:00
|
|
|
DOM_CLASSINFO_MAP_END
|
2003-04-11 04:56:27 +04:00
|
|
|
#endif
|
2002-01-05 10:17:10 +03:00
|
|
|
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 15:39:26 +03:00
|
|
|
#ifdef MOZ_XUL
|
2005-01-17 12:24:56 +03:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN(XULTemplateBuilder, nsIXULTemplateBuilder)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIXULTemplateBuilder)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 15:39:26 +03:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN(XULTreeBuilder, nsIXULTreeBuilder)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIXULTreeBuilder)
|
2013-01-29 21:51:55 +04:00
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIXULTemplateBuilder)
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 15:39:26 +03:00
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsITreeView)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
#endif
|
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN(CSSMozDocumentRule, nsIDOMCSSMozDocumentRule)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSMozDocumentRule)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
2012-08-02 04:32:12 +04:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN(CSSSupportsRule, nsIDOMCSSSupportsRule)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSSupportsRule)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
2008-08-11 01:13:49 +04:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN(CSSFontFaceRule, nsIDOMCSSFontFaceRule)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSFontFaceRule)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
2012-08-27 18:13:02 +04:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(ContentFrameMessageManager, nsISupports)
|
2010-05-18 16:28:37 +04:00
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
|
2012-08-27 18:13:02 +04:00
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIMessageListenerManager)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIMessageSender)
|
2010-08-31 22:58:35 +04:00
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsISyncMessageSender)
|
2010-05-18 16:28:37 +04:00
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIContentFrameMessageManager)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
2015-02-20 04:13:02 +03:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(ContentProcessMessageManager, nsISupports)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIMessageListenerManager)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIMessageSender)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsISyncMessageSender)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIContentProcessMessageManager)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
2012-08-27 18:13:02 +04:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(ChromeMessageBroadcaster, nsISupports)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIFrameScriptLoader)
|
2015-02-20 04:13:02 +03:00
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIProcessScriptLoader)
|
2015-05-01 04:20:51 +03:00
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIGlobalProcessScriptLoader)
|
2012-08-27 18:13:02 +04:00
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIMessageListenerManager)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIMessageBroadcaster)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
|
|
|
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(ChromeMessageSender, nsISupports)
|
2012-12-22 16:00:10 +04:00
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIProcessChecker)
|
2012-08-27 18:13:02 +04:00
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIFrameScriptLoader)
|
2015-02-20 04:13:02 +03:00
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIProcessScriptLoader)
|
2012-08-27 18:13:02 +04:00
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIMessageListenerManager)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIMessageSender)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN(MozCSSKeyframeRule, nsIDOMMozCSSKeyframeRule)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozCSSKeyframeRule)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
|
|
|
DOM_CLASSINFO_MAP_BEGIN(MozCSSKeyframesRule, nsIDOMMozCSSKeyframesRule)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozCSSKeyframesRule)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
2014-06-12 05:10:00 +04:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN(CSSCounterStyleRule, nsIDOMCSSCounterStyleRule)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSCounterStyleRule)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
2012-09-01 01:21:28 +04:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN(CSSPageRule, nsIDOMCSSPageRule)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSPageRule)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
2013-05-20 06:59:20 +04:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN(CSSFontFeatureValuesRule, nsIDOMCSSFontFeatureValuesRule)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSFontFeatureValuesRule)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
2013-08-09 18:35:54 +04:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(XULControlElement, nsIDOMXULControlElement)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMXULControlElement)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
|
|
|
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(XULLabeledControlElement, nsIDOMXULLabeledControlElement)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMXULLabeledControlElement)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
2013-07-30 17:26:27 +04:00
|
|
|
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(XULButtonElement, nsIDOMXULButtonElement)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMXULButtonElement)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
|
|
|
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(XULCheckboxElement, nsIDOMXULCheckboxElement)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMXULCheckboxElement)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
|
|
|
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(XULPopupElement, nsIDOMXULPopupElement)
|
|
|
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMXULPopupElement)
|
|
|
|
DOM_CLASSINFO_MAP_END
|
|
|
|
|
2013-07-18 21:59:53 +04:00
|
|
|
static_assert(MOZ_ARRAY_LENGTH(sClassInfoData) == eDOMClassInfoIDCount,
|
|
|
|
"The number of items in sClassInfoData doesn't match the "
|
|
|
|
"number of nsIDOMClassInfo ID's, this is bad! Fix it!");
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2013-02-12 03:15:55 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
for (size_t i = 0; i < eDOMClassInfoIDCount; i++) {
|
|
|
|
if (!sClassInfoData[i].u.mConstructorFptr ||
|
|
|
|
sClassInfoData[i].mDebugID != i) {
|
2013-06-29 05:38:30 +04:00
|
|
|
MOZ_CRASH("Class info data out of sync, you forgot to update "
|
2013-06-29 05:38:32 +04:00
|
|
|
"nsDOMClassInfo.h and nsDOMClassInfo.cpp! Fix this, "
|
|
|
|
"mozilla will not work without this fixed!");
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
2013-02-12 03:15:55 +04:00
|
|
|
}
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2013-02-12 03:15:55 +04:00
|
|
|
for (size_t i = 0; i < eDOMClassInfoIDCount; i++) {
|
|
|
|
if (!sClassInfoData[i].mInterfaces) {
|
2013-06-29 05:38:30 +04:00
|
|
|
MOZ_CRASH("Class info data without an interface list! Fix this, "
|
2013-06-29 05:38:32 +04:00
|
|
|
"mozilla will not work without this fixed!");
|
2013-02-12 03:15:55 +04:00
|
|
|
}
|
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Initialize static JSString's
|
2002-08-16 01:18:20 +04:00
|
|
|
DefineStaticJSVals(cx);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t i;
|
2001-07-11 13:09:30 +04:00
|
|
|
|
|
|
|
for (i = 0; i < eDOMClassInfoIDCount; ++i) {
|
2014-02-16 01:12:34 +04:00
|
|
|
if (i == eDOMClassInfo_DOMPrototype_id) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-08-09 11:19:42 +04:00
|
|
|
nsDOMClassInfoData& data = sClassInfoData[i];
|
|
|
|
nameSpaceManager->RegisterClassName(data.mName, i, data.mChromeOnly,
|
2014-02-16 01:12:34 +04:00
|
|
|
data.mAllowXBL, &data.mNameUTF16);
|
2001-07-11 13:09:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < eDOMClassInfoIDCount; ++i) {
|
|
|
|
RegisterClassProtos(i);
|
|
|
|
}
|
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
RegisterExternalClasses();
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
sIsInitialized = true;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-01 05:10:59 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsDOMClassInfo::GetInterfaces(uint32_t *aCount, nsIID ***aArray)
|
2001-04-01 05:10:59 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = 0;
|
2001-04-01 05:10:59 +04:00
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
while (mData->mInterfaces[count]) {
|
2001-07-11 13:09:30 +04:00
|
|
|
count++;
|
|
|
|
}
|
2001-04-01 05:10:59 +04:00
|
|
|
|
2001-07-11 13:09:30 +04:00
|
|
|
*aCount = count;
|
2001-04-01 05:10:59 +04:00
|
|
|
|
2001-07-11 13:09:30 +04:00
|
|
|
if (!count) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aArray = nullptr;
|
2001-04-01 05:10:59 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-27 03:01:12 +03:00
|
|
|
*aArray = static_cast<nsIID **>(moz_xmalloc(count * sizeof(nsIID *)));
|
2001-04-01 05:10:59 +04:00
|
|
|
NS_ENSURE_TRUE(*aArray, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i;
|
2001-07-11 13:09:30 +04:00
|
|
|
for (i = 0; i < count; i++) {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsIID *iid = static_cast<nsIID *>(nsMemory::Clone(mData->mInterfaces[i],
|
2002-08-16 01:18:20 +04:00
|
|
|
sizeof(nsIID)));
|
2001-04-01 05:10:59 +04:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
if (!iid) {
|
|
|
|
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(i, *aArray);
|
2001-04-01 05:10:59 +04:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2001-04-01 05:10:59 +04:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
*((*aArray) + i) = iid;
|
2001-04-01 05:10:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-03-29 17:52:54 +03:00
|
|
|
nsDOMClassInfo::GetScriptableHelper(nsIXPCScriptable **_retval)
|
2001-04-01 05:10:59 +04:00
|
|
|
{
|
2015-03-29 17:52:54 +03:00
|
|
|
nsCOMPtr<nsIXPCScriptable> rval = this;
|
|
|
|
rval.forget(_retval);
|
2001-04-01 05:10:59 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
nsDOMClassInfo::GetContractID(char **aContractID)
|
2001-04-01 05:10:59 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aContractID = nullptr;
|
2001-04-01 05:10:59 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-19 13:14:19 +04:00
|
|
|
NS_IMETHODIMP
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
nsDOMClassInfo::GetClassDescription(char **aClassDescription)
|
|
|
|
{
|
|
|
|
return GetClassName(aClassDescription);
|
|
|
|
}
|
|
|
|
|
2001-04-01 05:10:59 +04:00
|
|
|
NS_IMETHODIMP
|
2001-08-07 07:59:29 +04:00
|
|
|
nsDOMClassInfo::GetClassID(nsCID **aClassID)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aClassID = nullptr;
|
2001-08-07 07:59:29 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMClassInfo::GetClassIDNoAlloc(nsCID *aClassID)
|
2001-04-01 05:10:59 +04:00
|
|
|
{
|
2001-07-31 23:05:34 +04:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2001-04-01 05:10:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsDOMClassInfo::GetFlags(uint32_t *aFlags)
|
2001-04-01 05:10:59 +04:00
|
|
|
{
|
2002-08-29 08:05:39 +04:00
|
|
|
*aFlags = DOMCLASSINFO_STANDARD_FLAGS;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIXPCScriptable
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMClassInfo::GetClassName(char **aClassName)
|
|
|
|
{
|
2006-11-12 18:15:37 +03:00
|
|
|
*aClassName = NS_strdup(mData->mName);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-17 12:11:16 +04:00
|
|
|
// virtual
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2012-06-17 12:11:16 +04:00
|
|
|
nsDOMClassInfo::GetScriptableFlags()
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
{
|
2012-06-17 12:11:16 +04:00
|
|
|
return mData->mScriptableFlags;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMClassInfo::PreCreate(nsISupports *nativeObj, JSContext *cx,
|
|
|
|
JSObject *globalObj, JSObject **parentObj)
|
|
|
|
{
|
2005-09-13 04:26:53 +04:00
|
|
|
*parentObj = globalObj;
|
|
|
|
return NS_OK;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMClassInfo::AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2015-03-28 16:47:02 +03:00
|
|
|
JSObject *obj, jsid id, JS::Handle<JS::Value> val,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *_retval)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
{
|
2006-02-22 05:18:33 +03:00
|
|
|
NS_WARNING("nsDOMClassInfo::AddProperty Don't call me!");
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMClassInfo::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2015-07-18 22:45:35 +03:00
|
|
|
JSObject *obj, jsid id, JS::Value *vp,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *_retval)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
{
|
2006-02-22 05:18:33 +03:00
|
|
|
NS_WARNING("nsDOMClassInfo::GetProperty Don't call me!");
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMClassInfo::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2015-07-18 22:45:35 +03:00
|
|
|
JSObject *obj, jsid id, JS::Value *vp,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *_retval)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
{
|
2006-02-22 05:18:33 +03:00
|
|
|
NS_WARNING("nsDOMClassInfo::SetProperty Don't call me!");
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMClassInfo::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2011-09-29 10:19:26 +04:00
|
|
|
JSObject *obj, bool *_retval)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
{
|
2001-09-01 07:30:51 +04:00
|
|
|
return NS_OK;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-12-11 21:31:10 +03:00
|
|
|
nsDOMClassInfo::NewEnumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|
|
|
JSObject *obj, JS::AutoIdVector &properties,
|
|
|
|
bool *_retval)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
{
|
2006-02-22 05:18:33 +03:00
|
|
|
NS_WARNING("nsDOMClassInfo::NewEnumerate Don't call me!");
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2014-11-08 03:07:12 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMClassInfo::Resolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2014-11-08 03:15:52 +03:00
|
|
|
JSObject *aObj, jsid aId, bool *resolvedp, bool *_retval)
|
2003-01-22 06:22:35 +03:00
|
|
|
{
|
2014-11-08 03:15:52 +03:00
|
|
|
JS::Rooted<JSObject*> obj(cx, aObj);
|
|
|
|
JS::Rooted<jsid> id(cx, aId);
|
|
|
|
|
2014-11-08 03:07:12 +03:00
|
|
|
if (id != sConstructor_id) {
|
|
|
|
*resolvedp = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-03 22:53:32 +04:00
|
|
|
JS::Rooted<JSObject*> global(cx, ::JS_GetGlobalForObject(cx, obj));
|
2003-01-22 06:22:35 +03:00
|
|
|
|
2016-01-28 13:28:04 +03:00
|
|
|
JS::Rooted<JS::PropertyDescriptor> desc(cx);
|
2014-12-17 02:28:39 +03:00
|
|
|
if (!JS_GetPropertyDescriptor(cx, global, mData->mName, &desc)) {
|
2003-01-22 06:22:35 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2014-12-17 02:28:39 +03:00
|
|
|
if (desc.object() && !desc.hasGetterOrSetter() && desc.value().isObject()) {
|
2003-01-22 06:22:35 +03:00
|
|
|
// If val is not an (non-null) object there either is no
|
|
|
|
// constructor for this class, or someone messed with
|
|
|
|
// window.classname, just fall through and let the JS engine
|
|
|
|
// return the Object constructor.
|
2014-12-17 02:28:39 +03:00
|
|
|
if (!::JS_DefinePropertyById(cx, obj, id, desc.value(),
|
2014-10-29 22:06:32 +03:00
|
|
|
JSPROP_ENUMERATE,
|
2014-10-29 22:06:31 +03:00
|
|
|
JS_STUBGETTER, JS_STUBSETTER)) {
|
2003-01-22 06:22:35 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2014-11-08 03:07:12 +03:00
|
|
|
*resolvedp = true;
|
2003-01-22 06:22:35 +03:00
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2003-01-22 06:22:35 +03:00
|
|
|
return NS_OK;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-03-19 18:34:55 +04:00
|
|
|
nsDOMClassInfo::Finalize(nsIXPConnectWrappedNative *wrapper, JSFreeOp *fop,
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
JSObject *obj)
|
|
|
|
{
|
2006-02-22 05:18:33 +03:00
|
|
|
NS_WARNING("nsDOMClassInfo::Finalize Don't call me!");
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMClassInfo::Call(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2013-05-04 21:25:15 +04:00
|
|
|
JSObject *obj, const JS::CallArgs &args, bool *_retval)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
{
|
2006-02-22 05:18:33 +03:00
|
|
|
NS_WARNING("nsDOMClassInfo::Call Don't call me!");
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMClassInfo::Construct(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2013-05-04 21:25:15 +04:00
|
|
|
JSObject *obj, const JS::CallArgs &args,
|
|
|
|
bool *_retval)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
{
|
2006-02-22 05:18:33 +03:00
|
|
|
NS_WARNING("nsDOMClassInfo::Construct Don't call me!");
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMClassInfo::HasInstance(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2014-01-09 21:39:36 +04:00
|
|
|
JSObject *obj, JS::Handle<JS::Value> val, bool *bp,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *_retval)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
{
|
2006-02-22 05:18:33 +03:00
|
|
|
NS_WARNING("nsDOMClassInfo::HasInstance Don't call me!");
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2009-03-24 14:02:30 +03:00
|
|
|
static nsresult
|
|
|
|
GetExternalClassInfo(nsScriptNameSpaceManager *aNameSpaceManager,
|
2014-02-16 01:12:34 +04:00
|
|
|
const nsAString &aName,
|
2009-03-24 14:02:30 +03:00
|
|
|
const nsGlobalNameStruct *aStruct,
|
|
|
|
const nsGlobalNameStruct **aResult)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aStruct->mType ==
|
|
|
|
nsGlobalNameStruct::eTypeExternalClassInfoCreator,
|
|
|
|
"Wrong type!");
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDOMCIExtension> creator(do_CreateInstance(aStruct->mCID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMScriptObjectFactory> sof(do_GetService(kDOMSOF_CID));
|
|
|
|
NS_ENSURE_TRUE(sof, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
rv = creator->RegisterDOMCI(NS_ConvertUTF16toUTF8(aName).get(), sof);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-03-29 22:43:13 +04:00
|
|
|
const nsGlobalNameStruct *name_struct = aNameSpaceManager->LookupName(aName);
|
|
|
|
if (name_struct &&
|
2009-03-24 14:02:30 +03:00
|
|
|
name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) {
|
|
|
|
*aResult = name_struct;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ERROR("Couldn't get the DOM ClassInfo data.");
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*aResult = nullptr;
|
2009-03-24 14:02:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx,
|
2014-01-04 19:02:17 +04:00
|
|
|
JS::Handle<JSObject*> obj, const char16_t *name,
|
2010-10-19 02:20:47 +04:00
|
|
|
const nsDOMClassInfoData *ci_data,
|
2009-03-24 14:02:30 +03:00
|
|
|
const nsGlobalNameStruct *name_struct,
|
|
|
|
nsScriptNameSpaceManager *nameSpaceManager,
|
2014-01-30 10:33:23 +04:00
|
|
|
JSObject *dot_prototype,
|
2016-01-28 13:28:04 +03:00
|
|
|
JS::MutableHandle<JS::PropertyDescriptor> ctorDesc);
|
2009-03-24 14:02:30 +03:00
|
|
|
|
2008-08-20 06:38:24 +04:00
|
|
|
NS_IMETHODIMP
|
2013-05-03 22:53:32 +04:00
|
|
|
nsDOMClassInfo::PostCreatePrototype(JSContext * cx, JSObject * aProto)
|
2008-08-20 06:38:24 +04:00
|
|
|
{
|
2013-05-03 22:53:32 +04:00
|
|
|
JS::Rooted<JSObject*> proto(cx, aProto);
|
2009-03-24 14:02:30 +03:00
|
|
|
|
2011-12-29 01:22:05 +04:00
|
|
|
// This is called before any other location that requires
|
|
|
|
// sObjectClass, so compute it here. We assume that nobody has had a
|
|
|
|
// chance to monkey around with proto's prototype chain before this.
|
|
|
|
if (!sObjectClass) {
|
2012-09-04 03:42:10 +04:00
|
|
|
FindObjectClass(cx, proto);
|
2011-12-29 01:22:05 +04:00
|
|
|
NS_ASSERTION(sObjectClass && !strcmp(sObjectClass->name, "Object"),
|
|
|
|
"Incorrect object class!");
|
|
|
|
}
|
|
|
|
|
2012-09-04 03:42:17 +04:00
|
|
|
#ifdef DEBUG
|
2013-05-30 00:16:04 +04:00
|
|
|
JS::Rooted<JSObject*> proto2(cx);
|
2013-07-31 20:20:33 +04:00
|
|
|
JS_GetPrototype(cx, proto, &proto2);
|
2012-09-04 03:42:17 +04:00
|
|
|
NS_ASSERTION(proto2 && JS_GetClass(proto2) == sObjectClass,
|
|
|
|
"Hmm, somebody did something evil?");
|
|
|
|
#endif
|
2011-12-29 01:22:05 +04:00
|
|
|
|
2009-03-24 14:02:30 +03:00
|
|
|
#ifdef DEBUG
|
2009-12-09 00:46:42 +03:00
|
|
|
if (mData->mHasClassInterface && mData->mProtoChainInterface &&
|
|
|
|
mData->mProtoChainInterface != &NS_GET_IID(nsISupports)) {
|
2009-03-24 14:02:30 +03:00
|
|
|
nsCOMPtr<nsIInterfaceInfoManager>
|
|
|
|
iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID));
|
|
|
|
|
|
|
|
if (iim) {
|
|
|
|
nsCOMPtr<nsIInterfaceInfo> if_info;
|
|
|
|
iim->GetInfoForIID(mData->mProtoChainInterface,
|
|
|
|
getter_AddRefs(if_info));
|
|
|
|
|
|
|
|
if (if_info) {
|
|
|
|
nsXPIDLCString name;
|
|
|
|
if_info->GetName(getter_Copies(name));
|
2010-09-18 01:54:40 +04:00
|
|
|
NS_ASSERTION(nsCRT::strcmp(CutPrefix(name), mData->mName) == 0,
|
2009-03-24 14:02:30 +03:00
|
|
|
"Class name and proto chain interface name mismatch!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-06-03 19:30:18 +04:00
|
|
|
// Make prototype delegation work correctly. Consider if a site sets
|
|
|
|
// HTMLElement.prototype.foopy = function () { ... } Now, calling
|
|
|
|
// document.body.foopy() needs to ensure that looking up foopy on
|
|
|
|
// document.body's prototype will find the right function.
|
2013-05-03 22:53:32 +04:00
|
|
|
JS::Rooted<JSObject*> global(cx, ::JS_GetGlobalForObject(cx, proto));
|
2009-06-03 19:30:18 +04:00
|
|
|
|
2011-12-29 01:22:05 +04:00
|
|
|
// Only do this if the global object is a window.
|
|
|
|
// XXX Is there a better way to check this?
|
|
|
|
nsISupports *globalNative = XPConnect()->GetNativeOfWrapper(cx, global);
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> piwin = do_QueryInterface(globalNative);
|
2011-12-29 01:22:05 +04:00
|
|
|
if (!piwin) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsGlobalWindow *win = nsGlobalWindow::Cast(piwin);
|
2011-12-29 01:22:05 +04:00
|
|
|
if (win->IsClosedOrClosing()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the window is in a different compartment than the global object, then
|
|
|
|
// it's likely that global is a sandbox object whose prototype is a window.
|
|
|
|
// Don't do anything in this case.
|
|
|
|
if (win->FastGetGlobalJSObject() &&
|
|
|
|
js::GetObjectCompartment(global) != js::GetObjectCompartment(win->FastGetGlobalJSObject())) {
|
2010-12-07 01:46:49 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-06-24 10:30:11 +04:00
|
|
|
// Don't overwrite a property set by content.
|
2014-01-30 10:33:23 +04:00
|
|
|
bool contentDefinedProperty;
|
2014-07-22 08:43:21 +04:00
|
|
|
if (!::JS_AlreadyHasOwnUCProperty(cx, global, reinterpret_cast<const char16_t*>(mData->mNameUTF16),
|
2014-01-30 10:33:23 +04:00
|
|
|
NS_strlen(mData->mNameUTF16),
|
|
|
|
&contentDefinedProperty)) {
|
2009-06-24 10:30:11 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-08-20 03:24:29 +04:00
|
|
|
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
|
2009-06-03 19:30:18 +04:00
|
|
|
NS_ENSURE_TRUE(nameSpaceManager, NS_OK);
|
|
|
|
|
2016-01-28 13:28:04 +03:00
|
|
|
JS::Rooted<JS::PropertyDescriptor> desc(cx);
|
2014-01-30 10:33:23 +04:00
|
|
|
nsresult rv = ResolvePrototype(sXPConnect, win, cx, global, mData->mNameUTF16,
|
|
|
|
mData, nullptr, nameSpaceManager, proto,
|
|
|
|
&desc);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-05-01 22:03:17 +03:00
|
|
|
if (!contentDefinedProperty && desc.object() && !desc.value().isUndefined()) {
|
|
|
|
desc.attributesRef() |= JSPROP_RESOLVING;
|
|
|
|
if (!JS_DefineUCProperty(cx, global, mData->mNameUTF16,
|
|
|
|
NS_strlen(mData->mNameUTF16), desc)) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2014-01-30 10:33:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2008-08-20 06:38:24 +04:00
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
// static
|
2001-07-11 13:09:30 +04:00
|
|
|
nsIClassInfo *
|
2007-03-19 12:19:16 +03:00
|
|
|
NS_GetDOMClassInfoInstance(nsDOMClassInfoID aID)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
{
|
|
|
|
if (aID >= eDOMClassInfoIDCount) {
|
|
|
|
NS_ERROR("Bad ID!");
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
|
|
|
|
2014-08-08 17:03:29 +04:00
|
|
|
nsresult rv = RegisterDOMNames();
|
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
2014-08-08 21:29:28 +04:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
if (!sClassInfoData[aID].mCachedClassInfo) {
|
|
|
|
nsDOMClassInfoData& data = sClassInfoData[aID];
|
|
|
|
|
2002-03-04 06:37:18 +03:00
|
|
|
data.mCachedClassInfo = data.u.mConstructorFptr(&data);
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_TRUE(data.mCachedClassInfo, nullptr);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
NS_ADDREF(data.mCachedClassInfo);
|
|
|
|
}
|
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
NS_ASSERTION(!IS_EXTERNAL(sClassInfoData[aID].mCachedClassInfo),
|
|
|
|
"This is bad, internal class marked as external!");
|
|
|
|
|
2004-01-06 03:36:01 +03:00
|
|
|
return sClassInfoData[aID].mCachedClassInfo;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
// static
|
|
|
|
nsIClassInfo *
|
|
|
|
nsDOMClassInfo::GetClassInfoInstance(nsDOMClassInfoData* aData)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(IS_EXTERNAL(aData->mCachedClassInfo)
|
|
|
|
|| !aData->mCachedClassInfo,
|
|
|
|
"This is bad, external class marked as internal!");
|
|
|
|
|
|
|
|
if (!aData->mCachedClassInfo) {
|
2002-03-04 06:37:18 +03:00
|
|
|
if (aData->u.mExternalConstructorFptr) {
|
2002-08-16 01:18:20 +04:00
|
|
|
aData->mCachedClassInfo =
|
|
|
|
aData->u.mExternalConstructorFptr(aData->mName);
|
2002-03-04 05:25:08 +03:00
|
|
|
} else {
|
|
|
|
aData->mCachedClassInfo = nsDOMGenericSH::doCreate(aData);
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_TRUE(aData->mCachedClassInfo, nullptr);
|
2002-03-04 05:25:08 +03:00
|
|
|
|
|
|
|
NS_ADDREF(aData->mCachedClassInfo);
|
|
|
|
aData->mCachedClassInfo = MARK_EXTERNAL(aData->mCachedClassInfo);
|
|
|
|
}
|
|
|
|
|
2004-01-06 03:36:01 +03:00
|
|
|
return GET_CLEAN_CI_PTR(aData->mCachedClassInfo);
|
2002-03-04 05:25:08 +03:00
|
|
|
}
|
|
|
|
|
2006-11-23 02:18:16 +03:00
|
|
|
|
2007-01-05 01:31:26 +03:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsDOMClassInfo::ShutDown()
|
|
|
|
{
|
2002-03-04 06:37:18 +03:00
|
|
|
if (sClassInfoData[0].u.mConstructorFptr) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
for (i = 0; i < eDOMClassInfoIDCount; i++) {
|
|
|
|
NS_IF_RELEASE(sClassInfoData[i].mCachedClassInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-17 06:27:43 +04:00
|
|
|
sConstructor_id = JSID_VOID;
|
|
|
|
sWrappedJSObject_id = JSID_VOID;
|
2011-04-26 16:30:17 +04:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
NS_IF_RELEASE(sXPConnect);
|
2011-10-17 18:59:28 +04:00
|
|
|
sIsInitialized = false;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
|
|
|
|
2005-12-09 22:08:45 +03:00
|
|
|
static nsresult
|
2007-12-12 11:33:32 +03:00
|
|
|
BaseStubConstructor(nsIWeakReference* aWeakOwner,
|
|
|
|
const nsGlobalNameStruct *name_struct, JSContext *cx,
|
2013-05-04 21:25:15 +04:00
|
|
|
JS::Handle<JSObject*> obj, const JS::CallArgs &args)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
{
|
2013-04-26 10:48:40 +04:00
|
|
|
MOZ_ASSERT(obj);
|
2014-08-04 21:01:00 +04:00
|
|
|
MOZ_ASSERT(cx == nsContentUtils::GetCurrentJSContext());
|
2013-04-26 10:48:40 +04:00
|
|
|
|
2003-01-22 06:22:35 +03:00
|
|
|
nsresult rv;
|
2002-03-04 05:25:08 +03:00
|
|
|
nsCOMPtr<nsISupports> native;
|
2005-11-18 16:39:43 +03:00
|
|
|
if (name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) {
|
2014-10-15 14:57:35 +04:00
|
|
|
rv = NS_ERROR_NOT_AVAILABLE;
|
2005-11-18 16:39:43 +03:00
|
|
|
} else if (name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructor) {
|
2002-03-04 05:25:08 +03:00
|
|
|
native = do_CreateInstance(name_struct->mCID, &rv);
|
2002-08-30 12:48:58 +04:00
|
|
|
} else if (name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias) {
|
|
|
|
native = do_CreateInstance(name_struct->mAlias->mCID, &rv);
|
2002-03-04 05:25:08 +03:00
|
|
|
} else {
|
|
|
|
native = do_CreateInstance(*name_struct->mData->mConstructorCID, &rv);
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("Failed to create the object");
|
2005-12-09 22:08:45 +03:00
|
|
|
return rv;
|
2002-03-04 05:25:08 +03:00
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2014-04-10 08:58:42 +04:00
|
|
|
js::AssertSameCompartment(cx, obj);
|
2015-02-04 11:40:59 +03:00
|
|
|
return nsContentUtils::WrapNative(cx, native, args.rval(), true);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
|
|
|
|
2001-07-11 13:09:30 +04:00
|
|
|
static nsresult
|
2013-05-03 22:53:32 +04:00
|
|
|
DefineInterfaceConstants(JSContext *cx, JS::Handle<JSObject*> obj, const nsIID *aIID)
|
2001-07-11 13:09:30 +04:00
|
|
|
{
|
2005-11-10 19:19:44 +03:00
|
|
|
nsCOMPtr<nsIInterfaceInfoManager>
|
|
|
|
iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID));
|
2001-07-11 13:09:30 +04:00
|
|
|
NS_ENSURE_TRUE(iim, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInterfaceInfo> if_info;
|
|
|
|
|
|
|
|
nsresult rv = iim->GetInfoForIID(aIID, getter_AddRefs(if_info));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && if_info, rv);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t constant_count;
|
2001-07-11 13:09:30 +04:00
|
|
|
|
|
|
|
if_info->GetConstantCount(&constant_count);
|
|
|
|
|
|
|
|
if (!constant_count) {
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-07-11 13:09:30 +04:00
|
|
|
nsCOMPtr<nsIInterfaceInfo> parent_if_info;
|
|
|
|
|
|
|
|
rv = if_info->GetParent(getter_AddRefs(parent_if_info));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && parent_if_info, rv);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t parent_constant_count, i;
|
2001-07-11 13:09:30 +04:00
|
|
|
parent_if_info->GetConstantCount(&parent_constant_count);
|
|
|
|
|
2014-01-22 06:11:17 +04:00
|
|
|
JS::Rooted<JS::Value> v(cx);
|
2001-07-11 13:09:30 +04:00
|
|
|
for (i = parent_constant_count; i < constant_count; i++) {
|
2014-05-09 00:45:36 +04:00
|
|
|
nsXPIDLCString name;
|
|
|
|
rv = if_info->GetConstant(i, &v, getter_Copies(name));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv), rv);
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2014-05-09 00:45:36 +04:00
|
|
|
if (!::JS_DefineProperty(cx, obj, name, v,
|
2014-10-29 22:06:32 +03:00
|
|
|
JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT,
|
2014-10-29 22:06:31 +03:00
|
|
|
JS_STUBGETTER, JS_STUBSETTER)) {
|
2003-01-31 15:10:13 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsDOMConstructor final : public nsIDOMDOMConstructor
|
2003-01-22 06:22:35 +03:00
|
|
|
{
|
2008-02-27 05:03:27 +03:00
|
|
|
protected:
|
2014-01-04 19:02:17 +04:00
|
|
|
nsDOMConstructor(const char16_t* aName,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsConstructable,
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* aOwner)
|
2007-05-09 16:04:59 +04:00
|
|
|
: mClassName(aName),
|
2009-06-03 19:30:18 +04:00
|
|
|
mConstructable(aIsConstructable),
|
2007-12-12 11:33:32 +03:00
|
|
|
mWeakOwner(do_GetWeakReference(aOwner))
|
2005-12-09 22:08:45 +03:00
|
|
|
{
|
|
|
|
}
|
2003-01-22 06:22:35 +03:00
|
|
|
|
2014-06-23 23:56:07 +04:00
|
|
|
~nsDOMConstructor() {}
|
|
|
|
|
2008-02-27 05:03:27 +03:00
|
|
|
public:
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
static nsresult Create(const char16_t* aName,
|
2009-06-03 19:30:18 +04:00
|
|
|
const nsDOMClassInfoData* aData,
|
2008-02-27 05:03:27 +03:00
|
|
|
const nsGlobalNameStruct* aNameStruct,
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* aOwner,
|
2008-02-27 05:03:27 +03:00
|
|
|
nsDOMConstructor** aResult);
|
|
|
|
|
2005-12-09 22:08:45 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
2007-11-12 09:43:14 +03:00
|
|
|
NS_DECL_NSIDOMDOMCONSTRUCTOR
|
2005-12-09 22:08:45 +03:00
|
|
|
|
2011-01-11 23:15:52 +03:00
|
|
|
nsresult PreCreate(JSContext *cx, JSObject *globalObj, JSObject **parentObj);
|
|
|
|
|
2005-12-09 22:08:45 +03:00
|
|
|
nsresult Construct(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2013-05-04 21:25:15 +04:00
|
|
|
JS::Handle<JSObject*> obj, const JS::CallArgs &args,
|
2013-05-04 21:25:15 +04:00
|
|
|
bool *_retval);
|
2005-12-09 22:08:45 +03:00
|
|
|
|
|
|
|
nsresult HasInstance(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2015-07-18 22:45:35 +03:00
|
|
|
JS::Handle<JSObject*> obj, const JS::Value &val, bool *bp,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *_retval);
|
2005-12-09 22:08:45 +03:00
|
|
|
|
2013-05-03 22:53:32 +04:00
|
|
|
nsresult ResolveInterfaceConstants(JSContext *cx, JS::Handle<JSObject*> obj);
|
2011-09-22 06:16:50 +04:00
|
|
|
|
2005-12-09 22:08:45 +03:00
|
|
|
private:
|
2007-05-09 16:04:59 +04:00
|
|
|
const nsGlobalNameStruct *GetNameStruct()
|
|
|
|
{
|
|
|
|
if (!mClassName) {
|
|
|
|
NS_ERROR("Can't get name");
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2007-05-09 16:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
const nsGlobalNameStruct *nameStruct;
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsresult rv =
|
|
|
|
#endif
|
|
|
|
GetNameStruct(nsDependentString(mClassName), &nameStruct);
|
|
|
|
|
|
|
|
NS_ASSERTION(NS_FAILED(rv) || nameStruct, "Name isn't in hash.");
|
|
|
|
|
|
|
|
return nameStruct;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult GetNameStruct(const nsAString& aName,
|
|
|
|
const nsGlobalNameStruct **aNameStruct)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aNameStruct = nullptr;
|
2007-05-09 16:04:59 +04:00
|
|
|
|
2013-08-20 03:24:29 +04:00
|
|
|
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
|
2007-11-13 13:35:49 +03:00
|
|
|
if (!nameSpaceManager) {
|
2007-05-09 16:04:59 +04:00
|
|
|
NS_ERROR("Can't get namespace manager.");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2012-03-29 22:43:13 +04:00
|
|
|
*aNameStruct = nameSpaceManager->LookupName(aName);
|
2007-05-09 16:04:59 +04:00
|
|
|
|
|
|
|
// Return NS_OK here, aName just isn't a DOM class but nothing failed.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsConstructable(const nsDOMClassInfoData *aData)
|
2009-06-03 19:30:18 +04:00
|
|
|
{
|
2009-12-09 08:50:27 +03:00
|
|
|
if (IS_EXTERNAL(aData->mCachedClassInfo)) {
|
2009-06-03 19:30:18 +04:00
|
|
|
const nsExternalDOMClassInfoData* data =
|
|
|
|
static_cast<const nsExternalDOMClassInfoData*>(aData);
|
2012-07-30 18:20:58 +04:00
|
|
|
return data->mConstructorCID != nullptr;
|
2009-06-03 19:30:18 +04:00
|
|
|
}
|
|
|
|
|
2014-11-04 22:16:56 +03:00
|
|
|
return false;
|
2009-06-03 19:30:18 +04:00
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsConstructable(const nsGlobalNameStruct *aNameStruct)
|
2007-05-09 16:04:59 +04:00
|
|
|
{
|
|
|
|
return
|
|
|
|
(aNameStruct->mType == nsGlobalNameStruct::eTypeClassConstructor &&
|
2009-06-03 19:30:18 +04:00
|
|
|
IsConstructable(&sClassInfoData[aNameStruct->mDOMClassInfoID])) ||
|
2007-05-09 16:04:59 +04:00
|
|
|
(aNameStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo &&
|
2009-06-03 19:30:18 +04:00
|
|
|
IsConstructable(aNameStruct->mData)) ||
|
2007-05-09 16:04:59 +04:00
|
|
|
aNameStruct->mType == nsGlobalNameStruct::eTypeExternalConstructor ||
|
|
|
|
aNameStruct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias;
|
|
|
|
}
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* mClassName;
|
2011-09-29 10:19:26 +04:00
|
|
|
const bool mConstructable;
|
2007-12-12 11:33:32 +03:00
|
|
|
nsWeakPtr mWeakOwner;
|
2005-12-09 22:08:45 +03:00
|
|
|
};
|
2003-01-22 06:22:35 +03:00
|
|
|
|
2008-02-27 05:03:27 +03:00
|
|
|
//static
|
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsDOMConstructor::Create(const char16_t* aName,
|
2009-06-03 19:30:18 +04:00
|
|
|
const nsDOMClassInfoData* aData,
|
2008-02-27 05:03:27 +03:00
|
|
|
const nsGlobalNameStruct* aNameStruct,
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* aOwner,
|
2008-02-27 05:03:27 +03:00
|
|
|
nsDOMConstructor** aResult)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aResult = nullptr;
|
2008-12-29 01:42:30 +03:00
|
|
|
// Prevent creating a constructor if aOwner is inner window which doesn't have
|
|
|
|
// an outer window. If the outer window doesn't have an inner window or the
|
|
|
|
// caller can't access the outer window's current inner window then try to use
|
|
|
|
// the owner (so long as it is, in fact, an inner window). If that doesn't
|
|
|
|
// work then prevent creation also.
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* outerWindow = aOwner->GetOuterWindow();
|
|
|
|
nsPIDOMWindowInner* currentInner =
|
2008-12-29 01:42:30 +03:00
|
|
|
outerWindow ? outerWindow->GetCurrentInnerWindow() : aOwner;
|
2010-10-25 23:15:04 +04:00
|
|
|
if (!currentInner ||
|
2008-04-25 13:45:58 +04:00
|
|
|
(aOwner != currentInner &&
|
2008-12-29 01:42:30 +03:00
|
|
|
!nsContentUtils::CanCallerAccess(currentInner) &&
|
|
|
|
!(currentInner = aOwner)->IsInnerWindow())) {
|
2008-02-27 05:03:27 +03:00
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
2009-06-03 19:30:18 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool constructable = aNameStruct ?
|
2009-06-03 19:30:18 +04:00
|
|
|
IsConstructable(aNameStruct) :
|
|
|
|
IsConstructable(aData);
|
|
|
|
|
|
|
|
*aResult = new nsDOMConstructor(aName, constructable, currentInner);
|
2008-02-27 05:03:27 +03:00
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-12-09 22:08:45 +03:00
|
|
|
NS_IMPL_ADDREF(nsDOMConstructor)
|
|
|
|
NS_IMPL_RELEASE(nsDOMConstructor)
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDOMConstructor)
|
2007-11-12 09:43:14 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDOMConstructor)
|
2005-12-09 22:08:45 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2007-05-09 16:04:59 +04:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIClassInfo))) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
const nsGlobalNameStruct *name_struct = GetNameStruct();
|
|
|
|
NS_ASSERTION(!name_struct ||
|
|
|
|
mConstructable == IsConstructable(name_struct),
|
|
|
|
"Can't change constructability dynamically!");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
foundInterface =
|
|
|
|
NS_GetDOMClassInfoInstance(mConstructable ?
|
2007-11-12 09:43:14 +03:00
|
|
|
eDOMClassInfo_DOMConstructor_id :
|
|
|
|
eDOMClassInfo_DOMPrototype_id);
|
2007-05-09 16:04:59 +04:00
|
|
|
if (!foundInterface) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aInstancePtr = nullptr;
|
2007-05-09 16:04:59 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
} else
|
2005-12-09 22:08:45 +03:00
|
|
|
NS_INTERFACE_MAP_END
|
2003-01-22 06:22:35 +03:00
|
|
|
|
2011-01-11 23:15:52 +03:00
|
|
|
nsresult
|
|
|
|
nsDOMConstructor::PreCreate(JSContext *cx, JSObject *globalObj, JSObject **parentObj)
|
|
|
|
{
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> owner(do_QueryReferent(mWeakOwner));
|
2011-01-11 23:15:52 +03:00
|
|
|
if (!owner) {
|
|
|
|
// Can't do anything.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsGlobalWindow *win = nsGlobalWindow::Cast(owner);
|
2012-04-27 12:38:14 +04:00
|
|
|
return SetParentToWindow(win, parentObj);
|
2011-01-11 23:15:52 +03:00
|
|
|
}
|
|
|
|
|
2005-12-09 22:52:04 +03:00
|
|
|
nsresult
|
2005-12-09 22:08:45 +03:00
|
|
|
nsDOMConstructor::Construct(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
2013-05-04 21:25:15 +04:00
|
|
|
JS::Handle<JSObject*> obj, const JS::CallArgs &args,
|
|
|
|
bool *_retval)
|
2005-12-09 22:08:45 +03:00
|
|
|
{
|
2013-04-26 10:48:40 +04:00
|
|
|
MOZ_ASSERT(obj);
|
2005-12-09 22:08:45 +03:00
|
|
|
|
2007-05-09 16:04:59 +04:00
|
|
|
const nsGlobalNameStruct *name_struct = GetNameStruct();
|
|
|
|
NS_ENSURE_TRUE(name_struct, NS_ERROR_FAILURE);
|
2003-01-22 06:22:35 +03:00
|
|
|
|
2007-05-09 16:04:59 +04:00
|
|
|
if (!IsConstructable(name_struct)) {
|
2013-08-07 10:59:54 +04:00
|
|
|
// ignore return value, we return false anyway
|
2005-12-09 22:08:45 +03:00
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
2003-01-22 06:22:35 +03:00
|
|
|
}
|
|
|
|
|
2013-05-04 21:25:15 +04:00
|
|
|
return BaseStubConstructor(mWeakOwner, name_struct, cx, obj, args);
|
2003-01-22 06:22:35 +03:00
|
|
|
}
|
|
|
|
|
2005-12-09 22:52:04 +03:00
|
|
|
nsresult
|
2005-12-09 22:08:45 +03:00
|
|
|
nsDOMConstructor::HasInstance(nsIXPConnectWrappedNative *wrapper,
|
2013-05-04 11:51:53 +04:00
|
|
|
JSContext * cx, JS::Handle<JSObject*> obj,
|
2015-07-18 22:45:35 +03:00
|
|
|
const JS::Value &v, bool *bp, bool *_retval)
|
2005-12-09 22:08:45 +03:00
|
|
|
|
2003-01-22 06:22:35 +03:00
|
|
|
{
|
2004-01-23 20:07:57 +03:00
|
|
|
// No need to look these up in the hash.
|
2011-10-17 18:59:28 +04:00
|
|
|
*bp = false;
|
2014-04-28 07:27:54 +04:00
|
|
|
if (v.isPrimitive()) {
|
2005-12-09 22:08:45 +03:00
|
|
|
return NS_OK;
|
2003-01-22 06:22:35 +03:00
|
|
|
}
|
|
|
|
|
2013-05-03 22:53:32 +04:00
|
|
|
JS::Rooted<JSObject*> dom_obj(cx, v.toObjectOrNull());
|
2005-12-09 22:08:45 +03:00
|
|
|
NS_ASSERTION(dom_obj, "nsDOMConstructor::HasInstance couldn't get object");
|
2004-01-23 20:07:57 +03:00
|
|
|
|
2013-02-26 20:15:44 +04:00
|
|
|
// This might not be the right object, if there are wrappers. Unwrap if we can.
|
2015-11-06 21:03:52 +03:00
|
|
|
JSObject *wrapped_obj = js::CheckedUnwrap(dom_obj, /* stopAtWindowProxy = */ false);
|
2013-02-26 20:15:44 +04:00
|
|
|
if (wrapped_obj)
|
|
|
|
dom_obj = wrapped_obj;
|
2005-05-23 01:30:15 +04:00
|
|
|
|
2013-09-11 16:49:05 +04:00
|
|
|
const JSClass *dom_class = JS_GetClass(dom_obj);
|
2003-01-22 06:22:35 +03:00
|
|
|
if (!dom_class) {
|
2005-12-09 22:08:45 +03:00
|
|
|
NS_ERROR("nsDOMConstructor::HasInstance can't get class.");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2003-01-22 06:22:35 +03:00
|
|
|
}
|
|
|
|
|
2007-05-09 16:04:59 +04:00
|
|
|
const nsGlobalNameStruct *name_struct;
|
2013-02-26 20:15:44 +04:00
|
|
|
nsresult rv = GetNameStruct(NS_ConvertASCIItoUTF16(dom_class->name), &name_struct);
|
2011-07-17 23:09:13 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2007-05-09 16:04:59 +04:00
|
|
|
return rv;
|
2003-01-22 06:22:35 +03:00
|
|
|
}
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
if (!name_struct) {
|
|
|
|
// This isn't a normal DOM object, see if this constructor lives on its
|
|
|
|
// prototype chain.
|
2016-01-28 13:28:04 +03:00
|
|
|
JS::Rooted<JS::PropertyDescriptor> desc(cx);
|
2014-12-17 02:28:39 +03:00
|
|
|
if (!JS_GetPropertyDescriptor(cx, obj, "prototype", &desc)) {
|
2011-07-17 23:09:13 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2014-12-17 02:28:39 +03:00
|
|
|
if (!desc.object() || desc.hasGetterOrSetter() || !desc.value().isObject()) {
|
2012-02-29 21:11:03 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-12-17 02:28:39 +03:00
|
|
|
JS::Rooted<JSObject*> dot_prototype(cx, &desc.value().toObject());
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-05-03 22:53:32 +04:00
|
|
|
JS::Rooted<JSObject*> proto(cx, dom_obj);
|
2012-09-04 03:42:17 +04:00
|
|
|
for (;;) {
|
2013-07-31 20:20:33 +04:00
|
|
|
if (!JS_GetPrototype(cx, proto, &proto)) {
|
2012-09-04 03:42:17 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
if (!proto) {
|
|
|
|
break;
|
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
if (proto == dot_prototype) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*bp = true;
|
2011-07-17 23:09:13 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-02-08 19:11:41 +03:00
|
|
|
if (name_struct->mType != nsGlobalNameStruct::eTypeClassConstructor &&
|
|
|
|
name_struct->mType != nsGlobalNameStruct::eTypeExternalClassInfo &&
|
|
|
|
name_struct->mType != nsGlobalNameStruct::eTypeExternalConstructorAlias) {
|
|
|
|
// Doesn't have DOM interfaces.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-01-22 06:22:35 +03:00
|
|
|
|
2007-05-09 16:04:59 +04:00
|
|
|
const nsGlobalNameStruct *class_name_struct = GetNameStruct();
|
|
|
|
NS_ENSURE_TRUE(class_name_struct, NS_ERROR_FAILURE);
|
2003-01-22 06:22:35 +03:00
|
|
|
|
2003-10-21 15:33:34 +04:00
|
|
|
if (name_struct == class_name_struct) {
|
2013-08-07 10:59:54 +04:00
|
|
|
*bp = true;
|
2003-10-21 15:33:34 +04:00
|
|
|
|
2005-12-09 22:08:45 +03:00
|
|
|
return NS_OK;
|
2003-10-21 15:33:34 +04:00
|
|
|
}
|
|
|
|
|
2013-08-20 03:24:29 +04:00
|
|
|
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
|
2007-11-13 13:35:49 +03:00
|
|
|
NS_ASSERTION(nameSpaceManager, "Can't get namespace manager?");
|
2007-05-09 16:04:59 +04:00
|
|
|
|
2003-10-21 15:33:34 +04:00
|
|
|
const nsIID *class_iid;
|
|
|
|
if (class_name_struct->mType == nsGlobalNameStruct::eTypeInterface ||
|
|
|
|
class_name_struct->mType == nsGlobalNameStruct::eTypeClassProto) {
|
|
|
|
class_iid = &class_name_struct->mIID;
|
|
|
|
} else if (class_name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) {
|
|
|
|
class_iid =
|
|
|
|
sClassInfoData[class_name_struct->mDOMClassInfoID].mProtoChainInterface;
|
|
|
|
} else if (class_name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) {
|
|
|
|
class_iid = class_name_struct->mData->mProtoChainInterface;
|
|
|
|
} else if (class_name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias) {
|
|
|
|
const nsGlobalNameStruct* alias_struct =
|
2007-11-13 13:35:49 +03:00
|
|
|
nameSpaceManager->GetConstructorProto(class_name_struct);
|
2003-10-21 15:33:34 +04:00
|
|
|
if (!alias_struct) {
|
|
|
|
NS_ERROR("Couldn't get constructor prototype.");
|
2005-12-09 22:08:45 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2003-10-21 15:33:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (alias_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) {
|
|
|
|
class_iid =
|
|
|
|
sClassInfoData[alias_struct->mDOMClassInfoID].mProtoChainInterface;
|
|
|
|
} else if (alias_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) {
|
|
|
|
class_iid = alias_struct->mData->mProtoChainInterface;
|
|
|
|
} else {
|
|
|
|
NS_ERROR("Expected eTypeClassConstructor or eTypeExternalClassInfo.");
|
2005-12-09 22:08:45 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2003-10-21 15:33:34 +04:00
|
|
|
}
|
|
|
|
} else {
|
2013-08-07 10:59:54 +04:00
|
|
|
*bp = false;
|
2003-01-22 06:22:35 +03:00
|
|
|
|
2005-12-09 22:08:45 +03:00
|
|
|
return NS_OK;
|
2003-01-22 06:22:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias) {
|
2007-11-13 13:35:49 +03:00
|
|
|
name_struct = nameSpaceManager->GetConstructorProto(name_struct);
|
2003-01-22 06:22:35 +03:00
|
|
|
if (!name_struct) {
|
|
|
|
NS_ERROR("Couldn't get constructor prototype.");
|
2005-12-09 22:08:45 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2003-01-22 06:22:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor ||
|
|
|
|
name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo,
|
|
|
|
"The constructor was set up with a struct of the wrong type.");
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
const nsDOMClassInfoData *ci_data = nullptr;
|
2003-01-22 06:22:35 +03:00
|
|
|
if (name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor &&
|
|
|
|
name_struct->mDOMClassInfoID >= 0) {
|
|
|
|
ci_data = &sClassInfoData[name_struct->mDOMClassInfoID];
|
|
|
|
} else if (name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) {
|
|
|
|
ci_data = name_struct->mData;
|
|
|
|
}
|
|
|
|
|
2005-11-10 19:19:44 +03:00
|
|
|
nsCOMPtr<nsIInterfaceInfoManager>
|
|
|
|
iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID));
|
2003-01-22 06:22:35 +03:00
|
|
|
if (!iim) {
|
2005-12-09 22:08:45 +03:00
|
|
|
NS_ERROR("nsDOMConstructor::HasInstance can't get interface info mgr.");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2003-01-22 06:22:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInterfaceInfo> if_info;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = 0;
|
2003-01-22 06:22:35 +03:00
|
|
|
const nsIID* class_interface;
|
|
|
|
while ((class_interface = ci_data->mInterfaces[count++])) {
|
2003-10-21 15:33:34 +04:00
|
|
|
if (class_iid->Equals(*class_interface)) {
|
2013-08-07 10:59:54 +04:00
|
|
|
*bp = true;
|
2003-01-22 06:22:35 +03:00
|
|
|
|
2005-12-09 22:08:45 +03:00
|
|
|
return NS_OK;
|
2003-01-22 06:22:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
iim->GetInfoForIID(class_interface, getter_AddRefs(if_info));
|
|
|
|
if (!if_info) {
|
2005-12-09 22:08:45 +03:00
|
|
|
NS_ERROR("nsDOMConstructor::HasInstance can't get interface info.");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2003-01-22 06:22:35 +03:00
|
|
|
}
|
|
|
|
|
2003-10-21 15:33:34 +04:00
|
|
|
if_info->HasAncestor(class_iid, bp);
|
2003-01-22 06:22:35 +03:00
|
|
|
|
|
|
|
if (*bp) {
|
2005-12-09 22:08:45 +03:00
|
|
|
return NS_OK;
|
2003-01-22 06:22:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-09 22:08:45 +03:00
|
|
|
return NS_OK;
|
2003-01-22 06:22:35 +03:00
|
|
|
}
|
|
|
|
|
2011-09-22 06:16:50 +04:00
|
|
|
nsresult
|
2013-05-03 22:53:32 +04:00
|
|
|
nsDOMConstructor::ResolveInterfaceConstants(JSContext *cx, JS::Handle<JSObject*> obj)
|
2011-09-22 06:16:50 +04:00
|
|
|
{
|
|
|
|
const nsGlobalNameStruct *class_name_struct = GetNameStruct();
|
|
|
|
if (!class_name_struct)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
const nsIID *class_iid;
|
|
|
|
if (class_name_struct->mType == nsGlobalNameStruct::eTypeInterface ||
|
|
|
|
class_name_struct->mType == nsGlobalNameStruct::eTypeClassProto) {
|
|
|
|
class_iid = &class_name_struct->mIID;
|
|
|
|
} else if (class_name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) {
|
|
|
|
class_iid =
|
|
|
|
sClassInfoData[class_name_struct->mDOMClassInfoID].mProtoChainInterface;
|
|
|
|
} else if (class_name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) {
|
|
|
|
class_iid = class_name_struct->mData->mProtoChainInterface;
|
|
|
|
} else {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-08-02 13:38:49 +04:00
|
|
|
nsresult rv = DefineInterfaceConstants(cx, obj, class_iid);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
2011-09-22 06:16:50 +04:00
|
|
|
}
|
|
|
|
|
2005-12-09 22:08:45 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMConstructor::ToString(nsAString &aResult)
|
2003-01-22 06:22:35 +03:00
|
|
|
{
|
2005-12-10 04:08:51 +03:00
|
|
|
aResult.AssignLiteral("[object ");
|
2005-12-09 22:08:45 +03:00
|
|
|
aResult.Append(mClassName);
|
2014-01-04 19:02:17 +04:00
|
|
|
aResult.Append(char16_t(']'));
|
2003-01-22 06:22:35 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2001-07-11 13:09:30 +04:00
|
|
|
}
|
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
|
2009-03-24 14:02:30 +03:00
|
|
|
static nsresult
|
2009-06-03 19:30:18 +04:00
|
|
|
GetXPCProto(nsIXPConnect *aXPConnect, JSContext *cx, nsGlobalWindow *aWin,
|
|
|
|
const nsGlobalNameStruct *aNameStruct,
|
2015-02-04 11:41:00 +03:00
|
|
|
JS::MutableHandle<JSObject*> aProto)
|
2009-03-24 14:02:30 +03:00
|
|
|
{
|
2009-06-03 19:30:18 +04:00
|
|
|
NS_ASSERTION(aNameStruct->mType ==
|
2009-03-24 14:02:30 +03:00
|
|
|
nsGlobalNameStruct::eTypeClassConstructor ||
|
2009-06-03 19:30:18 +04:00
|
|
|
aNameStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo,
|
2009-03-24 14:02:30 +03:00
|
|
|
"Wrong type!");
|
2002-03-04 05:25:08 +03:00
|
|
|
|
2009-06-03 19:30:18 +04:00
|
|
|
nsCOMPtr<nsIClassInfo> ci;
|
|
|
|
if (aNameStruct->mType == nsGlobalNameStruct::eTypeClassConstructor) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t id = aNameStruct->mDOMClassInfoID;
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(id >= 0, "Negative DOM classinfo?!?");
|
2003-01-31 15:10:13 +03:00
|
|
|
|
2009-06-03 19:30:18 +04:00
|
|
|
nsDOMClassInfoID ci_id = (nsDOMClassInfoID)id;
|
2005-12-09 22:08:45 +03:00
|
|
|
|
2009-06-03 19:30:18 +04:00
|
|
|
ci = NS_GetDOMClassInfoInstance(ci_id);
|
2009-03-26 17:53:33 +03:00
|
|
|
}
|
2009-06-03 19:30:18 +04:00
|
|
|
else {
|
|
|
|
ci = nsDOMClassInfo::GetClassInfoInstance(aNameStruct->mData);
|
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE(ci, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2011-01-06 07:28:19 +03:00
|
|
|
nsresult rv =
|
2015-07-01 21:17:17 +03:00
|
|
|
aXPConnect->GetWrappedNativePrototype(cx, aWin->GetGlobalJSObject(), ci, aProto.address());
|
2011-01-06 07:28:19 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2015-02-04 11:41:00 +03:00
|
|
|
return JS_WrapObject(cx, aProto) ? NS_OK : NS_ERROR_FAILURE;
|
2009-06-03 19:30:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Either ci_data must be non-null or name_struct must be non-null and of type
|
|
|
|
// eTypeClassProto.
|
|
|
|
static nsresult
|
|
|
|
ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx,
|
2014-01-04 19:02:17 +04:00
|
|
|
JS::Handle<JSObject*> obj, const char16_t *name,
|
2010-10-19 02:20:47 +04:00
|
|
|
const nsDOMClassInfoData *ci_data,
|
2009-06-03 19:30:18 +04:00
|
|
|
const nsGlobalNameStruct *name_struct,
|
|
|
|
nsScriptNameSpaceManager *nameSpaceManager,
|
2014-01-30 10:33:23 +04:00
|
|
|
JSObject* aDot_prototype,
|
2016-01-28 13:28:04 +03:00
|
|
|
JS::MutableHandle<JS::PropertyDescriptor> ctorDesc)
|
2009-06-03 19:30:18 +04:00
|
|
|
{
|
2013-05-04 11:51:53 +04:00
|
|
|
JS::Rooted<JSObject*> dot_prototype(cx, aDot_prototype);
|
2009-06-03 19:30:18 +04:00
|
|
|
NS_ASSERTION(ci_data ||
|
|
|
|
(name_struct &&
|
|
|
|
name_struct->mType == nsGlobalNameStruct::eTypeClassProto),
|
|
|
|
"Wrong type or missing ci_data!");
|
2003-11-12 17:25:03 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsDOMConstructor> constructor;
|
2016-01-30 20:05:36 +03:00
|
|
|
nsresult rv = nsDOMConstructor::Create(name, ci_data, name_struct,
|
|
|
|
aWin->AsInner(),
|
2009-03-24 14:02:30 +03:00
|
|
|
getter_AddRefs(constructor));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-11-12 17:25:03 +03:00
|
|
|
|
2013-05-03 22:53:32 +04:00
|
|
|
JS::Rooted<JS::Value> v(cx);
|
2005-12-09 22:08:45 +03:00
|
|
|
|
2014-04-10 08:58:42 +04:00
|
|
|
js::AssertSameCompartment(cx, obj);
|
2015-02-04 11:40:59 +03:00
|
|
|
rv = nsContentUtils::WrapNative(cx, constructor,
|
|
|
|
&NS_GET_IID(nsIDOMDOMConstructor), &v,
|
|
|
|
false);
|
2009-03-24 14:02:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2014-01-30 10:33:23 +04:00
|
|
|
FillPropertyDescriptor(ctorDesc, obj, 0, v);
|
|
|
|
// And make sure we wrap the value into the right compartment. Note that we
|
|
|
|
// do this with ctorDesc.value(), not with v, because we need v to be in the
|
|
|
|
// right compartment (that of the reflector of |constructor|) below.
|
|
|
|
if (!JS_WrapValue(cx, ctorDesc.value())) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2009-06-24 10:30:11 +04:00
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2014-01-06 23:54:43 +04:00
|
|
|
JS::Rooted<JSObject*> class_obj(cx, &v.toObject());
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2009-03-24 14:02:30 +03:00
|
|
|
const nsIID *primary_iid = &NS_GET_IID(nsISupports);
|
2002-08-30 12:48:58 +04:00
|
|
|
|
2009-06-03 19:30:18 +04:00
|
|
|
if (!ci_data) {
|
2009-03-24 14:02:30 +03:00
|
|
|
primary_iid = &name_struct->mIID;
|
2009-06-03 19:30:18 +04:00
|
|
|
}
|
|
|
|
else if (ci_data->mProtoChainInterface) {
|
2009-03-24 14:02:30 +03:00
|
|
|
primary_iid = ci_data->mProtoChainInterface;
|
|
|
|
}
|
2005-12-09 22:08:45 +03:00
|
|
|
|
2011-12-29 01:22:05 +04:00
|
|
|
nsCOMPtr<nsIInterfaceInfo> if_info;
|
|
|
|
nsCOMPtr<nsIInterfaceInfo> parent;
|
2012-07-30 18:20:58 +04:00
|
|
|
const char *class_parent_name = nullptr;
|
2011-12-29 01:22:05 +04:00
|
|
|
|
2009-03-24 14:02:30 +03:00
|
|
|
if (!primary_iid->Equals(NS_GET_IID(nsISupports))) {
|
2012-08-22 05:42:53 +04:00
|
|
|
JSAutoCompartment ac(cx, class_obj);
|
2011-01-11 23:15:52 +03:00
|
|
|
|
2009-03-24 14:02:30 +03:00
|
|
|
rv = DefineInterfaceConstants(cx, class_obj, primary_iid);
|
2009-03-26 17:53:33 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-12-09 22:08:45 +03:00
|
|
|
|
2011-12-29 01:22:05 +04:00
|
|
|
nsCOMPtr<nsIInterfaceInfoManager>
|
|
|
|
iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID));
|
|
|
|
NS_ENSURE_TRUE(iim, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
|
|
|
|
iim->GetInfoForIID(primary_iid, getter_AddRefs(if_info));
|
|
|
|
NS_ENSURE_TRUE(if_info, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
const nsIID *iid = nullptr;
|
2011-12-29 01:22:05 +04:00
|
|
|
|
|
|
|
if (ci_data && !ci_data->mHasClassInterface) {
|
|
|
|
if_info->GetIIDShared(&iid);
|
|
|
|
} else {
|
|
|
|
if_info->GetParent(getter_AddRefs(parent));
|
|
|
|
NS_ENSURE_TRUE(parent, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
parent->GetIIDShared(&iid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iid) {
|
|
|
|
if (!iid->Equals(NS_GET_IID(nsISupports))) {
|
|
|
|
if (ci_data && !ci_data->mHasClassInterface) {
|
|
|
|
// If the class doesn't have a class interface the primary
|
|
|
|
// interface is the interface that should be
|
|
|
|
// constructor.prototype.__proto__.
|
|
|
|
|
|
|
|
if_info->GetNameShared(&class_parent_name);
|
|
|
|
} else {
|
|
|
|
// If the class does have a class interface (or there's no
|
|
|
|
// real class for this name) then the parent of the
|
|
|
|
// primary interface is what we want on
|
|
|
|
// constructor.prototype.__proto__.
|
|
|
|
|
|
|
|
NS_ASSERTION(parent, "Whoa, this is bad, null parent here!");
|
|
|
|
|
|
|
|
parent->GetNameShared(&class_parent_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-24 14:02:30 +03:00
|
|
|
}
|
2001-12-06 09:57:03 +03:00
|
|
|
|
2010-10-19 02:20:47 +04:00
|
|
|
{
|
2013-05-03 22:53:32 +04:00
|
|
|
JS::Rooted<JSObject*> winobj(cx, aWin->FastGetGlobalJSObject());
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2013-05-03 22:53:32 +04:00
|
|
|
JS::Rooted<JSObject*> proto(cx);
|
2011-12-29 01:22:05 +04:00
|
|
|
|
|
|
|
if (class_parent_name) {
|
2012-08-22 05:42:53 +04:00
|
|
|
JSAutoCompartment ac(cx, winobj);
|
2011-12-29 01:22:05 +04:00
|
|
|
|
2016-01-28 13:28:04 +03:00
|
|
|
JS::Rooted<JS::PropertyDescriptor> desc(cx);
|
2014-12-17 02:28:39 +03:00
|
|
|
if (!JS_GetPropertyDescriptor(cx, winobj, CutPrefix(class_parent_name), &desc)) {
|
2011-12-29 01:22:05 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2014-12-17 02:28:39 +03:00
|
|
|
if (desc.object() && !desc.hasGetterOrSetter() && desc.value().isObject()) {
|
|
|
|
JS::Rooted<JSObject*> obj(cx, &desc.value().toObject());
|
|
|
|
if (!JS_GetPropertyDescriptor(cx, obj, "prototype", &desc)) {
|
2011-12-29 01:22:05 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2014-12-17 02:28:39 +03:00
|
|
|
if (desc.object() && !desc.hasGetterOrSetter() && desc.value().isObject()) {
|
|
|
|
proto = &desc.value().toObject();
|
2011-12-29 01:22:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-11-07 10:52:41 +03:00
|
|
|
|
2010-10-19 02:20:47 +04:00
|
|
|
if (dot_prototype) {
|
2012-08-22 05:42:53 +04:00
|
|
|
JSAutoCompartment ac(cx, dot_prototype);
|
2013-05-03 22:53:32 +04:00
|
|
|
JS::Rooted<JSObject*> xpc_proto_proto(cx);
|
2013-07-31 20:20:33 +04:00
|
|
|
if (!::JS_GetPrototype(cx, dot_prototype, &xpc_proto_proto)) {
|
2012-09-04 03:42:17 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2010-10-19 02:20:47 +04:00
|
|
|
if (proto &&
|
|
|
|
(!xpc_proto_proto ||
|
2012-02-04 04:54:57 +04:00
|
|
|
JS_GetClass(xpc_proto_proto) == sObjectClass)) {
|
2013-10-16 04:02:23 +04:00
|
|
|
if (!JS_WrapObject(cx, &proto) ||
|
2010-11-02 08:24:24 +03:00
|
|
|
!JS_SetPrototype(cx, dot_prototype, proto)) {
|
2010-10-19 02:20:47 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2009-03-26 17:53:33 +03:00
|
|
|
}
|
2010-10-19 02:20:47 +04:00
|
|
|
} else {
|
2012-08-22 05:42:53 +04:00
|
|
|
JSAutoCompartment ac(cx, winobj);
|
2012-11-21 20:19:26 +04:00
|
|
|
if (!proto) {
|
|
|
|
proto = JS_GetObjectPrototype(cx, winobj);
|
|
|
|
}
|
|
|
|
dot_prototype = ::JS_NewObjectWithUniqueType(cx,
|
|
|
|
&sDOMConstructorProtoClass,
|
2015-03-09 19:49:50 +03:00
|
|
|
proto);
|
2010-10-19 02:20:47 +04:00
|
|
|
NS_ENSURE_TRUE(dot_prototype, NS_ERROR_OUT_OF_MEMORY);
|
2009-03-24 14:02:30 +03:00
|
|
|
}
|
|
|
|
}
|
2009-03-24 14:02:30 +03:00
|
|
|
|
2015-07-01 07:09:46 +03:00
|
|
|
v.setObject(*dot_prototype);
|
2002-08-30 12:48:58 +04:00
|
|
|
|
2012-08-22 05:42:53 +04:00
|
|
|
JSAutoCompartment ac(cx, class_obj);
|
2011-01-11 23:15:52 +03:00
|
|
|
|
2009-03-24 14:02:30 +03:00
|
|
|
// Per ECMA, the prototype property is {DontEnum, DontDelete, ReadOnly}
|
2013-10-26 20:19:05 +04:00
|
|
|
if (!JS_WrapValue(cx, &v) ||
|
2013-03-21 19:20:42 +04:00
|
|
|
!JS_DefineProperty(cx, class_obj, "prototype", v,
|
2014-10-29 22:06:32 +03:00
|
|
|
JSPROP_PERMANENT | JSPROP_READONLY,
|
2014-10-29 22:06:31 +03:00
|
|
|
JS_STUBGETTER, JS_STUBSETTER)) {
|
2009-03-24 14:02:30 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2009-03-24 14:02:30 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2012-06-14 18:56:38 +04:00
|
|
|
static bool
|
2013-06-13 09:12:26 +04:00
|
|
|
OldBindingConstructorEnabled(const nsGlobalNameStruct *aStruct,
|
2013-08-09 18:35:53 +04:00
|
|
|
nsGlobalWindow *aWin, JSContext *cx)
|
2012-06-14 18:56:38 +04:00
|
|
|
{
|
2014-02-16 01:12:34 +04:00
|
|
|
MOZ_ASSERT(aStruct->mType == nsGlobalNameStruct::eTypeProperty ||
|
|
|
|
aStruct->mType == nsGlobalNameStruct::eTypeClassConstructor ||
|
2012-06-14 18:56:38 +04:00
|
|
|
aStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo);
|
|
|
|
|
|
|
|
// Don't expose chrome only constructors to content windows.
|
2014-02-16 01:12:34 +04:00
|
|
|
if (aStruct->mChromeOnly) {
|
|
|
|
bool expose;
|
|
|
|
if (aStruct->mAllowXBL) {
|
|
|
|
expose = IsChromeOrXBL(cx, nullptr);
|
|
|
|
} else {
|
|
|
|
expose = nsContentUtils::IsSystemPrincipal(aWin->GetPrincipal());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!expose) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-02 04:32:12 +04:00
|
|
|
}
|
|
|
|
|
2012-06-14 18:56:38 +04:00
|
|
|
return true;
|
|
|
|
}
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2014-01-30 10:33:20 +04:00
|
|
|
static nsresult
|
2014-01-30 10:33:23 +04:00
|
|
|
LookupComponentsShim(JSContext *cx, JS::Handle<JSObject*> global,
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner *win,
|
2016-01-28 13:28:04 +03:00
|
|
|
JS::MutableHandle<JS::PropertyDescriptor> desc);
|
2014-01-30 10:33:20 +04:00
|
|
|
|
2014-09-05 22:28:45 +04:00
|
|
|
// static
|
2014-02-16 01:12:34 +04:00
|
|
|
bool
|
|
|
|
nsWindowSH::NameStructEnabled(JSContext* aCx, nsGlobalWindow *aWin,
|
|
|
|
const nsAString& aName,
|
|
|
|
const nsGlobalNameStruct& aNameStruct)
|
|
|
|
{
|
|
|
|
const nsGlobalNameStruct* nameStruct = &aNameStruct;
|
|
|
|
if (nameStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfoCreator) {
|
|
|
|
nsresult rv = GetExternalClassInfo(GetNameSpaceManager(), aName, nameStruct,
|
|
|
|
&nameStruct);
|
|
|
|
if (NS_FAILED(rv) || !nameStruct) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (nameStruct->mType != nsGlobalNameStruct::eTypeProperty &&
|
|
|
|
nameStruct->mType != nsGlobalNameStruct::eTypeClassConstructor &&
|
|
|
|
nameStruct->mType != nsGlobalNameStruct::eTypeExternalClassInfo) ||
|
|
|
|
OldBindingConstructorEnabled(nameStruct, aWin, aCx);
|
|
|
|
}
|
|
|
|
|
2014-05-20 00:08:08 +04:00
|
|
|
#ifdef RELEASE_BUILD
|
|
|
|
#define USE_CONTROLLERS_SHIM
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_CONTROLLERS_SHIM
|
|
|
|
static const JSClass ControllersShimClass = {
|
2014-11-22 21:23:39 +03:00
|
|
|
"XULControllers", 0
|
2014-05-20 00:08:08 +04:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2009-03-24 14:02:30 +03:00
|
|
|
// static
|
|
|
|
nsresult
|
2010-09-18 01:54:40 +04:00
|
|
|
nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
|
2013-05-04 11:51:53 +04:00
|
|
|
JS::Handle<JSObject*> obj, JS::Handle<jsid> id,
|
2016-01-28 13:28:04 +03:00
|
|
|
JS::MutableHandle<JS::PropertyDescriptor> desc)
|
2009-03-24 14:02:30 +03:00
|
|
|
{
|
2014-01-30 10:33:20 +04:00
|
|
|
if (id == XPCJSRuntime::Get()->GetStringID(XPCJSRuntime::IDX_COMPONENTS)) {
|
2016-01-30 20:05:36 +03:00
|
|
|
return LookupComponentsShim(cx, obj, aWin->AsInner(), desc);
|
2014-01-30 10:33:20 +04:00
|
|
|
}
|
|
|
|
|
2014-05-20 00:08:08 +04:00
|
|
|
#ifdef USE_CONTROLLERS_SHIM
|
2014-07-02 21:13:14 +04:00
|
|
|
// Note: We use |obj| rather than |aWin| to get the principal here, because
|
|
|
|
// this is called during Window setup when the Document isn't necessarily
|
|
|
|
// hooked up yet.
|
2014-05-20 00:08:08 +04:00
|
|
|
if (id == XPCJSRuntime::Get()->GetStringID(XPCJSRuntime::IDX_CONTROLLERS) &&
|
|
|
|
!xpc::IsXrayWrapper(obj) &&
|
2014-07-02 21:13:14 +04:00
|
|
|
!nsContentUtils::IsSystemPrincipal(nsContentUtils::ObjectPrincipal(obj)))
|
2014-05-20 00:08:08 +04:00
|
|
|
{
|
|
|
|
if (aWin->GetDoc()) {
|
|
|
|
aWin->GetDoc()->WarnOnceAbout(nsIDocument::eWindow_Controllers);
|
|
|
|
}
|
2015-02-13 14:20:02 +03:00
|
|
|
MOZ_ASSERT(JS_IsGlobalObject(obj));
|
|
|
|
JS::Rooted<JSObject*> shim(cx, JS_NewObject(cx, &ControllersShimClass));
|
2014-05-20 00:08:08 +04:00
|
|
|
if (NS_WARN_IF(!shim)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
FillPropertyDescriptor(desc, obj, JS::ObjectValue(*shim), /* readOnly = */ false);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-08-20 03:24:29 +04:00
|
|
|
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
|
2009-03-24 14:02:30 +03:00
|
|
|
NS_ENSURE_TRUE(nameSpaceManager, NS_ERROR_NOT_INITIALIZED);
|
2005-09-02 03:02:57 +04:00
|
|
|
|
2014-11-08 03:07:12 +03:00
|
|
|
// Note - Our only caller is nsGlobalWindow::DoResolve, which checks that
|
2014-06-11 07:15:56 +04:00
|
|
|
// JSID_IS_STRING(id) is true.
|
2014-07-05 19:30:54 +04:00
|
|
|
nsAutoJSString name;
|
|
|
|
if (!name.init(cx, JSID_TO_STRING(id))) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2005-09-02 03:02:57 +04:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *class_name = nullptr;
|
2012-03-29 22:43:13 +04:00
|
|
|
const nsGlobalNameStruct *name_struct =
|
|
|
|
nameSpaceManager->LookupName(name, &class_name);
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2009-03-24 14:02:30 +03:00
|
|
|
if (!name_struct) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2014-01-30 10:33:23 +04:00
|
|
|
// The class_name had better match our name
|
|
|
|
MOZ_ASSERT(name.Equals(class_name));
|
|
|
|
|
2009-03-24 14:02:30 +03:00
|
|
|
NS_ENSURE_TRUE(class_name, NS_ERROR_UNEXPECTED);
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2009-03-24 14:02:30 +03:00
|
|
|
nsresult rv = NS_OK;
|
2002-03-04 05:25:08 +03:00
|
|
|
|
2009-03-24 14:02:30 +03:00
|
|
|
if (name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfoCreator) {
|
|
|
|
rv = GetExternalClassInfo(nameSpaceManager, name, name_struct,
|
|
|
|
&name_struct);
|
|
|
|
if (NS_FAILED(rv) || !name_struct) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
2002-03-04 05:25:08 +03:00
|
|
|
|
2012-06-14 18:56:38 +04:00
|
|
|
if (name_struct->mType == nsGlobalNameStruct::eTypeNewDOMBinding ||
|
|
|
|
name_struct->mType == nsGlobalNameStruct::eTypeInterface ||
|
|
|
|
name_struct->mType == nsGlobalNameStruct::eTypeClassProto ||
|
|
|
|
name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) {
|
2012-03-31 08:42:20 +04:00
|
|
|
// Lookup new DOM bindings.
|
2014-01-30 10:33:22 +04:00
|
|
|
DefineInterface getOrCreateInterfaceObject =
|
2012-03-31 08:42:20 +04:00
|
|
|
name_struct->mDefineDOMInterface;
|
2014-01-30 10:33:22 +04:00
|
|
|
if (getOrCreateInterfaceObject) {
|
2012-06-14 18:56:38 +04:00
|
|
|
if (name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor &&
|
2013-08-09 18:35:53 +04:00
|
|
|
!OldBindingConstructorEnabled(name_struct, aWin, cx)) {
|
2012-09-05 21:37:28 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-30 10:33:22 +04:00
|
|
|
ConstructorEnabled* checkEnabledForScope = name_struct->mConstructorEnabled;
|
2014-02-05 22:38:18 +04:00
|
|
|
// We do the enabled check on the current compartment of cx, but for the
|
|
|
|
// actual object we pass in the underlying object in the Xray case. That
|
|
|
|
// way the callee can decide whether to allow access based on the caller
|
|
|
|
// or the window being touched.
|
|
|
|
JS::Rooted<JSObject*> global(cx,
|
2015-11-06 21:03:52 +03:00
|
|
|
js::CheckedUnwrap(obj, /* stopAtWindowProxy = */ false));
|
2014-02-05 22:38:18 +04:00
|
|
|
if (!global) {
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
|
|
|
if (checkEnabledForScope && !checkEnabledForScope(cx, global)) {
|
2014-01-30 10:33:22 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-30 10:33:23 +04:00
|
|
|
// The DOM constructor resolve machinery interacts with Xrays in tricky
|
|
|
|
// ways, and there are some asymmetries that are important to understand.
|
|
|
|
//
|
|
|
|
// In the regular (non-Xray) case, we only want to resolve constructors
|
|
|
|
// once (so that if they're deleted, they don't reappear). We do this by
|
|
|
|
// stashing the constructor in a slot on the global, such that we can see
|
|
|
|
// during resolve whether we've created it already. This is rather
|
|
|
|
// memory-intensive, so we don't try to maintain these semantics when
|
|
|
|
// manipulating a global over Xray (so the properties just re-resolve if
|
|
|
|
// they've been deleted).
|
|
|
|
//
|
|
|
|
// Unfortunately, there's a bit of an impedance-mismatch between the Xray
|
|
|
|
// and non-Xray machinery. The Xray machinery wants an API that returns a
|
2016-01-28 13:28:04 +03:00
|
|
|
// JS::PropertyDescriptor, so that the resolve hook doesn't have to get
|
2014-01-30 10:33:23 +04:00
|
|
|
// snared up with trying to define a property on the Xray holder. At the
|
|
|
|
// same time, the DefineInterface callbacks are set up to define things
|
|
|
|
// directly on the global. And re-jiggering them to return property
|
|
|
|
// descriptors is tricky, because some DefineInterface callbacks define
|
|
|
|
// multiple things (like the Image() alias for HTMLImageElement).
|
|
|
|
//
|
|
|
|
// So the setup is as-follows:
|
|
|
|
//
|
2016-01-28 13:28:04 +03:00
|
|
|
// * The resolve function takes a JS::PropertyDescriptor, but in the
|
2014-01-30 10:33:23 +04:00
|
|
|
// non-Xray case, callees may define things directly on the global, and
|
|
|
|
// set the value on the property descriptor to |undefined| to indicate
|
|
|
|
// that there's nothing more for the caller to do. We assert against
|
|
|
|
// this behavior in the Xray case.
|
|
|
|
//
|
|
|
|
// * We make sure that we do a non-Xray resolve first, so that all the
|
|
|
|
// slots are set up. In the Xray case, this means unwrapping and doing
|
|
|
|
// a non-Xray resolve before doing the Xray resolve.
|
|
|
|
//
|
|
|
|
// This all could use some grand refactoring, but for now we just limp
|
|
|
|
// along.
|
|
|
|
if (xpc::WrapperFactory::IsXrayWrapper(obj)) {
|
|
|
|
JS::Rooted<JSObject*> interfaceObject(cx);
|
|
|
|
{
|
|
|
|
JSAutoCompartment ac(cx, global);
|
|
|
|
interfaceObject = getOrCreateInterfaceObject(cx, global, id, false);
|
|
|
|
}
|
|
|
|
if (NS_WARN_IF(!interfaceObject)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
if (!JS_WrapObject(cx, &interfaceObject)) {
|
2012-10-09 22:50:27 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-01-30 10:33:23 +04:00
|
|
|
FillPropertyDescriptor(desc, obj, 0, JS::ObjectValue(*interfaceObject));
|
|
|
|
} else {
|
|
|
|
JS::Rooted<JSObject*> interfaceObject(cx,
|
|
|
|
getOrCreateInterfaceObject(cx, obj, id, true));
|
|
|
|
if (NS_WARN_IF(!interfaceObject)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
// We've already defined the property. We indicate this to the caller
|
|
|
|
// by filling a property descriptor with JS::UndefinedValue() as the
|
|
|
|
// value. We still have to fill in a property descriptor, though, so
|
|
|
|
// that the caller knows the property is in fact on this object. It
|
|
|
|
// doesn't matter what we pass for the "readonly" argument here.
|
|
|
|
FillPropertyDescriptor(desc, obj, JS::UndefinedValue(), false);
|
2013-08-08 01:40:00 +04:00
|
|
|
}
|
2012-10-09 22:50:27 +04:00
|
|
|
|
2013-08-08 01:40:00 +04:00
|
|
|
return NS_OK;
|
2012-03-31 08:42:20 +04:00
|
|
|
}
|
2012-06-14 18:56:38 +04:00
|
|
|
}
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2012-06-14 18:56:38 +04:00
|
|
|
if (name_struct->mType == nsGlobalNameStruct::eTypeInterface) {
|
|
|
|
// We're resolving a name of a DOM interface for which there is no
|
|
|
|
// direct DOM class, create a constructor object...
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsDOMConstructor> constructor;
|
2009-06-03 19:30:18 +04:00
|
|
|
rv = nsDOMConstructor::Create(class_name,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr,
|
2009-03-24 14:02:30 +03:00
|
|
|
name_struct,
|
2016-01-30 20:05:36 +03:00
|
|
|
aWin->AsInner(),
|
2009-03-24 14:02:30 +03:00
|
|
|
getter_AddRefs(constructor));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-03-04 05:25:08 +03:00
|
|
|
|
2013-05-03 22:53:32 +04:00
|
|
|
JS::Rooted<JS::Value> v(cx);
|
2014-04-10 08:58:42 +04:00
|
|
|
js::AssertSameCompartment(cx, obj);
|
2015-02-04 11:40:59 +03:00
|
|
|
rv = nsContentUtils::WrapNative(cx, constructor,
|
|
|
|
&NS_GET_IID(nsIDOMDOMConstructor), &v,
|
|
|
|
false);
|
2009-03-24 14:02:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-03-24 16:47:01 +03:00
|
|
|
|
2014-01-06 23:54:43 +04:00
|
|
|
JS::Rooted<JSObject*> class_obj(cx, &v.toObject());
|
2009-03-26 17:53:33 +03:00
|
|
|
|
2009-03-24 14:02:30 +03:00
|
|
|
// ... and define the constants from the DOM interface on that
|
|
|
|
// constructor object.
|
|
|
|
|
2014-01-30 10:33:23 +04:00
|
|
|
{
|
|
|
|
JSAutoCompartment ac(cx, class_obj);
|
|
|
|
rv = DefineInterfaceConstants(cx, class_obj, &name_struct->mIID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2014-01-30 10:33:23 +04:00
|
|
|
if (!JS_WrapValue(cx, &v)) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2014-01-30 10:33:23 +04:00
|
|
|
FillPropertyDescriptor(desc, obj, 0, v);
|
2001-07-11 13:09:30 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-03-24 14:02:30 +03:00
|
|
|
if (name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor ||
|
2009-06-03 19:30:18 +04:00
|
|
|
name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) {
|
2013-08-09 18:35:53 +04:00
|
|
|
if (!OldBindingConstructorEnabled(name_struct, aWin, cx)) {
|
2010-04-20 20:44:56 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-06-03 19:30:18 +04:00
|
|
|
// Create the XPConnect prototype for our classinfo, PostCreateProto will
|
2014-01-30 10:33:23 +04:00
|
|
|
// set up the prototype chain. This will go ahead and define things on the
|
|
|
|
// actual window's global.
|
2015-02-04 11:41:00 +03:00
|
|
|
JS::Rooted<JSObject*> dot_prototype(cx);
|
2014-09-05 22:28:45 +04:00
|
|
|
rv = GetXPCProto(nsDOMClassInfo::sXPConnect, cx, aWin, name_struct,
|
2015-02-04 11:41:00 +03:00
|
|
|
&dot_prototype);
|
2014-01-30 10:33:23 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-02-04 11:41:00 +03:00
|
|
|
MOZ_ASSERT(dot_prototype);
|
|
|
|
|
2014-01-30 10:33:23 +04:00
|
|
|
bool isXray = xpc::WrapperFactory::IsXrayWrapper(obj);
|
|
|
|
MOZ_ASSERT_IF(obj != aWin->GetGlobalJSObject(), isXray);
|
|
|
|
if (!isXray) {
|
|
|
|
// GetXPCProto already defined the property for us
|
|
|
|
FillPropertyDescriptor(desc, obj, JS::UndefinedValue(), false);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-06-03 19:30:18 +04:00
|
|
|
|
2014-01-30 10:33:23 +04:00
|
|
|
// This is the Xray case. Look up the constructor object for this
|
|
|
|
// prototype.
|
|
|
|
const nsDOMClassInfoData *ci_data;
|
|
|
|
if (name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) {
|
|
|
|
ci_data = &sClassInfoData[name_struct->mDOMClassInfoID];
|
|
|
|
} else {
|
|
|
|
ci_data = name_struct->mData;
|
2009-07-22 22:50:24 +04:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:28:45 +04:00
|
|
|
return ResolvePrototype(nsDOMClassInfo::sXPConnect, aWin, cx, obj,
|
|
|
|
class_name, ci_data,
|
2014-01-30 10:33:23 +04:00
|
|
|
name_struct, nameSpaceManager, dot_prototype,
|
|
|
|
desc);
|
2009-06-03 19:30:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (name_struct->mType == nsGlobalNameStruct::eTypeClassProto) {
|
|
|
|
// We don't have a XPConnect prototype object, let ResolvePrototype create
|
|
|
|
// one.
|
2014-09-05 22:28:45 +04:00
|
|
|
return ResolvePrototype(nsDOMClassInfo::sXPConnect, aWin, cx, obj,
|
|
|
|
class_name, nullptr,
|
2014-01-30 10:33:23 +04:00
|
|
|
name_struct, nameSpaceManager, nullptr, desc);
|
2009-06-03 19:30:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias) {
|
|
|
|
const nsGlobalNameStruct *alias_struct =
|
|
|
|
nameSpaceManager->GetConstructorProto(name_struct);
|
|
|
|
NS_ENSURE_TRUE(alias_struct, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
// We need to use the XPConnect prototype for the DOM class that this
|
|
|
|
// constructor is an alias for (for example for Image we need the prototype
|
|
|
|
// for HTMLImageElement).
|
2015-02-04 11:41:00 +03:00
|
|
|
JS::Rooted<JSObject*> dot_prototype(cx);
|
2014-09-05 22:28:45 +04:00
|
|
|
rv = GetXPCProto(nsDOMClassInfo::sXPConnect, cx, aWin, alias_struct,
|
2015-02-04 11:41:00 +03:00
|
|
|
&dot_prototype);
|
2009-06-03 19:30:18 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-02-04 11:41:00 +03:00
|
|
|
MOZ_ASSERT(dot_prototype);
|
2009-06-03 19:30:18 +04:00
|
|
|
|
|
|
|
const nsDOMClassInfoData *ci_data;
|
|
|
|
if (alias_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) {
|
|
|
|
ci_data = &sClassInfoData[alias_struct->mDOMClassInfoID];
|
|
|
|
} else if (alias_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) {
|
|
|
|
ci_data = alias_struct->mData;
|
|
|
|
} else {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:28:45 +04:00
|
|
|
return ResolvePrototype(nsDOMClassInfo::sXPConnect, aWin, cx, obj,
|
|
|
|
class_name, ci_data,
|
2014-01-30 10:33:23 +04:00
|
|
|
name_struct, nameSpaceManager, nullptr, desc);
|
2009-03-24 14:02:30 +03:00
|
|
|
}
|
|
|
|
|
2001-07-11 13:09:30 +04:00
|
|
|
if (name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructor) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsDOMConstructor> constructor;
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = nsDOMConstructor::Create(class_name, nullptr, name_struct,
|
2016-01-30 20:05:36 +03:00
|
|
|
aWin->AsInner(), getter_AddRefs(constructor));
|
2008-02-27 05:03:27 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2013-05-03 22:53:32 +04:00
|
|
|
JS::Rooted<JS::Value> val(cx);
|
2014-04-10 08:58:42 +04:00
|
|
|
js::AssertSameCompartment(cx, obj);
|
2015-02-04 11:40:59 +03:00
|
|
|
rv = nsContentUtils::WrapNative(cx, constructor,
|
|
|
|
&NS_GET_IID(nsIDOMDOMConstructor), &val,
|
|
|
|
true);
|
2005-12-09 22:08:45 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-01-06 23:54:43 +04:00
|
|
|
NS_ASSERTION(val.isObject(), "Why didn't we get a JSObject?");
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2014-01-30 10:33:23 +04:00
|
|
|
FillPropertyDescriptor(desc, obj, 0, val);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name_struct->mType == nsGlobalNameStruct::eTypeProperty) {
|
2014-02-16 01:12:34 +04:00
|
|
|
if (!OldBindingConstructorEnabled(name_struct, aWin, cx))
|
2007-06-26 18:44:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2013-07-03 04:35:36 +04:00
|
|
|
// Before defining a global property, check for a named subframe of the
|
|
|
|
// same name. If it exists, we don't want to shadow it.
|
2016-01-30 20:05:36 +03:00
|
|
|
if (nsCOMPtr<nsPIDOMWindowOuter> childWin = aWin->GetChildWindow(name)) {
|
2013-07-03 04:35:36 +04:00
|
|
|
return NS_OK;
|
2016-01-30 20:05:36 +03:00
|
|
|
}
|
2013-07-03 04:35:36 +04:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
nsCOMPtr<nsISupports> native(do_CreateInstance(name_struct->mCID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-05-03 22:53:32 +04:00
|
|
|
JS::Rooted<JS::Value> prop_val(cx, JS::UndefinedValue()); // Property value.
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2012-07-14 02:23:59 +04:00
|
|
|
nsCOMPtr<nsIDOMGlobalPropertyInitializer> gpi(do_QueryInterface(native));
|
|
|
|
if (gpi) {
|
2016-01-30 20:05:36 +03:00
|
|
|
rv = gpi->Init(aWin->AsInner(), &prop_val);
|
2012-07-14 02:23:59 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-11-10 02:00:01 +03:00
|
|
|
}
|
|
|
|
|
2014-04-28 07:27:54 +04:00
|
|
|
if (prop_val.isPrimitive() && !prop_val.isNull()) {
|
2015-02-04 11:40:59 +03:00
|
|
|
rv = nsContentUtils::WrapNative(cx, native, &prop_val, true);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-10-26 20:19:05 +04:00
|
|
|
if (!JS_WrapValue(cx, &prop_val)) {
|
2011-02-04 20:55:21 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2014-01-30 10:33:23 +04:00
|
|
|
FillPropertyDescriptor(desc, obj, prop_val, false);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2014-01-30 10:33:23 +04:00
|
|
|
return NS_OK;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-03-28 05:27:26 +04:00
|
|
|
struct InterfaceShimEntry {
|
|
|
|
const char *geckoName;
|
|
|
|
const char *domName;
|
|
|
|
};
|
|
|
|
|
|
|
|
// We add shims from Components.interfaces.nsIDOMFoo to window.Foo for each
|
|
|
|
// interface that has interface constants that sites might be getting off
|
|
|
|
// of Ci.
|
|
|
|
const InterfaceShimEntry kInterfaceShimMap[] =
|
2015-12-09 23:52:15 +03:00
|
|
|
{ { "nsIXMLHttpRequest", "XMLHttpRequest" },
|
2013-03-28 05:27:26 +04:00
|
|
|
{ "nsIDOMDOMException", "DOMException" },
|
|
|
|
{ "nsIDOMNode", "Node" },
|
|
|
|
{ "nsIDOMCSSPrimitiveValue", "CSSPrimitiveValue" },
|
|
|
|
{ "nsIDOMCSSRule", "CSSRule" },
|
|
|
|
{ "nsIDOMCSSValue", "CSSValue" },
|
|
|
|
{ "nsIDOMEvent", "Event" },
|
|
|
|
{ "nsIDOMNSEvent", "Event" },
|
|
|
|
{ "nsIDOMKeyEvent", "KeyEvent" },
|
|
|
|
{ "nsIDOMMouseEvent", "MouseEvent" },
|
|
|
|
{ "nsIDOMMouseScrollEvent", "MouseScrollEvent" },
|
|
|
|
{ "nsIDOMMutationEvent", "MutationEvent" },
|
|
|
|
{ "nsIDOMSimpleGestureEvent", "SimpleGestureEvent" },
|
|
|
|
{ "nsIDOMUIEvent", "UIEvent" },
|
|
|
|
{ "nsIDOMHTMLMediaElement", "HTMLMediaElement" },
|
|
|
|
{ "nsIDOMMediaError", "MediaError" },
|
|
|
|
{ "nsIDOMOfflineResourceList", "OfflineResourceList" },
|
|
|
|
{ "nsIDOMRange", "Range" },
|
|
|
|
{ "nsIDOMSVGLength", "SVGLength" },
|
|
|
|
{ "nsIDOMNodeFilter", "NodeFilter" },
|
2013-08-09 18:35:54 +04:00
|
|
|
{ "nsIDOMXPathResult", "XPathResult" } };
|
2013-03-28 05:27:26 +04:00
|
|
|
|
|
|
|
static nsresult
|
2014-01-30 10:33:23 +04:00
|
|
|
LookupComponentsShim(JSContext *cx, JS::Handle<JSObject*> global,
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner *win,
|
2016-01-28 13:28:04 +03:00
|
|
|
JS::MutableHandle<JS::PropertyDescriptor> desc)
|
2013-03-28 05:27:26 +04:00
|
|
|
{
|
2013-03-28 05:27:27 +04:00
|
|
|
// Keep track of how often this happens.
|
|
|
|
Telemetry::Accumulate(Telemetry::COMPONENTS_SHIM_ACCESSED_BY_CONTENT, true);
|
|
|
|
|
2013-08-19 21:44:31 +04:00
|
|
|
// Warn once.
|
|
|
|
nsCOMPtr<nsIDocument> doc = win->GetExtantDoc();
|
|
|
|
if (doc) {
|
|
|
|
doc->WarnOnceAbout(nsIDocument::eComponents, /* asError = */ true);
|
|
|
|
}
|
|
|
|
|
2013-03-28 05:27:26 +04:00
|
|
|
// Create a fake Components object.
|
2015-01-24 18:38:08 +03:00
|
|
|
AssertSameCompartment(cx, global);
|
|
|
|
JS::Rooted<JSObject*> components(cx, JS_NewPlainObject(cx));
|
2013-03-28 05:27:26 +04:00
|
|
|
NS_ENSURE_TRUE(components, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
// Create a fake interfaces object.
|
2015-01-24 18:38:08 +03:00
|
|
|
JS::Rooted<JSObject*> interfaces(cx, JS_NewPlainObject(cx));
|
2013-03-28 05:27:26 +04:00
|
|
|
NS_ENSURE_TRUE(interfaces, NS_ERROR_OUT_OF_MEMORY);
|
2014-01-30 10:33:23 +04:00
|
|
|
bool ok =
|
2014-01-22 06:11:17 +04:00
|
|
|
JS_DefineProperty(cx, components, "interfaces", interfaces,
|
2014-10-29 22:06:32 +03:00
|
|
|
JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY,
|
2014-10-29 22:06:31 +03:00
|
|
|
JS_STUBGETTER, JS_STUBSETTER);
|
2013-03-28 05:27:26 +04:00
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
// Define a bunch of shims from the Ci.nsIDOMFoo to window.Foo for DOM
|
|
|
|
// interfaces with constants.
|
|
|
|
for (uint32_t i = 0; i < ArrayLength(kInterfaceShimMap); ++i) {
|
|
|
|
|
|
|
|
// Grab the names from the table.
|
|
|
|
const char *geckoName = kInterfaceShimMap[i].geckoName;
|
|
|
|
const char *domName = kInterfaceShimMap[i].domName;
|
|
|
|
|
|
|
|
// Look up the appopriate interface object on the global.
|
2013-05-03 22:53:32 +04:00
|
|
|
JS::Rooted<JS::Value> v(cx, JS::UndefinedValue());
|
2013-07-26 13:00:38 +04:00
|
|
|
ok = JS_GetProperty(cx, global, domName, &v);
|
2013-03-28 05:27:26 +04:00
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
if (!v.isObject()) {
|
|
|
|
NS_WARNING("Unable to find interface object on global");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Define the shim on the interfaces object.
|
|
|
|
ok = JS_DefineProperty(cx, interfaces, geckoName, v,
|
2014-10-29 22:06:32 +03:00
|
|
|
JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY,
|
2014-10-29 22:06:31 +03:00
|
|
|
JS_STUBGETTER, JS_STUBSETTER);
|
2013-03-28 05:27:26 +04:00
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
}
|
|
|
|
|
2014-01-30 10:33:23 +04:00
|
|
|
FillPropertyDescriptor(desc, global, JS::ObjectValue(*components), false);
|
|
|
|
|
2013-03-28 05:27:26 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-08-14 15:04:43 +04:00
|
|
|
// EventTarget helper
|
|
|
|
|
2008-11-13 19:54:52 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventTargetSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
|
2013-05-04 11:51:53 +04:00
|
|
|
JSObject *aGlobalObj, JSObject **parentObj)
|
2008-11-13 19:54:52 +03:00
|
|
|
{
|
2013-05-04 11:51:53 +04:00
|
|
|
JS::Rooted<JSObject*> globalObj(cx, aGlobalObj);
|
2014-04-01 10:13:50 +04:00
|
|
|
DOMEventTargetHelper* target = DOMEventTargetHelper::FromSupports(nativeObj);
|
2008-11-13 19:54:52 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> native_parent;
|
|
|
|
target->GetParentObject(getter_AddRefs(native_parent));
|
|
|
|
|
|
|
|
*parentObj = native_parent ? native_parent->GetGlobalJSObject() : globalObj;
|
|
|
|
|
2012-04-27 12:38:14 +04:00
|
|
|
return *parentObj ? NS_OK : NS_ERROR_FAILURE;
|
2008-11-13 19:54:52 +03:00
|
|
|
}
|
|
|
|
|
2008-09-25 18:40:30 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventTargetSH::AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2015-03-28 16:47:02 +03:00
|
|
|
JSObject *obj, jsid id, JS::Handle<JS::Value> val,
|
|
|
|
bool *_retval)
|
2008-09-25 18:40:30 +04:00
|
|
|
{
|
2009-11-29 11:32:39 +03:00
|
|
|
nsEventTargetSH::PreserveWrapper(GetNative(wrapper, obj));
|
2008-11-13 19:54:52 +03:00
|
|
|
|
2008-11-06 14:09:30 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-11-29 11:32:39 +03:00
|
|
|
void
|
|
|
|
nsEventTargetSH::PreserveWrapper(nsISupports *aNative)
|
|
|
|
{
|
2014-04-01 10:13:50 +04:00
|
|
|
DOMEventTargetHelper* target = DOMEventTargetHelper::FromSupports(aNative);
|
2013-06-23 11:15:42 +04:00
|
|
|
target->PreserveWrapper(aNative);
|
2009-11-29 11:32:39 +03:00
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
// nsIDOMEventListener::HandleEvent() 'this' converter helper
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsEventListenerThisTranslator)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIXPCFunctionThisTranslator)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsEventListenerThisTranslator)
|
|
|
|
NS_IMPL_RELEASE(nsEventListenerThisTranslator)
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventListenerThisTranslator::TranslateThis(nsISupports *aInitialThis,
|
|
|
|
nsISupports **_retval)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMEvent> event(do_QueryInterface(aInitialThis));
|
|
|
|
NS_ENSURE_TRUE(event, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2013-04-20 02:18:32 +04:00
|
|
|
nsCOMPtr<EventTarget> target = event->InternalDOMEvent()->GetCurrentTarget();
|
2014-03-15 23:00:15 +04:00
|
|
|
target.forget(_retval);
|
2001-04-01 05:10:59 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-12-09 22:08:45 +03:00
|
|
|
|
2011-01-11 23:15:52 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMConstructorSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
|
2013-05-04 11:51:53 +04:00
|
|
|
JSObject *aGlobalObj, JSObject **parentObj)
|
2011-01-11 23:15:52 +03:00
|
|
|
{
|
2013-05-04 11:51:53 +04:00
|
|
|
JS::Rooted<JSObject*> globalObj(cx, aGlobalObj);
|
2011-01-11 23:15:52 +03:00
|
|
|
nsDOMConstructor *wrapped = static_cast<nsDOMConstructor *>(nativeObj);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMDOMConstructor> is_constructor =
|
|
|
|
do_QueryInterface(nativeObj);
|
|
|
|
NS_ASSERTION(is_constructor, "How did we not get a constructor?");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return wrapped->PreCreate(cx, globalObj, parentObj);
|
|
|
|
}
|
|
|
|
|
2011-09-22 06:16:50 +04:00
|
|
|
NS_IMETHODIMP
|
2014-11-08 03:07:12 +03:00
|
|
|
nsDOMConstructorSH::Resolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|
|
|
JSObject *aObj, jsid aId, bool *resolvedp,
|
|
|
|
bool *_retval)
|
2011-09-22 06:16:50 +04:00
|
|
|
{
|
2013-05-04 11:51:53 +04:00
|
|
|
JS::Rooted<JSObject*> obj(cx, aObj);
|
|
|
|
JS::Rooted<jsid> id(cx, aId);
|
2011-09-22 06:16:50 +04:00
|
|
|
// For regular DOM constructors, we have our interface constants defined on
|
|
|
|
// us by nsWindowSH::GlobalResolve. However, XrayWrappers can't see these
|
|
|
|
// interface constants (as they look like expando properties) so we have to
|
|
|
|
// specially resolve those constants here, but only for Xray wrappers.
|
|
|
|
if (!ObjectIsNativeWrapper(cx, obj)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-03 22:53:32 +04:00
|
|
|
JS::Rooted<JSObject*> nativePropsObj(cx, xpc::XrayUtils::GetNativePropertiesObject(cx, obj));
|
2011-09-22 06:16:50 +04:00
|
|
|
nsDOMConstructor *wrapped =
|
|
|
|
static_cast<nsDOMConstructor *>(wrapper->Native());
|
|
|
|
nsresult rv = wrapped->ResolveInterfaceConstants(cx, nativePropsObj);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Now re-lookup the ID to see if we should report back that we resolved the
|
|
|
|
// looked-for constant. Note that we don't have to worry about infinitely
|
|
|
|
// recurring back here because the Xray wrapper's holder object doesn't call
|
2014-11-08 03:07:12 +03:00
|
|
|
// Resolve hooks.
|
2013-08-09 02:53:04 +04:00
|
|
|
bool found;
|
2011-09-22 06:16:50 +04:00
|
|
|
if (!JS_HasPropertyById(cx, nativePropsObj, id, &found)) {
|
2012-04-04 13:15:10 +04:00
|
|
|
*_retval = false;
|
2011-09-22 06:16:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
2014-11-08 03:07:12 +03:00
|
|
|
*resolvedp = true;
|
2011-09-22 06:16:50 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-09 16:04:59 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMConstructorSH::Call(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2013-05-04 21:25:15 +04:00
|
|
|
JSObject *aObj, const JS::CallArgs &args, bool *_retval)
|
2007-05-09 16:04:59 +04:00
|
|
|
{
|
2013-05-03 22:53:32 +04:00
|
|
|
JS::Rooted<JSObject*> obj(cx, aObj);
|
2013-04-26 10:48:40 +04:00
|
|
|
MOZ_ASSERT(obj);
|
|
|
|
|
2007-05-09 16:04:59 +04:00
|
|
|
nsDOMConstructor *wrapped =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsDOMConstructor *>(wrapper->Native());
|
2007-05-09 16:04:59 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
2007-11-12 09:43:14 +03:00
|
|
|
nsCOMPtr<nsIDOMDOMConstructor> is_constructor =
|
|
|
|
do_QueryWrappedNative(wrapper);
|
2007-05-09 16:04:59 +04:00
|
|
|
NS_ASSERTION(is_constructor, "How did we not get a constructor?");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-05-04 21:25:15 +04:00
|
|
|
return wrapped->Construct(wrapper, cx, obj, args, _retval);
|
2007-05-09 16:04:59 +04:00
|
|
|
}
|
|
|
|
|
2005-12-09 22:08:45 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMConstructorSH::Construct(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2013-05-04 21:25:15 +04:00
|
|
|
JSObject *aObj, const JS::CallArgs &args, bool *_retval)
|
2005-12-09 22:08:45 +03:00
|
|
|
{
|
2013-05-04 11:51:53 +04:00
|
|
|
JS::Rooted<JSObject*> obj(cx, aObj);
|
2013-04-26 10:48:40 +04:00
|
|
|
MOZ_ASSERT(obj);
|
|
|
|
|
2005-12-09 22:08:45 +03:00
|
|
|
nsDOMConstructor *wrapped =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsDOMConstructor *>(wrapper->Native());
|
2005-12-09 22:08:45 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
2007-11-12 09:52:07 +03:00
|
|
|
nsCOMPtr<nsIDOMDOMConstructor> is_constructor =
|
2007-11-12 09:43:14 +03:00
|
|
|
do_QueryWrappedNative(wrapper);
|
2005-12-09 22:08:45 +03:00
|
|
|
NS_ASSERTION(is_constructor, "How did we not get a constructor?");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-05-04 21:25:15 +04:00
|
|
|
return wrapped->Construct(wrapper, cx, obj, args, _retval);
|
2005-12-09 22:08:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMConstructorSH::HasInstance(nsIXPConnectWrappedNative *wrapper,
|
2014-01-09 21:39:36 +04:00
|
|
|
JSContext *cx, JSObject *aObj, JS::Handle<JS::Value> val,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *bp, bool *_retval)
|
2005-12-09 22:08:45 +03:00
|
|
|
{
|
2013-05-04 11:51:53 +04:00
|
|
|
JS::Rooted<JSObject*> obj(cx, aObj);
|
2005-12-09 22:08:45 +03:00
|
|
|
nsDOMConstructor *wrapped =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsDOMConstructor *>(wrapper->Native());
|
2005-12-09 22:08:45 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
2007-11-12 09:43:14 +03:00
|
|
|
nsCOMPtr<nsIDOMDOMConstructor> is_constructor =
|
|
|
|
do_QueryWrappedNative(wrapper);
|
2005-12-09 22:08:45 +03:00
|
|
|
NS_ASSERTION(is_constructor, "How did we not get a constructor?");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return wrapped->HasInstance(wrapper, cx, obj, val, bp, _retval);
|
|
|
|
}
|
2006-02-23 06:17:11 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsNonDOMObjectSH::GetFlags(uint32_t *aFlags)
|
2006-02-23 06:17:11 +03:00
|
|
|
{
|
|
|
|
// This is NOT a DOM Object. Use this helper class for cases when you need
|
|
|
|
// to do something like implement nsISecurityCheckedComponent in a meaningful
|
|
|
|
// way.
|
2012-07-13 16:33:25 +04:00
|
|
|
*aFlags = nsIClassInfo::MAIN_THREAD_ONLY | nsIClassInfo::SINGLETON_CLASSINFO;
|
2006-02-23 06:38:59 +03:00
|
|
|
return NS_OK;
|
2006-02-23 06:17:11 +03:00
|
|
|
}
|
2015-03-06 09:08:06 +03:00
|
|
|
|
|
|
|
// nsContentFrameMessageManagerSH
|
|
|
|
|
|
|
|
template<typename Super>
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMessageManagerSH<Super>::Resolve(nsIXPConnectWrappedNative* wrapper,
|
|
|
|
JSContext* cx, JSObject* obj_,
|
|
|
|
jsid id_, bool* resolvedp,
|
|
|
|
bool* _retval)
|
|
|
|
{
|
|
|
|
JS::Rooted<JSObject*> obj(cx, obj_);
|
|
|
|
JS::Rooted<jsid> id(cx, id_);
|
|
|
|
|
|
|
|
*_retval = SystemGlobalResolve(cx, obj, id, resolvedp);
|
|
|
|
NS_ENSURE_TRUE(*_retval, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
if (*resolvedp) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Super::Resolve(wrapper, cx, obj, id, resolvedp, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Super>
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMessageManagerSH<Super>::Enumerate(nsIXPConnectWrappedNative* wrapper,
|
|
|
|
JSContext* cx, JSObject* obj_,
|
|
|
|
bool* _retval)
|
|
|
|
{
|
|
|
|
JS::Rooted<JSObject*> obj(cx, obj_);
|
|
|
|
|
|
|
|
*_retval = SystemGlobalEnumerate(cx, obj);
|
|
|
|
NS_ENSURE_TRUE(*_retval, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// Don't call up to our superclass, since neither nsDOMGenericSH nor
|
|
|
|
// nsEventTargetSH have WANT_ENUMERATE.
|
|
|
|
return NS_OK;
|
|
|
|
}
|