Sat, 03 Jan 2015 20:18:00 +0100
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 | |
michael@0 | 7 | #include <stddef.h> // for nullptr |
michael@0 | 8 | |
michael@0 | 9 | #include "nsAString.h" |
michael@0 | 10 | #include "nsCOMPtr.h" // for nsCOMPtr, do_QueryInterface, etc |
michael@0 | 11 | #include "nsCSSStyleSheet.h" // for nsCSSStyleSheet |
michael@0 | 12 | #include "nsDebug.h" // for NS_ENSURE_TRUE |
michael@0 | 13 | #include "nsError.h" // for NS_OK, etc |
michael@0 | 14 | #include "nsIDOMDocument.h" // for nsIDOMDocument |
michael@0 | 15 | #include "nsIDocument.h" // for nsIDocument |
michael@0 | 16 | #include "nsIDocumentObserver.h" // for UPDATE_STYLE |
michael@0 | 17 | #include "nsIEditor.h" // for nsIEditor |
michael@0 | 18 | #include "nsStyleSheetTxns.h" |
michael@0 | 19 | |
michael@0 | 20 | class nsIStyleSheet; |
michael@0 | 21 | |
michael@0 | 22 | static void |
michael@0 | 23 | AddStyleSheet(nsIEditor* aEditor, nsIStyleSheet* aSheet) |
michael@0 | 24 | { |
michael@0 | 25 | nsCOMPtr<nsIDOMDocument> domDoc; |
michael@0 | 26 | aEditor->GetDocument(getter_AddRefs(domDoc)); |
michael@0 | 27 | nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc); |
michael@0 | 28 | if (doc) { |
michael@0 | 29 | doc->BeginUpdate(UPDATE_STYLE); |
michael@0 | 30 | doc->AddStyleSheet(aSheet); |
michael@0 | 31 | doc->EndUpdate(UPDATE_STYLE); |
michael@0 | 32 | } |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | static void |
michael@0 | 36 | RemoveStyleSheet(nsIEditor *aEditor, nsIStyleSheet *aSheet) |
michael@0 | 37 | { |
michael@0 | 38 | nsCOMPtr<nsIDOMDocument> domDoc; |
michael@0 | 39 | aEditor->GetDocument(getter_AddRefs(domDoc)); |
michael@0 | 40 | nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc); |
michael@0 | 41 | if (doc) { |
michael@0 | 42 | doc->BeginUpdate(UPDATE_STYLE); |
michael@0 | 43 | doc->RemoveStyleSheet(aSheet); |
michael@0 | 44 | doc->EndUpdate(UPDATE_STYLE); |
michael@0 | 45 | } |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | AddStyleSheetTxn::AddStyleSheetTxn() |
michael@0 | 49 | : EditTxn() |
michael@0 | 50 | , mEditor(nullptr) |
michael@0 | 51 | { |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | NS_IMPL_CYCLE_COLLECTION_INHERITED(AddStyleSheetTxn, EditTxn, |
michael@0 | 55 | mSheet) |
michael@0 | 56 | |
michael@0 | 57 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AddStyleSheetTxn) |
michael@0 | 58 | NS_INTERFACE_MAP_END_INHERITING(EditTxn) |
michael@0 | 59 | |
michael@0 | 60 | NS_IMETHODIMP |
michael@0 | 61 | AddStyleSheetTxn::Init(nsIEditor *aEditor, nsCSSStyleSheet *aSheet) |
michael@0 | 62 | { |
michael@0 | 63 | NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG); |
michael@0 | 64 | |
michael@0 | 65 | mEditor = aEditor; |
michael@0 | 66 | mSheet = aSheet; |
michael@0 | 67 | |
michael@0 | 68 | return NS_OK; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | |
michael@0 | 72 | NS_IMETHODIMP |
michael@0 | 73 | AddStyleSheetTxn::DoTransaction() |
michael@0 | 74 | { |
michael@0 | 75 | NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 76 | |
michael@0 | 77 | AddStyleSheet(mEditor, mSheet); |
michael@0 | 78 | return NS_OK; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | NS_IMETHODIMP |
michael@0 | 82 | AddStyleSheetTxn::UndoTransaction() |
michael@0 | 83 | { |
michael@0 | 84 | NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 85 | |
michael@0 | 86 | RemoveStyleSheet(mEditor, mSheet); |
michael@0 | 87 | return NS_OK; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | NS_IMETHODIMP |
michael@0 | 91 | AddStyleSheetTxn::GetTxnDescription(nsAString& aString) |
michael@0 | 92 | { |
michael@0 | 93 | aString.AssignLiteral("AddStyleSheetTxn"); |
michael@0 | 94 | return NS_OK; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | |
michael@0 | 98 | RemoveStyleSheetTxn::RemoveStyleSheetTxn() |
michael@0 | 99 | : EditTxn() |
michael@0 | 100 | , mEditor(nullptr) |
michael@0 | 101 | { |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | NS_IMPL_CYCLE_COLLECTION_INHERITED(RemoveStyleSheetTxn, EditTxn, |
michael@0 | 105 | mSheet) |
michael@0 | 106 | |
michael@0 | 107 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(RemoveStyleSheetTxn) |
michael@0 | 108 | NS_INTERFACE_MAP_END_INHERITING(EditTxn) |
michael@0 | 109 | |
michael@0 | 110 | NS_IMETHODIMP |
michael@0 | 111 | RemoveStyleSheetTxn::Init(nsIEditor *aEditor, nsCSSStyleSheet *aSheet) |
michael@0 | 112 | { |
michael@0 | 113 | NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG); |
michael@0 | 114 | |
michael@0 | 115 | mEditor = aEditor; |
michael@0 | 116 | mSheet = aSheet; |
michael@0 | 117 | |
michael@0 | 118 | return NS_OK; |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | |
michael@0 | 122 | NS_IMETHODIMP |
michael@0 | 123 | RemoveStyleSheetTxn::DoTransaction() |
michael@0 | 124 | { |
michael@0 | 125 | NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 126 | |
michael@0 | 127 | RemoveStyleSheet(mEditor, mSheet); |
michael@0 | 128 | return NS_OK; |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | NS_IMETHODIMP |
michael@0 | 132 | RemoveStyleSheetTxn::UndoTransaction() |
michael@0 | 133 | { |
michael@0 | 134 | NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 135 | |
michael@0 | 136 | AddStyleSheet(mEditor, mSheet); |
michael@0 | 137 | return NS_OK; |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | NS_IMETHODIMP |
michael@0 | 141 | RemoveStyleSheetTxn::GetTxnDescription(nsAString& aString) |
michael@0 | 142 | { |
michael@0 | 143 | aString.AssignLiteral("RemoveStyleSheetTxn"); |
michael@0 | 144 | return NS_OK; |
michael@0 | 145 | } |