| Index: chrome/browser/ui/ash/chrome_screenshot_taker.cc
|
| diff --git a/chrome/browser/ui/ash/screenshot_taker.cc b/chrome/browser/ui/ash/chrome_screenshot_taker.cc
|
| similarity index 53%
|
| rename from chrome/browser/ui/ash/screenshot_taker.cc
|
| rename to chrome/browser/ui/ash/chrome_screenshot_taker.cc
|
| index 108ca8b580a5a3ff652d9edbcc719e30bf4c8963..38d3e35170159c30c53acf78ea29005012f090ca 100644
|
| --- a/chrome/browser/ui/ash/screenshot_taker.cc
|
| +++ b/chrome/browser/ui/ash/chrome_screenshot_taker.cc
|
| @@ -1,26 +1,18 @@
|
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/ui/ash/screenshot_taker.h"
|
| -
|
| -#include <climits>
|
| -#include <string>
|
| +#include "chrome/browser/ui/ash/chrome_screenshot_taker.h"
|
|
|
| #include "ash/shell.h"
|
| -#include "ash/shell_delegate.h"
|
| #include "ash/system/system_notifier.h"
|
| #include "base/base64.h"
|
| #include "base/bind.h"
|
| -#include "base/files/file_util.h"
|
| +#include "base/callback.h"
|
| #include "base/i18n/time_formatting.h"
|
| -#include "base/logging.h"
|
| -#include "base/memory/ref_counted_memory.h"
|
| #include "base/prefs/pref_service.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| -#include "base/threading/sequenced_worker_pool.h"
|
| -#include "base/time/time.h"
|
| #include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/download/download_prefs.h"
|
| #include "chrome/browser/notifications/notification_ui_manager.h"
|
| @@ -31,14 +23,10 @@
|
| #include "content/public/browser/user_metrics.h"
|
| #include "grit/ash_strings.h"
|
| #include "grit/theme_resources.h"
|
| -#include "ui/aura/window.h"
|
| -#include "ui/aura/window_event_dispatcher.h"
|
| #include "ui/base/clipboard/clipboard.h"
|
| #include "ui/base/clipboard/scoped_clipboard_writer.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| #include "ui/base/resource/resource_bundle.h"
|
| -#include "ui/gfx/image/image.h"
|
| -#include "ui/snapshot/snapshot.h"
|
| #include "ui/strings/grit/ui_strings.h"
|
|
|
| #if defined(OS_CHROMEOS)
|
| @@ -51,9 +39,6 @@
|
| #endif
|
|
|
| namespace {
|
| -// The minimum interval between two screenshot commands. It has to be
|
| -// more than 1000 to prevent the conflict of filenames.
|
| -const int kScreenshotMinimumIntervalInMS = 1000;
|
|
|
| const char kNotificationId[] = "screenshot";
|
|
|
| @@ -168,76 +153,45 @@ class ScreenshotTakerNotificationDelegate : public NotificationDelegate {
|
| DISALLOW_COPY_AND_ASSIGN(ScreenshotTakerNotificationDelegate);
|
| };
|
|
|
| -typedef base::Callback<
|
| - void(ScreenshotTakerObserver::Result screenshot_result,
|
| - const base::FilePath& screenshot_path)> ShowNotificationCallback;
|
| -
|
| -void SaveScreenshotInternal(const ShowNotificationCallback& callback,
|
| - const base::FilePath& screenshot_path,
|
| - const base::FilePath& local_path,
|
| - scoped_refptr<base::RefCountedBytes> png_data) {
|
| - DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
|
| - DCHECK(!local_path.empty());
|
| - ScreenshotTakerObserver::Result result =
|
| - ScreenshotTakerObserver::SCREENSHOT_SUCCESS;
|
| - if (static_cast<size_t>(base::WriteFile(
|
| - local_path,
|
| - reinterpret_cast<char*>(&(png_data->data()[0])),
|
| - png_data->size())) != png_data->size()) {
|
| - LOG(ERROR) << "Failed to save to " << local_path.value();
|
| - result = ScreenshotTakerObserver::SCREENSHOT_WRITE_FILE_FAILED;
|
| +#if defined(OS_CHROMEOS)
|
| +int GetScreenshotNotificationTitle(
|
| + ScreenshotTakerObserver::Result screenshot_result) {
|
| + switch (screenshot_result) {
|
| + case ScreenshotTakerObserver::SCREENSHOTS_DISABLED:
|
| + return IDS_ASH_SCREENSHOT_NOTIFICATION_TITLE_DISABLED;
|
| + case ScreenshotTakerObserver::SCREENSHOT_SUCCESS:
|
| + return IDS_ASH_SCREENSHOT_NOTIFICATION_TITLE_SUCCESS;
|
| + default:
|
| + return IDS_ASH_SCREENSHOT_NOTIFICATION_TITLE_FAIL;
|
| }
|
| - content::BrowserThread::PostTask(
|
| - content::BrowserThread::UI, FROM_HERE,
|
| - base::Bind(callback, result, screenshot_path));
|
| }
|
|
|
| -void SaveScreenshot(const ShowNotificationCallback& callback,
|
| - const base::FilePath& screenshot_path,
|
| - scoped_refptr<base::RefCountedBytes> png_data) {
|
| - DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
|
| - DCHECK(!screenshot_path.empty());
|
| -
|
| - if (!base::CreateDirectory(screenshot_path.DirName())) {
|
| - LOG(ERROR) << "Failed to ensure the existence of "
|
| - << screenshot_path.DirName().value();
|
| - content::BrowserThread::PostTask(
|
| - content::BrowserThread::UI, FROM_HERE,
|
| - base::Bind(callback,
|
| - ScreenshotTakerObserver::SCREENSHOT_CREATE_DIR_FAILED,
|
| - screenshot_path));
|
| - return;
|
| +int GetScreenshotNotificationText(
|
| + ScreenshotTakerObserver::Result screenshot_result) {
|
| + switch (screenshot_result) {
|
| + case ScreenshotTakerObserver::SCREENSHOTS_DISABLED:
|
| + return IDS_ASH_SCREENSHOT_NOTIFICATION_TEXT_DISABLED;
|
| + case ScreenshotTakerObserver::SCREENSHOT_SUCCESS:
|
| + return IDS_ASH_SCREENSHOT_NOTIFICATION_TEXT_SUCCESS;
|
| + default:
|
| + return IDS_ASH_SCREENSHOT_NOTIFICATION_TEXT_FAIL;
|
| }
|
| - SaveScreenshotInternal(callback, screenshot_path, screenshot_path, png_data);
|
| }
|
|
|
| -// TODO(kinaba): crbug.com/140425, remove this ungly #ifdef dispatch.
|
| -#if defined(OS_CHROMEOS)
|
| -void SaveScreenshotToDrive(const ShowNotificationCallback& callback,
|
| - const base::FilePath& screenshot_path,
|
| - scoped_refptr<base::RefCountedBytes> png_data,
|
| - drive::FileError error,
|
| - const base::FilePath& local_path) {
|
| - // |screenshot_path| is used in the notification callback.
|
| - // |local_path| is a temporary file in a hidden cache directory used for
|
| - // internal work generated by drive::util::PrepareWritableFileAndRun.
|
| - if (error != drive::FILE_ERROR_OK) {
|
| - LOG(ERROR) << "Failed to write screenshot image to Google Drive: " << error;
|
| - content::BrowserThread::PostTask(
|
| - content::BrowserThread::UI, FROM_HERE,
|
| - base::Bind(callback,
|
| - ScreenshotTakerObserver::SCREENSHOT_CREATE_FILE_FAILED,
|
| - screenshot_path));
|
| - return;
|
| - }
|
| - SaveScreenshotInternal(callback, screenshot_path, local_path, png_data);
|
| +void PrepareWritableFileCallback(
|
| + const ChromeScreenshotTaker::WritableFileCallback& callback,
|
| + drive::FileError error,
|
| + const base::FilePath& local_path) {
|
| + callback.Run(error == drive::FILE_ERROR_OK ?
|
| + ScreenshotTakerClient::WRITABLE_FILE_SUCCESS :
|
| + ScreenshotTakerClient::WRITABLE_FILE_CREATE_FAILED,
|
| + local_path);
|
| }
|
|
|
| void EnsureDirectoryExistsCallback(
|
| - const ShowNotificationCallback& callback,
|
| + const ChromeScreenshotTaker::WritableFileCallback& callback,
|
| Profile* profile,
|
| - const base::FilePath& screenshot_path,
|
| - scoped_refptr<base::RefCountedBytes> png_data,
|
| + const base::FilePath& path,
|
| drive::FileError error) {
|
| // It is okay to fail with FILE_ERROR_EXISTS since anyway the directory
|
| // of the target file exists.
|
| @@ -245,53 +199,26 @@ void EnsureDirectoryExistsCallback(
|
| error == drive::FILE_ERROR_EXISTS) {
|
| drive::util::PrepareWritableFileAndRun(
|
| profile,
|
| - screenshot_path,
|
| - base::Bind(&SaveScreenshotToDrive,
|
| - callback,
|
| - screenshot_path,
|
| - png_data));
|
| + path,
|
| + base::Bind(&PrepareWritableFileCallback,
|
| + callback));
|
| } else {
|
| LOG(ERROR) << "Failed to ensure the existence of the specified directory "
|
| << "in Google Drive: " << error;
|
| - callback.Run(ScreenshotTakerObserver::SCREENSHOT_CHECK_DIR_FAILED,
|
| - screenshot_path);
|
| - }
|
| -}
|
| -
|
| -void PostSaveScreenshotTask(const ShowNotificationCallback& callback,
|
| - Profile* profile,
|
| - const base::FilePath& screenshot_path,
|
| - scoped_refptr<base::RefCountedBytes> png_data) {
|
| - if (drive::util::IsUnderDriveMountPoint(screenshot_path)) {
|
| - drive::util::EnsureDirectoryExists(
|
| - profile,
|
| - screenshot_path.DirName(),
|
| - base::Bind(&EnsureDirectoryExistsCallback,
|
| - callback,
|
| - profile,
|
| - screenshot_path,
|
| - png_data));
|
| - } else {
|
| content::BrowserThread::GetBlockingPool()->PostTask(
|
| - FROM_HERE, base::Bind(&SaveScreenshot,
|
| - callback,
|
| - screenshot_path,
|
| - png_data));
|
| + FROM_HERE, base::Bind(
|
| + callback,
|
| + ScreenshotTakerClient::WRITABLE_FILE_CHECK_DIR_FAILED,
|
| + base::FilePath()));
|
| }
|
| }
|
| -#else
|
| -void PostSaveScreenshotTask(const ShowNotificationCallback& callback,
|
| - Profile* profile,
|
| - const base::FilePath& screenshot_path,
|
| - scoped_refptr<base::RefCountedBytes> png_data) {
|
| - content::BrowserThread::GetBlockingPool()->PostTask(
|
| - FROM_HERE, base::Bind(&SaveScreenshot,
|
| - callback,
|
| - screenshot_path,
|
| - png_data));
|
| -}
|
| #endif
|
|
|
| +bool ScreenshotsDisabled() {
|
| + return g_browser_process->local_state()->
|
| + GetBoolean(prefs::kDisableScreenshots);
|
| +}
|
| +
|
| bool ShouldUse24HourClock() {
|
| #if defined(OS_CHROMEOS)
|
| Profile* profile = ProfileManager::GetActiveUserProfile();
|
| @@ -302,6 +229,26 @@ bool ShouldUse24HourClock() {
|
| return base::GetHourClockType() == base::k24HourClock;
|
| }
|
|
|
| +bool GetScreenshotDirectory(base::FilePath* directory) {
|
| + bool is_logged_in = true;
|
| +
|
| +#if defined(OS_CHROMEOS)
|
| + is_logged_in = chromeos::LoginState::Get()->IsUserLoggedIn();
|
| +#endif
|
| +
|
| + if (is_logged_in) {
|
| + DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext(
|
| + ProfileManager::GetActiveUserProfile());
|
| + *directory = download_prefs->DownloadPath();
|
| + } else {
|
| + if (!base::GetTempDir(directory)) {
|
| + LOG(ERROR) << "Failed to find temporary directory.";
|
| + return false;
|
| + }
|
| + }
|
| + return true;
|
| +}
|
| +
|
| std::string GetScreenshotBaseFilename() {
|
| base::Time::Exploded now;
|
| base::Time::Now().LocalExplode(&now);
|
| @@ -331,80 +278,29 @@ std::string GetScreenshotBaseFilename() {
|
| return file_name;
|
| }
|
|
|
| -bool GetScreenshotDirectory(base::FilePath* directory) {
|
| - bool is_logged_in = true;
|
| -
|
| -#if defined(OS_CHROMEOS)
|
| - is_logged_in = chromeos::LoginState::Get()->IsUserLoggedIn();
|
| -#endif
|
| -
|
| - if (is_logged_in) {
|
| - DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext(
|
| - ProfileManager::GetActiveUserProfile());
|
| - *directory = download_prefs->DownloadPath();
|
| - } else {
|
| - if (!base::GetTempDir(directory)) {
|
| - LOG(ERROR) << "Failed to find temporary directory.";
|
| - return false;
|
| - }
|
| - }
|
| - return true;
|
| -}
|
| -
|
| -#if defined(OS_CHROMEOS)
|
| -int GetScreenshotNotificationTitle(
|
| - ScreenshotTakerObserver::Result screenshot_result) {
|
| - switch (screenshot_result) {
|
| - case ScreenshotTakerObserver::SCREENSHOTS_DISABLED:
|
| - return IDS_ASH_SCREENSHOT_NOTIFICATION_TITLE_DISABLED;
|
| - case ScreenshotTakerObserver::SCREENSHOT_SUCCESS:
|
| - return IDS_ASH_SCREENSHOT_NOTIFICATION_TITLE_SUCCESS;
|
| - default:
|
| - return IDS_ASH_SCREENSHOT_NOTIFICATION_TITLE_FAIL;
|
| - }
|
| -}
|
| -
|
| -int GetScreenshotNotificationText(
|
| - ScreenshotTakerObserver::Result screenshot_result) {
|
| - switch (screenshot_result) {
|
| - case ScreenshotTakerObserver::SCREENSHOTS_DISABLED:
|
| - return IDS_ASH_SCREENSHOT_NOTIFICATION_TEXT_DISABLED;
|
| - case ScreenshotTakerObserver::SCREENSHOT_SUCCESS:
|
| - return IDS_ASH_SCREENSHOT_NOTIFICATION_TEXT_SUCCESS;
|
| - default:
|
| - return IDS_ASH_SCREENSHOT_NOTIFICATION_TEXT_FAIL;
|
| - }
|
| -}
|
| -#endif
|
| -
|
| } // namespace
|
|
|
| -ScreenshotTaker::ScreenshotTaker()
|
| - : profile_for_test_(NULL),
|
| - factory_(this) {
|
| +ChromeScreenshotTaker::ChromeScreenshotTaker()
|
| + : screenshot_taker_(new ScreenshotTaker(this)) {
|
| + screenshot_taker_->AddObserver(this);
|
| }
|
|
|
| -ScreenshotTaker::~ScreenshotTaker() {
|
| +ChromeScreenshotTaker::~ChromeScreenshotTaker() {
|
| + screenshot_taker_->RemoveObserver(this);
|
| }
|
|
|
| -void ScreenshotTaker::HandleTakeScreenshotForAllRootWindows() {
|
| - if (g_browser_process->local_state()->
|
| - GetBoolean(prefs::kDisableScreenshots)) {
|
| - ShowNotification(ScreenshotTakerObserver::SCREENSHOTS_DISABLED,
|
| - base::FilePath());
|
| +void ChromeScreenshotTaker::HandleTakeScreenshotForAllRootWindows() {
|
| + if (ScreenshotsDisabled())
|
| return;
|
| - }
|
| +
|
| base::FilePath screenshot_directory;
|
| - if (!screenshot_directory_for_test_.empty()) {
|
| - screenshot_directory = screenshot_directory_for_test_;
|
| - } else if (!GetScreenshotDirectory(&screenshot_directory)) {
|
| - ShowNotification(ScreenshotTakerObserver::SCREENSHOT_GET_DIR_FAILED,
|
| - base::FilePath());
|
| + if (!GetScreenshotDirectory(&screenshot_directory)) {
|
| + OnScreenshotCompleted(ScreenshotTakerObserver::SCREENSHOT_GET_DIR_FAILED,
|
| + base::FilePath());
|
| return;
|
| }
|
| - std::string screenshot_basename = !screenshot_basename_for_test_.empty() ?
|
| - screenshot_basename_for_test_ : GetScreenshotBaseFilename();
|
|
|
| + std::string screenshot_basename = GetScreenshotBaseFilename();
|
| aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows();
|
| // Reorder root_windows to take the primary root window's snapshot at first.
|
| aura::Window* primary_root = ash::Shell::GetPrimaryRootWindow();
|
| @@ -413,6 +309,7 @@ void ScreenshotTaker::HandleTakeScreenshotForAllRootWindows() {
|
| root_windows.begin(), root_windows.end(), primary_root));
|
| root_windows.insert(root_windows.begin(), primary_root);
|
| }
|
| + std::vector<base::FilePath> filenames;
|
| for (size_t i = 0; i < root_windows.size(); ++i) {
|
| aura::Window* root_window = root_windows[i];
|
| std::string basename = screenshot_basename;
|
| @@ -421,55 +318,90 @@ void ScreenshotTaker::HandleTakeScreenshotForAllRootWindows() {
|
| basename += base::StringPrintf(" - Display %d", static_cast<int>(i + 1));
|
| base::FilePath screenshot_path =
|
| screenshot_directory.AppendASCII(basename + ".png");
|
| - GrabFullWindowSnapshotAsync(
|
| - root_window, rect, GetProfile(), screenshot_path, i);
|
| + screenshot_taker_->TakeScreenshot(root_window,
|
| + rect,
|
| + screenshot_path);
|
| }
|
| content::RecordAction(base::UserMetricsAction("Screenshot_TakeFull"));
|
| }
|
|
|
| -void ScreenshotTaker::HandleTakePartialScreenshot(
|
| - aura::Window* window, const gfx::Rect& rect) {
|
| - if (g_browser_process->local_state()->
|
| - GetBoolean(prefs::kDisableScreenshots)) {
|
| - ShowNotification(ScreenshotTakerObserver::SCREENSHOTS_DISABLED,
|
| - base::FilePath());
|
| +void ChromeScreenshotTaker::HandleTakePartialScreenshot(
|
| + aura::Window* window,
|
| + const gfx::Rect& rect) {
|
| + if (ScreenshotsDisabled())
|
| return;
|
| - }
|
| - DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
|
|
| base::FilePath screenshot_directory;
|
| - if (!screenshot_directory_for_test_.empty()) {
|
| - screenshot_directory = screenshot_directory_for_test_;
|
| - } else if (!GetScreenshotDirectory(&screenshot_directory)) {
|
| - ShowNotification(ScreenshotTakerObserver::SCREENSHOT_GET_DIR_FAILED,
|
| - base::FilePath());
|
| + if (!GetScreenshotDirectory(&screenshot_directory)) {
|
| + OnScreenshotCompleted(ScreenshotTakerObserver::SCREENSHOT_GET_DIR_FAILED,
|
| + base::FilePath());
|
| return;
|
| }
|
|
|
| - std::string screenshot_basename = !screenshot_basename_for_test_.empty() ?
|
| - screenshot_basename_for_test_ : GetScreenshotBaseFilename();
|
| base::FilePath screenshot_path =
|
| - screenshot_directory.AppendASCII(screenshot_basename + ".png");
|
| - GrabPartialWindowSnapshotAsync(window, rect, GetProfile(), screenshot_path);
|
| + screenshot_directory.AppendASCII(GetScreenshotBaseFilename() + ".png");
|
| + screenshot_taker_->TakeScreenshot(window, rect, screenshot_path);
|
| content::RecordAction(base::UserMetricsAction("Screenshot_TakePartial"));
|
| }
|
|
|
| -bool ScreenshotTaker::CanTakeScreenshot() {
|
| - return last_screenshot_timestamp_.is_null() ||
|
| - base::Time::Now() - last_screenshot_timestamp_ >
|
| - base::TimeDelta::FromMilliseconds(
|
| - kScreenshotMinimumIntervalInMS);
|
| +bool ChromeScreenshotTaker::CanTakeScreenshot() {
|
| + return screenshot_taker_->CanTakeScreenshot();
|
| +}
|
| +
|
| +void ChromeScreenshotTaker::PrepareWritableFileAndRunOnBlockingPool(
|
| + const base::FilePath& path,
|
| + WritableFileCallback callback) {
|
| +#if defined(OS_CHROMEOS)
|
| + Profile* profile = ProfileManager::GetActiveUserProfile();
|
| + if (drive::util::IsUnderDriveMountPoint(path)) {
|
| + drive::util::EnsureDirectoryExists(
|
| + profile,
|
| + path.DirName(),
|
| + base::Bind(&EnsureDirectoryExistsCallback,
|
| + callback,
|
| + profile,
|
| + path));
|
| + return;
|
| + }
|
| +#endif
|
| + ScreenshotTakerClient::PrepareWritableFileAndRunOnBlockingPool(
|
| + path, callback);
|
| +}
|
| +
|
| +void ChromeScreenshotTaker::OnScreenshotCompleted(
|
| + ScreenshotTakerObserver::Result result,
|
| + const base::FilePath& screenshot_path) {
|
| +#if defined(OS_CHROMEOS)
|
| + // Do not show a notification that a screenshot was taken while no user is
|
| + // logged in, since it is confusing for the user to get a message about it
|
| + // after he logs in (crbug.com/235217).
|
| + if (!chromeos::LoginState::Get()->IsUserLoggedIn())
|
| + return;
|
| +
|
| + // TODO(sschmitz): make this work for Windows.
|
| + Profile* profile = ProfileManager::GetActiveUserProfile();
|
| + DesktopNotificationService* const service =
|
| + DesktopNotificationServiceFactory::GetForProfile(profile);
|
| + if (service->IsNotifierEnabled(message_center::NotifierId(
|
| + message_center::NotifierId::SYSTEM_COMPONENT,
|
| + ash::system_notifier::kNotifierScreenshot))) {
|
| + scoped_ptr<Notification> notification(
|
| + CreateNotification(result, screenshot_path));
|
| + g_browser_process->notification_ui_manager()->Add(*notification, profile);
|
| + }
|
| +#endif
|
| }
|
|
|
| #if defined(OS_CHROMEOS)
|
| -Notification* ScreenshotTaker::CreateNotification(
|
| +Notification* ChromeScreenshotTaker::CreateNotification(
|
| ScreenshotTakerObserver::Result screenshot_result,
|
| const base::FilePath& screenshot_path) {
|
| const std::string notification_id(kNotificationId);
|
| // We cancel a previous screenshot notification, if any, to ensure we get
|
| // a fresh notification pop-up.
|
| + Profile* profile = ProfileManager::GetActiveUserProfile();
|
| g_browser_process->notification_ui_manager()->CancelById(
|
| - notification_id, NotificationUIManager::GetProfileID(GetProfile()));
|
| + notification_id, NotificationUIManager::GetProfileID(profile));
|
| const base::string16 replace_id(base::UTF8ToUTF16(notification_id));
|
| bool success =
|
| (screenshot_result == ScreenshotTakerObserver::SCREENSHOT_SUCCESS);
|
| @@ -496,133 +428,6 @@ Notification* ScreenshotTaker::CreateNotification(
|
| replace_id,
|
| optional_field,
|
| new ScreenshotTakerNotificationDelegate(
|
| - success, GetProfile(), screenshot_path));
|
| + success, profile, screenshot_path));
|
| }
|
| #endif
|
| -
|
| -void ScreenshotTaker::ShowNotification(
|
| - ScreenshotTakerObserver::Result screenshot_result,
|
| - const base::FilePath& screenshot_path) {
|
| - DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| -#if defined(OS_CHROMEOS)
|
| - // Do not show a notification that a screenshot was taken while no user is
|
| - // logged in, since it is confusing for the user to get a message about it
|
| - // after he logs in (crbug.com/235217).
|
| - if (!chromeos::LoginState::Get()->IsUserLoggedIn())
|
| - return;
|
| -
|
| - // TODO(sschmitz): make this work for Windows.
|
| - DesktopNotificationService* const service =
|
| - DesktopNotificationServiceFactory::GetForProfile(GetProfile());
|
| - if (service->IsNotifierEnabled(message_center::NotifierId(
|
| - message_center::NotifierId::SYSTEM_COMPONENT,
|
| - ash::system_notifier::kNotifierScreenshot))) {
|
| - scoped_ptr<Notification> notification(
|
| - CreateNotification(screenshot_result, screenshot_path));
|
| - g_browser_process->notification_ui_manager()->Add(*notification,
|
| - GetProfile());
|
| - }
|
| -#endif
|
| - FOR_EACH_OBSERVER(ScreenshotTakerObserver, observers_,
|
| - OnScreenshotCompleted(screenshot_result, screenshot_path));
|
| -}
|
| -
|
| -void ScreenshotTaker::AddObserver(ScreenshotTakerObserver* observer) {
|
| - observers_.AddObserver(observer);
|
| -}
|
| -
|
| -void ScreenshotTaker::RemoveObserver(ScreenshotTakerObserver* observer) {
|
| - observers_.RemoveObserver(observer);
|
| -}
|
| -
|
| -bool ScreenshotTaker::HasObserver(
|
| - const ScreenshotTakerObserver* observer) const {
|
| - return observers_.HasObserver(observer);
|
| -}
|
| -
|
| -void ScreenshotTaker::GrabWindowSnapshotAsyncCallback(
|
| - base::FilePath screenshot_path,
|
| - bool is_partial,
|
| - int window_idx,
|
| - scoped_refptr<base::RefCountedBytes> png_data) {
|
| - if (!png_data.get()) {
|
| - if (is_partial) {
|
| - LOG(ERROR) << "Failed to grab the window screenshot";
|
| - ShowNotification(
|
| - ScreenshotTakerObserver::SCREENSHOT_GRABWINDOW_PARTIAL_FAILED,
|
| - screenshot_path);
|
| - } else {
|
| - LOG(ERROR) << "Failed to grab the window screenshot for " << window_idx;
|
| - ShowNotification(
|
| - ScreenshotTakerObserver::SCREENSHOT_GRABWINDOW_FULL_FAILED,
|
| - screenshot_path);
|
| - }
|
| - return;
|
| - }
|
| -
|
| - PostSaveScreenshotTask(
|
| - base::Bind(&ScreenshotTaker::ShowNotification, factory_.GetWeakPtr()),
|
| - GetProfile(),
|
| - screenshot_path,
|
| - png_data);
|
| -}
|
| -
|
| -void ScreenshotTaker::GrabPartialWindowSnapshotAsync(
|
| - aura::Window* window,
|
| - const gfx::Rect& snapshot_bounds,
|
| - Profile* profile,
|
| - base::FilePath screenshot_path) {
|
| - last_screenshot_timestamp_ = base::Time::Now();
|
| -
|
| - bool is_partial = true;
|
| - int window_idx = -1; // unused
|
| - ui::GrabWindowSnapshotAsync(
|
| - window,
|
| - snapshot_bounds,
|
| - content::BrowserThread::GetBlockingPool(),
|
| - base::Bind(&ScreenshotTaker::GrabWindowSnapshotAsyncCallback,
|
| - factory_.GetWeakPtr(),
|
| - screenshot_path,
|
| - is_partial,
|
| - window_idx));
|
| -}
|
| -
|
| -void ScreenshotTaker::GrabFullWindowSnapshotAsync(
|
| - aura::Window* window,
|
| - const gfx::Rect& snapshot_bounds,
|
| - Profile* profile,
|
| - base::FilePath screenshot_path,
|
| - int window_idx) {
|
| - last_screenshot_timestamp_ = base::Time::Now();
|
| -
|
| - bool is_partial = false;
|
| - ui::GrabWindowSnapshotAsync(
|
| - window,
|
| - snapshot_bounds,
|
| - content::BrowserThread::GetBlockingPool(),
|
| - base::Bind(&ScreenshotTaker::GrabWindowSnapshotAsyncCallback,
|
| - factory_.GetWeakPtr(),
|
| - screenshot_path,
|
| - is_partial,
|
| - window_idx));
|
| -}
|
| -
|
| -Profile* ScreenshotTaker::GetProfile() {
|
| - if (profile_for_test_)
|
| - return profile_for_test_;
|
| - return ProfileManager::GetActiveUserProfile();
|
| -}
|
| -
|
| -void ScreenshotTaker::SetScreenshotDirectoryForTest(
|
| - const base::FilePath& directory) {
|
| - screenshot_directory_for_test_ = directory;
|
| -}
|
| -
|
| -void ScreenshotTaker::SetScreenshotBasenameForTest(
|
| - const std::string& basename) {
|
| - screenshot_basename_for_test_ = basename;
|
| -}
|
| -
|
| -void ScreenshotTaker::SetScreenshotProfileForTest(Profile* profile) {
|
| - profile_for_test_ = profile;
|
| -}
|
|
|