2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2007-01-30 00:06:41 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2001-10-19 21:00:02 +00:00
|
|
|
#include "nsUnicharUtils.h"
|
2013-01-08 20:45:06 +00:00
|
|
|
#include "mozilla/dom/ProcessingInstruction.h"
|
2013-01-08 20:45:06 +00:00
|
|
|
#include "mozilla/dom/ProcessingInstructionBinding.h"
|
2013-04-04 12:01:11 +00:00
|
|
|
#include "mozilla/dom/XMLStylesheetProcessingInstruction.h"
|
2014-03-27 20:38:33 +00:00
|
|
|
#include "mozilla/IntegerPrintfMacros.h"
|
2012-02-27 11:57:48 +00:00
|
|
|
#include "nsContentUtils.h"
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2013-04-04 12:01:11 +00:00
|
|
|
already_AddRefed<mozilla::dom::ProcessingInstruction>
|
|
|
|
NS_NewXMLProcessingInstruction(nsNodeInfoManager *aNodeInfoManager,
|
2002-03-23 22:46:13 +00:00
|
|
|
const nsAString& aTarget,
|
2005-09-24 18:43:15 +00:00
|
|
|
const nsAString& aData)
|
1999-03-31 20:49:25 +00:00
|
|
|
{
|
2013-01-08 20:45:06 +00:00
|
|
|
using mozilla::dom::ProcessingInstruction;
|
2013-04-04 12:01:11 +00:00
|
|
|
using mozilla::dom::XMLStylesheetProcessingInstruction;
|
2013-01-08 20:45:06 +00:00
|
|
|
|
2005-09-24 18:43:15 +00:00
|
|
|
NS_PRECONDITION(aNodeInfoManager, "Missing nodeinfo manager");
|
|
|
|
|
2016-03-28 23:09:43 +00:00
|
|
|
nsCOMPtr<nsIAtom> target = NS_Atomize(aTarget);
|
2013-04-04 12:01:11 +00:00
|
|
|
MOZ_ASSERT(target);
|
2011-06-14 07:56:49 +00:00
|
|
|
|
|
|
|
if (target == nsGkAtoms::xml_stylesheet) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<XMLStylesheetProcessingInstruction> pi =
|
2013-04-04 12:01:11 +00:00
|
|
|
new XMLStylesheetProcessingInstruction(aNodeInfoManager, aData);
|
|
|
|
return pi.forget();
|
2002-09-04 06:57:25 +00:00
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> ni;
|
2008-09-12 22:32:18 +00:00
|
|
|
ni = aNodeInfoManager->GetNodeInfo(nsGkAtoms::processingInstructionTagName,
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr, kNameSpaceID_None,
|
2011-06-14 07:56:49 +00:00
|
|
|
nsIDOMNode::PROCESSING_INSTRUCTION_NODE,
|
|
|
|
target);
|
2005-09-24 18:43:15 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ProcessingInstruction> instance =
|
2013-01-08 20:45:06 +00:00
|
|
|
new ProcessingInstruction(ni.forget(), aData);
|
2004-08-10 10:22:36 +00:00
|
|
|
|
2013-04-04 12:01:11 +00:00
|
|
|
return instance.forget();
|
1999-03-31 20:49:25 +00:00
|
|
|
}
|
|
|
|
|
2013-01-08 20:45:06 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
ProcessingInstruction::ProcessingInstruction(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2013-01-08 20:45:06 +00:00
|
|
|
const nsAString& aData)
|
2014-03-15 19:00:17 +00:00
|
|
|
: nsGenericDOMDataNode(Move(aNodeInfo))
|
1999-03-31 20:49:25 +00:00
|
|
|
{
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(mNodeInfo->NodeType() == nsIDOMNode::PROCESSING_INSTRUCTION_NODE,
|
|
|
|
"Bad NodeType in aNodeInfo");
|
2011-06-14 07:56:49 +00:00
|
|
|
|
2008-03-05 07:14:42 +00:00
|
|
|
SetTextInternal(0, mText.GetLength(),
|
|
|
|
aData.BeginReading(), aData.Length(),
|
2011-10-17 14:59:28 +00:00
|
|
|
false); // Don't notify (bug 420429).
|
1999-03-31 20:49:25 +00:00
|
|
|
}
|
|
|
|
|
2013-01-08 20:45:06 +00:00
|
|
|
ProcessingInstruction::~ProcessingInstruction()
|
1999-03-31 20:49:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(ProcessingInstruction, nsGenericDOMDataNode,
|
|
|
|
nsIDOMNode, nsIDOMCharacterData,
|
|
|
|
nsIDOMProcessingInstruction)
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2013-01-08 20:45:06 +00:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
ProcessingInstruction::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-01-08 20:45:06 +00:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
return ProcessingInstructionBinding::Wrap(aCx, this, aGivenProto);
|
2013-01-08 20:45:06 +00:00
|
|
|
}
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2000-05-14 02:11:44 +00:00
|
|
|
NS_IMETHODIMP
|
2013-01-08 20:45:06 +00:00
|
|
|
ProcessingInstruction::GetTarget(nsAString& aTarget)
|
1999-03-31 20:49:25 +00:00
|
|
|
{
|
2011-06-14 07:56:49 +00:00
|
|
|
aTarget = NodeName();
|
1999-03-31 20:49:25 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2013-01-08 20:45:06 +00:00
|
|
|
ProcessingInstruction::GetAttrValue(nsIAtom *aName, nsAString& aValue)
|
2000-05-14 02:11:44 +00:00
|
|
|
{
|
|
|
|
nsAutoString data;
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
GetData(data);
|
2012-02-27 11:57:48 +00:00
|
|
|
return nsContentUtils::GetPseudoAttributeValue(data, aName, aValue);
|
2000-05-14 02:11:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2013-01-08 20:45:06 +00:00
|
|
|
ProcessingInstruction::IsNodeOfType(uint32_t aFlags) const
|
2003-08-01 11:44:17 +00:00
|
|
|
{
|
2006-07-19 04:36:36 +00:00
|
|
|
return !(aFlags & ~(eCONTENT | ePROCESSING_INSTRUCTION | eDATA_NODE));
|
2003-08-01 11:44:17 +00:00
|
|
|
}
|
|
|
|
|
2005-09-11 17:15:08 +00:00
|
|
|
nsGenericDOMDataNode*
|
2014-06-20 02:01:40 +00:00
|
|
|
ProcessingInstruction::CloneDataNode(mozilla::dom::NodeInfo *aNodeInfo,
|
2013-01-08 20:45:06 +00:00
|
|
|
bool aCloneText) const
|
1999-03-31 20:49:25 +00:00
|
|
|
{
|
2001-12-16 06:59:31 +00:00
|
|
|
nsAutoString data;
|
2005-09-12 07:34:25 +00:00
|
|
|
nsGenericDOMDataNode::GetData(data);
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
|
2013-01-08 20:45:06 +00:00
|
|
|
return new ProcessingInstruction(ni.forget(), data);
|
2004-05-07 20:55:17 +00:00
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
#ifdef DEBUG
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
2013-01-08 20:45:06 +00:00
|
|
|
ProcessingInstruction::List(FILE* out, int32_t aIndent) const
|
1999-03-31 20:49:25 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t index;
|
1999-03-31 20:49:25 +00:00
|
|
|
for (index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
2014-03-27 20:38:33 +00:00
|
|
|
fprintf(out, "Processing instruction refcount=%" PRIuPTR "<", mRefCnt.get());
|
1999-03-31 20:49:25 +00:00
|
|
|
|
|
|
|
nsAutoString tmp;
|
2001-12-16 06:59:31 +00:00
|
|
|
ToCString(tmp, 0, mText.GetLength());
|
2011-06-14 07:56:49 +00:00
|
|
|
tmp.Insert(nsDependentAtomString(NodeInfo()->GetExtraName()).get(), 0);
|
2006-02-03 14:18:39 +00:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
|
1999-03-31 20:49:25 +00:00
|
|
|
|
|
|
|
fputs(">\n", out);
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
2013-01-08 20:45:06 +00:00
|
|
|
ProcessingInstruction::DumpContent(FILE* out, int32_t aIndent,
|
|
|
|
bool aDumpAll) const
|
2004-01-09 23:54:21 +00:00
|
|
|
{
|
2000-05-26 19:45:54 +00:00
|
|
|
}
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
2013-01-08 20:45:06 +00:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|