Bug 652991 - Part 1. Carry local-url-flag in URLValueData. draft
authorcku <cku@mozilla.com>
Wed, 15 Jun 2016 16:11:05 +0100
changeset 395496 93a3112ec374bbf922f6f76e67cc2d1081dfdea7
parent 394995 ffac2798999c5b84f1b4605a1280994bb665a406
child 395497 46fd63b7849ce6ad93365b2c41941b4d1419d34e
push id24801
push usercku@mozilla.com
push dateTue, 02 Aug 2016 14:45:11 +0000
bugs652991
milestone51.0a1
Bug 652991 - Part 1. Carry local-url-flag in URLValueData. MozReview-Commit-ID: 8Qvaa27LCv0
layout/style/nsCSSValue.cpp
layout/style/nsCSSValue.h
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -23,16 +23,32 @@
 #include "nsNetUtil.h"
 #include "nsPresContext.h"
 #include "nsStyleUtil.h"
 #include "nsDeviceContext.h"
 #include "nsStyleSet.h"
 
 using namespace mozilla;
 
+static bool
+IsLocalRefURL(nsStringBuffer* aString)
+{
+  // Find the first non-"C0 controls + space" character.
+  char16_t* current = static_cast<char16_t*>(aString->Data());
+  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;
+}
+
 nsCSSValue::nsCSSValue(int32_t aValue, nsCSSUnit aUnit)
   : mUnit(aUnit)
 {
   MOZ_ASSERT(aUnit == eCSSUnit_Integer || aUnit == eCSSUnit_Enumerated ||
              aUnit == eCSSUnit_EnumColor,
              "not an int value");
   if (aUnit == eCSSUnit_Integer || aUnit == eCSSUnit_Enumerated ||
       aUnit == eCSSUnit_EnumColor) {
@@ -2513,30 +2529,32 @@ css::URLValueData::URLValueData(already_
                                 already_AddRefed<PtrHolder<nsIURI>> aReferrer,
                                 already_AddRefed<PtrHolder<nsIPrincipal>>
                                   aOriginPrincipal)
   : mURI(Move(aURI))
   , mString(aString)
   , mReferrer(Move(aReferrer))
   , mOriginPrincipal(Move(aOriginPrincipal))
   , mURIResolved(true)
+  , mLocalURLFlag(IsLocalRefURL(aString))
 {
   MOZ_ASSERT(mOriginPrincipal, "Must have an origin principal");
 }
 
 css::URLValueData::URLValueData(nsStringBuffer* aString,
                                 already_AddRefed<PtrHolder<nsIURI>> aBaseURI,
                                 already_AddRefed<PtrHolder<nsIURI>> aReferrer,
                                 already_AddRefed<PtrHolder<nsIPrincipal>>
                                   aOriginPrincipal)
   : mURI(Move(aBaseURI))
   , mString(aString)
   , mReferrer(Move(aReferrer))
   , mOriginPrincipal(Move(aOriginPrincipal))
   , mURIResolved(false)
+  , mLocalURLFlag(IsLocalRefURL(aString))
 {
   MOZ_ASSERT(mOriginPrincipal, "Must have an origin principal");
 }
 
 bool
 css::URLValueData::operator==(const URLValueData& aOther) const
 {
   bool eq;
--- a/layout/style/nsCSSValue.h
+++ b/layout/style/nsCSSValue.h
@@ -116,27 +116,32 @@ struct URLValueData
   // mURI member of both URL objects is non-null.  Do NOT call this method
   // unless you're sure this is the case.
   bool URIEquals(const URLValueData& aOther) const;
 
   nsIURI* GetURI() const;
 
   size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
+  bool GetLocalURLFlag() const { return mLocalURLFlag; }
+
 private:
   // If mURIResolved is false, mURI stores the base URI.
   // If mURIResolved is true, mURI stores the URI we resolve to; this may be
   // null if the URI is invalid.
   mutable PtrHandle<nsIURI> mURI;
 public:
   RefPtr<nsStringBuffer> mString;
   PtrHandle<nsIURI> mReferrer;
   PtrHandle<nsIPrincipal> mOriginPrincipal;
 private:
   mutable bool mURIResolved;
+  // mLocalURLFlag is set when url starts with a U+0023 number
+  // sign(#) character.
+  bool mLocalURLFlag;
 
   URLValueData(const URLValueData& aOther) = delete;
   URLValueData& operator=(const URLValueData& aOther) = delete;
 };
 
 struct URLValue : public URLValueData
 {
   // These two constructors are safe to call only on the main thread.