Commit 781e0e7e authored by Shane Caraveo's avatar Shane Caraveo Committed by Georg Koppen
Browse files

Bug 1322748 add ability to get registered channelwrappers, r=kmag

MozReview-Commit-ID: SphwWjzQuo

--HG--
extra : rebase_source : 0b5193d7f4e9e7f27f9a7d622699b673781c3dd4
parent 6606683b
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -48,6 +48,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.
+19 −0
Original line number Diff line number Diff line
@@ -77,6 +77,25 @@ already_AddRefed<ChannelWrapper> ChannelWrapper::Get(const GlobalObject& global,
  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) {
  detail::ChannelHolder::SetChannel(aChannel);
  ClearCachedAttributes();
+3 −0
Original line number Diff line number Diff line
@@ -121,6 +121,9 @@ class ChannelWrapper final : public DOMEventTargetHelper,

  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; }