From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- embedding/components/appstartup/moz.build | 15 + .../components/appstartup/nsAppStartupNotifier.cpp | 90 + .../components/appstartup/nsAppStartupNotifier.h | 30 + .../components/appstartup/nsIAppStartupNotifier.h | 59 + embedding/components/build/moz.build | 38 + embedding/components/build/nsEmbeddingModule.cpp | 120 + embedding/components/commandhandler/moz.build | 26 + .../commandhandler/nsBaseCommandController.cpp | 184 ++ .../commandhandler/nsBaseCommandController.h | 49 + .../components/commandhandler/nsCommandGroup.cpp | 296 +++ .../components/commandhandler/nsCommandGroup.h | 44 + .../components/commandhandler/nsCommandManager.cpp | 262 ++ .../components/commandhandler/nsCommandManager.h | 50 + .../components/commandhandler/nsCommandParams.cpp | 264 ++ .../components/commandhandler/nsCommandParams.h | 131 + .../commandhandler/nsControllerCommandTable.cpp | 209 ++ .../commandhandler/nsControllerCommandTable.h | 36 + .../commandhandler/nsICommandManager.idl | 118 + .../components/commandhandler/nsICommandParams.idl | 85 + .../commandhandler/nsIControllerCommand.idl | 51 + .../commandhandler/nsIControllerCommandTable.idl | 100 + .../commandhandler/nsIControllerContext.idl | 35 + .../commandhandler/nsPICommandUpdater.idl | 39 + embedding/components/find/moz.build | 19 + embedding/components/find/nsFind.cpp | 1383 ++++++++++ embedding/components/find/nsFind.h | 83 + embedding/components/find/nsIFind.idl | 34 + embedding/components/find/nsIWebBrowserFind.idl | 145 + embedding/components/find/nsWebBrowserFind.cpp | 868 ++++++ embedding/components/find/nsWebBrowserFind.h | 95 + embedding/components/moz.build | 20 + .../printingui/ipc/PPrintProgressDialog.ipdl | 35 + .../printingui/ipc/PPrintSettingsDialog.ipdl | 29 + embedding/components/printingui/ipc/PPrinting.ipdl | 48 + .../components/printingui/ipc/PPrintingTypes.ipdlh | 126 + .../components/printingui/ipc/PrintDataUtils.cpp | 158 ++ .../components/printingui/ipc/PrintDataUtils.h | 39 + .../printingui/ipc/PrintProgressDialogChild.cpp | 132 + .../printingui/ipc/PrintProgressDialogChild.h | 40 + .../printingui/ipc/PrintProgressDialogParent.cpp | 113 + .../printingui/ipc/PrintProgressDialogParent.h | 64 + .../printingui/ipc/PrintSettingsDialogChild.cpp | 38 + .../printingui/ipc/PrintSettingsDialogChild.h | 35 + .../printingui/ipc/PrintSettingsDialogParent.cpp | 28 + .../printingui/ipc/PrintSettingsDialogParent.h | 29 + .../components/printingui/ipc/PrintingParent.cpp | 336 +++ .../components/printingui/ipc/PrintingParent.h | 109 + embedding/components/printingui/ipc/moz.build | 35 + .../components/printingui/ipc/nsPrintingProxy.cpp | 269 ++ .../components/printingui/ipc/nsPrintingProxy.h | 57 + embedding/components/printingui/mac/moz.build | 16 + .../components/printingui/mac/nsPrintProgress.cpp | 213 ++ .../components/printingui/mac/nsPrintProgress.h | 44 + .../printingui/mac/nsPrintProgressParams.cpp | 47 + .../printingui/mac/nsPrintProgressParams.h | 28 + .../printingui/mac/nsPrintingPromptService.h | 43 + .../printingui/mac/nsPrintingPromptServiceX.mm | 128 + embedding/components/printingui/moz.build | 17 + .../components/printingui/unixshared/moz.build | 13 + .../printingui/unixshared/nsPrintProgress.cpp | 267 ++ .../printingui/unixshared/nsPrintProgress.h | 46 + .../unixshared/nsPrintProgressParams.cpp | 47 + .../printingui/unixshared/nsPrintProgressParams.h | 28 + .../unixshared/nsPrintingPromptService.cpp | 298 +++ .../unixshared/nsPrintingPromptService.h | 58 + embedding/components/printingui/win/moz.build | 18 + .../printingui/win/nsPrintDialogUtil.cpp | 854 ++++++ .../components/printingui/win/nsPrintDialogUtil.h | 12 + .../components/printingui/win/nsPrintProgress.cpp | 293 ++ .../components/printingui/win/nsPrintProgress.h | 43 + .../printingui/win/nsPrintProgressParams.cpp | 47 + .../printingui/win/nsPrintProgressParams.h | 27 + .../printingui/win/nsPrintingPromptService.cpp | 341 +++ .../printingui/win/nsPrintingPromptService.h | 58 + .../PWebBrowserPersistDocument.ipdl | 90 + .../PWebBrowserPersistResources.ipdl | 26 + .../PWebBrowserPersistSerialize.ipdl | 29 + .../WebBrowserPersistDocumentChild.cpp | 159 ++ .../WebBrowserPersistDocumentChild.h | 62 + .../WebBrowserPersistDocumentParent.cpp | 125 + .../WebBrowserPersistDocumentParent.h | 79 + .../WebBrowserPersistLocalDocument.cpp | 1475 ++++++++++ .../WebBrowserPersistLocalDocument.h | 51 + .../WebBrowserPersistRemoteDocument.cpp | 186 ++ .../WebBrowserPersistRemoteDocument.h | 55 + .../WebBrowserPersistResourcesChild.cpp | 73 + .../WebBrowserPersistResourcesChild.h | 31 + .../WebBrowserPersistResourcesParent.cpp | 87 + .../WebBrowserPersistResourcesParent.h | 54 + .../WebBrowserPersistSerializeChild.cpp | 143 + .../WebBrowserPersistSerializeChild.h | 39 + .../WebBrowserPersistSerializeParent.cpp | 90 + .../WebBrowserPersistSerializeParent.h | 49 + embedding/components/webbrowserpersist/moz.build | 49 + .../webbrowserpersist/nsCWebBrowserPersist.idl | 15 + .../webbrowserpersist/nsIWebBrowserPersist.idl | 286 ++ .../nsIWebBrowserPersistDocument.idl | 197 ++ .../webbrowserpersist/nsIWebBrowserPersistable.idl | 41 + .../webbrowserpersist/nsWebBrowserPersist.cpp | 2812 ++++++++++++++++++++ .../webbrowserpersist/nsWebBrowserPersist.h | 181 ++ embedding/components/windowwatcher/moz.build | 49 + .../windowwatcher/nsAutoWindowStateHelper.cpp | 73 + .../windowwatcher/nsAutoWindowStateHelper.h | 35 + .../windowwatcher/nsDialogParamBlock.cpp | 101 + .../components/windowwatcher/nsDialogParamBlock.h | 45 + .../windowwatcher/nsIDialogParamBlock.idl | 42 + .../components/windowwatcher/nsIPromptFactory.idl | 22 + .../components/windowwatcher/nsIPromptService.idl | 346 +++ .../components/windowwatcher/nsIPromptService2.idl | 45 + .../components/windowwatcher/nsIWindowWatcher.idl | 167 ++ .../components/windowwatcher/nsPIPromptService.idl | 31 + .../components/windowwatcher/nsPIWindowWatcher.idl | 146 + embedding/components/windowwatcher/nsPromptUtils.h | 141 + .../components/windowwatcher/nsWindowWatcher.cpp | 2610 ++++++++++++++++++ .../components/windowwatcher/nsWindowWatcher.h | 156 ++ .../components/windowwatcher/test/browser.ini | 9 + .../test/browser_new_content_window_chromeflags.js | 278 ++ ...ser_new_content_window_from_chrome_principal.js | 34 + .../test/browser_new_remote_window_flags.js | 78 + .../windowwatcher/test/browser_new_sized_window.js | 67 + embedding/components/windowwatcher/test/chrome.ini | 7 + .../windowwatcher/test/file_storage_copied.html | 13 + .../windowwatcher/test/file_test_dialog.html | 14 + .../components/windowwatcher/test/mochitest.ini | 12 + embedding/components/windowwatcher/test/moz.build | 18 + .../test/test_blank_named_window.html | 45 + .../windowwatcher/test/test_dialog_arguments.html | 38 + .../windowwatcher/test/test_modal_windows.html | 56 + .../windowwatcher/test/test_named_window.html | 92 + .../windowwatcher/test/test_storage_copied.html | 45 + 130 files changed, 20983 insertions(+) create mode 100644 embedding/components/appstartup/moz.build create mode 100644 embedding/components/appstartup/nsAppStartupNotifier.cpp create mode 100644 embedding/components/appstartup/nsAppStartupNotifier.h create mode 100644 embedding/components/appstartup/nsIAppStartupNotifier.h create mode 100644 embedding/components/build/moz.build create mode 100644 embedding/components/build/nsEmbeddingModule.cpp create mode 100644 embedding/components/commandhandler/moz.build create mode 100644 embedding/components/commandhandler/nsBaseCommandController.cpp create mode 100644 embedding/components/commandhandler/nsBaseCommandController.h create mode 100644 embedding/components/commandhandler/nsCommandGroup.cpp create mode 100644 embedding/components/commandhandler/nsCommandGroup.h create mode 100644 embedding/components/commandhandler/nsCommandManager.cpp create mode 100644 embedding/components/commandhandler/nsCommandManager.h create mode 100644 embedding/components/commandhandler/nsCommandParams.cpp create mode 100644 embedding/components/commandhandler/nsCommandParams.h create mode 100644 embedding/components/commandhandler/nsControllerCommandTable.cpp create mode 100644 embedding/components/commandhandler/nsControllerCommandTable.h create mode 100644 embedding/components/commandhandler/nsICommandManager.idl create mode 100644 embedding/components/commandhandler/nsICommandParams.idl create mode 100644 embedding/components/commandhandler/nsIControllerCommand.idl create mode 100644 embedding/components/commandhandler/nsIControllerCommandTable.idl create mode 100644 embedding/components/commandhandler/nsIControllerContext.idl create mode 100644 embedding/components/commandhandler/nsPICommandUpdater.idl create mode 100644 embedding/components/find/moz.build create mode 100644 embedding/components/find/nsFind.cpp create mode 100644 embedding/components/find/nsFind.h create mode 100644 embedding/components/find/nsIFind.idl create mode 100644 embedding/components/find/nsIWebBrowserFind.idl create mode 100644 embedding/components/find/nsWebBrowserFind.cpp create mode 100644 embedding/components/find/nsWebBrowserFind.h create mode 100644 embedding/components/moz.build create mode 100644 embedding/components/printingui/ipc/PPrintProgressDialog.ipdl create mode 100644 embedding/components/printingui/ipc/PPrintSettingsDialog.ipdl create mode 100644 embedding/components/printingui/ipc/PPrinting.ipdl create mode 100644 embedding/components/printingui/ipc/PPrintingTypes.ipdlh create mode 100644 embedding/components/printingui/ipc/PrintDataUtils.cpp create mode 100644 embedding/components/printingui/ipc/PrintDataUtils.h create mode 100644 embedding/components/printingui/ipc/PrintProgressDialogChild.cpp create mode 100644 embedding/components/printingui/ipc/PrintProgressDialogChild.h create mode 100644 embedding/components/printingui/ipc/PrintProgressDialogParent.cpp create mode 100644 embedding/components/printingui/ipc/PrintProgressDialogParent.h create mode 100644 embedding/components/printingui/ipc/PrintSettingsDialogChild.cpp create mode 100644 embedding/components/printingui/ipc/PrintSettingsDialogChild.h create mode 100644 embedding/components/printingui/ipc/PrintSettingsDialogParent.cpp create mode 100644 embedding/components/printingui/ipc/PrintSettingsDialogParent.h create mode 100644 embedding/components/printingui/ipc/PrintingParent.cpp create mode 100644 embedding/components/printingui/ipc/PrintingParent.h create mode 100644 embedding/components/printingui/ipc/moz.build create mode 100644 embedding/components/printingui/ipc/nsPrintingProxy.cpp create mode 100644 embedding/components/printingui/ipc/nsPrintingProxy.h create mode 100644 embedding/components/printingui/mac/moz.build create mode 100644 embedding/components/printingui/mac/nsPrintProgress.cpp create mode 100644 embedding/components/printingui/mac/nsPrintProgress.h create mode 100644 embedding/components/printingui/mac/nsPrintProgressParams.cpp create mode 100644 embedding/components/printingui/mac/nsPrintProgressParams.h create mode 100644 embedding/components/printingui/mac/nsPrintingPromptService.h create mode 100644 embedding/components/printingui/mac/nsPrintingPromptServiceX.mm create mode 100644 embedding/components/printingui/moz.build create mode 100644 embedding/components/printingui/unixshared/moz.build create mode 100644 embedding/components/printingui/unixshared/nsPrintProgress.cpp create mode 100644 embedding/components/printingui/unixshared/nsPrintProgress.h create mode 100644 embedding/components/printingui/unixshared/nsPrintProgressParams.cpp create mode 100644 embedding/components/printingui/unixshared/nsPrintProgressParams.h create mode 100644 embedding/components/printingui/unixshared/nsPrintingPromptService.cpp create mode 100644 embedding/components/printingui/unixshared/nsPrintingPromptService.h create mode 100644 embedding/components/printingui/win/moz.build create mode 100644 embedding/components/printingui/win/nsPrintDialogUtil.cpp create mode 100644 embedding/components/printingui/win/nsPrintDialogUtil.h create mode 100644 embedding/components/printingui/win/nsPrintProgress.cpp create mode 100644 embedding/components/printingui/win/nsPrintProgress.h create mode 100644 embedding/components/printingui/win/nsPrintProgressParams.cpp create mode 100644 embedding/components/printingui/win/nsPrintProgressParams.h create mode 100644 embedding/components/printingui/win/nsPrintingPromptService.cpp create mode 100644 embedding/components/printingui/win/nsPrintingPromptService.h create mode 100644 embedding/components/webbrowserpersist/PWebBrowserPersistDocument.ipdl create mode 100644 embedding/components/webbrowserpersist/PWebBrowserPersistResources.ipdl create mode 100644 embedding/components/webbrowserpersist/PWebBrowserPersistSerialize.ipdl create mode 100644 embedding/components/webbrowserpersist/WebBrowserPersistDocumentChild.cpp create mode 100644 embedding/components/webbrowserpersist/WebBrowserPersistDocumentChild.h create mode 100644 embedding/components/webbrowserpersist/WebBrowserPersistDocumentParent.cpp create mode 100644 embedding/components/webbrowserpersist/WebBrowserPersistDocumentParent.h create mode 100644 embedding/components/webbrowserpersist/WebBrowserPersistLocalDocument.cpp create mode 100644 embedding/components/webbrowserpersist/WebBrowserPersistLocalDocument.h create mode 100644 embedding/components/webbrowserpersist/WebBrowserPersistRemoteDocument.cpp create mode 100644 embedding/components/webbrowserpersist/WebBrowserPersistRemoteDocument.h create mode 100644 embedding/components/webbrowserpersist/WebBrowserPersistResourcesChild.cpp create mode 100644 embedding/components/webbrowserpersist/WebBrowserPersistResourcesChild.h create mode 100644 embedding/components/webbrowserpersist/WebBrowserPersistResourcesParent.cpp create mode 100644 embedding/components/webbrowserpersist/WebBrowserPersistResourcesParent.h create mode 100644 embedding/components/webbrowserpersist/WebBrowserPersistSerializeChild.cpp create mode 100644 embedding/components/webbrowserpersist/WebBrowserPersistSerializeChild.h create mode 100644 embedding/components/webbrowserpersist/WebBrowserPersistSerializeParent.cpp create mode 100644 embedding/components/webbrowserpersist/WebBrowserPersistSerializeParent.h create mode 100644 embedding/components/webbrowserpersist/moz.build create mode 100644 embedding/components/webbrowserpersist/nsCWebBrowserPersist.idl create mode 100644 embedding/components/webbrowserpersist/nsIWebBrowserPersist.idl create mode 100644 embedding/components/webbrowserpersist/nsIWebBrowserPersistDocument.idl create mode 100644 embedding/components/webbrowserpersist/nsIWebBrowserPersistable.idl create mode 100644 embedding/components/webbrowserpersist/nsWebBrowserPersist.cpp create mode 100644 embedding/components/webbrowserpersist/nsWebBrowserPersist.h create mode 100644 embedding/components/windowwatcher/moz.build create mode 100644 embedding/components/windowwatcher/nsAutoWindowStateHelper.cpp create mode 100644 embedding/components/windowwatcher/nsAutoWindowStateHelper.h create mode 100644 embedding/components/windowwatcher/nsDialogParamBlock.cpp create mode 100644 embedding/components/windowwatcher/nsDialogParamBlock.h create mode 100644 embedding/components/windowwatcher/nsIDialogParamBlock.idl create mode 100644 embedding/components/windowwatcher/nsIPromptFactory.idl create mode 100644 embedding/components/windowwatcher/nsIPromptService.idl create mode 100644 embedding/components/windowwatcher/nsIPromptService2.idl create mode 100644 embedding/components/windowwatcher/nsIWindowWatcher.idl create mode 100644 embedding/components/windowwatcher/nsPIPromptService.idl create mode 100644 embedding/components/windowwatcher/nsPIWindowWatcher.idl create mode 100644 embedding/components/windowwatcher/nsPromptUtils.h create mode 100644 embedding/components/windowwatcher/nsWindowWatcher.cpp create mode 100644 embedding/components/windowwatcher/nsWindowWatcher.h create mode 100644 embedding/components/windowwatcher/test/browser.ini create mode 100644 embedding/components/windowwatcher/test/browser_new_content_window_chromeflags.js create mode 100644 embedding/components/windowwatcher/test/browser_new_content_window_from_chrome_principal.js create mode 100644 embedding/components/windowwatcher/test/browser_new_remote_window_flags.js create mode 100644 embedding/components/windowwatcher/test/browser_new_sized_window.js create mode 100644 embedding/components/windowwatcher/test/chrome.ini create mode 100644 embedding/components/windowwatcher/test/file_storage_copied.html create mode 100644 embedding/components/windowwatcher/test/file_test_dialog.html create mode 100644 embedding/components/windowwatcher/test/mochitest.ini create mode 100644 embedding/components/windowwatcher/test/moz.build create mode 100644 embedding/components/windowwatcher/test/test_blank_named_window.html create mode 100644 embedding/components/windowwatcher/test/test_dialog_arguments.html create mode 100644 embedding/components/windowwatcher/test/test_modal_windows.html create mode 100644 embedding/components/windowwatcher/test/test_named_window.html create mode 100644 embedding/components/windowwatcher/test/test_storage_copied.html (limited to 'embedding/components') diff --git a/embedding/components/appstartup/moz.build b/embedding/components/appstartup/moz.build new file mode 100644 index 000000000..237591a50 --- /dev/null +++ b/embedding/components/appstartup/moz.build @@ -0,0 +1,15 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +EXPORTS += [ + 'nsIAppStartupNotifier.h', +] + +SOURCES += [ + 'nsAppStartupNotifier.cpp', +] + +FINAL_LIBRARY = 'xul' diff --git a/embedding/components/appstartup/nsAppStartupNotifier.cpp b/embedding/components/appstartup/nsAppStartupNotifier.cpp new file mode 100644 index 000000000..4ef38fb8d --- /dev/null +++ b/embedding/components/appstartup/nsAppStartupNotifier.cpp @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsCOMPtr.h" +#include "nsString.h" +#include "nsXPIDLString.h" +#include "nsIServiceManager.h" +#include "nsICategoryManager.h" +#include "nsXPCOM.h" +#include "nsISupportsPrimitives.h" +#include "nsAppStartupNotifier.h" +#include "nsISimpleEnumerator.h" + +NS_IMPL_ISUPPORTS(nsAppStartupNotifier, nsIObserver) + +nsAppStartupNotifier::nsAppStartupNotifier() +{ +} + +nsAppStartupNotifier::~nsAppStartupNotifier() +{ +} + +NS_IMETHODIMP nsAppStartupNotifier::Observe(nsISupports *aSubject, const char *aTopic, const char16_t *someData) +{ + NS_ENSURE_ARG(aTopic); + nsresult rv; + + // now initialize all startup listeners + nsCOMPtr categoryManager = + do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr enumerator; + rv = categoryManager->EnumerateCategory(aTopic, + getter_AddRefs(enumerator)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr entry; + while (NS_SUCCEEDED(enumerator->GetNext(getter_AddRefs(entry)))) { + nsCOMPtr category = do_QueryInterface(entry, &rv); + + if (NS_SUCCEEDED(rv)) { + nsAutoCString categoryEntry; + rv = category->GetData(categoryEntry); + + nsXPIDLCString contractId; + categoryManager->GetCategoryEntry(aTopic, + categoryEntry.get(), + getter_Copies(contractId)); + + if (NS_SUCCEEDED(rv)) { + + // If we see the word "service," in the beginning + // of the contractId then we create it as a service + // if not we do a createInstance + + nsCOMPtr startupInstance; + if (Substring(contractId, 0, 8).EqualsLiteral("service,")) + startupInstance = do_GetService(contractId.get() + 8, &rv); + else + startupInstance = do_CreateInstance(contractId, &rv); + + if (NS_SUCCEEDED(rv)) { + // Try to QI to nsIObserver + nsCOMPtr startupObserver = + do_QueryInterface(startupInstance, &rv); + if (NS_SUCCEEDED(rv)) { + rv = startupObserver->Observe(nullptr, aTopic, nullptr); + + // mainly for debugging if you want to know if your observer worked. + NS_ASSERTION(NS_SUCCEEDED(rv), "Startup Observer failed!\n"); + } + } + else { + #ifdef DEBUG + nsAutoCString warnStr("Cannot create startup observer : "); + warnStr += contractId.get(); + NS_WARNING(warnStr.get()); + #endif + } + + } + } + } + + return NS_OK; +} diff --git a/embedding/components/appstartup/nsAppStartupNotifier.h b/embedding/components/appstartup/nsAppStartupNotifier.h new file mode 100644 index 000000000..31077ed38 --- /dev/null +++ b/embedding/components/appstartup/nsAppStartupNotifier.h @@ -0,0 +1,30 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef nsAppStartupNotifier_h___ +#define nsAppStartupNotifier_h___ + +#include "nsIAppStartupNotifier.h" + +// {1F59B001-02C9-11d5-AE76-CC92F7DB9E03} +#define NS_APPSTARTUPNOTIFIER_CID \ + { 0x1f59b001, 0x2c9, 0x11d5, { 0xae, 0x76, 0xcc, 0x92, 0xf7, 0xdb, 0x9e, 0x3 } } + +class nsAppStartupNotifier : public nsIObserver +{ +public: + NS_DEFINE_STATIC_CID_ACCESSOR( NS_APPSTARTUPNOTIFIER_CID ) + + NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER + + nsAppStartupNotifier(); + +protected: + virtual ~nsAppStartupNotifier(); +}; + +#endif /* nsAppStartupNotifier_h___ */ + diff --git a/embedding/components/appstartup/nsIAppStartupNotifier.h b/embedding/components/appstartup/nsIAppStartupNotifier.h new file mode 100644 index 000000000..113bfa171 --- /dev/null +++ b/embedding/components/appstartup/nsIAppStartupNotifier.h @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef nsIAppStartupNotifier_h___ +#define nsIAppStartupNotifier_h___ + +#include "nsIObserver.h" + +/* + Some components need to be run at the startup of mozilla or embedding - to + start new services etc. + + This interface provides a generic way to start up arbitrary components + without requiring them to hack into main1() (or into NS_InitEmbedding) as + it's currently being done for services such as wallet, command line handlers + etc. + + We will have a category called "app-startup" which components register + themselves in using the CategoryManager. + + Components can also (optionally) add the word "service," as a prefix + to the "value" they pass in during a call to AddCategoryEntry() as + shown below: + + categoryManager->AddCategoryEntry(APPSTARTUP_CATEGORY, "testcomp", + "service," NS_WALLETSERVICE_CONTRACTID + true, true, + getter_Copies(previous)); + + Presence of the "service" keyword indicates the components desire to + be started as a service. When the "service" keyword is not present + we just do a do_CreateInstance. + + When mozilla starts (and when NS_InitEmbedding()) is invoked + we create an instance of the AppStartupNotifier component (which + implements nsIObserver) and invoke its Observe() method. + + Observe() will enumerate the components registered into the + APPSTARTUP_CATEGORY and notify them that startup has begun + and release them. +*/ + +#define NS_APPSTARTUPNOTIFIER_CONTRACTID "@mozilla.org/embedcomp/appstartup-notifier;1" + +#define APPSTARTUP_CATEGORY "app-startup" +#define APPSTARTUP_TOPIC "app-startup" + + +/* + Please note that there's not a new interface in this file. + We're just leveraging nsIObserver instead of creating a + new one + + This file exists solely to provide the defines above +*/ + +#endif /* nsIAppStartupNotifier_h___ */ diff --git a/embedding/components/build/moz.build b/embedding/components/build/moz.build new file mode 100644 index 000000000..defbfc0c8 --- /dev/null +++ b/embedding/components/build/moz.build @@ -0,0 +1,38 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +SOURCES += [ + 'nsEmbeddingModule.cpp', +] + +FINAL_LIBRARY = 'xul' +LOCAL_INCLUDES += [ + '../appstartup', + '../commandhandler', + '../find', + '../printingui/ipc', + '../webbrowserpersist', + '../windowwatcher', +] + +if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows': + DEFINES['PROXY_PRINTING'] = 1 + LOCAL_INCLUDES += [ + '../printingui/win', + ] +elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa': + DEFINES['PROXY_PRINTING'] = 1 + LOCAL_INCLUDES += [ + '../printingui/mac', + ] + +if CONFIG['MOZ_PDF_PRINTING']: + DEFINES['PROXY_PRINTING'] = 1 + LOCAL_INCLUDES += [ + '../printingui/unixshared', + ] + +include('/ipc/chromium/chromium-config.mozbuild') diff --git a/embedding/components/build/nsEmbeddingModule.cpp b/embedding/components/build/nsEmbeddingModule.cpp new file mode 100644 index 000000000..48351ec3a --- /dev/null +++ b/embedding/components/build/nsEmbeddingModule.cpp @@ -0,0 +1,120 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "mozilla/ModuleUtils.h" +#include "nsDialogParamBlock.h" +#include "nsWindowWatcher.h" +#include "nsAppStartupNotifier.h" +#include "nsFind.h" +#include "nsWebBrowserFind.h" +#include "nsWebBrowserPersist.h" +#include "nsCommandManager.h" +#include "nsControllerCommandTable.h" +#include "nsCommandParams.h" +#include "nsCommandGroup.h" +#include "nsBaseCommandController.h" +#include "nsNetCID.h" +#include "nsEmbedCID.h" + +#ifdef NS_PRINTING +#include "nsPrintingPromptService.h" +#include "nsPrintingProxy.h" +#endif + + +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsWindowWatcher, Init) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsAppStartupNotifier) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsFind) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebBrowserFind) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebBrowserPersist) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsControllerCommandTable) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsCommandManager) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsCommandParams) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsControllerCommandGroup) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsBaseCommandController) + +#ifdef MOZ_XUL +NS_GENERIC_FACTORY_CONSTRUCTOR(nsDialogParamBlock) +#ifdef NS_PRINTING +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintingPromptService, Init) +#ifdef PROXY_PRINTING +NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsPrintingProxy, + nsPrintingProxy::GetInstance) +#endif +#endif +#endif + +#ifdef MOZ_XUL +NS_DEFINE_NAMED_CID(NS_DIALOGPARAMBLOCK_CID); +#ifdef NS_PRINTING +NS_DEFINE_NAMED_CID(NS_PRINTINGPROMPTSERVICE_CID); +#endif +#endif +NS_DEFINE_NAMED_CID(NS_WINDOWWATCHER_CID); +NS_DEFINE_NAMED_CID(NS_FIND_CID); +NS_DEFINE_NAMED_CID(NS_WEB_BROWSER_FIND_CID); +NS_DEFINE_NAMED_CID(NS_APPSTARTUPNOTIFIER_CID); +NS_DEFINE_NAMED_CID(NS_WEBBROWSERPERSIST_CID); +NS_DEFINE_NAMED_CID(NS_CONTROLLERCOMMANDTABLE_CID); +NS_DEFINE_NAMED_CID(NS_COMMAND_MANAGER_CID); +NS_DEFINE_NAMED_CID(NS_COMMAND_PARAMS_CID); +NS_DEFINE_NAMED_CID(NS_CONTROLLER_COMMAND_GROUP_CID); +NS_DEFINE_NAMED_CID(NS_BASECOMMANDCONTROLLER_CID); + +static const mozilla::Module::CIDEntry kEmbeddingCIDs[] = { +#ifdef MOZ_XUL + { &kNS_DIALOGPARAMBLOCK_CID, false, nullptr, nsDialogParamBlockConstructor }, +#ifdef NS_PRINTING + +#ifdef PROXY_PRINTING + { &kNS_PRINTINGPROMPTSERVICE_CID, false, nullptr, nsPrintingPromptServiceConstructor, + mozilla::Module::MAIN_PROCESS_ONLY }, + { &kNS_PRINTINGPROMPTSERVICE_CID, false, nullptr, nsPrintingProxyConstructor, + mozilla::Module::CONTENT_PROCESS_ONLY }, +#else + { &kNS_PRINTINGPROMPTSERVICE_CID, false, nullptr, nsPrintingPromptServiceConstructor }, +#endif +#endif +#endif + { &kNS_WINDOWWATCHER_CID, false, nullptr, nsWindowWatcherConstructor }, + { &kNS_FIND_CID, false, nullptr, nsFindConstructor }, + { &kNS_WEB_BROWSER_FIND_CID, false, nullptr, nsWebBrowserFindConstructor }, + { &kNS_APPSTARTUPNOTIFIER_CID, false, nullptr, nsAppStartupNotifierConstructor }, + { &kNS_WEBBROWSERPERSIST_CID, false, nullptr, nsWebBrowserPersistConstructor }, + { &kNS_CONTROLLERCOMMANDTABLE_CID, false, nullptr, nsControllerCommandTableConstructor }, + { &kNS_COMMAND_MANAGER_CID, false, nullptr, nsCommandManagerConstructor }, + { &kNS_COMMAND_PARAMS_CID, false, nullptr, nsCommandParamsConstructor }, + { &kNS_CONTROLLER_COMMAND_GROUP_CID, false, nullptr, nsControllerCommandGroupConstructor }, + { &kNS_BASECOMMANDCONTROLLER_CID, false, nullptr, nsBaseCommandControllerConstructor }, + { nullptr } +}; + +static const mozilla::Module::ContractIDEntry kEmbeddingContracts[] = { +#ifdef MOZ_XUL + { NS_DIALOGPARAMBLOCK_CONTRACTID, &kNS_DIALOGPARAMBLOCK_CID }, +#ifdef NS_PRINTING + { NS_PRINTINGPROMPTSERVICE_CONTRACTID, &kNS_PRINTINGPROMPTSERVICE_CID }, +#endif +#endif + { NS_WINDOWWATCHER_CONTRACTID, &kNS_WINDOWWATCHER_CID }, + { NS_FIND_CONTRACTID, &kNS_FIND_CID }, + { NS_WEB_BROWSER_FIND_CONTRACTID, &kNS_WEB_BROWSER_FIND_CID }, + { NS_APPSTARTUPNOTIFIER_CONTRACTID, &kNS_APPSTARTUPNOTIFIER_CID }, + { NS_WEBBROWSERPERSIST_CONTRACTID, &kNS_WEBBROWSERPERSIST_CID }, + { NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &kNS_CONTROLLERCOMMANDTABLE_CID }, + { NS_COMMAND_MANAGER_CONTRACTID, &kNS_COMMAND_MANAGER_CID }, + { NS_COMMAND_PARAMS_CONTRACTID, &kNS_COMMAND_PARAMS_CID }, + { NS_CONTROLLER_COMMAND_GROUP_CONTRACTID, &kNS_CONTROLLER_COMMAND_GROUP_CID }, + { NS_BASECOMMANDCONTROLLER_CONTRACTID, &kNS_BASECOMMANDCONTROLLER_CID }, + { nullptr } +}; + +static const mozilla::Module kEmbeddingModule = { + mozilla::Module::kVersion, + kEmbeddingCIDs, + kEmbeddingContracts +}; + +NSMODULE_DEFN(embedcomponents) = &kEmbeddingModule; diff --git a/embedding/components/commandhandler/moz.build b/embedding/components/commandhandler/moz.build new file mode 100644 index 000000000..d44d57f20 --- /dev/null +++ b/embedding/components/commandhandler/moz.build @@ -0,0 +1,26 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +XPIDL_SOURCES += [ + 'nsICommandManager.idl', + 'nsICommandParams.idl', + 'nsIControllerCommand.idl', + 'nsIControllerCommandTable.idl', + 'nsIControllerContext.idl', + 'nsPICommandUpdater.idl', +] + +XPIDL_MODULE = 'commandhandler' + +UNIFIED_SOURCES += [ + 'nsBaseCommandController.cpp', + 'nsCommandGroup.cpp', + 'nsCommandManager.cpp', + 'nsCommandParams.cpp', + 'nsControllerCommandTable.cpp', +] + +FINAL_LIBRARY = 'xul' diff --git a/embedding/components/commandhandler/nsBaseCommandController.cpp b/embedding/components/commandhandler/nsBaseCommandController.cpp new file mode 100644 index 000000000..2bd87b6f5 --- /dev/null +++ b/embedding/components/commandhandler/nsBaseCommandController.cpp @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsString.h" +#include "nsIComponentManager.h" +#include "nsBaseCommandController.h" + +#include "nsString.h" +#include "nsWeakPtr.h" + +NS_IMPL_ADDREF(nsBaseCommandController) +NS_IMPL_RELEASE(nsBaseCommandController) + +NS_INTERFACE_MAP_BEGIN(nsBaseCommandController) + NS_INTERFACE_MAP_ENTRY(nsIController) + NS_INTERFACE_MAP_ENTRY(nsICommandController) + NS_INTERFACE_MAP_ENTRY(nsIControllerContext) + NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIControllerContext) +NS_INTERFACE_MAP_END + +nsBaseCommandController::nsBaseCommandController() + : mCommandContextRawPtr(nullptr) +{ +} + +nsBaseCommandController::~nsBaseCommandController() +{ +} + +NS_IMETHODIMP +nsBaseCommandController::Init(nsIControllerCommandTable* aCommandTable) +{ + nsresult rv = NS_OK; + + if (aCommandTable) { + mCommandTable = aCommandTable; + } else { + mCommandTable = + do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv); + } + + return rv; +} + +NS_IMETHODIMP +nsBaseCommandController::SetCommandContext(nsISupports* aCommandContext) +{ + mCommandContextWeakPtr = nullptr; + mCommandContextRawPtr = nullptr; + + if (aCommandContext) { + nsCOMPtr weak = do_QueryInterface(aCommandContext); + if (weak) { + nsresult rv = + weak->GetWeakReference(getter_AddRefs(mCommandContextWeakPtr)); + NS_ENSURE_SUCCESS(rv, rv); + } else { + mCommandContextRawPtr = aCommandContext; + } + } + + return NS_OK; +} + +NS_IMETHODIMP +nsBaseCommandController::GetInterface(const nsIID& aIID, void** aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + + if (NS_SUCCEEDED(QueryInterface(aIID, aResult))) { + return NS_OK; + } + + if (aIID.Equals(NS_GET_IID(nsIControllerCommandTable))) { + if (mCommandTable) { + return mCommandTable->QueryInterface(aIID, aResult); + } + return NS_ERROR_NOT_INITIALIZED; + } + + return NS_NOINTERFACE; +} + +/* ======================================================================= + * nsIController + * ======================================================================= */ + +NS_IMETHODIMP +nsBaseCommandController::IsCommandEnabled(const char* aCommand, bool* aResult) +{ + NS_ENSURE_ARG_POINTER(aCommand); + NS_ENSURE_ARG_POINTER(aResult); + NS_ENSURE_STATE(mCommandTable); + + nsISupports* context = mCommandContextRawPtr; + nsCOMPtr weak; + if (!context) { + weak = do_QueryReferent(mCommandContextWeakPtr); + context = weak; + } + return mCommandTable->IsCommandEnabled(aCommand, context, aResult); +} + +NS_IMETHODIMP +nsBaseCommandController::SupportsCommand(const char* aCommand, bool* aResult) +{ + NS_ENSURE_ARG_POINTER(aCommand); + NS_ENSURE_ARG_POINTER(aResult); + NS_ENSURE_STATE(mCommandTable); + + nsISupports* context = mCommandContextRawPtr; + nsCOMPtr weak; + if (!context) { + weak = do_QueryReferent(mCommandContextWeakPtr); + context = weak; + } + return mCommandTable->SupportsCommand(aCommand, context, aResult); +} + +NS_IMETHODIMP +nsBaseCommandController::DoCommand(const char* aCommand) +{ + NS_ENSURE_ARG_POINTER(aCommand); + NS_ENSURE_STATE(mCommandTable); + + nsISupports* context = mCommandContextRawPtr; + nsCOMPtr weak; + if (!context) { + weak = do_QueryReferent(mCommandContextWeakPtr); + context = weak; + } + return mCommandTable->DoCommand(aCommand, context); +} + +NS_IMETHODIMP +nsBaseCommandController::DoCommandWithParams(const char* aCommand, + nsICommandParams* aParams) +{ + NS_ENSURE_ARG_POINTER(aCommand); + NS_ENSURE_STATE(mCommandTable); + + nsISupports* context = mCommandContextRawPtr; + nsCOMPtr weak; + if (!context) { + weak = do_QueryReferent(mCommandContextWeakPtr); + context = weak; + } + return mCommandTable->DoCommandParams(aCommand, aParams, context); +} + +NS_IMETHODIMP +nsBaseCommandController::GetCommandStateWithParams(const char* aCommand, + nsICommandParams* aParams) +{ + NS_ENSURE_ARG_POINTER(aCommand); + NS_ENSURE_STATE(mCommandTable); + + nsISupports* context = mCommandContextRawPtr; + nsCOMPtr weak; + if (!context) { + weak = do_QueryReferent(mCommandContextWeakPtr); + context = weak; + } + return mCommandTable->GetCommandState(aCommand, aParams, context); +} + +NS_IMETHODIMP +nsBaseCommandController::OnEvent(const char* aEventName) +{ + NS_ENSURE_ARG_POINTER(aEventName); + return NS_OK; +} + +NS_IMETHODIMP +nsBaseCommandController::GetSupportedCommands(uint32_t* aCount, + char*** aCommands) +{ + NS_ENSURE_STATE(mCommandTable); + return mCommandTable->GetSupportedCommands(aCount, aCommands); +} diff --git a/embedding/components/commandhandler/nsBaseCommandController.h b/embedding/components/commandhandler/nsBaseCommandController.h new file mode 100644 index 000000000..83976faac --- /dev/null +++ b/embedding/components/commandhandler/nsBaseCommandController.h @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef nsBaseCommandController_h__ +#define nsBaseCommandController_h__ + +#define NS_BASECOMMANDCONTROLLER_CID \ + { 0xbf88b48c, 0xfd8e, 0x40b4, { 0xba, 0x36, 0xc7, 0xc3, 0xad, 0x6d, 0x8a, 0xc9 } } +#define NS_BASECOMMANDCONTROLLER_CONTRACTID \ + "@mozilla.org/embedcomp/base-command-controller;1" + +#include "nsIController.h" +#include "nsIControllerContext.h" +#include "nsIControllerCommandTable.h" +#include "nsIInterfaceRequestor.h" +#include "nsIWeakReferenceUtils.h" + +// The base editor controller is used for both text widgets, and all other text +// and html editing +class nsBaseCommandController + : public nsIController + , public nsIControllerContext + , public nsIInterfaceRequestor + , public nsICommandController +{ +public: + nsBaseCommandController(); + + NS_DECL_ISUPPORTS + NS_DECL_NSICONTROLLER + NS_DECL_NSICOMMANDCONTROLLER + NS_DECL_NSICONTROLLERCONTEXT + NS_DECL_NSIINTERFACEREQUESTOR + +protected: + virtual ~nsBaseCommandController(); + +private: + nsWeakPtr mCommandContextWeakPtr; + nsISupports* mCommandContextRawPtr; + + // Our reference to the command manager + nsCOMPtr mCommandTable; +}; + +#endif /* nsBaseCommandController_h_ */ diff --git a/embedding/components/commandhandler/nsCommandGroup.cpp b/embedding/components/commandhandler/nsCommandGroup.cpp new file mode 100644 index 000000000..696b93f67 --- /dev/null +++ b/embedding/components/commandhandler/nsCommandGroup.cpp @@ -0,0 +1,296 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsString.h" +#include "nsReadableUtils.h" +#include "nsTArray.h" +#include "nsISimpleEnumerator.h" +#include "nsXPCOM.h" +#include "nsSupportsPrimitives.h" +#include "nsIComponentManager.h" +#include "nsCommandGroup.h" +#include "nsIControllerCommand.h" +#include "nsCRT.h" + +class nsGroupsEnumerator : public nsISimpleEnumerator +{ +public: + explicit nsGroupsEnumerator( + nsControllerCommandGroup::GroupsHashtable& aInHashTable); + + NS_DECL_ISUPPORTS + NS_DECL_NSISIMPLEENUMERATOR + +protected: + virtual ~nsGroupsEnumerator(); + + nsresult Initialize(); + +protected: + nsControllerCommandGroup::GroupsHashtable& mHashTable; + int32_t mIndex; + const char** mGroupNames; // array of pointers to char16_t* in the hash table + bool mInitted; +}; + +/* Implementation file */ +NS_IMPL_ISUPPORTS(nsGroupsEnumerator, nsISimpleEnumerator) + +nsGroupsEnumerator::nsGroupsEnumerator( + nsControllerCommandGroup::GroupsHashtable& aInHashTable) + : mHashTable(aInHashTable) + , mIndex(-1) + , mGroupNames(nullptr) + , mInitted(false) +{ +} + +nsGroupsEnumerator::~nsGroupsEnumerator() +{ + delete[] mGroupNames; +} + +NS_IMETHODIMP +nsGroupsEnumerator::HasMoreElements(bool* aResult) +{ + nsresult rv = NS_OK; + + NS_ENSURE_ARG_POINTER(aResult); + + if (!mInitted) { + rv = Initialize(); + if (NS_FAILED(rv)) { + return rv; + } + } + + *aResult = (mIndex < static_cast(mHashTable.Count()) - 1); + return NS_OK; +} + +NS_IMETHODIMP +nsGroupsEnumerator::GetNext(nsISupports** aResult) +{ + nsresult rv = NS_OK; + + NS_ENSURE_ARG_POINTER(aResult); + + if (!mInitted) { + rv = Initialize(); + if (NS_FAILED(rv)) { + return rv; + } + } + + mIndex++; + if (mIndex >= static_cast(mHashTable.Count())) { + return NS_ERROR_FAILURE; + } + + const char* thisGroupName = mGroupNames[mIndex]; + + nsCOMPtr supportsString = + do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID, &rv); + if (NS_FAILED(rv)) { + return rv; + } + + supportsString->SetData(nsDependentCString(thisGroupName)); + return CallQueryInterface(supportsString, aResult); +} + +nsresult +nsGroupsEnumerator::Initialize() +{ + if (mInitted) { + return NS_OK; + } + + mGroupNames = new const char*[mHashTable.Count()]; + if (!mGroupNames) { + return NS_ERROR_OUT_OF_MEMORY; + } + + mIndex = 0; + for (auto iter = mHashTable.Iter(); !iter.Done(); iter.Next()) { + mGroupNames[mIndex] = iter.Key().Data(); + mIndex++; + } + + mIndex = -1; + mInitted = true; + return NS_OK; +} + +class nsNamedGroupEnumerator : public nsISimpleEnumerator +{ +public: + explicit nsNamedGroupEnumerator(nsTArray* aInArray); + + NS_DECL_ISUPPORTS + NS_DECL_NSISIMPLEENUMERATOR + +protected: + virtual ~nsNamedGroupEnumerator(); + + nsTArray* mGroupArray; + int32_t mIndex; +}; + +nsNamedGroupEnumerator::nsNamedGroupEnumerator(nsTArray* aInArray) + : mGroupArray(aInArray) + , mIndex(-1) +{ +} + +nsNamedGroupEnumerator::~nsNamedGroupEnumerator() +{ +} + +NS_IMPL_ISUPPORTS(nsNamedGroupEnumerator, nsISimpleEnumerator) + +NS_IMETHODIMP +nsNamedGroupEnumerator::HasMoreElements(bool* aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + + int32_t arrayLen = mGroupArray ? mGroupArray->Length() : 0; + *aResult = (mIndex < arrayLen - 1); + return NS_OK; +} + +NS_IMETHODIMP +nsNamedGroupEnumerator::GetNext(nsISupports** aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + + if (!mGroupArray) { + return NS_ERROR_FAILURE; + } + + mIndex++; + if (mIndex >= int32_t(mGroupArray->Length())) { + return NS_ERROR_FAILURE; + } + + const nsCString& thisGroupName = mGroupArray->ElementAt(mIndex); + + nsresult rv; + nsCOMPtr supportsString = + do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID, &rv); + if (NS_FAILED(rv)) { + return rv; + } + + supportsString->SetData(thisGroupName); + return CallQueryInterface(supportsString, aResult); +} + +NS_IMPL_ISUPPORTS(nsControllerCommandGroup, nsIControllerCommandGroup) + +nsControllerCommandGroup::nsControllerCommandGroup() +{ +} + +nsControllerCommandGroup::~nsControllerCommandGroup() +{ + ClearGroupsHash(); +} + +void +nsControllerCommandGroup::ClearGroupsHash() +{ + mGroupsHash.Clear(); +} + +NS_IMETHODIMP +nsControllerCommandGroup::AddCommandToGroup(const char* aCommand, + const char* aGroup) +{ + nsDependentCString groupKey(aGroup); + nsTArray* commandList = mGroupsHash.Get(groupKey); + if (!commandList) { + // make this list + commandList = new AutoTArray; + mGroupsHash.Put(groupKey, commandList); + } + +#ifdef DEBUG + nsCString* appended = +#endif + commandList->AppendElement(aCommand); + NS_ASSERTION(appended, "Append failed"); + + return NS_OK; +} + +NS_IMETHODIMP +nsControllerCommandGroup::RemoveCommandFromGroup(const char* aCommand, + const char* aGroup) +{ + nsDependentCString groupKey(aGroup); + nsTArray* commandList = mGroupsHash.Get(groupKey); + if (!commandList) { + return NS_OK; // no group + } + + uint32_t numEntries = commandList->Length(); + for (uint32_t i = 0; i < numEntries; i++) { + nsCString commandString = commandList->ElementAt(i); + if (nsDependentCString(aCommand) != commandString) { + commandList->RemoveElementAt(i); + break; + } + } + return NS_OK; +} + +NS_IMETHODIMP +nsControllerCommandGroup::IsCommandInGroup(const char* aCommand, + const char* aGroup, bool* aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + *aResult = false; + + nsDependentCString groupKey(aGroup); + nsTArray* commandList = mGroupsHash.Get(groupKey); + if (!commandList) { + return NS_OK; // no group + } + + uint32_t numEntries = commandList->Length(); + for (uint32_t i = 0; i < numEntries; i++) { + nsCString commandString = commandList->ElementAt(i); + if (nsDependentCString(aCommand) != commandString) { + *aResult = true; + break; + } + } + return NS_OK; +} + +NS_IMETHODIMP +nsControllerCommandGroup::GetGroupsEnumerator(nsISimpleEnumerator** aResult) +{ + RefPtr groupsEnum = new nsGroupsEnumerator(mGroupsHash); + + groupsEnum.forget(aResult); + return NS_OK; +} + +NS_IMETHODIMP +nsControllerCommandGroup::GetEnumeratorForGroup(const char* aGroup, + nsISimpleEnumerator** aResult) +{ + nsDependentCString groupKey(aGroup); + nsTArray* commandList = mGroupsHash.Get(groupKey); // may be null + + RefPtr theGroupEnum = + new nsNamedGroupEnumerator(commandList); + + theGroupEnum.forget(aResult); + return NS_OK; +} diff --git a/embedding/components/commandhandler/nsCommandGroup.h b/embedding/components/commandhandler/nsCommandGroup.h new file mode 100644 index 000000000..b06d725b3 --- /dev/null +++ b/embedding/components/commandhandler/nsCommandGroup.h @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef nsCommandGroup_h__ +#define nsCommandGroup_h__ + +#include "nsIController.h" +#include "nsClassHashtable.h" +#include "nsHashKeys.h" + +// {ecd55a01-2780-11d5-a73c-ca641a6813bc} +#define NS_CONTROLLER_COMMAND_GROUP_CID \ + { 0xecd55a01, 0x2780, 0x11d5, { 0xa7, 0x3c, 0xca, 0x64, 0x1a, 0x68, 0x13, 0xbc } } + +#define NS_CONTROLLER_COMMAND_GROUP_CONTRACTID \ + "@mozilla.org/embedcomp/controller-command-group;1" + +class nsControllerCommandGroup : public nsIControllerCommandGroup +{ +public: + nsControllerCommandGroup(); + + NS_DECL_ISUPPORTS + NS_DECL_NSICONTROLLERCOMMANDGROUP + +public: + typedef nsClassHashtable> + GroupsHashtable; + +protected: + virtual ~nsControllerCommandGroup(); + + void ClearGroupsHash(); + +protected: + // Hash keyed on command group. This could be made more space-efficient, + // maybe with atoms. + GroupsHashtable mGroupsHash; +}; + +#endif // nsCommandGroup_h__ diff --git a/embedding/components/commandhandler/nsCommandManager.cpp b/embedding/components/commandhandler/nsCommandManager.cpp new file mode 100644 index 000000000..c11a901b2 --- /dev/null +++ b/embedding/components/commandhandler/nsCommandManager.cpp @@ -0,0 +1,262 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsString.h" + +#include "nsIController.h" +#include "nsIControllers.h" +#include "nsIObserver.h" + +#include "nsIComponentManager.h" + +#include "nsServiceManagerUtils.h" +#include "nsIScriptSecurityManager.h" + +#include "nsContentUtils.h" +#include "nsIDOMWindow.h" +#include "nsPIDOMWindow.h" +#include "nsPIWindowRoot.h" +#include "nsIFocusManager.h" + +#include "nsCOMArray.h" + +#include "nsCommandManager.h" + +nsCommandManager::nsCommandManager() + : mWindow(nullptr) +{ +} + +nsCommandManager::~nsCommandManager() +{ +} + +NS_IMPL_CYCLE_COLLECTION_CLASS(nsCommandManager) + +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsCommandManager) + tmp->mObserversTable.Clear(); +NS_IMPL_CYCLE_COLLECTION_UNLINK_END +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCommandManager) + for (auto iter = tmp->mObserversTable.Iter(); !iter.Done(); iter.Next()) { + nsCommandManager::ObserverList* observers = iter.UserData(); + int32_t numItems = observers->Length(); + for (int32_t i = 0; i < numItems; ++i) { + cb.NoteXPCOMChild(observers->ElementAt(i)); + } + } +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +NS_IMPL_CYCLE_COLLECTING_ADDREF(nsCommandManager) +NS_IMPL_CYCLE_COLLECTING_RELEASE(nsCommandManager) + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsCommandManager) + NS_INTERFACE_MAP_ENTRY(nsICommandManager) + NS_INTERFACE_MAP_ENTRY(nsPICommandUpdater) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICommandManager) +NS_INTERFACE_MAP_END + +NS_IMETHODIMP +nsCommandManager::Init(mozIDOMWindowProxy* aWindow) +{ + NS_ENSURE_ARG_POINTER(aWindow); + + mWindow = aWindow; // weak ptr + return NS_OK; +} + +NS_IMETHODIMP +nsCommandManager::CommandStatusChanged(const char* aCommandName) +{ + ObserverList* commandObservers; + mObserversTable.Get(aCommandName, &commandObservers); + + if (commandObservers) { + // XXX Should we worry about observers removing themselves from Observe()? + int32_t i, numItems = commandObservers->Length(); + for (i = 0; i < numItems; ++i) { + nsCOMPtr observer = commandObservers->ElementAt(i); + // should we get the command state to pass here? This might be expensive. + observer->Observe(NS_ISUPPORTS_CAST(nsICommandManager*, this), + aCommandName, + u"command_status_changed"); + } + } + + return NS_OK; +} + +#if 0 +#pragma mark - +#endif + +NS_IMETHODIMP +nsCommandManager::AddCommandObserver(nsIObserver* aCommandObserver, + const char* aCommandToObserve) +{ + NS_ENSURE_ARG(aCommandObserver); + + // XXX todo: handle special cases of aCommandToObserve being null, or empty + + // for each command in the table, we make a list of observers for that command + ObserverList* commandObservers; + if (!mObserversTable.Get(aCommandToObserve, &commandObservers)) { + commandObservers = new ObserverList; + mObserversTable.Put(aCommandToObserve, commandObservers); + } + + // need to check that this command observer hasn't already been registered + int32_t existingIndex = commandObservers->IndexOf(aCommandObserver); + if (existingIndex == -1) { + commandObservers->AppendElement(aCommandObserver); + } else { + NS_WARNING("Registering command observer twice on the same command"); + } + + return NS_OK; +} + +NS_IMETHODIMP +nsCommandManager::RemoveCommandObserver(nsIObserver* aCommandObserver, + const char* aCommandObserved) +{ + NS_ENSURE_ARG(aCommandObserver); + + // XXX todo: handle special cases of aCommandToObserve being null, or empty + + ObserverList* commandObservers; + if (!mObserversTable.Get(aCommandObserved, &commandObservers)) { + return NS_ERROR_UNEXPECTED; + } + + commandObservers->RemoveElement(aCommandObserver); + + return NS_OK; +} + +NS_IMETHODIMP +nsCommandManager::IsCommandSupported(const char* aCommandName, + mozIDOMWindowProxy* aTargetWindow, + bool* aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + + nsCOMPtr controller; + GetControllerForCommand(aCommandName, aTargetWindow, + getter_AddRefs(controller)); + *aResult = (controller.get() != nullptr); + return NS_OK; +} + +NS_IMETHODIMP +nsCommandManager::IsCommandEnabled(const char* aCommandName, + mozIDOMWindowProxy* aTargetWindow, + bool* aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + + bool commandEnabled = false; + + nsCOMPtr controller; + GetControllerForCommand(aCommandName, aTargetWindow, + getter_AddRefs(controller)); + if (controller) { + controller->IsCommandEnabled(aCommandName, &commandEnabled); + } + *aResult = commandEnabled; + return NS_OK; +} + +NS_IMETHODIMP +nsCommandManager::GetCommandState(const char* aCommandName, + mozIDOMWindowProxy* aTargetWindow, + nsICommandParams* aCommandParams) +{ + nsCOMPtr controller; + nsAutoString tValue; + nsresult rv = GetControllerForCommand(aCommandName, aTargetWindow, + getter_AddRefs(controller)); + if (!controller) { + return NS_ERROR_FAILURE; + } + + nsCOMPtr commandController = + do_QueryInterface(controller); + if (commandController) { + rv = commandController->GetCommandStateWithParams(aCommandName, + aCommandParams); + } else { + rv = NS_ERROR_NOT_IMPLEMENTED; + } + return rv; +} + +NS_IMETHODIMP +nsCommandManager::DoCommand(const char* aCommandName, + nsICommandParams* aCommandParams, + mozIDOMWindowProxy* aTargetWindow) +{ + nsCOMPtr controller; + nsresult rv = GetControllerForCommand(aCommandName, aTargetWindow, + getter_AddRefs(controller)); + if (!controller) { + return NS_ERROR_FAILURE; + } + + nsCOMPtr commandController = + do_QueryInterface(controller); + if (commandController && aCommandParams) { + rv = commandController->DoCommandWithParams(aCommandName, aCommandParams); + } else { + rv = controller->DoCommand(aCommandName); + } + return rv; +} + +nsresult +nsCommandManager::GetControllerForCommand(const char* aCommand, + mozIDOMWindowProxy* aTargetWindow, + nsIController** aResult) +{ + nsresult rv = NS_ERROR_FAILURE; + *aResult = nullptr; + + // check if we're in content or chrome + // if we're not chrome we must have a target window or we bail + if (!nsContentUtils::LegacyIsCallerChromeOrNativeCode()) { + if (!aTargetWindow) { + return rv; + } + + // if a target window is specified, it must be the window we expect + if (aTargetWindow != mWindow) { + return NS_ERROR_FAILURE; + } + } + + if (auto* targetWindow = nsPIDOMWindowOuter::From(aTargetWindow)) { + // get the controller for this particular window + nsCOMPtr controllers; + rv = targetWindow->GetControllers(getter_AddRefs(controllers)); + if (NS_FAILED(rv)) { + return rv; + } + if (!controllers) { + return NS_ERROR_FAILURE; + } + + // dispatch the command + return controllers->GetControllerForCommand(aCommand, aResult); + } + + auto* window = nsPIDOMWindowOuter::From(mWindow); + NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); + nsCOMPtr root = window->GetTopWindowRoot(); + NS_ENSURE_TRUE(root, NS_ERROR_FAILURE); + + // no target window; send command to focus controller + return root->GetControllerForCommand(aCommand, aResult); +} diff --git a/embedding/components/commandhandler/nsCommandManager.h b/embedding/components/commandhandler/nsCommandManager.h new file mode 100644 index 000000000..1d26c40ba --- /dev/null +++ b/embedding/components/commandhandler/nsCommandManager.h @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef nsCommandManager_h__ +#define nsCommandManager_h__ + +#include "nsString.h" +#include "nsClassHashtable.h" +#include "nsWeakReference.h" + +#include "nsICommandManager.h" +#include "nsPICommandUpdater.h" +#include "nsCycleCollectionParticipant.h" + +class nsIController; +template class nsCOMArray; + +class nsCommandManager + : public nsICommandManager + , public nsPICommandUpdater + , public nsSupportsWeakReference +{ +public: + typedef nsTArray > ObserverList; + + nsCommandManager(); + + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsCommandManager, nsICommandManager) + + NS_DECL_NSICOMMANDMANAGER + NS_DECL_NSPICOMMANDUPDATER + +protected: + virtual ~nsCommandManager(); + + nsresult GetControllerForCommand(const char* aCommand, + mozIDOMWindowProxy* aDirectedToThisWindow, + nsIController** aResult); + +protected: + nsClassHashtable mObserversTable; + + mozIDOMWindowProxy* mWindow; // weak ptr. The window should always outlive us +}; + +#endif // nsCommandManager_h__ diff --git a/embedding/components/commandhandler/nsCommandParams.cpp b/embedding/components/commandhandler/nsCommandParams.cpp new file mode 100644 index 000000000..86647d4dd --- /dev/null +++ b/embedding/components/commandhandler/nsCommandParams.cpp @@ -0,0 +1,264 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "xpcom-config.h" +#include +#include "nscore.h" +#include "nsCRT.h" + +#include "nsCommandParams.h" +#include "mozilla/HashFunctions.h" + +using namespace mozilla; + +const PLDHashTableOps nsCommandParams::sHashOps = +{ + HashKey, + HashMatchEntry, + HashMoveEntry, + HashClearEntry +}; + +NS_IMPL_ISUPPORTS(nsCommandParams, nsICommandParams) + +nsCommandParams::nsCommandParams() + : mValuesHash(&sHashOps, sizeof(HashEntry), 2) +{ +} + +nsCommandParams::~nsCommandParams() +{ +} + +NS_IMETHODIMP +nsCommandParams::GetValueType(const char* aName, int16_t* aRetVal) +{ + NS_ENSURE_ARG_POINTER(aRetVal); + + HashEntry* foundEntry = GetNamedEntry(aName); + if (foundEntry) { + *aRetVal = foundEntry->mEntryType; + return NS_OK; + } + *aRetVal = eNoType; + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsCommandParams::GetBooleanValue(const char* aName, bool* aRetVal) +{ + NS_ENSURE_ARG_POINTER(aRetVal); + + HashEntry* foundEntry = GetNamedEntry(aName); + if (foundEntry && foundEntry->mEntryType == eBooleanType) { + *aRetVal = foundEntry->mData.mBoolean; + return NS_OK; + } + *aRetVal = false; + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsCommandParams::GetLongValue(const char* aName, int32_t* aRetVal) +{ + NS_ENSURE_ARG_POINTER(aRetVal); + + HashEntry* foundEntry = GetNamedEntry(aName); + if (foundEntry && foundEntry->mEntryType == eLongType) { + *aRetVal = foundEntry->mData.mLong; + return NS_OK; + } + *aRetVal = false; + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsCommandParams::GetDoubleValue(const char* aName, double* aRetVal) +{ + NS_ENSURE_ARG_POINTER(aRetVal); + + HashEntry* foundEntry = GetNamedEntry(aName); + if (foundEntry && foundEntry->mEntryType == eDoubleType) { + *aRetVal = foundEntry->mData.mDouble; + return NS_OK; + } + *aRetVal = 0.0; + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsCommandParams::GetStringValue(const char* aName, nsAString& aRetVal) +{ + HashEntry* foundEntry = GetNamedEntry(aName); + if (foundEntry && foundEntry->mEntryType == eWStringType) { + NS_ASSERTION(foundEntry->mData.mString, "Null string"); + aRetVal.Assign(*foundEntry->mData.mString); + return NS_OK; + } + aRetVal.Truncate(); + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsCommandParams::GetCStringValue(const char* aName, char** aRetVal) +{ + NS_ENSURE_ARG_POINTER(aRetVal); + + HashEntry* foundEntry = GetNamedEntry(aName); + if (foundEntry && foundEntry->mEntryType == eStringType) { + NS_ASSERTION(foundEntry->mData.mCString, "Null string"); + *aRetVal = ToNewCString(*foundEntry->mData.mCString); + return NS_OK; + } + *aRetVal = nullptr; + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsCommandParams::GetISupportsValue(const char* aName, nsISupports** aRetVal) +{ + NS_ENSURE_ARG_POINTER(aRetVal); + + HashEntry* foundEntry = GetNamedEntry(aName); + if (foundEntry && foundEntry->mEntryType == eISupportsType) { + NS_IF_ADDREF(*aRetVal = foundEntry->mISupports.get()); + return NS_OK; + } + *aRetVal = nullptr; + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsCommandParams::SetBooleanValue(const char* aName, bool aValue) +{ + HashEntry* foundEntry = GetOrMakeEntry(aName, eBooleanType); + if (!foundEntry) { + return NS_ERROR_OUT_OF_MEMORY; + } + foundEntry->mData.mBoolean = aValue; + return NS_OK; +} + +NS_IMETHODIMP +nsCommandParams::SetLongValue(const char* aName, int32_t aValue) +{ + HashEntry* foundEntry = GetOrMakeEntry(aName, eLongType); + if (!foundEntry) { + return NS_ERROR_OUT_OF_MEMORY; + } + foundEntry->mData.mLong = aValue; + return NS_OK; +} + +NS_IMETHODIMP +nsCommandParams::SetDoubleValue(const char* aName, double aValue) +{ + HashEntry* foundEntry = GetOrMakeEntry(aName, eDoubleType); + if (!foundEntry) { + return NS_ERROR_OUT_OF_MEMORY; + } + foundEntry->mData.mDouble = aValue; + return NS_OK; +} + +NS_IMETHODIMP +nsCommandParams::SetStringValue(const char* aName, const nsAString& aValue) +{ + HashEntry* foundEntry = GetOrMakeEntry(aName, eWStringType); + if (!foundEntry) { + return NS_ERROR_OUT_OF_MEMORY; + } + foundEntry->mData.mString = new nsString(aValue); + return NS_OK; +} + +NS_IMETHODIMP +nsCommandParams::SetCStringValue(const char* aName, const char* aValue) +{ + HashEntry* foundEntry = GetOrMakeEntry(aName, eStringType); + if (!foundEntry) { + return NS_ERROR_OUT_OF_MEMORY; + } + foundEntry->mData.mCString = new nsCString(aValue); + return NS_OK; +} + +NS_IMETHODIMP +nsCommandParams::SetISupportsValue(const char* aName, nsISupports* aValue) +{ + HashEntry* foundEntry = GetOrMakeEntry(aName, eISupportsType); + if (!foundEntry) { + return NS_ERROR_OUT_OF_MEMORY; + } + foundEntry->mISupports = aValue; // addrefs + return NS_OK; +} + +NS_IMETHODIMP +nsCommandParams::RemoveValue(const char* aName) +{ + mValuesHash.Remove((void*)aName); + return NS_OK; +} + +nsCommandParams::HashEntry* +nsCommandParams::GetNamedEntry(const char* aName) +{ + return static_cast(mValuesHash.Search((void*)aName)); +} + +nsCommandParams::HashEntry* +nsCommandParams::GetOrMakeEntry(const char* aName, uint8_t aEntryType) +{ + auto foundEntry = static_cast(mValuesHash.Search((void*)aName)); + if (foundEntry) { // reuse existing entry + foundEntry->Reset(aEntryType); + return foundEntry; + } + + foundEntry = static_cast(mValuesHash.Add((void*)aName, fallible)); + if (!foundEntry) { + return nullptr; + } + + // Use placement new. Our ctor does not clobber keyHash, which is important. + new (foundEntry) HashEntry(aEntryType, aName); + return foundEntry; +} + +PLDHashNumber +nsCommandParams::HashKey(const void* aKey) +{ + return HashString((const char*)aKey); +} + +bool +nsCommandParams::HashMatchEntry(const PLDHashEntryHdr* aEntry, const void* aKey) +{ + const char* keyString = (const char*)aKey; + const HashEntry* thisEntry = static_cast(aEntry); + return thisEntry->mEntryName.Equals(keyString); +} + +void +nsCommandParams::HashMoveEntry(PLDHashTable* aTable, + const PLDHashEntryHdr* aFrom, + PLDHashEntryHdr* aTo) +{ + const HashEntry* fromEntry = static_cast(aFrom); + HashEntry* toEntry = static_cast(aTo); + + new (toEntry) HashEntry(*fromEntry); + + fromEntry->~HashEntry(); +} + +void +nsCommandParams::HashClearEntry(PLDHashTable* aTable, PLDHashEntryHdr* aEntry) +{ + HashEntry* thisEntry = static_cast(aEntry); + thisEntry->~HashEntry(); +} diff --git a/embedding/components/commandhandler/nsCommandParams.h b/embedding/components/commandhandler/nsCommandParams.h new file mode 100644 index 000000000..52df28d79 --- /dev/null +++ b/embedding/components/commandhandler/nsCommandParams.h @@ -0,0 +1,131 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef nsCommandParams_h__ +#define nsCommandParams_h__ + +#include "nsString.h" +#include "nsICommandParams.h" +#include "nsCOMPtr.h" +#include "PLDHashTable.h" + +class nsCommandParams : public nsICommandParams +{ +public: + nsCommandParams(); + + NS_DECL_ISUPPORTS + NS_DECL_NSICOMMANDPARAMS + +protected: + virtual ~nsCommandParams(); + + struct HashEntry : public PLDHashEntryHdr + { + nsCString mEntryName; + + uint8_t mEntryType; + union + { + bool mBoolean; + int32_t mLong; + double mDouble; + nsString* mString; + nsCString* mCString; + } mData; + + nsCOMPtr mISupports; + + HashEntry(uint8_t aType, const char* aEntryName) + : mEntryName(aEntryName) + , mEntryType(aType) + { + Reset(mEntryType); + } + + HashEntry(const HashEntry& aRHS) + : mEntryType(aRHS.mEntryType) + { + Reset(mEntryType); + switch (mEntryType) { + case eBooleanType: + mData.mBoolean = aRHS.mData.mBoolean; + break; + case eLongType: + mData.mLong = aRHS.mData.mLong; + break; + case eDoubleType: + mData.mDouble = aRHS.mData.mDouble; + break; + case eWStringType: + NS_ASSERTION(aRHS.mData.mString, "Source entry has no string"); + mData.mString = new nsString(*aRHS.mData.mString); + break; + case eStringType: + NS_ASSERTION(aRHS.mData.mCString, "Source entry has no string"); + mData.mCString = new nsCString(*aRHS.mData.mCString); + break; + case eISupportsType: + mISupports = aRHS.mISupports.get(); + break; + default: + NS_ERROR("Unknown type"); + } + } + + ~HashEntry() { Reset(eNoType); } + + void Reset(uint8_t aNewType) + { + switch (mEntryType) { + case eNoType: + break; + case eBooleanType: + mData.mBoolean = false; + break; + case eLongType: + mData.mLong = 0; + break; + case eDoubleType: + mData.mDouble = 0.0; + break; + case eWStringType: + delete mData.mString; + mData.mString = nullptr; + break; + case eISupportsType: + mISupports = nullptr; + break; + case eStringType: + delete mData.mCString; + mData.mCString = nullptr; + break; + default: + NS_ERROR("Unknown type"); + } + mEntryType = aNewType; + } + }; + + HashEntry* GetNamedEntry(const char* aName); + HashEntry* GetOrMakeEntry(const char* aName, uint8_t aEntryType); + +protected: + static PLDHashNumber HashKey(const void* aKey); + + static bool HashMatchEntry(const PLDHashEntryHdr* aEntry, const void* aKey); + + static void HashMoveEntry(PLDHashTable* aTable, const PLDHashEntryHdr* aFrom, + PLDHashEntryHdr* aTo); + + static void HashClearEntry(PLDHashTable* aTable, PLDHashEntryHdr* aEntry); + + PLDHashTable mValuesHash; + + static const PLDHashTableOps sHashOps; +}; + +#endif // nsCommandParams_h__ diff --git a/embedding/components/commandhandler/nsControllerCommandTable.cpp b/embedding/components/commandhandler/nsControllerCommandTable.cpp new file mode 100644 index 000000000..91075bba4 --- /dev/null +++ b/embedding/components/commandhandler/nsControllerCommandTable.cpp @@ -0,0 +1,209 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsString.h" +#include "nsIControllerCommand.h" +#include "nsControllerCommandTable.h" + +nsresult NS_NewControllerCommandTable(nsIControllerCommandTable** aResult); + +// this value is used to size the hash table. Just a sensible upper bound +#define NUM_COMMANDS_LENGTH 32 + +nsControllerCommandTable::nsControllerCommandTable() + : mCommandsTable(NUM_COMMANDS_LENGTH) + , mMutable(true) +{ +} + +nsControllerCommandTable::~nsControllerCommandTable() +{ +} + +NS_IMPL_ISUPPORTS(nsControllerCommandTable, nsIControllerCommandTable, + nsISupportsWeakReference) + +NS_IMETHODIMP +nsControllerCommandTable::MakeImmutable(void) +{ + mMutable = false; + return NS_OK; +} + +NS_IMETHODIMP +nsControllerCommandTable::RegisterCommand(const char* aCommandName, + nsIControllerCommand* aCommand) +{ + NS_ENSURE_TRUE(mMutable, NS_ERROR_FAILURE); + + mCommandsTable.Put(nsDependentCString(aCommandName), aCommand); + + return NS_OK; +} + +NS_IMETHODIMP +nsControllerCommandTable::UnregisterCommand(const char* aCommandName, + nsIControllerCommand* aCommand) +{ + NS_ENSURE_TRUE(mMutable, NS_ERROR_FAILURE); + + nsDependentCString commandKey(aCommandName); + if (!mCommandsTable.Get(commandKey, nullptr)) { + return NS_ERROR_FAILURE; + } + + mCommandsTable.Remove(commandKey); + return NS_OK; +} + +NS_IMETHODIMP +nsControllerCommandTable::FindCommandHandler(const char* aCommandName, + nsIControllerCommand** aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + + *aResult = nullptr; + + nsCOMPtr foundCommand; + mCommandsTable.Get(nsDependentCString(aCommandName), + getter_AddRefs(foundCommand)); + if (!foundCommand) { + return NS_ERROR_FAILURE; + } + + foundCommand.forget(aResult); + return NS_OK; +} + +NS_IMETHODIMP +nsControllerCommandTable::IsCommandEnabled(const char* aCommandName, + nsISupports* aCommandRefCon, + bool* aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + + *aResult = false; + + nsCOMPtr commandHandler; + FindCommandHandler(aCommandName, getter_AddRefs(commandHandler)); + if (!commandHandler) { + NS_WARNING("Controller command table asked about a command that it does " + "not handle"); + return NS_OK; + } + + return commandHandler->IsCommandEnabled(aCommandName, aCommandRefCon, + aResult); +} + +NS_IMETHODIMP +nsControllerCommandTable::UpdateCommandState(const char* aCommandName, + nsISupports* aCommandRefCon) +{ + nsCOMPtr commandHandler; + FindCommandHandler(aCommandName, getter_AddRefs(commandHandler)); + if (!commandHandler) { + NS_WARNING("Controller command table asked to update the state of a " + "command that it does not handle"); + return NS_OK; + } + + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsControllerCommandTable::SupportsCommand(const char* aCommandName, + nsISupports* aCommandRefCon, + bool* aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + + // XXX: need to check the readonly and disabled states + + *aResult = false; + + nsCOMPtr commandHandler; + FindCommandHandler(aCommandName, getter_AddRefs(commandHandler)); + + *aResult = (commandHandler.get() != nullptr); + return NS_OK; +} + +NS_IMETHODIMP +nsControllerCommandTable::DoCommand(const char* aCommandName, + nsISupports* aCommandRefCon) +{ + nsCOMPtr commandHandler; + FindCommandHandler(aCommandName, getter_AddRefs(commandHandler)); + if (!commandHandler) { + NS_WARNING("Controller command table asked to do a command that it does " + "not handle"); + return NS_OK; + } + + return commandHandler->DoCommand(aCommandName, aCommandRefCon); +} + +NS_IMETHODIMP +nsControllerCommandTable::DoCommandParams(const char* aCommandName, + nsICommandParams* aParams, + nsISupports* aCommandRefCon) +{ + nsCOMPtr commandHandler; + FindCommandHandler(aCommandName, getter_AddRefs(commandHandler)); + if (!commandHandler) { + NS_WARNING("Controller command table asked to do a command that it does " + "not handle"); + return NS_OK; + } + return commandHandler->DoCommandParams(aCommandName, aParams, aCommandRefCon); +} + +NS_IMETHODIMP +nsControllerCommandTable::GetCommandState(const char* aCommandName, + nsICommandParams* aParams, + nsISupports* aCommandRefCon) +{ + nsCOMPtr commandHandler; + FindCommandHandler(aCommandName, getter_AddRefs(commandHandler)); + if (!commandHandler) { + NS_WARNING("Controller command table asked to do a command that it does " + "not handle"); + return NS_OK; + } + return commandHandler->GetCommandStateParams(aCommandName, aParams, + aCommandRefCon); +} + +NS_IMETHODIMP +nsControllerCommandTable::GetSupportedCommands(uint32_t* aCount, + char*** aCommands) +{ + char** commands = + static_cast(moz_xmalloc(sizeof(char*) * mCommandsTable.Count())); + *aCount = mCommandsTable.Count(); + *aCommands = commands; + + for (auto iter = mCommandsTable.Iter(); !iter.Done(); iter.Next()) { + *commands = ToNewCString(iter.Key()); + commands++; + } + return NS_OK; +} + +nsresult +NS_NewControllerCommandTable(nsIControllerCommandTable** aResult) +{ + NS_PRECONDITION(aResult != nullptr, "null ptr"); + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + + nsControllerCommandTable* newCommandTable = new nsControllerCommandTable(); + NS_ADDREF(newCommandTable); + *aResult = newCommandTable; + return NS_OK; +} diff --git a/embedding/components/commandhandler/nsControllerCommandTable.h b/embedding/components/commandhandler/nsControllerCommandTable.h new file mode 100644 index 000000000..353850bc0 --- /dev/null +++ b/embedding/components/commandhandler/nsControllerCommandTable.h @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef nsControllerCommandTable_h_ +#define nsControllerCommandTable_h_ + +#include "nsIControllerCommandTable.h" +#include "nsWeakReference.h" +#include "nsInterfaceHashtable.h" + +class nsIControllerCommand; + +class nsControllerCommandTable final + : public nsIControllerCommandTable + , public nsSupportsWeakReference +{ +public: + nsControllerCommandTable(); + + NS_DECL_ISUPPORTS + NS_DECL_NSICONTROLLERCOMMANDTABLE + +protected: + virtual ~nsControllerCommandTable(); + + // Hash table of nsIControllerCommands, keyed by command name. + nsInterfaceHashtable mCommandsTable; + + // Are we mutable? + bool mMutable; +}; + +#endif // nsControllerCommandTable_h_ diff --git a/embedding/components/commandhandler/nsICommandManager.idl b/embedding/components/commandhandler/nsICommandManager.idl new file mode 100644 index 000000000..958108740 --- /dev/null +++ b/embedding/components/commandhandler/nsICommandManager.idl @@ -0,0 +1,118 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsISupports.idl" +#include "nsIObserver.idl" +#include "nsICommandParams.idl" + +interface mozIDOMWindowProxy; + +/* + * nsICommandManager is an interface used to executing user-level commands, + * and getting the state of available commands. + * + * Commands are identified by strings, which are documented elsewhere. + * In addition, the list of required and optional parameters for + * each command, that are passed in via the nsICommandParams, are + * also documented elsewhere. (Where? Need a good location for this). + */ + + +[scriptable, uuid(bb5a1730-d83b-4fa2-831b-35b9d5842e84)] +interface nsICommandManager : nsISupports +{ + /* + * Register an observer on the specified command. The observer's Observe + * method will get called when the state (enabled/disbaled, or toggled etc) + * of the command changes. + * + * You can register the same observer on multiple commmands by calling this + * multiple times. + */ + void addCommandObserver(in nsIObserver aCommandObserver, + in string aCommandToObserve); + + /* + * Stop an observer from observering the specified command. If the observer + * was also registered on ther commands, they will continue to be observed. + * + * Passing an empty string in 'aCommandObserved' will remove the observer + * from all commands. + */ + void removeCommandObserver(in nsIObserver aCommandObserver, + in string aCommandObserved); + + /* + * Ask the command manager if the specified command is supported. + * If aTargetWindow is null, the focused window is used. + * + */ + boolean isCommandSupported(in string aCommandName, + in mozIDOMWindowProxy aTargetWindow); + + /* + * Ask the command manager if the specified command is currently. + * enabled. + * If aTargetWindow is null, the focused window is used. + */ + boolean isCommandEnabled(in string aCommandName, + in mozIDOMWindowProxy aTargetWindow); + + /* + * Get the state of the specified commands. + * + * On input: aCommandParams filled in with values that the caller cares + * about, most of which are command-specific (see the command documentation + * for details). One boolean value, "enabled", applies to all commands, + * and, in return will be set to indicate whether the command is enabled + * (equivalent to calling isCommandEnabled). + * + * aCommandName is the name of the command that needs the state + * aTargetWindow is the source of command controller + * (null means use focus controller) + * On output: aCommandParams: values set by the caller filled in with + * state from the command. + */ + void getCommandState(in string aCommandName, + in mozIDOMWindowProxy aTargetWindow, + /* inout */ in nsICommandParams aCommandParams); + + /* + * Execute the specified command. + * The command will be executed in aTargetWindow if it is specified. + * If aTargetWindow is null, it will go to the focused window. + * + * param: aCommandParams, a list of name-value pairs of command parameters, + * may be null for parameter-less commands. + * + */ + void doCommand(in string aCommandName, + in nsICommandParams aCommandParams, + in mozIDOMWindowProxy aTargetWindow); + +}; + + +/* + +Arguments to observers "Observe" method are as follows: + + void Observe( in nsISupports aSubject, // The nsICommandManager calling this Observer + in string aTopic, // Name of the command + in wstring aDummy ); // unused + +*/ + +// {64edb481-0c04-11d5-a73c-e964b968b0bc} +%{C++ +#define NS_COMMAND_MANAGER_CID \ +{ 0x64edb481, 0x0c04, 0x11d5, { 0xa7, 0x3c, 0xe9, 0x64, 0xb9, 0x68, 0xb0, 0xbc } } + +#define NS_COMMAND_MANAGER_CONTRACTID \ + "@mozilla.org/embedcomp/command-manager;1" +%} + + + diff --git a/embedding/components/commandhandler/nsICommandParams.idl b/embedding/components/commandhandler/nsICommandParams.idl new file mode 100644 index 000000000..fcd3ff973 --- /dev/null +++ b/embedding/components/commandhandler/nsICommandParams.idl @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsISupports.idl" + +/* + * nsICommandParams is used to pass parameters to commands executed + * via nsICommandManager, and to get command state. + * + */ + +[scriptable, uuid(b1fdf3c4-74e3-4f7d-a14d-2b76bcf53482)] +interface nsICommandParams : nsISupports +{ + /* + * List of primitive types for parameter values. + */ + const short eNoType = 0; /* Only used for sanity checking */ + const short eBooleanType = 1; + const short eLongType = 2; + const short eDoubleType = 3; + const short eWStringType = 4; + const short eISupportsType = 5; + const short eStringType = 6; + + /* + * getValueType + * + * Get the type of a specified parameter + */ + short getValueType(in string name); + + /* + * get_Value + * + * Get the value of a specified parameter. Will return + * an error if the parameter does not exist, or if the value + * is of the wrong type (no coercion is performed for you). + * + * nsISupports values can contain any XPCOM interface, + * as documented for the command. It is permissible + * for it to contain nsICommandParams, but not *this* + * one (i.e. self-containing is not allowed). + */ + boolean getBooleanValue(in string name); + long getLongValue(in string name); + double getDoubleValue(in string name); + AString getStringValue(in string name); + string getCStringValue(in string name); + nsISupports getISupportsValue(in string name); + + /* + * set_Value + * + * Set the value of a specified parameter (thus creating + * an entry for it). + * + * nsISupports values can contain any XPCOM interface, + * as documented for the command. It is permissible + * for it to contain nsICommandParams, but not *this* + * one (i.e. self-containing is not allowed). + */ + void setBooleanValue(in string name, in boolean value); + void setLongValue(in string name, in long value); + void setDoubleValue(in string name, in double value); + void setStringValue(in string name, in AString value); + void setCStringValue(in string name, in string value); + void setISupportsValue(in string name, in nsISupports value); + + /* + * removeValue + * + * Remove the specified parameter from the list. + */ + void removeValue(in string name); +}; + +// {f7fa4581-238e-11d5-a73c-ab64fb68f2bc} +%{C++ +#define NS_COMMAND_PARAMS_CID { 0xf7fa4581, 0x238e, 0x11d5, { 0xa7, 0x3c, 0xab, 0x64, 0xfb, 0x68, 0xf2, 0xbc } } +#define NS_COMMAND_PARAMS_CONTRACTID "@mozilla.org/embedcomp/command-params;1" +%} + diff --git a/embedding/components/commandhandler/nsIControllerCommand.idl b/embedding/components/commandhandler/nsIControllerCommand.idl new file mode 100644 index 000000000..a1ea583a4 --- /dev/null +++ b/embedding/components/commandhandler/nsIControllerCommand.idl @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsISupports.idl" +#include "nsICommandParams.idl" + +/** + * nsIControllerCommand + * + * A generic command interface. You can register an nsIControllerCommand + * with the nsIControllerCommandTable. + */ + +[scriptable, uuid(0eae9a46-1dd2-11b2-aca0-9176f05fe9db)] +interface nsIControllerCommand : nsISupports +{ + + /** + * Returns true if the command is currently enabled. An nsIControllerCommand + * can implement more than one commands; say, a group of related commands + * (e.g. delete left/delete right). Because of this, the command name is + * passed to each method. + * + * @param aCommandName the name of the command for which we want the enabled + * state. + * @param aCommandContext a cookie held by the nsIControllerCommandTable, + * allowing the command to get some context information. + * The contents of this cookie are implementation-defined. + */ + boolean isCommandEnabled(in string aCommandName, in nsISupports aCommandContext); + + void getCommandStateParams(in string aCommandName, in nsICommandParams aParams, in nsISupports aCommandContext); + + /** + * Execute the name command. + * + * @param aCommandName the name of the command to execute. + * + * @param aCommandContext a cookie held by the nsIControllerCommandTable, + * allowing the command to get some context information. + * The contents of this cookie are implementation-defined. + */ + void doCommand(in string aCommandName, in nsISupports aCommandContext); + + void doCommandParams(in string aCommandName, in nsICommandParams aParams, in nsISupports aCommandContext); + +}; + diff --git a/embedding/components/commandhandler/nsIControllerCommandTable.idl b/embedding/components/commandhandler/nsIControllerCommandTable.idl new file mode 100644 index 000000000..fb2c86fae --- /dev/null +++ b/embedding/components/commandhandler/nsIControllerCommandTable.idl @@ -0,0 +1,100 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsISupports.idl" +#include "nsIControllerCommand.idl" +#include "nsICommandParams.idl" + +/** + * nsIControllerCommandTable + * + * An interface via which a controller can maintain a series of commands, + * and efficiently dispatch commands to their respective handlers. + * + * Controllers that use an nsIControllerCommandTable should support + * nsIInterfaceRequestor, and be able to return an interface to their + * controller command table via getInterface(). + * + */ + +[scriptable, uuid(c847f90e-b8f3-49db-a4df-8867831f2800)] +interface nsIControllerCommandTable : nsISupports +{ + /** + * Make this command table immutable, so that commands cannot + * be registered or unregistered. Some command tables are made + * mutable after command registration so that they can be + * used as singletons. + */ + void makeImmutable(); + + /** + * Register and unregister commands with the command table. + * + * @param aCommandName the name of the command under which to register or + * unregister the given command handler. + * + * @param aCommand the handler for this command. + */ + void registerCommand(in string aCommandName, in nsIControllerCommand aCommand); + void unregisterCommand(in string aCommandName, in nsIControllerCommand aCommand); + + /** + * Find the command handler which has been registered to handle the named command. + * + * @param aCommandName the name of the command to find the handler for. + */ + nsIControllerCommand findCommandHandler(in string aCommandName); + + /** + * Get whether the named command is enabled. + * + * @param aCommandName the name of the command to test + * @param aCommandRefCon the command context data + */ + boolean isCommandEnabled(in string aCommandName, in nsISupports aCommandRefCon); + + /** + * Tell the command to update its state (if it is a state updating command) + * + * @param aCommandName the name of the command to update + * @param aCommandRefCon the command context data + */ + void updateCommandState(in string aCommandName, in nsISupports aCommandRefCon); + + /** + * Get whether the named command is supported. + * + * @param aCommandName the name of the command to test + * @param aCommandRefCon the command context data + */ + boolean supportsCommand(in string aCommandName, in nsISupports aCommandRefCon); + + /** + * Execute the named command. + * + * @param aCommandName the name of the command to execute + * @param aCommandRefCon the command context data + */ + void doCommand(in string aCommandName, in nsISupports aCommandRefCon); + + void doCommandParams(in string aCommandName, in nsICommandParams aParam, in nsISupports aCommandRefCon); + + void getCommandState(in string aCommandName, in nsICommandParams aParam, in nsISupports aCommandRefCon); + + void getSupportedCommands(out unsigned long count, + [array, size_is(count), retval] out string commands); +}; + + + +%{C++ +// {670ee5da-6ad5-11d7-9950-000393636592} +#define NS_CONTROLLERCOMMANDTABLE_CID \ + {0x670ee5da, 0x6ad5, 0x11d7, \ + { 0x99, 0x50, 0x00, 0x03, 0x93, 0x63, 0x65, 0x92 }} + +#define NS_CONTROLLERCOMMANDTABLE_CONTRACTID \ + "@mozilla.org/embedcomp/controller-command-table;1" +%} diff --git a/embedding/components/commandhandler/nsIControllerContext.idl b/embedding/components/commandhandler/nsIControllerContext.idl new file mode 100644 index 000000000..7c7ed67fd --- /dev/null +++ b/embedding/components/commandhandler/nsIControllerContext.idl @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsISupports.idl" +#include "nsIControllerCommandTable.idl" + +[scriptable, uuid(47B82B60-A36F-4167-8072-6F421151ED50)] +interface nsIControllerContext : nsISupports +{ + + /** + * Init the controller, optionally passing a controller + * command table. + * + * @param aCommandTable a command table, used internally + * by this controller. May be null, in + * which case the controller will create + * a new, empty table. + */ + void init(in nsIControllerCommandTable aCommandTable); + + /** + * Set a context on this controller, which is passed + * to commands to give them some context when they execute. + * + * @param aCommandContext the context passed to commands. + * Note that this is *not* addreffed by the + * controller, and so needs to outlive it, + * or be nulled out. + */ + void setCommandContext(in nsISupports aCommandContext); + +}; diff --git a/embedding/components/commandhandler/nsPICommandUpdater.idl b/embedding/components/commandhandler/nsPICommandUpdater.idl new file mode 100644 index 000000000..3712dbdff --- /dev/null +++ b/embedding/components/commandhandler/nsPICommandUpdater.idl @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsISupports.idl" + +interface mozIDOMWindowProxy; + +/* + The nsPICommandUpdater interface is used by modules that implement + commands, to tell the command manager that commands need updating. + This is a private interface; embedders should not use it. + + Command-implementing modules should get one of these by a QI + from an nsICommandManager. +*/ + +[scriptable, uuid(35e474ae-8016-4c34-9644-edc11f8b0ce1)] +interface nsPICommandUpdater : nsISupports +{ + + /* + * Init the command updater, passing an nsIDOMWindow which + * is the window that the command updater lives on. + * + */ + void init(in mozIDOMWindowProxy aWindow); + + /* + * Notify the command manager that the status of a command + * changed. It may have changed from enabled to disabled, + * or vice versa, or become toggled etc. + */ + void commandStatusChanged(in string aCommandName); + +}; + + diff --git a/embedding/components/find/moz.build b/embedding/components/find/moz.build new file mode 100644 index 000000000..6586914da --- /dev/null +++ b/embedding/components/find/moz.build @@ -0,0 +1,19 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +XPIDL_SOURCES += [ + 'nsIFind.idl', + 'nsIWebBrowserFind.idl', +] + +XPIDL_MODULE = 'find' + +UNIFIED_SOURCES += [ + 'nsFind.cpp', + 'nsWebBrowserFind.cpp', +] + +FINAL_LIBRARY = 'xul' diff --git a/embedding/components/find/nsFind.cpp b/embedding/components/find/nsFind.cpp new file mode 100644 index 000000000..cbc42298b --- /dev/null +++ b/embedding/components/find/nsFind.cpp @@ -0,0 +1,1383 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//#define DEBUG_FIND 1 + +#include "nsFind.h" +#include "nsContentCID.h" +#include "nsIContent.h" +#include "nsIDOMNode.h" +#include "nsIDOMNodeList.h" +#include "nsISelection.h" +#include "nsISelectionController.h" +#include "nsIFrame.h" +#include "nsITextControlFrame.h" +#include "nsIFormControl.h" +#include "nsIEditor.h" +#include "nsIPlaintextEditor.h" +#include "nsTextFragment.h" +#include "nsString.h" +#include "nsIAtom.h" +#include "nsServiceManagerUtils.h" +#include "nsUnicharUtils.h" +#include "nsIDOMElement.h" +#include "nsIWordBreaker.h" +#include "nsCRT.h" +#include "nsRange.h" +#include "nsContentUtils.h" +#include "mozilla/DebugOnly.h" + +using namespace mozilla; + +// Yikes! Casting a char to unichar can fill with ones! +#define CHAR_TO_UNICHAR(c) ((char16_t)(const unsigned char)c) + +static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID); +static NS_DEFINE_CID(kCPreContentIteratorCID, NS_PRECONTENTITERATOR_CID); + +#define CH_QUOTE ((char16_t)0x22) +#define CH_APOSTROPHE ((char16_t)0x27) +#define CH_LEFT_SINGLE_QUOTE ((char16_t)0x2018) +#define CH_RIGHT_SINGLE_QUOTE ((char16_t)0x2019) +#define CH_LEFT_DOUBLE_QUOTE ((char16_t)0x201C) +#define CH_RIGHT_DOUBLE_QUOTE ((char16_t)0x201D) + +#define CH_SHY ((char16_t)0xAD) + +// nsFind::Find casts CH_SHY to char before calling StripChars +// This works correctly if and only if CH_SHY <= 255 +static_assert(CH_SHY <= 255, "CH_SHY is not an ascii character"); + +// nsFindContentIterator is a special iterator that also goes through any +// existing