blob: 3a38554350eaa2d56b6109aa8dc90097696b7220 [file] [log] [blame]
// Copyright 2019 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.
#import <Cocoa/Cocoa.h>
#include "base/mac/scoped_nsobject.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "ui/gfx/text_elider.h"
#include "ui/views_bridge_mac/mojo/alert.mojom.h"
#include "ui/views_bridge_mac/views_bridge_mac_export.h"
@class AlertBridgeHelper;
namespace views_bridge_mac {
// Class that displays an NSAlert with associated UI as described by the mojo
// AlertBridge interface.
: public views_bridge_mac::mojom::AlertBridge {
// Creates a new alert which controls its own lifetime. It will destroy itself
// once its NSAlert goes away.
AlertBridge(mojom::AlertBridgeRequest bridge_request);
// Send the specified disposition via the Show callback, then destroy |this|.
void SendResultAndDestroy(mojom::AlertDisposition disposition);
// Called by Cocoa to indicate when the NSAlert is visible (and can be
// programmatically updated by Accept, Cancel, and Close).
void SetAlertHasShown();
// Private destructor is called only through SendResultAndDestroy.
~AlertBridge() override;
// Handle being disconnected (e.g, because the alert was programmatically
// dismissed).
void OnConnectionError();
// views_bridge_mac::mojom::Alert:
void Show(mojom::AlertBridgeInitParamsPtr params,
ShowCallback callback) override;
// The NSAlert's owner and delegate.
base::scoped_nsobject<AlertBridgeHelper> helper_;
// Set once the alert window is showing (needed because showing is done in a
// posted task).
bool alert_shown_ = false;
// The callback to make when the dialog has finished running.
ShowCallback callback_;
mojo::Binding<views_bridge_mac::mojom::AlertBridge> mojo_binding_;
base::WeakPtrFactory<AlertBridge> weak_factory_;
} // namespace views_bridge_mac