Bug 1357432 - Part 1. Move IsLocalRefURL to nsContentUtils to reuse this function. draft
authorcku <cku@mozilla.com>
Tue, 18 Apr 2017 23:35:56 +0800
changeset 565676 6ddd25df8da07327aa847a08d19791bd71eb4323
parent 565531 20dff607fb88ee69135a280bbb7f32df75a86237
child 565677 b6709df3454bb10a9ad1864861df14946d34bbf7
child 565683 86f3241de747f1e936ccf51288eb3ef661c58de8
push id54955
push userbmo:cku@mozilla.com
push dateThu, 20 Apr 2017 07:53:57 +0000
bugs1357432
milestone55.0a1
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
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
layout/style/nsCSSValue.cpp
--- 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
 {