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