File: protocol_handler_launch_dialog_view.cc

package info (click to toggle)
chromium 139.0.7258.127-1~deb13u1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,096 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (95 lines) | stat: -rw-r--r-- 3,563 bytes parent folder | download | duplicates (5)
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
// 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/base/ui_base_types.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();
  auto* widget =
      views::DialogDelegate::CreateDialogWidget(std::move(view),
                                                /*context=*/gfx::NativeWindow(),
                                                /*parent=*/gfx::NativeView());
#if BUILDFLAG(IS_CHROMEOS)
  // On ChromeOS this dialog will be hidden underneath an existing Chrome
  // instance unless kFloatingWindow is specified.
  widget->SetZOrderLevel(ui::ZOrderLevel::kFloatingWindow);
#endif
  widget->Show();
}

}  // namespace web_app