File: protocol_handler_launch_dialog_view.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; 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 (88 lines) | stat: -rw-r--r-- 3,277 bytes parent folder | download | duplicates (2)
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
// Copyright 2021 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/views/web_apps/protocol_handler_launch_dialog_view.h"

#include <memory>
#include <string>
#include <utility>

#include "chrome/browser/ui/web_applications/web_app_dialogs.h"
#include "chrome/grit/generated_resources.h"
#include "components/custom_handlers/protocol_handler.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/mojom/dialog_button.mojom.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/layout_provider.h"

namespace web_app {

ProtocolHandlerLaunchDialogView::ProtocolHandlerLaunchDialogView(
    GURL url,
    Profile* profile,
    const webapps::AppId& app_id,
    WebAppLaunchAcceptanceCallback close_callback)
    : LaunchAppUserChoiceDialogView(profile, app_id, std::move(close_callback)),
      url_(std::move(url)) {
  auto* layout_provider = views::LayoutProvider::Get();
  set_margins(layout_provider->GetDialogInsetsForContentType(
      views::DialogContentType::kText, views::DialogContentType::kControl));
  set_fixed_width(layout_provider->GetDistanceMetric(
      views::DISTANCE_BUBBLE_PREFERRED_WIDTH));
  SetButtonLabel(ui::mojom::DialogButton::kOk,
                 l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW));
  SetButtonLabel(
      ui::mojom::DialogButton::kCancel,
      l10n_util::GetStringUTF16(IDS_WEB_APP_PERMISSION_NEGATIVE_BUTTON));
  SetDefaultButton(static_cast<int>(ui::mojom::DialogButton::kCancel));
}

ProtocolHandlerLaunchDialogView::~ProtocolHandlerLaunchDialogView() = default;

std::unique_ptr<views::View>
ProtocolHandlerLaunchDialogView::CreateAboveAppInfoView() {
  // Add "Allow app to open" label.
  auto open_app_label = std::make_unique<views::Label>(
      l10n_util::GetStringFUTF16(
          IDS_PROTOCOL_HANDLER_INTENT_PICKER_QUESTION,
          custom_handlers::ProtocolHandler::GetProtocolDisplayName(
              url_.scheme())),
      views::style::CONTEXT_DIALOG_BODY_TEXT,
      views::style::TextStyle::STYLE_PRIMARY);
  open_app_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
  open_app_label->SetMultiLine(true);
  return open_app_label;
}

std::unique_ptr<views::View>
ProtocolHandlerLaunchDialogView::CreateBelowAppInfoView() {
  return nullptr;
}

std::u16string ProtocolHandlerLaunchDialogView::GetRememberChoiceString() {
  return l10n_util::GetStringUTF16(
      IDS_INTENT_PICKER_BUBBLE_VIEW_REMEMBER_SELECTION);
}

BEGIN_METADATA(ProtocolHandlerLaunchDialogView)
END_METADATA

void ShowWebAppProtocolLaunchDialog(
    const GURL& url,
    Profile* profile,
    const webapps::AppId& app_id,
    WebAppLaunchAcceptanceCallback close_callback) {
  auto view = std::make_unique<web_app::ProtocolHandlerLaunchDialogView>(
      url, profile, app_id, std::move(close_callback));
  view->Init();
  views::DialogDelegate::CreateDialogWidget(std::move(view),
                                            /*context=*/gfx::NativeWindow(),
                                            /*parent=*/gfx::NativeView())
      ->Show();
}

}  // namespace web_app