2014-07-18 19:59:00 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2000-04-05 06:39:51 +04: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 08:32:30 +03:00
|
|
|
*/
|
|
|
|
|
1999-02-02 01:34:51 +03:00
|
|
|
#include "nsCOMPtr.h"
|
1999-02-16 22:30:04 +03:00
|
|
|
#include "nsDOMCID.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2004-04-01 23:44:17 +04:00
|
|
|
#include "nsDOMString.h"
|
2000-12-30 22:22:22 +03:00
|
|
|
#include "nsIDOMEvent.h"
|
1999-01-12 08:32:30 +03:00
|
|
|
#include "nsIAtom.h"
|
2007-10-30 07:03:42 +03:00
|
|
|
#include "nsIBaseWindow.h"
|
1999-02-17 14:09:57 +03:00
|
|
|
#include "nsIDOMAttr.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
1999-01-12 22:41:06 +03:00
|
|
|
#include "nsIDOMElement.h"
|
1999-10-29 05:21:15 +04:00
|
|
|
#include "nsIDOMEventListener.h"
|
1999-01-12 08:32:30 +03:00
|
|
|
#include "nsIDOMNodeList.h"
|
1999-12-06 02:04:22 +03:00
|
|
|
#include "nsIDOMXULCommandDispatcher.h"
|
1999-02-17 14:09:57 +03:00
|
|
|
#include "nsIDOMXULElement.h"
|
2006-09-21 07:35:50 +04:00
|
|
|
#include "nsIDOMElementCSSInlineStyle.h"
|
2002-01-12 04:20:29 +03:00
|
|
|
#include "nsIDOMXULSelectCntrlItemEl.h"
|
1999-01-12 08:32:30 +03:00
|
|
|
#include "nsIDocument.h"
|
2014-05-24 22:51:06 +04:00
|
|
|
#include "nsLayoutStylesheetCache.h"
|
2015-04-28 17:22:38 +03:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2014-03-17 10:56:53 +04:00
|
|
|
#include "mozilla/EventListenerManager.h"
|
2014-04-01 08:09:23 +04:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.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 22:00:39 +04:00
|
|
|
#include "nsFocusManager.h"
|
2004-04-13 01:56:09 +04:00
|
|
|
#include "nsHTMLStyleSheet.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2001-07-31 23:05:34 +04:00
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
1999-12-17 03:06:28 +03:00
|
|
|
#include "nsIPresShell.h"
|
1999-11-18 05:25:33 +03:00
|
|
|
#include "nsIPrincipal.h"
|
1999-01-20 04:42:13 +03:00
|
|
|
#include "nsIRDFCompositeDataSource.h"
|
1999-01-12 08:32:30 +03:00
|
|
|
#include "nsIRDFNode.h"
|
|
|
|
#include "nsIRDFService.h"
|
1999-12-17 03:06:28 +03:00
|
|
|
#include "nsIScriptContext.h"
|
2014-07-18 19:59:00 +04:00
|
|
|
#include "nsIScriptError.h"
|
2013-08-09 03:51:34 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
1999-01-12 08:32:30 +03:00
|
|
|
#include "nsIServiceManager.h"
|
2011-03-11 05:48:57 +03:00
|
|
|
#include "mozilla/css/StyleRule.h"
|
1999-12-17 03:06:28 +03:00
|
|
|
#include "nsIStyleSheet.h"
|
1999-03-05 03:01:26 +03:00
|
|
|
#include "nsIURL.h"
|
2013-01-05 07:12:24 +04:00
|
|
|
#include "nsViewManager.h"
|
2002-02-20 06:33:52 +03:00
|
|
|
#include "nsIWidget.h"
|
1999-10-06 01:13:55 +04:00
|
|
|
#include "nsIXULDocument.h"
|
2000-05-06 03:39:59 +04:00
|
|
|
#include "nsIXULTemplateBuilder.h"
|
1999-12-17 03:06:28 +03:00
|
|
|
#include "nsLayoutCID.h"
|
2001-02-20 00:50:04 +03:00
|
|
|
#include "nsContentCID.h"
|
2014-03-05 04:37:43 +04:00
|
|
|
#include "mozilla/dom/Event.h"
|
1999-12-17 03:06:28 +03:00
|
|
|
#include "nsRDFCID.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsXPIDLString.h"
|
1999-12-06 02:04:22 +03:00
|
|
|
#include "nsXULControllers.h"
|
2000-05-30 12:11:35 +04:00
|
|
|
#include "nsIBoxObject.h"
|
|
|
|
#include "nsPIBoxObject.h"
|
2013-03-26 19:31:53 +04:00
|
|
|
#include "XULDocument.h"
|
2007-07-04 19:49:38 +04:00
|
|
|
#include "nsXULPopupListener.h"
|
2001-10-24 04:01:09 +04:00
|
|
|
#include "nsRuleWalker.h"
|
2000-06-14 12:12:32 +04:00
|
|
|
#include "nsIDOMCSSStyleDeclaration.h"
|
2010-03-02 23:59:32 +03:00
|
|
|
#include "nsCSSParser.h"
|
2014-10-15 00:15:21 +04: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 20:46:42 +04:00
|
|
|
#include "nsContentUtils.h"
|
2003-02-01 02:21:22 +03:00
|
|
|
#include "nsContentList.h"
|
2014-02-27 14:51:15 +04:00
|
|
|
#include "mozilla/InternalMutationEvent.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2000-11-27 10:55:20 +03:00
|
|
|
#include "nsIDOMMutationEvent.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2013-08-09 03:51:34 +04:00
|
|
|
#include "nsJSPrincipals.h"
|
2004-02-10 12:08:06 +03:00
|
|
|
#include "nsDOMAttributeMap.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2005-01-24 13:45:00 +03:00
|
|
|
#include "nsXULContentUtils.h"
|
2006-07-02 11:23:10 +04:00
|
|
|
#include "nsNodeUtils.h"
|
2008-03-21 14:18:10 +03:00
|
|
|
#include "nsFrameLoader.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
1999-03-29 23:52:54 +04:00
|
|
|
#include "rdf.h"
|
1999-10-14 14:58:25 +04:00
|
|
|
#include "nsIControllers.h"
|
2012-02-14 06:00:56 +04:00
|
|
|
#include "nsAttrValueOrString.h"
|
2012-09-30 20:40:24 +04:00
|
|
|
#include "nsAttrValueInlines.h"
|
2012-06-19 06:30:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-23 03:23:30 +04:00
|
|
|
#include "nsIController.h"
|
2015-04-15 19:47:03 +03:00
|
|
|
#include "nsQueryObject.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
1999-06-09 03:04:24 +04:00
|
|
|
|
1999-08-21 13:08:12 +04:00
|
|
|
// The XUL doc interface
|
|
|
|
#include "nsIDOMXULDocument.h"
|
|
|
|
|
2001-10-23 00:48:52 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsIFrame.h"
|
2004-06-25 16:26:02 +04:00
|
|
|
#include "nsNodeInfoManager.h"
|
2005-02-26 01:07:01 +03:00
|
|
|
#include "nsXBLBinding.h"
|
2014-03-18 08:48:21 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2008-04-11 21:29:06 +04:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2008-06-05 00:23:37 +04:00
|
|
|
#include "nsIDOMXULCommandEvent.h"
|
2008-10-08 15:41:52 +04:00
|
|
|
#include "nsCCUncollectableMarker.h"
|
2012-10-16 15:51:00 +04:00
|
|
|
#include "nsICSSDeclaration.h"
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2013-01-29 21:51:55 +04:00
|
|
|
#include "mozilla/dom/XULElementBinding.h"
|
2014-10-15 00:15:21 +04:00
|
|
|
#include "mozilla/dom/BoxObject.h"
|
2013-01-29 21:51:55 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-03-26 19:31:53 +04:00
|
|
|
using namespace mozilla::dom;
|
2011-03-11 05:48:57 +03:00
|
|
|
|
1999-12-03 06:40:30 +03:00
|
|
|
#ifdef XUL_PROTOTYPE_ATTRIBUTE_METERING
|
2012-08-22 19:56:38 +04: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 06:40:30 +03:00
|
|
|
#endif
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsXULElementTearoff final : public nsIDOMElementCSSInlineStyle,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIFrameLoaderOwner
|
2006-09-21 07:35:50 +04:00
|
|
|
{
|
2014-06-25 06:09:15 +04:00
|
|
|
~nsXULElementTearoff() {}
|
|
|
|
|
2006-09-22 10:19:14 +04:00
|
|
|
public:
|
2008-03-21 14:18:10 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULElementTearoff,
|
|
|
|
nsIDOMElementCSSInlineStyle)
|
2006-09-21 07:35:50 +04:00
|
|
|
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit nsXULElementTearoff(nsXULElement* aElement)
|
2006-09-21 07:35:50 +04:00
|
|
|
: mElement(aElement)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle) override
|
2010-08-06 01:59:36 +04:00
|
|
|
{
|
2013-01-11 12:42:59 +04:00
|
|
|
nsXULElement* element = static_cast<nsXULElement*>(mElement.get());
|
|
|
|
NS_ADDREF(*aStyle = element->Style());
|
2010-08-06 01:59:36 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-12-09 21:23:19 +04:00
|
|
|
NS_FORWARD_NSIFRAMELOADEROWNER(static_cast<nsXULElement*>(mElement.get())->)
|
2006-09-21 07:35:50 +04:00
|
|
|
private:
|
2008-03-21 14:18:10 +03:00
|
|
|
nsCOMPtr<nsIDOMXULElement> mElement;
|
2006-09-21 07:35:50 +04:00
|
|
|
};
|
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION(nsXULElementTearoff, mElement)
|
2008-03-21 14:18:10 +03:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXULElementTearoff)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXULElementTearoff)
|
2006-09-21 07:35:50 +04:00
|
|
|
|
2008-03-21 14:18:10 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULElementTearoff)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIFrameLoaderOwner)
|
2006-09-21 07:35:50 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMElementCSSInlineStyle)
|
|
|
|
NS_INTERFACE_MAP_END_AGGREGATED(mElement)
|
|
|
|
|
1999-10-29 05:21:15 +04:00
|
|
|
//----------------------------------------------------------------------
|
1999-10-19 02:08:15 +04:00
|
|
|
// nsXULElement
|
2001-10-23 00:48:52 +04:00
|
|
|
//
|
1999-10-07 05:51:30 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
nsXULElement::nsXULElement(already_AddRefed<mozilla::dom::NodeInfo> aNodeInfo)
|
2010-02-24 07:37:46 +03:00
|
|
|
: nsStyledElement(aNodeInfo),
|
2012-07-30 18:20:58 +04:00
|
|
|
mBindingParent(nullptr)
|
1999-01-12 08:32:30 +03:00
|
|
|
{
|
1999-12-07 05:06:10 +03:00
|
|
|
XUL_PROTOTYPE_ATTRIBUTE_METER(gNumElements);
|
2011-06-01 05:46:57 +04: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 22:55:32 +04:00
|
|
|
}
|
1999-02-02 01:34:51 +03:00
|
|
|
|
2014-07-09 01:23:16 +04:00
|
|
|
nsXULElement::~nsXULElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-04-08 06:29:49 +04:00
|
|
|
nsXULElement::nsXULSlots::nsXULSlots()
|
|
|
|
: nsXULElement::nsDOMSlots()
|
2006-09-02 17:21:05 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXULElement::nsXULSlots::~nsXULSlots()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mControllers); // Forces release
|
2008-03-21 14:18:10 +03:00
|
|
|
if (mFrameLoader) {
|
|
|
|
mFrameLoader->Destroy();
|
|
|
|
}
|
2006-09-02 17:21:05 +04:00
|
|
|
}
|
|
|
|
|
2011-08-28 18:07:24 +04:00
|
|
|
void
|
|
|
|
nsXULElement::nsXULSlots::Traverse(nsCycleCollectionTraversalCallback &cb)
|
|
|
|
{
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mFrameLoader");
|
|
|
|
cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIFrameLoader*, mFrameLoader));
|
|
|
|
}
|
|
|
|
|
2006-09-02 17:21:05 +04:00
|
|
|
nsINode::nsSlots*
|
|
|
|
nsXULElement::CreateSlots()
|
|
|
|
{
|
2011-04-08 06:29:49 +04:00
|
|
|
return new nsXULSlots();
|
2006-09-02 17:21:05 +04:00
|
|
|
}
|
|
|
|
|
2013-02-05 03:22:51 +04:00
|
|
|
void
|
|
|
|
nsXULElement::MaybeUpdatePrivateLifetime()
|
|
|
|
{
|
|
|
|
if (AttrValueIs(kNameSpaceID_None, nsGkAtoms::windowtype,
|
|
|
|
NS_LITERAL_STRING("navigator:browser"),
|
|
|
|
eCaseMatters)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPIDOMWindow* win = OwnerDoc()->GetWindow();
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = win ? win->GetDocShell() : nullptr;
|
|
|
|
if (docShell) {
|
|
|
|
docShell->SetAffectPrivateSessionLifetime(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-11 21:15:08 +04:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<nsXULElement>
|
2014-06-20 06:01:40 +04:00
|
|
|
nsXULElement::Create(nsXULPrototypeElement* aPrototype, mozilla::dom::NodeInfo *aNodeInfo,
|
2013-02-05 03:22:51 +04:00
|
|
|
bool aIsScriptable, bool aIsRoot)
|
2005-09-11 21:15:08 +04:00
|
|
|
{
|
2014-06-20 06:01:40 +04:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
|
2013-04-22 15:15:59 +04:00
|
|
|
nsRefPtr<nsXULElement> element = new nsXULElement(ni.forget());
|
2005-09-11 21:15:08 +04:00
|
|
|
if (element) {
|
2007-09-18 12:38:24 +04:00
|
|
|
if (aPrototype->mHasIdAttribute) {
|
2011-04-08 06:29:50 +04:00
|
|
|
element->SetHasID();
|
2007-09-18 12:38:24 +04:00
|
|
|
}
|
|
|
|
if (aPrototype->mHasClassAttribute) {
|
|
|
|
element->SetFlags(NODE_MAY_HAVE_CLASS);
|
|
|
|
}
|
|
|
|
if (aPrototype->mHasStyleAttribute) {
|
2011-04-08 06:29:50 +04:00
|
|
|
element->SetMayHaveStyle();
|
2007-09-18 12:38:24 +04:00
|
|
|
}
|
2005-09-11 21:15:08 +04:00
|
|
|
|
2012-07-14 19:28:54 +04:00
|
|
|
element->MakeHeavyweight(aPrototype);
|
2005-09-11 21:15:08 +04: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 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < aPrototype->mNumAttributes; ++i) {
|
2005-09-11 21:15:08 +04:00
|
|
|
element->AddListenerFor(aPrototype->mAttributes[i].mName,
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
2005-09-11 21:15:08 +04:00
|
|
|
}
|
|
|
|
}
|
2013-02-05 03:22:51 +04: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 21:15:08 +04:00
|
|
|
}
|
|
|
|
|
2013-04-22 15:15:59 +04:00
|
|
|
return element.forget();
|
2005-09-11 21:15:08 +04:00
|
|
|
}
|
2005-09-11 19:42:31 +04:00
|
|
|
|
2005-01-14 22:30:55 +03:00
|
|
|
nsresult
|
|
|
|
nsXULElement::Create(nsXULPrototypeElement* aPrototype,
|
|
|
|
nsIDocument* aDocument,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsScriptable,
|
2013-02-05 03:22:51 +04:00
|
|
|
bool aIsRoot,
|
2010-04-30 17:12:05 +04:00
|
|
|
Element** aResult)
|
1999-01-12 08:32:30 +03:00
|
|
|
{
|
2005-01-14 22:30:55 +03:00
|
|
|
// Create an nsXULElement from a prototype
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(aPrototype != nullptr, "null ptr");
|
2005-01-14 22:30:55 +03:00
|
|
|
if (! aPrototype)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-02-18 01:32:40 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(aResult != nullptr, "null ptr");
|
2005-01-14 22:30:55 +03:00
|
|
|
if (! aResult)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-02-18 01:32:40 +03:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2005-01-14 22:30:55 +03:00
|
|
|
if (aDocument) {
|
2014-06-20 06:01:40 +04:00
|
|
|
mozilla::dom::NodeInfo* ni = aPrototype->mNodeInfo;
|
2011-06-14 11:56:49 +04:00
|
|
|
nodeInfo = aDocument->NodeInfoManager()->
|
|
|
|
GetNodeInfo(ni->NameAtom(), ni->GetPrefixAtom(), ni->NamespaceID(),
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2005-01-14 22:30:55 +03:00
|
|
|
}
|
|
|
|
else {
|
2005-09-11 21:15:08 +04:00
|
|
|
nodeInfo = aPrototype->mNodeInfo;
|
2005-01-14 22:30:55 +03:00
|
|
|
}
|
1999-01-12 08:32:30 +03:00
|
|
|
|
2005-09-11 21:15:08 +04:00
|
|
|
nsRefPtr<nsXULElement> element = Create(aPrototype, nodeInfo,
|
2013-02-05 03:22:51 +04:00
|
|
|
aIsScriptable, aIsRoot);
|
2005-09-11 21:15:08 +04:00
|
|
|
if (!element) {
|
2005-01-14 22:30:55 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2005-09-11 21:15:08 +04:00
|
|
|
}
|
2000-05-16 00:31:55 +04:00
|
|
|
|
2012-07-14 19:28:54 +04:00
|
|
|
element.forget(aResult);
|
2005-09-11 21:15:08 +04:00
|
|
|
|
2005-01-14 22:30:55 +03:00
|
|
|
return NS_OK;
|
2000-05-16 00:31:55 +04:00
|
|
|
}
|
|
|
|
|
2005-01-14 22:30:55 +03:00
|
|
|
nsresult
|
2014-06-20 06:01:40 +04:00
|
|
|
NS_NewXULElement(Element** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
2000-05-16 00:31:55 +04:00
|
|
|
{
|
2014-06-20 06:01:40 +04:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
|
2014-03-15 23:00:15 +04:00
|
|
|
|
|
|
|
NS_PRECONDITION(ni, "need nodeinfo for non-proto Create");
|
2000-05-16 00:31:55 +04:00
|
|
|
|
2014-03-15 23:00:15 +04:00
|
|
|
nsIDocument* doc = ni->GetDocument();
|
2010-08-20 03:12:46 +04:00
|
|
|
if (doc && !doc->AllowXULXBL()) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2000-05-16 00:31:55 +04:00
|
|
|
|
2014-03-15 23:00:15 +04:00
|
|
|
NS_ADDREF(*aResult = new nsXULElement(ni.forget()));
|
2000-05-16 00:31:55 +04:00
|
|
|
|
2010-08-20 05:41:58 +04:00
|
|
|
return NS_OK;
|
2010-08-20 03:12:46 +04:00
|
|
|
}
|
|
|
|
|
2010-08-20 03:12:46 +04:00
|
|
|
void
|
2014-03-15 23:00:17 +04:00
|
|
|
NS_TrustedNewXULElement(nsIContent** aResult,
|
2014-06-20 06:01:40 +04:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
2010-08-20 03:12:46 +04:00
|
|
|
{
|
2014-06-20 06:01:40 +04:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
|
2014-03-15 23:00:15 +04:00
|
|
|
NS_PRECONDITION(ni, "need nodeinfo for non-proto Create");
|
2010-08-20 03:12:46 +04:00
|
|
|
|
|
|
|
// Create an nsXULElement with the specified namespace and tag.
|
2014-03-15 23:00:15 +04:00
|
|
|
NS_ADDREF(*aResult = new nsXULElement(ni.forget()));
|
2010-08-20 03:12:46 +04:00
|
|
|
}
|
|
|
|
|
2005-01-14 22:30:55 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports interface
|
2004-02-10 12:08:06 +03:00
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULElement)
|
|
|
|
|
2007-05-24 18:10:02 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXULElement,
|
2010-02-24 07:37:46 +03:00
|
|
|
nsStyledElement)
|
2011-02-16 15:07:47 +03:00
|
|
|
{
|
|
|
|
nsXULSlots* slots = static_cast<nsXULSlots*>(tmp->GetExistingSlots());
|
|
|
|
if (slots) {
|
2011-08-28 18:07:24 +04:00
|
|
|
slots->Traverse(cb);
|
2011-02-16 15:07:47 +03:00
|
|
|
}
|
|
|
|
}
|
2007-05-24 18:10:02 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2014-05-30 11:36:53 +04: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 07:37:46 +03:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsXULElement, nsStyledElement)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsXULElement, nsStyledElement)
|
2004-02-10 12:08:06 +03:00
|
|
|
|
2008-11-03 13:31:47 +03:00
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsXULElement)
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(nsXULElement, nsIDOMNode, nsIDOMElement,
|
|
|
|
nsIDOMXULElement)
|
2008-11-03 13:31:47 +03:00
|
|
|
NS_ELEMENT_INTERFACE_TABLE_TO_MAP_SEGUE
|
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMElementCSSInlineStyle,
|
|
|
|
new nsXULElementTearoff(this))
|
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIFrameLoaderOwner,
|
|
|
|
new nsXULElementTearoff(this))
|
2013-08-08 00:23:08 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsStyledElement)
|
2000-05-16 00:31:55 +04:00
|
|
|
|
2005-01-14 22:30:55 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMNode interface
|
|
|
|
|
2005-09-11 21:15:08 +04:00
|
|
|
nsresult
|
2014-06-20 06:01:40 +04:00
|
|
|
nsXULElement::Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const
|
2000-05-16 00:31:55 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aResult = nullptr;
|
2000-05-16 00:31:55 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
|
2012-07-14 19:28:54 +04:00
|
|
|
nsRefPtr<nsXULElement> element = new nsXULElement(ni.forget());
|
2003-01-31 17:28:50 +03:00
|
|
|
|
2005-01-14 22:30:55 +03: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-16 00:31:55 +04:00
|
|
|
|
2005-01-14 22:30:55 +03:00
|
|
|
// Note that we're _not_ copying mControllers.
|
2000-05-16 00:31:55 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = mAttrsAndChildren.AttrCount();
|
2012-07-19 13:21:40 +04:00
|
|
|
nsresult rv = NS_OK;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2012-07-19 13:21:40 +04:00
|
|
|
const nsAttrName* originalName = mAttrsAndChildren.AttrNameAt(i);
|
|
|
|
const nsAttrValue* originalValue = mAttrsAndChildren.AttrAt(i);
|
|
|
|
nsAttrValue attrValue;
|
|
|
|
|
|
|
|
// Style rules need to be cloned.
|
|
|
|
if (originalValue->Type() == nsAttrValue::eCSSStyleRule) {
|
|
|
|
nsRefPtr<css::Rule> ruleClone =
|
|
|
|
originalValue->GetCSSStyleRuleValue()->Clone();
|
|
|
|
|
|
|
|
nsString stringValue;
|
|
|
|
originalValue->ToString(stringValue);
|
|
|
|
|
|
|
|
nsRefPtr<css::StyleRule> styleRule = do_QueryObject(ruleClone);
|
|
|
|
attrValue.SetTo(styleRule, &stringValue);
|
|
|
|
} else {
|
|
|
|
attrValue.SetTo(*originalValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (originalName->IsAtom()) {
|
|
|
|
rv = element->mAttrsAndChildren.SetAndTakeAttr(originalName->Atom(),
|
|
|
|
attrValue);
|
|
|
|
} else {
|
|
|
|
rv = element->mAttrsAndChildren.SetAndTakeAttr(originalName->NodeInfo(),
|
|
|
|
attrValue);
|
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
element->AddListenerFor(*originalName, true);
|
2012-07-21 01:55:19 +04:00
|
|
|
if (originalName->Equals(nsGkAtoms::id) &&
|
|
|
|
!originalValue->IsEmptyString()) {
|
2012-07-19 13:21:40 +04:00
|
|
|
element->SetHasID();
|
|
|
|
}
|
|
|
|
if (originalName->Equals(nsGkAtoms::_class)) {
|
|
|
|
element->SetFlags(NODE_MAY_HAVE_CLASS);
|
|
|
|
}
|
|
|
|
if (originalName->Equals(nsGkAtoms::style)) {
|
|
|
|
element->SetMayHaveStyle();
|
|
|
|
}
|
2000-05-16 00:31:55 +04:00
|
|
|
}
|
|
|
|
|
2012-07-19 13:21:40 +04:00
|
|
|
element.forget(aResult);
|
2005-09-11 21:15:08 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2005-01-14 22:30:55 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1999-02-23 05:40:51 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:46:13 +03:00
|
|
|
nsXULElement::GetElementsByAttribute(const nsAString& aAttribute,
|
|
|
|
const nsAString& aValue,
|
2000-08-23 21:27:06 +04:00
|
|
|
nsIDOMNodeList** aReturn)
|
2013-01-29 21:51:55 +04:00
|
|
|
{
|
2014-03-15 23:00:15 +04:00
|
|
|
*aReturn = GetElementsByAttribute(aAttribute, aValue).take();
|
2013-01-29 21:51:55 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsINodeList>
|
|
|
|
nsXULElement::GetElementsByAttribute(const nsAString& aAttribute,
|
|
|
|
const nsAString& aValue)
|
1999-02-23 05:40:51 +03:00
|
|
|
{
|
2004-04-15 05:51:32 +04:00
|
|
|
nsCOMPtr<nsIAtom> attrAtom(do_GetAtom(aAttribute));
|
2007-02-01 18:14:00 +03:00
|
|
|
void* attrValue = new nsString(aValue);
|
2013-01-29 21:51:55 +04:00
|
|
|
nsRefPtr<nsContentList> list =
|
2006-07-02 11:23:10 +04:00
|
|
|
new nsContentList(this,
|
2013-03-26 19:31:53 +04:00
|
|
|
XULDocument::MatchAttribute,
|
2007-02-01 18:14:00 +03:00
|
|
|
nsContentUtils::DestroyMatchString,
|
|
|
|
attrValue,
|
2011-10-17 18:59:28 +04:00
|
|
|
true,
|
2004-04-15 05:51:32 +04:00
|
|
|
attrAtom,
|
2006-06-22 06:37:06 +04:00
|
|
|
kNameSpaceID_Unknown);
|
2013-01-29 21:51:55 +04:00
|
|
|
return list.forget();
|
1999-02-23 05:40:51 +03:00
|
|
|
}
|
|
|
|
|
2006-09-14 08:29:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::GetElementsByAttributeNS(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsIDOMNodeList** aReturn)
|
2013-01-29 21:51:55 +04:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
*aReturn =
|
2014-03-15 23:00:15 +04:00
|
|
|
GetElementsByAttributeNS(aNamespaceURI, aAttribute, aValue, rv).take();
|
2015-04-27 16:18:51 +03:00
|
|
|
return rv.StealNSResult();
|
2013-01-29 21:51:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsINodeList>
|
|
|
|
nsXULElement::GetElementsByAttributeNS(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
ErrorResult& rv)
|
2006-09-14 08:29:02 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> attrAtom(do_GetAtom(aAttribute));
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nameSpaceId = kNameSpaceID_Wildcard;
|
2006-09-14 08:29:02 +04:00
|
|
|
if (!aNamespaceURI.EqualsLiteral("*")) {
|
2013-01-29 21:51:55 +04:00
|
|
|
rv =
|
2006-09-14 08:29:02 +04:00
|
|
|
nsContentUtils::NameSpaceManager()->RegisterNameSpace(aNamespaceURI,
|
|
|
|
nameSpaceId);
|
2013-01-29 21:51:55 +04:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2006-09-14 08:29:02 +04:00
|
|
|
}
|
|
|
|
|
2007-02-01 18:14:00 +03:00
|
|
|
void* attrValue = new nsString(aValue);
|
2013-01-29 21:51:55 +04:00
|
|
|
nsRefPtr<nsContentList> list =
|
2006-09-14 08:29:02 +04:00
|
|
|
new nsContentList(this,
|
2013-03-26 19:31:53 +04:00
|
|
|
XULDocument::MatchAttribute,
|
2007-02-01 18:14:00 +03:00
|
|
|
nsContentUtils::DestroyMatchString,
|
|
|
|
attrValue,
|
2011-10-17 18:59:28 +04:00
|
|
|
true,
|
2006-09-14 08:29:02 +04:00
|
|
|
attrAtom,
|
|
|
|
nameSpaceId);
|
|
|
|
|
2013-01-29 21:51:55 +04:00
|
|
|
return list.forget();
|
2006-09-14 08:29:02 +04:00
|
|
|
}
|
|
|
|
|
2014-03-17 10:56:53 +04:00
|
|
|
EventListenerManager*
|
2011-09-29 10:19:26 +04:00
|
|
|
nsXULElement::GetEventListenerManagerForAttr(nsIAtom* aAttrName, bool* aDefer)
|
1999-10-29 05:21:15 +04:00
|
|
|
{
|
2014-10-03 16:29:48 +04:00
|
|
|
// XXXbz sXBL/XBL2 issue: should we instead use GetComposedDoc()
|
2005-10-28 06:59:38 +04:00
|
|
|
// here, override BindToTree for those classes and munge event
|
|
|
|
// listeners there?
|
2011-10-18 14:53:36 +04:00
|
|
|
nsIDocument* doc = OwnerDoc();
|
1999-10-29 05:21:15 +04:00
|
|
|
|
2008-05-08 08:57:21 +04:00
|
|
|
nsPIDOMWindow *window;
|
2010-04-30 17:12:05 +04:00
|
|
|
Element *root = doc->GetRootElement();
|
2008-05-08 08:57:21 +04:00
|
|
|
if ((!root || root == this) && !mNodeInfo->Equals(nsGkAtoms::overlay) &&
|
2013-04-29 19:34:16 +04:00
|
|
|
(window = doc->GetInnerWindow())) {
|
2005-11-29 05:06:23 +03:00
|
|
|
|
2013-04-06 04:44:15 +04:00
|
|
|
nsCOMPtr<EventTarget> piTarget = do_QueryInterface(window);
|
1999-10-29 05:21:15 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*aDefer = false;
|
2013-10-23 03:32:04 +04:00
|
|
|
return piTarget->GetOrCreateListenerManager();
|
1999-10-29 05:21:15 +04:00
|
|
|
}
|
|
|
|
|
2011-09-28 19:54:50 +04:00
|
|
|
return nsStyledElement::GetEventListenerManagerForAttr(aAttrName, aDefer);
|
1999-10-29 05:21:15 +04:00
|
|
|
}
|
|
|
|
|
2010-04-21 18:53:42 +04:00
|
|
|
// returns true if the element is not a list
|
2014-06-20 06:01:40 +04:00
|
|
|
static bool IsNonList(mozilla::dom::NodeInfo* aNodeInfo)
|
2010-04-21 18:53:42 +04:00
|
|
|
{
|
|
|
|
return !aNodeInfo->Equals(nsGkAtoms::tree) &&
|
|
|
|
!aNodeInfo->Equals(nsGkAtoms::listbox) &&
|
|
|
|
!aNodeInfo->Equals(nsGkAtoms::richlistbox);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-11-20 02:21:16 +04:00
|
|
|
nsXULElement::IsFocusableInternal(int32_t *aTabIndex, bool aWithMouse)
|
2004-07-25 01:12:43 +04:00
|
|
|
{
|
2008-03-07 19:33:38 +03: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 19:19:05 +03:00
|
|
|
* property, where -1 means no and 0 means yes.
|
2008-03-07 19:33:38 +03: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 10:19:26 +04:00
|
|
|
bool shouldFocus = false;
|
2008-03-07 19:33:38 +03:00
|
|
|
|
2010-04-21 18:53:42 +04:00
|
|
|
#ifdef XP_MACOSX
|
2013-08-23 23:17:13 +04: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 &&
|
|
|
|
IsNonList(mNodeInfo) &&
|
2014-04-01 08:09:23 +04:00
|
|
|
!EventStateManager::IsRemoteTarget(this))
|
2013-08-23 23:17:13 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2013-08-23 23:17:13 +04:00
|
|
|
}
|
2010-04-21 18:53:42 +04:00
|
|
|
#endif
|
|
|
|
|
2011-08-31 01:45:31 +04:00
|
|
|
nsCOMPtr<nsIDOMXULControlElement> xulControl = do_QueryObject(this);
|
2004-07-25 01:12:43 +04:00
|
|
|
if (xulControl) {
|
2008-03-07 19:33:38 +03:00
|
|
|
// a disabled element cannot be focused and is not part of the tab order
|
2011-09-29 10:19:26 +04:00
|
|
|
bool disabled;
|
2004-07-25 01:12:43 +04:00
|
|
|
xulControl->GetDisabled(&disabled);
|
|
|
|
if (disabled) {
|
2008-03-07 19:33:38 +03:00
|
|
|
if (aTabIndex)
|
|
|
|
*aTabIndex = -1;
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2004-07-25 01:12:43 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
shouldFocus = true;
|
2008-03-07 19:33:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aTabIndex) {
|
2008-03-27 19:19:05 +03: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 19:56:38 +04:00
|
|
|
int32_t tabIndex = 0;
|
2008-03-27 19:19:05 +03:00
|
|
|
xulControl->GetTabIndex(&tabIndex);
|
|
|
|
shouldFocus = *aTabIndex >= 0 || tabIndex >= 0;
|
|
|
|
*aTabIndex = tabIndex;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// otherwise, if there is no tabindex attribute, just use the value of
|
2009-11-20 15:09:33 +03:00
|
|
|
// *aTabIndex to indicate focusability. Reset any supplied tabindex to 0.
|
2008-03-27 19:19:05 +03:00
|
|
|
shouldFocus = *aTabIndex >= 0;
|
2009-11-20 15:09:33 +03:00
|
|
|
if (shouldFocus)
|
|
|
|
*aTabIndex = 0;
|
2008-03-27 19:19:05 +03:00
|
|
|
}
|
2008-03-13 17:07:23 +03: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 18:53:42 +04:00
|
|
|
if (IsNonList(mNodeInfo))
|
2008-03-13 17:07:23 +03:00
|
|
|
*aTabIndex = -1;
|
|
|
|
}
|
2008-03-07 19:33:38 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
shouldFocus = *aTabIndex >= 0;
|
2004-07-25 01:12:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-07 19:33:38 +03:00
|
|
|
return shouldFocus;
|
2004-07-25 01:12:43 +04:00
|
|
|
}
|
|
|
|
|
2007-02-13 18:02:57 +03:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsXULElement::PerformAccesskey(bool aKeyCausesActivation,
|
|
|
|
bool aIsTrustedEvent)
|
2007-02-13 18:02:57 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content(this);
|
|
|
|
|
2015-03-03 14:09:00 +03:00
|
|
|
if (IsXULElement(nsGkAtoms::label)) {
|
2007-02-13 18:02:57 +03:00
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
|
|
|
|
nsAutoString control;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::control, control);
|
|
|
|
if (!control.IsEmpty()) {
|
2014-10-03 16:29:48 +04:00
|
|
|
//XXXsmaug Should we use ShadowRoot::GetElementById in case
|
|
|
|
// content is in Shadow DOM?
|
2007-02-13 18:02:57 +03:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDocument =
|
2014-10-03 16:29:48 +04:00
|
|
|
do_QueryInterface(content->GetUncomposedDoc());
|
2007-02-13 18:02:57 +03: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);
|
|
|
|
|
|
|
|
if (!content)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-25 00:20:05 +03:00
|
|
|
nsIFrame* frame = content->GetPrimaryFrame();
|
2011-10-27 03:57:55 +04:00
|
|
|
if (!frame || !frame->IsVisibleConsideringAncestors())
|
2007-02-13 18:02:57 +03:00
|
|
|
return;
|
|
|
|
|
2010-08-28 01:26:24 +04:00
|
|
|
nsXULElement* elm = FromContent(content);
|
2007-11-12 01:44:48 +03:00
|
|
|
if (elm) {
|
|
|
|
// Define behavior for each type of XUL element.
|
2015-03-03 14:09:00 +03: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 22:00:39 +04:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
2009-06-15 19:08:41 +04:00
|
|
|
if (fm) {
|
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
// for radio buttons, focus the radiogroup instead
|
2015-03-03 14:09:00 +03:00
|
|
|
if (content->IsXULElement(nsGkAtoms::radio)) {
|
2010-08-28 01:26:24 +04:00
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> controlItem(do_QueryInterface(content));
|
2009-06-15 19:08:41 +04:00
|
|
|
if (controlItem) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool disabled;
|
2009-06-15 19:08:41 +04:00
|
|
|
controlItem->GetDisabled(&disabled);
|
|
|
|
if (!disabled) {
|
|
|
|
nsCOMPtr<nsIDOMXULSelectControlElement> selectControl;
|
|
|
|
controlItem->GetControl(getter_AddRefs(selectControl));
|
|
|
|
element = do_QueryInterface(selectControl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
element = do_QueryInterface(content);
|
|
|
|
}
|
|
|
|
if (element)
|
|
|
|
fm->SetFocus(element, nsIFocusManager::FLAG_BYKEY);
|
|
|
|
}
|
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 22:00:39 +04:00
|
|
|
}
|
2015-03-03 14:09:00 +03:00
|
|
|
if (aKeyCausesActivation &&
|
|
|
|
!content->IsAnyOfXULElements(nsGkAtoms::textbox, nsGkAtoms::menulist)) {
|
2011-08-26 11:43:56 +04:00
|
|
|
elm->ClickWithInputSource(nsIDOMMouseEvent::MOZ_SOURCE_KEYBOARD);
|
2010-04-06 16:59:24 +04:00
|
|
|
}
|
2007-11-12 01:44:48 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
content->PerformAccesskey(aKeyCausesActivation, aIsTrustedEvent);
|
2007-02-13 18:02:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-03 06:40:30 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2004-02-10 12:08:06 +03:00
|
|
|
void
|
|
|
|
nsXULElement::AddListenerFor(const nsAttrName& aName,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aCompileEventHandlers)
|
1999-01-12 08:32:30 +03:00
|
|
|
{
|
2001-10-23 00:48:52 +04: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 12:08:06 +03:00
|
|
|
// Eventlistenener-attributes are always in the null namespace
|
|
|
|
if (aName.IsAtom()) {
|
|
|
|
nsIAtom *attr = aName.Atom();
|
|
|
|
MaybeAddPopupListener(attr);
|
2007-04-02 21:17:36 +04:00
|
|
|
if (aCompileEventHandlers &&
|
|
|
|
nsContentUtils::IsEventAttributeName(attr, EventNameType_XUL)) {
|
2003-09-20 10:09:10 +04:00
|
|
|
nsAutoString value;
|
2004-02-10 12:08:06 +03:00
|
|
|
GetAttr(kNameSpaceID_None, attr, value);
|
2012-08-30 20:25:10 +04:00
|
|
|
SetEventHandler(attr, value, true);
|
1999-01-12 08:32:30 +03:00
|
|
|
}
|
2001-10-23 00:48:52 +04:00
|
|
|
}
|
2004-02-10 12:08:06 +03:00
|
|
|
}
|
2001-10-23 00:48:52 +04:00
|
|
|
|
2004-02-10 12:08:06 +03: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 20:47:52 +03:00
|
|
|
if (aLocalName == nsGkAtoms::menu ||
|
|
|
|
aLocalName == nsGkAtoms::contextmenu ||
|
2004-02-10 12:08:06 +03:00
|
|
|
// XXXdwh popup and context are deprecated
|
2006-12-26 20:47:52 +03:00
|
|
|
aLocalName == nsGkAtoms::popup ||
|
|
|
|
aLocalName == nsGkAtoms::context) {
|
2004-02-10 12:08:06 +03:00
|
|
|
AddPopupListener(aLocalName);
|
|
|
|
}
|
2001-10-23 00:48:52 +04:00
|
|
|
}
|
1999-02-24 03:01:26 +03:00
|
|
|
|
2004-02-10 12:08:06 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsIContent interface
|
|
|
|
//
|
2011-06-01 05:46:57 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsXULElement::UpdateEditableState(bool aNotify)
|
2011-06-01 05:46:57 +04:00
|
|
|
{
|
2012-11-15 02:10:08 +04:00
|
|
|
// Don't call through to Element here because the things
|
2011-06-01 05:46:57 +04: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 12:08:06 +03:00
|
|
|
|
2014-05-24 22:51:06 +04: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
|
|
|
|
|
2014-07-18 19:59:00 +04:00
|
|
|
class XULInContentErrorReporter : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit XULInContentErrorReporter(nsIDocument* aDocument) : mDocument(aDocument) {}
|
2014-07-18 19:59:00 +04:00
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
mDocument->WarnOnceAbout(nsIDocument::eImportXULIntoContent, false);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIDocument> mDocument;
|
|
|
|
};
|
|
|
|
|
2008-03-21 14:18:10 +03:00
|
|
|
nsresult
|
|
|
|
nsXULElement::BindToTree(nsIDocument* aDocument,
|
|
|
|
nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aCompileEventHandlers)
|
2008-03-21 14:18:10 +03:00
|
|
|
{
|
2014-07-18 19:59:00 +04:00
|
|
|
if (!aBindingParent &&
|
|
|
|
aDocument &&
|
2014-08-29 23:33:16 +04:00
|
|
|
!aDocument->IsLoadedAsInteractiveData() &&
|
2014-07-18 19:59:00 +04:00
|
|
|
!aDocument->AllowXULXBL() &&
|
|
|
|
!aDocument->HasWarnedAbout(nsIDocument::eImportXULIntoContent)) {
|
|
|
|
nsContentUtils::AddScriptRunner(new XULInContentErrorReporter(aDocument));
|
|
|
|
}
|
|
|
|
|
2010-06-04 05:09:20 +04:00
|
|
|
nsresult rv = nsStyledElement::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
2008-03-21 14:18:10 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-09-18 14:54:00 +04:00
|
|
|
nsIDocument* doc = GetComposedDoc();
|
|
|
|
if (doc &&
|
|
|
|
!doc->LoadsFullXULStyleSheetUpFront() &&
|
|
|
|
!doc->IsUnstyledDocument()) {
|
2014-05-24 22:51:06 +04: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 14:09:00 +03:00
|
|
|
if (!XULElementsRulesInMinimalXULSheet(NodeInfo()->NameAtom())) {
|
2014-09-18 14:54:00 +04:00
|
|
|
doc->EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::XULSheet());
|
2014-05-24 22:51:06 +04: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) ||
|
|
|
|
IsInFeedSubscribeLine(this),
|
|
|
|
"Unexpected XUL element in non-XUL doc");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-21 14:18:10 +03:00
|
|
|
if (aDocument) {
|
2009-01-02 18:41:43 +03:00
|
|
|
NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
|
|
|
|
"Missing a script blocker!");
|
2008-03-21 14:18:10 +03:00
|
|
|
// We're in a document now. Kick off the frame load.
|
|
|
|
LoadSrc();
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-05-22 02:22:51 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsXULElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2007-05-22 02:22:51 +04: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 14:18:10 +03:00
|
|
|
nsXULSlots* slots = static_cast<nsXULSlots*>(GetExistingDOMSlots());
|
2007-05-22 02:22:51 +04:00
|
|
|
if (slots) {
|
|
|
|
NS_IF_RELEASE(slots->mControllers);
|
2008-03-21 14:18:10 +03:00
|
|
|
if (slots->mFrameLoader) {
|
|
|
|
// This element is being taken out of the document, destroy the
|
|
|
|
// possible frame loader.
|
|
|
|
// XXXbz we really want to only partially destroy the frame
|
|
|
|
// loader... we don't want to tear down the docshell. Food for
|
|
|
|
// later bug.
|
|
|
|
slots->mFrameLoader->Destroy();
|
2012-07-30 18:20:58 +04:00
|
|
|
slots->mFrameLoader = nullptr;
|
2008-03-21 14:18:10 +03:00
|
|
|
}
|
2007-05-22 02:22:51 +04:00
|
|
|
}
|
|
|
|
|
2010-02-24 07:37:46 +03:00
|
|
|
nsStyledElement::UnbindFromTree(aDeep, aNullParent);
|
2007-05-22 02:22:51 +04:00
|
|
|
}
|
|
|
|
|
2012-03-30 01:09:07 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXULElement::RemoveChildAt(uint32_t aIndex, bool aNotify)
|
1999-01-12 08:32:30 +03:00
|
|
|
{
|
2006-03-28 02:00:40 +04:00
|
|
|
nsCOMPtr<nsIContent> oldKid = mAttrsAndChildren.GetSafeChildAt(aIndex);
|
|
|
|
if (!oldKid) {
|
2012-03-30 01:09:07 +04:00
|
|
|
return;
|
2000-11-27 10:55:20 +03:00
|
|
|
}
|
|
|
|
|
1999-08-23 05:13:29 +04: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 04:20:29 +03:00
|
|
|
nsCOMPtr<nsIDOMXULMultiSelectControlElement> controlElement;
|
2002-03-29 05:46:01 +03:00
|
|
|
nsCOMPtr<nsIListBoxObject> listBox;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool fireSelectionHandler = false;
|
2000-08-24 10:14:45 +04:00
|
|
|
|
2000-09-07 09:49:04 +04:00
|
|
|
// -1 = do nothing, -2 = null out current item
|
|
|
|
// anything else = index to re-set as current
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t newCurrentIndex = -1;
|
2000-09-07 09:49:04 +04:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (oldKid->NodeInfo()->Equals(nsGkAtoms::listitem, kNameSpaceID_XUL)) {
|
1999-08-23 05:13:29 +04:00
|
|
|
// This is the nasty case. We have (potentially) a slew of selected items
|
|
|
|
// and cells going away.
|
|
|
|
// First, retrieve the tree.
|
2000-07-11 00:19:32 +04:00
|
|
|
// Check first whether this element IS the tree
|
2011-08-31 01:45:31 +04:00
|
|
|
controlElement = do_QueryObject(this);
|
2000-07-11 00:19:32 +04:00
|
|
|
|
|
|
|
// If it's not, look at our parent
|
2002-01-12 04:20:29 +03:00
|
|
|
if (!controlElement)
|
2012-03-30 01:09:07 +04:00
|
|
|
GetParentTree(getter_AddRefs(controlElement));
|
2014-04-16 23:13:41 +04:00
|
|
|
nsCOMPtr<nsIDOMXULElement> xulElement(do_QueryInterface(controlElement));
|
2005-01-24 13:45:00 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> oldKidElem = do_QueryInterface(oldKid);
|
2014-04-16 23:13:41 +04:00
|
|
|
if (xulElement && oldKidElem) {
|
2002-01-12 04:20:29 +03:00
|
|
|
// Iterate over all of the items and find out if they are contained inside
|
|
|
|
// the removed subtree.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t length;
|
2002-01-12 04:20:29 +03:00
|
|
|
controlElement->GetSelectedCount(&length);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < length; i++) {
|
2002-01-12 04:20:29 +03:00
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> node;
|
2012-08-07 11:06:29 +04:00
|
|
|
controlElement->MultiGetSelectedItem(i, getter_AddRefs(node));
|
2005-01-24 13:45:00 +03: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 04:20:29 +03:00
|
|
|
length--;
|
|
|
|
i--;
|
2011-10-17 18:59:28 +04:00
|
|
|
fireSelectionHandler = true;
|
1999-08-23 05:13:29 +04:00
|
|
|
}
|
2000-09-07 09:49:04 +04:00
|
|
|
}
|
2000-08-24 10:14:45 +04:00
|
|
|
|
2002-01-12 04:20:29 +03:00
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> curItem;
|
|
|
|
controlElement->GetCurrentItem(getter_AddRefs(curItem));
|
2005-01-24 13:45:00 +03:00
|
|
|
nsCOMPtr<nsIContent> curNode = do_QueryInterface(curItem);
|
2006-03-24 03:09:50 +03:00
|
|
|
if (curNode && nsContentUtils::ContentIsDescendantOf(curNode, oldKid)) {
|
2000-09-07 09:49:04 +04:00
|
|
|
// Current item going away
|
2000-08-24 10:14:45 +04:00
|
|
|
nsCOMPtr<nsIBoxObject> box;
|
2014-04-16 23:13:41 +04:00
|
|
|
xulElement->GetBoxObject(getter_AddRefs(box));
|
2002-03-29 05:46:01 +03:00
|
|
|
listBox = do_QueryInterface(box);
|
2005-01-24 13:45:00 +03:00
|
|
|
if (listBox && oldKidElem) {
|
|
|
|
listBox->GetIndexOfItem(oldKidElem, &newCurrentIndex);
|
2000-08-24 10:14:45 +04:00
|
|
|
}
|
2000-09-07 09:49:04 +04:00
|
|
|
|
|
|
|
// If any of this fails, we'll just set the current item to null
|
|
|
|
if (newCurrentIndex == -1)
|
|
|
|
newCurrentIndex = -2;
|
1999-08-23 05:13:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-30 01:09:07 +04:00
|
|
|
nsStyledElement::RemoveChildAt(aIndex, aNotify);
|
2006-03-28 02:00:40 +04:00
|
|
|
|
2004-02-10 12:08:06 +03:00
|
|
|
if (newCurrentIndex == -2)
|
2012-07-30 18:20:58 +04:00
|
|
|
controlElement->SetCurrentItem(nullptr);
|
2004-02-10 12:08:06 +03:00
|
|
|
else if (newCurrentIndex > -1) {
|
|
|
|
// Make sure the index is still valid
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t treeRows;
|
2004-02-10 12:08:06 +03:00
|
|
|
listBox->GetRowCount(&treeRows);
|
|
|
|
if (treeRows > 0) {
|
2013-01-15 16:22:03 +04:00
|
|
|
newCurrentIndex = std::min((treeRows - 1), newCurrentIndex);
|
2004-02-10 12:08:06 +03:00
|
|
|
nsCOMPtr<nsIDOMElement> newCurrentItem;
|
|
|
|
listBox->GetItemAtIndex(newCurrentIndex, getter_AddRefs(newCurrentItem));
|
2004-03-10 04:34:55 +03:00
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> xulCurItem = do_QueryInterface(newCurrentItem);
|
|
|
|
if (xulCurItem)
|
|
|
|
controlElement->SetCurrentItem(xulCurItem);
|
2004-02-10 12:08:06 +03:00
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
controlElement->SetCurrentItem(nullptr);
|
2000-08-24 10:14:45 +04:00
|
|
|
}
|
2004-02-10 12:08:06 +03: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 05:34:11 +04:00
|
|
|
|
2006-03-28 02:00:40 +04:00
|
|
|
nsIDocument* doc;
|
2014-10-03 16:29:48 +04:00
|
|
|
if (fireSelectionHandler && (doc = GetComposedDoc())) {
|
2005-10-10 22:38:57 +04:00
|
|
|
nsContentUtils::DispatchTrustedEvent(doc,
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsIContent*>(this),
|
2005-10-10 22:38:57 +04:00
|
|
|
NS_LITERAL_STRING("select"),
|
2011-10-17 18:59:28 +04:00
|
|
|
false,
|
|
|
|
true);
|
2004-02-10 12:08:06 +03:00
|
|
|
}
|
1999-01-12 08:32:30 +03:00
|
|
|
}
|
|
|
|
|
2002-02-21 16:39:39 +03: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 05:34:11 +04:00
|
|
|
//
|
2014-10-03 16:29:48 +04:00
|
|
|
nsIDocument* doc = GetComposedDoc();
|
2005-01-14 22:30:55 +03:00
|
|
|
if (doc && !aOldValue.IsEmpty()) {
|
2010-06-25 17:59:57 +04:00
|
|
|
nsIPresShell *shell = doc->GetShell();
|
2002-02-21 16:39:39 +03:00
|
|
|
|
|
|
|
if (shell) {
|
2004-09-28 23:18:43 +04:00
|
|
|
nsIContent *content = this;
|
2002-02-21 16:39:39 +03:00
|
|
|
|
|
|
|
// find out what type of content node this is
|
2006-12-26 20:47:52 +03:00
|
|
|
if (mNodeInfo->Equals(nsGkAtoms::label)) {
|
2004-09-28 23:18:43 +04:00
|
|
|
// For anonymous labels the unregistering must
|
|
|
|
// occur on the binding parent control.
|
2008-07-23 08:50:20 +04:00
|
|
|
// XXXldb: And what if the binding parent is null?
|
2004-09-28 23:18:43 +04:00
|
|
|
content = GetBindingParent();
|
2002-02-21 16:39:39 +03:00
|
|
|
}
|
|
|
|
|
2004-09-28 23:18:43 +04:00
|
|
|
if (content) {
|
2004-08-21 00:34:37 +04:00
|
|
|
shell->GetPresContext()->EventStateManager()->
|
2004-09-28 23:18:43 +04:00
|
|
|
UnregisterAccessKey(content, aOldValue.First());
|
2002-02-21 16:39:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-02-17 14:09:57 +03:00
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXULElement::BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName,
|
2012-02-14 06:00:56 +04:00
|
|
|
const nsAttrValueOrString* aValue, bool aNotify)
|
2005-10-28 06:59:38 +04:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aNamespaceID == kNameSpaceID_None && aName == nsGkAtoms::accesskey &&
|
2005-10-28 06:59:38 +04:00
|
|
|
IsInDoc()) {
|
2012-07-14 19:28:54 +04:00
|
|
|
nsAutoString oldValue;
|
|
|
|
if (GetAttr(aNamespaceID, aName, oldValue)) {
|
2005-10-28 06:59:38 +04:00
|
|
|
UnregisterAccessKey(oldValue);
|
2003-06-22 10:34:08 +04:00
|
|
|
}
|
2008-01-29 18:12:34 +03:00
|
|
|
}
|
|
|
|
else if (aNamespaceID == kNameSpaceID_None && (aName ==
|
|
|
|
nsGkAtoms::command || aName == nsGkAtoms::observes) && IsInDoc()) {
|
|
|
|
// 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);
|
|
|
|
}
|
2003-06-22 10:34:08 +04:00
|
|
|
}
|
2010-06-25 06:01:07 +04:00
|
|
|
else if (aNamespaceID == kNameSpaceID_None &&
|
|
|
|
aValue &&
|
|
|
|
mNodeInfo->Equals(nsGkAtoms::window) &&
|
|
|
|
aName == nsGkAtoms::chromemargin) {
|
|
|
|
nsAttrValue attrValue;
|
|
|
|
// Make sure the margin format is valid first
|
2012-02-14 06:00:56 +04:00
|
|
|
if (!attrValue.ParseIntMarginValue(aValue->String())) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2010-06-25 06:01:07 +04:00
|
|
|
}
|
|
|
|
}
|
2003-06-21 08:55:32 +04:00
|
|
|
|
2010-02-24 07:37:46 +03:00
|
|
|
return nsStyledElement::BeforeSetAttr(aNamespaceID, aName,
|
|
|
|
aValue, aNotify);
|
2005-10-28 06:59:38 +04:00
|
|
|
}
|
2003-06-22 10:34:08 +04:00
|
|
|
|
2005-10-28 06:59:38 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXULElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
|
2012-02-14 06:00:56 +04:00
|
|
|
const nsAttrValue* aValue, bool aNotify)
|
2005-10-28 06:59:38 +04:00
|
|
|
{
|
2004-02-10 12:08:06 +03:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
2012-07-19 13:14:27 +04: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 20:25:10 +04:00
|
|
|
SetEventHandler(aName, aValue->GetStringValue(), true);
|
2012-07-19 13:14:27 +04:00
|
|
|
} else {
|
|
|
|
nsAutoString body;
|
|
|
|
aValue->ToString(body);
|
2012-08-30 20:25:10 +04:00
|
|
|
SetEventHandler(aName, body, true);
|
2012-07-19 13:14:27 +04:00
|
|
|
}
|
2012-02-14 06:00:56 +04:00
|
|
|
}
|
2012-07-19 13:14:27 +04:00
|
|
|
|
2014-10-03 16:29:48 +04:00
|
|
|
nsIDocument* document = GetUncomposedDoc();
|
2013-02-05 03:22:51 +04:00
|
|
|
|
2012-07-19 13:14:27 +04:00
|
|
|
// Hide chrome if needed
|
|
|
|
if (mNodeInfo->Equals(nsGkAtoms::window)) {
|
|
|
|
if (aName == nsGkAtoms::hidechrome) {
|
|
|
|
HideWindowChrome(
|
|
|
|
aValue->Equals(NS_LITERAL_STRING("true"), eCaseMatters));
|
|
|
|
}
|
|
|
|
else if (aName == nsGkAtoms::chromemargin) {
|
|
|
|
SetChromeMargins(aValue);
|
|
|
|
}
|
2013-02-05 03:22:51 +04:00
|
|
|
|
|
|
|
else if (aName == nsGkAtoms::windowtype &&
|
|
|
|
document && document->GetRootElement() == this) {
|
|
|
|
MaybeUpdatePrivateLifetime();
|
|
|
|
}
|
2009-07-29 22:33:53 +04:00
|
|
|
}
|
2012-07-19 13:14:27 +04: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);
|
|
|
|
}
|
|
|
|
else if ((aName == nsGkAtoms::activetitlebarcolor ||
|
|
|
|
aName == nsGkAtoms::inactivetitlebarcolor)) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
else if (aName == nsGkAtoms::drawintitlebar) {
|
|
|
|
SetDrawsInTitlebar(
|
|
|
|
aValue->Equals(NS_LITERAL_STRING("true"), eCaseMatters));
|
|
|
|
}
|
2013-12-17 20:11:13 +04:00
|
|
|
else if (aName == nsGkAtoms::drawtitle) {
|
|
|
|
SetDrawsTitle(
|
|
|
|
aValue->Equals(NS_LITERAL_STRING("true"), eCaseMatters));
|
|
|
|
}
|
2012-07-19 13:14:27 +04:00
|
|
|
else if (aName == nsGkAtoms::localedir) {
|
|
|
|
// if the localedir changed on the root element, reset the document direction
|
|
|
|
nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(document);
|
|
|
|
if (xuldoc) {
|
|
|
|
xuldoc->ResetDocumentDirection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (aName == nsGkAtoms::lwtheme ||
|
|
|
|
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 06:14:10 +03:00
|
|
|
UpdateBrightTitlebarForeground(document);
|
2012-07-19 13:14:27 +04:00
|
|
|
}
|
2012-02-14 06:00:56 +04:00
|
|
|
}
|
2014-11-04 06:14:10 +03:00
|
|
|
else if (aName == nsGkAtoms::brighttitlebarforeground) {
|
|
|
|
UpdateBrightTitlebarForeground(document);
|
|
|
|
}
|
2009-10-21 11:05:34 +04:00
|
|
|
}
|
2012-07-19 13:14:27 +04:00
|
|
|
|
|
|
|
if (aName == nsGkAtoms::src && document) {
|
|
|
|
LoadSrc();
|
2009-10-21 11:05:34 +04:00
|
|
|
}
|
2012-07-19 13:14:27 +04:00
|
|
|
} else {
|
|
|
|
if (mNodeInfo->Equals(nsGkAtoms::window)) {
|
|
|
|
if (aName == nsGkAtoms::hidechrome) {
|
|
|
|
HideWindowChrome(false);
|
|
|
|
}
|
|
|
|
else if (aName == nsGkAtoms::chromemargin) {
|
|
|
|
ResetChromeMargins();
|
2009-10-21 11:05:34 +04:00
|
|
|
}
|
|
|
|
}
|
2012-07-19 13:14:27 +04:00
|
|
|
|
2014-10-03 16:29:48 +04:00
|
|
|
nsIDocument* doc = GetUncomposedDoc();
|
2012-07-19 13:14:27 +04: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);
|
|
|
|
}
|
|
|
|
else if (aName == nsGkAtoms::localedir) {
|
|
|
|
// if the localedir changed on the root element, reset the document direction
|
|
|
|
nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(doc);
|
|
|
|
if (xuldoc) {
|
|
|
|
xuldoc->ResetDocumentDirection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((aName == nsGkAtoms::lwtheme ||
|
|
|
|
aName == nsGkAtoms::lwthemetextcolor)) {
|
|
|
|
// if the lwtheme changed, make sure to restyle appropriately
|
|
|
|
nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(doc);
|
|
|
|
if (xuldoc) {
|
|
|
|
xuldoc->ResetDocumentLWTheme();
|
2014-11-04 06:14:10 +03:00
|
|
|
UpdateBrightTitlebarForeground(doc);
|
2012-07-19 13:14:27 +04:00
|
|
|
}
|
|
|
|
}
|
2014-11-04 06:14:10 +03:00
|
|
|
else if (aName == nsGkAtoms::brighttitlebarforeground) {
|
|
|
|
UpdateBrightTitlebarForeground(doc);
|
|
|
|
}
|
2012-07-19 13:14:27 +04:00
|
|
|
else if (aName == nsGkAtoms::drawintitlebar) {
|
|
|
|
SetDrawsInTitlebar(false);
|
2009-10-21 11:05:34 +04:00
|
|
|
}
|
2013-12-17 20:11:13 +04:00
|
|
|
else if (aName == nsGkAtoms::drawtitle) {
|
|
|
|
SetDrawsTitle(false);
|
|
|
|
}
|
2009-10-02 10:22:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-28 06:59:38 +04: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 06:33:52 +03:00
|
|
|
}
|
|
|
|
|
2010-02-24 07:37:46 +03:00
|
|
|
return nsStyledElement::AfterSetAttr(aNamespaceID, aName,
|
|
|
|
aValue, aNotify);
|
2004-02-10 12:08:06 +03:00
|
|
|
}
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXULElement::ParseAttribute(int32_t aNamespaceID,
|
2005-11-29 19:37:15 +03:00
|
|
|
nsIAtom* aAttribute,
|
2005-10-28 06:59:38 +04:00
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
2004-02-10 12:08:06 +03:00
|
|
|
{
|
2005-10-28 06:59:38 +04:00
|
|
|
// Parse into a nsAttrValue
|
2010-02-24 07:37:46 +03:00
|
|
|
if (!nsStyledElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
|
|
|
aResult)) {
|
2005-10-28 06:59:38 +04:00
|
|
|
// Fall back to parsing as atom for short values
|
|
|
|
aResult.ParseStringOrAtom(aValue);
|
2004-02-10 12:08:06 +03:00
|
|
|
}
|
2003-10-30 04:40:33 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2003-10-30 04:40:33 +03:00
|
|
|
}
|
|
|
|
|
2008-01-29 18:12:34 +03:00
|
|
|
void
|
|
|
|
nsXULElement::RemoveBroadcaster(const nsAString & broadcasterId)
|
|
|
|
{
|
2011-10-18 14:53:36 +04:00
|
|
|
nsCOMPtr<nsIDOMXULDocument> xuldoc = do_QueryInterface(OwnerDoc());
|
2008-01-29 18:12:34 +03: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 20:57:03 +03:00
|
|
|
void
|
|
|
|
nsXULElement::DestroyContent()
|
|
|
|
{
|
2008-03-21 14:18:10 +03:00
|
|
|
nsXULSlots* slots = static_cast<nsXULSlots*>(GetExistingDOMSlots());
|
2007-11-30 20:57:03 +03:00
|
|
|
if (slots) {
|
2008-03-21 14:18:10 +03:00
|
|
|
NS_IF_RELEASE(slots->mControllers);
|
|
|
|
if (slots->mFrameLoader) {
|
|
|
|
slots->mFrameLoader->Destroy();
|
2012-07-30 18:20:58 +04:00
|
|
|
slots->mFrameLoader = nullptr;
|
2008-03-21 14:18:10 +03:00
|
|
|
}
|
2007-11-30 20:57:03 +03:00
|
|
|
}
|
|
|
|
|
2010-02-24 07:37:46 +03:00
|
|
|
nsStyledElement::DestroyContent();
|
2007-11-30 20:57:03 +03:00
|
|
|
}
|
1999-01-12 08:32:30 +03:00
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
2004-01-10 02:54:21 +03:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXULElement::List(FILE* out, int32_t aIndent) const
|
1999-01-12 08:32:30 +03:00
|
|
|
{
|
2009-08-13 19:38:23 +04:00
|
|
|
nsCString prefix("XUL");
|
2006-12-27 20:26:32 +03:00
|
|
|
if (HasSlots()) {
|
|
|
|
prefix.Append('*');
|
2001-08-03 11:34:28 +04:00
|
|
|
}
|
2006-12-27 20:26:32 +03:00
|
|
|
prefix.Append(' ');
|
1999-01-12 08:32:30 +03:00
|
|
|
|
2010-02-24 07:37:46 +03:00
|
|
|
nsStyledElement::List(out, aIndent, prefix);
|
1999-01-12 08:32:30 +03:00
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
1999-01-12 08:32:30 +03:00
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
nsresult
|
2014-03-18 08:48:19 +04:00
|
|
|
nsXULElement::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
2006-03-07 20:08:51 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
aVisitor.mForceContentDispatch = true; //FIXME! Bug 329119
|
2009-06-23 14:07:39 +04:00
|
|
|
if (IsRootOfNativeAnonymousSubtree() &&
|
2015-03-03 14:09:00 +03:00
|
|
|
(IsAnyOfXULElements(nsGkAtoms::scrollbar, nsGkAtoms::scrollcorner)) &&
|
2009-06-23 14:07:39 +04:00
|
|
|
(aVisitor.mEvent->message == NS_MOUSE_CLICK ||
|
|
|
|
aVisitor.mEvent->message == NS_MOUSE_DOUBLECLICK ||
|
|
|
|
aVisitor.mEvent->message == NS_XUL_COMMAND ||
|
2009-08-03 11:55:35 +04:00
|
|
|
aVisitor.mEvent->message == NS_CONTEXTMENU ||
|
|
|
|
aVisitor.mEvent->message == NS_DRAGDROP_START ||
|
|
|
|
aVisitor.mEvent->message == NS_DRAGDROP_GESTURE)) {
|
2009-06-23 14:07:39 +04:00
|
|
|
// Don't propagate these events from native anonymous scrollbar.
|
2011-10-17 18:59:28 +04:00
|
|
|
aVisitor.mCanHandle = true;
|
2012-07-30 18:20:58 +04:00
|
|
|
aVisitor.mParentTarget = nullptr;
|
2009-06-23 14:07:39 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-03-07 20:08:51 +03:00
|
|
|
if (aVisitor.mEvent->message == NS_XUL_COMMAND &&
|
2014-08-04 09:28:47 +04:00
|
|
|
aVisitor.mEvent->mClass == eInputEventClass &&
|
2007-07-08 11:08:04 +04:00
|
|
|
aVisitor.mEvent->originalTarget == static_cast<nsIContent*>(this) &&
|
2015-03-03 14:09:00 +03:00
|
|
|
!IsXULElement(nsGkAtoms::command)) {
|
2009-06-30 11:56:40 +04: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 20:08:51 +03: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 11:56:40 +04:00
|
|
|
if (xulEvent && GetAttr(kNameSpaceID_None, nsGkAtoms::command, command) &&
|
|
|
|
!command.IsEmpty()) {
|
2006-05-23 00:37:32 +04: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 18:59:28 +04:00
|
|
|
aVisitor.mCanHandle = false;
|
2013-01-03 19:17:36 +04:00
|
|
|
aVisitor.mAutomaticChromeDispatch = false;
|
2006-05-23 00:37:32 +04:00
|
|
|
|
2006-03-07 20:08:51 +03:00
|
|
|
// XXX sXBL/XBL2 issue! Owner or current document?
|
2014-10-03 16:29:48 +04:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(GetUncomposedDoc()));
|
2007-01-03 08:16:25 +03:00
|
|
|
NS_ENSURE_STATE(domDoc);
|
2006-03-07 20:08:51 +03:00
|
|
|
nsCOMPtr<nsIDOMElement> commandElt;
|
|
|
|
domDoc->GetElementById(command, getter_AddRefs(commandElt));
|
|
|
|
nsCOMPtr<nsIContent> commandContent(do_QueryInterface(commandElt));
|
2006-05-11 21:36:18 +04:00
|
|
|
if (commandContent) {
|
2006-05-23 00:37:32 +04: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 11:44:00 +04:00
|
|
|
nsCOMPtr<nsIDOMEvent> domEvent = aVisitor.mDOMEvent;
|
|
|
|
while (domEvent) {
|
2014-03-05 04:37:43 +04:00
|
|
|
Event* event = domEvent->InternalDOMEvent();
|
2013-04-06 04:44:15 +04:00
|
|
|
NS_ENSURE_STATE(!SameCOMIdentity(event->GetOriginalTarget(),
|
|
|
|
commandContent));
|
2008-06-05 00:23:37 +04:00
|
|
|
nsCOMPtr<nsIDOMXULCommandEvent> commandEvent =
|
2012-08-04 11:44:00 +04:00
|
|
|
do_QueryInterface(domEvent);
|
2008-06-05 00:23:37 +04:00
|
|
|
if (commandEvent) {
|
2012-08-04 11:44:00 +04:00
|
|
|
commandEvent->GetSourceEvent(getter_AddRefs(domEvent));
|
|
|
|
} else {
|
2013-04-03 05:14:24 +04:00
|
|
|
domEvent = nullptr;
|
2008-06-05 00:23:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-18 10:10:26 +04:00
|
|
|
WidgetInputEvent* orig = aVisitor.mEvent->AsInputEvent();
|
2009-06-30 11:56:40 +04:00
|
|
|
nsContentUtils::DispatchXULCommand(
|
|
|
|
commandContent,
|
2012-12-16 05:26:03 +04:00
|
|
|
aVisitor.mEvent->mFlags.mIsTrusted,
|
2009-06-30 11:56:40 +04:00
|
|
|
aVisitor.mDOMEvent,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr,
|
2012-04-25 07:00:02 +04:00
|
|
|
orig->IsControl(),
|
|
|
|
orig->IsAlt(),
|
|
|
|
orig->IsShift(),
|
|
|
|
orig->IsMeta());
|
2006-03-07 20:08:51 +03:00
|
|
|
} else {
|
|
|
|
NS_WARNING("A XUL element is attached to a command that doesn't exist!\n");
|
2003-03-25 06:15:37 +03:00
|
|
|
}
|
2006-03-07 20:08:51 +03:00
|
|
|
return NS_OK;
|
1999-09-08 12:06:28 +04:00
|
|
|
}
|
1999-05-16 10:58:56 +04:00
|
|
|
}
|
1999-02-02 01:34:51 +03:00
|
|
|
|
2010-02-24 07:37:46 +03:00
|
|
|
return nsStyledElement::PreHandleEvent(aVisitor);
|
1999-01-12 08:32:30 +03:00
|
|
|
}
|
|
|
|
|
1999-06-15 07:21:20 +04:00
|
|
|
// XXX This _should_ be an implementation method, _not_ publicly exposed :-(
|
1999-03-10 23:20:52 +03:00
|
|
|
NS_IMETHODIMP
|
1999-10-19 02:08:15 +04:00
|
|
|
nsXULElement::GetResource(nsIRDFResource** aResource)
|
2013-01-29 21:51:55 +04:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
2014-03-15 23:00:15 +04:00
|
|
|
*aResource = GetResource(rv).take();
|
2015-04-27 16:18:51 +03:00
|
|
|
return rv.StealNSResult();
|
2013-01-29 21:51:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIRDFResource>
|
|
|
|
nsXULElement::GetResource(ErrorResult& rv)
|
1999-03-10 23:20:52 +03:00
|
|
|
{
|
1999-10-06 01:13:55 +04:00
|
|
|
nsAutoString id;
|
2006-12-26 20:47:52 +03:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::ref, id);
|
2005-10-28 15:25:24 +04:00
|
|
|
if (id.IsEmpty()) {
|
2006-12-26 20:47:52 +03:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::id, id);
|
1999-10-06 01:13:55 +04:00
|
|
|
}
|
1999-07-28 03:02:13 +04:00
|
|
|
|
2013-01-29 21:51:55 +04:00
|
|
|
if (id.IsEmpty()) {
|
|
|
|
return nullptr;
|
1999-10-06 01:13:55 +04:00
|
|
|
}
|
|
|
|
|
2013-01-29 21:51:55 +04:00
|
|
|
nsCOMPtr<nsIRDFResource> resource;
|
|
|
|
rv = nsXULContentUtils::RDFService()->
|
|
|
|
GetUnicodeResource(id, getter_AddRefs(resource));
|
|
|
|
return resource.forget();
|
1999-03-10 23:20:52 +03:00
|
|
|
}
|
|
|
|
|
1999-07-27 21:20:28 +04:00
|
|
|
NS_IMETHODIMP
|
1999-10-19 02:08:15 +04:00
|
|
|
nsXULElement::GetDatabase(nsIRDFCompositeDataSource** aDatabase)
|
1999-07-27 21:20:28 +04:00
|
|
|
{
|
2014-03-15 23:00:15 +04:00
|
|
|
*aDatabase = GetDatabase().take();
|
2013-01-29 21:51:55 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-23 13:56:18 +03:00
|
|
|
|
2013-01-29 21:51:55 +04:00
|
|
|
already_AddRefed<nsIRDFCompositeDataSource>
|
|
|
|
nsXULElement::GetDatabase()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIXULTemplateBuilder> builder = GetBuilder();
|
|
|
|
if (!builder) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2001-03-23 13:56:18 +03:00
|
|
|
|
2013-01-29 21:51:55 +04:00
|
|
|
nsCOMPtr<nsIRDFCompositeDataSource> database;
|
|
|
|
builder->GetDatabase(getter_AddRefs(database));
|
|
|
|
return database.forget();
|
1999-07-27 21:20:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-05-06 03:39:59 +04:00
|
|
|
nsXULElement::GetBuilder(nsIXULTemplateBuilder** aBuilder)
|
1999-07-27 21:20:28 +04:00
|
|
|
{
|
2014-03-15 23:00:15 +04:00
|
|
|
*aBuilder = GetBuilder().take();
|
2013-01-29 21:51:55 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-23 13:56:18 +03:00
|
|
|
|
2013-01-29 21:51:55 +04:00
|
|
|
already_AddRefed<nsIXULTemplateBuilder>
|
|
|
|
nsXULElement::GetBuilder()
|
|
|
|
{
|
2005-01-14 22:30:55 +03:00
|
|
|
// XXX sXBL/XBL2 issue! Owner or current document?
|
2014-10-03 16:29:48 +04:00
|
|
|
nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(GetUncomposedDoc());
|
2013-01-29 21:51:55 +04:00
|
|
|
if (!xuldoc) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2001-03-23 13:56:18 +03:00
|
|
|
|
2013-01-29 21:51:55 +04:00
|
|
|
nsCOMPtr<nsIXULTemplateBuilder> builder;
|
|
|
|
xuldoc->GetTemplateBuilderFor(this, getter_AddRefs(builder));
|
|
|
|
return builder.forget();
|
1999-07-27 21:20:28 +04:00
|
|
|
}
|
|
|
|
|
1999-10-29 05:21:15 +04:00
|
|
|
//----------------------------------------------------------------------
|
1999-03-10 23:20:52 +03:00
|
|
|
// Implementation methods
|
|
|
|
|
1999-03-05 03:01:26 +03:00
|
|
|
NS_IMETHODIMP
|
2001-10-24 04:01:09 +04:00
|
|
|
nsXULElement::WalkContentStyleRules(nsRuleWalker* aRuleWalker)
|
1999-03-05 03:01:26 +03:00
|
|
|
{
|
1999-10-20 22:55:32 +04:00
|
|
|
return NS_OK;
|
1999-03-05 03:01:26 +03:00
|
|
|
}
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2004-10-24 21:10:32 +04:00
|
|
|
nsChangeHint
|
2003-07-12 01:16:12 +04:00
|
|
|
nsXULElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType) const
|
1999-03-05 03:01:26 +03:00
|
|
|
{
|
2004-10-24 21:10:32 +04:00
|
|
|
nsChangeHint retval(NS_STYLE_HINT_NONE);
|
2000-02-22 09:09:41 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::value &&
|
2003-11-19 04:20:56 +03:00
|
|
|
(aModType == nsIDOMMutationEvent::REMOVAL ||
|
|
|
|
aModType == nsIDOMMutationEvent::ADDITION)) {
|
2015-03-03 14:09:00 +03:00
|
|
|
if (IsAnyOfXULElements(nsGkAtoms::label, nsGkAtoms::description))
|
2003-11-19 04:20:56 +03: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.)
|
2004-10-24 21:10:32 +04:00
|
|
|
retval = NS_STYLE_HINT_FRAMECHANGE;
|
2000-07-11 00:10:27 +04:00
|
|
|
} else {
|
2003-11-19 04:20:56 +03:00
|
|
|
// if left or top changes we reflow. This will happen in xul
|
2009-07-29 22:33:53 +04:00
|
|
|
// containers that manage positioned children such as a stack.
|
2009-09-14 01:13:54 +04:00
|
|
|
if (nsGkAtoms::left == aAttribute || nsGkAtoms::top == aAttribute ||
|
2011-02-28 21:06:29 +03:00
|
|
|
nsGkAtoms::right == aAttribute || nsGkAtoms::bottom == aAttribute ||
|
|
|
|
nsGkAtoms::start == aAttribute || nsGkAtoms::end == aAttribute)
|
2004-10-24 21:10:32 +04:00
|
|
|
retval = NS_STYLE_HINT_REFLOW;
|
2000-02-22 09:09:41 +03:00
|
|
|
}
|
|
|
|
|
2004-10-24 21:10:32 +04:00
|
|
|
return retval;
|
1999-03-05 03:01:26 +03:00
|
|
|
}
|
1999-06-09 01:58:55 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2004-02-26 00:04:50 +03:00
|
|
|
nsXULElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
2003-07-12 01:16:12 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2003-07-12 01:16:12 +04:00
|
|
|
}
|
|
|
|
|
1999-10-14 14:58:25 +04:00
|
|
|
// Controllers Methods
|
1999-06-09 01:58:55 +04:00
|
|
|
NS_IMETHODIMP
|
1999-10-19 02:08:15 +04:00
|
|
|
nsXULElement::GetControllers(nsIControllers** aResult)
|
2013-01-29 21:51:55 +04:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*aResult = GetControllers(rv));
|
2015-04-27 16:18:51 +03:00
|
|
|
return rv.StealNSResult();
|
2013-01-29 21:51:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIControllers*
|
|
|
|
nsXULElement::GetControllers(ErrorResult& rv)
|
1999-06-09 01:58:55 +04:00
|
|
|
{
|
1999-12-06 02:04:22 +03:00
|
|
|
if (! Controllers()) {
|
2010-12-22 04:04:00 +03:00
|
|
|
nsDOMSlots* slots = DOMSlots();
|
2005-01-14 22:30:55 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = NS_NewXULControllers(nullptr, NS_GET_IID(nsIControllers),
|
2007-07-08 11:08:04 +04:00
|
|
|
reinterpret_cast<void**>(&slots->mControllers));
|
1999-10-20 22:55:32 +04:00
|
|
|
|
2015-04-27 16:18:52 +03:00
|
|
|
NS_ASSERTION(!rv.Failed(), "unable to create a controllers");
|
2013-01-29 21:51:55 +04:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
1999-10-20 22:55:32 +04:00
|
|
|
}
|
|
|
|
|
2013-01-29 21:51:55 +04:00
|
|
|
return Controllers();
|
1999-06-09 01:58:55 +04:00
|
|
|
}
|
|
|
|
|
2000-05-30 12:11:35 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::GetBoxObject(nsIBoxObject** aResult)
|
2000-03-24 01:17:37 +03:00
|
|
|
{
|
2013-01-29 21:51:55 +04:00
|
|
|
ErrorResult rv;
|
2014-03-15 23:00:15 +04:00
|
|
|
*aResult = GetBoxObject(rv).take();
|
2015-04-27 16:18:51 +03:00
|
|
|
return rv.StealNSResult();
|
2013-01-29 21:51:55 +04:00
|
|
|
}
|
2000-03-24 01:17:37 +03:00
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
already_AddRefed<BoxObject>
|
2013-01-29 21:51:55 +04:00
|
|
|
nsXULElement::GetBoxObject(ErrorResult& rv)
|
|
|
|
{
|
|
|
|
// XXX sXBL/XBL2 issue! Owner or current document?
|
2013-03-26 19:31:53 +04:00
|
|
|
return OwnerDoc()->GetBoxObjectFor(this, rv);
|
2000-03-24 01:17:37 +03:00
|
|
|
}
|
|
|
|
|
1999-06-09 09:45:15 +04:00
|
|
|
// Methods for setting/getting attributes from nsIDOMXULElement
|
2005-01-24 13:45:00 +03:00
|
|
|
#define NS_IMPL_XUL_STRING_ATTR(_method, _atom) \
|
|
|
|
NS_IMETHODIMP \
|
|
|
|
nsXULElement::Get##_method(nsAString& aReturn) \
|
|
|
|
{ \
|
2006-12-26 20:47:52 +03:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::_atom, aReturn); \
|
2005-10-28 15:25:24 +04:00
|
|
|
return NS_OK; \
|
2005-01-24 13:45:00 +03:00
|
|
|
} \
|
|
|
|
NS_IMETHODIMP \
|
|
|
|
nsXULElement::Set##_method(const nsAString& aValue) \
|
|
|
|
{ \
|
2006-12-26 20:47:52 +03:00
|
|
|
return SetAttr(kNameSpaceID_None, nsGkAtoms::_atom, aValue, \
|
2011-10-17 18:59:28 +04:00
|
|
|
true); \
|
2005-01-24 13:45:00 +03:00
|
|
|
}
|
2001-08-12 07:47:33 +04:00
|
|
|
|
2005-01-24 13:45:00 +03:00
|
|
|
#define NS_IMPL_XUL_BOOL_ATTR(_method, _atom) \
|
|
|
|
NS_IMETHODIMP \
|
2013-01-29 21:51:55 +04:00
|
|
|
nsXULElement::Get##_method(bool* aResult) \
|
2005-01-24 13:45:00 +03:00
|
|
|
{ \
|
2013-01-29 21:51:55 +04:00
|
|
|
*aResult = _method(); \
|
2005-01-24 13:45:00 +03:00
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
NS_IMETHODIMP \
|
2013-01-29 21:51:55 +04:00
|
|
|
nsXULElement::Set##_method(bool aValue) \
|
2005-01-24 13:45:00 +03:00
|
|
|
{ \
|
2013-01-29 21:51:55 +04:00
|
|
|
SetXULBoolAttr(nsGkAtoms::_atom, aValue); \
|
|
|
|
return NS_OK; \
|
2005-01-24 13:45:00 +03:00
|
|
|
}
|
2001-08-12 07:47:33 +04:00
|
|
|
|
|
|
|
|
2005-01-24 13:45:00 +03: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 07:47:33 +04:00
|
|
|
|
2008-03-21 14:18:10 +03:00
|
|
|
nsresult
|
|
|
|
nsXULElement::LoadSrc()
|
|
|
|
{
|
|
|
|
// Allow frame loader only on objects for which a container box object
|
|
|
|
// can be obtained.
|
2015-03-03 14:09:00 +03:00
|
|
|
if (!IsAnyOfXULElements(nsGkAtoms::browser, nsGkAtoms::editor,
|
|
|
|
nsGkAtoms::iframe)) {
|
2008-03-21 14:18:10 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (!IsInDoc() ||
|
2011-10-18 14:53:36 +04:00
|
|
|
!OwnerDoc()->GetRootElement() ||
|
|
|
|
OwnerDoc()->GetRootElement()->
|
2008-03-21 14:18:10 +03:00
|
|
|
NodeInfo()->Equals(nsGkAtoms::overlay, kNameSpaceID_XUL)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-11 02:27:28 +04:00
|
|
|
nsXULSlots* slots = static_cast<nsXULSlots*>(Slots());
|
2008-03-21 14:18:10 +03:00
|
|
|
if (!slots->mFrameLoader) {
|
2011-10-17 18:59:28 +04:00
|
|
|
// false as the last parameter so that xul:iframe/browser/editor
|
2010-08-17 18:13:55 +04:00
|
|
|
// session history handling works like dynamic html:iframes.
|
|
|
|
// Usually xul elements are used in chrome, which doesn't have
|
|
|
|
// session history at all.
|
2011-10-17 18:59:28 +04:00
|
|
|
slots->mFrameLoader = nsFrameLoader::Create(this, false);
|
2015-04-30 12:50:39 +03:00
|
|
|
NS_ENSURE_TRUE(slots->mFrameLoader, NS_OK);
|
|
|
|
|
2015-04-28 17:22:38 +03:00
|
|
|
(new AsyncEventDispatcher(this,
|
|
|
|
NS_LITERAL_STRING("XULFrameLoaderCreated"),
|
|
|
|
/* aBubbles */ true))->RunDOMEventWhenSafe();
|
|
|
|
|
2015-01-05 22:16:09 +03:00
|
|
|
if (AttrValueIs(kNameSpaceID_None, nsGkAtoms::prerendered,
|
|
|
|
NS_LITERAL_STRING("true"), eIgnoreCase)) {
|
|
|
|
nsresult rv = slots->mFrameLoader->SetIsPrerendered();
|
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
}
|
2008-03-21 14:18:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return slots->mFrameLoader->LoadFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULElement::GetFrameLoader(nsIFrameLoader **aFrameLoader)
|
|
|
|
{
|
2014-03-15 23:00:15 +04:00
|
|
|
*aFrameLoader = GetFrameLoader().take();
|
2008-03-21 14:18:10 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-21 01:33:59 +04:00
|
|
|
already_AddRefed<nsFrameLoader>
|
|
|
|
nsXULElement::GetFrameLoader()
|
|
|
|
{
|
|
|
|
nsXULSlots* slots = static_cast<nsXULSlots*>(GetExistingSlots());
|
|
|
|
if (!slots)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-10-21 01:33:59 +04:00
|
|
|
|
2013-04-22 15:15:59 +04:00
|
|
|
nsRefPtr<nsFrameLoader> loader = slots->mFrameLoader;
|
|
|
|
return loader.forget();
|
2009-10-21 01:33:59 +04:00
|
|
|
}
|
|
|
|
|
2015-01-05 22:16:09 +03:00
|
|
|
nsresult
|
|
|
|
nsXULElement::SetIsPrerendered()
|
|
|
|
{
|
|
|
|
return SetAttr(kNameSpaceID_None, nsGkAtoms::prerendered, nullptr,
|
|
|
|
NS_LITERAL_STRING("true"), true);
|
|
|
|
}
|
|
|
|
|
2008-08-11 12:38:43 +04:00
|
|
|
nsresult
|
|
|
|
nsXULElement::SwapFrameLoaders(nsIFrameLoaderOwner* aOtherOwner)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> otherContent(do_QueryInterface(aOtherOwner));
|
|
|
|
NS_ENSURE_TRUE(otherContent, NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
|
|
|
|
nsXULElement* otherEl = FromContent(otherContent);
|
|
|
|
NS_ENSURE_TRUE(otherEl, NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
|
2013-01-29 21:51:55 +04:00
|
|
|
ErrorResult rv;
|
|
|
|
SwapFrameLoaders(*otherEl, rv);
|
2015-04-27 16:18:51 +03:00
|
|
|
return rv.StealNSResult();
|
2013-01-29 21:51:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULElement::SwapFrameLoaders(nsXULElement& aOtherElement, ErrorResult& rv)
|
|
|
|
{
|
|
|
|
if (&aOtherElement == this) {
|
2008-08-11 12:38:43 +04:00
|
|
|
// nothing to do
|
2013-01-29 21:51:55 +04:00
|
|
|
return;
|
2008-08-11 12:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXULSlots *ourSlots = static_cast<nsXULSlots*>(GetExistingDOMSlots());
|
|
|
|
nsXULSlots *otherSlots =
|
2013-01-29 21:51:55 +04:00
|
|
|
static_cast<nsXULSlots*>(aOtherElement.GetExistingDOMSlots());
|
2008-08-11 12:38:43 +04:00
|
|
|
if (!ourSlots || !ourSlots->mFrameLoader ||
|
|
|
|
!otherSlots || !otherSlots->mFrameLoader) {
|
|
|
|
// Can't handle swapping when there is nothing to swap... yet.
|
2013-01-29 21:51:55 +04:00
|
|
|
rv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
return;
|
2008-08-11 12:38:43 +04:00
|
|
|
}
|
|
|
|
|
2013-01-29 21:51:55 +04:00
|
|
|
rv = ourSlots->mFrameLoader->SwapWithOtherLoader(otherSlots->mFrameLoader,
|
|
|
|
ourSlots->mFrameLoader,
|
|
|
|
otherSlots->mFrameLoader);
|
2008-08-11 12:38:43 +04:00
|
|
|
}
|
|
|
|
|
1999-08-22 10:01:52 +04:00
|
|
|
NS_IMETHODIMP
|
2002-01-12 04:20:29 +03:00
|
|
|
nsXULElement::GetParentTree(nsIDOMXULMultiSelectControlElement** aTreeElement)
|
1999-08-22 10:01:52 +04:00
|
|
|
{
|
2003-11-19 04:20:56 +03:00
|
|
|
for (nsIContent* current = GetParent(); current;
|
|
|
|
current = current->GetParent()) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (current->NodeInfo()->Equals(nsGkAtoms::listbox,
|
2005-09-24 22:43:15 +04:00
|
|
|
kNameSpaceID_XUL)) {
|
2003-11-19 04:20:56 +03: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 10:01:52 +04:00
|
|
|
}
|
2003-11-19 04:20:56 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-08-22 10:01:52 +04:00
|
|
|
}
|
|
|
|
|
2000-01-25 09:35:27 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::Focus()
|
2013-01-29 21:51:55 +04:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
Focus(rv);
|
2015-04-27 16:18:51 +03:00
|
|
|
return rv.StealNSResult();
|
2013-01-29 21:51:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULElement::Focus(ErrorResult& rv)
|
2000-01-25 09:35:27 +03: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 22:00:39 +04:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
2011-08-31 01:45:31 +04:00
|
|
|
nsCOMPtr<nsIDOMElement> elem = do_QueryObject(this);
|
2013-01-29 21:51:55 +04:00
|
|
|
if (fm) {
|
|
|
|
rv = fm->SetFocus(this, 0);
|
|
|
|
}
|
2000-01-25 09:35:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::Blur()
|
2013-01-29 21:51:55 +04:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
Blur(rv);
|
2015-04-27 16:18:51 +03:00
|
|
|
return rv.StealNSResult();
|
2013-01-29 21:51:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULElement::Blur(ErrorResult& rv)
|
2000-01-25 09:35:27 +03: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 22:00:39 +04:00
|
|
|
if (!ShouldBlur(this))
|
2013-01-29 21:51:55 +04:00
|
|
|
return;
|
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 22:00:39 +04:00
|
|
|
|
2014-10-03 16:29:48 +04:00
|
|
|
nsIDocument* doc = GetComposedDoc();
|
2005-01-14 22:30:55 +03:00
|
|
|
if (!doc)
|
2013-01-29 21:51:55 +04:00
|
|
|
return;
|
2000-01-25 09:35:27 +03: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 22:00:39 +04:00
|
|
|
nsIDOMWindow* win = doc->GetWindow();
|
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
2013-01-29 21:51:55 +04:00
|
|
|
if (win && fm) {
|
|
|
|
rv = fm->ClearFocus(win);
|
|
|
|
}
|
2000-01-25 09:35:27 +03:00
|
|
|
}
|
|
|
|
|
2000-02-12 13:08:52 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::Click()
|
2010-04-06 16:59:24 +04:00
|
|
|
{
|
2011-08-26 11:43:56 +04:00
|
|
|
return ClickWithInputSource(nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN);
|
2010-04-06 16:59:24 +04:00
|
|
|
}
|
|
|
|
|
2013-01-29 21:51:55 +04:00
|
|
|
void
|
|
|
|
nsXULElement::Click(ErrorResult& rv)
|
|
|
|
{
|
|
|
|
rv = Click();
|
|
|
|
}
|
|
|
|
|
2010-04-06 16:59:24 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXULElement::ClickWithInputSource(uint16_t aInputSource)
|
2000-02-12 13:08:52 +03:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
if (BoolAttrIsTrue(nsGkAtoms::disabled))
|
2004-01-10 02:54:21 +03:00
|
|
|
return NS_OK;
|
2002-02-02 02:55:49 +03:00
|
|
|
|
2014-10-03 16:29:48 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = GetComposedDoc(); // Strong just in case
|
2004-01-10 02:54:21 +03:00
|
|
|
if (doc) {
|
2010-06-25 17:59:57 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell = doc->GetShell();
|
2010-01-07 13:36:11 +03:00
|
|
|
if (shell) {
|
2007-05-23 01:45:03 +04:00
|
|
|
// strong ref to PresContext so events don't destroy it
|
2010-03-25 16:17:11 +03:00
|
|
|
nsRefPtr<nsPresContext> context = shell->GetPresContext();
|
2004-01-10 02:54:21 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isCallerChrome = nsContentUtils::IsCallerChrome();
|
2005-04-29 03:48:28 +04:00
|
|
|
|
2013-10-02 10:38:27 +04:00
|
|
|
WidgetMouseEvent eventDown(isCallerChrome, NS_MOUSE_BUTTON_DOWN,
|
|
|
|
nullptr, WidgetMouseEvent::eReal);
|
|
|
|
WidgetMouseEvent eventUp(isCallerChrome, NS_MOUSE_BUTTON_UP,
|
|
|
|
nullptr, WidgetMouseEvent::eReal);
|
|
|
|
WidgetMouseEvent eventClick(isCallerChrome, NS_MOUSE_CLICK, nullptr,
|
|
|
|
WidgetMouseEvent::eReal);
|
2010-04-06 16:59:24 +04:00
|
|
|
eventDown.inputSource = eventUp.inputSource = eventClick.inputSource
|
|
|
|
= aInputSource;
|
2004-01-10 02:54:21 +03:00
|
|
|
|
|
|
|
// send mouse down
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2014-03-18 08:48:21 +04:00
|
|
|
EventDispatcher::Dispatch(static_cast<nsIContent*>(this),
|
|
|
|
context, &eventDown, nullptr, &status);
|
2004-01-10 02:54:21 +03:00
|
|
|
|
|
|
|
// send mouse up
|
|
|
|
status = nsEventStatus_eIgnore; // reset status
|
2014-03-18 08:48:21 +04:00
|
|
|
EventDispatcher::Dispatch(static_cast<nsIContent*>(this),
|
|
|
|
context, &eventUp, nullptr, &status);
|
2004-01-10 02:54:21 +03:00
|
|
|
|
|
|
|
// send mouse click
|
|
|
|
status = nsEventStatus_eIgnore; // reset status
|
2014-03-18 08:48:21 +04:00
|
|
|
EventDispatcher::Dispatch(static_cast<nsIContent*>(this),
|
|
|
|
context, &eventClick, nullptr, &status);
|
2004-01-10 02:54:21 +03:00
|
|
|
}
|
2001-06-20 06:02:57 +04: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 05:34:11 +04:00
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
// oncommand is fired when an element is clicked...
|
|
|
|
return DoCommand();
|
2001-06-20 06:02:57 +04:00
|
|
|
}
|
2000-02-12 13:47:33 +03:00
|
|
|
|
2001-06-20 06:02:57 +04:00
|
|
|
NS_IMETHODIMP
|
2001-08-12 07:47:33 +04:00
|
|
|
nsXULElement::DoCommand()
|
2001-06-20 06:02:57 +04:00
|
|
|
{
|
2014-10-03 16:29:48 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = GetComposedDoc(); // strong just in case
|
2004-01-10 02:54:21 +03:00
|
|
|
if (doc) {
|
2011-10-17 18:59:28 +04:00
|
|
|
nsContentUtils::DispatchXULCommand(this, true);
|
2000-02-12 13:08:52 +03:00
|
|
|
}
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
return NS_OK;
|
2000-02-12 13:08:52 +03:00
|
|
|
}
|
2000-01-25 09:35:27 +03:00
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
nsIContent *
|
2003-07-29 01:17:26 +04:00
|
|
|
nsXULElement::GetBindingParent() const
|
2000-08-12 10:28:02 +04:00
|
|
|
{
|
2004-01-10 02:54:21 +03:00
|
|
|
return mBindingParent;
|
2000-08-12 10:28:02 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04: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 20:46:42 +04:00
|
|
|
{
|
2010-04-30 17:12:06 +04: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 20:46:42 +04:00
|
|
|
}
|
|
|
|
|
1999-10-29 05:21:15 +04:00
|
|
|
nsresult
|
|
|
|
nsXULElement::AddPopupListener(nsIAtom* aName)
|
|
|
|
{
|
2007-07-04 19:49:38 +04:00
|
|
|
// Add a popup listener to the element
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isContext = (aName == nsGkAtoms::context ||
|
2007-07-04 19:49:38 +04:00
|
|
|
aName == nsGkAtoms::contextmenu);
|
2012-10-16 16:37:26 +04:00
|
|
|
uint32_t listenerFlag = isContext ?
|
|
|
|
XUL_ELEMENT_HAS_CONTENTMENU_LISTENER :
|
|
|
|
XUL_ELEMENT_HAS_POPUP_LISTENER;
|
|
|
|
|
|
|
|
if (HasFlag(listenerFlag)) {
|
2006-08-16 12:44:45 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-06-30 02:15:59 +04:00
|
|
|
|
2012-10-16 16:37:26 +04:00
|
|
|
nsCOMPtr<nsIDOMEventListener> listener =
|
|
|
|
new nsXULPopupListener(this, isContext);
|
1999-10-29 05:21:15 +04:00
|
|
|
|
|
|
|
// Add the popup as a listener on this element.
|
2014-03-17 10:56:53 +04:00
|
|
|
EventListenerManager* manager = GetOrCreateListenerManager();
|
2012-10-16 16:37:26 +04:00
|
|
|
SetFlags(listenerFlag);
|
2009-06-23 14:07:39 +04:00
|
|
|
|
|
|
|
if (isContext) {
|
2011-06-24 06:18:02 +04:00
|
|
|
manager->AddEventListenerByType(listener,
|
|
|
|
NS_LITERAL_STRING("contextmenu"),
|
2014-03-17 10:56:52 +04:00
|
|
|
TrustedEventsAtSystemGroupBubble());
|
2009-06-23 14:07:39 +04:00
|
|
|
} else {
|
2011-06-24 06:18:02 +04:00
|
|
|
manager->AddEventListenerByType(listener,
|
|
|
|
NS_LITERAL_STRING("mousedown"),
|
2014-03-17 10:56:52 +04:00
|
|
|
TrustedEventsAtSystemGroupBubble());
|
2009-06-23 14:07:39 +04:00
|
|
|
}
|
1999-10-29 05:21:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates
|
2007-06-28 06:48:16 +04:00
|
|
|
nsXULElement::IntrinsicState() const
|
|
|
|
{
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates state = nsStyledElement::IntrinsicState();
|
2007-06-28 06:48:16 +04:00
|
|
|
|
2011-06-01 05:46:57 +04:00
|
|
|
if (IsReadWriteTextElement()) {
|
2007-06-28 06:48:16 +04:00
|
|
|
state |= NS_EVENT_STATE_MOZ_READWRITE;
|
|
|
|
state &= ~NS_EVENT_STATE_MOZ_READONLY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
1999-10-29 05:21:15 +04:00
|
|
|
//----------------------------------------------------------------------
|
1999-10-20 22:55:32 +04:00
|
|
|
|
2012-07-14 19:28:54 +04:00
|
|
|
nsresult
|
|
|
|
nsXULElement::MakeHeavyweight(nsXULPrototypeElement* aPrototype)
|
2001-10-23 00:48:52 +04:00
|
|
|
{
|
2012-07-14 19:28:54 +04:00
|
|
|
if (!aPrototype) {
|
|
|
|
return NS_OK;
|
2001-10-23 00:48:52 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i;
|
2005-01-14 22:30:55 +03:00
|
|
|
nsresult rv;
|
2012-07-14 19:28:54 +04:00
|
|
|
for (i = 0; i < aPrototype->mNumAttributes; ++i) {
|
|
|
|
nsXULPrototypeAttribute* protoattr = &aPrototype->mAttributes[i];
|
2010-08-13 10:03:23 +04:00
|
|
|
nsAttrValue attrValue;
|
2007-04-29 21:58:52 +04:00
|
|
|
|
|
|
|
// Style rules need to be cloned.
|
2010-08-13 10:03:23 +04:00
|
|
|
if (protoattr->mValue.Type() == nsAttrValue::eCSSStyleRule) {
|
2011-04-08 05:23:46 +04:00
|
|
|
nsRefPtr<css::Rule> ruleClone =
|
2010-08-15 19:19:34 +04:00
|
|
|
protoattr->mValue.GetCSSStyleRuleValue()->Clone();
|
2007-04-29 21:58:52 +04:00
|
|
|
|
2010-08-13 10:03:23 +04:00
|
|
|
nsString stringValue;
|
|
|
|
protoattr->mValue.ToString(stringValue);
|
|
|
|
|
2011-03-11 05:48:57 +03:00
|
|
|
nsRefPtr<css::StyleRule> styleRule = do_QueryObject(ruleClone);
|
2010-08-13 10:03:23 +04:00
|
|
|
attrValue.SetTo(styleRule, &stringValue);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
attrValue.SetTo(protoattr->mValue);
|
2007-04-29 21:58:52 +04:00
|
|
|
}
|
|
|
|
|
2010-08-13 10:03:23 +04:00
|
|
|
// XXX we might wanna have a SetAndTakeAttr that takes an nsAttrName
|
2004-02-10 12:08:06 +03:00
|
|
|
if (protoattr->mName.IsAtom()) {
|
|
|
|
rv = mAttrsAndChildren.SetAndTakeAttr(protoattr->mName.Atom(), attrValue);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = mAttrsAndChildren.SetAndTakeAttr(protoattr->mName.NodeInfo(),
|
|
|
|
attrValue);
|
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-11-03 13:24:03 +03:00
|
|
|
}
|
1999-10-20 22:55:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-02-20 06:33:52 +03:00
|
|
|
nsresult
|
2011-09-29 10:19:26 +04:00
|
|
|
nsXULElement::HideWindowChrome(bool aShouldHide)
|
2002-02-20 06:33:52 +03:00
|
|
|
{
|
2014-10-03 16:29:48 +04:00
|
|
|
nsIDocument* doc = GetUncomposedDoc();
|
2010-04-30 17:12:05 +04:00
|
|
|
if (!doc || doc->GetRootElement() != this)
|
2005-01-14 22:30:55 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2007-08-21 10:44:43 +04:00
|
|
|
// only top level chrome documents can hide the window chrome
|
2008-10-05 00:00:09 +04:00
|
|
|
if (!doc->IsRootDisplayDocument())
|
2007-08-21 10:44:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-06-25 17:59:57 +04:00
|
|
|
nsIPresShell *shell = doc->GetShell();
|
2002-02-20 06:33:52 +03:00
|
|
|
|
|
|
|
if (shell) {
|
2009-12-25 00:20:05 +03: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 05:34:11 +04:00
|
|
|
|
2004-08-21 00:34:37 +04: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 05:34:11 +04:00
|
|
|
|
2007-08-21 10:44:43 +04:00
|
|
|
if (frame && presContext && presContext->IsChrome()) {
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView* view = frame->GetClosestView();
|
2002-02-20 06:33:52 +03:00
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
if (view) {
|
2006-11-23 18:55:58 +03:00
|
|
|
nsIWidget* w = view->GetWidget();
|
|
|
|
NS_ENSURE_STATE(w);
|
|
|
|
w->HideWindowChrome(aShouldHide);
|
2003-09-27 08:18:26 +04:00
|
|
|
}
|
2002-02-20 06:33:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
return NS_OK;
|
2002-02-20 06:33:52 +03:00
|
|
|
}
|
|
|
|
|
2009-10-21 11:05:34 +04:00
|
|
|
nsIWidget*
|
|
|
|
nsXULElement::GetWindowWidget()
|
2007-10-30 07:03:42 +03:00
|
|
|
{
|
2014-10-03 16:29:48 +04:00
|
|
|
nsIDocument* doc = GetComposedDoc();
|
2007-10-30 07:03:42 +03:00
|
|
|
|
|
|
|
// only top level chrome documents can set the titlebar color
|
2013-11-22 19:40:31 +04:00
|
|
|
if (doc && doc->IsRootDisplayDocument()) {
|
2007-10-30 07:03:42 +03: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 11:05:34 +04:00
|
|
|
return mainWidget;
|
2007-10-30 07:03:42 +03:00
|
|
|
}
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-10-21 11:05:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsXULElement::SetTitlebarColor(nscolor aColor, bool aActive)
|
2009-10-21 11:05:34 +04:00
|
|
|
{
|
|
|
|
nsIWidget* mainWidget = GetWindowWidget();
|
|
|
|
if (mainWidget) {
|
|
|
|
mainWidget->SetWindowTitlebarColor(aColor, aActive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-04 15:59:33 +03:00
|
|
|
class SetDrawInTitleBarEvent : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2011-09-29 10:19:26 +04:00
|
|
|
SetDrawInTitleBarEvent(nsIWidget* aWidget, bool aState)
|
2011-02-04 15:59:33 +03:00
|
|
|
: mWidget(aWidget)
|
|
|
|
, mState(aState)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
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 10:19:26 +04:00
|
|
|
bool mState;
|
2011-02-04 15:59:33 +03:00
|
|
|
};
|
|
|
|
|
2009-10-21 11:05:34 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsXULElement::SetDrawsInTitlebar(bool aState)
|
2009-10-21 11:05:34 +04:00
|
|
|
{
|
|
|
|
nsIWidget* mainWidget = GetWindowWidget();
|
|
|
|
if (mainWidget) {
|
2011-02-10 03:45:54 +03:00
|
|
|
nsContentUtils::AddScriptRunner(new SetDrawInTitleBarEvent(mainWidget, aState));
|
2009-10-21 11:05:34 +04:00
|
|
|
}
|
2007-10-30 07:03:42 +03:00
|
|
|
}
|
|
|
|
|
2013-12-17 20:11:13 +04: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 06:14:10 +03: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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-03 22:32:32 +04:00
|
|
|
class MarginSetter : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit MarginSetter(nsIWidget* aWidget) :
|
2011-08-03 22:32:32 +04:00
|
|
|
mWidget(aWidget), mMargin(-1, -1, -1, -1)
|
|
|
|
{}
|
|
|
|
MarginSetter(nsIWidget *aWidget, const nsIntMargin& aMargin) :
|
|
|
|
mWidget(aWidget), mMargin(aMargin)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
// SetNonClientMargins can dispatch native events, hence doing
|
|
|
|
// it off a script runner.
|
|
|
|
mWidget->SetNonClientMargins(mMargin);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIWidget> mWidget;
|
|
|
|
nsIntMargin mMargin;
|
|
|
|
};
|
|
|
|
|
2010-06-25 06:01:07 +04:00
|
|
|
void
|
2012-02-14 06:00:56 +04:00
|
|
|
nsXULElement::SetChromeMargins(const nsAttrValue* aValue)
|
2010-06-25 06:01:07 +04:00
|
|
|
{
|
|
|
|
if (!aValue)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIWidget* mainWidget = GetWindowWidget();
|
|
|
|
if (!mainWidget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// top, right, bottom, left - see nsAttrValue
|
|
|
|
nsIntMargin margins;
|
2012-02-14 06:00:56 +04:00
|
|
|
bool gotMargins = false;
|
2010-06-25 06:01:07 +04:00
|
|
|
|
2012-02-14 06:00:56 +04:00
|
|
|
if (aValue->Type() == nsAttrValue::eIntMarginValue) {
|
|
|
|
gotMargins = aValue->GetIntMarginValue(margins);
|
|
|
|
} else {
|
|
|
|
nsAutoString tmp;
|
|
|
|
aValue->ToString(tmp);
|
|
|
|
gotMargins = nsContentUtils::ParseIntMarginValue(tmp, margins);
|
|
|
|
}
|
|
|
|
if (gotMargins) {
|
2011-08-03 22:32:32 +04:00
|
|
|
nsContentUtils::AddScriptRunner(new MarginSetter(mainWidget, margins));
|
2010-06-25 06:01:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULElement::ResetChromeMargins()
|
|
|
|
{
|
|
|
|
nsIWidget* mainWidget = GetWindowWidget();
|
|
|
|
if (!mainWidget)
|
|
|
|
return;
|
|
|
|
// See nsIWidget
|
2011-08-03 22:32:32 +04:00
|
|
|
nsContentUtils::AddScriptRunner(new MarginSetter(mainWidget));
|
2010-06-25 06:01:07 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-01-29 21:51:55 +04:00
|
|
|
nsXULElement::BoolAttrIsTrue(nsIAtom* aName) const
|
2005-01-24 13:45:00 +03:00
|
|
|
{
|
|
|
|
const nsAttrValue* attr =
|
2012-07-14 19:28:54 +04:00
|
|
|
GetAttrInfo(kNameSpaceID_None, aName).mValue;
|
2005-01-24 13:45:00 +03:00
|
|
|
|
|
|
|
return attr && attr->Type() == nsAttrValue::eAtom &&
|
2006-12-26 20:47:52 +03:00
|
|
|
attr->GetAtomValue() == nsGkAtoms::_true;
|
2005-01-24 13:45:00 +03:00
|
|
|
}
|
|
|
|
|
2006-10-07 14:27:45 +04:00
|
|
|
void
|
|
|
|
nsXULElement::RecompileScriptEventListeners()
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t i, count = mAttrsAndChildren.AttrCount();
|
2006-10-07 14:27:45 +04: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 21:17:36 +04:00
|
|
|
if (!nsContentUtils::IsEventAttributeName(attr, EventNameType_XUL)) {
|
2006-10-07 14:27:45 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString value;
|
|
|
|
GetAttr(kNameSpaceID_None, attr, value);
|
2012-08-30 20:25:10 +04:00
|
|
|
SetEventHandler(attr, value, true);
|
2006-10-07 14:27:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-03 00:24:07 +04:00
|
|
|
bool
|
|
|
|
nsXULElement::IsEventAttributeName(nsIAtom *aName)
|
|
|
|
{
|
|
|
|
return nsContentUtils::IsEventAttributeName(aName, EventNameType_XUL);
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:51:55 +04: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 17:13:33 +03:00
|
|
|
nsXULElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-01-29 21:51:55 +04: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 17:13:33 +03:00
|
|
|
return dom::XULElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-01-29 21:51:55 +04:00
|
|
|
}
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULPrototypeNode)
|
|
|
|
|
2012-11-22 21:15:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXULPrototypeNode)
|
2007-11-02 01:51:57 +03:00
|
|
|
if (tmp->mType == nsXULPrototypeNode::eType_Element) {
|
|
|
|
static_cast<nsXULPrototypeElement*>(tmp)->Unlink();
|
|
|
|
}
|
2010-11-08 18:02:49 +03:00
|
|
|
else if (tmp->mType == nsXULPrototypeNode::eType_Script) {
|
|
|
|
static_cast<nsXULPrototypeScript*>(tmp)->UnlinkJSObjects();
|
|
|
|
}
|
2007-11-02 01:51:57 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2012-11-22 21:15:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULPrototypeNode)
|
2007-05-24 18:10:02 +04:00
|
|
|
if (tmp->mType == nsXULPrototypeNode::eType_Element) {
|
|
|
|
nsXULPrototypeElement *elem =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsXULPrototypeElement*>(tmp);
|
2012-01-24 03:25:53 +04:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mNodeInfo");
|
2014-06-20 06:01:40 +04:00
|
|
|
cb.NoteNativeChild(elem->mNodeInfo,
|
|
|
|
NS_CYCLE_COLLECTION_PARTICIPANT(NodeInfo));
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i;
|
2008-03-28 17:09:00 +03:00
|
|
|
for (i = 0; i < elem->mNumAttributes; ++i) {
|
|
|
|
const nsAttrName& name = elem->mAttributes[i].mName;
|
2012-01-24 03:25:53 +04:00
|
|
|
if (!name.IsAtom()) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb,
|
|
|
|
"mAttributes[i].mName.NodeInfo()");
|
2014-06-20 06:01:40 +04:00
|
|
|
cb.NoteNativeChild(name.NodeInfo(),
|
|
|
|
NS_CYCLE_COLLECTION_PARTICIPANT(NodeInfo));
|
2012-01-24 03:25:53 +04:00
|
|
|
}
|
2008-03-28 17:09:00 +03:00
|
|
|
}
|
2012-11-15 11:32:39 +04:00
|
|
|
ImplCycleCollectionTraverse(cb, elem->mChildren, "mChildren");
|
2007-05-24 18:10:02 +04:00
|
|
|
}
|
2007-10-29 16:45:07 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2012-11-23 23:27:06 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsXULPrototypeNode)
|
2012-07-19 13:18:01 +04:00
|
|
|
if (tmp->mType == nsXULPrototypeNode::eType_Script) {
|
2007-10-29 16:45:07 +03:00
|
|
|
nsXULPrototypeScript *script =
|
|
|
|
static_cast<nsXULPrototypeScript*>(tmp);
|
2013-05-27 15:50:49 +04:00
|
|
|
script->Trace(aCallbacks, aClosure);
|
2007-05-24 18:10:02 +04:00
|
|
|
}
|
2007-10-29 16:45:07 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
2012-05-01 02:54:16 +04:00
|
|
|
|
2012-08-24 20:50:06 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsXULPrototypeNode, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsXULPrototypeNode, Release)
|
2007-05-24 18:10:02 +04:00
|
|
|
|
1999-12-06 11:23:47 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsXULPrototypeAttribute
|
|
|
|
//
|
|
|
|
|
|
|
|
nsXULPrototypeAttribute::~nsXULPrototypeAttribute()
|
|
|
|
{
|
2003-10-30 04:40:33 +03:00
|
|
|
MOZ_COUNT_DTOR(nsXULPrototypeAttribute);
|
1999-12-06 11:23:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-29 05:21:15 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsXULPrototypeElement
|
|
|
|
//
|
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
nsresult
|
|
|
|
nsXULPrototypeElement::Serialize(nsIObjectOutputStream* aStream,
|
2013-08-20 03:24:27 +04:00
|
|
|
nsXULPrototypeDocument* aProtoDoc,
|
2014-06-20 06:01:40 +04:00
|
|
|
const nsTArray<nsRefPtr<mozilla::dom::NodeInfo>> *aNodeInfos)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2002-05-03 07:04:34 +04:00
|
|
|
// Write basic prototype data
|
|
|
|
rv = aStream->Write32(mType);
|
|
|
|
|
|
|
|
// Write Node Info
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = aNodeInfos->IndexOf(mNodeInfo);
|
2014-06-20 06:01:40 +04:00
|
|
|
NS_ASSERTION(index >= 0, "unknown mozilla::dom::NodeInfo index");
|
2012-07-27 18:03:08 +04:00
|
|
|
nsresult tmp = aStream->Write32(index);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2002-05-03 07:04:34 +04:00
|
|
|
// Write Attributes
|
2012-07-27 18:03:08 +04:00
|
|
|
tmp = aStream->Write32(mNumAttributes);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2002-05-03 07:04:34 +04:00
|
|
|
|
2002-09-04 02:31:38 +04:00
|
|
|
nsAutoString attributeValue;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i;
|
2002-05-03 07:04:34 +04:00
|
|
|
for (i = 0; i < mNumAttributes; ++i) {
|
2014-06-20 06:01:40 +04:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> ni;
|
2004-02-10 12:08:06 +03:00
|
|
|
if (mAttributes[i].mName.IsAtom()) {
|
2008-09-13 02:32:18 +04:00
|
|
|
ni = mNodeInfo->NodeInfoManager()->
|
2012-07-30 18:20:58 +04:00
|
|
|
GetNodeInfo(mAttributes[i].mName.Atom(), nullptr,
|
2011-06-14 11:56:49 +04:00
|
|
|
kNameSpaceID_None,
|
|
|
|
nsIDOMNode::ATTRIBUTE_NODE);
|
2004-02-10 12:08:06 +03:00
|
|
|
NS_ASSERTION(ni, "the nodeinfo should already exist");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ni = mAttributes[i].mName.NodeInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
index = aNodeInfos->IndexOf(ni);
|
2014-06-20 06:01:40 +04:00
|
|
|
NS_ASSERTION(index >= 0, "unknown mozilla::dom::NodeInfo index");
|
2012-07-27 18:03:08 +04:00
|
|
|
tmp = aStream->Write32(index);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2002-05-03 07:04:34 +04:00
|
|
|
|
2004-02-10 12:08:06 +03:00
|
|
|
mAttributes[i].mValue.ToString(attributeValue);
|
2012-07-27 18:03:08 +04:00
|
|
|
tmp = aStream->WriteWStringZ(attributeValue.get());
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2001-07-31 23:05:34 +04:00
|
|
|
}
|
2002-05-03 07:04:34 +04:00
|
|
|
|
|
|
|
// Now write children
|
2012-08-22 19:56:38 +04:00
|
|
|
tmp = aStream->Write32(uint32_t(mChildren.Length()));
|
2012-07-27 18:03:08 +04:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2008-10-08 15:41:52 +04:00
|
|
|
for (i = 0; i < mChildren.Length(); i++) {
|
|
|
|
nsXULPrototypeNode* child = mChildren[i].get();
|
2002-05-03 07:04:34 +04:00
|
|
|
switch (child->mType) {
|
|
|
|
case eType_Element:
|
|
|
|
case eType_Text:
|
2006-11-12 01:27:00 +03:00
|
|
|
case eType_PI:
|
2013-08-20 03:24:27 +04:00
|
|
|
tmp = child->Serialize(aStream, aProtoDoc, aNodeInfos);
|
2012-07-27 18:03:08 +04:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2002-05-03 07:04:34 +04:00
|
|
|
break;
|
|
|
|
case eType_Script:
|
2012-07-27 18:03:08 +04:00
|
|
|
tmp = aStream->Write32(child->mType);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-07-08 11:08:04 +04:00
|
|
|
nsXULPrototypeScript* script = static_cast<nsXULPrototypeScript*>(child);
|
2002-05-03 07:04:34 +04:00
|
|
|
|
2012-07-27 18:03:08 +04: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 05:34:11 +04:00
|
|
|
if (! script->mOutOfLine) {
|
2013-08-20 03:24:27 +04:00
|
|
|
tmp = script->Serialize(aStream, aProtoDoc, aNodeInfos);
|
2012-07-27 18:03:08 +04: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 05:34:11 +04:00
|
|
|
} else {
|
2012-07-27 18:03:08 +04: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 05:34:11 +04:00
|
|
|
NS_GET_IID(nsIURI),
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
2012-07-27 18:03:08 +04: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 05:34:11 +04:00
|
|
|
|
2012-08-25 00:22:23 +04:00
|
|
|
if (script->GetScriptObject()) {
|
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 05:34:11 +04:00
|
|
|
// This may return NS_OK without muxing script->mSrcURI's
|
2010-08-12 23:42:36 +04: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 05:34:11 +04:00
|
|
|
// muxed document is already there (written by a prior
|
2010-08-12 23:42:36 +04: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 05:34:11 +04:00
|
|
|
// session).
|
2013-08-20 03:24:27 +04:00
|
|
|
tmp = script->SerializeOutOfLine(aStream, aProtoDoc);
|
2012-07-27 18:03:08 +04: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 05:34:11 +04:00
|
|
|
}
|
2002-05-03 07:04:34 +04: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 05:34:11 +04:00
|
|
|
}
|
2002-05-03 07:04:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2001-07-31 23:05:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
|
2013-08-20 03:24:27 +04:00
|
|
|
nsXULPrototypeDocument* aProtoDoc,
|
2002-07-24 02:16:45 +04:00
|
|
|
nsIURI* aDocumentURI,
|
2014-06-20 06:01:40 +04:00
|
|
|
const nsTArray<nsRefPtr<mozilla::dom::NodeInfo>> *aNodeInfos)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
2002-09-04 02:31:38 +04:00
|
|
|
NS_PRECONDITION(aNodeInfos, "missing nodeinfo array");
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2002-05-03 07:04:34 +04:00
|
|
|
// Read Node Info
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t number;
|
2012-04-11 18:48:14 +04:00
|
|
|
nsresult rv = aStream->Read32(&number);
|
2014-06-20 06:01:40 +04:00
|
|
|
mNodeInfo = aNodeInfos->ElementAt(number);
|
2002-09-04 02:31:38 +04:00
|
|
|
if (!mNodeInfo)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2002-05-03 07:04:34 +04:00
|
|
|
|
|
|
|
// Read Attributes
|
2012-07-27 18:03:08 +04:00
|
|
|
nsresult tmp = aStream->Read32(&number);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
mNumAttributes = int32_t(number);
|
2003-09-27 08:18:26 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i;
|
2002-05-03 07:04:34 +04:00
|
|
|
if (mNumAttributes > 0) {
|
|
|
|
mAttributes = new nsXULPrototypeAttribute[mNumAttributes];
|
|
|
|
if (! mAttributes)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2002-11-14 21:16:31 +03:00
|
|
|
nsAutoString attributeValue;
|
2002-05-03 07:04:34 +04:00
|
|
|
for (i = 0; i < mNumAttributes; ++i) {
|
2012-07-27 18:03:08 +04:00
|
|
|
tmp = aStream->Read32(&number);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2014-06-20 06:01:40 +04:00
|
|
|
mozilla::dom::NodeInfo* ni = aNodeInfos->ElementAt(number);
|
2004-02-10 12:08:06 +03:00
|
|
|
if (!ni)
|
2002-09-04 02:31:38 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2002-05-03 07:04:34 +04:00
|
|
|
|
2004-02-10 12:08:06 +03:00
|
|
|
mAttributes[i].mName.SetTo(ni);
|
2002-05-03 07:04:34 +04:00
|
|
|
|
2012-07-27 18:03:08 +04:00
|
|
|
tmp = aStream->ReadString(attributeValue);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
|
|
|
tmp = SetAttrAt(i, attributeValue, aDocumentURI);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2002-05-03 07:04:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-27 18:03:08 +04:00
|
|
|
tmp = aStream->Read32(&number);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t numChildren = int32_t(number);
|
2002-09-25 13:56:09 +04:00
|
|
|
|
2008-10-08 15:41:52 +04:00
|
|
|
if (numChildren > 0) {
|
2013-03-21 22:56:07 +04:00
|
|
|
mChildren.SetCapacity(numChildren);
|
2002-05-03 07:04:34 +04:00
|
|
|
|
2008-10-08 15:41:52 +04:00
|
|
|
for (i = 0; i < numChildren; i++) {
|
2012-07-27 18:03:08 +04:00
|
|
|
tmp = aStream->Read32(&number);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2002-05-03 07:04:34 +04:00
|
|
|
Type childType = (Type)number;
|
|
|
|
|
2008-10-08 15:41:52 +04:00
|
|
|
nsRefPtr<nsXULPrototypeNode> child;
|
2002-05-03 07:04:34 +04:00
|
|
|
|
|
|
|
switch (childType) {
|
|
|
|
case eType_Element:
|
2002-09-25 13:56:09 +04:00
|
|
|
child = new nsXULPrototypeElement();
|
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 05:34:11 +04:00
|
|
|
if (! child)
|
2002-05-03 07:04:34 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
child->mType = childType;
|
|
|
|
|
2013-08-20 03:24:27 +04:00
|
|
|
tmp = child->Deserialize(aStream, aProtoDoc, aDocumentURI,
|
2002-09-04 02:31:38 +04:00
|
|
|
aNodeInfos);
|
2012-07-27 18:03:08 +04:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2002-05-03 07:04:34 +04:00
|
|
|
break;
|
|
|
|
case eType_Text:
|
2002-09-25 13:56:09 +04:00
|
|
|
child = new nsXULPrototypeText();
|
2002-05-03 07:04:34 +04:00
|
|
|
if (! child)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
child->mType = childType;
|
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 05:34:11 +04:00
|
|
|
|
2013-08-20 03:24:27 +04:00
|
|
|
tmp = child->Deserialize(aStream, aProtoDoc, aDocumentURI,
|
2006-11-12 01:27:00 +03:00
|
|
|
aNodeInfos);
|
2012-07-27 18:03:08 +04:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2006-11-12 01:27:00 +03:00
|
|
|
break;
|
|
|
|
case eType_PI:
|
|
|
|
child = new nsXULPrototypePI();
|
|
|
|
if (! child)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
child->mType = childType;
|
|
|
|
|
2013-08-20 03:24:27 +04:00
|
|
|
tmp = child->Deserialize(aStream, aProtoDoc, aDocumentURI,
|
2002-09-04 02:31:38 +04:00
|
|
|
aNodeInfos);
|
2012-07-27 18:03:08 +04:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2002-05-03 07:04:34 +04:00
|
|
|
break;
|
2002-11-08 07:28:04 +03:00
|
|
|
case eType_Script: {
|
2005-07-02 23:52:25 +04:00
|
|
|
// language version/options obtained during deserialization.
|
2012-04-25 02:31:28 +04:00
|
|
|
nsXULPrototypeScript* script = new nsXULPrototypeScript(0, 0);
|
2002-11-08 07:28:04 +03:00
|
|
|
if (! script)
|
2002-05-03 07:04:34 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-11-08 07:28:04 +03:00
|
|
|
child = script;
|
2002-05-03 07:04:34 +04:00
|
|
|
child->mType = childType;
|
|
|
|
|
2012-07-27 18:03:08 +04:00
|
|
|
tmp = aStream->ReadBoolean(&script->mOutOfLine);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2002-11-08 07:28:04 +03:00
|
|
|
if (! script->mOutOfLine) {
|
2013-08-20 03:24:27 +04:00
|
|
|
tmp = script->Deserialize(aStream, aProtoDoc, aDocumentURI,
|
2005-07-02 23:52:25 +04:00
|
|
|
aNodeInfos);
|
2012-07-27 18:03:08 +04:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2005-07-02 23:52:25 +04:00
|
|
|
} else {
|
2014-03-15 23:00:17 +04:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
tmp = aStream->ReadObject(true, getter_AddRefs(supports));
|
|
|
|
script->mSrcURI = do_QueryInterface(supports);
|
2012-07-27 18:03:08 +04:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2002-05-03 07:04:34 +04:00
|
|
|
|
2013-08-20 03:24:27 +04:00
|
|
|
tmp = script->DeserializeOutOfLine(aStream, aProtoDoc);
|
2012-07-27 18:03:08 +04:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2002-11-08 07:28:04 +03:00
|
|
|
}
|
2006-06-13 07:07:47 +04:00
|
|
|
// If we failed to deserialize, consider deleting 'script'?
|
2002-05-03 07:04:34 +04:00
|
|
|
break;
|
|
|
|
}
|
2006-12-30 14:10:24 +03:00
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unexpected child type!");
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
2002-11-08 07:28:04 +03:00
|
|
|
}
|
2002-05-03 07:04:34 +04:00
|
|
|
|
2008-10-08 15:41:52 +04:00
|
|
|
mChildren.AppendElement(child);
|
2002-06-09 14:31:00 +04: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 05:34:11 +04:00
|
|
|
// Oh dear. Something failed during the deserialization.
|
|
|
|
// We don't know what. But likely consequences of failed
|
2010-08-12 23:42:36 +04: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 05:34:11 +04: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.
|
2002-06-09 14:31:00 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-05-03 07:04:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2001-07-31 23:05:34 +04:00
|
|
|
}
|
|
|
|
|
1999-10-29 05:21:15 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXULPrototypeElement::SetAttrAt(uint32_t aPos, const nsAString& aValue,
|
2004-02-10 12:08:06 +03:00
|
|
|
nsIURI* aDocumentURI)
|
1999-10-29 05:21:15 +04:00
|
|
|
{
|
2004-02-10 12:08:06 +03: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 05:06:28 +03:00
|
|
|
mAttributes[aPos].mValue.ParseStringOrAtom(aValue);
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2004-02-10 12:08:06 +03:00
|
|
|
return NS_OK;
|
1999-10-29 05:21:15 +04:00
|
|
|
}
|
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (mAttributes[aPos].mName.Equals(nsGkAtoms::id) &&
|
2004-02-10 12:08:06 +03:00
|
|
|
!aValue.IsEmpty()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mHasIdAttribute = true;
|
2004-02-10 12:08:06 +03:00
|
|
|
// Store id as atom.
|
|
|
|
// id="" means that the element has no id. Not that it has
|
|
|
|
// emptystring as id.
|
2004-03-04 05:06:28 +03:00
|
|
|
mAttributes[aPos].mValue.ParseAtom(aValue);
|
2004-02-10 12:08:06 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (mAttributes[aPos].mName.Equals(nsGkAtoms::_class)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mHasClassAttribute = true;
|
2004-02-10 12:08:06 +03:00
|
|
|
// Compute the element's class list
|
2004-03-04 05:06:28 +03:00
|
|
|
mAttributes[aPos].mValue.ParseAtomArray(aValue);
|
2010-03-02 23:59:32 +03:00
|
|
|
|
2004-03-04 05:06:28 +03:00
|
|
|
return NS_OK;
|
2004-02-10 12:08:06 +03:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (mAttributes[aPos].mName.Equals(nsGkAtoms::style)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mHasStyleAttribute = true;
|
2004-02-10 12:08:06 +03:00
|
|
|
// Parse the element's 'style' attribute
|
2011-03-11 05:48:57 +03:00
|
|
|
nsRefPtr<css::StyleRule> rule;
|
2010-03-02 23:59:32 +03:00
|
|
|
|
|
|
|
nsCSSParser parser;
|
2004-02-10 12:08:06 +03:00
|
|
|
|
2004-09-11 03:31:48 +04:00
|
|
|
// XXX Get correct Base URI (need GetBaseURI on *prototype* element)
|
2012-08-30 21:58:24 +04: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.
|
2010-03-02 23:59:32 +03:00
|
|
|
parser.ParseStyleAttribute(aValue, aDocumentURI, aDocumentURI,
|
|
|
|
// This is basically duplicating what
|
|
|
|
// nsINode::NodePrincipal() does
|
|
|
|
mNodeInfo->NodeInfoManager()->
|
|
|
|
DocumentPrincipal(),
|
|
|
|
getter_AddRefs(rule));
|
2004-02-10 12:08:06 +03:00
|
|
|
if (rule) {
|
2010-08-13 10:03:23 +04:00
|
|
|
mAttributes[aPos].mValue.SetTo(rule, &aValue);
|
2004-02-10 12:08:06 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// Don't abort if parsing failed, it could just be malformed css.
|
|
|
|
}
|
|
|
|
|
2004-03-04 05:06:28 +03:00
|
|
|
mAttributes[aPos].mValue.ParseStringOrAtom(aValue);
|
2004-02-10 12:08:06 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-18 05:25:33 +03:00
|
|
|
|
2007-10-29 16:45:07 +03:00
|
|
|
void
|
2010-11-08 18:02:49 +03:00
|
|
|
nsXULPrototypeElement::Unlink()
|
2007-10-29 16:45:07 +03:00
|
|
|
{
|
|
|
|
mNumAttributes = 0;
|
|
|
|
delete[] mAttributes;
|
2012-07-30 18:20:58 +04:00
|
|
|
mAttributes = nullptr;
|
2013-08-07 04:37:05 +04:00
|
|
|
mChildren.Clear();
|
2007-10-29 16:45:07 +03:00
|
|
|
}
|
|
|
|
|
2012-08-25 00:22:23 +04: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-29 00:37:22 +04:00
|
|
|
static_cast<nsXULPrototypeScript*>(child)->TraceScriptObject(aTrc);
|
2012-08-25 00:22:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-06 11:23:47 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsXULPrototypeScript
|
|
|
|
//
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXULPrototypeScript::nsXULPrototypeScript(uint32_t aLineNo, uint32_t aVersion)
|
2002-09-25 13:56:09 +04:00
|
|
|
: nsXULPrototypeNode(eType_Script),
|
|
|
|
mLineNo(aLineNo),
|
2011-10-17 18:59:28 +04:00
|
|
|
mSrcLoading(false),
|
|
|
|
mOutOfLine(true),
|
2012-07-30 18:20:58 +04:00
|
|
|
mSrcLoadWaiters(nullptr),
|
2006-06-27 01:12:32 +04:00
|
|
|
mLangVersion(aVersion),
|
2012-08-25 00:22:23 +04:00
|
|
|
mScriptObject(nullptr)
|
1999-11-18 05:25:33 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsXULPrototypeScript::~nsXULPrototypeScript()
|
|
|
|
{
|
2008-01-30 05:05:43 +03:00
|
|
|
UnlinkJSObjects();
|
1999-11-18 05:25:33 +03:00
|
|
|
}
|
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
nsresult
|
|
|
|
nsXULPrototypeScript::Serialize(nsIObjectOutputStream* aStream,
|
2013-08-20 03:24:27 +04:00
|
|
|
nsXULPrototypeDocument* aProtoDoc,
|
2014-06-20 06:01:40 +04:00
|
|
|
const nsTArray<nsRefPtr<mozilla::dom::NodeInfo>> *aNodeInfos)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
2014-04-15 01:40:49 +04:00
|
|
|
NS_ENSURE_TRUE(aProtoDoc, NS_ERROR_UNEXPECTED);
|
2013-08-20 03:24:27 +04:00
|
|
|
AutoSafeJSContext cx;
|
2014-08-18 21:57:30 +04:00
|
|
|
JS::Rooted<JSObject*> global(cx, xpc::CompilationScope());
|
2013-08-20 03:24:27 +04:00
|
|
|
NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED);
|
|
|
|
JSAutoCompartment ac(cx, global);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(!mSrcLoading || mSrcLoadWaiters != nullptr ||
|
2012-08-25 00:22:23 +04:00
|
|
|
!mScriptObject,
|
2002-11-08 01:46:38 +03:00
|
|
|
"script source still loading when serializing?!");
|
2012-08-25 00:22:23 +04:00
|
|
|
if (!mScriptObject)
|
2002-11-08 01:46:38 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2002-05-03 07:04:34 +04:00
|
|
|
// Write basic prototype data
|
2006-06-13 07:07:47 +04:00
|
|
|
nsresult rv;
|
|
|
|
rv = aStream->Write32(mLineNo);
|
2001-07-31 23:05:34 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2006-06-13 07:07:47 +04:00
|
|
|
rv = aStream->Write32(mLangVersion);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2013-07-23 13:58:28 +04:00
|
|
|
|
|
|
|
// Calling fromMarkedLocation() is safe because we trace mScriptObject in
|
|
|
|
// TraceScriptObject() and because its value is never changed after it has
|
|
|
|
// been set.
|
2013-07-23 13:58:27 +04:00
|
|
|
JS::Handle<JSScript*> script =
|
|
|
|
JS::Handle<JSScript*>::fromMarkedLocation(mScriptObject.address());
|
2014-08-18 21:57:30 +04:00
|
|
|
MOZ_ASSERT(xpc::CompilationScope() == JS::CurrentGlobalOrNull(cx));
|
2013-08-20 03:24:27 +04:00
|
|
|
return nsContentUtils::XPConnect()->WriteScript(aStream, cx,
|
|
|
|
xpc_UnmarkGrayScript(script));
|
2001-07-31 23:05:34 +04: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 05:34:11 +04:00
|
|
|
nsresult
|
|
|
|
nsXULPrototypeScript::SerializeOutOfLine(nsIObjectOutputStream* aStream,
|
2013-08-20 03:24:27 +04: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 05:34:11 +04:00
|
|
|
{
|
2010-08-12 23:42:36 +04:00
|
|
|
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isChrome = false;
|
2010-08-12 23:42:36 +04: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 08:53:33 +03: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 05:34:11 +04:00
|
|
|
|
2007-03-12 08:53:33 +03:00
|
|
|
NS_ASSERTION(cache->IsEnabled(),
|
2010-08-12 23:42:36 +04:00
|
|
|
"writing to the cache file, but the XUL cache is off?");
|
2011-09-29 10:19:26 +04:00
|
|
|
bool exists;
|
2010-08-12 23:42:36 +04:00
|
|
|
cache->HasData(mSrcURI, &exists);
|
2013-07-23 13:58:27 +04:00
|
|
|
|
2005-06-01 22:33:20 +04: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 05:34:11 +04:00
|
|
|
if (exists)
|
2005-06-01 22:33:20 +04: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 05:34:11 +04:00
|
|
|
|
2010-08-12 23:42:36 +04:00
|
|
|
nsCOMPtr<nsIObjectOutputStream> oos;
|
|
|
|
rv = cache->GetOutputStream(mSrcURI, getter_AddRefs(oos));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-08-20 03:24:27 +04:00
|
|
|
nsresult tmp = Serialize(oos, aProtoDoc, nullptr);
|
2012-07-27 18:03:08 +04: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 05:34:11 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
2010-08-12 23:42:36 +04: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 05:34:11 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
nsresult
|
|
|
|
nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream,
|
2013-08-20 03:24:27 +04:00
|
|
|
nsXULPrototypeDocument* aProtoDoc,
|
2002-07-24 02:16:45 +04:00
|
|
|
nsIURI* aDocumentURI,
|
2014-06-20 06:01:40 +04:00
|
|
|
const nsTArray<nsRefPtr<mozilla::dom::NodeInfo>> *aNodeInfos)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(!mSrcLoading || mSrcLoadWaiters != nullptr ||
|
2012-08-25 00:22:23 +04:00
|
|
|
!mScriptObject,
|
2001-07-31 23:05:34 +04: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 05:34:11 +04:00
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
// Read basic prototype data
|
|
|
|
aStream->Read32(&mLineNo);
|
|
|
|
aStream->Read32(&mLangVersion);
|
|
|
|
|
2013-08-20 03:24:27 +04:00
|
|
|
AutoSafeJSContext cx;
|
2014-08-18 21:57:30 +04:00
|
|
|
JS::Rooted<JSObject*> global(cx, xpc::CompilationScope());
|
2013-08-20 03:24:27 +04:00
|
|
|
NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED);
|
|
|
|
JSAutoCompartment ac(cx, global);
|
|
|
|
|
2013-08-20 03:24:27 +04:00
|
|
|
JS::Rooted<JSScript*> newScriptObject(cx);
|
|
|
|
nsresult rv = nsContentUtils::XPConnect()->ReadScript(aStream, cx,
|
|
|
|
newScriptObject.address());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-10-29 16:45:07 +03:00
|
|
|
Set(newScriptObject);
|
2001-07-31 23:05:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-05-03 07:04:34 +04: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 05:34:11 +04:00
|
|
|
nsXULPrototypeScript::DeserializeOutOfLine(nsIObjectInputStream* aInput,
|
2013-08-20 03:24:27 +04:00
|
|
|
nsXULPrototypeDocument* aProtoDoc)
|
2002-05-03 07:04:34 +04:00
|
|
|
{
|
2010-08-12 23:42:36 +04:00
|
|
|
// Keep track of failure via rv, so we can
|
|
|
|
// AbortCaching if things look bad.
|
2002-06-09 14:31:00 +04:00
|
|
|
nsresult rv = NS_OK;
|
2007-03-12 08:53:33 +03:00
|
|
|
nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
|
2010-08-12 23:42:36 +04:00
|
|
|
|
2003-01-17 13:04:49 +03:00
|
|
|
nsCOMPtr<nsIObjectInputStream> objectInput = aInput;
|
2010-08-12 23:42:36 +04:00
|
|
|
if (cache) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool useXULCache = true;
|
2002-05-03 07:04:34 +04:00
|
|
|
if (mSrcURI) {
|
|
|
|
// NB: we must check the XUL script cache early, to avoid
|
2010-08-12 23:42:36 +04:00
|
|
|
// multiple deserialization attempts for a given script.
|
2013-03-26 19:31:53 +04:00
|
|
|
// Note that XULDocument::LoadScript
|
2002-05-03 07:04:34 +04: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 23:42:36 +04:00
|
|
|
// different XUL documents stored in the cache file.
|
2007-03-12 08:53:33 +03:00
|
|
|
useXULCache = cache->IsEnabled();
|
2002-05-03 07:04:34 +04:00
|
|
|
|
|
|
|
if (useXULCache) {
|
2011-10-30 00:13:31 +04:00
|
|
|
JSScript* newScriptObject =
|
2012-04-25 02:31:28 +04:00
|
|
|
cache->GetScript(mSrcURI);
|
|
|
|
if (newScriptObject)
|
2007-10-29 16:45:07 +03:00
|
|
|
Set(newScriptObject);
|
2002-05-03 07:04:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-25 00:22:23 +04:00
|
|
|
if (!mScriptObject) {
|
2002-05-03 07:04:34 +04:00
|
|
|
if (mSrcURI) {
|
2010-08-12 23:42:36 +04:00
|
|
|
rv = cache->GetInputStream(mSrcURI, getter_AddRefs(objectInput));
|
|
|
|
}
|
|
|
|
// If !mSrcURI, we have an inline script. We shouldn't have
|
|
|
|
// to do anything else in that case, I think.
|
|
|
|
|
2003-01-17 13:04:49 +03:00
|
|
|
// We do reflect errors into rv, but our caller may want to
|
2006-06-13 07:07:47 +04:00
|
|
|
// ignore our return value, because mScriptObject will be null
|
2003-01-17 13:04:49 +03:00
|
|
|
// after any error, and that suffices to cause the script to
|
2002-05-03 07:04:34 +04: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 23:42:36 +04:00
|
|
|
// error.
|
2002-05-03 07:04:34 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2013-08-20 03:24:27 +04:00
|
|
|
rv = Deserialize(objectInput, aProtoDoc, nullptr, nullptr);
|
2002-05-03 07:04:34 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (useXULCache && mSrcURI) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isChrome = false;
|
2002-05-03 07:04:34 +04:00
|
|
|
mSrcURI->SchemeIs("chrome", &isChrome);
|
2012-04-25 02:31:28 +04:00
|
|
|
if (isChrome)
|
2013-05-20 16:40:06 +04:00
|
|
|
cache->PutScript(mSrcURI, GetScriptObject());
|
2002-05-03 07:04:34 +04:00
|
|
|
}
|
2010-08-12 23:42:36 +04:00
|
|
|
cache->FinishInputStream(mSrcURI);
|
2002-05-03 07:04:34 +04:00
|
|
|
} else {
|
2010-08-12 23:42:36 +04:00
|
|
|
// If mSrcURI is not in the cache,
|
2002-05-03 07:04:34 +04:00
|
|
|
// rv will be NS_ERROR_NOT_AVAILABLE and we'll try to
|
2010-08-12 23:42:36 +04:00
|
|
|
// update the cache file to hold a serialization of
|
2002-05-03 07:04:34 +04:00
|
|
|
// this script, once it has finished loading.
|
|
|
|
if (rv != NS_ERROR_NOT_AVAILABLE)
|
2010-08-12 23:42:36 +04:00
|
|
|
cache->AbortCaching();
|
2002-05-03 07:04:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-06-09 14:31:00 +04:00
|
|
|
return rv;
|
2002-05-03 07:04:34 +04:00
|
|
|
}
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2013-08-16 01:14:43 +04:00
|
|
|
class NotifyOffThreadScriptCompletedRunnable : public nsRunnable
|
|
|
|
{
|
|
|
|
nsRefPtr<nsIOffThreadScriptReceiver> mReceiver;
|
2013-08-29 19:56:05 +04:00
|
|
|
void *mToken;
|
2013-08-16 01:14:43 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
NotifyOffThreadScriptCompletedRunnable(already_AddRefed<nsIOffThreadScriptReceiver> aReceiver,
|
2013-08-29 19:56:05 +04:00
|
|
|
void *aToken)
|
|
|
|
: mReceiver(aReceiver), mToken(aToken)
|
2013-08-16 01:14:43 +04:00
|
|
|
{}
|
|
|
|
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
NotifyOffThreadScriptCompletedRunnable::Run()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
// Note: this unroots mScript so that it is available to be collected by the
|
|
|
|
// JS GC. The receiver needs to root the script before performing a call that
|
|
|
|
// could GC.
|
2013-09-11 03:18:30 +04:00
|
|
|
JSScript *script;
|
|
|
|
{
|
|
|
|
AutoSafeJSContext cx;
|
2014-08-18 21:57:30 +04:00
|
|
|
JSAutoCompartment ac(cx, xpc::CompilationScope());
|
2013-09-11 03:18:30 +04:00
|
|
|
script = JS::FinishOffThreadScript(cx, JS_GetRuntime(cx), mToken);
|
|
|
|
}
|
2013-08-16 01:14:43 +04:00
|
|
|
|
2013-08-29 19:56:05 +04:00
|
|
|
return mReceiver->OnScriptCompileComplete(script, script ? NS_OK : NS_ERROR_FAILURE);
|
2013-08-16 01:14:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-08-29 19:56:05 +04:00
|
|
|
OffThreadScriptReceiverCallback(void *aToken, void *aCallbackData)
|
2013-08-16 01:14:43 +04:00
|
|
|
{
|
|
|
|
// Be careful not to adjust the refcount on the receiver, as this callback
|
|
|
|
// may be invoked off the main thread.
|
2013-08-29 19:56:05 +04:00
|
|
|
nsIOffThreadScriptReceiver* aReceiver = static_cast<nsIOffThreadScriptReceiver*>(aCallbackData);
|
2013-08-16 01:14:43 +04:00
|
|
|
nsRefPtr<NotifyOffThreadScriptCompletedRunnable> notify =
|
|
|
|
new NotifyOffThreadScriptCompletedRunnable(
|
2013-08-29 19:56:05 +04:00
|
|
|
already_AddRefed<nsIOffThreadScriptReceiver>(aReceiver), aToken);
|
2013-08-16 01:14:43 +04:00
|
|
|
NS_DispatchToMainThread(notify);
|
|
|
|
}
|
|
|
|
|
1999-11-18 05:25:33 +03:00
|
|
|
nsresult
|
2014-04-25 18:11:57 +04:00
|
|
|
nsXULPrototypeScript::Compile(JS::SourceBufferHolder& aSrcBuf,
|
2014-05-27 18:15:00 +04:00
|
|
|
nsIURI* aURI, uint32_t aLineNo,
|
1999-12-17 03:06:28 +03:00
|
|
|
nsIDocument* aDocument,
|
2013-08-16 01:14:43 +04:00
|
|
|
nsIOffThreadScriptReceiver *aOffThreadReceiver /* = nullptr */)
|
1999-11-18 05:25:33 +03:00
|
|
|
{
|
2014-04-20 22:48:14 +04:00
|
|
|
// We'll compile the script in the compilation scope.
|
2013-08-20 03:24:27 +04:00
|
|
|
AutoSafeJSContext cx;
|
2014-08-18 21:57:30 +04:00
|
|
|
JSAutoCompartment ac(cx, xpc::CompilationScope());
|
2000-01-23 01:00:35 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString urlspec;
|
2008-11-14 03:00:11 +03:00
|
|
|
nsContentUtils::GetWrapperSafeScriptFilename(aDocument, aURI, urlspec);
|
1999-12-17 03:06:28 +03:00
|
|
|
|
2000-01-23 01:00:35 +03:00
|
|
|
// Ok, compile it to create a prototype script object!
|
2013-08-09 03:51:34 +04:00
|
|
|
NS_ENSURE_TRUE(JSVersion(mLangVersion) != JSVERSION_UNKNOWN, NS_OK);
|
|
|
|
JS::CompileOptions options(cx);
|
2014-03-13 00:10:02 +04:00
|
|
|
options.setIntroductionType("scriptElement")
|
|
|
|
.setFileAndLine(urlspec.get(), aLineNo)
|
2013-08-09 03:51:34 +04:00
|
|
|
.setVersion(JSVersion(mLangVersion));
|
2012-08-07 21:39:47 +04: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-23 01:08:27 +04:00
|
|
|
options.setSourceIsLazy(mOutOfLine);
|
2013-11-11 12:04:41 +04:00
|
|
|
JS::Rooted<JSObject*> scope(cx, JS::CurrentGlobalOrNull(cx));
|
2013-09-09 07:28:48 +04:00
|
|
|
if (scope) {
|
|
|
|
JS::ExposeObjectToActiveJS(scope);
|
|
|
|
}
|
2013-08-16 01:14:43 +04:00
|
|
|
|
2014-04-25 18:11:57 +04:00
|
|
|
if (aOffThreadReceiver && JS::CanCompileOffThread(cx, options, aSrcBuf.length())) {
|
2014-04-11 19:47:43 +04:00
|
|
|
if (!JS::CompileOffThread(cx, options,
|
2014-04-25 18:11:57 +04:00
|
|
|
aSrcBuf.get(), aSrcBuf.length(),
|
2013-08-16 01:14:43 +04:00
|
|
|
OffThreadScriptReceiverCallback,
|
|
|
|
static_cast<void*>(aOffThreadReceiver))) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
// This reference will be consumed by the NotifyOffThreadScriptCompletedRunnable.
|
|
|
|
NS_ADDREF(aOffThreadReceiver);
|
|
|
|
} else {
|
2014-06-12 04:38:22 +04:00
|
|
|
JS::Rooted<JSScript*> script(cx);
|
2015-03-19 17:13:34 +03:00
|
|
|
if (!JS::Compile(cx, options, aSrcBuf, &script))
|
2013-08-16 01:14:43 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
Set(script);
|
|
|
|
}
|
2013-08-09 03:51:34 +04:00
|
|
|
return NS_OK;
|
1999-11-18 05:25:33 +03:00
|
|
|
}
|
2002-05-03 07:04:34 +04:00
|
|
|
|
2014-04-25 18:11:57 +04: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 18:15:00 +04:00
|
|
|
return Compile(srcBuf, aURI, aLineNo, aDocument, aOffThreadReceiver);
|
2014-04-25 18:11:57 +04:00
|
|
|
}
|
|
|
|
|
2011-08-11 17:29:50 +04:00
|
|
|
void
|
|
|
|
nsXULPrototypeScript::UnlinkJSObjects()
|
|
|
|
{
|
2012-08-25 00:22:23 +04:00
|
|
|
if (mScriptObject) {
|
|
|
|
mScriptObject = nullptr;
|
2013-08-17 00:10:17 +04:00
|
|
|
mozilla::DropJSObjects(this);
|
2011-08-11 17:29:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-10-30 00:13:31 +04:00
|
|
|
nsXULPrototypeScript::Set(JSScript* aObject)
|
2011-08-11 17:29:50 +04:00
|
|
|
{
|
2012-08-25 00:22:23 +04:00
|
|
|
MOZ_ASSERT(!mScriptObject, "Leaking script object.");
|
2011-08-11 17:29:50 +04:00
|
|
|
if (!aObject) {
|
2012-08-25 00:22:23 +04:00
|
|
|
mScriptObject = nullptr;
|
2011-08-11 17:29:50 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-20 16:40:06 +04:00
|
|
|
mScriptObject = aObject;
|
2013-08-17 00:10:17 +04:00
|
|
|
mozilla::HoldJSObjects(this);
|
2011-08-11 17:29:50 +04:00
|
|
|
}
|
|
|
|
|
2002-05-03 07:04:34 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsXULPrototypeText
|
|
|
|
//
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypeText::Serialize(nsIObjectOutputStream* aStream,
|
2013-08-20 03:24:27 +04:00
|
|
|
nsXULPrototypeDocument* aProtoDoc,
|
2014-06-20 06:01:40 +04:00
|
|
|
const nsTArray<nsRefPtr<mozilla::dom::NodeInfo>> *aNodeInfos)
|
2002-05-03 07:04:34 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Write basic prototype data
|
|
|
|
rv = aStream->Write32(mType);
|
|
|
|
|
2012-07-27 18:03:08 +04:00
|
|
|
nsresult tmp = aStream->WriteWStringZ(mValue.get());
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2002-05-03 07:04:34 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypeText::Deserialize(nsIObjectInputStream* aStream,
|
2013-08-20 03:24:27 +04:00
|
|
|
nsXULPrototypeDocument* aProtoDoc,
|
2002-07-24 02:16:45 +04:00
|
|
|
nsIURI* aDocumentURI,
|
2014-06-20 06:01:40 +04:00
|
|
|
const nsTArray<nsRefPtr<mozilla::dom::NodeInfo>> *aNodeInfos)
|
2002-05-03 07:04:34 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2006-11-08 20:52:58 +03:00
|
|
|
rv = aStream->ReadString(mValue);
|
2006-11-08 05:25:37 +03:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2006-11-12 01:27:00 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsXULPrototypePI
|
|
|
|
//
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypePI::Serialize(nsIObjectOutputStream* aStream,
|
2013-08-20 03:24:27 +04:00
|
|
|
nsXULPrototypeDocument* aProtoDoc,
|
2014-06-20 06:01:40 +04:00
|
|
|
const nsTArray<nsRefPtr<mozilla::dom::NodeInfo>> *aNodeInfos)
|
2006-11-12 01:27:00 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Write basic prototype data
|
|
|
|
rv = aStream->Write32(mType);
|
|
|
|
|
2012-07-27 18:03:08 +04: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-12 01:27:00 +03:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypePI::Deserialize(nsIObjectInputStream* aStream,
|
2013-08-20 03:24:27 +04:00
|
|
|
nsXULPrototypeDocument* aProtoDoc,
|
2006-11-12 01:27:00 +03:00
|
|
|
nsIURI* aDocumentURI,
|
2014-06-20 06:01:40 +04:00
|
|
|
const nsTArray<nsRefPtr<mozilla::dom::NodeInfo>> *aNodeInfos)
|
2006-11-12 01:27:00 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = aStream->ReadString(mTarget);
|
2012-07-27 18:03:08 +04:00
|
|
|
nsresult tmp = aStream->ReadString(mData);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2006-11-12 01:27:00 +03:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|