dom/xbl/nsXBLPrototypeResources.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.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "nsIStyleRuleProcessor.h"
michael@0 7 #include "nsIDocument.h"
michael@0 8 #include "nsIContent.h"
michael@0 9 #include "nsIServiceManager.h"
michael@0 10 #include "nsXBLResourceLoader.h"
michael@0 11 #include "nsXBLPrototypeResources.h"
michael@0 12 #include "nsXBLPrototypeBinding.h"
michael@0 13 #include "nsIDocumentObserver.h"
michael@0 14 #include "mozilla/css/Loader.h"
michael@0 15 #include "nsIURI.h"
michael@0 16 #include "nsLayoutCID.h"
michael@0 17 #include "nsCSSRuleProcessor.h"
michael@0 18 #include "nsStyleSet.h"
michael@0 19 #include "mozilla/dom/URL.h"
michael@0 20
michael@0 21 using mozilla::dom::IsChromeURI;
michael@0 22
michael@0 23 nsXBLPrototypeResources::nsXBLPrototypeResources(nsXBLPrototypeBinding* aBinding)
michael@0 24 {
michael@0 25 MOZ_COUNT_CTOR(nsXBLPrototypeResources);
michael@0 26
michael@0 27 mLoader = new nsXBLResourceLoader(aBinding, this);
michael@0 28 }
michael@0 29
michael@0 30 nsXBLPrototypeResources::~nsXBLPrototypeResources()
michael@0 31 {
michael@0 32 MOZ_COUNT_DTOR(nsXBLPrototypeResources);
michael@0 33 if (mLoader) {
michael@0 34 mLoader->mResources = nullptr;
michael@0 35 }
michael@0 36 }
michael@0 37
michael@0 38 void
michael@0 39 nsXBLPrototypeResources::AddResource(nsIAtom* aResourceType, const nsAString& aSrc)
michael@0 40 {
michael@0 41 if (mLoader)
michael@0 42 mLoader->AddResource(aResourceType, aSrc);
michael@0 43 }
michael@0 44
michael@0 45 void
michael@0 46 nsXBLPrototypeResources::LoadResources(bool* aResult)
michael@0 47 {
michael@0 48 if (mLoader)
michael@0 49 mLoader->LoadResources(aResult);
michael@0 50 else
michael@0 51 *aResult = true; // All resources loaded.
michael@0 52 }
michael@0 53
michael@0 54 void
michael@0 55 nsXBLPrototypeResources::AddResourceListener(nsIContent* aBoundElement)
michael@0 56 {
michael@0 57 if (mLoader)
michael@0 58 mLoader->AddResourceListener(aBoundElement);
michael@0 59 }
michael@0 60
michael@0 61 nsresult
michael@0 62 nsXBLPrototypeResources::FlushSkinSheets()
michael@0 63 {
michael@0 64 if (mStyleSheetList.Length() == 0)
michael@0 65 return NS_OK;
michael@0 66
michael@0 67 nsCOMPtr<nsIDocument> doc =
michael@0 68 mLoader->mBinding->XBLDocumentInfo()->GetDocument();
michael@0 69
michael@0 70 // If doc is null, we're in the process of tearing things down, so just
michael@0 71 // return without rebuilding anything.
michael@0 72 if (!doc) {
michael@0 73 return NS_OK;
michael@0 74 }
michael@0 75
michael@0 76 // We have scoped stylesheets. Reload any chrome stylesheets we
michael@0 77 // encounter. (If they aren't skin sheets, it doesn't matter, since
michael@0 78 // they'll still be in the chrome cache.
michael@0 79 mRuleProcessor = nullptr;
michael@0 80
michael@0 81 sheet_array_type oldSheets(mStyleSheetList);
michael@0 82 mStyleSheetList.Clear();
michael@0 83
michael@0 84 mozilla::css::Loader* cssLoader = doc->CSSLoader();
michael@0 85
michael@0 86 for (sheet_array_type::size_type i = 0, count = oldSheets.Length();
michael@0 87 i < count; ++i) {
michael@0 88 nsCSSStyleSheet* oldSheet = oldSheets[i];
michael@0 89
michael@0 90 nsIURI* uri = oldSheet->GetSheetURI();
michael@0 91
michael@0 92 nsRefPtr<nsCSSStyleSheet> newSheet;
michael@0 93 if (IsChromeURI(uri)) {
michael@0 94 if (NS_FAILED(cssLoader->LoadSheetSync(uri, getter_AddRefs(newSheet))))
michael@0 95 continue;
michael@0 96 }
michael@0 97 else {
michael@0 98 newSheet = oldSheet;
michael@0 99 }
michael@0 100
michael@0 101 mStyleSheetList.AppendElement(newSheet);
michael@0 102 }
michael@0 103 mRuleProcessor = new nsCSSRuleProcessor(mStyleSheetList,
michael@0 104 nsStyleSet::eDocSheet,
michael@0 105 nullptr);
michael@0 106
michael@0 107 return NS_OK;
michael@0 108 }
michael@0 109
michael@0 110 nsresult
michael@0 111 nsXBLPrototypeResources::Write(nsIObjectOutputStream* aStream)
michael@0 112 {
michael@0 113 if (mLoader)
michael@0 114 return mLoader->Write(aStream);
michael@0 115 return NS_OK;
michael@0 116 }
michael@0 117
michael@0 118 void
michael@0 119 nsXBLPrototypeResources::Traverse(nsCycleCollectionTraversalCallback &cb) const
michael@0 120 {
michael@0 121 NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "proto mResources mLoader");
michael@0 122 cb.NoteXPCOMChild(mLoader);
michael@0 123 }
michael@0 124
michael@0 125 void
michael@0 126 nsXBLPrototypeResources::ClearLoader()
michael@0 127 {
michael@0 128 mLoader = nullptr;
michael@0 129 }

mercurial