editor/libeditor/base/nsStyleSheetTxns.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.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #include <stddef.h>                     // for nullptr
     9 #include "nsAString.h"
    10 #include "nsCOMPtr.h"                   // for nsCOMPtr, do_QueryInterface, etc
    11 #include "nsCSSStyleSheet.h"            // for nsCSSStyleSheet
    12 #include "nsDebug.h"                    // for NS_ENSURE_TRUE
    13 #include "nsError.h"                    // for NS_OK, etc
    14 #include "nsIDOMDocument.h"             // for nsIDOMDocument
    15 #include "nsIDocument.h"                // for nsIDocument
    16 #include "nsIDocumentObserver.h"        // for UPDATE_STYLE
    17 #include "nsIEditor.h"                  // for nsIEditor
    18 #include "nsStyleSheetTxns.h"
    20 class nsIStyleSheet;
    22 static void
    23 AddStyleSheet(nsIEditor* aEditor, nsIStyleSheet* aSheet)
    24 {
    25   nsCOMPtr<nsIDOMDocument> domDoc;
    26   aEditor->GetDocument(getter_AddRefs(domDoc));
    27   nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
    28   if (doc) {
    29     doc->BeginUpdate(UPDATE_STYLE);
    30     doc->AddStyleSheet(aSheet);
    31     doc->EndUpdate(UPDATE_STYLE);
    32   }
    33 }
    35 static void
    36 RemoveStyleSheet(nsIEditor *aEditor, nsIStyleSheet *aSheet)
    37 {
    38   nsCOMPtr<nsIDOMDocument> domDoc;
    39   aEditor->GetDocument(getter_AddRefs(domDoc));
    40   nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
    41   if (doc) {
    42     doc->BeginUpdate(UPDATE_STYLE);
    43     doc->RemoveStyleSheet(aSheet);
    44     doc->EndUpdate(UPDATE_STYLE);
    45   }
    46 }
    48 AddStyleSheetTxn::AddStyleSheetTxn()
    49 :  EditTxn()
    50 ,  mEditor(nullptr)
    51 {
    52 }
    54 NS_IMPL_CYCLE_COLLECTION_INHERITED(AddStyleSheetTxn, EditTxn,
    55                                    mSheet)
    57 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AddStyleSheetTxn)
    58 NS_INTERFACE_MAP_END_INHERITING(EditTxn)
    60 NS_IMETHODIMP
    61 AddStyleSheetTxn::Init(nsIEditor *aEditor, nsCSSStyleSheet *aSheet)
    62 {
    63   NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG);
    65   mEditor = aEditor;
    66   mSheet = aSheet;
    68   return NS_OK;
    69 }
    72 NS_IMETHODIMP
    73 AddStyleSheetTxn::DoTransaction()
    74 {
    75   NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
    77   AddStyleSheet(mEditor, mSheet);
    78   return NS_OK;
    79 }
    81 NS_IMETHODIMP
    82 AddStyleSheetTxn::UndoTransaction()
    83 {
    84   NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
    86   RemoveStyleSheet(mEditor, mSheet);
    87   return NS_OK;
    88 }
    90 NS_IMETHODIMP
    91 AddStyleSheetTxn::GetTxnDescription(nsAString& aString)
    92 {
    93   aString.AssignLiteral("AddStyleSheetTxn");
    94   return NS_OK;
    95 }
    98 RemoveStyleSheetTxn::RemoveStyleSheetTxn()
    99 :  EditTxn()
   100 ,  mEditor(nullptr)
   101 {
   102 }
   104 NS_IMPL_CYCLE_COLLECTION_INHERITED(RemoveStyleSheetTxn, EditTxn,
   105                                    mSheet)
   107 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(RemoveStyleSheetTxn)
   108 NS_INTERFACE_MAP_END_INHERITING(EditTxn)
   110 NS_IMETHODIMP
   111 RemoveStyleSheetTxn::Init(nsIEditor *aEditor, nsCSSStyleSheet *aSheet)
   112 {
   113   NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG);
   115   mEditor = aEditor;
   116   mSheet = aSheet;
   118   return NS_OK;
   119 }
   122 NS_IMETHODIMP
   123 RemoveStyleSheetTxn::DoTransaction()
   124 {
   125   NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
   127   RemoveStyleSheet(mEditor, mSheet);
   128   return NS_OK;
   129 }
   131 NS_IMETHODIMP
   132 RemoveStyleSheetTxn::UndoTransaction()
   133 {
   134   NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
   136   AddStyleSheet(mEditor, mSheet);
   137   return NS_OK;
   138 }
   140 NS_IMETHODIMP
   141 RemoveStyleSheetTxn::GetTxnDescription(nsAString& aString)
   142 {
   143   aString.AssignLiteral("RemoveStyleSheetTxn");
   144   return NS_OK;
   145 }

mercurial