dom/xbl/nsXBLProtoImplMethod.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: C++; tab-width: 2; 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/. */
     6 #ifndef nsXBLProtoImplMethod_h__
     7 #define nsXBLProtoImplMethod_h__
     9 #include "mozilla/Attributes.h"
    10 #include "nsIAtom.h"
    11 #include "nsString.h"
    12 #include "nsString.h"
    13 #include "nsXBLMaybeCompiled.h"
    14 #include "nsXBLProtoImplMember.h"
    15 #include "nsXBLSerialize.h"
    17 class nsIContent;
    19 struct nsXBLParameter {
    20   nsXBLParameter* mNext;
    21   char* mName;
    23   nsXBLParameter(const nsAString& aName) {
    24     MOZ_COUNT_CTOR(nsXBLParameter);
    25     mName = ToNewCString(aName);
    26     mNext = nullptr;
    27   }
    29   ~nsXBLParameter() {
    30     MOZ_COUNT_DTOR(nsXBLParameter);
    31     nsMemory::Free(mName);
    32     NS_CONTENT_DELETE_LIST_MEMBER(nsXBLParameter, this, mNext);
    33   }
    34 };
    36 struct nsXBLUncompiledMethod {
    37   nsXBLParameter* mParameters;
    38   nsXBLParameter* mLastParameter;
    39   nsXBLTextWithLineNumber mBodyText;
    41   nsXBLUncompiledMethod() :
    42     mParameters(nullptr),
    43     mLastParameter(nullptr),
    44     mBodyText()
    45   {
    46     MOZ_COUNT_CTOR(nsXBLUncompiledMethod);
    47   }
    49   ~nsXBLUncompiledMethod() {
    50     MOZ_COUNT_DTOR(nsXBLUncompiledMethod);
    51     delete mParameters;
    52   }
    54   int32_t GetParameterCount() {
    55     int32_t result = 0;
    56     for (nsXBLParameter* curr = mParameters; curr; curr=curr->mNext)
    57       result++;
    58     return result;
    59   }
    61   void AppendBodyText(const nsAString& aText) {
    62     mBodyText.AppendText(aText);
    63   }
    65   void AddParameter(const nsAString& aText) {
    66     nsXBLParameter* param = new nsXBLParameter(aText);
    67     if (!param)
    68       return;
    69     if (!mParameters)
    70       mParameters = param;
    71     else
    72       mLastParameter->mNext = param;
    73     mLastParameter = param;
    74   }
    76   void SetLineNumber(uint32_t aLineNumber) {
    77     mBodyText.SetLineNumber(aLineNumber);
    78   }
    79 };
    81 class nsXBLProtoImplMethod: public nsXBLProtoImplMember
    82 {
    83 public:
    84   nsXBLProtoImplMethod(const char16_t* aName);
    85   virtual ~nsXBLProtoImplMethod();
    87   void AppendBodyText(const nsAString& aBody);
    88   void AddParameter(const nsAString& aName);
    90   void SetLineNumber(uint32_t aLineNumber);
    92   virtual nsresult InstallMember(JSContext* aCx,
    93                                  JS::Handle<JSObject*> aTargetClassObject) MOZ_OVERRIDE;
    94   virtual nsresult CompileMember(const nsCString& aClassStr,
    95                                  JS::Handle<JSObject*> aClassObject) MOZ_OVERRIDE;
    97   virtual void Trace(const TraceCallbacks& aCallbacks, void *aClosure) MOZ_OVERRIDE;
    99   nsresult Read(nsIObjectInputStream* aStream);
   100   virtual nsresult Write(nsIObjectOutputStream* aStream) MOZ_OVERRIDE;
   102   bool IsCompiled() const
   103   {
   104     return mMethod.IsCompiled();
   105   }
   107   void SetUncompiledMethod(nsXBLUncompiledMethod* aUncompiledMethod)
   108   {
   109     mMethod.SetUncompiled(aUncompiledMethod);
   110   }
   112   nsXBLUncompiledMethod* GetUncompiledMethod() const
   113   {
   114     return mMethod.GetUncompiled();
   115   }
   117 protected:
   118   void SetCompiledMethod(JSObject* aCompiledMethod)
   119   {
   120     mMethod.SetJSFunction(aCompiledMethod);
   121   }
   123   JSObject* GetCompiledMethod() const
   124   {
   125     return mMethod.GetJSFunction();
   126   }
   128   JSObject* GetCompiledMethodPreserveColor() const
   129   {
   130     return mMethod.GetJSFunctionPreserveColor();
   131   }
   133   JS::Heap<nsXBLMaybeCompiled<nsXBLUncompiledMethod> > mMethod;
   134 };
   136 class nsXBLProtoImplAnonymousMethod : public nsXBLProtoImplMethod {
   137 public:
   138   nsXBLProtoImplAnonymousMethod(const char16_t* aName) :
   139     nsXBLProtoImplMethod(aName)
   140   {}
   142   nsresult Execute(nsIContent* aBoundElement);
   144   // Override InstallMember; these methods never get installed as members on
   145   // binding instantiations (though they may hang out in mMembers on the
   146   // prototype implementation).
   147   virtual nsresult InstallMember(JSContext* aCx,
   148                                  JS::Handle<JSObject*> aTargetClassObject) MOZ_OVERRIDE {
   149     return NS_OK;
   150   }
   152   using nsXBLProtoImplMethod::Write;
   153   nsresult Write(nsIObjectOutputStream* aStream,
   154                  XBLBindingSerializeDetails aType);
   155 };
   157 #endif // nsXBLProtoImplMethod_h__

mercurial