| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/net/network_portal_notification_controller.h" | 5 #include "chrome/browser/chromeos/net/network_portal_notification_controller.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 12 #include "ash/system/system_notifier.h" | 13 #include "ash/system/system_notifier.h" |
| 13 #include "ash/system/tray/system_tray_notifier.h" | 14 #include "ash/system/tray/system_tray_notifier.h" |
| 14 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 15 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 16 #include "base/macros.h" | 17 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/scoped_ptr.h" | |
| 19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 20 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
| 21 #include "base/strings/string16.h" | 21 #include "base/strings/string16.h" |
| 22 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/browser_process_platform_part.h" | 25 #include "chrome/browser/browser_process_platform_part.h" |
| 26 #include "chrome/browser/chromeos/mobile/mobile_activator.h" | 26 #include "chrome/browser/chromeos/mobile/mobile_activator.h" |
| 27 #include "chrome/browser/chromeos/net/network_portal_web_dialog.h" | 27 #include "chrome/browser/chromeos/net/network_portal_web_dialog.h" |
| 28 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 28 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 } | 322 } |
| 323 | 323 |
| 324 void NetworkPortalNotificationController::OnDialogDestroyed( | 324 void NetworkPortalNotificationController::OnDialogDestroyed( |
| 325 const NetworkPortalWebDialog* dialog) { | 325 const NetworkPortalWebDialog* dialog) { |
| 326 if (dialog == dialog_) { | 326 if (dialog == dialog_) { |
| 327 dialog_ = nullptr; | 327 dialog_ = nullptr; |
| 328 ProfileHelper::Get()->ClearSigninProfile(base::Closure()); | 328 ProfileHelper::Get()->ClearSigninProfile(base::Closure()); |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 | 331 |
| 332 scoped_ptr<message_center::Notification> | 332 std::unique_ptr<message_center::Notification> |
| 333 NetworkPortalNotificationController::CreateDefaultCaptivePortalNotification( | 333 NetworkPortalNotificationController::CreateDefaultCaptivePortalNotification( |
| 334 const NetworkState* network) { | 334 const NetworkState* network) { |
| 335 message_center::RichNotificationData data; | 335 message_center::RichNotificationData data; |
| 336 scoped_refptr<NetworkPortalNotificationControllerDelegate> delegate( | 336 scoped_refptr<NetworkPortalNotificationControllerDelegate> delegate( |
| 337 new NetworkPortalNotificationControllerDelegate( | 337 new NetworkPortalNotificationControllerDelegate( |
| 338 std::string(), network->guid(), weak_factory_.GetWeakPtr())); | 338 std::string(), network->guid(), weak_factory_.GetWeakPtr())); |
| 339 gfx::Image& icon = GetImageForNotification(); | 339 gfx::Image& icon = GetImageForNotification(); |
| 340 message_center::NotifierId notifier_id( | 340 message_center::NotifierId notifier_id( |
| 341 message_center::NotifierId::SYSTEM_COMPONENT, | 341 message_center::NotifierId::SYSTEM_COMPONENT, |
| 342 ash::system_notifier::kNotifierNetworkPortalDetector); | 342 ash::system_notifier::kNotifierNetworkPortalDetector); |
| 343 base::string16 notificationText; | 343 base::string16 notificationText; |
| 344 bool is_wifi = NetworkTypePattern::WiFi().MatchesType(network->type()); | 344 bool is_wifi = NetworkTypePattern::WiFi().MatchesType(network->type()); |
| 345 scoped_ptr<Notification> notification(new Notification( | 345 std::unique_ptr<Notification> notification(new Notification( |
| 346 message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId, | 346 message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId, |
| 347 l10n_util::GetStringUTF16( | 347 l10n_util::GetStringUTF16( |
| 348 is_wifi ? IDS_PORTAL_DETECTION_NOTIFICATION_TITLE_WIFI | 348 is_wifi ? IDS_PORTAL_DETECTION_NOTIFICATION_TITLE_WIFI |
| 349 : IDS_PORTAL_DETECTION_NOTIFICATION_TITLE_WIRED), | 349 : IDS_PORTAL_DETECTION_NOTIFICATION_TITLE_WIRED), |
| 350 l10n_util::GetStringFUTF16( | 350 l10n_util::GetStringFUTF16( |
| 351 is_wifi ? IDS_PORTAL_DETECTION_NOTIFICATION_MESSAGE_WIFI | 351 is_wifi ? IDS_PORTAL_DETECTION_NOTIFICATION_MESSAGE_WIFI |
| 352 : IDS_PORTAL_DETECTION_NOTIFICATION_MESSAGE_WIRED, | 352 : IDS_PORTAL_DETECTION_NOTIFICATION_MESSAGE_WIRED, |
| 353 base::UTF8ToUTF16(network->name())), | 353 base::UTF8ToUTF16(network->name())), |
| 354 icon, base::string16(), GURL(), notifier_id, data, delegate.get())); | 354 icon, base::string16(), GURL(), notifier_id, data, delegate.get())); |
| 355 notification->SetSystemPriority(); | 355 notification->SetSystemPriority(); |
| 356 return notification; | 356 return notification; |
| 357 } | 357 } |
| 358 | 358 |
| 359 scoped_ptr<message_center::Notification> NetworkPortalNotificationController:: | 359 std::unique_ptr<message_center::Notification> |
| 360 NetworkPortalNotificationController:: |
| 360 CreateCaptivePortalNotificationForExtension( | 361 CreateCaptivePortalNotificationForExtension( |
| 361 const NetworkState* network, | 362 const NetworkState* network, |
| 362 extensions::NetworkingConfigService* networking_config_service, | 363 extensions::NetworkingConfigService* networking_config_service, |
| 363 const extensions::Extension* extension) { | 364 const extensions::Extension* extension) { |
| 364 message_center::RichNotificationData data; | 365 message_center::RichNotificationData data; |
| 365 scoped_refptr<NetworkPortalNotificationControllerDelegate> delegate( | 366 scoped_refptr<NetworkPortalNotificationControllerDelegate> delegate( |
| 366 new NetworkPortalNotificationControllerDelegate( | 367 new NetworkPortalNotificationControllerDelegate( |
| 367 extension->id(), network->guid(), weak_factory_.GetWeakPtr())); | 368 extension->id(), network->guid(), weak_factory_.GetWeakPtr())); |
| 368 gfx::Image& icon = GetImageForNotification(); | 369 gfx::Image& icon = GetImageForNotification(); |
| 369 message_center::NotifierId notifier_id( | 370 message_center::NotifierId notifier_id( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 390 notificationText = l10n_util::GetStringFUTF16( | 391 notificationText = l10n_util::GetStringFUTF16( |
| 391 IDS_PORTAL_DETECTION_NOTIFICATION_MESSAGE_FAILED_WIFI, | 392 IDS_PORTAL_DETECTION_NOTIFICATION_MESSAGE_FAILED_WIFI, |
| 392 base::UTF8ToUTF16(network->name())); | 393 base::UTF8ToUTF16(network->name())); |
| 393 data.buttons.push_back( | 394 data.buttons.push_back( |
| 394 message_center::ButtonInfo(l10n_util::GetStringFUTF16( | 395 message_center::ButtonInfo(l10n_util::GetStringFUTF16( |
| 395 IDS_PORTAL_DETECTION_NOTIFICATION_BUTTON_EXTENSION_RETRY, | 396 IDS_PORTAL_DETECTION_NOTIFICATION_BUTTON_EXTENSION_RETRY, |
| 396 base::UTF8ToUTF16(extension->name())))); | 397 base::UTF8ToUTF16(extension->name())))); |
| 397 data.buttons.push_back(message_center::ButtonInfo(l10n_util::GetStringUTF16( | 398 data.buttons.push_back(message_center::ButtonInfo(l10n_util::GetStringUTF16( |
| 398 IDS_PORTAL_DETECTION_NOTIFICATION_BUTTON_PORTAL))); | 399 IDS_PORTAL_DETECTION_NOTIFICATION_BUTTON_PORTAL))); |
| 399 } | 400 } |
| 400 scoped_ptr<Notification> notification(new Notification( | 401 std::unique_ptr<Notification> notification(new Notification( |
| 401 message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId, | 402 message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId, |
| 402 l10n_util::GetStringUTF16(IDS_PORTAL_DETECTION_NOTIFICATION_TITLE_WIFI), | 403 l10n_util::GetStringUTF16(IDS_PORTAL_DETECTION_NOTIFICATION_TITLE_WIFI), |
| 403 notificationText, icon, base::string16() /* display_source */, GURL(), | 404 notificationText, icon, base::string16() /* display_source */, GURL(), |
| 404 notifier_id, data, delegate.get())); | 405 notifier_id, data, delegate.get())); |
| 405 notification->SetSystemPriority(); | 406 notification->SetSystemPriority(); |
| 406 return notification; | 407 return notification; |
| 407 } | 408 } |
| 408 | 409 |
| 409 scoped_ptr<Notification> NetworkPortalNotificationController::GetNotification( | 410 std::unique_ptr<Notification> |
| 411 NetworkPortalNotificationController::GetNotification( |
| 410 const NetworkState* network, | 412 const NetworkState* network, |
| 411 const NetworkPortalDetector::CaptivePortalState& state) { | 413 const NetworkPortalDetector::CaptivePortalState& state) { |
| 412 base::string16 notificationText; | 414 base::string16 notificationText; |
| 413 Profile* profile = GetProfileForPrimaryUser(); | 415 Profile* profile = GetProfileForPrimaryUser(); |
| 414 extensions::NetworkingConfigService* networking_config_service = | 416 extensions::NetworkingConfigService* networking_config_service = |
| 415 GetNetworkingConfigService(profile); | 417 GetNetworkingConfigService(profile); |
| 416 std::string extension_id; | 418 std::string extension_id; |
| 417 const extensions::Extension* extension = nullptr; | 419 const extensions::Extension* extension = nullptr; |
| 418 if (networking_config_service) { | 420 if (networking_config_service) { |
| 419 extension = LookupExtensionForRawSsid(networking_config_service, | 421 extension = LookupExtensionForRawSsid(networking_config_service, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 440 if (dialog_) | 442 if (dialog_) |
| 441 dialog_->Close(); | 443 dialog_->Close(); |
| 442 } | 444 } |
| 443 | 445 |
| 444 const NetworkPortalWebDialog* | 446 const NetworkPortalWebDialog* |
| 445 NetworkPortalNotificationController::GetDialogForTesting() const { | 447 NetworkPortalNotificationController::GetDialogForTesting() const { |
| 446 return dialog_; | 448 return dialog_; |
| 447 } | 449 } |
| 448 | 450 |
| 449 } // namespace chromeos | 451 } // namespace chromeos |
| OLD | NEW |