LCOV - code coverage report
Current view: top level - editor/composer - nsComposerRegistration.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 53 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 10 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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/. */
       5             : 
       6             : #include <stddef.h>                     // for nullptr
       7             : 
       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
      27             : 
      28             : class nsISupports;
      29             : 
      30             : #define NS_HTMLEDITOR_COMMANDTABLE_CID \
      31             : { 0x13e50d8d, 0x9cee, 0x4ad1, { 0xa3, 0xa2, 0x4a, 0x44, 0x2f, 0xdf, 0x7d, 0xfa } }
      32             : 
      33             : #define NS_HTMLEDITOR_DOCSTATE_COMMANDTABLE_CID \
      34             : { 0xa33982d3, 0x1adf, 0x4162, { 0x99, 0x41, 0xf7, 0x34, 0xbc, 0x45, 0xe4, 0xed } }
      35             : 
      36             : 
      37             : static NS_DEFINE_CID(kHTMLEditorCommandTableCID, NS_HTMLEDITOR_COMMANDTABLE_CID);
      38             : static NS_DEFINE_CID(kHTMLEditorDocStateCommandTableCID, NS_HTMLEDITOR_DOCSTATE_COMMANDTABLE_CID);
      39             : 
      40             : 
      41             : ////////////////////////////////////////////////////////////////////////
      42             : // Define the contructor function for the objects
      43             : //
      44             : // NOTE: This creates an instance of objects by using the default constructor
      45             : //
      46             : 
      47           0 : NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditingSession)
      48           0 : NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorSpellCheck)
      49             : 
      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           0 : nsComposeTxtSrvFilterConstructor(nsISupports *aOuter, REFNSIID aIID,
      58             :                                  void **aResult, bool aIsForMail)
      59             : {
      60           0 :   *aResult = nullptr;
      61           0 :   if (aOuter) {
      62           0 :       return NS_ERROR_NO_AGGREGATION;
      63             :   }
      64           0 :   nsComposeTxtSrvFilter * inst = new nsComposeTxtSrvFilter();
      65           0 :   if (!inst) {
      66           0 :       return NS_ERROR_OUT_OF_MEMORY;
      67             :   }
      68           0 :   NS_ADDREF(inst);
      69           0 :   inst->Init(aIsForMail);
      70           0 :   nsresult rv = inst->QueryInterface(aIID, aResult);
      71           0 :   NS_RELEASE(inst);
      72           0 :   return rv;
      73             : }
      74             : 
      75             : static nsresult
      76           0 : nsComposeTxtSrvFilterConstructorForComposer(nsISupports *aOuter,
      77             :                                             REFNSIID aIID,
      78             :                                             void **aResult)
      79             : {
      80           0 :   return nsComposeTxtSrvFilterConstructor(aOuter, aIID, aResult, false);
      81             : }
      82             : 
      83             : static nsresult
      84           0 : nsComposeTxtSrvFilterConstructorForMail(nsISupports *aOuter,
      85             :                                         REFNSIID aIID,
      86             :                                         void **aResult)
      87             : {
      88           0 :   return nsComposeTxtSrvFilterConstructor(aOuter, aIID, aResult, true);
      89             : }
      90             : 
      91             : 
      92             : // Constructor for a controller set up with a command table specified
      93             : // by the CID passed in. This function uses do_GetService to get the
      94             : // command table, so that every controller shares a single command
      95             : // table, for space-efficiency.
      96             : //
      97             : // The only reason to go via the service manager for the command table
      98             : // is that it holds onto the singleton for us, avoiding static variables here.
      99             : static nsresult
     100           0 : CreateControllerWithSingletonCommandTable(const nsCID& inCommandTableCID, nsIController **aResult)
     101             : {
     102             :   nsresult rv;
     103           0 :   nsCOMPtr<nsIController> controller = do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv);
     104           0 :   NS_ENSURE_SUCCESS(rv, rv);
     105             : 
     106           0 :   nsCOMPtr<nsIControllerCommandTable> composerCommandTable = do_GetService(inCommandTableCID, &rv);
     107           0 :   NS_ENSURE_SUCCESS(rv, rv);
     108             : 
     109             :   // this guy is a singleton, so make it immutable
     110           0 :   composerCommandTable->MakeImmutable();
     111             : 
     112           0 :   nsCOMPtr<nsIControllerContext> controllerContext = do_QueryInterface(controller, &rv);
     113           0 :   NS_ENSURE_SUCCESS(rv, rv);
     114             : 
     115           0 :   rv = controllerContext->Init(composerCommandTable);
     116           0 :   NS_ENSURE_SUCCESS(rv, rv);
     117             : 
     118           0 :   *aResult = controller;
     119           0 :   NS_ADDREF(*aResult);
     120           0 :   return NS_OK;
     121             : }
     122             : 
     123             : 
     124             : // Here we make an instance of the controller that holds doc state commands.
     125             : // We set it up with a singleton command table.
     126             : static nsresult
     127           0 : nsHTMLEditorDocStateControllerConstructor(nsISupports *aOuter, REFNSIID aIID,
     128             :                                               void **aResult)
     129             : {
     130           0 :   nsCOMPtr<nsIController> controller;
     131           0 :   nsresult rv = CreateControllerWithSingletonCommandTable(kHTMLEditorDocStateCommandTableCID, getter_AddRefs(controller));
     132           0 :   NS_ENSURE_SUCCESS(rv, rv);
     133             : 
     134           0 :   return controller->QueryInterface(aIID, aResult);
     135             : }
     136             : 
     137             : // Tere we make an instance of the controller that holds composer commands.
     138             : // We set it up with a singleton command table.
     139             : static nsresult
     140           0 : nsHTMLEditorControllerConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
     141             : {
     142           0 :   nsCOMPtr<nsIController> controller;
     143           0 :   nsresult rv = CreateControllerWithSingletonCommandTable(kHTMLEditorCommandTableCID, getter_AddRefs(controller));
     144           0 :   NS_ENSURE_SUCCESS(rv, rv);
     145             : 
     146           0 :   return controller->QueryInterface(aIID, aResult);
     147             : }
     148             : 
     149             : // Constructor for a command table that is pref-filled with HTML editor commands
     150             : static nsresult
     151           0 : nsHTMLEditorCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID,
     152             :                                               void **aResult)
     153             : {
     154             :   nsresult rv;
     155             :   nsCOMPtr<nsIControllerCommandTable> commandTable =
     156           0 :       do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv);
     157           0 :   NS_ENSURE_SUCCESS(rv, rv);
     158             : 
     159           0 :   rv = nsComposerController::RegisterHTMLEditorCommands(commandTable);
     160           0 :   NS_ENSURE_SUCCESS(rv, rv);
     161             : 
     162             :   // we don't know here whether we're being created as an instance,
     163             :   // or a service, so we can't become immutable
     164             : 
     165           0 :   return commandTable->QueryInterface(aIID, aResult);
     166             : }
     167             : 
     168             : 
     169             : // Constructor for a command table that is pref-filled with HTML editor doc state commands
     170             : static nsresult
     171           0 : nsHTMLEditorDocStateCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID,
     172             :                                               void **aResult)
     173             : {
     174             :   nsresult rv;
     175             :   nsCOMPtr<nsIControllerCommandTable> commandTable =
     176           0 :       do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv);
     177           0 :   NS_ENSURE_SUCCESS(rv, rv);
     178             : 
     179           0 :   rv = nsComposerController::RegisterEditorDocStateCommands(commandTable);
     180           0 :   NS_ENSURE_SUCCESS(rv, rv);
     181             : 
     182             :   // we don't know here whether we're being created as an instance,
     183             :   // or a service, so we can't become immutable
     184             : 
     185           0 :   return commandTable->QueryInterface(aIID, aResult);
     186             : }
     187             : 
     188             : NS_DEFINE_NAMED_CID(NS_HTMLEDITORCONTROLLER_CID);
     189             : NS_DEFINE_NAMED_CID(NS_EDITORDOCSTATECONTROLLER_CID);
     190             : NS_DEFINE_NAMED_CID(NS_HTMLEDITOR_COMMANDTABLE_CID);
     191             : NS_DEFINE_NAMED_CID(NS_HTMLEDITOR_DOCSTATE_COMMANDTABLE_CID);
     192             : NS_DEFINE_NAMED_CID(NS_EDITINGSESSION_CID);
     193             : NS_DEFINE_NAMED_CID(NS_EDITORSPELLCHECK_CID);
     194             : NS_DEFINE_NAMED_CID(NS_COMPOSERTXTSRVFILTER_CID);
     195             : NS_DEFINE_NAMED_CID(NS_COMPOSERTXTSRVFILTERMAIL_CID);
     196             : 
     197             : 
     198             : static const mozilla::Module::CIDEntry kComposerCIDs[] = {
     199             :   { &kNS_HTMLEDITORCONTROLLER_CID, false, nullptr, nsHTMLEditorControllerConstructor },
     200             :   { &kNS_EDITORDOCSTATECONTROLLER_CID, false, nullptr, nsHTMLEditorDocStateControllerConstructor },
     201             :   { &kNS_HTMLEDITOR_COMMANDTABLE_CID, false, nullptr, nsHTMLEditorCommandTableConstructor },
     202             :   { &kNS_HTMLEDITOR_DOCSTATE_COMMANDTABLE_CID, false, nullptr, nsHTMLEditorDocStateCommandTableConstructor },
     203             :   { &kNS_EDITINGSESSION_CID, false, nullptr, nsEditingSessionConstructor },
     204             :   { &kNS_EDITORSPELLCHECK_CID, false, nullptr, nsEditorSpellCheckConstructor },
     205             :   { &kNS_COMPOSERTXTSRVFILTER_CID, false, nullptr, nsComposeTxtSrvFilterConstructorForComposer },
     206             :   { &kNS_COMPOSERTXTSRVFILTERMAIL_CID, false, nullptr, nsComposeTxtSrvFilterConstructorForMail },
     207             :   { nullptr }
     208             : };
     209             : 
     210             : static const mozilla::Module::ContractIDEntry kComposerContracts[] = {
     211             :   { "@mozilla.org/editor/htmleditorcontroller;1", &kNS_HTMLEDITORCONTROLLER_CID },
     212             :   { "@mozilla.org/editor/editordocstatecontroller;1", &kNS_EDITORDOCSTATECONTROLLER_CID },
     213             :   { "@mozilla.org/editor/editingsession;1", &kNS_EDITINGSESSION_CID },
     214             :   { "@mozilla.org/editor/editorspellchecker;1", &kNS_EDITORSPELLCHECK_CID },
     215             :   { COMPOSER_TXTSRVFILTER_CONTRACTID, &kNS_COMPOSERTXTSRVFILTER_CID },
     216             :   { COMPOSER_TXTSRVFILTERMAIL_CONTRACTID, &kNS_COMPOSERTXTSRVFILTERMAIL_CID },
     217             :   { nullptr }
     218             : };
     219             : 
     220             : static const mozilla::Module kComposerModule = {
     221             :   mozilla::Module::kVersion,
     222             :   kComposerCIDs,
     223             :   kComposerContracts
     224             : };
     225             : 
     226             : NSMODULE_DEFN(nsComposerModule) = &kComposerModule;

Generated by: LCOV version 1.13