Bug 1357432 - Part 1. Move IsLocalRefURL to nsContentUtils to reuse this function.
IsLocalRefURL is originally designed to be used by URLValue only. Since we need
this function in SVGUseElement::LookupHref too, move it to nsContentUtils as a
util function.
MozReview-Commit-ID: FDjWVbTfB0V
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -10180,17 +10180,17 @@ nsContentUtils::HtmlObjectContentTypeFor
// ShouldPlay will handle checking for disabled plugins
return nsIObjectLoadingContent::TYPE_PLUGIN;
}
return nsIObjectLoadingContent::TYPE_NULL;
}
/* static */ already_AddRefed<nsIEventTarget>
- nsContentUtils::GetEventTargetByLoadInfo(nsILoadInfo* aLoadInfo, TaskCategory aCategory)
+nsContentUtils::GetEventTargetByLoadInfo(nsILoadInfo* aLoadInfo, TaskCategory aCategory)
{
if (NS_WARN_IF(!aLoadInfo)) {
return nullptr;
}
nsCOMPtr<nsIDOMDocument> domDoc;
aLoadInfo->GetLoadingDocument(getter_AddRefs(domDoc));
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
@@ -10213,8 +10213,24 @@ nsContentUtils::HtmlObjectContentTypeFor
return nullptr;
}
target = window->TabGroup()->EventTargetFor(aCategory);
}
return target.forget();
}
+
+/* static */ bool
+nsContentUtils::IsLocalRefURL(const nsString& aString)
+{
+ // Find the first non-"C0 controls + space" character.
+ const char16_t* current = aString.get();
+ for (; *current != '\0'; current++) {
+ if (*current > 0x20) {
+ // if the first non-"C0 controls + space" character is '#', this is a
+ // local-ref URL.
+ return *current == '#';
+ }
+ }
+
+ return false;
+}
\ No newline at end of file
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -2858,16 +2858,23 @@ public:
*/
static uint32_t
HtmlObjectContentTypeForMIMEType(const nsCString& aMIMEType,
nsIContent* aContent);
static already_AddRefed<nsIEventTarget>
GetEventTargetByLoadInfo(nsILoadInfo* aLoadInfo, mozilla::TaskCategory aCategory);
+ /**
+ * Detect whether a string is a local-url.
+ * https://drafts.csswg.org/css-values/#local-urls
+ */
+ static bool
+ IsLocalRefURL(const nsString& aString);
+
private:
static bool InitializeEventTable();
static nsresult EnsureStringBundle(PropertiesFile aFile);
static bool CanCallerAccess(nsIPrincipal* aSubjectPrincipal,
nsIPrincipal* aPrincipal);
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -25,32 +25,16 @@
#include "nsDeviceContext.h"
#include "nsStyleSet.h"
#include "nsContentUtils.h"
using namespace mozilla;
using namespace mozilla::css;
static bool
-IsLocalRefURL(const nsString& aString)
-{
- // Find the first non-"C0 controls + space" character.
- const char16_t* current = aString.get();
- for (; *current != '\0'; current++) {
- if (*current > 0x20) {
- // if the first non-"C0 controls + space" character is '#', this is a
- // local-ref URL.
- return *current == '#';
- }
- }
-
- return false;
-}
-
-static bool
MightHaveRef(const nsString& aString)
{
const char16_t* current = aString.get();
for (; *current != '\0'; current++) {
if (*current == '#') {
return true;
}
}
@@ -2870,17 +2854,17 @@ css::URLValueData::GetURI() const
return mURI;
}
bool
css::URLValueData::IsLocalRef() const
{
if (mIsLocalRef.isNothing()) {
// IsLocalRefURL is O(N), use it only when IsLocalRef is called.
- mIsLocalRef.emplace(IsLocalRefURL(mString));
+ mIsLocalRef.emplace(nsContentUtils::IsLocalRefURL(mString));
}
return mIsLocalRef.value();
}
bool
css::URLValueData::HasRef() const
{