Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "extensions/browser/api/clipboard/clipboard_api.h" | 5 #include "extensions/browser/api/clipboard/clipboard_api.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "extensions/browser/event_router.h" | 12 #include "extensions/browser/event_router.h" |
| 13 #include "extensions/browser/extensions_browser_client.h" | |
| 13 #include "extensions/common/api/clipboard.h" | 14 #include "extensions/common/api/clipboard.h" |
| 14 #include "ui/base/clipboard/clipboard_monitor.h" | 15 #include "ui/base/clipboard/clipboard_monitor.h" |
| 15 | 16 |
| 16 namespace extensions { | 17 namespace extensions { |
| 17 | 18 |
| 18 namespace clipboard = api::clipboard; | 19 namespace clipboard = api::clipboard; |
| 19 | 20 |
| 20 static base::LazyInstance<BrowserContextKeyedAPIFactory<ClipboardAPI>> | 21 static base::LazyInstance<BrowserContextKeyedAPIFactory<ClipboardAPI>> |
| 21 g_factory = LAZY_INSTANCE_INITIALIZER; | 22 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 22 | 23 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 40 if (router && | 41 if (router && |
| 41 router->HasEventListener(clipboard::OnClipboardDataChanged::kEventName)) { | 42 router->HasEventListener(clipboard::OnClipboardDataChanged::kEventName)) { |
| 42 std::unique_ptr<Event> event( | 43 std::unique_ptr<Event> event( |
| 43 new Event(events::CLIPBOARD_ON_CLIPBOARD_DATA_CHANGED, | 44 new Event(events::CLIPBOARD_ON_CLIPBOARD_DATA_CHANGED, |
| 44 clipboard::OnClipboardDataChanged::kEventName, | 45 clipboard::OnClipboardDataChanged::kEventName, |
| 45 base::MakeUnique<base::ListValue>())); | 46 base::MakeUnique<base::ListValue>())); |
| 46 router->BroadcastEvent(std::move(event)); | 47 router->BroadcastEvent(std::move(event)); |
| 47 } | 48 } |
| 48 } | 49 } |
| 49 | 50 |
| 51 ClipboardSetImageDataFunction::~ClipboardSetImageDataFunction() {} | |
| 52 | |
| 53 ExtensionFunction::ResponseAction ClipboardSetImageDataFunction::Run() { | |
| 54 std::unique_ptr<clipboard::SetImageData::Params> params( | |
| 55 clipboard::SetImageData::Params::Create(*args_)); | |
| 56 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 57 SaveImageData(params->image_data, params->type); | |
| 58 return RespondLater(); | |
| 59 } | |
| 60 | |
| 61 void ClipboardSetImageDataFunction::SaveImageData( | |
| 62 const std::vector<char>& image_data, | |
| 63 const std::string& type) { | |
| 64 ExtensionsBrowserClient::Get()->SaveImageDataToClipboard( | |
|
dcheng
2016/10/04 05:13:27
I might be missing something, but can the Extensio
jennyz
2016/10/04 23:53:54
The image decoding code we used is under chrome/br
| |
| 65 image_data, type, | |
| 66 base::Bind(&ClipboardSetImageDataFunction::OnSaveImageDataSuccess, this), | |
| 67 base::Bind(&ClipboardSetImageDataFunction::OnSaveImageDataError, this)); | |
| 68 } | |
| 69 | |
| 70 void ClipboardSetImageDataFunction::OnSaveImageDataSuccess() { | |
| 71 Respond(OneArgument(base::MakeUnique<base::FundamentalValue>(true))); | |
| 72 } | |
| 73 | |
| 74 void ClipboardSetImageDataFunction::OnSaveImageDataError() { | |
| 75 Respond(OneArgument(base::MakeUnique<base::FundamentalValue>(false))); | |
| 76 } | |
| 77 | |
| 50 } // namespace extensions | 78 } // namespace extensions |
| OLD | NEW |