Skip to content

Commit

Permalink
Bug 1000540 - added an observer notification to nsFileChannel. r=vale…
Browse files Browse the repository at this point in the history
…ntin,necko-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D193392
  • Loading branch information
DylanOToole2 committed Nov 15, 2023
1 parent 0a9c3af commit 7601cd7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions netwerk/protocol/file/nsFileChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "nsProxyRelease.h"
#include "nsIContentPolicy.h"
#include "nsContentUtils.h"
#include "mozilla/dom/ContentParent.h"

#include "nsIFileURL.h"
#include "nsIURIMutator.h"
Expand Down Expand Up @@ -406,6 +407,9 @@ nsresult nsFileChannel::OpenContentStream(bool async, nsIInputStream** result,
}
}

// notify "file-channel-opened" observers
MaybeSendFileOpenNotification();

*result = nullptr;
stream.swap(*result);
return NS_OK;
Expand Down Expand Up @@ -481,6 +485,38 @@ nsFileChannel::GetFile(nsIFile** file) {
return fileURL->GetFile(file);
}

nsresult nsFileChannel::MaybeSendFileOpenNotification() {
nsCOMPtr<nsIObserverService> obsService = services::GetObserverService();
if (!obsService) {
return NS_OK;
}

nsCOMPtr<nsILoadInfo> loadInfo;
nsresult rv = GetLoadInfo(getter_AddRefs(loadInfo));
if (NS_FAILED(rv)) {
return rv;
}

bool isTopLevel;
rv = loadInfo->GetIsTopLevelLoad(&isTopLevel);
if (NS_FAILED(rv)) {
return rv;
}

uint64_t browsingContextID;
rv = loadInfo->GetBrowsingContextID(&browsingContextID);
if (NS_FAILED(rv)) {
return rv;
}

if ((browsingContextID != 0 && isTopLevel) ||
!loadInfo->TriggeringPrincipal()->IsSystemPrincipal()) {
obsService->NotifyObservers(static_cast<nsIChannel*>(this),
"file-channel-opened", nullptr);
}
return NS_OK;
}

//-----------------------------------------------------------------------------
// nsFileChannel::nsIUploadChannel

Expand Down
1 change: 1 addition & 0 deletions netwerk/protocol/file/nsFileChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class nsFileChannel : public nsBaseChannel,

private:
nsresult FixupContentLength(bool async);
nsresult MaybeSendFileOpenNotification();

nsCOMPtr<nsIInputStream> mUploadStream;
int64_t mUploadLength;
Expand Down

0 comments on commit 7601cd7

Please sign in to comment.