2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2002-09-04 10:57:25 +04:00
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
#include "XMLStylesheetProcessingInstruction.h"
|
2013-02-01 16:28:37 +04:00
|
|
|
#include "mozilla/dom/XMLStylesheetProcessingInstructionBinding.h"
|
2014-03-17 10:56:53 +04:00
|
|
|
#include "nsContentUtils.h"
|
2002-09-04 10:57:25 +04:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2002-09-04 10:57:25 +04:00
|
|
|
|
|
|
|
// nsISupports implementation
|
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(XMLStylesheetProcessingInstruction)
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(XMLStylesheetProcessingInstruction, nsIDOMNode,
|
|
|
|
nsIDOMProcessingInstruction,
|
|
|
|
nsIStyleSheetLinkingElement)
|
2013-01-10 13:54:46 +04:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(ProcessingInstruction)
|
2002-09-04 10:57:25 +04:00
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(XMLStylesheetProcessingInstruction,
|
|
|
|
ProcessingInstruction)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(XMLStylesheetProcessingInstruction,
|
|
|
|
ProcessingInstruction)
|
2002-09-04 10:57:25 +04:00
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(XMLStylesheetProcessingInstruction)
|
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(XMLStylesheetProcessingInstruction,
|
2013-01-09 00:45:06 +04:00
|
|
|
ProcessingInstruction)
|
2012-10-08 06:39:09 +04:00
|
|
|
tmp->nsStyleLinkElement::Traverse(cb);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2013-08-02 05:29:05 +04:00
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(XMLStylesheetProcessingInstruction,
|
2013-01-09 00:45:06 +04:00
|
|
|
ProcessingInstruction)
|
2012-10-08 06:39:09 +04:00
|
|
|
tmp->nsStyleLinkElement::Unlink();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2002-09-04 10:57:25 +04:00
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
XMLStylesheetProcessingInstruction::~XMLStylesheetProcessingInstruction()
|
2002-09-04 10:57:25 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-01 16:28:37 +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
|
|
|
XMLStylesheetProcessingInstruction::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-02-01 16:28:37 +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 XMLStylesheetProcessingInstructionBinding::Wrap(aCx, this, aGivenProto);
|
2013-02-01 16:28:37 +04:00
|
|
|
}
|
|
|
|
|
2002-09-04 10:57:25 +04:00
|
|
|
// nsIContent
|
|
|
|
|
2005-04-06 03:54:35 +04:00
|
|
|
nsresult
|
2013-02-01 16:28:36 +04:00
|
|
|
XMLStylesheetProcessingInstruction::BindToTree(nsIDocument* aDocument,
|
|
|
|
nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
2005-04-06 03:54:35 +04:00
|
|
|
{
|
2013-01-09 00:45:06 +04:00
|
|
|
nsresult rv = ProcessingInstruction::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
2005-04-06 03:54:35 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
void (XMLStylesheetProcessingInstruction::*update)() =
|
|
|
|
&XMLStylesheetProcessingInstruction::UpdateStyleSheetInternal;
|
2017-06-12 22:34:10 +03:00
|
|
|
nsContentUtils::AddScriptRunner(NewRunnableMethod(
|
|
|
|
"dom::XMLStylesheetProcessingInstruction::BindToTree", this, update));
|
2005-04-06 03:54:35 +04:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
return rv;
|
2005-04-06 03:54:35 +04:00
|
|
|
}
|
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
void
|
2013-02-01 16:28:36 +04:00
|
|
|
XMLStylesheetProcessingInstruction::UnbindFromTree(bool aDeep, bool aNullParent)
|
2002-09-04 10:57:25 +04:00
|
|
|
{
|
2016-03-31 14:46:32 +03:00
|
|
|
nsCOMPtr<nsIDocument> oldDoc = GetUncomposedDoc();
|
2004-01-10 02:54:21 +03:00
|
|
|
|
2013-01-09 00:45:06 +04:00
|
|
|
ProcessingInstruction::UnbindFromTree(aDeep, aNullParent);
|
2013-12-02 14:26:12 +04:00
|
|
|
UpdateStyleSheetInternal(oldDoc, nullptr);
|
2002-09-04 10:57:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMNode
|
|
|
|
|
2012-10-09 16:31:24 +04:00
|
|
|
void
|
2013-02-01 16:28:36 +04:00
|
|
|
XMLStylesheetProcessingInstruction::SetNodeValueInternal(const nsAString& aNodeValue,
|
|
|
|
ErrorResult& aError)
|
2002-09-04 10:57:25 +04:00
|
|
|
{
|
2012-10-21 11:38:41 +04:00
|
|
|
nsGenericDOMDataNode::SetNodeValueInternal(aNodeValue, aError);
|
2012-10-09 16:31:24 +04:00
|
|
|
if (!aError.Failed()) {
|
2013-12-02 14:26:12 +04:00
|
|
|
UpdateStyleSheetInternal(nullptr, nullptr, true);
|
2002-09-04 10:57:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsStyleLinkElement
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-01 16:28:36 +04:00
|
|
|
XMLStylesheetProcessingInstruction::GetCharset(nsAString& aCharset)
|
2002-09-04 10:57:25 +04:00
|
|
|
{
|
2006-03-17 17:38:57 +03:00
|
|
|
return GetAttrValue(nsGkAtoms::charset, aCharset) ? NS_OK : NS_ERROR_FAILURE;
|
2002-09-04 10:57:25 +04:00
|
|
|
}
|
|
|
|
|
2006-12-18 06:59:46 +03:00
|
|
|
/* virtual */ void
|
2013-02-01 16:28:36 +04:00
|
|
|
XMLStylesheetProcessingInstruction::OverrideBaseURI(nsIURI* aNewBaseURI)
|
2006-12-18 06:59:46 +03:00
|
|
|
{
|
|
|
|
mOverriddenBaseURI = aNewBaseURI;
|
|
|
|
}
|
|
|
|
|
2009-07-28 20:07:31 +04:00
|
|
|
already_AddRefed<nsIURI>
|
2013-02-01 16:28:36 +04:00
|
|
|
XMLStylesheetProcessingInstruction::GetStyleSheetURL(bool* aIsInline)
|
2002-09-04 10:57:25 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsInline = false;
|
2002-09-04 10:57:25 +04:00
|
|
|
|
|
|
|
nsAutoString href;
|
2008-11-29 00:21:55 +03:00
|
|
|
if (!GetAttrValue(nsGkAtoms::href, href)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2002-09-04 10:57:25 +04:00
|
|
|
}
|
|
|
|
|
2003-10-22 10:09:48 +04:00
|
|
|
nsIURI *baseURL;
|
2011-10-18 14:53:36 +04:00
|
|
|
nsIDocument *document = OwnerDoc();
|
2011-10-18 15:19:44 +04:00
|
|
|
baseURL = mOverriddenBaseURI ?
|
|
|
|
mOverriddenBaseURI.get() :
|
|
|
|
document->GetDocBaseURI();
|
2017-06-18 14:37:50 +03:00
|
|
|
auto encoding = document->GetDocumentCharacterSet();
|
2003-10-22 10:09:48 +04:00
|
|
|
|
2009-07-28 20:07:31 +04:00
|
|
|
nsCOMPtr<nsIURI> aURI;
|
2017-06-18 14:37:50 +03:00
|
|
|
NS_NewURI(getter_AddRefs(aURI), href, encoding, baseURL);
|
2009-07-28 20:07:31 +04:00
|
|
|
return aURI.forget();
|
2002-09-04 10:57:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-01 16:28:36 +04:00
|
|
|
XMLStylesheetProcessingInstruction::GetStyleSheetInfo(nsAString& aTitle,
|
|
|
|
nsAString& aType,
|
|
|
|
nsAString& aMedia,
|
|
|
|
bool* aIsScoped,
|
|
|
|
bool* aIsAlternate)
|
2002-09-04 10:57:25 +04:00
|
|
|
{
|
|
|
|
aTitle.Truncate();
|
|
|
|
aType.Truncate();
|
|
|
|
aMedia.Truncate();
|
2013-01-09 03:25:47 +04:00
|
|
|
*aIsScoped = false;
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsAlternate = false;
|
2002-09-04 10:57:25 +04:00
|
|
|
|
|
|
|
// xml-stylesheet PI is special only in prolog
|
|
|
|
if (!nsContentUtils::InProlog(this)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-03-17 17:38:57 +03:00
|
|
|
nsAutoString data;
|
|
|
|
GetData(data);
|
2002-09-04 10:57:25 +04:00
|
|
|
|
2012-02-27 15:57:48 +04:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::title, aTitle);
|
2002-09-04 10:57:25 +04:00
|
|
|
|
2006-03-17 17:38:57 +03:00
|
|
|
nsAutoString alternate;
|
2012-02-27 15:57:48 +04:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(data,
|
|
|
|
nsGkAtoms::alternate,
|
|
|
|
alternate);
|
2002-09-04 10:57:25 +04:00
|
|
|
|
|
|
|
// if alternate, does it have title?
|
2004-05-23 02:15:22 +04:00
|
|
|
if (alternate.EqualsLiteral("yes")) {
|
2002-09-04 10:57:25 +04:00
|
|
|
if (aTitle.IsEmpty()) { // alternates must have title
|
|
|
|
return;
|
|
|
|
}
|
2006-03-17 17:38:57 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsAlternate = true;
|
2002-09-04 10:57:25 +04:00
|
|
|
}
|
|
|
|
|
2012-02-27 15:57:48 +04:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::media, aMedia);
|
2002-09-04 10:57:25 +04:00
|
|
|
|
2006-03-17 17:38:57 +03:00
|
|
|
nsAutoString type;
|
2012-02-27 15:57:48 +04:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::type, type);
|
2002-09-04 10:57:25 +04:00
|
|
|
|
2006-03-17 17:38:57 +03:00
|
|
|
nsAutoString mimeType, notUsed;
|
2012-02-27 15:57:48 +04:00
|
|
|
nsContentUtils::SplitMimeType(type, mimeType, notUsed);
|
2004-06-17 04:13:25 +04:00
|
|
|
if (!mimeType.IsEmpty() && !mimeType.LowerCaseEqualsLiteral("text/css")) {
|
2002-09-04 10:57:25 +04:00
|
|
|
aType.Assign(type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get here we assume that we're loading a css file, so set the
|
|
|
|
// type to 'text/css'
|
2004-06-17 04:13:25 +04:00
|
|
|
aType.AssignLiteral("text/css");
|
2002-09-04 10:57:25 +04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-09-11 21:15:08 +04:00
|
|
|
nsGenericDOMDataNode*
|
2014-06-20 06:01:40 +04:00
|
|
|
XMLStylesheetProcessingInstruction::CloneDataNode(mozilla::dom::NodeInfo *aNodeInfo,
|
2013-02-01 16:28:36 +04:00
|
|
|
bool aCloneText) const
|
2005-09-11 21:15:08 +04:00
|
|
|
{
|
|
|
|
nsAutoString data;
|
2005-09-12 11:34:25 +04:00
|
|
|
nsGenericDOMDataNode::GetData(data);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
|
2013-02-01 16:28:36 +04:00
|
|
|
return new XMLStylesheetProcessingInstruction(ni.forget(), data);
|
2005-09-11 21:15:08 +04:00
|
|
|
}
|
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|