1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/xbl/nsXBLPrototypeResources.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,129 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsIStyleRuleProcessor.h" 1.10 +#include "nsIDocument.h" 1.11 +#include "nsIContent.h" 1.12 +#include "nsIServiceManager.h" 1.13 +#include "nsXBLResourceLoader.h" 1.14 +#include "nsXBLPrototypeResources.h" 1.15 +#include "nsXBLPrototypeBinding.h" 1.16 +#include "nsIDocumentObserver.h" 1.17 +#include "mozilla/css/Loader.h" 1.18 +#include "nsIURI.h" 1.19 +#include "nsLayoutCID.h" 1.20 +#include "nsCSSRuleProcessor.h" 1.21 +#include "nsStyleSet.h" 1.22 +#include "mozilla/dom/URL.h" 1.23 + 1.24 +using mozilla::dom::IsChromeURI; 1.25 + 1.26 +nsXBLPrototypeResources::nsXBLPrototypeResources(nsXBLPrototypeBinding* aBinding) 1.27 +{ 1.28 + MOZ_COUNT_CTOR(nsXBLPrototypeResources); 1.29 + 1.30 + mLoader = new nsXBLResourceLoader(aBinding, this); 1.31 +} 1.32 + 1.33 +nsXBLPrototypeResources::~nsXBLPrototypeResources() 1.34 +{ 1.35 + MOZ_COUNT_DTOR(nsXBLPrototypeResources); 1.36 + if (mLoader) { 1.37 + mLoader->mResources = nullptr; 1.38 + } 1.39 +} 1.40 + 1.41 +void 1.42 +nsXBLPrototypeResources::AddResource(nsIAtom* aResourceType, const nsAString& aSrc) 1.43 +{ 1.44 + if (mLoader) 1.45 + mLoader->AddResource(aResourceType, aSrc); 1.46 +} 1.47 + 1.48 +void 1.49 +nsXBLPrototypeResources::LoadResources(bool* aResult) 1.50 +{ 1.51 + if (mLoader) 1.52 + mLoader->LoadResources(aResult); 1.53 + else 1.54 + *aResult = true; // All resources loaded. 1.55 +} 1.56 + 1.57 +void 1.58 +nsXBLPrototypeResources::AddResourceListener(nsIContent* aBoundElement) 1.59 +{ 1.60 + if (mLoader) 1.61 + mLoader->AddResourceListener(aBoundElement); 1.62 +} 1.63 + 1.64 +nsresult 1.65 +nsXBLPrototypeResources::FlushSkinSheets() 1.66 +{ 1.67 + if (mStyleSheetList.Length() == 0) 1.68 + return NS_OK; 1.69 + 1.70 + nsCOMPtr<nsIDocument> doc = 1.71 + mLoader->mBinding->XBLDocumentInfo()->GetDocument(); 1.72 + 1.73 + // If doc is null, we're in the process of tearing things down, so just 1.74 + // return without rebuilding anything. 1.75 + if (!doc) { 1.76 + return NS_OK; 1.77 + } 1.78 + 1.79 + // We have scoped stylesheets. Reload any chrome stylesheets we 1.80 + // encounter. (If they aren't skin sheets, it doesn't matter, since 1.81 + // they'll still be in the chrome cache. 1.82 + mRuleProcessor = nullptr; 1.83 + 1.84 + sheet_array_type oldSheets(mStyleSheetList); 1.85 + mStyleSheetList.Clear(); 1.86 + 1.87 + mozilla::css::Loader* cssLoader = doc->CSSLoader(); 1.88 + 1.89 + for (sheet_array_type::size_type i = 0, count = oldSheets.Length(); 1.90 + i < count; ++i) { 1.91 + nsCSSStyleSheet* oldSheet = oldSheets[i]; 1.92 + 1.93 + nsIURI* uri = oldSheet->GetSheetURI(); 1.94 + 1.95 + nsRefPtr<nsCSSStyleSheet> newSheet; 1.96 + if (IsChromeURI(uri)) { 1.97 + if (NS_FAILED(cssLoader->LoadSheetSync(uri, getter_AddRefs(newSheet)))) 1.98 + continue; 1.99 + } 1.100 + else { 1.101 + newSheet = oldSheet; 1.102 + } 1.103 + 1.104 + mStyleSheetList.AppendElement(newSheet); 1.105 + } 1.106 + mRuleProcessor = new nsCSSRuleProcessor(mStyleSheetList, 1.107 + nsStyleSet::eDocSheet, 1.108 + nullptr); 1.109 + 1.110 + return NS_OK; 1.111 +} 1.112 + 1.113 +nsresult 1.114 +nsXBLPrototypeResources::Write(nsIObjectOutputStream* aStream) 1.115 +{ 1.116 + if (mLoader) 1.117 + return mLoader->Write(aStream); 1.118 + return NS_OK; 1.119 +} 1.120 + 1.121 +void 1.122 +nsXBLPrototypeResources::Traverse(nsCycleCollectionTraversalCallback &cb) const 1.123 +{ 1.124 + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "proto mResources mLoader"); 1.125 + cb.NoteXPCOMChild(mLoader); 1.126 +} 1.127 + 1.128 +void 1.129 +nsXBLPrototypeResources::ClearLoader() 1.130 +{ 1.131 + mLoader = nullptr; 1.132 +}