Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: chrome/browser/extensions/clipboard_extension_helper_chromeos.cc

Issue 2837983002: Modify SetImageData to add additional items along with image data to save on clipboard. (Closed)
Patch Set: Make additional data items parameter optional and address other comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/extensions/clipboard_extension_helper_chromeos.h" 5 #include "chrome/browser/extensions/clipboard_extension_helper_chromeos.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h"
10 #include "base/synchronization/cancellation_flag.h" 12 #include "base/synchronization/cancellation_flag.h"
11 #include "chrome/browser/image_decoder.h" 13 #include "chrome/browser/image_decoder.h"
12 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
13 #include "ui/base/clipboard/scoped_clipboard_writer.h" 15 #include "ui/base/clipboard/scoped_clipboard_writer.h"
14 16
15 using content::BrowserThread; 17 using content::BrowserThread;
16 18
17 namespace extensions { 19 namespace extensions {
18 20
19 namespace clipboard = api::clipboard; 21 namespace clipboard = api::clipboard;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 76
75 ClipboardExtensionHelper::ClipboardExtensionHelper() { 77 ClipboardExtensionHelper::ClipboardExtensionHelper() {
76 clipboard_image_data_decoder_.reset(new ClipboardImageDataDecoder(this)); 78 clipboard_image_data_decoder_.reset(new ClipboardImageDataDecoder(this));
77 } 79 }
78 80
79 ClipboardExtensionHelper::~ClipboardExtensionHelper() {} 81 ClipboardExtensionHelper::~ClipboardExtensionHelper() {}
80 82
81 void ClipboardExtensionHelper::DecodeAndSaveImageData( 83 void ClipboardExtensionHelper::DecodeAndSaveImageData(
82 const std::vector<char>& data, 84 const std::vector<char>& data,
83 clipboard::ImageType type, 85 clipboard::ImageType type,
86 std::unique_ptr<AdditionalDataItemList> additional_items,
84 const base::Closure& success_callback, 87 const base::Closure& success_callback,
85 const base::Callback<void(const std::string&)>& error_callback) { 88 const base::Callback<void(const std::string&)>& error_callback) {
86 DCHECK_CURRENTLY_ON(BrowserThread::UI); 89 DCHECK_CURRENTLY_ON(BrowserThread::UI);
87 90
88 // If there is a previous image decoding request still running, cancel it 91 // If there is a previous image decoding request still running, cancel it
89 // first. We only need the most recent image save request be completed, since 92 // first. We only need the most recent image save request be completed, since
90 // the clipboard will only store data set by the most recent request, which 93 // the clipboard will only store data set by the most recent request, which
91 // is consistent with the clipboard "paste" behavior. 94 // is consistent with the clipboard "paste" behavior.
92 if (clipboard_image_data_decoder_->has_request_pending()) 95 if (clipboard_image_data_decoder_->has_request_pending())
93 clipboard_image_data_decoder_->Cancel(); 96 clipboard_image_data_decoder_->Cancel();
94 97
98 // Cache additonal items if they are available.
99 if (additional_items) {
100 additonal_items_.clear();
101 for (const clipboard::AdditionalDataItem& item : *additional_items) {
102 clipboard::AdditionalDataItem data_item;
103 data_item.type = item.type;
104 data_item.data = item.data;
105 additonal_items_.push_back(std::move(data_item));
Devlin 2017/05/17 16:08:43 If we're just going to move all of these anyway, w
jennyz 2017/05/18 23:33:48 Done.
106 }
107 }
108
95 image_save_success_callback_ = success_callback; 109 image_save_success_callback_ = success_callback;
96 image_save_error_callback_ = error_callback; 110 image_save_error_callback_ = error_callback;
97 clipboard_image_data_decoder_->Start(data, type); 111 clipboard_image_data_decoder_->Start(data, type);
98 } 112 }
99 113
100 void ClipboardExtensionHelper::OnImageDecodeFailure() { 114 void ClipboardExtensionHelper::OnImageDecodeFailure() {
101 base::ResetAndReturn(&image_save_error_callback_) 115 base::ResetAndReturn(&image_save_error_callback_)
102 .Run("Image data decoding failed"); 116 .Run("Image data decoding failed.");
103 } 117 }
104 118
105 void ClipboardExtensionHelper::OnImageDecoded(const SkBitmap& bitmap) { 119 void ClipboardExtensionHelper::OnImageDecoded(const SkBitmap& bitmap) {
106 { 120 {
107 ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE); 121 ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE);
108 // Write the decoded image data to clipboard. 122 // Write the decoded image data to clipboard.
109 if (!bitmap.empty() && !bitmap.isNull()) 123 if (!bitmap.empty() && !bitmap.isNull())
110 scw.WriteImage(bitmap); 124 scw.WriteImage(bitmap);
125
126 for (const clipboard::AdditionalDataItem& item : additonal_items_) {
127 if (item.type == clipboard::DATA_ITEM_TYPE_TEXT_PLAIN)
128 scw.WriteText(base::UTF8ToUTF16(item.data));
129 else if (item.type == clipboard::DATA_ITEM_TYPE_TEXT_HTML)
130 scw.WriteHTML(base::UTF8ToUTF16(item.data), std::string());
131 }
111 } 132 }
112 base::ResetAndReturn(&image_save_success_callback_).Run(); 133 base::ResetAndReturn(&image_save_success_callback_).Run();
113 } 134 }
114 135
115 void ClipboardExtensionHelper::OnImageDecodeCancel() { 136 void ClipboardExtensionHelper::OnImageDecodeCancel() {
116 base::ResetAndReturn(&image_save_error_callback_).Run("Request canceled"); 137 base::ResetAndReturn(&image_save_error_callback_).Run("Request canceled.");
117 } 138 }
118 139
119 } // namespace extensions 140 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698