1 // Copyright (c) 2012 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.
5 #include "chrome/browser/chromeos/login/login_web_dialog.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/chromeos/login/helper.h"
9 #include "chrome/browser/chromeos/profiles/profile_helper.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser_dialogs.h"
12 #include "content/public/browser/notification_source.h"
13 #include "content/public/browser/notification_types.h"
14 #include "ui/gfx/native_widget_types.h"
15 #include "ui/gfx/rect.h"
16 #include "ui/gfx/size.h"
17 #include "ui/views/widget/widget.h"
19 using content::WebContents
;
20 using content::WebUIMessageHandler
;
26 // Default width/height ratio of screen size.
27 const double kDefaultWidthRatio
= 0.6;
28 const double kDefaultHeightRatio
= 0.6;
30 // Default width/height ratio of minimal dialog size.
31 const double kMinimumWidthRatio
= 0.25;
32 const double kMinimumHeightRatio
= 0.25;
36 ///////////////////////////////////////////////////////////////////////////////
37 // LoginWebDialog, public:
39 void LoginWebDialog::Delegate::OnDialogClosed() {
42 LoginWebDialog::LoginWebDialog(Delegate
* delegate
,
43 gfx::NativeWindow parent_window
,
44 const base::string16
& title
,
47 : delegate_(delegate
),
48 parent_window_(parent_window
),
53 gfx::Rect
screen_bounds(chromeos::CalculateScreenBounds(gfx::Size()));
54 width_
= static_cast<int>(kDefaultWidthRatio
* screen_bounds
.width());
55 height_
= static_cast<int>(kDefaultHeightRatio
* screen_bounds
.height());
58 LoginWebDialog::~LoginWebDialog() {
62 void LoginWebDialog::Show() {
63 chrome::ShowWebDialog(parent_window_
,
64 ProfileHelper::GetSigninProfile(),
69 void LoginWebDialog::SetDialogSize(int width
, int height
) {
70 DCHECK(width
>= 0 && height
>= 0);
75 void LoginWebDialog::SetDialogTitle(const base::string16
& title
) {
79 ///////////////////////////////////////////////////////////////////////////////
80 // LoginWebDialog, protected:
82 ui::ModalType
LoginWebDialog::GetDialogModalType() const {
83 return ui::MODAL_TYPE_SYSTEM
;
86 base::string16
LoginWebDialog::GetDialogTitle() const {
90 GURL
LoginWebDialog::GetDialogContentURL() const {
94 void LoginWebDialog::GetWebUIMessageHandlers(
95 std::vector
<WebUIMessageHandler
*>* handlers
) const {
98 void LoginWebDialog::GetDialogSize(gfx::Size
* size
) const {
99 size
->SetSize(width_
, height_
);
102 void LoginWebDialog::GetMinimumDialogSize(gfx::Size
* size
) const {
103 gfx::Rect
screen_bounds(chromeos::CalculateScreenBounds(gfx::Size()));
104 size
->SetSize(kMinimumWidthRatio
* screen_bounds
.width(),
105 kMinimumHeightRatio
* screen_bounds
.height());
108 std::string
LoginWebDialog::GetDialogArgs() const {
109 return std::string();
112 void LoginWebDialog::OnDialogClosed(const std::string
& json_retval
) {
114 notification_registrar_
.RemoveAll();
116 delegate_
->OnDialogClosed();
120 void LoginWebDialog::OnCloseContents(WebContents
* source
,
121 bool* out_close_dialog
) {
122 if (out_close_dialog
)
123 *out_close_dialog
= true;
126 bool LoginWebDialog::ShouldShowDialogTitle() const {
130 bool LoginWebDialog::HandleContextMenu(
131 const content::ContextMenuParams
& params
) {
132 // Disable context menu.
136 void LoginWebDialog::Observe(int type
,
137 const content::NotificationSource
& source
,
138 const content::NotificationDetails
& details
) {
139 DCHECK(type
== content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME
);
140 // TODO(saintlou): Do we need a throbber for Aura?
144 } // namespace chromeos