From 047869e9befbb8b9fb383a953daf9d7f0ca85bdf Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Thu, 25 Mar 2021 19:47:03 +0000 Subject: [PATCH] Bug 1581859: Part 4b - Add skeleton WebNavigationContent class. r=zombie,nika This is a skeleton class which will be instantiated at startup in each process, and eventually track the same events that the deprecated WebNavigationContent.js frame script currently tracks. Actual implementation is added in follow-up patches. Differential Revision: https://phabricator.services.mozilla.com/D103213 --- .../webrequest/WebNavigationContent.cpp | 68 +++++++++++++++++++ .../webrequest/WebNavigationContent.h | 41 +++++++++++ .../extensions/webrequest/components.conf | 16 +++++ .../extensions/webrequest/moz.build | 6 ++ 4 files changed, 131 insertions(+) create mode 100644 toolkit/components/extensions/webrequest/WebNavigationContent.cpp create mode 100644 toolkit/components/extensions/webrequest/WebNavigationContent.h create mode 100644 toolkit/components/extensions/webrequest/components.conf diff --git a/toolkit/components/extensions/webrequest/WebNavigationContent.cpp b/toolkit/components/extensions/webrequest/WebNavigationContent.cpp new file mode 100644 index 000000000000..7b4cf64c1fec --- /dev/null +++ b/toolkit/components/extensions/webrequest/WebNavigationContent.cpp @@ -0,0 +1,68 @@ +/* -*- 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 "mozilla/extensions/WebNavigationContent.h" + +#include "mozilla/ClearOnShutdown.h" +#include "mozilla/dom/Event.h" +#include "mozilla/dom/EventTarget.h" +#include "mozilla/RefPtr.h" +#include "mozilla/Services.h" +#include "nsCRT.h" +#include "nsIObserverService.h" +#include "nsQueryObject.h" + +namespace mozilla { +namespace extensions { + +WebNavigationContent::WebNavigationContent() {} + +/* static */ +already_AddRefed WebNavigationContent::GetSingleton() { + static RefPtr sSingleton; + if (!sSingleton) { + sSingleton = new WebNavigationContent(); + sSingleton->Init(); + ClearOnShutdown(&sSingleton); + } + return do_AddRef(sSingleton); +} + +NS_IMPL_ISUPPORTS(WebNavigationContent, nsIObserver) + +void WebNavigationContent::Init() { + nsCOMPtr obs = services::GetObserverService(); + + obs->AddObserver(this, "chrome-event-target-created", false); + obs->AddObserver(this, "webNavigation-createdNavigationTarget-from-js", + false); +} + +NS_IMETHODIMP WebNavigationContent::Observe(nsISupports* aSubject, + char const* aTopic, + char16_t const* aData) { + if (!nsCRT::strcmp(aTopic, "chrome-event-target-created")) { + // This notification is sent whenever a new window root is created, with the + // subject being an EventTarget corresponding to either an nsWindowRoot in a + // child process or an InProcessBrowserChildMessageManager in the parent. + // This is the same entry point used to register listeners for the JS window + // actor API. + if (RefPtr eventTarget = do_QueryObject(aSubject)) { + AttachListeners(eventTarget); + } + } else if (!nsCRT::strcmp(aTopic, + "webNavigation-createdNavigationTarget-from-js")) { + } + return NS_OK; +} + +void WebNavigationContent::AttachListeners( + mozilla::dom::EventTarget* aEventTarget) {} + +NS_IMETHODIMP +WebNavigationContent::HandleEvent(dom::Event* aEvent) { return NS_OK; } + +} // namespace extensions +} // namespace mozilla diff --git a/toolkit/components/extensions/webrequest/WebNavigationContent.h b/toolkit/components/extensions/webrequest/WebNavigationContent.h new file mode 100644 index 000000000000..704615ba5b5b --- /dev/null +++ b/toolkit/components/extensions/webrequest/WebNavigationContent.h @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 2; 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 mozilla_extensions_WebNavigationContent_h +#define mozilla_extensions_WebNavigationContent_h + +#include "nsIDOMEventListener.h" +#include "nsIObserver.h" + +namespace mozilla { +namespace dom { +class EventTarget; +} // namespace dom + +namespace extensions { + +class WebNavigationContent final : public nsIObserver, + public nsIDOMEventListener { + public: + NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER + NS_DECL_NSIDOMEVENTLISTENER + + static already_AddRefed GetSingleton(); + + private: + WebNavigationContent(); + ~WebNavigationContent() = default; + + void AttachListeners(mozilla::dom::EventTarget* aEventTarget); + + void Init(); +}; + +} // namespace extensions +} // namespace mozilla + +#endif // defined mozilla_extensions_WebNavigationContent_h diff --git a/toolkit/components/extensions/webrequest/components.conf b/toolkit/components/extensions/webrequest/components.conf new file mode 100644 index 000000000000..9b1e6f86da37 --- /dev/null +++ b/toolkit/components/extensions/webrequest/components.conf @@ -0,0 +1,16 @@ +# -*- 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/. + +Classes = [ + { + 'cid': '{acb22042-2b6c-427b-b550-b9f407c6fff6}', + 'contract_ids': ['@mozilla.org/extensions/web-navigation-content;1'], + 'type': 'mozilla::extensions::WebNavigationContent', + 'constructor': 'mozilla::extensions::WebNavigationContent::GetSingleton', + 'headers': ['mozilla/extensions/WebNavigationContent.h'], + 'categories': {'app-startup': 'WebNavigationContent'}, + }, +] diff --git a/toolkit/components/extensions/webrequest/moz.build b/toolkit/components/extensions/webrequest/moz.build index d80b1333a9f0..a646a09e7a06 100644 --- a/toolkit/components/extensions/webrequest/moz.build +++ b/toolkit/components/extensions/webrequest/moz.build @@ -16,6 +16,7 @@ UNIFIED_SOURCES += [ "StreamFilterChild.cpp", "StreamFilterEvents.cpp", "StreamFilterParent.cpp", + "WebNavigationContent.cpp", "WebRequestService.cpp", ] @@ -23,6 +24,10 @@ IPDL_SOURCES += [ "PStreamFilter.ipdl", ] +XPCOM_MANIFESTS += [ + "components.conf", +] + EXPORTS.mozilla += [ "WebRequestService.h", ] @@ -34,6 +39,7 @@ EXPORTS.mozilla.extensions += [ "StreamFilterChild.h", "StreamFilterEvents.h", "StreamFilterParent.h", + "WebNavigationContent.h", ] LOCAL_INCLUDES += [