ServoStyleSheet.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "ServoBindings.h"
  6. #include "mozilla/ServoStyleSheet.h"
  7. #include "mozilla/StyleBackendType.h"
  8. #include "CSSRuleList.h"
  9. using namespace mozilla::dom;
  10. namespace mozilla {
  11. ServoStyleSheet::ServoStyleSheet(css::SheetParsingMode aParsingMode,
  12. CORSMode aCORSMode,
  13. net::ReferrerPolicy aReferrerPolicy,
  14. const dom::SRIMetadata& aIntegrity)
  15. : StyleSheet(StyleBackendType::Servo, aParsingMode)
  16. , mSheetInfo(aCORSMode, aReferrerPolicy, aIntegrity)
  17. {
  18. }
  19. ServoStyleSheet::~ServoStyleSheet()
  20. {
  21. DropSheet();
  22. }
  23. bool
  24. ServoStyleSheet::HasRules() const
  25. {
  26. return mSheet && Servo_StyleSheet_HasRules(mSheet);
  27. }
  28. void
  29. ServoStyleSheet::SetAssociatedDocument(nsIDocument* aDocument,
  30. DocumentAssociationMode aAssociationMode)
  31. {
  32. MOZ_ASSERT_IF(!aDocument, aAssociationMode == NotOwnedByDocument);
  33. // XXXheycam: Traverse to child ServoStyleSheets to set this, like
  34. // CSSStyleSheet::SetAssociatedDocument does.
  35. mDocument = aDocument;
  36. mDocumentAssociationMode = aAssociationMode;
  37. }
  38. ServoStyleSheet*
  39. ServoStyleSheet::GetParentSheet() const
  40. {
  41. // XXXheycam: When we implement support for child sheets, we'll have
  42. // to fix SetAssociatedDocument to propagate the associated document down
  43. // to the children.
  44. MOZ_CRASH("stylo: not implemented");
  45. }
  46. void
  47. ServoStyleSheet::AppendStyleSheet(ServoStyleSheet* aSheet)
  48. {
  49. // XXXheycam: When we implement support for child sheets, we'll have
  50. // to fix SetOwningDocument to propagate the owning document down
  51. // to the children.
  52. MOZ_CRASH("stylo: not implemented");
  53. }
  54. nsresult
  55. ServoStyleSheet::ParseSheet(const nsAString& aInput,
  56. nsIURI* aSheetURI,
  57. nsIURI* aBaseURI,
  58. nsIPrincipal* aSheetPrincipal,
  59. uint32_t aLineNumber)
  60. {
  61. DropSheet();
  62. RefPtr<ThreadSafeURIHolder> base = new ThreadSafeURIHolder(aBaseURI);
  63. RefPtr<ThreadSafeURIHolder> referrer = new ThreadSafeURIHolder(aSheetURI);
  64. RefPtr<ThreadSafePrincipalHolder> principal =
  65. new ThreadSafePrincipalHolder(aSheetPrincipal);
  66. nsCString baseString;
  67. nsresult rv = aBaseURI->GetSpec(baseString);
  68. NS_ENSURE_SUCCESS(rv, rv);
  69. NS_ConvertUTF16toUTF8 input(aInput);
  70. mSheet = Servo_StyleSheet_FromUTF8Bytes(&input, mParsingMode, &baseString,
  71. base, referrer, principal).Consume();
  72. return NS_OK;
  73. }
  74. void
  75. ServoStyleSheet::LoadFailed()
  76. {
  77. mSheet = Servo_StyleSheet_Empty(mParsingMode).Consume();
  78. }
  79. void
  80. ServoStyleSheet::DropSheet()
  81. {
  82. mSheet = nullptr;
  83. }
  84. size_t
  85. ServoStyleSheet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
  86. {
  87. MOZ_CRASH("stylo: not implemented");
  88. }
  89. #ifdef DEBUG
  90. void
  91. ServoStyleSheet::List(FILE* aOut, int32_t aIndex) const
  92. {
  93. MOZ_CRASH("stylo: not implemented");
  94. }
  95. #endif
  96. nsMediaList*
  97. ServoStyleSheet::Media()
  98. {
  99. return nullptr;
  100. }
  101. nsIDOMCSSRule*
  102. ServoStyleSheet::GetDOMOwnerRule() const
  103. {
  104. return nullptr;
  105. }
  106. CSSRuleList*
  107. ServoStyleSheet::GetCssRulesInternal(ErrorResult& aRv)
  108. {
  109. aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
  110. return nullptr;
  111. }
  112. uint32_t
  113. ServoStyleSheet::InsertRuleInternal(const nsAString& aRule,
  114. uint32_t aIndex, ErrorResult& aRv)
  115. {
  116. aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
  117. return 0;
  118. }
  119. void
  120. ServoStyleSheet::DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv)
  121. {
  122. aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
  123. }
  124. } // namespace mozilla