LCOV - code coverage report
Current view: top level - dom/xml - XMLStylesheetProcessingInstruction.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 49 83 59.0 %
Date: 2017-07-14 16:53:18 Functions: 7 16 43.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #include "XMLStylesheetProcessingInstruction.h"
       8             : #include "mozilla/dom/XMLStylesheetProcessingInstructionBinding.h"
       9             : #include "nsContentUtils.h"
      10             : #include "nsNetUtil.h"
      11             : 
      12             : namespace mozilla {
      13             : namespace dom {
      14             : 
      15             : // nsISupports implementation
      16             : 
      17         267 : NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(XMLStylesheetProcessingInstruction)
      18         261 :   NS_INTERFACE_TABLE_INHERITED(XMLStylesheetProcessingInstruction, nsIDOMNode,
      19             :                                nsIDOMProcessingInstruction,
      20             :                                nsIStyleSheetLinkingElement)
      21         261 : NS_INTERFACE_TABLE_TAIL_INHERITING(ProcessingInstruction)
      22             : 
      23         340 : NS_IMPL_ADDREF_INHERITED(XMLStylesheetProcessingInstruction,
      24             :                          ProcessingInstruction)
      25         334 : NS_IMPL_RELEASE_INHERITED(XMLStylesheetProcessingInstruction,
      26             :                           ProcessingInstruction)
      27             : 
      28             : NS_IMPL_CYCLE_COLLECTION_CLASS(XMLStylesheetProcessingInstruction)
      29             : 
      30           0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(XMLStylesheetProcessingInstruction,
      31             :                                                   ProcessingInstruction)
      32           0 :   tmp->nsStyleLinkElement::Traverse(cb);
      33           0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
      34             : 
      35           0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(XMLStylesheetProcessingInstruction,
      36             :                                                 ProcessingInstruction)
      37           0 :   tmp->nsStyleLinkElement::Unlink();
      38           0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
      39             : 
      40             : 
      41           0 : XMLStylesheetProcessingInstruction::~XMLStylesheetProcessingInstruction()
      42             : {
      43           0 : }
      44             : 
      45             : JSObject*
      46           0 : XMLStylesheetProcessingInstruction::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
      47             : {
      48           0 :   return XMLStylesheetProcessingInstructionBinding::Wrap(aCx, this, aGivenProto);
      49             : }
      50             : 
      51             : // nsIContent
      52             : 
      53             : nsresult
      54           6 : XMLStylesheetProcessingInstruction::BindToTree(nsIDocument* aDocument,
      55             :                                                nsIContent* aParent,
      56             :                                                nsIContent* aBindingParent,
      57             :                                                bool aCompileEventHandlers)
      58             : {
      59           6 :   nsresult rv = ProcessingInstruction::BindToTree(aDocument, aParent,
      60             :                                                   aBindingParent,
      61           6 :                                                   aCompileEventHandlers);
      62           6 :   NS_ENSURE_SUCCESS(rv, rv);
      63             : 
      64             :   void (XMLStylesheetProcessingInstruction::*update)() =
      65           6 :     &XMLStylesheetProcessingInstruction::UpdateStyleSheetInternal;
      66          12 :   nsContentUtils::AddScriptRunner(NewRunnableMethod(
      67           6 :     "dom::XMLStylesheetProcessingInstruction::BindToTree", this, update));
      68             : 
      69           6 :   return rv;
      70             : }
      71             : 
      72             : void
      73           0 : XMLStylesheetProcessingInstruction::UnbindFromTree(bool aDeep, bool aNullParent)
      74             : {
      75           0 :   nsCOMPtr<nsIDocument> oldDoc = GetUncomposedDoc();
      76             : 
      77           0 :   ProcessingInstruction::UnbindFromTree(aDeep, aNullParent);
      78           0 :   UpdateStyleSheetInternal(oldDoc, nullptr);
      79           0 : }
      80             : 
      81             : // nsIDOMNode
      82             : 
      83             : void
      84           0 : XMLStylesheetProcessingInstruction::SetNodeValueInternal(const nsAString& aNodeValue,
      85             :                                                          ErrorResult& aError)
      86             : {
      87           0 :   nsGenericDOMDataNode::SetNodeValueInternal(aNodeValue, aError);
      88           0 :   if (!aError.Failed()) {
      89           0 :     UpdateStyleSheetInternal(nullptr, nullptr, true);
      90             :   }
      91           0 : }
      92             : 
      93             : // nsStyleLinkElement
      94             : 
      95             : NS_IMETHODIMP
      96           0 : XMLStylesheetProcessingInstruction::GetCharset(nsAString& aCharset)
      97             : {
      98           0 :   return GetAttrValue(nsGkAtoms::charset, aCharset) ? NS_OK : NS_ERROR_FAILURE;
      99             : }
     100             : 
     101             : /* virtual */ void
     102           6 : XMLStylesheetProcessingInstruction::OverrideBaseURI(nsIURI* aNewBaseURI)
     103             : {
     104           6 :   mOverriddenBaseURI = aNewBaseURI;
     105           6 : }
     106             : 
     107             : already_AddRefed<nsIURI>
     108           6 : XMLStylesheetProcessingInstruction::GetStyleSheetURL(bool* aIsInline)
     109             : {
     110           6 :   *aIsInline = false;
     111             : 
     112          12 :   nsAutoString href;
     113           6 :   if (!GetAttrValue(nsGkAtoms::href, href)) {
     114           0 :     return nullptr;
     115             :   }
     116             : 
     117             :   nsIURI *baseURL;
     118           6 :   nsIDocument *document = OwnerDoc();
     119          12 :   baseURL = mOverriddenBaseURI ?
     120           6 :             mOverriddenBaseURI.get() :
     121           6 :             document->GetDocBaseURI();
     122           6 :   auto encoding = document->GetDocumentCharacterSet();
     123             : 
     124          12 :   nsCOMPtr<nsIURI> aURI;
     125           6 :   NS_NewURI(getter_AddRefs(aURI), href, encoding, baseURL);
     126           6 :   return aURI.forget();
     127             : }
     128             : 
     129             : void
     130           6 : XMLStylesheetProcessingInstruction::GetStyleSheetInfo(nsAString& aTitle,
     131             :                                                       nsAString& aType,
     132             :                                                       nsAString& aMedia,
     133             :                                                       bool* aIsScoped,
     134             :                                                       bool* aIsAlternate)
     135             : {
     136           6 :   aTitle.Truncate();
     137           6 :   aType.Truncate();
     138           6 :   aMedia.Truncate();
     139           6 :   *aIsScoped = false;
     140           6 :   *aIsAlternate = false;
     141             : 
     142             :   // xml-stylesheet PI is special only in prolog
     143           6 :   if (!nsContentUtils::InProlog(this)) {
     144           0 :     return;
     145             :   }
     146             : 
     147          12 :   nsAutoString data;
     148           6 :   GetData(data);
     149             : 
     150           6 :   nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::title, aTitle);
     151             : 
     152          12 :   nsAutoString alternate;
     153             :   nsContentUtils::GetPseudoAttributeValue(data,
     154             :                                           nsGkAtoms::alternate,
     155           6 :                                           alternate);
     156             : 
     157             :   // if alternate, does it have title?
     158           6 :   if (alternate.EqualsLiteral("yes")) {
     159           0 :     if (aTitle.IsEmpty()) { // alternates must have title
     160           0 :       return;
     161             :     }
     162             : 
     163           0 :     *aIsAlternate = true;
     164             :   }
     165             : 
     166           6 :   nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::media, aMedia);
     167             : 
     168          12 :   nsAutoString type;
     169           6 :   nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::type, type);
     170             : 
     171          12 :   nsAutoString mimeType, notUsed;
     172           6 :   nsContentUtils::SplitMimeType(type, mimeType, notUsed);
     173           6 :   if (!mimeType.IsEmpty() && !mimeType.LowerCaseEqualsLiteral("text/css")) {
     174           0 :     aType.Assign(type);
     175           0 :     return;
     176             :   }
     177             : 
     178             :   // If we get here we assume that we're loading a css file, so set the
     179             :   // type to 'text/css'
     180           6 :   aType.AssignLiteral("text/css");
     181             : 
     182           6 :   return;
     183             : }
     184             : 
     185             : nsGenericDOMDataNode*
     186           0 : XMLStylesheetProcessingInstruction::CloneDataNode(mozilla::dom::NodeInfo *aNodeInfo,
     187             :                                                   bool aCloneText) const
     188             : {
     189           0 :   nsAutoString data;
     190           0 :   nsGenericDOMDataNode::GetData(data);
     191           0 :   RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
     192           0 :   return new XMLStylesheetProcessingInstruction(ni.forget(), data);
     193             : }
     194             : 
     195             : } // namespace dom
     196             : } // namespace mozilla

Generated by: LCOV version 1.13