content/base/src/nsTraversal.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 *
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "nsTraversal.h"
michael@0 8
michael@0 9 #include "nsIDOMNode.h"
michael@0 10 #include "nsError.h"
michael@0 11 #include "nsINode.h"
michael@0 12 #include "mozilla/AutoRestore.h"
michael@0 13
michael@0 14 #include "nsGkAtoms.h"
michael@0 15
michael@0 16 using namespace mozilla;
michael@0 17 using namespace mozilla::dom;
michael@0 18
michael@0 19 nsTraversal::nsTraversal(nsINode *aRoot,
michael@0 20 uint32_t aWhatToShow,
michael@0 21 const NodeFilterHolder &aFilter) :
michael@0 22 mRoot(aRoot),
michael@0 23 mWhatToShow(aWhatToShow),
michael@0 24 mFilter(aFilter),
michael@0 25 mInAcceptNode(false)
michael@0 26 {
michael@0 27 NS_ASSERTION(aRoot, "invalid root in call to nsTraversal constructor");
michael@0 28 }
michael@0 29
michael@0 30 nsTraversal::~nsTraversal()
michael@0 31 {
michael@0 32 /* destructor code */
michael@0 33 }
michael@0 34
michael@0 35 /*
michael@0 36 * Tests if and how a node should be filtered. Uses mWhatToShow and
michael@0 37 * mFilter to test the node.
michael@0 38 * @param aNode Node to test
michael@0 39 * @param aResult Whether we succeeded
michael@0 40 * @returns Filtervalue. See nsIDOMNodeFilter.idl
michael@0 41 */
michael@0 42 int16_t
michael@0 43 nsTraversal::TestNode(nsINode* aNode, mozilla::ErrorResult& aResult)
michael@0 44 {
michael@0 45 if (mInAcceptNode) {
michael@0 46 aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
michael@0 47 return 0;
michael@0 48 }
michael@0 49
michael@0 50 uint16_t nodeType = aNode->NodeType();
michael@0 51
michael@0 52 if (nodeType <= 12 && !((1 << (nodeType-1)) & mWhatToShow)) {
michael@0 53 return nsIDOMNodeFilter::FILTER_SKIP;
michael@0 54 }
michael@0 55
michael@0 56 if (!mFilter.GetISupports()) {
michael@0 57 // No filter, just accept
michael@0 58 return nsIDOMNodeFilter::FILTER_ACCEPT;
michael@0 59 }
michael@0 60
michael@0 61 if (mFilter.HasWebIDLCallback()) {
michael@0 62 AutoRestore<bool> inAcceptNode(mInAcceptNode);
michael@0 63 mInAcceptNode = true;
michael@0 64 return mFilter.GetWebIDLCallback()->
michael@0 65 AcceptNode(*aNode, aResult, CallbackObject::eRethrowExceptions);
michael@0 66 }
michael@0 67
michael@0 68 nsCOMPtr<nsIDOMNode> domNode = do_QueryInterface(aNode);
michael@0 69 AutoRestore<bool> inAcceptNode(mInAcceptNode);
michael@0 70 mInAcceptNode = true;
michael@0 71 int16_t filtered;
michael@0 72 nsresult rv = mFilter.GetXPCOMCallback()->AcceptNode(domNode, &filtered);
michael@0 73 if (NS_FAILED(rv)) {
michael@0 74 aResult.Throw(rv);
michael@0 75 }
michael@0 76 return filtered;
michael@0 77 }

mercurial