1 // Copyright (c) 2013 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/charger_replace/charger_replacement_dialog.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/browser/ui/browser_dialogs.h"
11 #include "chrome/browser/ui/webui/chromeos/charger_replacement_handler.h"
12 #include "chrome/common/url_constants.h"
13 #include "content/public/browser/user_metrics.h"
14 #include "grit/generated_resources.h"
15 #include "ui/aura/window.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/gfx/size.h"
19 using content::WebContents
;
20 using content::WebUIMessageHandler
;
26 const int kDefaultDialogWidth
= 500;
27 const int kDefaultDialogHeight
= 590;
28 const int kMinDialogWidth
= 100;
29 const int kMinDialogHeight
= 100;
31 const char kNewChargerOrdered
[] = "1";
32 const char kNewChargerNotOrdered
[] = "0";
36 // static member variable.
37 bool ChargerReplacementDialog::is_window_visible_
= false;
38 gfx::NativeWindow
ChargerReplacementDialog::current_window_
= NULL
;
40 ChargerReplacementDialog::ChargerReplacementDialog(
41 gfx::NativeWindow parent_window
)
42 : parent_window_(parent_window
),
44 charger_replacement_handler_(new ChargerReplacementHandler(this)) {
47 ChargerReplacementDialog::~ChargerReplacementDialog() {
48 is_window_visible_
= false;
49 current_window_
= NULL
;
52 bool ChargerReplacementDialog::ShouldShowDialog() {
53 if (is_window_visible_
)
56 ChargerReplacementHandler::SpringChargerStatus charger_status
=
57 ChargerReplacementHandler::GetChargerStatusPref();
59 return (charger_status
== ChargerReplacementHandler::CHARGER_UNKNOWN
||
61 ChargerReplacementHandler::CONFIRM_NEW_CHARGER_ORDERED_ONLINE
||
63 ChargerReplacementHandler::CONFIRM_ORDER_NEW_CHARGER_BY_PHONE
);
66 void ChargerReplacementDialog::SetFocusOnChargerDialogIfVisible() {
67 if (is_window_visible_
&& current_window_
)
68 current_window_
->Focus();
71 void ChargerReplacementDialog::Show() {
72 content::RecordAction(
73 base::UserMetricsAction("ShowChargerReplacementDialog"));
75 is_window_visible_
= true;
76 // We show the dialog for the active user, so that the dialog will get
77 // displayed immediately. The parent window is a system modal/lock container
78 // and does not belong to any user.
79 current_window_
= chrome::ShowWebDialog(
81 ProfileManager::GetActiveUserProfile(),
83 charger_replacement_handler_
->set_charger_window(current_window_
);
86 ui::ModalType
ChargerReplacementDialog::GetDialogModalType() const {
87 return ui::MODAL_TYPE_SYSTEM
;
90 base::string16
ChargerReplacementDialog::GetDialogTitle() const {
91 return l10n_util::GetStringUTF16(IDS_CHARGER_REPLACEMENT_DIALOG_TITLE
);
94 GURL
ChargerReplacementDialog::GetDialogContentURL() const {
95 return GURL(chrome::kChromeUIChargerReplacementURL
);
98 void ChargerReplacementDialog::GetWebUIMessageHandlers(
99 std::vector
<WebUIMessageHandler
*>* handlers
) const {
100 handlers
->push_back(charger_replacement_handler_
);
103 void ChargerReplacementDialog::GetMinimumDialogSize(gfx::Size
* size
) const {
104 size
->SetSize(kMinDialogWidth
, kMinDialogHeight
);
107 void ChargerReplacementDialog::GetDialogSize(gfx::Size
* size
) const {
108 size
->SetSize(kDefaultDialogWidth
, kDefaultDialogHeight
);
111 std::string
ChargerReplacementDialog::GetDialogArgs() const {
112 ChargerReplacementHandler::SpringChargerStatus charger_status
=
113 ChargerReplacementHandler::GetChargerStatusPref();
114 if (charger_status
==
115 ChargerReplacementHandler::CONFIRM_NEW_CHARGER_ORDERED_ONLINE
||
117 ChargerReplacementHandler::CONFIRM_ORDER_NEW_CHARGER_BY_PHONE
) {
118 return std::string(kNewChargerOrdered
);
120 return std::string(kNewChargerNotOrdered
);
124 bool ChargerReplacementDialog::CanCloseDialog() const {
128 void ChargerReplacementDialog::OnDialogClosed(const std::string
& json_retval
) {
132 void ChargerReplacementDialog::OnCloseContents(WebContents
* source
,
133 bool* out_close_dialog
) {
134 if (out_close_dialog
)
135 *out_close_dialog
= true;
138 bool ChargerReplacementDialog::ShouldShowDialogTitle() const {
142 bool ChargerReplacementDialog::HandleContextMenu(
143 const content::ContextMenuParams
& params
) {
144 // Disable context menu.
148 } // namespace chromeos