| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/common/system/chromeos/network/tray_sms.h" | 5 #include "ash/common/system/chromeos/network/tray_sms.h" |
| 6 | 6 |
| 7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
| 8 #include "ash/common/metrics/user_metrics_action.h" |
| 8 #include "ash/common/system/tray/fixed_sized_scroll_view.h" | 9 #include "ash/common/system/tray/fixed_sized_scroll_view.h" |
| 9 #include "ash/common/system/tray/system_tray_bubble.h" | 10 #include "ash/common/system/tray/system_tray_bubble.h" |
| 10 #include "ash/common/system/tray/tray_constants.h" | 11 #include "ash/common/system/tray/tray_constants.h" |
| 11 #include "ash/common/system/tray/tray_details_view.h" | 12 #include "ash/common/system/tray/tray_details_view.h" |
| 12 #include "ash/common/system/tray/tray_item_more.h" | 13 #include "ash/common/system/tray/tray_item_more.h" |
| 13 #include "ash/common/system/tray/tray_item_view.h" | 14 #include "ash/common/system/tray/tray_item_view.h" |
| 14 #include "ash/common/system/tray/tray_notification_view.h" | 15 #include "ash/common/system/tray/tray_notification_view.h" |
| 15 #include "ash/common/system/tray/view_click_listener.h" | 16 #include "ash/common/system/tray/view_click_listener.h" |
| 17 #include "ash/common/wm_shell.h" |
| 16 #include "ash/system/tray/system_tray.h" | 18 #include "ash/system/tray/system_tray.h" |
| 17 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 19 #include "chromeos/network/network_event_log.h" | 21 #include "chromeos/network/network_event_log.h" |
| 20 #include "chromeos/network/network_handler.h" | 22 #include "chromeos/network/network_handler.h" |
| 21 #include "grit/ash_resources.h" | 23 #include "grit/ash_resources.h" |
| 22 #include "grit/ash_strings.h" | 24 #include "grit/ash_strings.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
| 25 #include "ui/gfx/paint_vector_icon.h" | 27 #include "ui/gfx/paint_vector_icon.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 if (view_type == VIEW_DETAILED) | 118 if (view_type == VIEW_DETAILED) |
| 117 LayoutDetailedView(); | 119 LayoutDetailedView(); |
| 118 else | 120 else |
| 119 LayoutNotificationView(); | 121 LayoutNotificationView(); |
| 120 } | 122 } |
| 121 | 123 |
| 122 ~SmsMessageView() override {} | 124 ~SmsMessageView() override {} |
| 123 | 125 |
| 124 // Overridden from ButtonListener. | 126 // Overridden from ButtonListener. |
| 125 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 127 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
| 126 owner_->RemoveMessage(index_); | 128 if (owner_->RemoveMessage(index_)) { |
| 129 WmShell::Get()->RecordUserMetricsAction( |
| 130 UMA_STATUS_AREA_SMS_DETAILED_DISMISS_MSG); |
| 131 } |
| 127 owner_->Update(false); | 132 owner_->Update(false); |
| 128 } | 133 } |
| 129 | 134 |
| 130 private: | 135 private: |
| 131 void LayoutDetailedView() { | 136 void LayoutDetailedView() { |
| 132 views::ImageButton* close_button = new views::ImageButton(this); | 137 views::ImageButton* close_button = new views::ImageButton(this); |
| 133 close_button->SetImage( | 138 close_button->SetImage( |
| 134 views::CustomButton::STATE_NORMAL, | 139 views::CustomButton::STATE_NORMAL, |
| 135 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 140 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 136 IDR_AURA_UBER_TRAY_SMS_DISMISS)); | 141 IDR_AURA_UBER_TRAY_SMS_DISMISS)); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 preferred_size.set_height(kMessageListMinHeight); | 219 preferred_size.set_height(kMessageListMinHeight); |
| 215 return preferred_size; | 220 return preferred_size; |
| 216 } | 221 } |
| 217 | 222 |
| 218 private: | 223 private: |
| 219 void UpdateMessageList() { | 224 void UpdateMessageList() { |
| 220 const base::ListValue& messages = | 225 const base::ListValue& messages = |
| 221 static_cast<TraySms*>(owner())->messages(); | 226 static_cast<TraySms*>(owner())->messages(); |
| 222 scroll_content()->RemoveAllChildViews(true); | 227 scroll_content()->RemoveAllChildViews(true); |
| 223 for (size_t index = 0; index < messages.GetSize(); ++index) { | 228 for (size_t index = 0; index < messages.GetSize(); ++index) { |
| 224 const base::DictionaryValue* message = NULL; | 229 const base::DictionaryValue* message = nullptr; |
| 225 if (!messages.GetDictionary(index, &message)) { | 230 if (!messages.GetDictionary(index, &message)) { |
| 226 LOG(ERROR) << "SMS message not a dictionary at: " << index; | 231 LOG(ERROR) << "SMS message not a dictionary at: " << index; |
| 227 continue; | 232 continue; |
| 228 } | 233 } |
| 229 std::string number, text; | 234 std::string number, text; |
| 230 if (!GetMessageFromDictionary(message, &number, &text)) { | 235 if (!GetMessageFromDictionary(message, &number, &text)) { |
| 231 LOG(ERROR) << "Error parsing SMS message"; | 236 LOG(ERROR) << "Error parsing SMS message"; |
| 232 continue; | 237 continue; |
| 233 } | 238 } |
| 234 SmsMessageView* msgview = new SmsMessageView( | 239 SmsMessageView* msgview = new SmsMessageView( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 264 void Update(size_t message_index, | 269 void Update(size_t message_index, |
| 265 const std::string& number, | 270 const std::string& number, |
| 266 const std::string& text) { | 271 const std::string& text) { |
| 267 SmsMessageView* message_view = | 272 SmsMessageView* message_view = |
| 268 new SmsMessageView(tray_sms(), SmsMessageView::VIEW_NOTIFICATION, | 273 new SmsMessageView(tray_sms(), SmsMessageView::VIEW_NOTIFICATION, |
| 269 message_index_, number, text); | 274 message_index_, number, text); |
| 270 UpdateView(message_view); | 275 UpdateView(message_view); |
| 271 } | 276 } |
| 272 | 277 |
| 273 // Overridden from TrayNotificationView: | 278 // Overridden from TrayNotificationView: |
| 274 void OnClose() override { tray_sms()->RemoveMessage(message_index_); } | 279 void OnClose() override { |
| 280 if (tray_sms()->RemoveMessage(message_index_)) { |
| 281 WmShell::Get()->RecordUserMetricsAction( |
| 282 UMA_STATUS_AREA_SMS_NOTIFICATION_DISMISS_MSG); |
| 283 } |
| 284 } |
| 275 | 285 |
| 276 void OnClickAction() override { owner()->PopupDetailedView(0, true); } | 286 void OnClickAction() override { owner()->PopupDetailedView(0, true); } |
| 277 | 287 |
| 278 private: | 288 private: |
| 279 TraySms* tray_sms() { return static_cast<TraySms*>(owner()); } | 289 TraySms* tray_sms() { return static_cast<TraySms*>(owner()); } |
| 280 | 290 |
| 281 size_t message_index_; | 291 size_t message_index_; |
| 282 | 292 |
| 283 DISALLOW_COPY_AND_ASSIGN(SmsNotificationView); | 293 DISALLOW_COPY_AND_ASSIGN(SmsNotificationView); |
| 284 }; | 294 }; |
| 285 | 295 |
| 286 TraySms::TraySms(SystemTray* system_tray) | 296 TraySms::TraySms(SystemTray* system_tray) |
| 287 : SystemTrayItem(system_tray), | 297 : SystemTrayItem(system_tray), |
| 288 default_(NULL), | 298 default_(nullptr), |
| 289 detailed_(NULL), | 299 detailed_(nullptr), |
| 290 notification_(NULL) { | 300 notification_(nullptr) { |
| 291 // TODO(armansito): SMS could be a special case for cellular that requires a | 301 // TODO(armansito): SMS could be a special case for cellular that requires a |
| 292 // user (perhaps the owner) to be logged in. If that is the case, then an | 302 // user (perhaps the owner) to be logged in. If that is the case, then an |
| 293 // additional check should be done before subscribing for SMS notifications. | 303 // additional check should be done before subscribing for SMS notifications. |
| 294 if (chromeos::NetworkHandler::IsInitialized()) | 304 if (chromeos::NetworkHandler::IsInitialized()) |
| 295 chromeos::NetworkHandler::Get()->network_sms_handler()->AddObserver(this); | 305 chromeos::NetworkHandler::Get()->network_sms_handler()->AddObserver(this); |
| 296 } | 306 } |
| 297 | 307 |
| 298 TraySms::~TraySms() { | 308 TraySms::~TraySms() { |
| 299 if (chromeos::NetworkHandler::IsInitialized()) { | 309 if (chromeos::NetworkHandler::IsInitialized()) { |
| 300 chromeos::NetworkHandler::Get()->network_sms_handler()->RemoveObserver( | 310 chromeos::NetworkHandler::Get()->network_sms_handler()->RemoveObserver( |
| 301 this); | 311 this); |
| 302 } | 312 } |
| 303 } | 313 } |
| 304 | 314 |
| 305 views::View* TraySms::CreateDefaultView(LoginStatus status) { | 315 views::View* TraySms::CreateDefaultView(LoginStatus status) { |
| 306 CHECK(default_ == NULL); | 316 CHECK(default_ == nullptr); |
| 307 default_ = new SmsDefaultView(this); | 317 default_ = new SmsDefaultView(this); |
| 308 default_->SetVisible(!messages_.empty()); | 318 default_->SetVisible(!messages_.empty()); |
| 309 return default_; | 319 return default_; |
| 310 } | 320 } |
| 311 | 321 |
| 312 views::View* TraySms::CreateDetailedView(LoginStatus status) { | 322 views::View* TraySms::CreateDetailedView(LoginStatus status) { |
| 313 CHECK(detailed_ == NULL); | 323 CHECK(detailed_ == nullptr); |
| 314 HideNotificationView(); | 324 HideNotificationView(); |
| 315 if (messages_.empty()) | 325 if (messages_.empty()) |
| 316 return NULL; | 326 return nullptr; |
| 317 detailed_ = new SmsDetailedView(this); | 327 detailed_ = new SmsDetailedView(this); |
| 328 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_DETAILED_SMS_VIEW); |
| 318 return detailed_; | 329 return detailed_; |
| 319 } | 330 } |
| 320 | 331 |
| 321 views::View* TraySms::CreateNotificationView(LoginStatus status) { | 332 views::View* TraySms::CreateNotificationView(LoginStatus status) { |
| 322 CHECK(notification_ == NULL); | 333 CHECK(notification_ == nullptr); |
| 323 if (detailed_) | 334 if (detailed_) |
| 324 return NULL; | 335 return nullptr; |
| 325 size_t index; | 336 size_t index; |
| 326 std::string number, text; | 337 std::string number, text; |
| 327 if (GetLatestMessage(&index, &number, &text)) | 338 if (GetLatestMessage(&index, &number, &text)) |
| 328 notification_ = new SmsNotificationView(this, index, number, text); | 339 notification_ = new SmsNotificationView(this, index, number, text); |
| 329 return notification_; | 340 return notification_; |
| 330 } | 341 } |
| 331 | 342 |
| 332 void TraySms::DestroyDefaultView() { | 343 void TraySms::DestroyDefaultView() { |
| 333 default_ = NULL; | 344 default_ = nullptr; |
| 334 } | 345 } |
| 335 | 346 |
| 336 void TraySms::DestroyDetailedView() { | 347 void TraySms::DestroyDetailedView() { |
| 337 detailed_ = NULL; | 348 detailed_ = nullptr; |
| 338 } | 349 } |
| 339 | 350 |
| 340 void TraySms::DestroyNotificationView() { | 351 void TraySms::DestroyNotificationView() { |
| 341 notification_ = NULL; | 352 notification_ = nullptr; |
| 342 } | 353 } |
| 343 | 354 |
| 344 void TraySms::MessageReceived(const base::DictionaryValue& message) { | 355 void TraySms::MessageReceived(const base::DictionaryValue& message) { |
| 345 std::string message_text; | 356 std::string message_text; |
| 346 if (!message.GetStringWithoutPathExpansion( | 357 if (!message.GetStringWithoutPathExpansion( |
| 347 chromeos::NetworkSmsHandler::kTextKey, &message_text)) { | 358 chromeos::NetworkSmsHandler::kTextKey, &message_text)) { |
| 348 NET_LOG_ERROR("SMS message contains no content.", ""); | 359 NET_LOG_ERROR("SMS message contains no content.", ""); |
| 349 return; | 360 return; |
| 350 } | 361 } |
| 351 // TODO(armansito): A message might be due to a special "Message Waiting" | 362 // TODO(armansito): A message might be due to a special "Message Waiting" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 381 base::DictionaryValue* message; | 392 base::DictionaryValue* message; |
| 382 size_t message_index = messages_.GetSize() - 1; | 393 size_t message_index = messages_.GetSize() - 1; |
| 383 if (!messages_.GetDictionary(message_index, &message)) | 394 if (!messages_.GetDictionary(message_index, &message)) |
| 384 return false; | 395 return false; |
| 385 if (!GetMessageFromDictionary(message, number, text)) | 396 if (!GetMessageFromDictionary(message, number, text)) |
| 386 return false; | 397 return false; |
| 387 *index = message_index; | 398 *index = message_index; |
| 388 return true; | 399 return true; |
| 389 } | 400 } |
| 390 | 401 |
| 391 void TraySms::RemoveMessage(size_t index) { | 402 bool TraySms::RemoveMessage(size_t index) { |
| 392 if (index < messages_.GetSize()) | 403 if (index >= messages_.GetSize()) |
| 393 messages_.Remove(index, NULL); | 404 return false; |
| 405 messages_.Remove(index, nullptr); |
| 406 return true; |
| 394 } | 407 } |
| 395 | 408 |
| 396 void TraySms::Update(bool notify) { | 409 void TraySms::Update(bool notify) { |
| 397 if (messages_.empty()) { | 410 if (messages_.empty()) { |
| 398 if (default_) | 411 if (default_) |
| 399 default_->SetVisible(false); | 412 default_->SetVisible(false); |
| 400 if (detailed_) | 413 if (detailed_) |
| 401 HideDetailedView(); | 414 HideDetailedView(); |
| 402 HideNotificationView(); | 415 HideNotificationView(); |
| 403 } else { | 416 } else { |
| 404 if (default_) { | 417 if (default_) { |
| 405 default_->SetVisible(true); | 418 default_->SetVisible(true); |
| 406 default_->Update(); | 419 default_->Update(); |
| 407 } | 420 } |
| 408 if (detailed_) | 421 if (detailed_) |
| 409 detailed_->Update(); | 422 detailed_->Update(); |
| 410 if (notification_) { | 423 if (notification_) { |
| 411 size_t index; | 424 size_t index; |
| 412 std::string number, text; | 425 std::string number, text; |
| 413 if (GetLatestMessage(&index, &number, &text)) | 426 if (GetLatestMessage(&index, &number, &text)) |
| 414 notification_->Update(index, number, text); | 427 notification_->Update(index, number, text); |
| 415 } else if (notify) { | 428 } else if (notify) { |
| 416 ShowNotificationView(); | 429 ShowNotificationView(); |
| 417 } | 430 } |
| 418 } | 431 } |
| 419 } | 432 } |
| 420 | 433 |
| 421 } // namespace ash | 434 } // namespace ash |
| OLD | NEW |