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
|
|
|
|
|
2017-09-01 02:29:22 +03:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(XMLStylesheetProcessingInstruction,
|
|
|
|
ProcessingInstruction,
|
|
|
|
nsIDOMNode,
|
|
|
|
nsIStyleSheetLinkingElement)
|
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
|
|
|
{
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::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
|
|
|
|
|
2018-02-02 16:21:32 +03:00
|
|
|
void
|
2013-02-01 16:28:36 +04:00
|
|
|
XMLStylesheetProcessingInstruction::GetCharset(nsAString& aCharset)
|
2002-09-04 10:57:25 +04:00
|
|
|
{
|
2018-02-02 16:21:32 +03:00
|
|
|
if (!GetAttrValue(nsGkAtoms::charset, aCharset)) {
|
|
|
|
aCharset.Truncate();
|
|
|
|
}
|
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>
|
2017-10-06 05:40:48 +03:00
|
|
|
XMLStylesheetProcessingInstruction::GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal)
|
2002-09-04 10:57:25 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsInline = false;
|
2017-10-06 05:40:48 +03:00
|
|
|
*aTriggeringPrincipal = nullptr;
|
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* aIsAlternate)
|
2002-09-04 10:57:25 +04:00
|
|
|
{
|
|
|
|
aTitle.Truncate();
|
|
|
|
aType.Truncate();
|
|
|
|
aMedia.Truncate();
|
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
|
|
|
|
2017-12-22 00:43:24 +03:00
|
|
|
// Make sure the type handling here matches
|
|
|
|
// nsXMLContentSink::HandleProcessingInstruction
|
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
|
|
|
}
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData*
|
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;
|
2018-03-19 22:18:06 +03:00
|
|
|
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
|