chromium/chrome/browser/resource_coordinator/discard_before_unload_helper.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/resource_coordinator/discard_before_unload_helper.h"

#include "base/functional/bind.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"

namespace resource_coordinator {

namespace {

// This is a helper class that determines whether or not there is a beforeunload
// handler associated with a given WebContents, and if so, whether or not it
// indicates that the page contains unsaved state.
//
// This is done by actually running the beforeunload handler if there is one. If
// the beforeunload handler returns a non-empty string then a javascript dialog
// request is made, in which case it is intercepted before it is displayed and
// implicitly canceled.
//
// The beforeunload is initiated via WebContents::DispatchBeforeUnload, and the
// outcome of the beforeunload is monitored via
// WebContentsObserver::BeforeUnloadFired and ::BeforeUnloadDialogCanceled.
//
// Note that the callback is guaranteed to be invoked; in the worst case
// scenario it will be invoked when the WebContents is destroyed, with a
// |proceed|=true value.
class DiscardBeforeUnloadHelper : public content::WebContentsObserver {};

void DiscardBeforeUnloadHelper::HasBeforeUnloadHandler(
    content::WebContents* contents,
    HasBeforeUnloadHandlerCallback&& callback) {}

DiscardBeforeUnloadHelper::DiscardBeforeUnloadHelper(
    content::WebContents* contents,
    HasBeforeUnloadHandlerCallback&& callback)
    :{}

DiscardBeforeUnloadHelper::~DiscardBeforeUnloadHelper() = default;

void DiscardBeforeUnloadHelper::BeforeUnloadFired(bool proceed) {}

void DiscardBeforeUnloadHelper::BeforeUnloadDialogCancelled() {}

void DiscardBeforeUnloadHelper::WebContentsDestroyed() {}

void DiscardBeforeUnloadHelper::Respond(bool has_beforeunload_handler) {}

}  // namespace

void HasBeforeUnloadHandler(content::WebContents* contents,
                            HasBeforeUnloadHandlerCallback&& callback) {}

}  // namespace resource_coordinator