Skip to content

Commit

Permalink
Backed out changeset 890d147bad1d (bug 1697866) for causing bustages …
Browse files Browse the repository at this point in the history
…in WindowGlobalParent.cpp CLOSED TREE
  • Loading branch information
nerli1 committed Sep 22, 2021
1 parent 9241c7d commit 50d4e6c
Show file tree
Hide file tree
Showing 18 changed files with 76 additions and 321 deletions.
10 changes: 4 additions & 6 deletions docshell/base/nsDocShell.cpp
Expand Up @@ -3679,17 +3679,15 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI* aURI,

// If the HTTPS-Only Mode upgraded this request and the upgrade might have
// caused this error, we replace the error-page with about:httpsonlyerror
bool isHttpsOnlyError =
nsHTTPSOnlyUtils::CouldBeHttpsOnlyError(aFailedChannel, aError);
if (isHttpsOnlyError) {
if (nsHTTPSOnlyUtils::CouldBeHttpsOnlyError(aFailedChannel, aError)) {
errorPage.AssignLiteral("httpsonlyerror");
}

if (nsCOMPtr<nsILoadURIDelegate> loadURIDelegate = GetLoadURIDelegate()) {
nsCOMPtr<nsIURI> errorPageURI;
rv = loadURIDelegate->HandleLoadError(
aURI, (isHttpsOnlyError ? NS_ERROR_HTTPS_ONLY : aError),
NS_ERROR_GET_MODULE(aError), getter_AddRefs(errorPageURI));
rv = loadURIDelegate->HandleLoadError(aURI, aError,
NS_ERROR_GET_MODULE(aError),
getter_AddRefs(errorPageURI));
// If the docshell is going away there's no point in showing an error page.
if (NS_FAILED(rv) || mIsBeingDestroyed) {
*aDisplayedErrorPage = false;
Expand Down
18 changes: 0 additions & 18 deletions dom/base/Document.cpp
Expand Up @@ -1511,18 +1511,6 @@ bool Document::CallerIsTrustedAboutNetError(JSContext* aCx, JSObject* aObject) {
#endif
}

bool Document::CallerIsTrustedAboutHttpsOnlyError(JSContext* aCx,
JSObject* aObject) {
nsGlobalWindowInner* win = xpc::WindowOrNull(aObject);
#ifdef ANDROID
// GeckoView uses data URLs for error pages, so for now just check for any
// error page
return win && win->GetDocument() && win->GetDocument()->IsErrorPage();
#else
return win && IsAboutErrorPage(win, "httpsonlyerror");
#endif
}

already_AddRefed<mozilla::dom::Promise> Document::AddCertException(
bool aIsTemporary) {
nsIGlobalObject* global = GetScopeObject();
Expand Down Expand Up @@ -1664,12 +1652,6 @@ already_AddRefed<mozilla::dom::Promise> Document::AddCertException(
return promise.forget();
}

void Document::ReloadWithHttpsOnlyException() {
if (WindowGlobalChild* wgc = GetWindowGlobalChild()) {
wgc->SendReloadWithHttpsOnlyException();
}
}

void Document::GetNetErrorInfo(NetErrorInfo& aInfo, ErrorResult& aRv) {
nsCOMPtr<nsISupports> info;
nsCOMPtr<nsITransportSecurityInfo> tsi;
Expand Down
9 changes: 0 additions & 9 deletions dom/base/Document.h
Expand Up @@ -2242,13 +2242,6 @@ class Document : public nsINode,
*/
static bool CallerIsTrustedAboutNetError(JSContext* aCx, JSObject* aObject);

/**
* This function checks if the document that is trying to access
* ReloadWithHttpsOnlyException is a trusted HTTPS only error page.
*/
static bool CallerIsTrustedAboutHttpsOnlyError(JSContext* aCx,
JSObject* aObject);

/**
* Get security info like error code for a failed channel. This
* property is only exposed to about:neterror documents.
Expand Down Expand Up @@ -4005,8 +3998,6 @@ class Document : public nsINode,

already_AddRefed<Promise> AddCertException(bool aIsTemporary);

void ReloadWithHttpsOnlyException();

// Subframes need to be static cloned after the main document has been
// embedded within a script global. A `PendingFrameStaticClone` is a static
// clone which has not yet been performed.
Expand Down
2 changes: 0 additions & 2 deletions dom/ipc/PWindowGlobal.ipdl
Expand Up @@ -203,8 +203,6 @@ parent:
async SetDocumentDomain(nsIURI aDomain);

async Destroy();

async ReloadWithHttpsOnlyException();
};

} // namespace dom
Expand Down
78 changes: 0 additions & 78 deletions dom/ipc/WindowGlobalParent.cpp
Expand Up @@ -49,8 +49,6 @@
#include "nsSandboxFlags.h"
#include "nsSerializationHelper.h"
#include "nsIBrowser.h"
#include "nsIEffectiveTLDService.h"
#include "nsIHttpsOnlyModePermission.h"
#include "nsIPromptCollection.h"
#include "nsITimer.h"
#include "nsITransportSecurityInfo.h"
Expand Down Expand Up @@ -1449,82 +1447,6 @@ mozilla::ipc::IPCResult WindowGlobalParent::RecvSetDocumentDomain(
return IPC_OK();
}

mozilla::ipc::IPCResult WindowGlobalParent::RecvReloadWithHttpsOnlyException() {
nsresult rv;
nsCOMPtr<nsIURI> currentUri = BrowsingContext()->Top()->GetCurrentURI();

bool isViewSource = currentUri->SchemeIs("view-source");

nsCOMPtr<nsINestedURI> nestedURI = do_QueryInterface(currentUri);
nsCOMPtr<nsIURI> innerURI;
if (isViewSource) {
nestedURI->GetInnerURI(getter_AddRefs(innerURI));
} else {
innerURI = currentUri;
}

if (!innerURI->SchemeIs("https") && !innerURI->SchemeIs("http")) {
return IPC_FAIL(this, "HTTPS-only mode: Illegal state");
}

// If the error page is within an iFrame, we create an exception for whatever
// scheme the top-level site is currently on, because the user wants to
// unbreak the iFrame and not the top-level page. When the error page shows up
// on a top-level request, then we replace the scheme with http, because the
// user wants to unbreak the whole page.
nsCOMPtr<nsIURI> newURI;
if (!BrowsingContext()->IsTop()) {
newURI = innerURI;
} else {
Unused << NS_MutateURI(innerURI).SetScheme("http"_ns).Finalize(
getter_AddRefs(newURI));
}

OriginAttributes originAttributes =
TopWindowContext()->DocumentPrincipal()->OriginAttributesRef();

originAttributes.SetFirstPartyDomain(true, newURI);

nsCOMPtr<nsIPermissionManager> permMgr =
components::PermissionManager::Service();
if (!permMgr) {
return IPC_FAIL(
this, "HTTPS-only mode: Failed to get Permission Manager service");
}

nsCOMPtr<nsIPrincipal> principal =
BasePrincipal::CreateContentPrincipal(newURI, originAttributes);

rv = permMgr->AddFromPrincipal(
principal, "https-only-load-insecure"_ns,
nsIHttpsOnlyModePermission::LOAD_INSECURE_ALLOW_SESSION,
nsIPermissionManager::EXPIRE_SESSION, 0);

if (NS_FAILED(rv)) {
return IPC_FAIL(
this, "HTTPS-only mode: Failed to add permission to the principal");
}

nsCOMPtr<nsIURI> insecureURI = newURI;
if (isViewSource) {
nsAutoCString spec;
MOZ_ALWAYS_SUCCEEDS(newURI->GetSpec(spec));
if (NS_FAILED(
NS_NewURI(getter_AddRefs(insecureURI), "view-source:"_ns + spec))) {
return IPC_FAIL(
this, "HTTPS-only mode: Failed to re-construct view-source URI");
}
}

RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(insecureURI);
loadState->SetTriggeringPrincipal(nsContentUtils::GetSystemPrincipal());
loadState->SetLoadFlags(nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY);

BrowsingContext()->Top()->LoadURI(loadState, /* setNavigating */ true);

return IPC_OK();
}

void WindowGlobalParent::ActorDestroy(ActorDestroyReason aWhy) {
if (mPageUseCountersWindow) {
mPageUseCountersWindow->FinishAccumulatingPageUseCounters();
Expand Down
2 changes: 0 additions & 2 deletions dom/ipc/WindowGlobalParent.h
Expand Up @@ -301,8 +301,6 @@ class WindowGlobalParent final : public WindowContext,

mozilla::ipc::IPCResult RecvSetDocumentDomain(nsIURI* aDomain);

mozilla::ipc::IPCResult RecvReloadWithHttpsOnlyException();

private:
WindowGlobalParent(CanonicalBrowsingContext* aBrowsingContext,
uint64_t aInnerWindowId, uint64_t aOuterWindowId,
Expand Down
3 changes: 0 additions & 3 deletions dom/webidl/Document.webidl
Expand Up @@ -322,9 +322,6 @@ partial interface Document {
[Func="Document::CallerIsTrustedAboutCertError"]
Promise<any> addCertException(boolean isTemporary);

[Func="Document::CallerIsTrustedAboutHttpsOnlyError"]
void reloadWithHttpsOnlyException();

[Func="Document::CallerIsTrustedAboutCertError", Throws]
FailedCertSecurityInfo getFailedCertSecurityInfo();

Expand Down
1 change: 0 additions & 1 deletion mobile/android/geckoview/api.txt
Expand Up @@ -2119,7 +2119,6 @@ package org.mozilla.geckoview {
field public static final int ERROR_DATA_URI_TOO_LONG = 117;
field public static final int ERROR_FILE_ACCESS_DENIED = 101;
field public static final int ERROR_FILE_NOT_FOUND = 85;
field public static final int ERROR_HTTPS_ONLY = 163;
field public static final int ERROR_INVALID_CONTENT_ENCODING = 84;
field public static final int ERROR_MALFORMED_URI = 53;
field public static final int ERROR_NET_INTERRUPT = 35;
Expand Down

This file was deleted.

0 comments on commit 50d4e6c

Please sign in to comment.