| 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 "chrome/browser/ui/ash/screenshot_taker.h" | 5 #include "chrome/browser/ui/ash/screenshot_taker.h" |
| 6 | 6 |
| 7 #include <climits> | 7 #include <climits> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/shell_delegate.h" |
| 11 #include "ash/system/system_notifier.h" | 12 #include "ash/system/system_notifier.h" |
| 12 #include "base/base64.h" | 13 #include "base/base64.h" |
| 13 #include "base/bind.h" | 14 #include "base/bind.h" |
| 14 #include "base/file_util.h" | 15 #include "base/file_util.h" |
| 15 #include "base/i18n/time_formatting.h" | 16 #include "base/i18n/time_formatting.h" |
| 16 #include "base/logging.h" | 17 #include "base/logging.h" |
| 17 #include "base/memory/ref_counted_memory.h" | 18 #include "base/memory/ref_counted_memory.h" |
| 18 #include "base/prefs/pref_service.h" | 19 #include "base/prefs/pref_service.h" |
| 19 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 33 #include "grit/ui_strings.h" | 34 #include "grit/ui_strings.h" |
| 34 #include "ui/aura/window.h" | 35 #include "ui/aura/window.h" |
| 35 #include "ui/aura/window_event_dispatcher.h" | 36 #include "ui/aura/window_event_dispatcher.h" |
| 36 #include "ui/base/clipboard/clipboard.h" | 37 #include "ui/base/clipboard/clipboard.h" |
| 37 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 38 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 38 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
| 39 #include "ui/base/resource/resource_bundle.h" | 40 #include "ui/base/resource/resource_bundle.h" |
| 40 #include "ui/gfx/image/image.h" | 41 #include "ui/gfx/image/image.h" |
| 41 #include "ui/snapshot/snapshot.h" | 42 #include "ui/snapshot/snapshot.h" |
| 42 | 43 |
| 43 #if defined(USE_ASH) | |
| 44 #include "ash/shell.h" | |
| 45 #include "ash/shell_delegate.h" | |
| 46 #endif | |
| 47 | |
| 48 #if defined(OS_CHROMEOS) | 44 #if defined(OS_CHROMEOS) |
| 49 #include "chrome/browser/chromeos/drive/file_system_interface.h" | 45 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
| 50 #include "chrome/browser/chromeos/drive/file_system_util.h" | 46 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 51 #include "chrome/browser/chromeos/file_manager/open_util.h" | 47 #include "chrome/browser/chromeos/file_manager/open_util.h" |
| 52 #include "chrome/browser/chromeos/login/user_manager.h" | 48 #include "chrome/browser/chromeos/login/user_manager.h" |
| 53 #include "chrome/browser/notifications/desktop_notification_service.h" | 49 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 54 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 50 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 55 #include "chromeos/login/login_state.h" | 51 #include "chromeos/login/login_state.h" |
| 56 #endif | 52 #endif |
| 57 | 53 |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 content::RecordAction(base::UserMetricsAction("Screenshot_TakePartial")); | 460 content::RecordAction(base::UserMetricsAction("Screenshot_TakePartial")); |
| 465 } | 461 } |
| 466 | 462 |
| 467 bool ScreenshotTaker::CanTakeScreenshot() { | 463 bool ScreenshotTaker::CanTakeScreenshot() { |
| 468 return last_screenshot_timestamp_.is_null() || | 464 return last_screenshot_timestamp_.is_null() || |
| 469 base::Time::Now() - last_screenshot_timestamp_ > | 465 base::Time::Now() - last_screenshot_timestamp_ > |
| 470 base::TimeDelta::FromMilliseconds( | 466 base::TimeDelta::FromMilliseconds( |
| 471 kScreenshotMinimumIntervalInMS); | 467 kScreenshotMinimumIntervalInMS); |
| 472 } | 468 } |
| 473 | 469 |
| 470 #if defined(OS_CHROMEOS) |
| 474 Notification* ScreenshotTaker::CreateNotification( | 471 Notification* ScreenshotTaker::CreateNotification( |
| 475 ScreenshotTakerObserver::Result screenshot_result, | 472 ScreenshotTakerObserver::Result screenshot_result, |
| 476 const base::FilePath& screenshot_path) { | 473 const base::FilePath& screenshot_path) { |
| 477 const std::string notification_id(kNotificationId); | 474 const std::string notification_id(kNotificationId); |
| 478 // We cancel a previous screenshot notification, if any, to ensure we get | 475 // We cancel a previous screenshot notification, if any, to ensure we get |
| 479 // a fresh notification pop-up. | 476 // a fresh notification pop-up. |
| 480 g_browser_process->notification_ui_manager()->CancelById(notification_id); | 477 g_browser_process->notification_ui_manager()->CancelById(notification_id); |
| 481 const base::string16 replace_id(base::UTF8ToUTF16(notification_id)); | 478 const base::string16 replace_id(base::UTF8ToUTF16(notification_id)); |
| 482 bool success = | 479 bool success = |
| 483 (screenshot_result == ScreenshotTakerObserver::SCREENSHOT_SUCCESS); | 480 (screenshot_result == ScreenshotTakerObserver::SCREENSHOT_SUCCESS); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 499 blink::WebTextDirectionDefault, | 496 blink::WebTextDirectionDefault, |
| 500 message_center::NotifierId( | 497 message_center::NotifierId( |
| 501 message_center::NotifierId::SYSTEM_COMPONENT, | 498 message_center::NotifierId::SYSTEM_COMPONENT, |
| 502 ash::system_notifier::kNotifierScreenshot), | 499 ash::system_notifier::kNotifierScreenshot), |
| 503 l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_NOTIFIER_SCREENSHOT_NAME), | 500 l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_NOTIFIER_SCREENSHOT_NAME), |
| 504 replace_id, | 501 replace_id, |
| 505 optional_field, | 502 optional_field, |
| 506 new ScreenshotTakerNotificationDelegate( | 503 new ScreenshotTakerNotificationDelegate( |
| 507 success, GetProfile(), screenshot_path)); | 504 success, GetProfile(), screenshot_path)); |
| 508 } | 505 } |
| 506 #endif |
| 509 | 507 |
| 510 void ScreenshotTaker::ShowNotification( | 508 void ScreenshotTaker::ShowNotification( |
| 511 ScreenshotTakerObserver::Result screenshot_result, | 509 ScreenshotTakerObserver::Result screenshot_result, |
| 512 const base::FilePath& screenshot_path) { | 510 const base::FilePath& screenshot_path) { |
| 513 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 511 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 514 #if defined(OS_CHROMEOS) | 512 #if defined(OS_CHROMEOS) |
| 515 // Do not show a notification that a screenshot was taken while no user is | 513 // Do not show a notification that a screenshot was taken while no user is |
| 516 // logged in, since it is confusing for the user to get a message about it | 514 // logged in, since it is confusing for the user to get a message about it |
| 517 // after he logs in (crbug.com/235217). | 515 // after he logs in (crbug.com/235217). |
| 518 if (!chromeos::LoginState::Get()->IsUserLoggedIn()) | 516 if (!chromeos::LoginState::Get()->IsUserLoggedIn()) |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 } | 623 } |
| 626 | 624 |
| 627 void ScreenshotTaker::SetScreenshotBasenameForTest( | 625 void ScreenshotTaker::SetScreenshotBasenameForTest( |
| 628 const std::string& basename) { | 626 const std::string& basename) { |
| 629 screenshot_basename_for_test_ = basename; | 627 screenshot_basename_for_test_ = basename; |
| 630 } | 628 } |
| 631 | 629 |
| 632 void ScreenshotTaker::SetScreenshotProfileForTest(Profile* profile) { | 630 void ScreenshotTaker::SetScreenshotProfileForTest(Profile* profile) { |
| 633 profile_for_test_ = profile; | 631 profile_for_test_ = profile; |
| 634 } | 632 } |
| OLD | NEW |