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
This commit is contained in:
Kris Maglione 2021-03-25 19:47:03 +00:00
Родитель fd79887e5f
Коммит 047869e9be
4 изменённых файлов: 131 добавлений и 0 удалений

Просмотреть файл

@ -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> WebNavigationContent::GetSingleton() {
static RefPtr<WebNavigationContent> sSingleton;
if (!sSingleton) {
sSingleton = new WebNavigationContent();
sSingleton->Init();
ClearOnShutdown(&sSingleton);
}
return do_AddRef(sSingleton);
}
NS_IMPL_ISUPPORTS(WebNavigationContent, nsIObserver)
void WebNavigationContent::Init() {
nsCOMPtr<nsIObserverService> 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<dom::EventTarget> 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

Просмотреть файл

@ -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<WebNavigationContent> GetSingleton();
private:
WebNavigationContent();
~WebNavigationContent() = default;
void AttachListeners(mozilla::dom::EventTarget* aEventTarget);
void Init();
};
} // namespace extensions
} // namespace mozilla
#endif // defined mozilla_extensions_WebNavigationContent_h

Просмотреть файл

@ -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'},
},
]

Просмотреть файл

@ -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 += [