2015-08-04 20:06:14 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00: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/.
|
2000-04-05 02:39:51 +00:00
|
|
|
*
|
|
|
|
* This Original Code has been modified by IBM Corporation.
|
|
|
|
* Modifications made by IBM described herein are
|
|
|
|
* Copyright (c) International Business Machines
|
|
|
|
* Corporation, 2000
|
|
|
|
*
|
|
|
|
* Modifications to Mozilla code or documentation
|
|
|
|
* identified per MPL Section 3.3
|
|
|
|
*
|
|
|
|
* Date Modified by Description of modification
|
|
|
|
* 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink
|
|
|
|
* use in OS2
|
1999-01-12 05:32:30 +00:00
|
|
|
*/
|
|
|
|
|
1999-02-01 22:34:51 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1999-02-16 19:30:04 +00:00
|
|
|
#include "nsDOMCID.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2004-04-01 19:44:17 +00:00
|
|
|
#include "nsDOMString.h"
|
2000-12-30 19:22:22 +00:00
|
|
|
#include "nsIDOMEvent.h"
|
1999-01-12 05:32:30 +00:00
|
|
|
#include "nsIAtom.h"
|
2007-10-30 04:03:42 +00:00
|
|
|
#include "nsIBaseWindow.h"
|
1999-02-17 11:09:57 +00:00
|
|
|
#include "nsIDOMAttr.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "nsIDOMElement.h"
|
1999-10-29 01:21:15 +00:00
|
|
|
#include "nsIDOMEventListener.h"
|
1999-01-12 05:32:30 +00:00
|
|
|
#include "nsIDOMNodeList.h"
|
1999-12-05 23:04:22 +00:00
|
|
|
#include "nsIDOMXULCommandDispatcher.h"
|
1999-02-17 11:09:57 +00:00
|
|
|
#include "nsIDOMXULElement.h"
|
2002-01-12 01:20:29 +00:00
|
|
|
#include "nsIDOMXULSelectCntrlItemEl.h"
|
1999-01-12 05:32:30 +00:00
|
|
|
#include "nsIDocument.h"
|
2014-05-24 18:51:06 +00:00
|
|
|
#include "nsLayoutStylesheetCache.h"
|
2015-04-28 14:22:38 +00:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2016-01-06 21:18:29 +00:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2014-03-17 06:56:53 +00:00
|
|
|
#include "mozilla/EventListenerManager.h"
|
2014-04-01 04:09:23 +00:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2014-04-03 04:18:36 +00:00
|
|
|
#include "mozilla/EventStates.h"
|
2016-10-18 04:29:03 +00:00
|
|
|
#include "mozilla/DeclarationBlockInlines.h"
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 18:00:39 +00:00
|
|
|
#include "nsFocusManager.h"
|
2004-04-12 21:56:09 +00:00
|
|
|
#include "nsHTMLStyleSheet.h"
|
2014-02-27 23:04:46 +00:00
|
|
|
#include "nsNameSpaceManager.h"
|
2001-07-31 19:05:34 +00:00
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
1999-12-17 00:06:28 +00:00
|
|
|
#include "nsIPresShell.h"
|
1999-11-18 02:25:33 +00:00
|
|
|
#include "nsIPrincipal.h"
|
1999-01-20 01:42:13 +00:00
|
|
|
#include "nsIRDFCompositeDataSource.h"
|
1999-01-12 05:32:30 +00:00
|
|
|
#include "nsIRDFNode.h"
|
|
|
|
#include "nsIRDFService.h"
|
1999-12-17 00:06:28 +00:00
|
|
|
#include "nsIScriptContext.h"
|
2014-07-18 15:59:00 +00:00
|
|
|
#include "nsIScriptError.h"
|
2013-08-08 23:51:34 +00:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
1999-01-12 05:32:30 +00:00
|
|
|
#include "nsIServiceManager.h"
|
2011-03-11 02:48:57 +00:00
|
|
|
#include "mozilla/css/StyleRule.h"
|
1999-03-05 00:01:26 +00:00
|
|
|
#include "nsIURL.h"
|
2013-01-05 03:12:24 +00:00
|
|
|
#include "nsViewManager.h"
|
2002-02-20 03:33:52 +00:00
|
|
|
#include "nsIWidget.h"
|
1999-10-05 21:13:55 +00:00
|
|
|
#include "nsIXULDocument.h"
|
2000-05-05 23:39:59 +00:00
|
|
|
#include "nsIXULTemplateBuilder.h"
|
1999-12-17 00:06:28 +00:00
|
|
|
#include "nsLayoutCID.h"
|
2001-02-19 21:50:04 +00:00
|
|
|
#include "nsContentCID.h"
|
2014-03-05 00:37:43 +00:00
|
|
|
#include "mozilla/dom/Event.h"
|
1999-12-17 00:06:28 +00:00
|
|
|
#include "nsRDFCID.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsXPIDLString.h"
|
1999-12-05 23:04:22 +00:00
|
|
|
#include "nsXULControllers.h"
|
2000-05-30 08:11:35 +00:00
|
|
|
#include "nsIBoxObject.h"
|
|
|
|
#include "nsPIBoxObject.h"
|
2013-03-26 15:31:53 +00:00
|
|
|
#include "XULDocument.h"
|
2007-07-04 15:49:38 +00:00
|
|
|
#include "nsXULPopupListener.h"
|
2001-10-24 00:01:09 +00:00
|
|
|
#include "nsRuleWalker.h"
|
2000-06-14 08:12:32 +00:00
|
|
|
#include "nsIDOMCSSStyleDeclaration.h"
|
2010-03-02 20:59:32 +00:00
|
|
|
#include "nsCSSParser.h"
|
2014-10-14 20:15:21 +00:00
|
|
|
#include "ListBoxObject.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 16:46:42 +00:00
|
|
|
#include "nsContentUtils.h"
|
2003-01-31 23:21:22 +00:00
|
|
|
#include "nsContentList.h"
|
2014-02-27 10:51:15 +00:00
|
|
|
#include "mozilla/InternalMutationEvent.h"
|
2013-09-25 11:21:18 +00:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2000-11-27 07:55:20 +00:00
|
|
|
#include "nsIDOMMutationEvent.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2013-08-08 23:51:34 +00:00
|
|
|
#include "nsJSPrincipals.h"
|
2004-02-10 09:08:06 +00:00
|
|
|
#include "nsDOMAttributeMap.h"
|
2007-01-30 00:06:41 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2005-01-24 10:45:00 +00:00
|
|
|
#include "nsXULContentUtils.h"
|
2006-07-02 07:23:10 +00:00
|
|
|
#include "nsNodeUtils.h"
|
2008-03-21 11:18:10 +00:00
|
|
|
#include "nsFrameLoader.h"
|
2015-05-19 18:15:34 +00:00
|
|
|
#include "mozilla/Logging.h"
|
1999-03-29 19:52:54 +00:00
|
|
|
#include "rdf.h"
|
1999-10-14 10:58:25 +00:00
|
|
|
#include "nsIControllers.h"
|
2012-02-14 02:00:56 +00:00
|
|
|
#include "nsAttrValueOrString.h"
|
2012-09-30 16:40:24 +00:00
|
|
|
#include "nsAttrValueInlines.h"
|
2012-06-19 02:30:09 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-22 23:23:30 +00:00
|
|
|
#include "nsIController.h"
|
2015-04-15 16:47:03 +00:00
|
|
|
#include "nsQueryObject.h"
|
2013-01-15 12:22:03 +00:00
|
|
|
#include <algorithm>
|
2016-10-07 18:59:59 +00:00
|
|
|
#include "nsIDOMChromeWindow.h"
|
1999-06-08 23:04:24 +00:00
|
|
|
|
1999-08-21 09:08:12 +00:00
|
|
|
// The XUL doc interface
|
|
|
|
#include "nsIDOMXULDocument.h"
|
|
|
|
|
2001-10-22 20:48:52 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
#include "nsIFrame.h"
|
2004-06-25 12:26:02 +00:00
|
|
|
#include "nsNodeInfoManager.h"
|
2005-02-25 22:07:01 +00:00
|
|
|
#include "nsXBLBinding.h"
|
2014-03-18 04:48:21 +00:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2008-04-11 17:29:06 +00:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2008-06-04 20:23:37 +00:00
|
|
|
#include "nsIDOMXULCommandEvent.h"
|
2008-10-08 11:41:52 +00:00
|
|
|
#include "nsCCUncollectableMarker.h"
|
2012-10-16 11:51:00 +00:00
|
|
|
#include "nsICSSDeclaration.h"
|
2000-03-31 07:08:36 +00:00
|
|
|
|
2013-01-29 17:51:55 +00:00
|
|
|
#include "mozilla/dom/XULElementBinding.h"
|
2014-10-14 20:15:21 +00:00
|
|
|
#include "mozilla/dom/BoxObject.h"
|
2016-01-09 00:11:58 +00:00
|
|
|
#include "mozilla/dom/HTMLIFrameElement.h"
|
2013-01-29 17:51:55 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-03-26 15:31:53 +00:00
|
|
|
using namespace mozilla::dom;
|
2011-03-11 02:48:57 +00:00
|
|
|
|
1999-12-03 03:40:30 +00:00
|
|
|
#ifdef XUL_PROTOTYPE_ATTRIBUTE_METERING
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t nsXULPrototypeAttribute::gNumElements;
|
|
|
|
uint32_t nsXULPrototypeAttribute::gNumAttributes;
|
|
|
|
uint32_t nsXULPrototypeAttribute::gNumCacheTests;
|
|
|
|
uint32_t nsXULPrototypeAttribute::gNumCacheHits;
|
|
|
|
uint32_t nsXULPrototypeAttribute::gNumCacheSets;
|
|
|
|
uint32_t nsXULPrototypeAttribute::gNumCacheFills;
|
1999-12-03 03:40:30 +00:00
|
|
|
#endif
|
|
|
|
|
2016-08-02 18:05:38 +00:00
|
|
|
class nsXULElementTearoff final : public nsIFrameLoaderOwner
|
2006-09-21 03:35:50 +00:00
|
|
|
{
|
2014-06-25 02:09:15 +00:00
|
|
|
~nsXULElementTearoff() {}
|
|
|
|
|
2006-09-22 06:19:14 +00:00
|
|
|
public:
|
2008-03-21 11:18:10 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2016-08-02 18:05:38 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS(nsXULElementTearoff)
|
2006-09-21 03:35:50 +00:00
|
|
|
|
2014-09-02 00:49:25 +00:00
|
|
|
explicit nsXULElementTearoff(nsXULElement* aElement)
|
2006-09-21 03:35:50 +00:00
|
|
|
: mElement(aElement)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-12-09 17:23:19 +00:00
|
|
|
NS_FORWARD_NSIFRAMELOADEROWNER(static_cast<nsXULElement*>(mElement.get())->)
|
2006-09-21 03:35:50 +00:00
|
|
|
private:
|
2008-03-21 11:18:10 +00:00
|
|
|
nsCOMPtr<nsIDOMXULElement> mElement;
|
2006-09-21 03:35:50 +00:00
|
|
|
};
|
|
|
|
|
2014-04-25 16:49:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION(nsXULElementTearoff, mElement)
|
2008-03-21 11:18:10 +00:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXULElementTearoff)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXULElementTearoff)
|
2006-09-21 03:35:50 +00:00
|
|
|
|
2008-03-21 11:18:10 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULElementTearoff)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIFrameLoaderOwner)
|
2006-09-21 03:35:50 +00:00
|
|
|
NS_INTERFACE_MAP_END_AGGREGATED(mElement)
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
1999-10-18 22:08:15 +00:00
|
|
|
// nsXULElement
|
2001-10-22 20:48:52 +00:00
|
|
|
//
|
1999-10-07 01:51:30 +00:00
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
nsXULElement::nsXULElement(already_AddRefed<mozilla::dom::NodeInfo> aNodeInfo)
|
2010-02-24 04:37:46 +00:00
|
|
|
: nsStyledElement(aNodeInfo),
|
2012-07-30 14:20:58 +00:00
|
|
|
mBindingParent(nullptr)
|
1999-01-12 05:32:30 +00:00
|
|
|
{
|
1999-12-07 02:06:10 +00:00
|
|
|
XUL_PROTOTYPE_ATTRIBUTE_METER(gNumElements);
|
2011-06-01 01:46:57 +00:00
|
|
|
|
|
|
|
// We may be READWRITE by default; check.
|
|
|
|
if (IsReadWriteTextElement()) {
|
|
|
|
AddStatesSilently(NS_EVENT_STATE_MOZ_READWRITE);
|
|
|
|
RemoveStatesSilently(NS_EVENT_STATE_MOZ_READONLY);
|
|
|
|
}
|
1999-10-20 18:55:32 +00:00
|
|
|
}
|
1999-02-01 22:34:51 +00:00
|
|
|
|
2014-07-08 21:23:16 +00:00
|
|
|
nsXULElement::~nsXULElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-04-08 02:29:49 +00:00
|
|
|
nsXULElement::nsXULSlots::nsXULSlots()
|
|
|
|
: nsXULElement::nsDOMSlots()
|
2006-09-02 13:21:05 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXULElement::nsXULSlots::~nsXULSlots()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mControllers); // Forces release
|
2016-10-17 14:37:50 +00:00
|
|
|
nsCOMPtr<nsIFrameLoader> frameLoader = do_QueryInterface(mFrameLoaderOrOpener);
|
|
|
|
if (frameLoader) {
|
|
|
|
static_cast<nsFrameLoader*>(frameLoader.get())->Destroy();
|
2008-03-21 11:18:10 +00:00
|
|
|
}
|
2006-09-02 13:21:05 +00:00
|
|
|
}
|
|
|
|
|
2011-08-28 14:07:24 +00:00
|
|
|
void
|
|
|
|
nsXULElement::nsXULSlots::Traverse(nsCycleCollectionTraversalCallback &cb)
|
|
|
|
{
|
2016-10-17 14:37:50 +00:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mFrameLoaderOrOpener");
|
|
|
|
cb.NoteXPCOMChild(mFrameLoaderOrOpener);
|
2011-08-28 14:07:24 +00:00
|
|
|
}
|
|
|
|
|
2006-09-02 13:21:05 +00:00
|
|
|
nsINode::nsSlots*
|
|
|
|
nsXULElement::CreateSlots()
|
|
|
|
{
|
2011-04-08 02:29:49 +00:00
|
|
|
return new nsXULSlots();
|
2006-09-02 13:21:05 +00:00
|
|
|
}
|
|
|
|
|
2013-02-04 23:22:51 +00:00
|
|
|
void
|
|
|
|
nsXULElement::MaybeUpdatePrivateLifetime()
|
|
|
|
{
|
|
|
|
if (AttrValueIs(kNameSpaceID_None, nsGkAtoms::windowtype,
|
|
|
|
NS_LITERAL_STRING("navigator:browser"),
|
|
|
|
eCaseMatters)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowOuter* win = OwnerDoc()->GetWindow();
|
2013-02-04 23:22:51 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = win ? win->GetDocShell() : nullptr;
|
|
|
|
if (docShell) {
|
|
|
|
docShell->SetAffectPrivateSessionLifetime(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-11 17:15:08 +00:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<nsXULElement>
|
2014-06-20 02:01:40 +00:00
|
|
|
nsXULElement::Create(nsXULPrototypeElement* aPrototype, mozilla::dom::NodeInfo *aNodeInfo,
|
2013-02-04 23:22:51 +00:00
|
|
|
bool aIsScriptable, bool aIsRoot)
|
2005-09-11 17:15:08 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
|
|
|
|
RefPtr<nsXULElement> element = new nsXULElement(ni.forget());
|
2005-09-11 17:15:08 +00:00
|
|
|
if (element) {
|
2007-09-18 08:38:24 +00:00
|
|
|
if (aPrototype->mHasIdAttribute) {
|
2011-04-08 02:29:50 +00:00
|
|
|
element->SetHasID();
|
2007-09-18 08:38:24 +00:00
|
|
|
}
|
|
|
|
if (aPrototype->mHasClassAttribute) {
|
|
|
|
element->SetFlags(NODE_MAY_HAVE_CLASS);
|
|
|
|
}
|
|
|
|
if (aPrototype->mHasStyleAttribute) {
|
2011-04-08 02:29:50 +00:00
|
|
|
element->SetMayHaveStyle();
|
2007-09-18 08:38:24 +00:00
|
|
|
}
|
2005-09-11 17:15:08 +00:00
|
|
|
|
2012-07-14 15:28:54 +00:00
|
|
|
element->MakeHeavyweight(aPrototype);
|
2005-09-11 17:15:08 +00:00
|
|
|
if (aIsScriptable) {
|
|
|
|
// Check each attribute on the prototype to see if we need to do
|
|
|
|
// any additional processing and hookup that would otherwise be
|
|
|
|
// done 'automagically' by SetAttr().
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < aPrototype->mNumAttributes; ++i) {
|
2005-09-11 17:15:08 +00:00
|
|
|
element->AddListenerFor(aPrototype->mAttributes[i].mName,
|
2011-10-17 14:59:28 +00:00
|
|
|
true);
|
2005-09-11 17:15:08 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-04 23:22:51 +00:00
|
|
|
|
|
|
|
if (aIsRoot && aPrototype->mNodeInfo->Equals(nsGkAtoms::window)) {
|
|
|
|
for (uint32_t i = 0; i < aPrototype->mNumAttributes; ++i) {
|
|
|
|
if (aPrototype->mAttributes[i].mName.Equals(nsGkAtoms::windowtype)) {
|
|
|
|
element->MaybeUpdatePrivateLifetime();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-09-11 17:15:08 +00:00
|
|
|
}
|
|
|
|
|
2013-04-22 11:15:59 +00:00
|
|
|
return element.forget();
|
2005-09-11 17:15:08 +00:00
|
|
|
}
|
2005-09-11 15:42:31 +00:00
|
|
|
|
2005-01-14 19:30:55 +00:00
|
|
|
nsresult
|
|
|
|
nsXULElement::Create(nsXULPrototypeElement* aPrototype,
|
|
|
|
nsIDocument* aDocument,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aIsScriptable,
|
2013-02-04 23:22:51 +00:00
|
|
|
bool aIsRoot,
|
2010-04-30 13:12:05 +00:00
|
|
|
Element** aResult)
|
1999-01-12 05:32:30 +00:00
|
|
|
{
|
2005-01-14 19:30:55 +00:00
|
|
|
// Create an nsXULElement from a prototype
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_PRECONDITION(aPrototype != nullptr, "null ptr");
|
2005-01-14 19:30:55 +00:00
|
|
|
if (! aPrototype)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-02-17 22:32:40 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_PRECONDITION(aResult != nullptr, "null ptr");
|
2005-01-14 19:30:55 +00:00
|
|
|
if (! aResult)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-02-17 22:32:40 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2005-01-14 19:30:55 +00:00
|
|
|
if (aDocument) {
|
2014-06-20 02:01:40 +00:00
|
|
|
mozilla::dom::NodeInfo* ni = aPrototype->mNodeInfo;
|
2011-06-14 07:56:49 +00:00
|
|
|
nodeInfo = aDocument->NodeInfoManager()->
|
|
|
|
GetNodeInfo(ni->NameAtom(), ni->GetPrefixAtom(), ni->NamespaceID(),
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2015-08-04 20:06:14 +00:00
|
|
|
} else {
|
2005-09-11 17:15:08 +00:00
|
|
|
nodeInfo = aPrototype->mNodeInfo;
|
2005-01-14 19:30:55 +00:00
|
|
|
}
|
1999-01-12 05:32:30 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsXULElement> element = Create(aPrototype, nodeInfo,
|
2013-02-04 23:22:51 +00:00
|
|
|
aIsScriptable, aIsRoot);
|
2012-07-14 15:28:54 +00:00
|
|
|
element.forget(aResult);
|
2005-09-11 17:15:08 +00:00
|
|
|
|
2005-01-14 19:30:55 +00:00
|
|
|
return NS_OK;
|
2000-05-15 20:31:55 +00:00
|
|
|
}
|
|
|
|
|
2005-01-14 19:30:55 +00:00
|
|
|
nsresult
|
2014-06-20 02:01:40 +00:00
|
|
|
NS_NewXULElement(Element** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
2000-05-15 20:31:55 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
|
2014-03-15 19:00:15 +00:00
|
|
|
|
|
|
|
NS_PRECONDITION(ni, "need nodeinfo for non-proto Create");
|
2000-05-15 20:31:55 +00:00
|
|
|
|
2014-03-15 19:00:15 +00:00
|
|
|
nsIDocument* doc = ni->GetDocument();
|
2010-08-19 23:12:46 +00:00
|
|
|
if (doc && !doc->AllowXULXBL()) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2000-05-15 20:31:55 +00:00
|
|
|
|
2014-03-15 19:00:15 +00:00
|
|
|
NS_ADDREF(*aResult = new nsXULElement(ni.forget()));
|
2000-05-15 20:31:55 +00:00
|
|
|
|
2010-08-20 01:41:58 +00:00
|
|
|
return NS_OK;
|
2010-08-19 23:12:46 +00:00
|
|
|
}
|
|
|
|
|
2010-08-19 23:12:46 +00:00
|
|
|
void
|
2014-03-15 19:00:17 +00:00
|
|
|
NS_TrustedNewXULElement(nsIContent** aResult,
|
2014-06-20 02:01:40 +00:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
2010-08-19 23:12:46 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
|
2014-03-15 19:00:15 +00:00
|
|
|
NS_PRECONDITION(ni, "need nodeinfo for non-proto Create");
|
2010-08-19 23:12:46 +00:00
|
|
|
|
|
|
|
// Create an nsXULElement with the specified namespace and tag.
|
2014-03-15 19:00:15 +00:00
|
|
|
NS_ADDREF(*aResult = new nsXULElement(ni.forget()));
|
2010-08-19 23:12:46 +00:00
|
|
|
}
|
|
|
|
|
2005-01-14 19:30:55 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports interface
|
2004-02-10 09:08:06 +00:00
|
|
|
|
2013-08-02 01:29:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULElement)
|
|
|
|
|
2007-05-24 14:10:02 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXULElement,
|
2010-02-24 04:37:46 +00:00
|
|
|
nsStyledElement)
|
2011-02-16 12:07:47 +00:00
|
|
|
{
|
|
|
|
nsXULSlots* slots = static_cast<nsXULSlots*>(tmp->GetExistingSlots());
|
|
|
|
if (slots) {
|
2011-08-28 14:07:24 +00:00
|
|
|
slots->Traverse(cb);
|
2011-02-16 12:07:47 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-24 14:10:02 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2014-05-30 07:36:53 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsXULElement,
|
|
|
|
nsStyledElement)
|
|
|
|
// Why aren't we unlinking the prototype?
|
|
|
|
tmp->ClearHasID();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2010-02-24 04:37:46 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsXULElement, nsStyledElement)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsXULElement, nsStyledElement)
|
2004-02-10 09:08:06 +00:00
|
|
|
|
2008-11-03 10:31:47 +00:00
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsXULElement)
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(nsXULElement, nsIDOMNode, nsIDOMElement,
|
|
|
|
nsIDOMXULElement)
|
2008-11-03 10:31:47 +00:00
|
|
|
NS_ELEMENT_INTERFACE_TABLE_TO_MAP_SEGUE
|
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIFrameLoaderOwner,
|
|
|
|
new nsXULElementTearoff(this))
|
2013-08-07 20:23:08 +00:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsStyledElement)
|
2000-05-15 20:31:55 +00:00
|
|
|
|
2005-01-14 19:30:55 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMNode interface
|
|
|
|
|
2005-09-11 17:15:08 +00:00
|
|
|
nsresult
|
2014-06-20 02:01:40 +00:00
|
|
|
nsXULElement::Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const
|
2000-05-15 20:31:55 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aResult = nullptr;
|
2000-05-15 20:31:55 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
|
|
|
|
RefPtr<nsXULElement> element = new nsXULElement(ni.forget());
|
2003-01-31 14:28:50 +00:00
|
|
|
|
2005-01-14 19:30:55 +00:00
|
|
|
// XXX TODO: set up RDF generic builder n' stuff if there is a
|
|
|
|
// 'datasources' attribute? This is really kind of tricky,
|
|
|
|
// because then we'd need to -selectively- copy children that
|
|
|
|
// -weren't- generated from RDF. Ugh. Forget it.
|
2000-05-15 20:31:55 +00:00
|
|
|
|
2005-01-14 19:30:55 +00:00
|
|
|
// Note that we're _not_ copying mControllers.
|
2000-05-15 20:31:55 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = mAttrsAndChildren.AttrCount();
|
2012-07-19 09:21:40 +00:00
|
|
|
nsresult rv = NS_OK;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2012-07-19 09:21:40 +00:00
|
|
|
const nsAttrName* originalName = mAttrsAndChildren.AttrNameAt(i);
|
|
|
|
const nsAttrValue* originalValue = mAttrsAndChildren.AttrAt(i);
|
|
|
|
nsAttrValue attrValue;
|
|
|
|
|
|
|
|
// Style rules need to be cloned.
|
2016-10-18 04:29:03 +00:00
|
|
|
if (originalValue->Type() == nsAttrValue::eCSSDeclaration) {
|
|
|
|
DeclarationBlock* decl = originalValue->GetCSSDeclarationValue();
|
|
|
|
RefPtr<css::Declaration>
|
|
|
|
declClone = new css::Declaration(*decl->AsGecko());
|
2012-07-19 09:21:40 +00:00
|
|
|
|
|
|
|
nsString stringValue;
|
|
|
|
originalValue->ToString(stringValue);
|
|
|
|
|
2016-10-18 04:29:03 +00:00
|
|
|
attrValue.SetTo(declClone.forget(), &stringValue);
|
2012-07-19 09:21:40 +00:00
|
|
|
} else {
|
|
|
|
attrValue.SetTo(*originalValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (originalName->IsAtom()) {
|
2015-07-22 02:09:41 +00:00
|
|
|
rv = element->mAttrsAndChildren.SetAndSwapAttr(originalName->Atom(),
|
2012-07-19 09:21:40 +00:00
|
|
|
attrValue);
|
|
|
|
} else {
|
2015-07-22 02:09:41 +00:00
|
|
|
rv = element->mAttrsAndChildren.SetAndSwapAttr(originalName->NodeInfo(),
|
2012-07-19 09:21:40 +00:00
|
|
|
attrValue);
|
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
element->AddListenerFor(*originalName, true);
|
2012-07-20 21:55:19 +00:00
|
|
|
if (originalName->Equals(nsGkAtoms::id) &&
|
|
|
|
!originalValue->IsEmptyString()) {
|
2012-07-19 09:21:40 +00:00
|
|
|
element->SetHasID();
|
|
|
|
}
|
|
|
|
if (originalName->Equals(nsGkAtoms::_class)) {
|
|
|
|
element->SetFlags(NODE_MAY_HAVE_CLASS);
|
|
|
|
}
|
|
|
|
if (originalName->Equals(nsGkAtoms::style)) {
|
|
|
|
element->SetMayHaveStyle();
|
|
|
|
}
|
2000-05-15 20:31:55 +00:00
|
|
|
}
|
|
|
|
|
2012-07-19 09:21:40 +00:00
|
|
|
element.forget(aResult);
|
2005-09-11 17:15:08 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2005-01-14 19:30:55 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1999-02-23 02:40:51 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULElement::GetElementsByAttribute(const nsAString& aAttribute,
|
|
|
|
const nsAString& aValue,
|
2000-08-23 17:27:06 +00:00
|
|
|
nsIDOMNodeList** aReturn)
|
2013-01-29 17:51:55 +00:00
|
|
|
{
|
2014-03-15 19:00:15 +00:00
|
|
|
*aReturn = GetElementsByAttribute(aAttribute, aValue).take();
|
2013-01-29 17:51:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsINodeList>
|
|
|
|
nsXULElement::GetElementsByAttribute(const nsAString& aAttribute,
|
|
|
|
const nsAString& aValue)
|
1999-02-23 02:40:51 +00:00
|
|
|
{
|
2016-03-28 23:09:43 +00:00
|
|
|
nsCOMPtr<nsIAtom> attrAtom(NS_Atomize(aAttribute));
|
2007-02-01 15:14:00 +00:00
|
|
|
void* attrValue = new nsString(aValue);
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsContentList> list =
|
2006-07-02 07:23:10 +00:00
|
|
|
new nsContentList(this,
|
2013-03-26 15:31:53 +00:00
|
|
|
XULDocument::MatchAttribute,
|
2007-02-01 15:14:00 +00:00
|
|
|
nsContentUtils::DestroyMatchString,
|
|
|
|
attrValue,
|
2011-10-17 14:59:28 +00:00
|
|
|
true,
|
2004-04-15 01:51:32 +00:00
|
|
|
attrAtom,
|
2006-06-22 02:37:06 +00:00
|
|
|
kNameSpaceID_Unknown);
|
2013-01-29 17:51:55 +00:00
|
|
|
return list.forget();
|
1999-02-23 02:40:51 +00:00
|
|
|
}
|
|
|
|
|
2006-09-14 04:29:02 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::GetElementsByAttributeNS(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsIDOMNodeList** aReturn)
|
2013-01-29 17:51:55 +00:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
*aReturn =
|
2014-03-15 19:00:15 +00:00
|
|
|
GetElementsByAttributeNS(aNamespaceURI, aAttribute, aValue, rv).take();
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2013-01-29 17:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsINodeList>
|
|
|
|
nsXULElement::GetElementsByAttributeNS(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
ErrorResult& rv)
|
2006-09-14 04:29:02 +00:00
|
|
|
{
|
2016-03-28 23:09:43 +00:00
|
|
|
nsCOMPtr<nsIAtom> attrAtom(NS_Atomize(aAttribute));
|
2006-09-14 04:29:02 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t nameSpaceId = kNameSpaceID_Wildcard;
|
2006-09-14 04:29:02 +00:00
|
|
|
if (!aNamespaceURI.EqualsLiteral("*")) {
|
2013-01-29 17:51:55 +00:00
|
|
|
rv =
|
2006-09-14 04:29:02 +00:00
|
|
|
nsContentUtils::NameSpaceManager()->RegisterNameSpace(aNamespaceURI,
|
|
|
|
nameSpaceId);
|
2013-01-29 17:51:55 +00:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2006-09-14 04:29:02 +00:00
|
|
|
}
|
|
|
|
|
2007-02-01 15:14:00 +00:00
|
|
|
void* attrValue = new nsString(aValue);
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsContentList> list =
|
2006-09-14 04:29:02 +00:00
|
|
|
new nsContentList(this,
|
2013-03-26 15:31:53 +00:00
|
|
|
XULDocument::MatchAttribute,
|
2007-02-01 15:14:00 +00:00
|
|
|
nsContentUtils::DestroyMatchString,
|
|
|
|
attrValue,
|
2011-10-17 14:59:28 +00:00
|
|
|
true,
|
2006-09-14 04:29:02 +00:00
|
|
|
attrAtom,
|
|
|
|
nameSpaceId);
|
|
|
|
|
2013-01-29 17:51:55 +00:00
|
|
|
return list.forget();
|
2006-09-14 04:29:02 +00:00
|
|
|
}
|
|
|
|
|
2014-03-17 06:56:53 +00:00
|
|
|
EventListenerManager*
|
2011-09-29 06:19:26 +00:00
|
|
|
nsXULElement::GetEventListenerManagerForAttr(nsIAtom* aAttrName, bool* aDefer)
|
1999-10-29 01:21:15 +00:00
|
|
|
{
|
2014-10-03 12:29:48 +00:00
|
|
|
// XXXbz sXBL/XBL2 issue: should we instead use GetComposedDoc()
|
2005-10-28 02:59:38 +00:00
|
|
|
// here, override BindToTree for those classes and munge event
|
|
|
|
// listeners there?
|
2011-10-18 10:53:36 +00:00
|
|
|
nsIDocument* doc = OwnerDoc();
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowInner *window;
|
2010-04-30 13:12:05 +00:00
|
|
|
Element *root = doc->GetRootElement();
|
2008-05-08 04:57:21 +00:00
|
|
|
if ((!root || root == this) && !mNodeInfo->Equals(nsGkAtoms::overlay) &&
|
2013-04-29 15:34:16 +00:00
|
|
|
(window = doc->GetInnerWindow())) {
|
2005-11-29 02:06:23 +00:00
|
|
|
|
2013-04-06 00:44:15 +00:00
|
|
|
nsCOMPtr<EventTarget> piTarget = do_QueryInterface(window);
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
*aDefer = false;
|
2013-10-22 23:32:04 +00:00
|
|
|
return piTarget->GetOrCreateListenerManager();
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
|
2011-09-28 15:54:50 +00:00
|
|
|
return nsStyledElement::GetEventListenerManagerForAttr(aAttrName, aDefer);
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
|
2010-04-21 14:53:42 +00:00
|
|
|
// returns true if the element is not a list
|
2014-06-20 02:01:40 +00:00
|
|
|
static bool IsNonList(mozilla::dom::NodeInfo* aNodeInfo)
|
2010-04-21 14:53:42 +00:00
|
|
|
{
|
|
|
|
return !aNodeInfo->Equals(nsGkAtoms::tree) &&
|
|
|
|
!aNodeInfo->Equals(nsGkAtoms::listbox) &&
|
|
|
|
!aNodeInfo->Equals(nsGkAtoms::richlistbox);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2013-11-19 22:21:16 +00:00
|
|
|
nsXULElement::IsFocusableInternal(int32_t *aTabIndex, bool aWithMouse)
|
2004-07-24 21:12:43 +00:00
|
|
|
{
|
2015-08-04 20:06:14 +00:00
|
|
|
/*
|
2008-03-07 16:33:38 +00:00
|
|
|
* Returns true if an element may be focused, and false otherwise. The inout
|
|
|
|
* argument aTabIndex will be set to the tab order index to be used; -1 for
|
|
|
|
* elements that should not be part of the tab order and a greater value to
|
|
|
|
* indicate its tab order.
|
|
|
|
*
|
|
|
|
* Confusingly, the supplied value for the aTabIndex argument may indicate
|
|
|
|
* whether the element may be focused as a result of the -moz-user-focus
|
2008-03-27 16:19:05 +00:00
|
|
|
* property, where -1 means no and 0 means yes.
|
2008-03-07 16:33:38 +00:00
|
|
|
*
|
|
|
|
* For controls, the element cannot be focused and is not part of the tab
|
|
|
|
* order if it is disabled.
|
|
|
|
*
|
|
|
|
* Controls (those that implement nsIDOMXULControlElement):
|
|
|
|
* *aTabIndex = -1 no tabindex Not focusable or tabbable
|
|
|
|
* *aTabIndex = -1 tabindex="-1" Not focusable or tabbable
|
|
|
|
* *aTabIndex = -1 tabindex=">=0" Focusable and tabbable
|
|
|
|
* *aTabIndex >= 0 no tabindex Focusable and tabbable
|
|
|
|
* *aTabIndex >= 0 tabindex="-1" Focusable but not tabbable
|
|
|
|
* *aTabIndex >= 0 tabindex=">=0" Focusable and tabbable
|
|
|
|
* Non-controls:
|
|
|
|
* *aTabIndex = -1 Not focusable or tabbable
|
|
|
|
* *aTabIndex >= 0 Focusable and tabbable
|
|
|
|
*
|
|
|
|
* If aTabIndex is null, then the tabindex is not computed, and
|
|
|
|
* true is returned for non-disabled controls and false otherwise.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// elements are not focusable by default
|
2011-09-29 06:19:26 +00:00
|
|
|
bool shouldFocus = false;
|
2008-03-07 16:33:38 +00:00
|
|
|
|
2010-04-21 14:53:42 +00:00
|
|
|
#ifdef XP_MACOSX
|
2013-08-23 19:17:13 +00:00
|
|
|
// on Mac, mouse interactions only focus the element if it's a list,
|
|
|
|
// or if it's a remote target, since the remote target must handle
|
|
|
|
// the focus.
|
|
|
|
if (aWithMouse &&
|
2015-08-04 20:06:14 +00:00
|
|
|
IsNonList(mNodeInfo) &&
|
2014-04-01 04:09:23 +00:00
|
|
|
!EventStateManager::IsRemoteTarget(this))
|
2013-08-23 19:17:13 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2013-08-23 19:17:13 +00:00
|
|
|
}
|
2010-04-21 14:53:42 +00:00
|
|
|
#endif
|
|
|
|
|
2011-08-30 21:45:31 +00:00
|
|
|
nsCOMPtr<nsIDOMXULControlElement> xulControl = do_QueryObject(this);
|
2004-07-24 21:12:43 +00:00
|
|
|
if (xulControl) {
|
2008-03-07 16:33:38 +00:00
|
|
|
// a disabled element cannot be focused and is not part of the tab order
|
2011-09-29 06:19:26 +00:00
|
|
|
bool disabled;
|
2004-07-24 21:12:43 +00:00
|
|
|
xulControl->GetDisabled(&disabled);
|
|
|
|
if (disabled) {
|
2008-03-07 16:33:38 +00:00
|
|
|
if (aTabIndex)
|
|
|
|
*aTabIndex = -1;
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2004-07-24 21:12:43 +00:00
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
shouldFocus = true;
|
2008-03-07 16:33:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aTabIndex) {
|
2008-03-27 16:19:05 +00:00
|
|
|
if (xulControl) {
|
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::tabindex)) {
|
|
|
|
// if either the aTabIndex argument or a specified tabindex is non-negative,
|
|
|
|
// the element becomes focusable.
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t tabIndex = 0;
|
2008-03-27 16:19:05 +00:00
|
|
|
xulControl->GetTabIndex(&tabIndex);
|
|
|
|
shouldFocus = *aTabIndex >= 0 || tabIndex >= 0;
|
|
|
|
*aTabIndex = tabIndex;
|
2015-08-04 20:06:14 +00:00
|
|
|
} else {
|
2008-03-27 16:19:05 +00:00
|
|
|
// otherwise, if there is no tabindex attribute, just use the value of
|
2009-11-20 12:09:33 +00:00
|
|
|
// *aTabIndex to indicate focusability. Reset any supplied tabindex to 0.
|
2008-03-27 16:19:05 +00:00
|
|
|
shouldFocus = *aTabIndex >= 0;
|
2009-11-20 12:09:33 +00:00
|
|
|
if (shouldFocus)
|
|
|
|
*aTabIndex = 0;
|
2008-03-27 16:19:05 +00:00
|
|
|
}
|
2008-03-13 14:07:23 +00:00
|
|
|
|
|
|
|
if (shouldFocus && sTabFocusModelAppliesToXUL &&
|
|
|
|
!(sTabFocusModel & eTabFocus_formElementsMask)) {
|
|
|
|
// By default, the tab focus model doesn't apply to xul element on any system but OS X.
|
|
|
|
// on OS X we're following it for UI elements (XUL) as sTabFocusModel is based on
|
|
|
|
// "Full Keyboard Access" system setting (see mac/nsILookAndFeel).
|
|
|
|
// both textboxes and list elements (i.e. trees and list) should always be focusable
|
|
|
|
// (textboxes are handled as html:input)
|
|
|
|
// For compatibility, we only do this for controls, otherwise elements like <browser>
|
|
|
|
// cannot take this focus.
|
2010-04-21 14:53:42 +00:00
|
|
|
if (IsNonList(mNodeInfo))
|
2008-03-13 14:07:23 +00:00
|
|
|
*aTabIndex = -1;
|
|
|
|
}
|
2015-08-04 20:06:14 +00:00
|
|
|
} else {
|
2008-03-07 16:33:38 +00:00
|
|
|
shouldFocus = *aTabIndex >= 0;
|
2004-07-24 21:12:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-07 16:33:38 +00:00
|
|
|
return shouldFocus;
|
2004-07-24 21:12:43 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 12:18:42 +00:00
|
|
|
bool
|
2011-09-29 06:19:26 +00:00
|
|
|
nsXULElement::PerformAccesskey(bool aKeyCausesActivation,
|
|
|
|
bool aIsTrustedEvent)
|
2007-02-13 15:02:57 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content(this);
|
|
|
|
|
2015-03-03 11:09:00 +00:00
|
|
|
if (IsXULElement(nsGkAtoms::label)) {
|
2007-02-13 15:02:57 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
|
|
|
|
nsAutoString control;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::control, control);
|
|
|
|
if (!control.IsEmpty()) {
|
2014-10-03 12:29:48 +00:00
|
|
|
//XXXsmaug Should we use ShadowRoot::GetElementById in case
|
|
|
|
// content is in Shadow DOM?
|
2007-02-13 15:02:57 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDocument =
|
2014-10-03 12:29:48 +00:00
|
|
|
do_QueryInterface(content->GetUncomposedDoc());
|
2007-02-13 15:02:57 +00:00
|
|
|
if (domDocument)
|
|
|
|
domDocument->GetElementById(control, getter_AddRefs(element));
|
|
|
|
}
|
|
|
|
// here we'll either change |content| to the element referenced by
|
|
|
|
// |element|, or clear it.
|
|
|
|
content = do_QueryInterface(element);
|
|
|
|
|
2015-09-18 12:18:42 +00:00
|
|
|
if (!content) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-02-13 15:02:57 +00:00
|
|
|
}
|
|
|
|
|
2009-12-24 21:20:05 +00:00
|
|
|
nsIFrame* frame = content->GetPrimaryFrame();
|
2015-09-18 12:18:42 +00:00
|
|
|
if (!frame || !frame->IsVisibleConsideringAncestors()) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-02-13 15:02:57 +00:00
|
|
|
|
2015-09-18 12:18:42 +00:00
|
|
|
bool focused = false;
|
2010-08-27 21:26:24 +00:00
|
|
|
nsXULElement* elm = FromContent(content);
|
2007-11-11 22:44:48 +00:00
|
|
|
if (elm) {
|
|
|
|
// Define behavior for each type of XUL element.
|
2015-03-03 11:09:00 +00:00
|
|
|
if (!content->IsXULElement(nsGkAtoms::toolbarbutton)) {
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 18:00:39 +00:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
2009-06-15 15:08:41 +00:00
|
|
|
if (fm) {
|
2015-09-18 12:18:42 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> elementToFocus;
|
2009-06-15 15:08:41 +00:00
|
|
|
// for radio buttons, focus the radiogroup instead
|
2015-03-03 11:09:00 +00:00
|
|
|
if (content->IsXULElement(nsGkAtoms::radio)) {
|
2010-08-27 21:26:24 +00:00
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> controlItem(do_QueryInterface(content));
|
2009-06-15 15:08:41 +00:00
|
|
|
if (controlItem) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool disabled;
|
2009-06-15 15:08:41 +00:00
|
|
|
controlItem->GetDisabled(&disabled);
|
|
|
|
if (!disabled) {
|
|
|
|
nsCOMPtr<nsIDOMXULSelectControlElement> selectControl;
|
|
|
|
controlItem->GetControl(getter_AddRefs(selectControl));
|
2015-09-18 12:18:42 +00:00
|
|
|
elementToFocus = do_QueryInterface(selectControl);
|
2009-06-15 15:08:41 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-04 20:06:14 +00:00
|
|
|
} else {
|
2015-09-18 12:18:42 +00:00
|
|
|
elementToFocus = do_QueryInterface(content);
|
|
|
|
}
|
|
|
|
if (elementToFocus) {
|
|
|
|
fm->SetFocus(elementToFocus, nsIFocusManager::FLAG_BYKEY);
|
|
|
|
|
|
|
|
// Return true if the element became focused.
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowOuter* window = OwnerDoc()->GetWindow();
|
2015-09-18 12:18:42 +00:00
|
|
|
focused = (window && window->GetFocusedNode());
|
2009-06-15 15:08:41 +00:00
|
|
|
}
|
|
|
|
}
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 18:00:39 +00:00
|
|
|
}
|
2015-03-03 11:09:00 +00:00
|
|
|
if (aKeyCausesActivation &&
|
|
|
|
!content->IsAnyOfXULElements(nsGkAtoms::textbox, nsGkAtoms::menulist)) {
|
2015-10-13 17:56:24 +00:00
|
|
|
elm->ClickWithInputSource(nsIDOMMouseEvent::MOZ_SOURCE_KEYBOARD, aIsTrustedEvent);
|
2010-04-06 12:59:24 +00:00
|
|
|
}
|
2015-08-04 20:06:14 +00:00
|
|
|
} else {
|
2015-09-18 12:18:42 +00:00
|
|
|
return content->PerformAccesskey(aKeyCausesActivation, aIsTrustedEvent);
|
2007-02-13 15:02:57 +00:00
|
|
|
}
|
2015-09-18 12:18:42 +00:00
|
|
|
|
|
|
|
return focused;
|
2007-02-13 15:02:57 +00:00
|
|
|
}
|
|
|
|
|
1999-12-03 03:40:30 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2004-02-10 09:08:06 +00:00
|
|
|
void
|
|
|
|
nsXULElement::AddListenerFor(const nsAttrName& aName,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aCompileEventHandlers)
|
1999-01-12 05:32:30 +00:00
|
|
|
{
|
2001-10-22 20:48:52 +00:00
|
|
|
// If appropriate, add a popup listener and/or compile the event
|
|
|
|
// handler. Called when we change the element's document, create a
|
|
|
|
// new element, change an attribute's value, etc.
|
2004-02-10 09:08:06 +00:00
|
|
|
// Eventlistenener-attributes are always in the null namespace
|
|
|
|
if (aName.IsAtom()) {
|
|
|
|
nsIAtom *attr = aName.Atom();
|
|
|
|
MaybeAddPopupListener(attr);
|
2007-04-02 17:17:36 +00:00
|
|
|
if (aCompileEventHandlers &&
|
|
|
|
nsContentUtils::IsEventAttributeName(attr, EventNameType_XUL)) {
|
2003-09-20 06:09:10 +00:00
|
|
|
nsAutoString value;
|
2004-02-10 09:08:06 +00:00
|
|
|
GetAttr(kNameSpaceID_None, attr, value);
|
2012-08-30 16:25:10 +00:00
|
|
|
SetEventHandler(attr, value, true);
|
1999-01-12 05:32:30 +00:00
|
|
|
}
|
2001-10-22 20:48:52 +00:00
|
|
|
}
|
2004-02-10 09:08:06 +00:00
|
|
|
}
|
2001-10-22 20:48:52 +00:00
|
|
|
|
2004-02-10 09:08:06 +00:00
|
|
|
void
|
|
|
|
nsXULElement::MaybeAddPopupListener(nsIAtom* aLocalName)
|
|
|
|
{
|
|
|
|
// If appropriate, add a popup listener. Called when we change the
|
|
|
|
// element's document, create a new element, change an attribute's
|
|
|
|
// value, etc.
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aLocalName == nsGkAtoms::menu ||
|
|
|
|
aLocalName == nsGkAtoms::contextmenu ||
|
2004-02-10 09:08:06 +00:00
|
|
|
// XXXdwh popup and context are deprecated
|
2006-12-26 17:47:52 +00:00
|
|
|
aLocalName == nsGkAtoms::popup ||
|
|
|
|
aLocalName == nsGkAtoms::context) {
|
2004-02-10 09:08:06 +00:00
|
|
|
AddPopupListener(aLocalName);
|
|
|
|
}
|
2001-10-22 20:48:52 +00:00
|
|
|
}
|
1999-02-24 00:01:26 +00:00
|
|
|
|
2004-02-10 09:08:06 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsIContent interface
|
|
|
|
//
|
2011-06-01 01:46:57 +00:00
|
|
|
void
|
2011-09-29 06:19:26 +00:00
|
|
|
nsXULElement::UpdateEditableState(bool aNotify)
|
2011-06-01 01:46:57 +00:00
|
|
|
{
|
2012-11-14 22:10:08 +00:00
|
|
|
// Don't call through to Element here because the things
|
2011-06-01 01:46:57 +00:00
|
|
|
// it does don't work for cases when we're an editable control.
|
|
|
|
nsIContent *parent = GetParent();
|
|
|
|
|
|
|
|
SetEditableFlag(parent && parent->HasFlag(NODE_IS_EDITABLE));
|
|
|
|
UpdateState(aNotify);
|
|
|
|
}
|
2004-02-10 09:08:06 +00:00
|
|
|
|
2014-05-24 18:51:06 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the user-agent style sheet rules for this XUL element are
|
|
|
|
* in minimal-xul.css instead of xul.css.
|
|
|
|
*/
|
|
|
|
static inline bool XULElementsRulesInMinimalXULSheet(nsIAtom* aTag)
|
|
|
|
{
|
|
|
|
return // scrollbar parts:
|
|
|
|
aTag == nsGkAtoms::scrollbar ||
|
|
|
|
aTag == nsGkAtoms::scrollbarbutton ||
|
|
|
|
aTag == nsGkAtoms::scrollcorner ||
|
|
|
|
aTag == nsGkAtoms::slider ||
|
|
|
|
aTag == nsGkAtoms::thumb ||
|
|
|
|
aTag == nsGkAtoms::scale ||
|
|
|
|
// other
|
|
|
|
aTag == nsGkAtoms::resizer ||
|
|
|
|
aTag == nsGkAtoms::label ||
|
|
|
|
aTag == nsGkAtoms::videocontrols;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
/**
|
|
|
|
* Returns true if aElement is a XUL element created by the video controls
|
|
|
|
* binding. HTML <video> and <audio> bindings pull in this binding. This
|
|
|
|
* binding creates lots of different types of XUL elements.
|
|
|
|
*/
|
|
|
|
static inline bool
|
|
|
|
IsInVideoControls(nsXULElement* aElement)
|
|
|
|
{
|
|
|
|
nsIContent* ancestor = aElement->GetParent();
|
|
|
|
while (ancestor) {
|
|
|
|
if (ancestor->NodeInfo()->Equals(nsGkAtoms::videocontrols, kNameSpaceID_XUL)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
ancestor = ancestor->GetParent();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if aElement is an element created by the <binding
|
|
|
|
* id="feedreaderUI"> binding or one of the bindings bound to such an element.
|
|
|
|
* element in one of the binding for such an element. Only
|
|
|
|
* subscribe.xhtml#feedSubscribeLine pulls in the feedreaderUI binding. This
|
|
|
|
* binding creates lots of different types of XUL elements.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
IsInFeedSubscribeLine(nsXULElement* aElement)
|
|
|
|
{
|
|
|
|
nsIContent* bindingParent = aElement->GetBindingParent();
|
|
|
|
if (bindingParent) {
|
|
|
|
while (bindingParent->GetBindingParent()) {
|
|
|
|
bindingParent = bindingParent->GetBindingParent();
|
|
|
|
}
|
|
|
|
nsIAtom* idAtom = bindingParent->GetID();
|
|
|
|
if (idAtom && idAtom->Equals(NS_LITERAL_STRING("feedSubscribeLine"))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-04-26 00:23:21 +00:00
|
|
|
class XULInContentErrorReporter : public Runnable
|
2014-07-18 15:59:00 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-09-02 00:49:25 +00:00
|
|
|
explicit XULInContentErrorReporter(nsIDocument* aDocument) : mDocument(aDocument) {}
|
2014-07-18 15:59:00 +00:00
|
|
|
|
2016-08-08 02:18:10 +00:00
|
|
|
NS_IMETHOD Run() override
|
2014-07-18 15:59:00 +00:00
|
|
|
{
|
|
|
|
mDocument->WarnOnceAbout(nsIDocument::eImportXULIntoContent, false);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIDocument> mDocument;
|
|
|
|
};
|
|
|
|
|
2008-03-21 11:18:10 +00:00
|
|
|
nsresult
|
|
|
|
nsXULElement::BindToTree(nsIDocument* aDocument,
|
|
|
|
nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aCompileEventHandlers)
|
2008-03-21 11:18:10 +00:00
|
|
|
{
|
2014-07-18 15:59:00 +00:00
|
|
|
if (!aBindingParent &&
|
|
|
|
aDocument &&
|
2014-08-29 19:33:16 +00:00
|
|
|
!aDocument->IsLoadedAsInteractiveData() &&
|
2014-07-18 15:59:00 +00:00
|
|
|
!aDocument->AllowXULXBL() &&
|
|
|
|
!aDocument->HasWarnedAbout(nsIDocument::eImportXULIntoContent)) {
|
|
|
|
nsContentUtils::AddScriptRunner(new XULInContentErrorReporter(aDocument));
|
|
|
|
}
|
|
|
|
|
2010-06-04 01:09:20 +00:00
|
|
|
nsresult rv = nsStyledElement::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
2008-03-21 11:18:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-09-18 10:54:00 +00:00
|
|
|
nsIDocument* doc = GetComposedDoc();
|
|
|
|
if (doc &&
|
|
|
|
!doc->LoadsFullXULStyleSheetUpFront() &&
|
|
|
|
!doc->IsUnstyledDocument()) {
|
2014-05-24 18:51:06 +00:00
|
|
|
|
|
|
|
// To save CPU cycles and memory, non-XUL documents only load the user
|
|
|
|
// agent style sheet rules for a minimal set of XUL elements such as
|
|
|
|
// 'scrollbar' that may be created implicitly for their content (those
|
|
|
|
// rules being in minimal-xul.css). This is where we make sure that all
|
|
|
|
// the other XUL UA style sheet rules (xul.css) have been loaded if the
|
|
|
|
// minimal set is not sufficient.
|
|
|
|
//
|
|
|
|
// We do this during binding, not element construction, because elements
|
|
|
|
// can be moved from the document that creates them to another document.
|
|
|
|
|
2015-03-03 11:09:00 +00:00
|
|
|
if (!XULElementsRulesInMinimalXULSheet(NodeInfo()->NameAtom())) {
|
2016-02-24 07:01:12 +00:00
|
|
|
auto cache = nsLayoutStylesheetCache::For(doc->GetStyleBackendType());
|
|
|
|
doc->EnsureOnDemandBuiltInUASheet(cache->XULSheet());
|
2014-05-24 18:51:06 +00:00
|
|
|
// To keep memory usage down it is important that we try and avoid
|
|
|
|
// pulling xul.css into non-XUL documents. That should be very rare, and
|
|
|
|
// for HTML we currently should only pull it in if the document contains
|
|
|
|
// an <audio> or <video> element. This assertion is here to make sure
|
|
|
|
// that we don't fail to notice if a change to bindings causes us to
|
|
|
|
// start pulling in xul.css much more frequently. If this assertion
|
|
|
|
// fails then we need to figure out why, and how we can continue to avoid
|
|
|
|
// pulling in xul.css.
|
|
|
|
// Note that add-ons may introduce bindings that cause this assertion to
|
|
|
|
// fire.
|
|
|
|
NS_ASSERTION(IsInVideoControls(this) ||
|
2016-10-06 04:17:00 +00:00
|
|
|
IsInFeedSubscribeLine(this) ||
|
|
|
|
IsXULElement(nsGkAtoms::datetimebox),
|
2014-05-24 18:51:06 +00:00
|
|
|
"Unexpected XUL element in non-XUL doc");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-21 11:18:10 +00:00
|
|
|
if (aDocument) {
|
2009-01-02 15:41:43 +00:00
|
|
|
NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
|
|
|
|
"Missing a script blocker!");
|
2008-03-21 11:18:10 +00:00
|
|
|
// We're in a document now. Kick off the frame load.
|
|
|
|
LoadSrc();
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-05-21 22:22:51 +00:00
|
|
|
void
|
2011-09-29 06:19:26 +00:00
|
|
|
nsXULElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2007-05-21 22:22:51 +00:00
|
|
|
{
|
|
|
|
// mControllers can own objects that are implemented
|
|
|
|
// in JavaScript (such as some implementations of
|
|
|
|
// nsIControllers. These objects prevent their global
|
|
|
|
// object's script object from being garbage collected,
|
|
|
|
// which means JS continues to hold an owning reference
|
|
|
|
// to the nsGlobalWindow, which owns the document,
|
|
|
|
// which owns this content. That's a cycle, so we break
|
|
|
|
// it here. (It might be better to break this by releasing
|
|
|
|
// mDocument in nsGlobalWindow::SetDocShell, but I'm not
|
|
|
|
// sure whether that would fix all possible cycles through
|
|
|
|
// mControllers.)
|
2008-03-21 11:18:10 +00:00
|
|
|
nsXULSlots* slots = static_cast<nsXULSlots*>(GetExistingDOMSlots());
|
2007-05-21 22:22:51 +00:00
|
|
|
if (slots) {
|
|
|
|
NS_IF_RELEASE(slots->mControllers);
|
2016-10-17 14:37:50 +00:00
|
|
|
RefPtr<nsFrameLoader> frameLoader = GetFrameLoader();
|
|
|
|
if (frameLoader) {
|
|
|
|
frameLoader->Destroy();
|
2008-03-21 11:18:10 +00:00
|
|
|
}
|
2016-10-17 14:37:50 +00:00
|
|
|
slots->mFrameLoaderOrOpener = nullptr;
|
2007-05-21 22:22:51 +00:00
|
|
|
}
|
|
|
|
|
2010-02-24 04:37:46 +00:00
|
|
|
nsStyledElement::UnbindFromTree(aDeep, aNullParent);
|
2007-05-21 22:22:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-29 21:09:07 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsXULElement::RemoveChildAt(uint32_t aIndex, bool aNotify)
|
1999-01-12 05:32:30 +00:00
|
|
|
{
|
2006-03-27 22:00:40 +00:00
|
|
|
nsCOMPtr<nsIContent> oldKid = mAttrsAndChildren.GetSafeChildAt(aIndex);
|
|
|
|
if (!oldKid) {
|
2012-03-29 21:09:07 +00:00
|
|
|
return;
|
2000-11-27 07:55:20 +00:00
|
|
|
}
|
|
|
|
|
1999-08-23 01:13:29 +00:00
|
|
|
// On the removal of a <treeitem>, <treechildren>, or <treecell> element,
|
|
|
|
// the possibility exists that some of the items in the removed subtree
|
|
|
|
// are selected (and therefore need to be deselected). We need to account for this.
|
2002-01-12 01:20:29 +00:00
|
|
|
nsCOMPtr<nsIDOMXULMultiSelectControlElement> controlElement;
|
2002-03-29 02:46:01 +00:00
|
|
|
nsCOMPtr<nsIListBoxObject> listBox;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool fireSelectionHandler = false;
|
2000-08-24 06:14:45 +00:00
|
|
|
|
2000-09-07 05:49:04 +00:00
|
|
|
// -1 = do nothing, -2 = null out current item
|
|
|
|
// anything else = index to re-set as current
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t newCurrentIndex = -1;
|
2000-09-07 05:49:04 +00:00
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
if (oldKid->NodeInfo()->Equals(nsGkAtoms::listitem, kNameSpaceID_XUL)) {
|
1999-08-23 01:13:29 +00:00
|
|
|
// This is the nasty case. We have (potentially) a slew of selected items
|
|
|
|
// and cells going away.
|
|
|
|
// First, retrieve the tree.
|
2000-07-10 20:19:32 +00:00
|
|
|
// Check first whether this element IS the tree
|
2011-08-30 21:45:31 +00:00
|
|
|
controlElement = do_QueryObject(this);
|
2000-07-10 20:19:32 +00:00
|
|
|
|
|
|
|
// If it's not, look at our parent
|
2002-01-12 01:20:29 +00:00
|
|
|
if (!controlElement)
|
2012-03-29 21:09:07 +00:00
|
|
|
GetParentTree(getter_AddRefs(controlElement));
|
2014-04-16 19:13:41 +00:00
|
|
|
nsCOMPtr<nsIDOMXULElement> xulElement(do_QueryInterface(controlElement));
|
2005-01-24 10:45:00 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> oldKidElem = do_QueryInterface(oldKid);
|
2014-04-16 19:13:41 +00:00
|
|
|
if (xulElement && oldKidElem) {
|
2002-01-12 01:20:29 +00:00
|
|
|
// Iterate over all of the items and find out if they are contained inside
|
|
|
|
// the removed subtree.
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t length;
|
2002-01-12 01:20:29 +00:00
|
|
|
controlElement->GetSelectedCount(&length);
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t i = 0; i < length; i++) {
|
2002-01-12 01:20:29 +00:00
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> node;
|
2012-08-07 07:06:29 +00:00
|
|
|
controlElement->MultiGetSelectedItem(i, getter_AddRefs(node));
|
2005-01-24 10:45:00 +00:00
|
|
|
// we need to QI here to do an XPCOM-correct pointercompare
|
|
|
|
nsCOMPtr<nsIDOMElement> selElem = do_QueryInterface(node);
|
|
|
|
if (selElem == oldKidElem &&
|
|
|
|
NS_SUCCEEDED(controlElement->RemoveItemFromSelection(node))) {
|
2002-01-12 01:20:29 +00:00
|
|
|
length--;
|
|
|
|
i--;
|
2011-10-17 14:59:28 +00:00
|
|
|
fireSelectionHandler = true;
|
1999-08-23 01:13:29 +00:00
|
|
|
}
|
2000-09-07 05:49:04 +00:00
|
|
|
}
|
2000-08-24 06:14:45 +00:00
|
|
|
|
2002-01-12 01:20:29 +00:00
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> curItem;
|
|
|
|
controlElement->GetCurrentItem(getter_AddRefs(curItem));
|
2005-01-24 10:45:00 +00:00
|
|
|
nsCOMPtr<nsIContent> curNode = do_QueryInterface(curItem);
|
2006-03-24 00:09:50 +00:00
|
|
|
if (curNode && nsContentUtils::ContentIsDescendantOf(curNode, oldKid)) {
|
2000-09-07 05:49:04 +00:00
|
|
|
// Current item going away
|
2000-08-24 06:14:45 +00:00
|
|
|
nsCOMPtr<nsIBoxObject> box;
|
2014-04-16 19:13:41 +00:00
|
|
|
xulElement->GetBoxObject(getter_AddRefs(box));
|
2002-03-29 02:46:01 +00:00
|
|
|
listBox = do_QueryInterface(box);
|
2005-01-24 10:45:00 +00:00
|
|
|
if (listBox && oldKidElem) {
|
|
|
|
listBox->GetIndexOfItem(oldKidElem, &newCurrentIndex);
|
2000-08-24 06:14:45 +00:00
|
|
|
}
|
2000-09-07 05:49:04 +00:00
|
|
|
|
|
|
|
// If any of this fails, we'll just set the current item to null
|
|
|
|
if (newCurrentIndex == -1)
|
|
|
|
newCurrentIndex = -2;
|
1999-08-23 01:13:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-29 21:09:07 +00:00
|
|
|
nsStyledElement::RemoveChildAt(aIndex, aNotify);
|
2015-08-04 20:06:14 +00:00
|
|
|
|
2015-08-04 20:06:14 +00:00
|
|
|
if (newCurrentIndex == -2) {
|
2012-07-30 14:20:58 +00:00
|
|
|
controlElement->SetCurrentItem(nullptr);
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if (newCurrentIndex > -1) {
|
2004-02-10 09:08:06 +00:00
|
|
|
// Make sure the index is still valid
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t treeRows;
|
2004-02-10 09:08:06 +00:00
|
|
|
listBox->GetRowCount(&treeRows);
|
|
|
|
if (treeRows > 0) {
|
2013-01-15 12:22:03 +00:00
|
|
|
newCurrentIndex = std::min((treeRows - 1), newCurrentIndex);
|
2004-02-10 09:08:06 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> newCurrentItem;
|
|
|
|
listBox->GetItemAtIndex(newCurrentIndex, getter_AddRefs(newCurrentItem));
|
2004-03-10 01:34:55 +00:00
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> xulCurItem = do_QueryInterface(newCurrentItem);
|
|
|
|
if (xulCurItem)
|
|
|
|
controlElement->SetCurrentItem(xulCurItem);
|
2004-02-10 09:08:06 +00:00
|
|
|
} else {
|
2012-07-30 14:20:58 +00:00
|
|
|
controlElement->SetCurrentItem(nullptr);
|
2000-08-24 06:14:45 +00:00
|
|
|
}
|
2004-02-10 09:08:06 +00:00
|
|
|
}
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
|
2006-03-27 22:00:40 +00:00
|
|
|
nsIDocument* doc;
|
2014-10-03 12:29:48 +00:00
|
|
|
if (fireSelectionHandler && (doc = GetComposedDoc())) {
|
2005-10-10 18:38:57 +00:00
|
|
|
nsContentUtils::DispatchTrustedEvent(doc,
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<nsIContent*>(this),
|
2005-10-10 18:38:57 +00:00
|
|
|
NS_LITERAL_STRING("select"),
|
2011-10-17 14:59:28 +00:00
|
|
|
false,
|
|
|
|
true);
|
2004-02-10 09:08:06 +00:00
|
|
|
}
|
1999-01-12 05:32:30 +00:00
|
|
|
}
|
|
|
|
|
2002-02-21 13:39:39 +00:00
|
|
|
void
|
|
|
|
nsXULElement::UnregisterAccessKey(const nsAString& aOldValue)
|
|
|
|
{
|
|
|
|
// If someone changes the accesskey, unregister the old one
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
//
|
2014-10-03 12:29:48 +00:00
|
|
|
nsIDocument* doc = GetComposedDoc();
|
2005-01-14 19:30:55 +00:00
|
|
|
if (doc && !aOldValue.IsEmpty()) {
|
2010-06-25 13:59:57 +00:00
|
|
|
nsIPresShell *shell = doc->GetShell();
|
2002-02-21 13:39:39 +00:00
|
|
|
|
|
|
|
if (shell) {
|
2004-09-28 19:18:43 +00:00
|
|
|
nsIContent *content = this;
|
2002-02-21 13:39:39 +00:00
|
|
|
|
|
|
|
// find out what type of content node this is
|
2006-12-26 17:47:52 +00:00
|
|
|
if (mNodeInfo->Equals(nsGkAtoms::label)) {
|
2004-09-28 19:18:43 +00:00
|
|
|
// For anonymous labels the unregistering must
|
|
|
|
// occur on the binding parent control.
|
2008-07-23 04:50:20 +00:00
|
|
|
// XXXldb: And what if the binding parent is null?
|
2004-09-28 19:18:43 +00:00
|
|
|
content = GetBindingParent();
|
2002-02-21 13:39:39 +00:00
|
|
|
}
|
|
|
|
|
2004-09-28 19:18:43 +00:00
|
|
|
if (content) {
|
2004-08-20 20:34:37 +00:00
|
|
|
shell->GetPresContext()->EventStateManager()->
|
2004-09-28 19:18:43 +00:00
|
|
|
UnregisterAccessKey(content, aOldValue.First());
|
2002-02-21 13:39:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-02-17 11:09:57 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsXULElement::BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName,
|
2015-08-01 05:14:06 +00:00
|
|
|
nsAttrValueOrString* aValue, bool aNotify)
|
2005-10-28 02:59:38 +00:00
|
|
|
{
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aNamespaceID == kNameSpaceID_None && aName == nsGkAtoms::accesskey &&
|
2016-03-31 10:58:25 +00:00
|
|
|
IsInUncomposedDoc()) {
|
2012-07-14 15:28:54 +00:00
|
|
|
nsAutoString oldValue;
|
|
|
|
if (GetAttr(aNamespaceID, aName, oldValue)) {
|
2005-10-28 02:59:38 +00:00
|
|
|
UnregisterAccessKey(oldValue);
|
2003-06-22 06:34:08 +00:00
|
|
|
}
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if (aNamespaceID == kNameSpaceID_None &&
|
|
|
|
(aName == nsGkAtoms::command || aName == nsGkAtoms::observes) &&
|
2016-03-31 10:58:25 +00:00
|
|
|
IsInUncomposedDoc()) {
|
2008-01-29 15:12:34 +00:00
|
|
|
// XXX sXBL/XBL2 issue! Owner or current document?
|
|
|
|
nsAutoString oldValue;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::observes, oldValue);
|
|
|
|
if (oldValue.IsEmpty()) {
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::command, oldValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!oldValue.IsEmpty()) {
|
|
|
|
RemoveBroadcaster(oldValue);
|
|
|
|
}
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if (aNamespaceID == kNameSpaceID_None &&
|
|
|
|
aValue &&
|
|
|
|
mNodeInfo->Equals(nsGkAtoms::window) &&
|
|
|
|
aName == nsGkAtoms::chromemargin) {
|
2010-06-25 02:01:07 +00:00
|
|
|
nsAttrValue attrValue;
|
|
|
|
// Make sure the margin format is valid first
|
2012-02-14 02:00:56 +00:00
|
|
|
if (!attrValue.ParseIntMarginValue(aValue->String())) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2010-06-25 02:01:07 +00:00
|
|
|
}
|
2016-08-23 06:41:51 +00:00
|
|
|
} else if (aNamespaceID == kNameSpaceID_None &&
|
|
|
|
aName == nsGkAtoms::usercontextid) {
|
|
|
|
nsAutoString oldValue;
|
|
|
|
bool hasAttribute = GetAttr(kNameSpaceID_None, nsGkAtoms::usercontextid, oldValue);
|
|
|
|
if (hasAttribute && (!aValue || !aValue->String().Equals(oldValue))) {
|
|
|
|
MOZ_ASSERT(false, "Changing usercontextid is not allowed.");
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2010-06-25 02:01:07 +00:00
|
|
|
}
|
2003-06-21 04:55:32 +00:00
|
|
|
|
2010-02-24 04:37:46 +00:00
|
|
|
return nsStyledElement::BeforeSetAttr(aNamespaceID, aName,
|
|
|
|
aValue, aNotify);
|
2005-10-28 02:59:38 +00:00
|
|
|
}
|
2003-06-22 06:34:08 +00:00
|
|
|
|
2005-10-28 02:59:38 +00:00
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsXULElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
|
2012-02-14 02:00:56 +00:00
|
|
|
const nsAttrValue* aValue, bool aNotify)
|
2005-10-28 02:59:38 +00:00
|
|
|
{
|
2004-02-10 09:08:06 +00:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
2012-07-19 09:14:27 +00:00
|
|
|
if (aValue) {
|
|
|
|
// Add popup and event listeners. We can't call AddListenerFor since
|
|
|
|
// the attribute isn't set yet.
|
|
|
|
MaybeAddPopupListener(aName);
|
|
|
|
if (nsContentUtils::IsEventAttributeName(aName, EventNameType_XUL)) {
|
|
|
|
if (aValue->Type() == nsAttrValue::eString) {
|
2012-08-30 16:25:10 +00:00
|
|
|
SetEventHandler(aName, aValue->GetStringValue(), true);
|
2012-07-19 09:14:27 +00:00
|
|
|
} else {
|
|
|
|
nsAutoString body;
|
|
|
|
aValue->ToString(body);
|
2012-08-30 16:25:10 +00:00
|
|
|
SetEventHandler(aName, body, true);
|
2012-07-19 09:14:27 +00:00
|
|
|
}
|
2012-02-14 02:00:56 +00:00
|
|
|
}
|
2015-08-04 20:06:14 +00:00
|
|
|
|
2014-10-03 12:29:48 +00:00
|
|
|
nsIDocument* document = GetUncomposedDoc();
|
2013-02-04 23:22:51 +00:00
|
|
|
|
2012-07-19 09:14:27 +00:00
|
|
|
// Hide chrome if needed
|
|
|
|
if (mNodeInfo->Equals(nsGkAtoms::window)) {
|
|
|
|
if (aName == nsGkAtoms::hidechrome) {
|
|
|
|
HideWindowChrome(
|
|
|
|
aValue->Equals(NS_LITERAL_STRING("true"), eCaseMatters));
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if (aName == nsGkAtoms::chromemargin) {
|
2012-07-19 09:14:27 +00:00
|
|
|
SetChromeMargins(aValue);
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if (aName == nsGkAtoms::windowtype &&
|
|
|
|
document && document->GetRootElement() == this) {
|
2013-02-04 23:22:51 +00:00
|
|
|
MaybeUpdatePrivateLifetime();
|
|
|
|
}
|
2009-07-29 18:33:53 +00:00
|
|
|
}
|
2012-07-19 09:14:27 +00:00
|
|
|
// title, (in)activetitlebarcolor and drawintitlebar are settable on
|
|
|
|
// any root node (windows, dialogs, etc)
|
|
|
|
if (document && document->GetRootElement() == this) {
|
|
|
|
if (aName == nsGkAtoms::title) {
|
|
|
|
document->NotifyPossibleTitleChange(false);
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if ((aName == nsGkAtoms::activetitlebarcolor ||
|
|
|
|
aName == nsGkAtoms::inactivetitlebarcolor)) {
|
2012-07-19 09:14:27 +00:00
|
|
|
nscolor color = NS_RGBA(0, 0, 0, 0);
|
|
|
|
if (aValue->Type() == nsAttrValue::eColor) {
|
|
|
|
aValue->GetColorValue(color);
|
|
|
|
} else {
|
|
|
|
nsAutoString tmp;
|
|
|
|
nsAttrValue attrValue;
|
|
|
|
aValue->ToString(tmp);
|
|
|
|
attrValue.ParseColor(tmp);
|
|
|
|
attrValue.GetColorValue(color);
|
|
|
|
}
|
|
|
|
SetTitlebarColor(color, aName == nsGkAtoms::activetitlebarcolor);
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if (aName == nsGkAtoms::drawintitlebar) {
|
2012-07-19 09:14:27 +00:00
|
|
|
SetDrawsInTitlebar(
|
|
|
|
aValue->Equals(NS_LITERAL_STRING("true"), eCaseMatters));
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if (aName == nsGkAtoms::drawtitle) {
|
2013-12-17 16:11:13 +00:00
|
|
|
SetDrawsTitle(
|
|
|
|
aValue->Equals(NS_LITERAL_STRING("true"), eCaseMatters));
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if (aName == nsGkAtoms::localedir) {
|
2012-07-19 09:14:27 +00:00
|
|
|
// if the localedir changed on the root element, reset the document direction
|
|
|
|
nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(document);
|
|
|
|
if (xuldoc) {
|
|
|
|
xuldoc->ResetDocumentDirection();
|
|
|
|
}
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if (aName == nsGkAtoms::lwtheme ||
|
2012-07-19 09:14:27 +00:00
|
|
|
aName == nsGkAtoms::lwthemetextcolor) {
|
|
|
|
// if the lwtheme changed, make sure to reset the document lwtheme cache
|
|
|
|
nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(document);
|
|
|
|
if (xuldoc) {
|
|
|
|
xuldoc->ResetDocumentLWTheme();
|
2014-11-04 03:14:10 +00:00
|
|
|
UpdateBrightTitlebarForeground(document);
|
2012-07-19 09:14:27 +00:00
|
|
|
}
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if (aName == nsGkAtoms::brighttitlebarforeground) {
|
2014-11-04 03:14:10 +00:00
|
|
|
UpdateBrightTitlebarForeground(document);
|
|
|
|
}
|
2009-10-21 07:05:34 +00:00
|
|
|
}
|
2015-08-04 20:06:14 +00:00
|
|
|
|
2012-07-19 09:14:27 +00:00
|
|
|
if (aName == nsGkAtoms::src && document) {
|
|
|
|
LoadSrc();
|
2009-10-21 07:05:34 +00:00
|
|
|
}
|
2015-08-04 20:06:14 +00:00
|
|
|
} else {
|
2012-07-19 09:14:27 +00:00
|
|
|
if (mNodeInfo->Equals(nsGkAtoms::window)) {
|
|
|
|
if (aName == nsGkAtoms::hidechrome) {
|
|
|
|
HideWindowChrome(false);
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if (aName == nsGkAtoms::chromemargin) {
|
2012-07-19 09:14:27 +00:00
|
|
|
ResetChromeMargins();
|
2009-10-21 07:05:34 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-04 20:06:14 +00:00
|
|
|
|
2014-10-03 12:29:48 +00:00
|
|
|
nsIDocument* doc = GetUncomposedDoc();
|
2012-07-19 09:14:27 +00:00
|
|
|
if (doc && doc->GetRootElement() == this) {
|
|
|
|
if ((aName == nsGkAtoms::activetitlebarcolor ||
|
|
|
|
aName == nsGkAtoms::inactivetitlebarcolor)) {
|
|
|
|
// Use 0, 0, 0, 0 as the "none" color.
|
|
|
|
SetTitlebarColor(NS_RGBA(0, 0, 0, 0), aName == nsGkAtoms::activetitlebarcolor);
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if (aName == nsGkAtoms::localedir) {
|
2012-07-19 09:14:27 +00:00
|
|
|
// if the localedir changed on the root element, reset the document direction
|
|
|
|
nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(doc);
|
|
|
|
if (xuldoc) {
|
|
|
|
xuldoc->ResetDocumentDirection();
|
|
|
|
}
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if ((aName == nsGkAtoms::lwtheme ||
|
|
|
|
aName == nsGkAtoms::lwthemetextcolor)) {
|
2012-07-19 09:14:27 +00:00
|
|
|
// if the lwtheme changed, make sure to restyle appropriately
|
|
|
|
nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(doc);
|
|
|
|
if (xuldoc) {
|
|
|
|
xuldoc->ResetDocumentLWTheme();
|
2014-11-04 03:14:10 +00:00
|
|
|
UpdateBrightTitlebarForeground(doc);
|
2012-07-19 09:14:27 +00:00
|
|
|
}
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if (aName == nsGkAtoms::brighttitlebarforeground) {
|
2014-11-04 03:14:10 +00:00
|
|
|
UpdateBrightTitlebarForeground(doc);
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if (aName == nsGkAtoms::drawintitlebar) {
|
2012-07-19 09:14:27 +00:00
|
|
|
SetDrawsInTitlebar(false);
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if (aName == nsGkAtoms::drawtitle) {
|
2013-12-17 16:11:13 +00:00
|
|
|
SetDrawsTitle(false);
|
|
|
|
}
|
2009-10-02 06:22:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-28 02:59:38 +00:00
|
|
|
// XXX need to check if they're changing an event handler: if
|
|
|
|
// so, then we need to unhook the old one. Or something.
|
2002-02-20 03:33:52 +00:00
|
|
|
}
|
|
|
|
|
2010-02-24 04:37:46 +00:00
|
|
|
return nsStyledElement::AfterSetAttr(aNamespaceID, aName,
|
|
|
|
aValue, aNotify);
|
2004-02-10 09:08:06 +00:00
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
nsXULElement::ParseAttribute(int32_t aNamespaceID,
|
2005-11-29 16:37:15 +00:00
|
|
|
nsIAtom* aAttribute,
|
2005-10-28 02:59:38 +00:00
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
2004-02-10 09:08:06 +00:00
|
|
|
{
|
2005-10-28 02:59:38 +00:00
|
|
|
// Parse into a nsAttrValue
|
2010-02-24 04:37:46 +00:00
|
|
|
if (!nsStyledElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
|
|
|
aResult)) {
|
2005-10-28 02:59:38 +00:00
|
|
|
// Fall back to parsing as atom for short values
|
|
|
|
aResult.ParseStringOrAtom(aValue);
|
2004-02-10 09:08:06 +00:00
|
|
|
}
|
2003-10-30 01:40:33 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2003-10-30 01:40:33 +00:00
|
|
|
}
|
|
|
|
|
2008-01-29 15:12:34 +00:00
|
|
|
void
|
|
|
|
nsXULElement::RemoveBroadcaster(const nsAString & broadcasterId)
|
|
|
|
{
|
2011-10-18 10:53:36 +00:00
|
|
|
nsCOMPtr<nsIDOMXULDocument> xuldoc = do_QueryInterface(OwnerDoc());
|
2008-01-29 15:12:34 +00:00
|
|
|
if (xuldoc) {
|
|
|
|
nsCOMPtr<nsIDOMElement> broadcaster;
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc (do_QueryInterface(xuldoc));
|
|
|
|
domDoc->GetElementById(broadcasterId, getter_AddRefs(broadcaster));
|
|
|
|
if (broadcaster) {
|
|
|
|
xuldoc->RemoveBroadcastListenerFor(broadcaster, this,
|
|
|
|
NS_LITERAL_STRING("*"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-30 17:57:03 +00:00
|
|
|
void
|
|
|
|
nsXULElement::DestroyContent()
|
|
|
|
{
|
2008-03-21 11:18:10 +00:00
|
|
|
nsXULSlots* slots = static_cast<nsXULSlots*>(GetExistingDOMSlots());
|
2007-11-30 17:57:03 +00:00
|
|
|
if (slots) {
|
2008-03-21 11:18:10 +00:00
|
|
|
NS_IF_RELEASE(slots->mControllers);
|
2016-10-17 14:37:50 +00:00
|
|
|
RefPtr<nsFrameLoader> frameLoader = GetFrameLoader();
|
|
|
|
if (frameLoader) {
|
|
|
|
frameLoader->Destroy();
|
2008-03-21 11:18:10 +00:00
|
|
|
}
|
2016-10-17 14:37:50 +00:00
|
|
|
slots->mFrameLoaderOrOpener = nullptr;
|
2007-11-30 17:57:03 +00:00
|
|
|
}
|
|
|
|
|
2010-02-24 04:37:46 +00:00
|
|
|
nsStyledElement::DestroyContent();
|
2007-11-30 17:57:03 +00:00
|
|
|
}
|
1999-01-12 05:32:30 +00:00
|
|
|
|
2001-10-16 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsXULElement::List(FILE* out, int32_t aIndent) const
|
1999-01-12 05:32:30 +00:00
|
|
|
{
|
2009-08-13 15:38:23 +00:00
|
|
|
nsCString prefix("XUL");
|
2006-12-27 17:26:32 +00:00
|
|
|
if (HasSlots()) {
|
|
|
|
prefix.Append('*');
|
2001-08-03 07:34:28 +00:00
|
|
|
}
|
2006-12-27 17:26:32 +00:00
|
|
|
prefix.Append(' ');
|
1999-01-12 05:32:30 +00:00
|
|
|
|
2010-02-24 04:37:46 +00:00
|
|
|
nsStyledElement::List(out, aIndent, prefix);
|
1999-01-12 05:32:30 +00:00
|
|
|
}
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
1999-01-12 05:32:30 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2014-03-18 04:48:19 +00:00
|
|
|
nsXULElement::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
2006-03-07 17:08:51 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
aVisitor.mForceContentDispatch = true; //FIXME! Bug 329119
|
2009-06-23 10:07:39 +00:00
|
|
|
if (IsRootOfNativeAnonymousSubtree() &&
|
2015-03-03 11:09:00 +00:00
|
|
|
(IsAnyOfXULElements(nsGkAtoms::scrollbar, nsGkAtoms::scrollcorner)) &&
|
2015-08-28 23:58:32 +00:00
|
|
|
(aVisitor.mEvent->mMessage == eMouseClick ||
|
2015-08-28 23:58:31 +00:00
|
|
|
aVisitor.mEvent->mMessage == eMouseDoubleClick ||
|
2015-09-04 10:54:12 +00:00
|
|
|
aVisitor.mEvent->mMessage == eXULCommand ||
|
2015-08-31 15:20:06 +00:00
|
|
|
aVisitor.mEvent->mMessage == eContextMenu ||
|
2016-05-27 18:32:59 +00:00
|
|
|
aVisitor.mEvent->mMessage == eDragStart)) {
|
2009-06-23 10:07:39 +00:00
|
|
|
// Don't propagate these events from native anonymous scrollbar.
|
2011-10-17 14:59:28 +00:00
|
|
|
aVisitor.mCanHandle = true;
|
2012-07-30 14:20:58 +00:00
|
|
|
aVisitor.mParentTarget = nullptr;
|
2009-06-23 10:07:39 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-09-04 10:54:12 +00:00
|
|
|
if (aVisitor.mEvent->mMessage == eXULCommand &&
|
2014-08-04 05:28:47 +00:00
|
|
|
aVisitor.mEvent->mClass == eInputEventClass &&
|
2016-04-18 16:33:23 +00:00
|
|
|
aVisitor.mEvent->mOriginalTarget == static_cast<nsIContent*>(this) &&
|
2015-03-03 11:09:00 +00:00
|
|
|
!IsXULElement(nsGkAtoms::command)) {
|
2009-06-30 07:56:40 +00:00
|
|
|
// Check that we really have an xul command event. That will be handled
|
|
|
|
// in a special way.
|
|
|
|
nsCOMPtr<nsIDOMXULCommandEvent> xulEvent =
|
|
|
|
do_QueryInterface(aVisitor.mDOMEvent);
|
2006-03-07 17:08:51 +00:00
|
|
|
// See if we have a command elt. If so, we execute on the command
|
|
|
|
// instead of on our content element.
|
|
|
|
nsAutoString command;
|
2009-06-30 07:56:40 +00:00
|
|
|
if (xulEvent && GetAttr(kNameSpaceID_None, nsGkAtoms::command, command) &&
|
|
|
|
!command.IsEmpty()) {
|
2006-05-22 20:37:32 +00:00
|
|
|
// Stop building the event target chain for the original event.
|
|
|
|
// We don't want it to propagate to any DOM nodes.
|
2011-10-17 14:59:28 +00:00
|
|
|
aVisitor.mCanHandle = false;
|
2013-01-03 15:17:36 +00:00
|
|
|
aVisitor.mAutomaticChromeDispatch = false;
|
2006-05-22 20:37:32 +00:00
|
|
|
|
2006-03-07 17:08:51 +00:00
|
|
|
// XXX sXBL/XBL2 issue! Owner or current document?
|
2014-10-03 12:29:48 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(GetUncomposedDoc()));
|
2007-01-03 05:16:25 +00:00
|
|
|
NS_ENSURE_STATE(domDoc);
|
2006-03-07 17:08:51 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> commandElt;
|
|
|
|
domDoc->GetElementById(command, getter_AddRefs(commandElt));
|
|
|
|
nsCOMPtr<nsIContent> commandContent(do_QueryInterface(commandElt));
|
2006-05-11 17:36:18 +00:00
|
|
|
if (commandContent) {
|
2006-05-22 20:37:32 +00:00
|
|
|
// Create a new command event to dispatch to the element
|
|
|
|
// pointed to by the command attribute. The new event's
|
|
|
|
// sourceEvent will be the original command event that we're
|
|
|
|
// handling.
|
2012-08-04 07:44:00 +00:00
|
|
|
nsCOMPtr<nsIDOMEvent> domEvent = aVisitor.mDOMEvent;
|
|
|
|
while (domEvent) {
|
2014-03-05 00:37:43 +00:00
|
|
|
Event* event = domEvent->InternalDOMEvent();
|
2013-04-06 00:44:15 +00:00
|
|
|
NS_ENSURE_STATE(!SameCOMIdentity(event->GetOriginalTarget(),
|
|
|
|
commandContent));
|
2008-06-04 20:23:37 +00:00
|
|
|
nsCOMPtr<nsIDOMXULCommandEvent> commandEvent =
|
2012-08-04 07:44:00 +00:00
|
|
|
do_QueryInterface(domEvent);
|
2008-06-04 20:23:37 +00:00
|
|
|
if (commandEvent) {
|
2012-08-04 07:44:00 +00:00
|
|
|
commandEvent->GetSourceEvent(getter_AddRefs(domEvent));
|
|
|
|
} else {
|
2013-04-03 01:14:24 +00:00
|
|
|
domEvent = nullptr;
|
2008-06-04 20:23:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-18 06:10:26 +00:00
|
|
|
WidgetInputEvent* orig = aVisitor.mEvent->AsInputEvent();
|
2009-06-30 07:56:40 +00:00
|
|
|
nsContentUtils::DispatchXULCommand(
|
|
|
|
commandContent,
|
2016-03-17 07:01:30 +00:00
|
|
|
aVisitor.mEvent->IsTrusted(),
|
2009-06-30 07:56:40 +00:00
|
|
|
aVisitor.mDOMEvent,
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr,
|
2012-04-25 03:00:02 +00:00
|
|
|
orig->IsControl(),
|
|
|
|
orig->IsAlt(),
|
|
|
|
orig->IsShift(),
|
|
|
|
orig->IsMeta());
|
2006-03-07 17:08:51 +00:00
|
|
|
} else {
|
|
|
|
NS_WARNING("A XUL element is attached to a command that doesn't exist!\n");
|
2003-03-25 03:15:37 +00:00
|
|
|
}
|
2006-03-07 17:08:51 +00:00
|
|
|
return NS_OK;
|
1999-09-08 08:06:28 +00:00
|
|
|
}
|
1999-05-16 06:58:56 +00:00
|
|
|
}
|
1999-02-01 22:34:51 +00:00
|
|
|
|
2010-02-24 04:37:46 +00:00
|
|
|
return nsStyledElement::PreHandleEvent(aVisitor);
|
1999-01-12 05:32:30 +00:00
|
|
|
}
|
|
|
|
|
1999-06-15 03:21:20 +00:00
|
|
|
// XXX This _should_ be an implementation method, _not_ publicly exposed :-(
|
1999-03-10 20:20:52 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-18 22:08:15 +00:00
|
|
|
nsXULElement::GetResource(nsIRDFResource** aResource)
|
2013-01-29 17:51:55 +00:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
2014-03-15 19:00:15 +00:00
|
|
|
*aResource = GetResource(rv).take();
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2013-01-29 17:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIRDFResource>
|
|
|
|
nsXULElement::GetResource(ErrorResult& rv)
|
1999-03-10 20:20:52 +00:00
|
|
|
{
|
1999-10-05 21:13:55 +00:00
|
|
|
nsAutoString id;
|
2006-12-26 17:47:52 +00:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::ref, id);
|
2005-10-28 11:25:24 +00:00
|
|
|
if (id.IsEmpty()) {
|
2006-12-26 17:47:52 +00:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::id, id);
|
1999-10-05 21:13:55 +00:00
|
|
|
}
|
1999-07-27 23:02:13 +00:00
|
|
|
|
2013-01-29 17:51:55 +00:00
|
|
|
if (id.IsEmpty()) {
|
|
|
|
return nullptr;
|
1999-10-05 21:13:55 +00:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:51:55 +00:00
|
|
|
nsCOMPtr<nsIRDFResource> resource;
|
|
|
|
rv = nsXULContentUtils::RDFService()->
|
|
|
|
GetUnicodeResource(id, getter_AddRefs(resource));
|
|
|
|
return resource.forget();
|
1999-03-10 20:20:52 +00:00
|
|
|
}
|
|
|
|
|
1999-07-27 17:20:28 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-18 22:08:15 +00:00
|
|
|
nsXULElement::GetDatabase(nsIRDFCompositeDataSource** aDatabase)
|
1999-07-27 17:20:28 +00:00
|
|
|
{
|
2014-03-15 19:00:15 +00:00
|
|
|
*aDatabase = GetDatabase().take();
|
2013-01-29 17:51:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-23 10:56:18 +00:00
|
|
|
|
2013-01-29 17:51:55 +00:00
|
|
|
already_AddRefed<nsIRDFCompositeDataSource>
|
|
|
|
nsXULElement::GetDatabase()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIXULTemplateBuilder> builder = GetBuilder();
|
|
|
|
if (!builder) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2001-03-23 10:56:18 +00:00
|
|
|
|
2013-01-29 17:51:55 +00:00
|
|
|
nsCOMPtr<nsIRDFCompositeDataSource> database;
|
|
|
|
builder->GetDatabase(getter_AddRefs(database));
|
|
|
|
return database.forget();
|
1999-07-27 17:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-05-05 23:39:59 +00:00
|
|
|
nsXULElement::GetBuilder(nsIXULTemplateBuilder** aBuilder)
|
1999-07-27 17:20:28 +00:00
|
|
|
{
|
2014-03-15 19:00:15 +00:00
|
|
|
*aBuilder = GetBuilder().take();
|
2013-01-29 17:51:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-23 10:56:18 +00:00
|
|
|
|
2013-01-29 17:51:55 +00:00
|
|
|
already_AddRefed<nsIXULTemplateBuilder>
|
|
|
|
nsXULElement::GetBuilder()
|
|
|
|
{
|
2005-01-14 19:30:55 +00:00
|
|
|
// XXX sXBL/XBL2 issue! Owner or current document?
|
2014-10-03 12:29:48 +00:00
|
|
|
nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(GetUncomposedDoc());
|
2013-01-29 17:51:55 +00:00
|
|
|
if (!xuldoc) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2001-03-23 10:56:18 +00:00
|
|
|
|
2013-01-29 17:51:55 +00:00
|
|
|
nsCOMPtr<nsIXULTemplateBuilder> builder;
|
|
|
|
xuldoc->GetTemplateBuilderFor(this, getter_AddRefs(builder));
|
|
|
|
return builder.forget();
|
1999-07-27 17:20:28 +00:00
|
|
|
}
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
1999-03-10 20:20:52 +00:00
|
|
|
// Implementation methods
|
|
|
|
|
1999-03-05 00:01:26 +00:00
|
|
|
NS_IMETHODIMP
|
2001-10-24 00:01:09 +00:00
|
|
|
nsXULElement::WalkContentStyleRules(nsRuleWalker* aRuleWalker)
|
1999-03-05 00:01:26 +00:00
|
|
|
{
|
1999-10-20 18:55:32 +00:00
|
|
|
return NS_OK;
|
1999-03-05 00:01:26 +00:00
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2004-10-24 17:10:32 +00:00
|
|
|
nsChangeHint
|
2003-07-11 21:16:12 +00:00
|
|
|
nsXULElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aModType) const
|
1999-03-05 00:01:26 +00:00
|
|
|
{
|
2016-07-17 14:20:21 +00:00
|
|
|
nsChangeHint retval(nsChangeHint(0));
|
2000-02-22 06:09:41 +00:00
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute == nsGkAtoms::value &&
|
2003-11-19 01:20:56 +00:00
|
|
|
(aModType == nsIDOMMutationEvent::REMOVAL ||
|
|
|
|
aModType == nsIDOMMutationEvent::ADDITION)) {
|
2015-03-03 11:09:00 +00:00
|
|
|
if (IsAnyOfXULElements(nsGkAtoms::label, nsGkAtoms::description))
|
2003-11-19 01:20:56 +00:00
|
|
|
// Label and description dynamically morph between a normal
|
|
|
|
// block and a cropping single-line XUL text frame. If the
|
|
|
|
// value attribute is being added or removed, then we need to
|
|
|
|
// return a hint of frame change. (See bugzilla bug 95475 for
|
|
|
|
// details.)
|
2016-07-06 05:06:14 +00:00
|
|
|
retval = nsChangeHint_ReconstructFrame;
|
2000-07-10 20:10:27 +00:00
|
|
|
} else {
|
2003-11-19 01:20:56 +00:00
|
|
|
// if left or top changes we reflow. This will happen in xul
|
2009-07-29 18:33:53 +00:00
|
|
|
// containers that manage positioned children such as a stack.
|
2009-09-13 21:13:54 +00:00
|
|
|
if (nsGkAtoms::left == aAttribute || nsGkAtoms::top == aAttribute ||
|
2011-02-28 18:06:29 +00:00
|
|
|
nsGkAtoms::right == aAttribute || nsGkAtoms::bottom == aAttribute ||
|
|
|
|
nsGkAtoms::start == aAttribute || nsGkAtoms::end == aAttribute)
|
2004-10-24 17:10:32 +00:00
|
|
|
retval = NS_STYLE_HINT_REFLOW;
|
2000-02-22 06:09:41 +00:00
|
|
|
}
|
|
|
|
|
2004-10-24 17:10:32 +00:00
|
|
|
return retval;
|
1999-03-05 00:01:26 +00:00
|
|
|
}
|
1999-06-08 21:58:55 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP_(bool)
|
2004-02-25 21:04:50 +00:00
|
|
|
nsXULElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
2003-07-11 21:16:12 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2003-07-11 21:16:12 +00:00
|
|
|
}
|
|
|
|
|
1999-10-14 10:58:25 +00:00
|
|
|
// Controllers Methods
|
1999-06-08 21:58:55 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-18 22:08:15 +00:00
|
|
|
nsXULElement::GetControllers(nsIControllers** aResult)
|
2013-01-29 17:51:55 +00:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*aResult = GetControllers(rv));
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2013-01-29 17:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIControllers*
|
|
|
|
nsXULElement::GetControllers(ErrorResult& rv)
|
1999-06-08 21:58:55 +00:00
|
|
|
{
|
1999-12-05 23:04:22 +00:00
|
|
|
if (! Controllers()) {
|
2010-12-22 01:04:00 +00:00
|
|
|
nsDOMSlots* slots = DOMSlots();
|
2005-01-14 19:30:55 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
rv = NS_NewXULControllers(nullptr, NS_GET_IID(nsIControllers),
|
2007-07-08 07:08:04 +00:00
|
|
|
reinterpret_cast<void**>(&slots->mControllers));
|
1999-10-20 18:55:32 +00:00
|
|
|
|
2015-04-27 13:18:52 +00:00
|
|
|
NS_ASSERTION(!rv.Failed(), "unable to create a controllers");
|
2013-01-29 17:51:55 +00:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
1999-10-20 18:55:32 +00:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:51:55 +00:00
|
|
|
return Controllers();
|
1999-06-08 21:58:55 +00:00
|
|
|
}
|
|
|
|
|
2000-05-30 08:11:35 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::GetBoxObject(nsIBoxObject** aResult)
|
2000-03-23 22:17:37 +00:00
|
|
|
{
|
2013-01-29 17:51:55 +00:00
|
|
|
ErrorResult rv;
|
2014-03-15 19:00:15 +00:00
|
|
|
*aResult = GetBoxObject(rv).take();
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2013-01-29 17:51:55 +00:00
|
|
|
}
|
2000-03-23 22:17:37 +00:00
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
already_AddRefed<BoxObject>
|
2013-01-29 17:51:55 +00:00
|
|
|
nsXULElement::GetBoxObject(ErrorResult& rv)
|
|
|
|
{
|
|
|
|
// XXX sXBL/XBL2 issue! Owner or current document?
|
2013-03-26 15:31:53 +00:00
|
|
|
return OwnerDoc()->GetBoxObjectFor(this, rv);
|
2000-03-23 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
1999-06-09 05:45:15 +00:00
|
|
|
// Methods for setting/getting attributes from nsIDOMXULElement
|
2005-01-24 10:45:00 +00:00
|
|
|
#define NS_IMPL_XUL_STRING_ATTR(_method, _atom) \
|
|
|
|
NS_IMETHODIMP \
|
|
|
|
nsXULElement::Get##_method(nsAString& aReturn) \
|
|
|
|
{ \
|
2006-12-26 17:47:52 +00:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::_atom, aReturn); \
|
2005-10-28 11:25:24 +00:00
|
|
|
return NS_OK; \
|
2005-01-24 10:45:00 +00:00
|
|
|
} \
|
|
|
|
NS_IMETHODIMP \
|
|
|
|
nsXULElement::Set##_method(const nsAString& aValue) \
|
|
|
|
{ \
|
2006-12-26 17:47:52 +00:00
|
|
|
return SetAttr(kNameSpaceID_None, nsGkAtoms::_atom, aValue, \
|
2011-10-17 14:59:28 +00:00
|
|
|
true); \
|
2005-01-24 10:45:00 +00:00
|
|
|
}
|
2001-08-12 03:47:33 +00:00
|
|
|
|
2005-01-24 10:45:00 +00:00
|
|
|
#define NS_IMPL_XUL_BOOL_ATTR(_method, _atom) \
|
|
|
|
NS_IMETHODIMP \
|
2013-01-29 17:51:55 +00:00
|
|
|
nsXULElement::Get##_method(bool* aResult) \
|
2005-01-24 10:45:00 +00:00
|
|
|
{ \
|
2013-01-29 17:51:55 +00:00
|
|
|
*aResult = _method(); \
|
2005-01-24 10:45:00 +00:00
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
NS_IMETHODIMP \
|
2013-01-29 17:51:55 +00:00
|
|
|
nsXULElement::Set##_method(bool aValue) \
|
2005-01-24 10:45:00 +00:00
|
|
|
{ \
|
2013-01-29 17:51:55 +00:00
|
|
|
SetXULBoolAttr(nsGkAtoms::_atom, aValue); \
|
|
|
|
return NS_OK; \
|
2005-01-24 10:45:00 +00:00
|
|
|
}
|
2001-08-12 03:47:33 +00:00
|
|
|
|
|
|
|
|
2005-01-24 10:45:00 +00:00
|
|
|
NS_IMPL_XUL_STRING_ATTR(Align, align)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Dir, dir)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Flex, flex)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(FlexGroup, flexgroup)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Ordinal, ordinal)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Orient, orient)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Pack, pack)
|
|
|
|
NS_IMPL_XUL_BOOL_ATTR(Hidden, hidden)
|
|
|
|
NS_IMPL_XUL_BOOL_ATTR(Collapsed, collapsed)
|
|
|
|
NS_IMPL_XUL_BOOL_ATTR(AllowEvents, allowevents)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Observes, observes)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Menu, menu)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(ContextMenu, contextmenu)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Tooltip, tooltip)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Width, width)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Height, height)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(MinWidth, minwidth)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(MinHeight, minheight)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(MaxWidth, maxwidth)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(MaxHeight, maxheight)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Persist, persist)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Left, left)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Top, top)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Datasources, datasources)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Ref, ref)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(TooltipText, tooltiptext)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(StatusText, statustext)
|
2001-08-12 03:47:33 +00:00
|
|
|
|
2008-03-21 11:18:10 +00:00
|
|
|
nsresult
|
|
|
|
nsXULElement::LoadSrc()
|
|
|
|
{
|
|
|
|
// Allow frame loader only on objects for which a container box object
|
|
|
|
// can be obtained.
|
2015-03-03 11:09:00 +00:00
|
|
|
if (!IsAnyOfXULElements(nsGkAtoms::browser, nsGkAtoms::editor,
|
|
|
|
nsGkAtoms::iframe)) {
|
2008-03-21 11:18:10 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-03-31 10:58:25 +00:00
|
|
|
if (!IsInUncomposedDoc() ||
|
2011-10-18 10:53:36 +00:00
|
|
|
!OwnerDoc()->GetRootElement() ||
|
|
|
|
OwnerDoc()->GetRootElement()->
|
2008-03-21 11:18:10 +00:00
|
|
|
NodeInfo()->Equals(nsGkAtoms::overlay, kNameSpaceID_XUL)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-10-17 14:37:50 +00:00
|
|
|
RefPtr<nsFrameLoader> frameLoader = GetFrameLoader();
|
|
|
|
if (!frameLoader) {
|
|
|
|
// Check if we have an opener we need to be setting
|
|
|
|
nsXULSlots* slots = static_cast<nsXULSlots*>(Slots());
|
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> opener = do_QueryInterface(slots->mFrameLoaderOrOpener);
|
|
|
|
if (!opener) {
|
2016-10-07 18:59:59 +00:00
|
|
|
// If we are a content-primary xul-browser, we want to take the opener property!
|
|
|
|
nsCOMPtr<nsIDOMChromeWindow> chromeWindow = do_QueryInterface(OwnerDoc()->GetWindow());
|
|
|
|
if (AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
NS_LITERAL_STRING("content-primary"), eIgnoreCase) &&
|
|
|
|
chromeWindow) {
|
|
|
|
nsCOMPtr<mozIDOMWindowProxy> wp;
|
|
|
|
chromeWindow->TakeOpenerForInitialContentBrowser(getter_AddRefs(wp));
|
|
|
|
opener = nsPIDOMWindowOuter::From(wp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-17 14:37:50 +00:00
|
|
|
// false as the last parameter so that xul:iframe/browser/editor
|
|
|
|
// session history handling works like dynamic html:iframes.
|
|
|
|
// Usually xul elements are used in chrome, which doesn't have
|
|
|
|
// session history at all.
|
|
|
|
frameLoader = nsFrameLoader::Create(this, opener, false);
|
|
|
|
slots->mFrameLoaderOrOpener = static_cast<nsIFrameLoader*>(frameLoader);
|
|
|
|
NS_ENSURE_TRUE(frameLoader, NS_OK);
|
2016-10-07 18:59:59 +00:00
|
|
|
|
2015-04-28 14:22:38 +00:00
|
|
|
(new AsyncEventDispatcher(this,
|
|
|
|
NS_LITERAL_STRING("XULFrameLoaderCreated"),
|
|
|
|
/* aBubbles */ true))->RunDOMEventWhenSafe();
|
|
|
|
|
2015-01-05 19:16:09 +00:00
|
|
|
if (AttrValueIs(kNameSpaceID_None, nsGkAtoms::prerendered,
|
|
|
|
NS_LITERAL_STRING("true"), eIgnoreCase)) {
|
2016-10-17 14:37:50 +00:00
|
|
|
nsresult rv = frameLoader->SetIsPrerendered();
|
2015-01-05 19:16:09 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
}
|
2008-03-21 11:18:10 +00:00
|
|
|
}
|
|
|
|
|
2016-10-17 14:37:50 +00:00
|
|
|
return frameLoader->LoadFrame();
|
2008-03-21 11:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-08-11 16:09:22 +00:00
|
|
|
nsXULElement::GetFrameLoaderXPCOM(nsIFrameLoader **aFrameLoader)
|
2008-03-21 11:18:10 +00:00
|
|
|
{
|
2014-03-15 19:00:15 +00:00
|
|
|
*aFrameLoader = GetFrameLoader().take();
|
2008-03-21 11:18:10 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-20 21:33:59 +00:00
|
|
|
already_AddRefed<nsFrameLoader>
|
|
|
|
nsXULElement::GetFrameLoader()
|
|
|
|
{
|
|
|
|
nsXULSlots* slots = static_cast<nsXULSlots*>(GetExistingSlots());
|
|
|
|
if (!slots)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-10-20 21:33:59 +00:00
|
|
|
|
2016-10-17 14:37:50 +00:00
|
|
|
nsCOMPtr<nsIFrameLoader> loader = do_QueryInterface(slots->mFrameLoaderOrOpener);
|
|
|
|
return already_AddRefed<nsFrameLoader>(static_cast<nsFrameLoader*>(loader.forget().take()));
|
2009-10-20 21:33:59 +00:00
|
|
|
}
|
|
|
|
|
2015-12-11 16:17:33 +00:00
|
|
|
nsresult
|
|
|
|
nsXULElement::GetParentApplication(mozIApplication** aApplication)
|
|
|
|
{
|
|
|
|
if (!aApplication) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aApplication = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-10-07 18:59:59 +00:00
|
|
|
void
|
|
|
|
nsXULElement::PresetOpenerWindow(mozIDOMWindowProxy* aWindow, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsXULSlots* slots = static_cast<nsXULSlots*>(Slots());
|
2016-10-17 14:37:50 +00:00
|
|
|
MOZ_ASSERT(!slots->mFrameLoaderOrOpener, "A frameLoader or opener is present when calling PresetOpenerWindow");
|
2016-10-07 18:59:59 +00:00
|
|
|
|
2016-10-17 14:37:50 +00:00
|
|
|
slots->mFrameLoaderOrOpener = aWindow;
|
2016-10-07 18:59:59 +00:00
|
|
|
}
|
|
|
|
|
2015-01-05 19:16:09 +00:00
|
|
|
nsresult
|
|
|
|
nsXULElement::SetIsPrerendered()
|
|
|
|
{
|
|
|
|
return SetAttr(kNameSpaceID_None, nsGkAtoms::prerendered, nullptr,
|
|
|
|
NS_LITERAL_STRING("true"), true);
|
|
|
|
}
|
|
|
|
|
2016-10-17 14:37:50 +00:00
|
|
|
void
|
|
|
|
nsXULElement::InternalSetFrameLoader(nsIFrameLoader* aNewFrameLoader)
|
|
|
|
{
|
|
|
|
nsXULSlots* slots = static_cast<nsXULSlots*>(GetExistingDOMSlots());
|
|
|
|
MOZ_ASSERT(slots);
|
|
|
|
|
|
|
|
slots->mFrameLoaderOrOpener = aNewFrameLoader;
|
|
|
|
}
|
|
|
|
|
2016-01-09 00:11:58 +00:00
|
|
|
void
|
|
|
|
nsXULElement::SwapFrameLoaders(HTMLIFrameElement& aOtherLoaderOwner,
|
|
|
|
ErrorResult& rv)
|
2008-08-11 08:38:43 +00:00
|
|
|
{
|
2016-10-17 14:37:50 +00:00
|
|
|
if (!GetExistingDOMSlots()) {
|
2016-01-09 00:11:58 +00:00
|
|
|
rv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
return;
|
|
|
|
}
|
2008-08-11 08:38:43 +00:00
|
|
|
|
2016-10-17 14:37:50 +00:00
|
|
|
nsCOMPtr<nsIFrameLoaderOwner> flo = do_QueryInterface(static_cast<nsIDOMXULElement*>(this));
|
|
|
|
aOtherLoaderOwner.SwapFrameLoaders(flo, rv);
|
2013-01-29 17:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-09 00:11:58 +00:00
|
|
|
nsXULElement::SwapFrameLoaders(nsXULElement& aOtherLoaderOwner,
|
|
|
|
ErrorResult& rv)
|
2013-01-29 17:51:55 +00:00
|
|
|
{
|
2016-01-09 00:11:58 +00:00
|
|
|
if (&aOtherLoaderOwner == this) {
|
2008-08-11 08:38:43 +00:00
|
|
|
// nothing to do
|
2013-01-29 17:51:55 +00:00
|
|
|
return;
|
2008-08-11 08:38:43 +00:00
|
|
|
}
|
|
|
|
|
2016-10-17 14:37:50 +00:00
|
|
|
if (!GetExistingDOMSlots()) {
|
2016-01-09 00:11:58 +00:00
|
|
|
rv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-17 14:37:50 +00:00
|
|
|
nsCOMPtr<nsIFrameLoaderOwner> flo = do_QueryInterface(static_cast<nsIDOMXULElement*>(this));
|
|
|
|
aOtherLoaderOwner.SwapFrameLoaders(flo, rv);
|
2016-01-09 00:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-17 14:37:50 +00:00
|
|
|
nsXULElement::SwapFrameLoaders(nsIFrameLoaderOwner* aOtherLoaderOwner,
|
2016-01-09 00:11:58 +00:00
|
|
|
mozilla::ErrorResult& rv)
|
|
|
|
{
|
2016-10-17 14:37:50 +00:00
|
|
|
if (!GetExistingDOMSlots()) {
|
|
|
|
rv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<nsFrameLoader> loader = GetFrameLoader();
|
|
|
|
RefPtr<nsFrameLoader> otherLoader = aOtherLoaderOwner->GetFrameLoader();
|
|
|
|
if (!loader || !otherLoader) {
|
2013-01-29 17:51:55 +00:00
|
|
|
rv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
return;
|
2008-08-11 08:38:43 +00:00
|
|
|
}
|
|
|
|
|
2016-10-17 14:37:50 +00:00
|
|
|
nsCOMPtr<nsIFrameLoaderOwner> flo = do_QueryInterface(static_cast<nsIDOMXULElement*>(this));
|
|
|
|
rv = loader->SwapWithOtherLoader(otherLoader, flo, aOtherLoaderOwner);
|
2008-08-11 08:38:43 +00:00
|
|
|
}
|
|
|
|
|
1999-08-22 06:01:52 +00:00
|
|
|
NS_IMETHODIMP
|
2002-01-12 01:20:29 +00:00
|
|
|
nsXULElement::GetParentTree(nsIDOMXULMultiSelectControlElement** aTreeElement)
|
1999-08-22 06:01:52 +00:00
|
|
|
{
|
2003-11-19 01:20:56 +00:00
|
|
|
for (nsIContent* current = GetParent(); current;
|
|
|
|
current = current->GetParent()) {
|
2006-12-26 17:47:52 +00:00
|
|
|
if (current->NodeInfo()->Equals(nsGkAtoms::listbox,
|
2005-09-24 18:43:15 +00:00
|
|
|
kNameSpaceID_XUL)) {
|
2003-11-19 01:20:56 +00:00
|
|
|
CallQueryInterface(current, aTreeElement);
|
|
|
|
// XXX returning NS_OK because that's what the code used to do;
|
|
|
|
// is that the right thing, though?
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-08-22 06:01:52 +00:00
|
|
|
}
|
2003-11-19 01:20:56 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-08-22 06:01:52 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 06:35:27 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::Focus()
|
2013-01-29 17:51:55 +00:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
Focus(rv);
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2013-01-29 17:51:55 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 06:35:27 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::Blur()
|
2013-01-29 17:51:55 +00:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
Blur(rv);
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2013-01-29 17:51:55 +00:00
|
|
|
}
|
|
|
|
|
2000-02-12 10:08:52 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::Click()
|
2010-04-06 12:59:24 +00:00
|
|
|
{
|
2015-10-13 17:56:24 +00:00
|
|
|
return ClickWithInputSource(nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN, /* aIsTrusted = */ true);
|
2010-04-06 12:59:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:51:55 +00:00
|
|
|
void
|
|
|
|
nsXULElement::Click(ErrorResult& rv)
|
|
|
|
{
|
2015-10-13 17:56:24 +00:00
|
|
|
rv = ClickWithInputSource(nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN, nsContentUtils::IsCallerChrome());
|
2013-01-29 17:51:55 +00:00
|
|
|
}
|
|
|
|
|
2010-04-06 12:59:24 +00:00
|
|
|
nsresult
|
2015-10-13 17:56:24 +00:00
|
|
|
nsXULElement::ClickWithInputSource(uint16_t aInputSource, bool aIsTrustedEvent)
|
2000-02-12 10:08:52 +00:00
|
|
|
{
|
2006-12-26 17:47:52 +00:00
|
|
|
if (BoolAttrIsTrue(nsGkAtoms::disabled))
|
2004-01-09 23:54:21 +00:00
|
|
|
return NS_OK;
|
2002-02-01 23:55:49 +00:00
|
|
|
|
2014-10-03 12:29:48 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc = GetComposedDoc(); // Strong just in case
|
2004-01-09 23:54:21 +00:00
|
|
|
if (doc) {
|
2010-06-25 13:59:57 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell = doc->GetShell();
|
2010-01-07 10:36:11 +00:00
|
|
|
if (shell) {
|
2007-05-22 21:45:03 +00:00
|
|
|
// strong ref to PresContext so events don't destroy it
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsPresContext> context = shell->GetPresContext();
|
2004-01-09 23:54:21 +00:00
|
|
|
|
2015-10-13 17:56:24 +00:00
|
|
|
WidgetMouseEvent eventDown(aIsTrustedEvent, eMouseDown,
|
2013-10-02 06:38:27 +00:00
|
|
|
nullptr, WidgetMouseEvent::eReal);
|
2015-10-13 17:56:24 +00:00
|
|
|
WidgetMouseEvent eventUp(aIsTrustedEvent, eMouseUp,
|
2013-10-02 06:38:27 +00:00
|
|
|
nullptr, WidgetMouseEvent::eReal);
|
2015-10-13 17:56:24 +00:00
|
|
|
WidgetMouseEvent eventClick(aIsTrustedEvent, eMouseClick, nullptr,
|
2013-10-02 06:38:27 +00:00
|
|
|
WidgetMouseEvent::eReal);
|
2015-08-04 20:06:14 +00:00
|
|
|
eventDown.inputSource = eventUp.inputSource = eventClick.inputSource
|
2010-04-06 12:59:24 +00:00
|
|
|
= aInputSource;
|
2004-01-09 23:54:21 +00:00
|
|
|
|
|
|
|
// send mouse down
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2014-03-18 04:48:21 +00:00
|
|
|
EventDispatcher::Dispatch(static_cast<nsIContent*>(this),
|
|
|
|
context, &eventDown, nullptr, &status);
|
2004-01-09 23:54:21 +00:00
|
|
|
|
|
|
|
// send mouse up
|
|
|
|
status = nsEventStatus_eIgnore; // reset status
|
2014-03-18 04:48:21 +00:00
|
|
|
EventDispatcher::Dispatch(static_cast<nsIContent*>(this),
|
|
|
|
context, &eventUp, nullptr, &status);
|
2004-01-09 23:54:21 +00:00
|
|
|
|
|
|
|
// send mouse click
|
|
|
|
status = nsEventStatus_eIgnore; // reset status
|
2014-03-18 04:48:21 +00:00
|
|
|
EventDispatcher::Dispatch(static_cast<nsIContent*>(this),
|
|
|
|
context, &eventClick, nullptr, &status);
|
2016-08-09 13:51:47 +00:00
|
|
|
|
|
|
|
// If the click has been prevented, lets skip the command call
|
|
|
|
// this is how a physical click works
|
|
|
|
if (status == nsEventStatus_eConsumeNoDefault) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-01-09 23:54:21 +00:00
|
|
|
}
|
2001-06-20 02:02:57 +00:00
|
|
|
}
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
// oncommand is fired when an element is clicked...
|
|
|
|
return DoCommand();
|
2001-06-20 02:02:57 +00:00
|
|
|
}
|
2000-02-12 10:47:33 +00:00
|
|
|
|
2001-06-20 02:02:57 +00:00
|
|
|
NS_IMETHODIMP
|
2001-08-12 03:47:33 +00:00
|
|
|
nsXULElement::DoCommand()
|
2001-06-20 02:02:57 +00:00
|
|
|
{
|
2014-10-03 12:29:48 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc = GetComposedDoc(); // strong just in case
|
2004-01-09 23:54:21 +00:00
|
|
|
if (doc) {
|
2011-10-17 14:59:28 +00:00
|
|
|
nsContentUtils::DispatchXULCommand(this, true);
|
2000-02-12 10:08:52 +00:00
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
return NS_OK;
|
2000-02-12 10:08:52 +00:00
|
|
|
}
|
2000-01-25 06:35:27 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsIContent *
|
2003-07-28 21:17:26 +00:00
|
|
|
nsXULElement::GetBindingParent() const
|
2000-08-12 06:28:02 +00:00
|
|
|
{
|
2004-01-09 23:54:21 +00:00
|
|
|
return mBindingParent;
|
2000-08-12 06:28:02 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
nsXULElement::IsNodeOfType(uint32_t aFlags) const
|
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 16:46:42 +00:00
|
|
|
{
|
2010-04-30 13:12:06 +00:00
|
|
|
return !(aFlags & ~eCONTENT);
|
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 16:46:42 +00:00
|
|
|
}
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
nsresult
|
|
|
|
nsXULElement::AddPopupListener(nsIAtom* aName)
|
|
|
|
{
|
2007-07-04 15:49:38 +00:00
|
|
|
// Add a popup listener to the element
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isContext = (aName == nsGkAtoms::context ||
|
2007-07-04 15:49:38 +00:00
|
|
|
aName == nsGkAtoms::contextmenu);
|
2012-10-16 12:37:26 +00:00
|
|
|
uint32_t listenerFlag = isContext ?
|
|
|
|
XUL_ELEMENT_HAS_CONTENTMENU_LISTENER :
|
|
|
|
XUL_ELEMENT_HAS_POPUP_LISTENER;
|
|
|
|
|
|
|
|
if (HasFlag(listenerFlag)) {
|
2006-08-16 08:44:45 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-06-29 22:15:59 +00:00
|
|
|
|
2012-10-16 12:37:26 +00:00
|
|
|
nsCOMPtr<nsIDOMEventListener> listener =
|
|
|
|
new nsXULPopupListener(this, isContext);
|
1999-10-29 01:21:15 +00:00
|
|
|
|
|
|
|
// Add the popup as a listener on this element.
|
2014-03-17 06:56:53 +00:00
|
|
|
EventListenerManager* manager = GetOrCreateListenerManager();
|
2012-10-16 12:37:26 +00:00
|
|
|
SetFlags(listenerFlag);
|
2009-06-23 10:07:39 +00:00
|
|
|
|
|
|
|
if (isContext) {
|
2011-06-24 02:18:02 +00:00
|
|
|
manager->AddEventListenerByType(listener,
|
|
|
|
NS_LITERAL_STRING("contextmenu"),
|
2014-03-17 06:56:52 +00:00
|
|
|
TrustedEventsAtSystemGroupBubble());
|
2009-06-23 10:07:39 +00:00
|
|
|
} else {
|
2011-06-24 02:18:02 +00:00
|
|
|
manager->AddEventListenerByType(listener,
|
|
|
|
NS_LITERAL_STRING("mousedown"),
|
2014-03-17 06:56:52 +00:00
|
|
|
TrustedEventsAtSystemGroupBubble());
|
2009-06-23 10:07:39 +00:00
|
|
|
}
|
1999-10-29 01:21:15 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-03 04:18:36 +00:00
|
|
|
EventStates
|
2007-06-28 02:48:16 +00:00
|
|
|
nsXULElement::IntrinsicState() const
|
|
|
|
{
|
2014-04-03 04:18:36 +00:00
|
|
|
EventStates state = nsStyledElement::IntrinsicState();
|
2007-06-28 02:48:16 +00:00
|
|
|
|
2011-06-01 01:46:57 +00:00
|
|
|
if (IsReadWriteTextElement()) {
|
2007-06-28 02:48:16 +00:00
|
|
|
state |= NS_EVENT_STATE_MOZ_READWRITE;
|
|
|
|
state &= ~NS_EVENT_STATE_MOZ_READONLY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
1999-10-20 18:55:32 +00:00
|
|
|
|
2012-07-14 15:28:54 +00:00
|
|
|
nsresult
|
|
|
|
nsXULElement::MakeHeavyweight(nsXULPrototypeElement* aPrototype)
|
2001-10-22 20:48:52 +00:00
|
|
|
{
|
2012-07-14 15:28:54 +00:00
|
|
|
if (!aPrototype) {
|
|
|
|
return NS_OK;
|
2001-10-22 20:48:52 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t i;
|
2005-01-14 19:30:55 +00:00
|
|
|
nsresult rv;
|
2012-07-14 15:28:54 +00:00
|
|
|
for (i = 0; i < aPrototype->mNumAttributes; ++i) {
|
|
|
|
nsXULPrototypeAttribute* protoattr = &aPrototype->mAttributes[i];
|
2010-08-13 06:03:23 +00:00
|
|
|
nsAttrValue attrValue;
|
2015-08-04 20:06:14 +00:00
|
|
|
|
2007-04-29 17:58:52 +00:00
|
|
|
// Style rules need to be cloned.
|
2016-10-18 04:29:03 +00:00
|
|
|
if (protoattr->mValue.Type() == nsAttrValue::eCSSDeclaration) {
|
|
|
|
DeclarationBlock* decl = protoattr->mValue.GetCSSDeclarationValue();
|
|
|
|
RefPtr<css::Declaration>
|
|
|
|
declClone = new css::Declaration(*decl->AsGecko());
|
2007-04-29 17:58:52 +00:00
|
|
|
|
2010-08-13 06:03:23 +00:00
|
|
|
nsString stringValue;
|
|
|
|
protoattr->mValue.ToString(stringValue);
|
|
|
|
|
2016-10-18 04:29:03 +00:00
|
|
|
attrValue.SetTo(declClone.forget(), &stringValue);
|
2015-08-04 20:06:14 +00:00
|
|
|
} else {
|
2010-08-13 06:03:23 +00:00
|
|
|
attrValue.SetTo(protoattr->mValue);
|
2007-04-29 17:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-08-13 06:03:23 +00:00
|
|
|
// XXX we might wanna have a SetAndTakeAttr that takes an nsAttrName
|
2004-02-10 09:08:06 +00:00
|
|
|
if (protoattr->mName.IsAtom()) {
|
2015-07-22 02:09:41 +00:00
|
|
|
rv = mAttrsAndChildren.SetAndSwapAttr(protoattr->mName.Atom(), attrValue);
|
2015-08-04 20:06:14 +00:00
|
|
|
} else {
|
2015-07-22 02:09:41 +00:00
|
|
|
rv = mAttrsAndChildren.SetAndSwapAttr(protoattr->mName.NodeInfo(),
|
2004-02-10 09:08:06 +00:00
|
|
|
attrValue);
|
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-11-03 10:24:03 +00:00
|
|
|
}
|
1999-10-20 18:55:32 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-02-20 03:33:52 +00:00
|
|
|
nsresult
|
2011-09-29 06:19:26 +00:00
|
|
|
nsXULElement::HideWindowChrome(bool aShouldHide)
|
2002-02-20 03:33:52 +00:00
|
|
|
{
|
2014-10-03 12:29:48 +00:00
|
|
|
nsIDocument* doc = GetUncomposedDoc();
|
2010-04-30 13:12:05 +00:00
|
|
|
if (!doc || doc->GetRootElement() != this)
|
2005-01-14 19:30:55 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2007-08-21 06:44:43 +00:00
|
|
|
// only top level chrome documents can hide the window chrome
|
2008-10-04 20:00:09 +00:00
|
|
|
if (!doc->IsRootDisplayDocument())
|
2007-08-21 06:44:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-06-25 13:59:57 +00:00
|
|
|
nsIPresShell *shell = doc->GetShell();
|
2002-02-20 03:33:52 +00:00
|
|
|
|
|
|
|
if (shell) {
|
2009-12-24 21:20:05 +00:00
|
|
|
nsIFrame* frame = GetPrimaryFrame();
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
|
2004-08-20 20:34:37 +00:00
|
|
|
nsPresContext *presContext = shell->GetPresContext();
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
|
2007-08-21 06:44:43 +00:00
|
|
|
if (frame && presContext && presContext->IsChrome()) {
|
2013-01-03 13:23:11 +00:00
|
|
|
nsView* view = frame->GetClosestView();
|
2002-02-20 03:33:52 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
if (view) {
|
2006-11-23 15:55:58 +00:00
|
|
|
nsIWidget* w = view->GetWidget();
|
|
|
|
NS_ENSURE_STATE(w);
|
|
|
|
w->HideWindowChrome(aShouldHide);
|
2003-09-27 04:18:26 +00:00
|
|
|
}
|
2002-02-20 03:33:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
return NS_OK;
|
2002-02-20 03:33:52 +00:00
|
|
|
}
|
|
|
|
|
2009-10-21 07:05:34 +00:00
|
|
|
nsIWidget*
|
|
|
|
nsXULElement::GetWindowWidget()
|
2007-10-30 04:03:42 +00:00
|
|
|
{
|
2014-10-03 12:29:48 +00:00
|
|
|
nsIDocument* doc = GetComposedDoc();
|
2007-10-30 04:03:42 +00:00
|
|
|
|
|
|
|
// only top level chrome documents can set the titlebar color
|
2013-11-22 15:40:31 +00:00
|
|
|
if (doc && doc->IsRootDisplayDocument()) {
|
2007-10-30 04:03:42 +00:00
|
|
|
nsCOMPtr<nsISupports> container = doc->GetContainer();
|
|
|
|
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(container);
|
|
|
|
if (baseWindow) {
|
|
|
|
nsCOMPtr<nsIWidget> mainWidget;
|
|
|
|
baseWindow->GetMainWidget(getter_AddRefs(mainWidget));
|
2009-10-21 07:05:34 +00:00
|
|
|
return mainWidget;
|
2007-10-30 04:03:42 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-10-21 07:05:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 06:19:26 +00:00
|
|
|
nsXULElement::SetTitlebarColor(nscolor aColor, bool aActive)
|
2009-10-21 07:05:34 +00:00
|
|
|
{
|
|
|
|
nsIWidget* mainWidget = GetWindowWidget();
|
|
|
|
if (mainWidget) {
|
|
|
|
mainWidget->SetWindowTitlebarColor(aColor, aActive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-26 00:23:21 +00:00
|
|
|
class SetDrawInTitleBarEvent : public Runnable
|
2011-02-04 12:59:33 +00:00
|
|
|
{
|
|
|
|
public:
|
2011-09-29 06:19:26 +00:00
|
|
|
SetDrawInTitleBarEvent(nsIWidget* aWidget, bool aState)
|
2011-02-04 12:59:33 +00:00
|
|
|
: mWidget(aWidget)
|
|
|
|
, mState(aState)
|
|
|
|
{}
|
|
|
|
|
2016-08-08 02:18:10 +00:00
|
|
|
NS_IMETHOD Run() override {
|
2011-02-04 12:59:33 +00:00
|
|
|
NS_ASSERTION(mWidget, "You shouldn't call this runnable with a null widget!");
|
|
|
|
|
|
|
|
mWidget->SetDrawsInTitlebar(mState);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIWidget> mWidget;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mState;
|
2011-02-04 12:59:33 +00:00
|
|
|
};
|
|
|
|
|
2009-10-21 07:05:34 +00:00
|
|
|
void
|
2011-09-29 06:19:26 +00:00
|
|
|
nsXULElement::SetDrawsInTitlebar(bool aState)
|
2009-10-21 07:05:34 +00:00
|
|
|
{
|
|
|
|
nsIWidget* mainWidget = GetWindowWidget();
|
|
|
|
if (mainWidget) {
|
2011-02-10 00:45:54 +00:00
|
|
|
nsContentUtils::AddScriptRunner(new SetDrawInTitleBarEvent(mainWidget, aState));
|
2009-10-21 07:05:34 +00:00
|
|
|
}
|
2007-10-30 04:03:42 +00:00
|
|
|
}
|
|
|
|
|
2013-12-17 16:11:13 +00:00
|
|
|
void
|
|
|
|
nsXULElement::SetDrawsTitle(bool aState)
|
|
|
|
{
|
|
|
|
nsIWidget* mainWidget = GetWindowWidget();
|
|
|
|
if (mainWidget) {
|
|
|
|
// We can do this synchronously because SetDrawsTitle doesn't have any
|
|
|
|
// synchronous effects apart from a harmless invalidation.
|
|
|
|
mainWidget->SetDrawsTitle(aState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-04 03:14:10 +00:00
|
|
|
void
|
|
|
|
nsXULElement::UpdateBrightTitlebarForeground(nsIDocument* aDoc)
|
|
|
|
{
|
|
|
|
nsIWidget* mainWidget = GetWindowWidget();
|
|
|
|
if (mainWidget) {
|
|
|
|
// We can do this synchronously because SetBrightTitlebarForeground doesn't have any
|
|
|
|
// synchronous effects apart from a harmless invalidation.
|
|
|
|
mainWidget->SetUseBrightTitlebarForeground(
|
|
|
|
aDoc->GetDocumentLWTheme() == nsIDocument::Doc_Theme_Bright ||
|
|
|
|
aDoc->GetRootElement()->AttrValueIs(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::brighttitlebarforeground,
|
|
|
|
NS_LITERAL_STRING("true"),
|
|
|
|
eCaseMatters));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-26 00:23:21 +00:00
|
|
|
class MarginSetter : public Runnable
|
2011-08-03 18:32:32 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-09-02 00:49:25 +00:00
|
|
|
explicit MarginSetter(nsIWidget* aWidget) :
|
2011-08-03 18:32:32 +00:00
|
|
|
mWidget(aWidget), mMargin(-1, -1, -1, -1)
|
|
|
|
{}
|
2015-11-12 07:05:04 +00:00
|
|
|
MarginSetter(nsIWidget *aWidget, const LayoutDeviceIntMargin& aMargin) :
|
2011-08-03 18:32:32 +00:00
|
|
|
mWidget(aWidget), mMargin(aMargin)
|
|
|
|
{}
|
|
|
|
|
2016-08-08 02:18:10 +00:00
|
|
|
NS_IMETHOD Run() override
|
2011-08-03 18:32:32 +00:00
|
|
|
{
|
|
|
|
// SetNonClientMargins can dispatch native events, hence doing
|
|
|
|
// it off a script runner.
|
|
|
|
mWidget->SetNonClientMargins(mMargin);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIWidget> mWidget;
|
2015-11-12 07:05:04 +00:00
|
|
|
LayoutDeviceIntMargin mMargin;
|
2011-08-03 18:32:32 +00:00
|
|
|
};
|
|
|
|
|
2010-06-25 02:01:07 +00:00
|
|
|
void
|
2012-02-14 02:00:56 +00:00
|
|
|
nsXULElement::SetChromeMargins(const nsAttrValue* aValue)
|
2010-06-25 02:01:07 +00:00
|
|
|
{
|
|
|
|
if (!aValue)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIWidget* mainWidget = GetWindowWidget();
|
|
|
|
if (!mainWidget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// top, right, bottom, left - see nsAttrValue
|
|
|
|
nsIntMargin margins;
|
2012-02-14 02:00:56 +00:00
|
|
|
bool gotMargins = false;
|
2010-06-25 02:01:07 +00:00
|
|
|
|
2012-02-14 02:00:56 +00:00
|
|
|
if (aValue->Type() == nsAttrValue::eIntMarginValue) {
|
|
|
|
gotMargins = aValue->GetIntMarginValue(margins);
|
|
|
|
} else {
|
|
|
|
nsAutoString tmp;
|
|
|
|
aValue->ToString(tmp);
|
|
|
|
gotMargins = nsContentUtils::ParseIntMarginValue(tmp, margins);
|
|
|
|
}
|
|
|
|
if (gotMargins) {
|
2015-11-12 07:05:04 +00:00
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new MarginSetter(
|
|
|
|
mainWidget, LayoutDeviceIntMargin::FromUnknownMargin(margins)));
|
2010-06-25 02:01:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULElement::ResetChromeMargins()
|
|
|
|
{
|
|
|
|
nsIWidget* mainWidget = GetWindowWidget();
|
|
|
|
if (!mainWidget)
|
|
|
|
return;
|
|
|
|
// See nsIWidget
|
2011-08-03 18:32:32 +00:00
|
|
|
nsContentUtils::AddScriptRunner(new MarginSetter(mainWidget));
|
2010-06-25 02:01:07 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2013-01-29 17:51:55 +00:00
|
|
|
nsXULElement::BoolAttrIsTrue(nsIAtom* aName) const
|
2005-01-24 10:45:00 +00:00
|
|
|
{
|
|
|
|
const nsAttrValue* attr =
|
2012-07-14 15:28:54 +00:00
|
|
|
GetAttrInfo(kNameSpaceID_None, aName).mValue;
|
2005-01-24 10:45:00 +00:00
|
|
|
|
|
|
|
return attr && attr->Type() == nsAttrValue::eAtom &&
|
2006-12-26 17:47:52 +00:00
|
|
|
attr->GetAtomValue() == nsGkAtoms::_true;
|
2005-01-24 10:45:00 +00:00
|
|
|
}
|
|
|
|
|
2006-10-07 10:27:45 +00:00
|
|
|
void
|
|
|
|
nsXULElement::RecompileScriptEventListeners()
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t i, count = mAttrsAndChildren.AttrCount();
|
2006-10-07 10:27:45 +00:00
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
const nsAttrName *name = mAttrsAndChildren.AttrNameAt(i);
|
|
|
|
|
|
|
|
// Eventlistenener-attributes are always in the null namespace
|
|
|
|
if (!name->IsAtom()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom *attr = name->Atom();
|
2007-04-02 17:17:36 +00:00
|
|
|
if (!nsContentUtils::IsEventAttributeName(attr, EventNameType_XUL)) {
|
2006-10-07 10:27:45 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString value;
|
|
|
|
GetAttr(kNameSpaceID_None, attr, value);
|
2012-08-30 16:25:10 +00:00
|
|
|
SetEventHandler(attr, value, true);
|
2006-10-07 10:27:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-02 20:24:07 +00:00
|
|
|
bool
|
|
|
|
nsXULElement::IsEventAttributeName(nsIAtom *aName)
|
|
|
|
{
|
|
|
|
return nsContentUtils::IsEventAttributeName(aName, EventNameType_XUL);
|
|
|
|
}
|
|
|
|
|
2013-01-29 17:51:55 +00:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
nsXULElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-01-29 17:51:55 +00:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
return dom::XULElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-01-29 17:51:55 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 01:29:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULPrototypeNode)
|
|
|
|
|
2012-11-22 17:15:38 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXULPrototypeNode)
|
2007-11-01 22:51:57 +00:00
|
|
|
if (tmp->mType == nsXULPrototypeNode::eType_Element) {
|
|
|
|
static_cast<nsXULPrototypeElement*>(tmp)->Unlink();
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if (tmp->mType == nsXULPrototypeNode::eType_Script) {
|
2010-11-08 15:02:49 +00:00
|
|
|
static_cast<nsXULPrototypeScript*>(tmp)->UnlinkJSObjects();
|
|
|
|
}
|
2007-11-01 22:51:57 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2012-11-22 17:15:38 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULPrototypeNode)
|
2007-05-24 14:10:02 +00:00
|
|
|
if (tmp->mType == nsXULPrototypeNode::eType_Element) {
|
|
|
|
nsXULPrototypeElement *elem =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<nsXULPrototypeElement*>(tmp);
|
2012-01-23 23:25:53 +00:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mNodeInfo");
|
2014-06-20 02:01:40 +00:00
|
|
|
cb.NoteNativeChild(elem->mNodeInfo,
|
|
|
|
NS_CYCLE_COLLECTION_PARTICIPANT(NodeInfo));
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t i;
|
2008-03-28 14:09:00 +00:00
|
|
|
for (i = 0; i < elem->mNumAttributes; ++i) {
|
|
|
|
const nsAttrName& name = elem->mAttributes[i].mName;
|
2012-01-23 23:25:53 +00:00
|
|
|
if (!name.IsAtom()) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb,
|
|
|
|
"mAttributes[i].mName.NodeInfo()");
|
2015-08-04 20:06:14 +00:00
|
|
|
cb.NoteNativeChild(name.NodeInfo(),
|
2014-06-20 02:01:40 +00:00
|
|
|
NS_CYCLE_COLLECTION_PARTICIPANT(NodeInfo));
|
2012-01-23 23:25:53 +00:00
|
|
|
}
|
2008-03-28 14:09:00 +00:00
|
|
|
}
|
2012-11-15 07:32:39 +00:00
|
|
|
ImplCycleCollectionTraverse(cb, elem->mChildren, "mChildren");
|
2007-05-24 14:10:02 +00:00
|
|
|
}
|
2007-10-29 13:45:07 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2012-11-23 19:27:06 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsXULPrototypeNode)
|
2012-07-19 09:18:01 +00:00
|
|
|
if (tmp->mType == nsXULPrototypeNode::eType_Script) {
|
2007-10-29 13:45:07 +00:00
|
|
|
nsXULPrototypeScript *script =
|
|
|
|
static_cast<nsXULPrototypeScript*>(tmp);
|
2013-05-27 11:50:49 +00:00
|
|
|
script->Trace(aCallbacks, aClosure);
|
2007-05-24 14:10:02 +00:00
|
|
|
}
|
2007-10-29 13:45:07 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
2012-04-30 22:54:16 +00:00
|
|
|
|
2012-08-24 16:50:06 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsXULPrototypeNode, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsXULPrototypeNode, Release)
|
2007-05-24 14:10:02 +00:00
|
|
|
|
1999-12-06 08:23:47 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsXULPrototypeAttribute
|
|
|
|
//
|
|
|
|
|
|
|
|
nsXULPrototypeAttribute::~nsXULPrototypeAttribute()
|
|
|
|
{
|
2003-10-30 01:40:33 +00:00
|
|
|
MOZ_COUNT_DTOR(nsXULPrototypeAttribute);
|
1999-12-06 08:23:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsXULPrototypeElement
|
|
|
|
//
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
nsresult
|
|
|
|
nsXULPrototypeElement::Serialize(nsIObjectOutputStream* aStream,
|
2013-08-19 23:24:27 +00:00
|
|
|
nsXULPrototypeDocument* aProtoDoc,
|
2015-10-18 05:24:48 +00:00
|
|
|
const nsTArray<RefPtr<mozilla::dom::NodeInfo>> *aNodeInfos)
|
2001-07-31 19:05:34 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2002-05-03 03:04:34 +00:00
|
|
|
// Write basic prototype data
|
|
|
|
rv = aStream->Write32(mType);
|
|
|
|
|
|
|
|
// Write Node Info
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t index = aNodeInfos->IndexOf(mNodeInfo);
|
2014-06-20 02:01:40 +00:00
|
|
|
NS_ASSERTION(index >= 0, "unknown mozilla::dom::NodeInfo index");
|
2012-07-27 14:03:08 +00:00
|
|
|
nsresult tmp = aStream->Write32(index);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2002-05-03 03:04:34 +00:00
|
|
|
// Write Attributes
|
2012-07-27 14:03:08 +00:00
|
|
|
tmp = aStream->Write32(mNumAttributes);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2002-05-03 03:04:34 +00:00
|
|
|
|
2002-09-03 22:31:38 +00:00
|
|
|
nsAutoString attributeValue;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t i;
|
2002-05-03 03:04:34 +00:00
|
|
|
for (i = 0; i < mNumAttributes; ++i) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> ni;
|
2004-02-10 09:08:06 +00:00
|
|
|
if (mAttributes[i].mName.IsAtom()) {
|
2008-09-12 22:32:18 +00:00
|
|
|
ni = mNodeInfo->NodeInfoManager()->
|
2012-07-30 14:20:58 +00:00
|
|
|
GetNodeInfo(mAttributes[i].mName.Atom(), nullptr,
|
2011-06-14 07:56:49 +00:00
|
|
|
kNameSpaceID_None,
|
|
|
|
nsIDOMNode::ATTRIBUTE_NODE);
|
2004-02-10 09:08:06 +00:00
|
|
|
NS_ASSERTION(ni, "the nodeinfo should already exist");
|
2015-08-04 20:06:14 +00:00
|
|
|
} else {
|
2004-02-10 09:08:06 +00:00
|
|
|
ni = mAttributes[i].mName.NodeInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
index = aNodeInfos->IndexOf(ni);
|
2014-06-20 02:01:40 +00:00
|
|
|
NS_ASSERTION(index >= 0, "unknown mozilla::dom::NodeInfo index");
|
2012-07-27 14:03:08 +00:00
|
|
|
tmp = aStream->Write32(index);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2002-05-03 03:04:34 +00:00
|
|
|
|
2004-02-10 09:08:06 +00:00
|
|
|
mAttributes[i].mValue.ToString(attributeValue);
|
2012-07-27 14:03:08 +00:00
|
|
|
tmp = aStream->WriteWStringZ(attributeValue.get());
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
}
|
2002-05-03 03:04:34 +00:00
|
|
|
|
|
|
|
// Now write children
|
2012-08-22 15:56:38 +00:00
|
|
|
tmp = aStream->Write32(uint32_t(mChildren.Length()));
|
2012-07-27 14:03:08 +00:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2008-10-08 11:41:52 +00:00
|
|
|
for (i = 0; i < mChildren.Length(); i++) {
|
|
|
|
nsXULPrototypeNode* child = mChildren[i].get();
|
2002-05-03 03:04:34 +00:00
|
|
|
switch (child->mType) {
|
|
|
|
case eType_Element:
|
|
|
|
case eType_Text:
|
2006-11-11 22:27:00 +00:00
|
|
|
case eType_PI:
|
2013-08-19 23:24:27 +00:00
|
|
|
tmp = child->Serialize(aStream, aProtoDoc, aNodeInfos);
|
2012-07-27 14:03:08 +00:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2002-05-03 03:04:34 +00:00
|
|
|
break;
|
|
|
|
case eType_Script:
|
2012-07-27 14:03:08 +00:00
|
|
|
tmp = aStream->Write32(child->mType);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-07-08 07:08:04 +00:00
|
|
|
nsXULPrototypeScript* script = static_cast<nsXULPrototypeScript*>(child);
|
2002-05-03 03:04:34 +00:00
|
|
|
|
2012-07-27 14:03:08 +00:00
|
|
|
tmp = aStream->Write8(script->mOutOfLine);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
if (! script->mOutOfLine) {
|
2013-08-19 23:24:27 +00:00
|
|
|
tmp = script->Serialize(aStream, aProtoDoc, aNodeInfos);
|
2012-07-27 14:03:08 +00:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
} else {
|
2012-07-27 14:03:08 +00:00
|
|
|
tmp = aStream->WriteCompoundObject(script->mSrcURI,
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
NS_GET_IID(nsIURI),
|
2011-10-17 14:59:28 +00:00
|
|
|
true);
|
2012-07-27 14:03:08 +00:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
|
2016-10-14 08:45:28 +00:00
|
|
|
if (script->HasScriptObject()) {
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
// This may return NS_OK without muxing script->mSrcURI's
|
2010-08-12 19:42:36 +00:00
|
|
|
// data into the cache file, in the case where that
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
// muxed document is already there (written by a prior
|
2010-08-12 19:42:36 +00:00
|
|
|
// session, or by an earlier cache episode during this
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
// session).
|
2013-08-19 23:24:27 +00:00
|
|
|
tmp = script->SerializeOutOfLine(aStream, aProtoDoc);
|
2012-07-27 14:03:08 +00:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
}
|
2002-05-03 03:04:34 +00:00
|
|
|
}
|
|
|
|
break;
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
}
|
2002-05-03 03:04:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2001-07-31 19:05:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
|
2013-08-19 23:24:27 +00:00
|
|
|
nsXULPrototypeDocument* aProtoDoc,
|
2002-07-23 22:16:45 +00:00
|
|
|
nsIURI* aDocumentURI,
|
2015-10-18 05:24:48 +00:00
|
|
|
const nsTArray<RefPtr<mozilla::dom::NodeInfo>> *aNodeInfos)
|
2001-07-31 19:05:34 +00:00
|
|
|
{
|
2002-09-03 22:31:38 +00:00
|
|
|
NS_PRECONDITION(aNodeInfos, "missing nodeinfo array");
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2002-05-03 03:04:34 +00:00
|
|
|
// Read Node Info
|
2015-08-04 20:06:14 +00:00
|
|
|
uint32_t number = 0;
|
2012-04-11 14:48:14 +00:00
|
|
|
nsresult rv = aStream->Read32(&number);
|
2015-08-13 21:24:59 +00:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
2015-08-04 20:06:14 +00:00
|
|
|
mNodeInfo = aNodeInfos->SafeElementAt(number, nullptr);
|
2015-08-04 20:06:14 +00:00
|
|
|
if (!mNodeInfo) {
|
2002-09-03 22:31:38 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2015-08-04 20:06:14 +00:00
|
|
|
}
|
2002-05-03 03:04:34 +00:00
|
|
|
|
|
|
|
// Read Attributes
|
2015-08-13 21:24:59 +00:00
|
|
|
rv = aStream->Read32(&number);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
2012-08-22 15:56:38 +00:00
|
|
|
mNumAttributes = int32_t(number);
|
2003-09-27 04:18:26 +00:00
|
|
|
|
2002-05-03 03:04:34 +00:00
|
|
|
if (mNumAttributes > 0) {
|
2015-08-04 20:06:14 +00:00
|
|
|
mAttributes = new (fallible) nsXULPrototypeAttribute[mNumAttributes];
|
2015-08-04 20:06:14 +00:00
|
|
|
if (!mAttributes) {
|
2002-05-03 03:04:34 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2015-08-04 20:06:14 +00:00
|
|
|
}
|
2002-05-03 03:04:34 +00:00
|
|
|
|
2002-11-14 18:16:31 +00:00
|
|
|
nsAutoString attributeValue;
|
2015-08-04 20:06:15 +00:00
|
|
|
for (uint32_t i = 0; i < mNumAttributes; ++i) {
|
2015-08-13 21:24:59 +00:00
|
|
|
rv = aStream->Read32(&number);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
2015-08-04 20:06:14 +00:00
|
|
|
mozilla::dom::NodeInfo* ni = aNodeInfos->SafeElementAt(number, nullptr);
|
2015-08-04 20:06:14 +00:00
|
|
|
if (!ni) {
|
2002-09-03 22:31:38 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2015-08-04 20:06:14 +00:00
|
|
|
}
|
2002-05-03 03:04:34 +00:00
|
|
|
|
2004-02-10 09:08:06 +00:00
|
|
|
mAttributes[i].mName.SetTo(ni);
|
2002-05-03 03:04:34 +00:00
|
|
|
|
2015-08-13 21:24:59 +00:00
|
|
|
rv = aStream->ReadString(attributeValue);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
|
|
|
rv = SetAttrAt(i, attributeValue, aDocumentURI);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
2002-05-03 03:04:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-13 21:24:59 +00:00
|
|
|
rv = aStream->Read32(&number);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t numChildren = int32_t(number);
|
2002-09-25 09:56:09 +00:00
|
|
|
|
2008-10-08 11:41:52 +00:00
|
|
|
if (numChildren > 0) {
|
2015-08-13 21:24:59 +00:00
|
|
|
if (!mChildren.SetCapacity(numChildren, fallible)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2002-05-03 03:04:34 +00:00
|
|
|
|
2015-08-04 20:06:15 +00:00
|
|
|
for (uint32_t i = 0; i < numChildren; i++) {
|
2015-08-13 21:24:59 +00:00
|
|
|
rv = aStream->Read32(&number);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
2002-05-03 03:04:34 +00:00
|
|
|
Type childType = (Type)number;
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsXULPrototypeNode> child;
|
2002-05-03 03:04:34 +00:00
|
|
|
|
|
|
|
switch (childType) {
|
|
|
|
case eType_Element:
|
2002-09-25 09:56:09 +00:00
|
|
|
child = new nsXULPrototypeElement();
|
2015-08-13 21:24:59 +00:00
|
|
|
rv = child->Deserialize(aStream, aProtoDoc, aDocumentURI,
|
|
|
|
aNodeInfos);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
2002-05-03 03:04:34 +00:00
|
|
|
break;
|
|
|
|
case eType_Text:
|
2002-09-25 09:56:09 +00:00
|
|
|
child = new nsXULPrototypeText();
|
2015-08-13 21:24:59 +00:00
|
|
|
rv = child->Deserialize(aStream, aProtoDoc, aDocumentURI,
|
|
|
|
aNodeInfos);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
2006-11-11 22:27:00 +00:00
|
|
|
break;
|
|
|
|
case eType_PI:
|
|
|
|
child = new nsXULPrototypePI();
|
2015-08-13 21:24:59 +00:00
|
|
|
rv = child->Deserialize(aStream, aProtoDoc, aDocumentURI,
|
|
|
|
aNodeInfos);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
2002-05-03 03:04:34 +00:00
|
|
|
break;
|
2002-11-08 04:28:04 +00:00
|
|
|
case eType_Script: {
|
2005-07-02 19:52:25 +00:00
|
|
|
// language version/options obtained during deserialization.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsXULPrototypeScript> script = new nsXULPrototypeScript(0, 0);
|
2002-05-03 03:04:34 +00:00
|
|
|
|
2015-08-13 21:24:59 +00:00
|
|
|
rv = aStream->ReadBoolean(&script->mOutOfLine);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
2015-08-13 21:24:59 +00:00
|
|
|
if (!script->mOutOfLine) {
|
2015-08-13 21:24:59 +00:00
|
|
|
rv = script->Deserialize(aStream, aProtoDoc, aDocumentURI,
|
|
|
|
aNodeInfos);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
2005-07-02 19:52:25 +00:00
|
|
|
} else {
|
2014-03-15 19:00:17 +00:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
2015-08-13 21:24:59 +00:00
|
|
|
rv = aStream->ReadObject(true, getter_AddRefs(supports));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
2014-03-15 19:00:17 +00:00
|
|
|
script->mSrcURI = do_QueryInterface(supports);
|
2002-05-03 03:04:34 +00:00
|
|
|
|
2015-08-13 21:24:59 +00:00
|
|
|
rv = script->DeserializeOutOfLine(aStream, aProtoDoc);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
2002-11-08 04:28:04 +00:00
|
|
|
}
|
2015-08-13 21:24:59 +00:00
|
|
|
|
|
|
|
child = script.forget();
|
2002-05-03 03:04:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-12-30 11:10:24 +00:00
|
|
|
default:
|
2015-08-04 20:06:14 +00:00
|
|
|
MOZ_ASSERT(false, "Unexpected child type!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2002-11-08 04:28:04 +00:00
|
|
|
}
|
2002-05-03 03:04:34 +00:00
|
|
|
|
2015-08-04 20:06:14 +00:00
|
|
|
MOZ_ASSERT(child, "Don't append null to mChildren");
|
2015-08-13 21:24:59 +00:00
|
|
|
MOZ_ASSERT(child->mType == childType);
|
2008-10-08 11:41:52 +00:00
|
|
|
mChildren.AppendElement(child);
|
2002-06-09 10:31:00 +00:00
|
|
|
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
// Oh dear. Something failed during the deserialization.
|
|
|
|
// We don't know what. But likely consequences of failed
|
2010-08-12 19:42:36 +00:00
|
|
|
// deserializations included calls to |AbortCaching| which
|
|
|
|
// shuts down the cache and closes our streams.
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
// If that happens, next time through this loop, we die a messy
|
|
|
|
// death. So, let's just fail now, and propagate that failure
|
|
|
|
// upward so that the ChromeProtocolHandler knows it can't use
|
|
|
|
// a cached chrome channel for this.
|
2015-08-13 21:24:59 +00:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv)))
|
2002-06-09 10:31:00 +00:00
|
|
|
return rv;
|
2002-05-03 03:04:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2001-07-31 19:05:34 +00:00
|
|
|
}
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsXULPrototypeElement::SetAttrAt(uint32_t aPos, const nsAString& aValue,
|
2004-02-10 09:08:06 +00:00
|
|
|
nsIURI* aDocumentURI)
|
1999-10-29 01:21:15 +00:00
|
|
|
{
|
2004-02-10 09:08:06 +00:00
|
|
|
NS_PRECONDITION(aPos < mNumAttributes, "out-of-bounds");
|
|
|
|
|
|
|
|
// WARNING!!
|
|
|
|
// This code is largely duplicated in nsXULElement::SetAttr.
|
|
|
|
// Any changes should be made to both functions.
|
|
|
|
|
|
|
|
if (!mNodeInfo->NamespaceEquals(kNameSpaceID_XUL)) {
|
2004-03-04 02:06:28 +00:00
|
|
|
mAttributes[aPos].mValue.ParseStringOrAtom(aValue);
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2004-02-10 09:08:06 +00:00
|
|
|
return NS_OK;
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
if (mAttributes[aPos].mName.Equals(nsGkAtoms::id) &&
|
2004-02-10 09:08:06 +00:00
|
|
|
!aValue.IsEmpty()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mHasIdAttribute = true;
|
2004-02-10 09:08:06 +00:00
|
|
|
// Store id as atom.
|
|
|
|
// id="" means that the element has no id. Not that it has
|
|
|
|
// emptystring as id.
|
2004-03-04 02:06:28 +00:00
|
|
|
mAttributes[aPos].mValue.ParseAtom(aValue);
|
2004-02-10 09:08:06 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if (mAttributes[aPos].mName.Equals(nsGkAtoms::_class)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mHasClassAttribute = true;
|
2004-02-10 09:08:06 +00:00
|
|
|
// Compute the element's class list
|
2004-03-04 02:06:28 +00:00
|
|
|
mAttributes[aPos].mValue.ParseAtomArray(aValue);
|
2010-03-02 20:59:32 +00:00
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
return NS_OK;
|
2015-08-04 20:06:14 +00:00
|
|
|
} else if (mAttributes[aPos].mName.Equals(nsGkAtoms::style)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mHasStyleAttribute = true;
|
2004-02-10 09:08:06 +00:00
|
|
|
// Parse the element's 'style' attribute
|
2010-03-02 20:59:32 +00:00
|
|
|
|
|
|
|
nsCSSParser parser;
|
2004-02-10 09:08:06 +00:00
|
|
|
|
2004-09-10 23:31:48 +00:00
|
|
|
// XXX Get correct Base URI (need GetBaseURI on *prototype* element)
|
2012-08-30 17:58:24 +00:00
|
|
|
// TODO: If we implement Content Security Policy for chrome documents
|
|
|
|
// as has been discussed, the CSP should be checked here to see if
|
|
|
|
// inline styles are allowed to be applied.
|
2015-11-09 07:57:16 +00:00
|
|
|
RefPtr<css::Declaration> declaration =
|
|
|
|
parser.ParseStyleAttribute(aValue, aDocumentURI, aDocumentURI,
|
|
|
|
// This is basically duplicating what
|
|
|
|
// nsINode::NodePrincipal() does
|
|
|
|
mNodeInfo->NodeInfoManager()->
|
|
|
|
DocumentPrincipal());
|
|
|
|
if (declaration) {
|
2016-10-18 04:29:03 +00:00
|
|
|
mAttributes[aPos].mValue.SetTo(declaration.forget(), &aValue);
|
2004-02-10 09:08:06 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// Don't abort if parsing failed, it could just be malformed css.
|
|
|
|
}
|
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
mAttributes[aPos].mValue.ParseStringOrAtom(aValue);
|
2004-02-10 09:08:06 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-18 02:25:33 +00:00
|
|
|
|
2007-10-29 13:45:07 +00:00
|
|
|
void
|
2010-11-08 15:02:49 +00:00
|
|
|
nsXULPrototypeElement::Unlink()
|
2007-10-29 13:45:07 +00:00
|
|
|
{
|
|
|
|
mNumAttributes = 0;
|
|
|
|
delete[] mAttributes;
|
2012-07-30 14:20:58 +00:00
|
|
|
mAttributes = nullptr;
|
2013-08-07 00:37:05 +00:00
|
|
|
mChildren.Clear();
|
2007-10-29 13:45:07 +00:00
|
|
|
}
|
|
|
|
|
2012-08-24 20:22:23 +00:00
|
|
|
void
|
|
|
|
nsXULPrototypeElement::TraceAllScripts(JSTracer* aTrc)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mChildren.Length(); ++i) {
|
|
|
|
nsXULPrototypeNode* child = mChildren[i];
|
|
|
|
if (child->mType == nsXULPrototypeNode::eType_Element) {
|
|
|
|
static_cast<nsXULPrototypeElement*>(child)->TraceAllScripts(aTrc);
|
|
|
|
} else if (child->mType == nsXULPrototypeNode::eType_Script) {
|
2013-03-28 20:37:22 +00:00
|
|
|
static_cast<nsXULPrototypeScript*>(child)->TraceScriptObject(aTrc);
|
2012-08-24 20:22:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-06 08:23:47 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsXULPrototypeScript
|
|
|
|
//
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
nsXULPrototypeScript::nsXULPrototypeScript(uint32_t aLineNo, uint32_t aVersion)
|
2002-09-25 09:56:09 +00:00
|
|
|
: nsXULPrototypeNode(eType_Script),
|
|
|
|
mLineNo(aLineNo),
|
2011-10-17 14:59:28 +00:00
|
|
|
mSrcLoading(false),
|
|
|
|
mOutOfLine(true),
|
2012-07-30 14:20:58 +00:00
|
|
|
mSrcLoadWaiters(nullptr),
|
2006-06-26 21:12:32 +00:00
|
|
|
mLangVersion(aVersion),
|
2012-08-24 20:22:23 +00:00
|
|
|
mScriptObject(nullptr)
|
1999-11-18 02:25:33 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsXULPrototypeScript::~nsXULPrototypeScript()
|
|
|
|
{
|
2008-01-30 02:05:43 +00:00
|
|
|
UnlinkJSObjects();
|
1999-11-18 02:25:33 +00:00
|
|
|
}
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
nsresult
|
|
|
|
nsXULPrototypeScript::Serialize(nsIObjectOutputStream* aStream,
|
2013-08-19 23:24:27 +00:00
|
|
|
nsXULPrototypeDocument* aProtoDoc,
|
2015-10-18 05:24:48 +00:00
|
|
|
const nsTArray<RefPtr<mozilla::dom::NodeInfo>> *aNodeInfos)
|
2001-07-31 19:05:34 +00:00
|
|
|
{
|
2014-04-14 21:40:49 +00:00
|
|
|
NS_ENSURE_TRUE(aProtoDoc, NS_ERROR_UNEXPECTED);
|
2016-03-18 14:48:38 +00:00
|
|
|
|
|
|
|
AutoJSAPI jsapi;
|
|
|
|
if (!jsapi.Init(xpc::CompilationScope())) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2013-08-19 23:24:27 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_ASSERTION(!mSrcLoading || mSrcLoadWaiters != nullptr ||
|
2012-08-24 20:22:23 +00:00
|
|
|
!mScriptObject,
|
2002-11-07 22:46:38 +00:00
|
|
|
"script source still loading when serializing?!");
|
2012-08-24 20:22:23 +00:00
|
|
|
if (!mScriptObject)
|
2002-11-07 22:46:38 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2002-05-03 03:04:34 +00:00
|
|
|
// Write basic prototype data
|
2006-06-13 03:07:47 +00:00
|
|
|
nsresult rv;
|
|
|
|
rv = aStream->Write32(mLineNo);
|
2001-07-31 19:05:34 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2006-06-13 03:07:47 +00:00
|
|
|
rv = aStream->Write32(mLangVersion);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2013-07-23 09:58:28 +00:00
|
|
|
|
2016-03-18 14:48:38 +00:00
|
|
|
JSContext* cx = jsapi.cx();
|
2016-10-14 08:45:28 +00:00
|
|
|
JS::Rooted<JSScript*> script(cx, mScriptObject);
|
2014-08-18 17:57:30 +00:00
|
|
|
MOZ_ASSERT(xpc::CompilationScope() == JS::CurrentGlobalOrNull(cx));
|
2016-10-14 08:45:28 +00:00
|
|
|
return nsContentUtils::XPConnect()->WriteScript(aStream, cx, script);
|
2001-07-31 19:05:34 +00:00
|
|
|
}
|
|
|
|
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
nsresult
|
|
|
|
nsXULPrototypeScript::SerializeOutOfLine(nsIObjectOutputStream* aStream,
|
2013-08-19 23:24:27 +00:00
|
|
|
nsXULPrototypeDocument* aProtoDoc)
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
{
|
2010-08-12 19:42:36 +00:00
|
|
|
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isChrome = false;
|
2010-08-12 19:42:36 +00:00
|
|
|
if (NS_FAILED(mSrcURI->SchemeIs("chrome", &isChrome)) || !isChrome)
|
|
|
|
// Don't cache scripts that don't come from chrome uris.
|
|
|
|
return rv;
|
|
|
|
|
2007-03-12 05:53:33 +00:00
|
|
|
nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
|
|
|
|
if (!cache)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
|
2007-03-12 05:53:33 +00:00
|
|
|
NS_ASSERTION(cache->IsEnabled(),
|
2010-08-12 19:42:36 +00:00
|
|
|
"writing to the cache file, but the XUL cache is off?");
|
2011-09-29 06:19:26 +00:00
|
|
|
bool exists;
|
2010-08-12 19:42:36 +00:00
|
|
|
cache->HasData(mSrcURI, &exists);
|
2013-07-23 09:58:27 +00:00
|
|
|
|
2005-06-01 18:33:20 +00:00
|
|
|
/* return will be NS_OK from GetAsciiSpec.
|
|
|
|
* that makes no sense.
|
|
|
|
* nor does returning NS_OK from HasMuxedDocument.
|
|
|
|
* XXX return something meaningful.
|
|
|
|
*/
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
if (exists)
|
2005-06-01 18:33:20 +00:00
|
|
|
return NS_OK;
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
|
2010-08-12 19:42:36 +00:00
|
|
|
nsCOMPtr<nsIObjectOutputStream> oos;
|
|
|
|
rv = cache->GetOutputStream(mSrcURI, getter_AddRefs(oos));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-08-04 20:06:14 +00:00
|
|
|
|
2013-08-19 23:24:27 +00:00
|
|
|
nsresult tmp = Serialize(oos, aProtoDoc, nullptr);
|
2012-07-27 14:03:08 +00:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
|
|
|
tmp = cache->FinishOutputStream(mSrcURI);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
2010-08-12 19:42:36 +00:00
|
|
|
cache->AbortCaching();
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
nsresult
|
|
|
|
nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream,
|
2013-08-19 23:24:27 +00:00
|
|
|
nsXULPrototypeDocument* aProtoDoc,
|
2002-07-23 22:16:45 +00:00
|
|
|
nsIURI* aDocumentURI,
|
2015-10-18 05:24:48 +00:00
|
|
|
const nsTArray<RefPtr<mozilla::dom::NodeInfo>> *aNodeInfos)
|
2001-07-31 19:05:34 +00:00
|
|
|
{
|
2015-08-13 21:24:59 +00:00
|
|
|
nsresult rv;
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_ASSERTION(!mSrcLoading || mSrcLoadWaiters != nullptr ||
|
2012-08-24 20:22:23 +00:00
|
|
|
!mScriptObject,
|
2001-07-31 19:05:34 +00:00
|
|
|
"prototype script not well-initialized when deserializing?!");
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
|
2006-06-13 03:07:47 +00:00
|
|
|
// Read basic prototype data
|
2015-08-13 21:24:59 +00:00
|
|
|
rv = aStream->Read32(&mLineNo);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = aStream->Read32(&mLangVersion);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2006-06-13 03:07:47 +00:00
|
|
|
|
2016-03-18 14:48:38 +00:00
|
|
|
AutoJSAPI jsapi;
|
|
|
|
if (!jsapi.Init(xpc::CompilationScope())) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
JSContext* cx = jsapi.cx();
|
2013-08-19 23:24:27 +00:00
|
|
|
|
2013-08-19 23:24:27 +00:00
|
|
|
JS::Rooted<JSScript*> newScriptObject(cx);
|
2015-08-13 21:24:59 +00:00
|
|
|
rv = nsContentUtils::XPConnect()->ReadScript(aStream, cx,
|
|
|
|
newScriptObject.address());
|
2013-08-19 23:24:27 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-10-29 13:45:07 +00:00
|
|
|
Set(newScriptObject);
|
2001-07-31 19:05:34 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-05-03 03:04:34 +00:00
|
|
|
|
|
|
|
nsresult
|
Reduce seeks outside the FastLoad file's underlying stream buffer (195010,
r=ben, sr=bryner).
- Pass null scope objects into nsIScriptContext::Compile{EventHandler,Script}
when precompiling for brutal sharing. The JS engine does not need a non-null
object parameter for static scope. That parameter can be non-null only if it
helps the compiler "pre-bind" functions to the same scope object that they'll
be parented by when executing, but with brutal sharing, functions are
precompiled once and executed against many different scope objects.
- A problem in XUL FastLoad was that it would serialize master .xul document
out-of-line scripts (those included via script src= from non-overlay, "master"
.xul docs) far from the place in the FastLoad file where XUL prototype script
info was serialized for the <script src=> tag itself. I fixed that so that,
unless the out-of-line script was previously serialized (by a different src=
reference from another .xul file), the OOL script data immediately follows the
proto-script info in the FastLoad file.
This required adding a SerializeOutOfLine method to nsXULPrototypeScript, which
restores symmetry by matching the existing DeserializeOutOfLine(Script) (note:
I dropped the redundant "Script" from the end of the latter method's name. We
need SerializeOutOfLine to handle overlay OOL scripts. They are serialized by
nsXULDocument::OnStreamComplete, because that code knows the difference between
an overlay and a master doc. This removes all trace of FastLoad writing from
nsXULPrototypeScript::Compile -- FastLoad stuff didn't belong there, not only
because we now want to write master OOL scripts later, when walking the master
XUL prototype doc's element tree, but also for modularity reasons. The caller
knows about FastLoad, nsXULPrototypeScript::Compile does just what its name
implies.
There are 132 seeks with the patch, only 49 of which dump the underlying file
stream's buffer, vs. 133 seeks without the patch, 87 of which dump the buffer.
- Nit-picked some comments to fit in 80 columns, and made other cosmetic fixes.
- Implicated the nsXULDocument::mIsWritingFastLoad flag from the useXULCache
"is the XUL cache enabled?" flag, so other places that test mIsWritingFastLoad
don't have to query whether the cache is enabled.
- Added METERING synchronous meter-dumping to /tmp/bufstats, only ifdef
DEBUG_brendan, in netwerk/base/src/nsBufferedStreams.cpp.
- Added the deferred seek optimization from the first patch in bug 195010 to
nsFastLoadFile.cpp.
- Fixed nsFastLoadFileReader so it overrides readSegments as well as read.
This catches up with the interface extension made to nsIInputStream to add
readSegments. The nsFastLoadFileReader extends nsBinaryInputStream, which is
a concrete class, and overrides Read in order to snoop on *all* bytes read.
It does this in order to demultiplex documents interleaved when the FastLoad
file was written.
But since the readSegments move into nsIInputStream.idl, certain primitives
in nsBinaryStream.cpp, e.g., nsBinaryInputStream::ReadCString, have used
ReadSegments, not Read, to consume parts of the underlying stream (to read
the C string's chars, in that example), and the FastLoad file implementation
has not accounted for those bytes.
- Added a new method to nsIFastLoadFileControl and its impls: hasMuxedDocument.
This is needed when serializing master XUL doc OOL scripts, because we must
not serialize twice, and any OOL script that other XUL docs can include via
script src= could already be in the FastLoad mux.
/be
2003-04-12 01:34:11 +00:00
|
|
|
nsXULPrototypeScript::DeserializeOutOfLine(nsIObjectInputStream* aInput,
|
2013-08-19 23:24:27 +00:00
|
|
|
nsXULPrototypeDocument* aProtoDoc)
|
2002-05-03 03:04:34 +00:00
|
|
|
{
|
2010-08-12 19:42:36 +00:00
|
|
|
// Keep track of failure via rv, so we can
|
|
|
|
// AbortCaching if things look bad.
|
2002-06-09 10:31:00 +00:00
|
|
|
nsresult rv = NS_OK;
|
2007-03-12 05:53:33 +00:00
|
|
|
nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
|
2015-08-04 20:06:14 +00:00
|
|
|
|
2003-01-17 10:04:49 +00:00
|
|
|
nsCOMPtr<nsIObjectInputStream> objectInput = aInput;
|
2010-08-12 19:42:36 +00:00
|
|
|
if (cache) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool useXULCache = true;
|
2002-05-03 03:04:34 +00:00
|
|
|
if (mSrcURI) {
|
|
|
|
// NB: we must check the XUL script cache early, to avoid
|
2015-08-04 20:06:14 +00:00
|
|
|
// multiple deserialization attempts for a given script.
|
2013-03-26 15:31:53 +00:00
|
|
|
// Note that XULDocument::LoadScript
|
2002-05-03 03:04:34 +00:00
|
|
|
// checks the XUL script cache too, in order to handle the
|
|
|
|
// serialization case.
|
|
|
|
//
|
|
|
|
// We need do this only for <script src='strres.js'> and the
|
|
|
|
// like, i.e., out-of-line scripts that are included by several
|
2010-08-12 19:42:36 +00:00
|
|
|
// different XUL documents stored in the cache file.
|
2007-03-12 05:53:33 +00:00
|
|
|
useXULCache = cache->IsEnabled();
|
2002-05-03 03:04:34 +00:00
|
|
|
|
|
|
|
if (useXULCache) {
|
2011-10-29 20:13:31 +00:00
|
|
|
JSScript* newScriptObject =
|
2012-04-24 22:31:28 +00:00
|
|
|
cache->GetScript(mSrcURI);
|
|
|
|
if (newScriptObject)
|
2007-10-29 13:45:07 +00:00
|
|
|
Set(newScriptObject);
|
2002-05-03 03:04:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-24 20:22:23 +00:00
|
|
|
if (!mScriptObject) {
|
2002-05-03 03:04:34 +00:00
|
|
|
if (mSrcURI) {
|
2010-08-12 19:42:36 +00:00
|
|
|
rv = cache->GetInputStream(mSrcURI, getter_AddRefs(objectInput));
|
2015-08-04 20:06:14 +00:00
|
|
|
}
|
|
|
|
// If !mSrcURI, we have an inline script. We shouldn't have
|
2010-08-12 19:42:36 +00:00
|
|
|
// to do anything else in that case, I think.
|
2015-08-04 20:06:14 +00:00
|
|
|
|
2003-01-17 10:04:49 +00:00
|
|
|
// We do reflect errors into rv, but our caller may want to
|
2006-06-13 03:07:47 +00:00
|
|
|
// ignore our return value, because mScriptObject will be null
|
2003-01-17 10:04:49 +00:00
|
|
|
// after any error, and that suffices to cause the script to
|
2002-05-03 03:04:34 +00:00
|
|
|
// be reloaded (from the src= URI, if any) and recompiled.
|
|
|
|
// We're better off slow-loading than bailing out due to a
|
2010-08-12 19:42:36 +00:00
|
|
|
// error.
|
2002-05-03 03:04:34 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2013-08-19 23:24:27 +00:00
|
|
|
rv = Deserialize(objectInput, aProtoDoc, nullptr, nullptr);
|
2002-05-03 03:04:34 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (useXULCache && mSrcURI) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isChrome = false;
|
2002-05-03 03:04:34 +00:00
|
|
|
mSrcURI->SchemeIs("chrome", &isChrome);
|
2016-10-14 08:45:28 +00:00
|
|
|
if (isChrome) {
|
|
|
|
JS::Rooted<JSScript*> script(RootingCx(), GetScriptObject());
|
|
|
|
cache->PutScript(mSrcURI, script);
|
|
|
|
}
|
2002-05-03 03:04:34 +00:00
|
|
|
}
|
2010-08-12 19:42:36 +00:00
|
|
|
cache->FinishInputStream(mSrcURI);
|
2002-05-03 03:04:34 +00:00
|
|
|
} else {
|
2010-08-12 19:42:36 +00:00
|
|
|
// If mSrcURI is not in the cache,
|
2002-05-03 03:04:34 +00:00
|
|
|
// rv will be NS_ERROR_NOT_AVAILABLE and we'll try to
|
2010-08-12 19:42:36 +00:00
|
|
|
// update the cache file to hold a serialization of
|
2002-05-03 03:04:34 +00:00
|
|
|
// this script, once it has finished loading.
|
|
|
|
if (rv != NS_ERROR_NOT_AVAILABLE)
|
2010-08-12 19:42:36 +00:00
|
|
|
cache->AbortCaching();
|
2002-05-03 03:04:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-06-09 10:31:00 +00:00
|
|
|
return rv;
|
2002-05-03 03:04:34 +00:00
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2016-04-26 00:23:21 +00:00
|
|
|
class NotifyOffThreadScriptCompletedRunnable : public Runnable
|
2013-08-15 21:14:43 +00:00
|
|
|
{
|
2016-01-06 21:18:29 +00:00
|
|
|
// An array of all outstanding script receivers. All reference counting of
|
|
|
|
// these objects happens on the main thread. When we return to the main
|
|
|
|
// thread from script compilation we make sure our receiver is still in
|
|
|
|
// this array (still alive) before proceeding. This array is cleared during
|
|
|
|
// shutdown, potentially before all outstanding script compilations have
|
|
|
|
// finished. We do not need to worry about pointer replay here, because
|
|
|
|
// a) we should not be starting script compilation after clearing this
|
|
|
|
// array and b) in all other cases the receiver will still be alive.
|
|
|
|
static StaticAutoPtr<nsTArray<nsCOMPtr<nsIOffThreadScriptReceiver>>> sReceivers;
|
|
|
|
static bool sSetupClearOnShutdown;
|
|
|
|
|
|
|
|
nsIOffThreadScriptReceiver* mReceiver;
|
2013-08-29 15:56:05 +00:00
|
|
|
void *mToken;
|
2013-08-15 21:14:43 +00:00
|
|
|
|
|
|
|
public:
|
2016-01-06 21:18:29 +00:00
|
|
|
NotifyOffThreadScriptCompletedRunnable(nsIOffThreadScriptReceiver* aReceiver,
|
2013-08-29 15:56:05 +00:00
|
|
|
void *aToken)
|
|
|
|
: mReceiver(aReceiver), mToken(aToken)
|
2013-08-15 21:14:43 +00:00
|
|
|
{}
|
|
|
|
|
2016-01-06 21:18:29 +00:00
|
|
|
static void NoteReceiver(nsIOffThreadScriptReceiver* aReceiver) {
|
|
|
|
if (!sSetupClearOnShutdown) {
|
|
|
|
ClearOnShutdown(&sReceivers);
|
|
|
|
sSetupClearOnShutdown = true;
|
|
|
|
sReceivers = new nsTArray<nsCOMPtr<nsIOffThreadScriptReceiver>>();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we ever crash here, it's because we tried to lazy compile script
|
|
|
|
// too late in shutdown.
|
|
|
|
sReceivers->AppendElement(aReceiver);
|
|
|
|
}
|
|
|
|
|
2013-08-15 21:14:43 +00:00
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
};
|
|
|
|
|
2016-01-06 21:18:29 +00:00
|
|
|
StaticAutoPtr<nsTArray<nsCOMPtr<nsIOffThreadScriptReceiver>>> NotifyOffThreadScriptCompletedRunnable::sReceivers;
|
|
|
|
bool NotifyOffThreadScriptCompletedRunnable::sSetupClearOnShutdown = false;
|
|
|
|
|
2013-08-15 21:14:43 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
NotifyOffThreadScriptCompletedRunnable::Run()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-08-11 12:39:23 +00:00
|
|
|
JS::Rooted<JSScript*> script(RootingCx());
|
2013-09-10 23:18:30 +00:00
|
|
|
{
|
2016-03-18 14:48:38 +00:00
|
|
|
AutoJSAPI jsapi;
|
|
|
|
if (!jsapi.Init(xpc::CompilationScope())) {
|
|
|
|
// Now what? I guess we just leak... this should probably never
|
|
|
|
// happen.
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
JSContext* cx = jsapi.cx();
|
2016-07-19 07:19:54 +00:00
|
|
|
script = JS::FinishOffThreadScript(cx, mToken);
|
2013-09-10 23:18:30 +00:00
|
|
|
}
|
2013-08-15 21:14:43 +00:00
|
|
|
|
2016-01-06 21:18:29 +00:00
|
|
|
if (!sReceivers) {
|
|
|
|
// We've already shut down.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto index = sReceivers->IndexOf(mReceiver);
|
|
|
|
MOZ_RELEASE_ASSERT(index != sReceivers->NoIndex);
|
|
|
|
nsCOMPtr<nsIOffThreadScriptReceiver> receiver = (*sReceivers)[index].forget();
|
|
|
|
sReceivers->RemoveElementAt(index);
|
|
|
|
|
|
|
|
return receiver->OnScriptCompileComplete(script, script ? NS_OK : NS_ERROR_FAILURE);
|
2013-08-15 21:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-08-29 15:56:05 +00:00
|
|
|
OffThreadScriptReceiverCallback(void *aToken, void *aCallbackData)
|
2013-08-15 21:14:43 +00:00
|
|
|
{
|
|
|
|
// Be careful not to adjust the refcount on the receiver, as this callback
|
|
|
|
// may be invoked off the main thread.
|
2013-08-29 15:56:05 +00:00
|
|
|
nsIOffThreadScriptReceiver* aReceiver = static_cast<nsIOffThreadScriptReceiver*>(aCallbackData);
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<NotifyOffThreadScriptCompletedRunnable> notify =
|
2016-01-06 21:18:29 +00:00
|
|
|
new NotifyOffThreadScriptCompletedRunnable(aReceiver, aToken);
|
2013-08-15 21:14:43 +00:00
|
|
|
NS_DispatchToMainThread(notify);
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
nsresult
|
2014-04-25 14:11:57 +00:00
|
|
|
nsXULPrototypeScript::Compile(JS::SourceBufferHolder& aSrcBuf,
|
2014-05-27 14:15:00 +00:00
|
|
|
nsIURI* aURI, uint32_t aLineNo,
|
1999-12-17 00:06:28 +00:00
|
|
|
nsIDocument* aDocument,
|
2013-08-15 21:14:43 +00:00
|
|
|
nsIOffThreadScriptReceiver *aOffThreadReceiver /* = nullptr */)
|
1999-11-18 02:25:33 +00:00
|
|
|
{
|
2014-04-20 18:48:14 +00:00
|
|
|
// We'll compile the script in the compilation scope.
|
2016-03-18 14:48:38 +00:00
|
|
|
AutoJSAPI jsapi;
|
|
|
|
if (!jsapi.Init(xpc::CompilationScope())) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
JSContext* cx = jsapi.cx();
|
2000-01-22 22:00:35 +00:00
|
|
|
|
2016-09-19 13:50:22 +00:00
|
|
|
nsresult rv;
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString urlspec;
|
2016-09-19 13:50:22 +00:00
|
|
|
nsContentUtils::GetWrapperSafeScriptFilename(aDocument, aURI, urlspec, &rv);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
1999-12-17 00:06:28 +00:00
|
|
|
|
2000-01-22 22:00:35 +00:00
|
|
|
// Ok, compile it to create a prototype script object!
|
2013-08-08 23:51:34 +00:00
|
|
|
NS_ENSURE_TRUE(JSVersion(mLangVersion) != JSVERSION_UNKNOWN, NS_OK);
|
|
|
|
JS::CompileOptions options(cx);
|
2014-03-12 20:10:02 +00:00
|
|
|
options.setIntroductionType("scriptElement")
|
|
|
|
.setFileAndLine(urlspec.get(), aLineNo)
|
2013-08-08 23:51:34 +00:00
|
|
|
.setVersion(JSVersion(mLangVersion));
|
2012-08-07 17:39:47 +00:00
|
|
|
// If the script was inline, tell the JS parser to save source for
|
|
|
|
// Function.prototype.toSource(). If it's out of line, we retrieve the
|
|
|
|
// source from the files on demand.
|
2014-04-22 21:08:27 +00:00
|
|
|
options.setSourceIsLazy(mOutOfLine);
|
2013-11-11 08:04:41 +00:00
|
|
|
JS::Rooted<JSObject*> scope(cx, JS::CurrentGlobalOrNull(cx));
|
2013-09-09 03:28:48 +00:00
|
|
|
if (scope) {
|
|
|
|
JS::ExposeObjectToActiveJS(scope);
|
|
|
|
}
|
2013-08-15 21:14:43 +00:00
|
|
|
|
2014-04-25 14:11:57 +00:00
|
|
|
if (aOffThreadReceiver && JS::CanCompileOffThread(cx, options, aSrcBuf.length())) {
|
2014-04-11 15:47:43 +00:00
|
|
|
if (!JS::CompileOffThread(cx, options,
|
2014-04-25 14:11:57 +00:00
|
|
|
aSrcBuf.get(), aSrcBuf.length(),
|
2013-08-15 21:14:43 +00:00
|
|
|
OffThreadScriptReceiverCallback,
|
|
|
|
static_cast<void*>(aOffThreadReceiver))) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2016-01-06 21:18:29 +00:00
|
|
|
NotifyOffThreadScriptCompletedRunnable::NoteReceiver(aOffThreadReceiver);
|
2013-08-15 21:14:43 +00:00
|
|
|
} else {
|
2014-06-12 00:38:22 +00:00
|
|
|
JS::Rooted<JSScript*> script(cx);
|
2015-03-19 14:13:34 +00:00
|
|
|
if (!JS::Compile(cx, options, aSrcBuf, &script))
|
2013-08-15 21:14:43 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
Set(script);
|
|
|
|
}
|
2013-08-08 23:51:34 +00:00
|
|
|
return NS_OK;
|
1999-11-18 02:25:33 +00:00
|
|
|
}
|
2002-05-03 03:04:34 +00:00
|
|
|
|
2014-04-25 14:11:57 +00:00
|
|
|
nsresult
|
|
|
|
nsXULPrototypeScript::Compile(const char16_t* aText,
|
|
|
|
int32_t aTextLength,
|
|
|
|
nsIURI* aURI,
|
|
|
|
uint32_t aLineNo,
|
|
|
|
nsIDocument* aDocument,
|
|
|
|
nsIOffThreadScriptReceiver *aOffThreadReceiver /* = nullptr */)
|
|
|
|
{
|
|
|
|
JS::SourceBufferHolder srcBuf(aText, aTextLength,
|
|
|
|
JS::SourceBufferHolder::NoOwnership);
|
2014-05-27 14:15:00 +00:00
|
|
|
return Compile(srcBuf, aURI, aLineNo, aDocument, aOffThreadReceiver);
|
2014-04-25 14:11:57 +00:00
|
|
|
}
|
|
|
|
|
2011-08-11 13:29:50 +00:00
|
|
|
void
|
|
|
|
nsXULPrototypeScript::UnlinkJSObjects()
|
|
|
|
{
|
2012-08-24 20:22:23 +00:00
|
|
|
if (mScriptObject) {
|
|
|
|
mScriptObject = nullptr;
|
2013-08-16 20:10:17 +00:00
|
|
|
mozilla::DropJSObjects(this);
|
2011-08-11 13:29:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-10-29 20:13:31 +00:00
|
|
|
nsXULPrototypeScript::Set(JSScript* aObject)
|
2011-08-11 13:29:50 +00:00
|
|
|
{
|
2012-08-24 20:22:23 +00:00
|
|
|
MOZ_ASSERT(!mScriptObject, "Leaking script object.");
|
2011-08-11 13:29:50 +00:00
|
|
|
if (!aObject) {
|
2012-08-24 20:22:23 +00:00
|
|
|
mScriptObject = nullptr;
|
2011-08-11 13:29:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-20 12:40:06 +00:00
|
|
|
mScriptObject = aObject;
|
2013-08-16 20:10:17 +00:00
|
|
|
mozilla::HoldJSObjects(this);
|
2011-08-11 13:29:50 +00:00
|
|
|
}
|
|
|
|
|
2002-05-03 03:04:34 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsXULPrototypeText
|
|
|
|
//
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypeText::Serialize(nsIObjectOutputStream* aStream,
|
2013-08-19 23:24:27 +00:00
|
|
|
nsXULPrototypeDocument* aProtoDoc,
|
2015-10-18 05:24:48 +00:00
|
|
|
const nsTArray<RefPtr<mozilla::dom::NodeInfo>> *aNodeInfos)
|
2002-05-03 03:04:34 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Write basic prototype data
|
|
|
|
rv = aStream->Write32(mType);
|
|
|
|
|
2012-07-27 14:03:08 +00:00
|
|
|
nsresult tmp = aStream->WriteWStringZ(mValue.get());
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2002-05-03 03:04:34 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypeText::Deserialize(nsIObjectInputStream* aStream,
|
2013-08-19 23:24:27 +00:00
|
|
|
nsXULPrototypeDocument* aProtoDoc,
|
2002-07-23 22:16:45 +00:00
|
|
|
nsIURI* aDocumentURI,
|
2015-10-18 05:24:48 +00:00
|
|
|
const nsTArray<RefPtr<mozilla::dom::NodeInfo>> *aNodeInfos)
|
2002-05-03 03:04:34 +00:00
|
|
|
{
|
2015-08-13 21:24:59 +00:00
|
|
|
nsresult rv = aStream->ReadString(mValue);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2006-11-08 02:25:37 +00:00
|
|
|
}
|
2006-11-11 22:27:00 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsXULPrototypePI
|
|
|
|
//
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypePI::Serialize(nsIObjectOutputStream* aStream,
|
2013-08-19 23:24:27 +00:00
|
|
|
nsXULPrototypeDocument* aProtoDoc,
|
2015-10-18 05:24:48 +00:00
|
|
|
const nsTArray<RefPtr<mozilla::dom::NodeInfo>> *aNodeInfos)
|
2006-11-11 22:27:00 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Write basic prototype data
|
|
|
|
rv = aStream->Write32(mType);
|
|
|
|
|
2012-07-27 14:03:08 +00:00
|
|
|
nsresult tmp = aStream->WriteWStringZ(mTarget.get());
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
|
|
|
tmp = aStream->WriteWStringZ(mData.get());
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2006-11-11 22:27:00 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypePI::Deserialize(nsIObjectInputStream* aStream,
|
2013-08-19 23:24:27 +00:00
|
|
|
nsXULPrototypeDocument* aProtoDoc,
|
2006-11-11 22:27:00 +00:00
|
|
|
nsIURI* aDocumentURI,
|
2015-10-18 05:24:48 +00:00
|
|
|
const nsTArray<RefPtr<mozilla::dom::NodeInfo>> *aNodeInfos)
|
2006-11-11 22:27:00 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = aStream->ReadString(mTarget);
|
2015-08-13 21:24:59 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = aStream->ReadString(mData);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2006-11-11 22:27:00 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|