Commit 54a7a5b6 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

weblayer: adds ability to disable ErrorPageHelper

The logic in ErrorPageHelper is only applicable when the error
page content is provided by weblayer. If the embedder provides
html for an error page, then ErrorPageHelper shouldn't be used.
This adds a mojom interface to disable ErrorPageHelper for the
next load. I had wanted to delete the instance, but this is
complicated if the frame is reused and would result in having to
duplicate some of the logic.

BUG=1031060
TEST=none

Change-Id: I21d9390a3bfd9dc32084bb77b7a4c1b55c770324
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2330936
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarClark DuVall <cduvall@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794285}
parent e7c49ee5
...@@ -124,7 +124,10 @@ if (is_android) { ...@@ -124,7 +124,10 @@ if (is_android) {
mojom("common_mojom") { mojom("common_mojom") {
disable_variants = true disable_variants = true
sources = [ "common/renderer_configuration.mojom" ] sources = [
"common/error_page_helper.mojom",
"common/renderer_configuration.mojom",
]
deps = [ "//components/content_settings/core/common:mojo_bindings" ] deps = [ "//components/content_settings/core/common:mojo_bindings" ]
} }
......
...@@ -5,9 +5,12 @@ ...@@ -5,9 +5,12 @@
#include "weblayer/browser/navigation_error_navigation_throttle.h" #include "weblayer/browser/navigation_error_navigation_throttle.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "weblayer/browser/navigation_controller_impl.h" #include "weblayer/browser/navigation_controller_impl.h"
#include "weblayer/browser/tab_impl.h" #include "weblayer/browser/tab_impl.h"
#include "weblayer/common/error_page_helper.mojom.h"
#include "weblayer/public/error_page.h" #include "weblayer/public/error_page.h"
#include "weblayer/public/error_page_delegate.h" #include "weblayer/public/error_page_delegate.h"
...@@ -48,12 +51,19 @@ NavigationErrorNavigationThrottle::WillFailRequest() { ...@@ -48,12 +51,19 @@ NavigationErrorNavigationThrottle::WillFailRequest() {
// The navigation this was created for should always outlive this. // The navigation this was created for should always outlive this.
DCHECK(navigation); DCHECK(navigation);
auto error_page = tab->error_page_delegate()->GetErrorPageContent(navigation); auto error_page = tab->error_page_delegate()->GetErrorPageContent(navigation);
if (error_page) { if (!error_page)
return NavigationThrottle::ThrottleCheckResult( return NavigationThrottle::PROCEED;
NavigationThrottle::BLOCK_REQUEST,
navigation_handle()->GetNetErrorCode(), error_page->html); mojo::AssociatedRemote<mojom::ErrorPageHelper> remote_error_page_helper;
} navigation_handle()
return NavigationThrottle::PROCEED; ->GetRenderFrameHost()
->GetRemoteAssociatedInterfaces()
->GetInterface(&remote_error_page_helper);
remote_error_page_helper->DisableErrorPageHelperForNextError();
return NavigationThrottle::ThrottleCheckResult(
NavigationThrottle::BLOCK_REQUEST, navigation_handle()->GetNetErrorCode(),
error_page->html);
} }
const char* NavigationErrorNavigationThrottle::GetNameForLogging() { const char* NavigationErrorNavigationThrottle::GetNameForLogging() {
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module weblayer.mojom;
// Used to control the renderer's ErrorPageHelper.
interface ErrorPageHelper {
// Used to disable the ErrorPageHelper for the next error. This is used when
// the embedder injects its own error page.
DisableErrorPageHelperForNextError();
};
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_thread.h" #include "content/public/renderer/render_thread.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
#include "third_party/blink/public/web/web_local_frame.h" #include "third_party/blink/public/web/web_local_frame.h"
#include "weblayer/common/features.h" #include "weblayer/common/features.h"
...@@ -40,10 +41,15 @@ ErrorPageHelper* ErrorPageHelper::GetForFrame( ...@@ -40,10 +41,15 @@ ErrorPageHelper* ErrorPageHelper::GetForFrame(
} }
void ErrorPageHelper::PrepareErrorPage(const error_page::Error& error) { void ErrorPageHelper::PrepareErrorPage(const error_page::Error& error) {
if (is_disabled_for_next_error_) {
is_disabled_for_next_error_ = false;
return;
}
pending_error_page_info_ = std::make_unique<ErrorPageInfo>(error); pending_error_page_info_ = std::make_unique<ErrorPageInfo>(error);
} }
void ErrorPageHelper::DidCommitProvisionalLoad(ui::PageTransition transition) { void ErrorPageHelper::DidCommitProvisionalLoad(ui::PageTransition transition) {
is_disabled_for_next_error_ = false;
committed_error_page_info_ = std::move(pending_error_page_info_); committed_error_page_info_ = std::move(pending_error_page_info_);
weak_factory_.InvalidateWeakPtrs(); weak_factory_.InvalidateWeakPtrs();
} }
...@@ -126,9 +132,17 @@ ErrorPageHelper::GetInterface() { ...@@ -126,9 +132,17 @@ ErrorPageHelper::GetInterface() {
return interface; return interface;
} }
void ErrorPageHelper::DisableErrorPageHelperForNextError() {
is_disabled_for_next_error_ = true;
}
ErrorPageHelper::ErrorPageHelper(content::RenderFrame* render_frame) ErrorPageHelper::ErrorPageHelper(content::RenderFrame* render_frame)
: RenderFrameObserver(render_frame), : RenderFrameObserver(render_frame),
RenderFrameObserverTracker<ErrorPageHelper>(render_frame) {} RenderFrameObserverTracker<ErrorPageHelper>(render_frame) {
render_frame->GetAssociatedInterfaceRegistry()->AddInterface(
base::BindRepeating(&ErrorPageHelper::BindErrorPageHelper,
weak_factory_.GetWeakPtr()));
}
ErrorPageHelper::~ErrorPageHelper() = default; ErrorPageHelper::~ErrorPageHelper() = default;
...@@ -138,4 +152,11 @@ void ErrorPageHelper::Reload() { ...@@ -138,4 +152,11 @@ void ErrorPageHelper::Reload() {
render_frame()->GetWebFrame()->StartReload(blink::WebFrameLoadType::kReload); render_frame()->GetWebFrame()->StartReload(blink::WebFrameLoadType::kReload);
} }
void ErrorPageHelper::BindErrorPageHelper(
mojo::PendingAssociatedReceiver<mojom::ErrorPageHelper> receiver) {
// There is only a need for a single receiver to be bound at a time.
error_page_helper_receiver_.reset();
error_page_helper_receiver_.Bind(std::move(receiver));
}
} // namespace weblayer } // namespace weblayer
...@@ -10,7 +10,10 @@ ...@@ -10,7 +10,10 @@
#include "components/security_interstitials/core/common/mojom/interstitial_commands.mojom.h" #include "components/security_interstitials/core/common/mojom/interstitial_commands.mojom.h"
#include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_frame_observer.h"
#include "content/public/renderer/render_frame_observer_tracker.h" #include "content/public/renderer/render_frame_observer_tracker.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "weblayer/common/error_page_helper.mojom.h"
namespace error_page { namespace error_page {
class Error; class Error;
...@@ -27,7 +30,8 @@ class ErrorPageHelper ...@@ -27,7 +30,8 @@ class ErrorPageHelper
: public content::RenderFrameObserver, : public content::RenderFrameObserver,
public content::RenderFrameObserverTracker<ErrorPageHelper>, public content::RenderFrameObserverTracker<ErrorPageHelper>,
public security_interstitials::SecurityInterstitialPageController:: public security_interstitials::SecurityInterstitialPageController::
Delegate { Delegate,
public mojom::ErrorPageHelper {
public: public:
// Creates an ErrorPageHelper which will observe and tie its lifetime to // Creates an ErrorPageHelper which will observe and tie its lifetime to
// |render_frame|, if it's a main frame. ErrorPageHelpers will not be created // |render_frame|, if it's a main frame. ErrorPageHelpers will not be created
...@@ -48,10 +52,12 @@ class ErrorPageHelper ...@@ -48,10 +52,12 @@ class ErrorPageHelper
// security_interstitials::SecurityInterstitialPageController::Delegate: // security_interstitials::SecurityInterstitialPageController::Delegate:
void SendCommand( void SendCommand(
security_interstitials::SecurityInterstitialCommand command) override; security_interstitials::SecurityInterstitialCommand command) override;
mojo::AssociatedRemote<security_interstitials::mojom::InterstitialCommands> mojo::AssociatedRemote<security_interstitials::mojom::InterstitialCommands>
GetInterface() override; GetInterface() override;
// mojom::ErrorPageHelper:
void DisableErrorPageHelperForNextError() override;
private: private:
struct ErrorPageInfo; struct ErrorPageInfo;
...@@ -60,6 +66,9 @@ class ErrorPageHelper ...@@ -60,6 +66,9 @@ class ErrorPageHelper
void Reload(); void Reload();
void BindErrorPageHelper(
mojo::PendingAssociatedReceiver<mojom::ErrorPageHelper> receiver);
// Information for the provisional / "pre-provisional" error page. Null when // Information for the provisional / "pre-provisional" error page. Null when
// there's no page pending, or the pending page is not an error page. // there's no page pending, or the pending page is not an error page.
std::unique_ptr<ErrorPageInfo> pending_error_page_info_; std::unique_ptr<ErrorPageInfo> pending_error_page_info_;
...@@ -68,6 +77,14 @@ class ErrorPageHelper ...@@ -68,6 +77,14 @@ class ErrorPageHelper
// not an error page. // not an error page.
std::unique_ptr<ErrorPageInfo> committed_error_page_info_; std::unique_ptr<ErrorPageInfo> committed_error_page_info_;
// Set to true when the embedder injects its own error page. When the
// embedder injects its own error page the support here is not needed and
// disabled.
bool is_disabled_for_next_error_ = false;
mojo::AssociatedReceiver<mojom::ErrorPageHelper> error_page_helper_receiver_{
this};
base::WeakPtrFactory<ErrorPageHelper> weak_factory_{this}; base::WeakPtrFactory<ErrorPageHelper> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ErrorPageHelper); DISALLOW_COPY_AND_ASSIGN(ErrorPageHelper);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment