editor/composer/src/nsComposerRegistration.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/. */
     6 #include <stddef.h>                     // for nullptr
     8 #include "mozilla/Module.h"             // for Module, Module::CIDEntry, etc
     9 #include "mozilla/ModuleUtils.h"
    10 #include "mozilla/mozalloc.h"           // for operator new
    11 #include "nsCOMPtr.h"                   // for nsCOMPtr, getter_AddRefs, etc
    12 #include "nsComponentManagerUtils.h"    // for do_CreateInstance
    13 #include "nsComposeTxtSrvFilter.h"      // for nsComposeTxtSrvFilter, etc
    14 #include "nsComposerController.h"       // for nsComposerController, etc
    15 #include "nsDebug.h"                    // for NS_ENSURE_SUCCESS
    16 #include "nsEditingSession.h"           // for NS_EDITINGSESSION_CID, etc
    17 #include "nsEditorSpellCheck.h"         // for NS_EDITORSPELLCHECK_CID, etc
    18 #include "nsError.h"                    // for NS_ERROR_NO_AGGREGATION, etc
    19 #include "nsIController.h"              // for nsIController
    20 #include "nsIControllerCommandTable.h"  // for nsIControllerCommandTable, etc
    21 #include "nsIControllerContext.h"       // for nsIControllerContext
    22 #include "nsID.h"                       // for NS_DEFINE_NAMED_CID, etc
    23 #include "nsISupportsImpl.h"
    24 #include "nsISupportsUtils.h"           // for NS_ADDREF, NS_RELEASE
    25 #include "nsServiceManagerUtils.h"      // for do_GetService
    26 #include "nscore.h"                     // for nsresult
    28 class nsISupports;
    30 #define NS_HTMLEDITOR_COMMANDTABLE_CID \
    31 { 0x13e50d8d, 0x9cee, 0x4ad1, { 0xa3, 0xa2, 0x4a, 0x44, 0x2f, 0xdf, 0x7d, 0xfa } }
    33 #define NS_HTMLEDITOR_DOCSTATE_COMMANDTABLE_CID \
    34 { 0xa33982d3, 0x1adf, 0x4162, { 0x99, 0x41, 0xf7, 0x34, 0xbc, 0x45, 0xe4, 0xed } }
    37 static NS_DEFINE_CID(kHTMLEditorCommandTableCID, NS_HTMLEDITOR_COMMANDTABLE_CID);
    38 static NS_DEFINE_CID(kHTMLEditorDocStateCommandTableCID, NS_HTMLEDITOR_DOCSTATE_COMMANDTABLE_CID);
    41 ////////////////////////////////////////////////////////////////////////
    42 // Define the contructor function for the objects
    43 //
    44 // NOTE: This creates an instance of objects by using the default constructor
    45 //
    47 NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditingSession)
    48 NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorSpellCheck)
    50 // There are no macros that enable us to have 2 constructors 
    51 // for the same object
    52 //
    53 // Here we are creating the same object with two different contract IDs
    54 // and then initializing it different.
    55 // Basically, we need to tell the filter whether it is doing mail or not
    56 static nsresult
    57 nsComposeTxtSrvFilterConstructor(nsISupports *aOuter, REFNSIID aIID,
    58                                  void **aResult, bool aIsForMail)
    59 {
    60     *aResult = nullptr;
    61     if (nullptr != aOuter) 
    62     {
    63         return NS_ERROR_NO_AGGREGATION;
    64     }
    65     nsComposeTxtSrvFilter * inst = new nsComposeTxtSrvFilter();
    66     if (nullptr == inst) 
    67     {
    68         return NS_ERROR_OUT_OF_MEMORY;
    69     }
    70     NS_ADDREF(inst);
    71 	  inst->Init(aIsForMail);
    72     nsresult rv = inst->QueryInterface(aIID, aResult);
    73     NS_RELEASE(inst);
    74     return rv;
    75 }
    77 static nsresult
    78 nsComposeTxtSrvFilterConstructorForComposer(nsISupports *aOuter, 
    79                                             REFNSIID aIID,
    80                                             void **aResult)
    81 {
    82     return nsComposeTxtSrvFilterConstructor(aOuter, aIID, aResult, false);
    83 }
    85 static nsresult
    86 nsComposeTxtSrvFilterConstructorForMail(nsISupports *aOuter, 
    87                                         REFNSIID aIID,
    88                                         void **aResult)
    89 {
    90     return nsComposeTxtSrvFilterConstructor(aOuter, aIID, aResult, true);
    91 }
    94 // Constructor for a controller set up with a command table specified
    95 // by the CID passed in. This function uses do_GetService to get the
    96 // command table, so that every controller shares a single command
    97 // table, for space-efficiency.
    98 // 
    99 // The only reason to go via the service manager for the command table
   100 // is that it holds onto the singleton for us, avoiding static variables here.
   101 static nsresult
   102 CreateControllerWithSingletonCommandTable(const nsCID& inCommandTableCID, nsIController **aResult)
   103 {
   104   nsresult rv;
   105   nsCOMPtr<nsIController> controller = do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv);
   106   NS_ENSURE_SUCCESS(rv, rv);
   108   nsCOMPtr<nsIControllerCommandTable> composerCommandTable = do_GetService(inCommandTableCID, &rv);
   109   NS_ENSURE_SUCCESS(rv, rv);
   111   // this guy is a singleton, so make it immutable
   112   composerCommandTable->MakeImmutable();
   114   nsCOMPtr<nsIControllerContext> controllerContext = do_QueryInterface(controller, &rv);
   115   NS_ENSURE_SUCCESS(rv, rv);
   117   rv = controllerContext->Init(composerCommandTable);
   118   NS_ENSURE_SUCCESS(rv, rv);
   120   *aResult = controller;
   121   NS_ADDREF(*aResult);
   122   return NS_OK;
   123 }
   126 // Here we make an instance of the controller that holds doc state commands.
   127 // We set it up with a singleton command table.
   128 static nsresult
   129 nsHTMLEditorDocStateControllerConstructor(nsISupports *aOuter, REFNSIID aIID, 
   130                                               void **aResult)
   131 {
   132   nsCOMPtr<nsIController> controller;
   133   nsresult rv = CreateControllerWithSingletonCommandTable(kHTMLEditorDocStateCommandTableCID, getter_AddRefs(controller));
   134   NS_ENSURE_SUCCESS(rv, rv);
   136   return controller->QueryInterface(aIID, aResult);
   137 }
   139 // Tere we make an instance of the controller that holds composer commands.
   140 // We set it up with a singleton command table.
   141 static nsresult
   142 nsHTMLEditorControllerConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
   143 {
   144   nsCOMPtr<nsIController> controller;
   145   nsresult rv = CreateControllerWithSingletonCommandTable(kHTMLEditorCommandTableCID, getter_AddRefs(controller));
   146   NS_ENSURE_SUCCESS(rv, rv);
   148   return controller->QueryInterface(aIID, aResult);
   149 }
   151 // Constructor for a command table that is pref-filled with HTML editor commands
   152 static nsresult
   153 nsHTMLEditorCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID, 
   154                                               void **aResult)
   155 {
   156   nsresult rv;
   157   nsCOMPtr<nsIControllerCommandTable> commandTable =
   158       do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv);
   159   NS_ENSURE_SUCCESS(rv, rv);
   161   rv = nsComposerController::RegisterHTMLEditorCommands(commandTable);
   162   NS_ENSURE_SUCCESS(rv, rv);
   164   // we don't know here whether we're being created as an instance,
   165   // or a service, so we can't become immutable
   167   return commandTable->QueryInterface(aIID, aResult);
   168 }
   171 // Constructor for a command table that is pref-filled with HTML editor doc state commands
   172 static nsresult
   173 nsHTMLEditorDocStateCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID, 
   174                                               void **aResult)
   175 {
   176   nsresult rv;
   177   nsCOMPtr<nsIControllerCommandTable> commandTable =
   178       do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv);
   179   NS_ENSURE_SUCCESS(rv, rv);
   181   rv = nsComposerController::RegisterEditorDocStateCommands(commandTable);
   182   NS_ENSURE_SUCCESS(rv, rv);
   184   // we don't know here whether we're being created as an instance,
   185   // or a service, so we can't become immutable
   187   return commandTable->QueryInterface(aIID, aResult);
   188 }
   190 NS_DEFINE_NAMED_CID(NS_HTMLEDITORCONTROLLER_CID);
   191 NS_DEFINE_NAMED_CID(NS_EDITORDOCSTATECONTROLLER_CID);
   192 NS_DEFINE_NAMED_CID(NS_HTMLEDITOR_COMMANDTABLE_CID);
   193 NS_DEFINE_NAMED_CID(NS_HTMLEDITOR_DOCSTATE_COMMANDTABLE_CID);
   194 NS_DEFINE_NAMED_CID(NS_EDITINGSESSION_CID);
   195 NS_DEFINE_NAMED_CID(NS_EDITORSPELLCHECK_CID);
   196 NS_DEFINE_NAMED_CID(NS_COMPOSERTXTSRVFILTER_CID);
   197 NS_DEFINE_NAMED_CID(NS_COMPOSERTXTSRVFILTERMAIL_CID);
   200 static const mozilla::Module::CIDEntry kComposerCIDs[] = {
   201   { &kNS_HTMLEDITORCONTROLLER_CID, false, nullptr, nsHTMLEditorControllerConstructor },
   202   { &kNS_EDITORDOCSTATECONTROLLER_CID, false, nullptr, nsHTMLEditorDocStateControllerConstructor },
   203   { &kNS_HTMLEDITOR_COMMANDTABLE_CID, false, nullptr, nsHTMLEditorCommandTableConstructor },
   204   { &kNS_HTMLEDITOR_DOCSTATE_COMMANDTABLE_CID, false, nullptr, nsHTMLEditorDocStateCommandTableConstructor },
   205   { &kNS_EDITINGSESSION_CID, false, nullptr, nsEditingSessionConstructor },
   206   { &kNS_EDITORSPELLCHECK_CID, false, nullptr, nsEditorSpellCheckConstructor },
   207   { &kNS_COMPOSERTXTSRVFILTER_CID, false, nullptr, nsComposeTxtSrvFilterConstructorForComposer },
   208   { &kNS_COMPOSERTXTSRVFILTERMAIL_CID, false, nullptr, nsComposeTxtSrvFilterConstructorForMail },
   209   { nullptr }
   210 };
   212 static const mozilla::Module::ContractIDEntry kComposerContracts[] = {
   213   { "@mozilla.org/editor/htmleditorcontroller;1", &kNS_HTMLEDITORCONTROLLER_CID },
   214   { "@mozilla.org/editor/editordocstatecontroller;1", &kNS_EDITORDOCSTATECONTROLLER_CID },
   215   { "@mozilla.org/editor/editingsession;1", &kNS_EDITINGSESSION_CID },
   216   { "@mozilla.org/editor/editorspellchecker;1", &kNS_EDITORSPELLCHECK_CID },
   217   { COMPOSER_TXTSRVFILTER_CONTRACTID, &kNS_COMPOSERTXTSRVFILTER_CID },
   218   { COMPOSER_TXTSRVFILTERMAIL_CONTRACTID, &kNS_COMPOSERTXTSRVFILTERMAIL_CID },
   219   { nullptr }
   220 };
   222 static const mozilla::Module kComposerModule = {
   223   mozilla::Module::kVersion,
   224   kComposerCIDs,
   225   kComposerContracts
   226 };
   228 NSMODULE_DEFN(nsComposerModule) = &kComposerModule;

mercurial