content/xul/templates/src/nsContentTestNode.cpp

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: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     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 #include "nsContentTestNode.h"
     7 #include "nsIRDFResource.h"
     8 #include "nsIAtom.h"
     9 #include "nsIDOMElement.h"
    10 #include "nsXULContentUtils.h"
    11 #include "nsIXULTemplateResult.h"
    12 #include "nsIXULTemplateBuilder.h"
    13 #include "nsXULTemplateQueryProcessorRDF.h"
    15 #include "prlog.h"
    16 #ifdef PR_LOGGING
    17 extern PRLogModuleInfo* gXULTemplateLog;
    18 #endif
    20 nsContentTestNode::nsContentTestNode(nsXULTemplateQueryProcessorRDF* aProcessor,
    21                                      nsIAtom* aRefVariable)
    22     : TestNode(nullptr),
    23       mProcessor(aProcessor),
    24       mDocument(nullptr),
    25       mRefVariable(aRefVariable),
    26       mTag(nullptr)
    27 {
    28 #ifdef PR_LOGGING
    29     if (PR_LOG_TEST(gXULTemplateLog, PR_LOG_DEBUG)) {
    30         nsAutoString tag(NS_LITERAL_STRING("(none)"));
    31         if (mTag)
    32             mTag->ToString(tag);
    34         nsAutoString refvar(NS_LITERAL_STRING("(none)"));
    35         if (aRefVariable)
    36             aRefVariable->ToString(refvar);
    38         PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
    39                ("nsContentTestNode[%p]: ref-var=%s tag=%s",
    40                 this, NS_ConvertUTF16toUTF8(refvar).get(),
    41                 NS_ConvertUTF16toUTF8(tag).get()));
    42     }
    43 #endif
    44 }
    46 nsresult
    47 nsContentTestNode::FilterInstantiations(InstantiationSet& aInstantiations,
    48                                         bool* aCantHandleYet) const
    50 {
    51     if (aCantHandleYet)
    52         *aCantHandleYet = false;
    53     return NS_OK;
    54 }
    56 nsresult
    57 nsContentTestNode::Constrain(InstantiationSet& aInstantiations)
    58 {
    59     // contrain the matches to those that have matched in the template builder
    61     nsIXULTemplateBuilder* builder = mProcessor->GetBuilder();
    62     if (!builder) {
    63         aInstantiations.Clear();
    64         return NS_OK;
    65     }
    67     nsresult rv;
    69     InstantiationSet::Iterator last = aInstantiations.Last();
    70     for (InstantiationSet::Iterator inst = aInstantiations.First(); inst != last; ++inst) {
    72         nsCOMPtr<nsIRDFNode> refValue;
    73         bool hasRefBinding = inst->mAssignments.GetAssignmentFor(mRefVariable,
    74                                                                    getter_AddRefs(refValue));
    75         if (hasRefBinding) {
    76             nsCOMPtr<nsIRDFResource> refResource = do_QueryInterface(refValue);
    77             if (refResource) {
    78                 bool generated;
    79                 rv = builder->HasGeneratedContent(refResource, mTag, &generated);
    80                 if (NS_FAILED(rv)) return rv;
    82                 if (generated)
    83                     continue;
    84             }
    85         }
    87         aInstantiations.Erase(inst--);
    88     }
    90     return NS_OK;
    91 }

mercurial