| 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" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 // Only cares about HTML because ChromeOS doesn't need other formats. | 76 // Only cares about HTML because ChromeOS doesn't need other formats. |
| 77 // TODO(dcheng): Why don't we take advantage of the ability to write bitmaps | 77 // TODO(dcheng): Why don't we take advantage of the ability to write bitmaps |
| 78 // to the clipboard here? | 78 // to the clipboard here? |
| 79 { | 79 { |
| 80 ui::ScopedClipboardWriter scw(ui::Clipboard::GetForCurrentThread(), | 80 ui::ScopedClipboardWriter scw(ui::Clipboard::GetForCurrentThread(), |
| 81 ui::CLIPBOARD_TYPE_COPY_PASTE); | 81 ui::CLIPBOARD_TYPE_COPY_PASTE); |
| 82 std::string html(kImageClipboardFormatPrefix); | 82 std::string html(kImageClipboardFormatPrefix); |
| 83 html += encoded; | 83 html += encoded; |
| 84 html += kImageClipboardFormatSuffix; | 84 html += kImageClipboardFormatSuffix; |
| 85 scw.WriteHTML(UTF8ToUTF16(html), std::string()); | 85 scw.WriteHTML(base::UTF8ToUTF16(html), std::string()); |
| 86 } | 86 } |
| 87 content::RecordAction(content::UserMetricsAction("Screenshot_CopyClipboard")); | 87 content::RecordAction(content::UserMetricsAction("Screenshot_CopyClipboard")); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void ReadFileAndCopyToClipboardLocal(const base::FilePath& screenshot_path) { | 90 void ReadFileAndCopyToClipboardLocal(const base::FilePath& screenshot_path) { |
| 91 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 91 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 92 | 92 |
| 93 scoped_refptr<base::RefCountedString> png_data(new base::RefCountedString()); | 93 scoped_refptr<base::RefCountedString> png_data(new base::RefCountedString()); |
| 94 if (!base::ReadFileToString(screenshot_path, &(png_data->data()))) { | 94 if (!base::ReadFileToString(screenshot_path, &(png_data->data()))) { |
| 95 LOG(ERROR) << "Failed to read the screenshot file: " | 95 LOG(ERROR) << "Failed to read the screenshot file: " |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 kScreenshotMinimumIntervalInMS); | 503 kScreenshotMinimumIntervalInMS); |
| 504 } | 504 } |
| 505 | 505 |
| 506 Notification* ScreenshotTaker::CreateNotification( | 506 Notification* ScreenshotTaker::CreateNotification( |
| 507 ScreenshotTakerObserver::Result screenshot_result, | 507 ScreenshotTakerObserver::Result screenshot_result, |
| 508 const base::FilePath& screenshot_path) { | 508 const base::FilePath& screenshot_path) { |
| 509 const std::string notification_id(kNotificationId); | 509 const std::string notification_id(kNotificationId); |
| 510 // We cancel a previous screenshot notification, if any, to ensure we get | 510 // We cancel a previous screenshot notification, if any, to ensure we get |
| 511 // a fresh notification pop-up. | 511 // a fresh notification pop-up. |
| 512 g_browser_process->notification_ui_manager()->CancelById(notification_id); | 512 g_browser_process->notification_ui_manager()->CancelById(notification_id); |
| 513 const base::string16 replace_id(UTF8ToUTF16(notification_id)); | 513 const base::string16 replace_id(base::UTF8ToUTF16(notification_id)); |
| 514 bool success = | 514 bool success = |
| 515 (screenshot_result == ScreenshotTakerObserver::SCREENSHOT_SUCCESS); | 515 (screenshot_result == ScreenshotTakerObserver::SCREENSHOT_SUCCESS); |
| 516 message_center::RichNotificationData optional_field; | 516 message_center::RichNotificationData optional_field; |
| 517 if (success) { | 517 if (success) { |
| 518 const base::string16 label = l10n_util::GetStringUTF16( | 518 const base::string16 label = l10n_util::GetStringUTF16( |
| 519 IDS_MESSAGE_CENTER_NOTIFICATION_BUTTON_COPY_SCREENSHOT_TO_CLIPBOARD); | 519 IDS_MESSAGE_CENTER_NOTIFICATION_BUTTON_COPY_SCREENSHOT_TO_CLIPBOARD); |
| 520 optional_field.buttons.push_back(message_center::ButtonInfo(label)); | 520 optional_field.buttons.push_back(message_center::ButtonInfo(label)); |
| 521 } | 521 } |
| 522 return new Notification( | 522 return new Notification( |
| 523 message_center::NOTIFICATION_TYPE_SIMPLE, | 523 message_center::NOTIFICATION_TYPE_SIMPLE, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 } | 590 } |
| 591 | 591 |
| 592 void ScreenshotTaker::SetScreenshotBasenameForTest( | 592 void ScreenshotTaker::SetScreenshotBasenameForTest( |
| 593 const std::string& basename) { | 593 const std::string& basename) { |
| 594 screenshot_basename_for_test_ = basename; | 594 screenshot_basename_for_test_ = basename; |
| 595 } | 595 } |
| 596 | 596 |
| 597 void ScreenshotTaker::SetScreenshotProfileForTest(Profile* profile) { | 597 void ScreenshotTaker::SetScreenshotProfileForTest(Profile* profile) { |
| 598 profile_for_test_ = profile; | 598 profile_for_test_ = profile; |
| 599 } | 599 } |
| OLD | NEW |