[tbb-commits] [tor-browser/tor-browser-60.3.0esr-8.5-1] Bug 1322748 add ability to get registered channelwrappers, r=kmag
gk at torproject.org
gk at torproject.org
Mon Dec 3 16:18:46 UTC 2018
commit c1774ae7fc74bef7956caca4fe1b8de1365f5d48
Author: Shane Caraveo <scaraveo at mozilla.com>
Date: Tue May 22 14:19:57 2018 -0400
Bug 1322748 add ability to get registered channelwrappers, r=kmag
MozReview-Commit-ID: SphwWjzQuo
--HG--
extra : rebase_source : 0b5193d7f4e9e7f27f9a7d622699b673781c3dd4
---
dom/chrome-webidl/ChannelWrapper.webidl | 8 ++++++++
.../extensions/webrequest/ChannelWrapper.cpp | 18 ++++++++++++++++++
.../components/extensions/webrequest/ChannelWrapper.h | 2 +-
3 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/dom/chrome-webidl/ChannelWrapper.webidl b/dom/chrome-webidl/ChannelWrapper.webidl
index b8d921cea58d..2777aab65c8e 100644
--- a/dom/chrome-webidl/ChannelWrapper.webidl
+++ b/dom/chrome-webidl/ChannelWrapper.webidl
@@ -49,6 +49,14 @@ interface ChannelWrapper : EventTarget {
static ChannelWrapper get(MozChannel channel);
/**
+ * Returns the wrapper instance for the given channel. The same wrapper is
+ * always returned for a given channel.
+ */
+ static ChannelWrapper getRegisteredChannel(unsigned long long aChannelId,
+ WebExtensionPolicy extension,
+ TabParent? tabParent);
+
+ /**
* A unique ID for for the requests which remains constant throughout the
* redirect chain.
*/
diff --git a/toolkit/components/extensions/webrequest/ChannelWrapper.cpp b/toolkit/components/extensions/webrequest/ChannelWrapper.cpp
index de4a7fee1a2a..52508f0f24ed 100644
--- a/toolkit/components/extensions/webrequest/ChannelWrapper.cpp
+++ b/toolkit/components/extensions/webrequest/ChannelWrapper.cpp
@@ -78,6 +78,24 @@ ChannelWrapper::Get(const GlobalObject& global, nsIChannel* channel)
return wrapper.forget();
}
+already_AddRefed<ChannelWrapper>
+ChannelWrapper::GetRegisteredChannel(const GlobalObject& global, uint64_t aChannelId, const WebExtensionPolicy& aAddon, nsITabParent* aTabParent)
+{
+ nsIContentParent* contentParent = nullptr;
+ if (TabParent* parent = static_cast<TabParent*>(aTabParent)) {
+ contentParent = static_cast<nsIContentParent*>(parent->Manager());
+ }
+
+ auto& webreq = WebRequestService::GetSingleton();
+
+ nsCOMPtr<nsITraceableChannel> channel = webreq.GetTraceableChannel(aChannelId, aAddon.Id(), contentParent);
+ if (!channel) {
+ return nullptr;
+ }
+ nsCOMPtr<nsIChannel> chan(do_QueryInterface(channel));
+ return ChannelWrapper::Get(global, chan);
+}
+
void
ChannelWrapper::SetChannel(nsIChannel* aChannel)
{
diff --git a/toolkit/components/extensions/webrequest/ChannelWrapper.h b/toolkit/components/extensions/webrequest/ChannelWrapper.h
index 8ba238991070..750aed434f6a 100644
--- a/toolkit/components/extensions/webrequest/ChannelWrapper.h
+++ b/toolkit/components/extensions/webrequest/ChannelWrapper.h
@@ -121,7 +121,7 @@ public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_CHANNELWRAPPER_IID)
static already_AddRefed<extensions::ChannelWrapper> Get(const dom::GlobalObject& global, nsIChannel* channel);
-
+ static already_AddRefed<extensions::ChannelWrapper> GetRegisteredChannel(const dom::GlobalObject& global, uint64_t aChannelId, const WebExtensionPolicy& aAddon, nsITabParent* aTabParent);
uint64_t Id() const { return mId; }
More information about the tbb-commits
mailing list