OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "chrome/browser/chromeos/charger_replace/charger_replacement_dialog.h" | |
6 | |
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 "grit/generated_resources.h" | |
14 #include "ui/base/l10n/l10n_util.h" | |
15 #include "ui/gfx/size.h" | |
16 | |
17 using content::WebContents; | |
18 using content::WebUIMessageHandler; | |
19 | |
20 namespace chromeos { | |
21 | |
22 namespace { | |
23 | |
24 const int kDefaultDialogWidth = 500; | |
25 const int kDefaultDialogHeight = 590; | |
26 const int kMinDialogWidth = 100; | |
27 const int kMinDialogHeight = 100; | |
28 | |
29 const char* kNewChargerOrdered = "1"; | |
xiyuan
2013/12/06 00:24:37
nit: use const char[] instead of *.
jennyz
2013/12/06 03:54:24
Done.
| |
30 const char* kNewChargerNotOrdered = "0"; | |
xiyuan
2013/12/06 00:24:37
nit: same here.
jennyz
2013/12/06 03:54:24
Done.
| |
31 | |
32 } // namespace | |
33 | |
34 // static member variable. | |
35 bool ChargerReplacementDialog::is_window_visible_ = false; | |
36 | |
37 ChargerReplacementDialog::ChargerReplacementDialog( | |
38 gfx::NativeWindow parent_window) | |
39 : parent_window_(parent_window), | |
40 can_close_(false), | |
41 charger_replacement_handler_(new ChargerReplacementHandler(this)) { | |
42 } | |
43 | |
44 ChargerReplacementDialog::~ChargerReplacementDialog() { | |
45 is_window_visible_ = false; | |
46 } | |
47 | |
48 bool ChargerReplacementDialog::ShouldShowDialog() { | |
49 if (is_window_visible_) | |
50 return false; | |
51 | |
52 ChargerReplacementHandler::SpringChargerStatus charger_status = | |
53 ChargerReplacementHandler::GetChargerStatusPref(); | |
54 | |
55 return (charger_status == ChargerReplacementHandler::CHARGER_UNKNOWN || | |
56 charger_status == | |
57 ChargerReplacementHandler::CONFIRM_NEW_CHARGER_ORDERED_ONLINE || | |
58 charger_status == | |
59 ChargerReplacementHandler::CONFIRM_ORDER_NEW_CHARGER_BY_PHONE); | |
60 } | |
61 | |
62 void ChargerReplacementDialog::Show() { | |
63 is_window_visible_ = true; | |
64 gfx::NativeWindow dialog_window = | |
65 chrome::ShowWebDialog(parent_window_, | |
66 ProfileManager::GetDefaultProfile(), | |
67 this); | |
68 charger_replacement_handler_->set_charger_window(dialog_window); | |
69 } | |
70 | |
71 ui::ModalType ChargerReplacementDialog::GetDialogModalType() const { | |
72 return ui::MODAL_TYPE_SYSTEM; | |
73 } | |
74 | |
75 string16 ChargerReplacementDialog::GetDialogTitle() const { | |
76 return l10n_util::GetStringUTF16(IDS_CHARGER_REPLACEMENT_DIALOG_TITLE); | |
77 } | |
78 | |
79 GURL ChargerReplacementDialog::GetDialogContentURL() const { | |
80 return GURL(chrome::kChromeUIChargerReplacementURL); | |
81 } | |
82 | |
83 void ChargerReplacementDialog::GetWebUIMessageHandlers( | |
84 std::vector<WebUIMessageHandler*>* handlers) const { | |
85 handlers->push_back(charger_replacement_handler_); | |
86 } | |
87 | |
88 void ChargerReplacementDialog::GetMinimumDialogSize(gfx::Size* size) const { | |
89 size->SetSize(kMinDialogWidth, kMinDialogHeight); | |
90 } | |
91 | |
92 void ChargerReplacementDialog::GetDialogSize(gfx::Size* size) const { | |
93 size->SetSize(kDefaultDialogWidth, kDefaultDialogHeight); | |
94 } | |
95 | |
96 std::string ChargerReplacementDialog::GetDialogArgs() const { | |
97 ChargerReplacementHandler::SpringChargerStatus charger_status = | |
98 ChargerReplacementHandler::GetChargerStatusPref(); | |
99 if (charger_status == | |
100 ChargerReplacementHandler::CONFIRM_NEW_CHARGER_ORDERED_ONLINE || | |
101 charger_status == | |
102 ChargerReplacementHandler::CONFIRM_ORDER_NEW_CHARGER_BY_PHONE) { | |
103 return std::string(kNewChargerOrdered); | |
104 } else { | |
105 return std::string(kNewChargerNotOrdered); | |
106 } | |
107 } | |
108 | |
109 bool ChargerReplacementDialog::CanCloseDialog() const { | |
110 return can_close_; | |
111 } | |
112 | |
113 void ChargerReplacementDialog::OnDialogClosed(const std::string& json_retval) { | |
114 delete this; | |
115 } | |
116 | |
117 void ChargerReplacementDialog::OnCloseContents(WebContents* source, | |
118 bool* out_close_dialog) { | |
119 if (out_close_dialog) | |
120 *out_close_dialog = true; | |
121 } | |
122 | |
123 bool ChargerReplacementDialog::ShouldShowDialogTitle() const { | |
124 return true; | |
125 } | |
126 | |
127 bool ChargerReplacementDialog::HandleContextMenu( | |
128 const content::ContextMenuParams& params) { | |
129 // Disable context menu. | |
130 return true; | |
131 } | |
132 | |
133 } // namespace chromeos | |
OLD | NEW |