File: tab_modal_confirm_dialog_delegate.cc

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (125 lines) | stat: -rw-r--r-- 3,271 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright 2012 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/ui/tab_modal_confirm_dialog_delegate.h"

#include "components/strings/grit/components_strings.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/mojom/dialog_button.mojom.h"
#include "ui/base/ui_base_types.h"

using content::WebContents;

TabModalConfirmDialogDelegate::TabModalConfirmDialogDelegate(
    WebContents* web_contents)
    : content::WebContentsObserver(web_contents),
      close_delegate_(nullptr),
      closing_(false) {}

TabModalConfirmDialogDelegate::~TabModalConfirmDialogDelegate() {
  // If we end up here, the window has been closed, so make sure we don't close
  // it again.
  close_delegate_ = nullptr;
  // Make sure everything is cleaned up.
  Cancel();
}

void TabModalConfirmDialogDelegate::Cancel() {
  if (closing_) {
    return;
  }
  // Make sure we won't do anything when another action occurs.
  closing_ = true;
  OnCanceled();
  CloseDialog();
}

void TabModalConfirmDialogDelegate::Accept() {
  if (closing_) {
    return;
  }
  // Make sure we won't do anything when another action occurs.
  closing_ = true;
  OnAccepted();
  CloseDialog();
}

void TabModalConfirmDialogDelegate::Close() {
  if (closing_) {
    return;
  }
  // Make sure we won't do anything when another action occurs.
  closing_ = true;
  OnClosed();
  CloseDialog();
}

void TabModalConfirmDialogDelegate::LinkClicked(
    WindowOpenDisposition disposition) {
  if (closing_) {
    return;
  }
  OnLinkClicked(disposition);
}

gfx::Image* TabModalConfirmDialogDelegate::GetIcon() {
  return nullptr;
}

int TabModalConfirmDialogDelegate::GetDialogButtons() const {
  return static_cast<int>(ui::mojom::DialogButton::kOk) |
         static_cast<int>(ui::mojom::DialogButton::kCancel);
}

std::u16string TabModalConfirmDialogDelegate::GetAcceptButtonTitle() {
  return l10n_util::GetStringUTF16(IDS_OK);
}

std::u16string TabModalConfirmDialogDelegate::GetCancelButtonTitle() {
  return l10n_util::GetStringUTF16(IDS_CANCEL);
}

std::u16string TabModalConfirmDialogDelegate::GetLinkText() const {
  return std::u16string();
}

const char* TabModalConfirmDialogDelegate::GetAcceptButtonIcon() {
  return nullptr;
}

const char* TabModalConfirmDialogDelegate::GetCancelButtonIcon() {
  return nullptr;
}

void TabModalConfirmDialogDelegate::OnAccepted() {}

void TabModalConfirmDialogDelegate::OnCanceled() {}

void TabModalConfirmDialogDelegate::OnLinkClicked(
    WindowOpenDisposition disposition) {}

void TabModalConfirmDialogDelegate::OnClosed() {}

void TabModalConfirmDialogDelegate::CloseDialog() {
  if (close_delegate_) {
    close_delegate_->CloseDialog();
  }
}

std::optional<int> TabModalConfirmDialogDelegate::GetDefaultDialogButton() {
  // Use the default, don't override.
  return std::nullopt;
}

std::optional<int> TabModalConfirmDialogDelegate::GetInitiallyFocusedButton() {
  // Use the default, don't override.
  return std::nullopt;
}

void TabModalConfirmDialogDelegate::DidStartLoading() {
  // Close the dialog if we load a page (because the action might not apply to
  // the same page anymore).
  Close();
}