1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/chromeos/login/ui/login_screen_extension_ui/dialog_delegate.h" 6 7 #include "base/strings/utf_string_conversions.h" 8 #include "chrome/browser/chromeos/login/ui/login_screen_extension_ui/create_options.h" 9 #include "chrome/grit/generated_resources.h" 10 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_ui_message_handler.h" 12 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/display/display.h" 14 #include "ui/display/screen.h" 15 #include "ui/gfx/geometry/size.h" 16 17 namespace chromeos { 18 19 namespace { 20 const double kRelativeScreenWidth = 0.9; 21 const double kRelativeScreenHeight = 0.8; 22 } // namespace 23 24 namespace login_screen_extension_ui { 25 DialogDelegate(CreateOptions * create_options)26DialogDelegate::DialogDelegate(CreateOptions* create_options) 27 : extension_name_(create_options->extension_name), 28 content_url_(create_options->content_url), 29 can_close_(create_options->can_be_closed_by_user), 30 close_callback_(std::move(create_options->close_callback)) { 31 set_can_resize(false); 32 } 33 34 DialogDelegate::~DialogDelegate() = default; 35 GetDialogModalType() const36ui::ModalType DialogDelegate::GetDialogModalType() const { 37 return ui::MODAL_TYPE_WINDOW; 38 } 39 GetDialogTitle() const40base::string16 DialogDelegate::GetDialogTitle() const { 41 return l10n_util::GetStringFUTF16(IDS_LOGIN_EXTENSION_UI_DIALOG_TITLE, 42 base::UTF8ToUTF16(extension_name_)); 43 } 44 GetDialogContentURL() const45GURL DialogDelegate::GetDialogContentURL() const { 46 return content_url_; 47 } 48 GetDialogSize(gfx::Size * size) const49void DialogDelegate::GetDialogSize(gfx::Size* size) const { 50 gfx::Size screen_size = display::Screen::GetScreen() 51 ->GetDisplayNearestWindow(native_window_) 52 .size(); 53 *size = gfx::Size(kRelativeScreenWidth * screen_size.width(), 54 kRelativeScreenHeight * screen_size.height()); 55 } 56 OnDialogCloseRequested()57bool DialogDelegate::OnDialogCloseRequested() { 58 return can_close_; 59 } 60 GetWebUIMessageHandlers(std::vector<content::WebUIMessageHandler * > * handlers) const61void DialogDelegate::GetWebUIMessageHandlers( 62 std::vector<content::WebUIMessageHandler*>* handlers) const {} 63 GetDialogArgs() const64std::string DialogDelegate::GetDialogArgs() const { 65 return std::string(); 66 } 67 OnDialogClosed(const std::string & json_retval)68void DialogDelegate::OnDialogClosed(const std::string& json_retval) { 69 std::move(close_callback_).Run(); 70 delete this; 71 } 72 OnCloseContents(content::WebContents * source,bool * out_close_dialog)73void DialogDelegate::OnCloseContents(content::WebContents* source, 74 bool* out_close_dialog) { 75 *out_close_dialog = true; 76 } 77 ShouldCloseDialogOnEscape() const78bool DialogDelegate::ShouldCloseDialogOnEscape() const { 79 return false; 80 } 81 ShouldShowDialogTitle() const82bool DialogDelegate::ShouldShowDialogTitle() const { 83 return true; 84 } 85 ShouldCenterDialogTitleText() const86bool DialogDelegate::ShouldCenterDialogTitleText() const { 87 return true; 88 } 89 ShouldShowCloseButton() const90bool DialogDelegate::ShouldShowCloseButton() const { 91 return can_close_; 92 } 93 94 } // namespace login_screen_extension_ui 95 96 } // namespace chromeos 97