-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1622028 - Log failed upgrades for HTTPS Only Mode. r=ckerschb,dra…
…gana Differential Revision: https://phabricator.services.mozilla.com/D68026 --HG-- extra : moz-landing-system : lando
- Loading branch information
JulianWels
committed
Mar 27, 2020
1 parent
40755c3
commit b9a66ff
Showing
18 changed files
with
200 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* -*- Mode: C++; tab-width: 8; 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/. */ | ||
|
||
#include "nsHTTPSOnlyStreamListener.h" | ||
#include "nsHTTPSOnlyUtils.h" | ||
#include "nsCOMPtr.h" | ||
#include "nsIChannel.h" | ||
#include "nsIRequest.h" | ||
#include "nsITransportSecurityInfo.h" | ||
#include "nsIURI.h" | ||
#include "nsPrintfCString.h" | ||
|
||
NS_IMPL_ISUPPORTS(nsHTTPSOnlyStreamListener, nsIStreamListener, | ||
nsIRequestObserver) | ||
|
||
nsHTTPSOnlyStreamListener::nsHTTPSOnlyStreamListener( | ||
nsIStreamListener* aListener) { | ||
mListener = aListener; | ||
} | ||
|
||
NS_IMETHODIMP | ||
nsHTTPSOnlyStreamListener::OnDataAvailable(nsIRequest* aRequest, | ||
nsIInputStream* aInputStream, | ||
uint64_t aOffset, uint32_t aCount) { | ||
return mListener->OnDataAvailable(aRequest, aInputStream, aOffset, aCount); | ||
} | ||
|
||
NS_IMETHODIMP | ||
nsHTTPSOnlyStreamListener::OnStartRequest(nsIRequest* request) { | ||
return mListener->OnStartRequest(request); | ||
} | ||
|
||
NS_IMETHODIMP | ||
nsHTTPSOnlyStreamListener::OnStopRequest(nsIRequest* request, | ||
nsresult aStatus) { | ||
// If the request failed we'll log it to the console with the error-code | ||
if (NS_FAILED(aStatus)) { | ||
nsresult rv; | ||
// Try to query for the channel-object | ||
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request, &rv); | ||
if (NS_SUCCEEDED(rv)) { | ||
nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo(); | ||
uint32_t innerWindowId = loadInfo->GetInnerWindowID(); | ||
|
||
nsCOMPtr<nsIURI> uri; | ||
rv = channel->GetURI(getter_AddRefs(uri)); | ||
if (NS_SUCCEEDED(rv)) { | ||
// Logging URI as well as Module- and Error-Code | ||
AutoTArray<nsString, 2> params = { | ||
NS_ConvertUTF8toUTF16(uri->GetSpecOrDefault()), | ||
NS_ConvertUTF8toUTF16(nsPrintfCString("M%u-C%u", | ||
NS_ERROR_GET_MODULE(aStatus), | ||
NS_ERROR_GET_CODE(aStatus)))}; | ||
nsHTTPSOnlyUtils::LogLocalizedString( | ||
"HTTPSOnlyFailedRequest", params, nsIScriptError::errorFlag, | ||
innerWindowId, !!loadInfo->GetOriginAttributes().mPrivateBrowsingId, | ||
uri); | ||
} | ||
} | ||
} | ||
|
||
return mListener->OnStopRequest(request, aStatus); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* -*- Mode: C++; tab-width: 8; 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 nsHTTPSOnlyStreamListener_h___ | ||
#define nsHTTPSOnlyStreamListener_h___ | ||
|
||
#include "nsIStreamListener.h" | ||
#include "nsCOMPtr.h" | ||
|
||
/** | ||
* This event listener gets registered for requests that have been upgraded | ||
* using the HTTPS-only mode to log failed upgrades to the console. | ||
*/ | ||
class nsHTTPSOnlyStreamListener : public nsIStreamListener { | ||
public: | ||
// nsISupports methods | ||
NS_DECL_ISUPPORTS | ||
NS_DECL_NSIREQUESTOBSERVER | ||
NS_DECL_NSISTREAMLISTENER | ||
|
||
explicit nsHTTPSOnlyStreamListener(nsIStreamListener* aListener); | ||
|
||
private: | ||
virtual ~nsHTTPSOnlyStreamListener() = default; | ||
|
||
nsCOMPtr<nsIStreamListener> mListener; | ||
}; | ||
|
||
#endif /* nsHTTPSOnlyStreamListener_h___ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.