2017-05-11 15:11:15 +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: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/CSSMozDocumentRule.h"
|
|
|
|
#include "mozilla/dom/CSSMozDocumentRuleBinding.h"
|
2018-08-02 00:52:07 +03:00
|
|
|
#include "mozilla/ServoBindings.h"
|
2018-02-13 03:53:44 +03:00
|
|
|
#include "nsContentUtils.h"
|
2017-05-11 15:11:15 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2017-11-17 12:31:22 +03:00
|
|
|
using namespace mozilla::css;
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
|
|
|
JSObject* CSSMozDocumentRule::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return CSSMozDocumentRule_Binding::Wrap(aCx, this, aGivenProto);
|
2017-05-11 15:11:15 +03:00
|
|
|
}
|
|
|
|
|
2019-02-19 14:17:28 +03:00
|
|
|
bool CSSMozDocumentRule::Match(const Document* aDoc, nsIURI* aDocURI,
|
2017-11-17 12:31:22 +03:00
|
|
|
const nsACString& aDocURISpec,
|
|
|
|
const nsACString& aPattern,
|
2018-07-19 13:56:27 +03:00
|
|
|
DocumentMatchingFunction aMatchingFunction) {
|
|
|
|
switch (aMatchingFunction) {
|
2018-07-19 20:50:19 +03:00
|
|
|
case DocumentMatchingFunction::MediaDocument: {
|
|
|
|
auto kind = aDoc->MediaDocumentKind();
|
|
|
|
if (aPattern.EqualsLiteral("all")) {
|
2019-01-02 16:05:23 +03:00
|
|
|
return kind != Document::MediaDocumentKind::NotMedia;
|
2018-07-19 20:50:19 +03:00
|
|
|
}
|
|
|
|
MOZ_ASSERT(aPattern.EqualsLiteral("plugin") ||
|
|
|
|
aPattern.EqualsLiteral("image") ||
|
|
|
|
aPattern.EqualsLiteral("video"));
|
|
|
|
switch (kind) {
|
2019-01-02 16:05:23 +03:00
|
|
|
case Document::MediaDocumentKind::NotMedia:
|
2018-07-19 20:50:19 +03:00
|
|
|
return false;
|
2019-01-02 16:05:23 +03:00
|
|
|
case Document::MediaDocumentKind::Plugin:
|
2018-07-19 20:50:19 +03:00
|
|
|
return aPattern.EqualsLiteral("plugin");
|
2019-01-02 16:05:23 +03:00
|
|
|
case Document::MediaDocumentKind::Image:
|
2018-07-19 20:50:19 +03:00
|
|
|
return aPattern.EqualsLiteral("image");
|
2019-01-02 16:05:23 +03:00
|
|
|
case Document::MediaDocumentKind::Video:
|
2018-07-19 20:50:19 +03:00
|
|
|
return aPattern.EqualsLiteral("video");
|
|
|
|
}
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unknown media document kind");
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-19 20:48:38 +03:00
|
|
|
case DocumentMatchingFunction::URL:
|
|
|
|
return aDocURISpec == aPattern;
|
|
|
|
case DocumentMatchingFunction::URLPrefix:
|
|
|
|
return StringBeginsWith(aDocURISpec, aPattern);
|
2018-07-19 13:56:27 +03:00
|
|
|
case DocumentMatchingFunction::Domain: {
|
2017-11-17 12:31:22 +03:00
|
|
|
nsAutoCString host;
|
|
|
|
if (aDocURI) {
|
|
|
|
aDocURI->GetHost(host);
|
|
|
|
}
|
|
|
|
int32_t lenDiff = host.Length() - aPattern.Length();
|
|
|
|
if (lenDiff == 0) {
|
2018-07-19 20:48:38 +03:00
|
|
|
return host == aPattern;
|
2017-11-17 12:31:22 +03:00
|
|
|
}
|
2018-07-19 20:48:38 +03:00
|
|
|
return StringEndsWith(host, aPattern) && host.CharAt(lenDiff - 1) == '.';
|
|
|
|
}
|
2018-07-19 13:56:27 +03:00
|
|
|
case DocumentMatchingFunction::RegExp: {
|
2017-11-17 12:31:22 +03:00
|
|
|
NS_ConvertUTF8toUTF16 spec(aDocURISpec);
|
|
|
|
NS_ConvertUTF8toUTF16 regex(aPattern);
|
2018-07-19 20:48:38 +03:00
|
|
|
return nsContentUtils::IsPatternMatching(spec, regex, aDoc);
|
|
|
|
}
|
2017-11-17 12:31:22 +03:00
|
|
|
}
|
2018-07-19 20:48:38 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Unknown matching function");
|
2017-11-17 12:31:22 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-05 18:16:51 +03:00
|
|
|
CSSMozDocumentRule::CSSMozDocumentRule(RefPtr<RawServoMozDocumentRule> aRawRule,
|
2018-06-29 05:56:09 +03:00
|
|
|
StyleSheet* aSheet,
|
|
|
|
css::Rule* aParentRule, uint32_t aLine,
|
|
|
|
uint32_t aColumn)
|
2018-06-05 18:16:51 +03:00
|
|
|
: css::ConditionRule(Servo_MozDocumentRule_GetRules(aRawRule).Consume(),
|
2018-06-29 05:56:09 +03:00
|
|
|
aSheet, aParentRule, aLine, aColumn),
|
2018-06-05 18:16:51 +03:00
|
|
|
mRawRule(std::move(aRawRule)) {}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(CSSMozDocumentRule, css::ConditionRule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(CSSMozDocumentRule, css::ConditionRule)
|
|
|
|
|
|
|
|
// QueryInterface implementation for MozDocumentRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSMozDocumentRule)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(css::ConditionRule)
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
|
|
|
void CSSMozDocumentRule::List(FILE* out, int32_t aIndent) const {
|
2018-06-05 18:16:51 +03:00
|
|
|
nsAutoCString str;
|
|
|
|
for (int32_t i = 0; i < aIndent; i++) {
|
|
|
|
str.AppendLiteral(" ");
|
|
|
|
}
|
|
|
|
Servo_MozDocumentRule_Debug(mRawRule, &str);
|
|
|
|
fprintf_stderr(out, "%s\n", str.get());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void CSSMozDocumentRule::GetConditionText(nsAString& aConditionText) {
|
|
|
|
Servo_MozDocumentRule_GetConditionText(mRawRule, &aConditionText);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSSMozDocumentRule::SetConditionText(const nsAString& aConditionText,
|
|
|
|
ErrorResult& aRv) {
|
2019-04-29 08:34:06 +03:00
|
|
|
if (IsReadOnly()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-05 18:16:51 +03:00
|
|
|
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
|
|
|
void CSSMozDocumentRule::GetCssText(nsAString& aCssText) const {
|
2018-06-05 18:16:51 +03:00
|
|
|
Servo_MozDocumentRule_GetCssText(mRawRule, &aCssText);
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
|
|
|
size_t CSSMozDocumentRule::SizeOfIncludingThis(
|
2018-06-05 18:16:51 +03:00
|
|
|
MallocSizeOf aMallocSizeOf) const {
|
|
|
|
// TODO Implement this!
|
|
|
|
return aMallocSizeOf(this);
|
|
|
|
}
|
|
|
|
|
2017-05-11 15:11:15 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|