Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | /* DOM object holding utility CSS functions */ |
michael@0 | 7 | |
michael@0 | 8 | #include "CSS.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "mozilla/dom/BindingDeclarations.h" |
michael@0 | 11 | #include "nsCSSParser.h" |
michael@0 | 12 | #include "nsGlobalWindow.h" |
michael@0 | 13 | #include "nsIDocument.h" |
michael@0 | 14 | #include "nsIURI.h" |
michael@0 | 15 | #include "nsStyleUtil.h" |
michael@0 | 16 | |
michael@0 | 17 | namespace mozilla { |
michael@0 | 18 | namespace dom { |
michael@0 | 19 | |
michael@0 | 20 | struct SupportsParsingInfo |
michael@0 | 21 | { |
michael@0 | 22 | nsIURI* mDocURI; |
michael@0 | 23 | nsIURI* mBaseURI; |
michael@0 | 24 | nsIPrincipal* mPrincipal; |
michael@0 | 25 | }; |
michael@0 | 26 | |
michael@0 | 27 | static nsresult |
michael@0 | 28 | GetParsingInfo(nsISupports* aGlobal, |
michael@0 | 29 | SupportsParsingInfo& aInfo) |
michael@0 | 30 | { |
michael@0 | 31 | if (!aGlobal) { |
michael@0 | 32 | return NS_ERROR_FAILURE; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | nsGlobalWindow* win = nsGlobalWindow::FromSupports(aGlobal); |
michael@0 | 36 | nsCOMPtr<nsIDocument> doc = win->GetDoc(); |
michael@0 | 37 | if (!doc) { |
michael@0 | 38 | return NS_ERROR_FAILURE; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | aInfo.mDocURI = nsCOMPtr<nsIURI>(doc->GetDocumentURI()); |
michael@0 | 42 | aInfo.mBaseURI = nsCOMPtr<nsIURI>(doc->GetBaseURI()); |
michael@0 | 43 | aInfo.mPrincipal = win->GetPrincipal(); |
michael@0 | 44 | return NS_OK; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | /* static */ bool |
michael@0 | 48 | CSS::Supports(const GlobalObject& aGlobal, |
michael@0 | 49 | const nsAString& aProperty, |
michael@0 | 50 | const nsAString& aValue, |
michael@0 | 51 | ErrorResult& aRv) |
michael@0 | 52 | { |
michael@0 | 53 | nsCSSParser parser; |
michael@0 | 54 | SupportsParsingInfo info; |
michael@0 | 55 | |
michael@0 | 56 | nsresult rv = GetParsingInfo(aGlobal.GetAsSupports(), info); |
michael@0 | 57 | if (NS_FAILED(rv)) { |
michael@0 | 58 | aRv.Throw(rv); |
michael@0 | 59 | return false; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | return parser.EvaluateSupportsDeclaration(aProperty, aValue, info.mDocURI, |
michael@0 | 63 | info.mBaseURI, info.mPrincipal); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | /* static */ bool |
michael@0 | 67 | CSS::Supports(const GlobalObject& aGlobal, |
michael@0 | 68 | const nsAString& aCondition, |
michael@0 | 69 | ErrorResult& aRv) |
michael@0 | 70 | { |
michael@0 | 71 | nsCSSParser parser; |
michael@0 | 72 | SupportsParsingInfo info; |
michael@0 | 73 | |
michael@0 | 74 | nsresult rv = GetParsingInfo(aGlobal.GetAsSupports(), info); |
michael@0 | 75 | if (NS_FAILED(rv)) { |
michael@0 | 76 | aRv.Throw(rv); |
michael@0 | 77 | return false; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | return parser.EvaluateSupportsCondition(aCondition, info.mDocURI, |
michael@0 | 81 | info.mBaseURI, info.mPrincipal); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | /* static */ void |
michael@0 | 85 | CSS::Escape(const GlobalObject& aGlobal, |
michael@0 | 86 | const nsAString& aIdent, |
michael@0 | 87 | nsAString& aReturn, |
michael@0 | 88 | ErrorResult& aRv) |
michael@0 | 89 | { |
michael@0 | 90 | bool success = nsStyleUtil::AppendEscapedCSSIdent(aIdent, aReturn); |
michael@0 | 91 | |
michael@0 | 92 | if (!success) { |
michael@0 | 93 | aRv.Throw(NS_ERROR_DOM_INVALID_CHARACTER_ERR); |
michael@0 | 94 | } |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | } // dom |
michael@0 | 98 | } // mozilla |