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/api/extensions_api_client.h" |
12 #include "extensions/browser/event_router.h" | 13 #include "extensions/browser/event_router.h" |
13 #include "extensions/common/api/clipboard.h" | |
14 #include "ui/base/clipboard/clipboard_monitor.h" | 14 #include "ui/base/clipboard/clipboard_monitor.h" |
15 | 15 |
16 namespace extensions { | 16 namespace extensions { |
17 | 17 |
18 namespace clipboard = api::clipboard; | 18 namespace clipboard = api::clipboard; |
19 | 19 |
20 static base::LazyInstance<BrowserContextKeyedAPIFactory<ClipboardAPI>> | 20 static base::LazyInstance<BrowserContextKeyedAPIFactory<ClipboardAPI>> |
21 g_factory = LAZY_INSTANCE_INITIALIZER; | 21 g_factory = LAZY_INSTANCE_INITIALIZER; |
22 | 22 |
23 // static | 23 // static |
(...skipping 16 matching lines...) Expand all Loading... |
40 if (router && | 40 if (router && |
41 router->HasEventListener(clipboard::OnClipboardDataChanged::kEventName)) { | 41 router->HasEventListener(clipboard::OnClipboardDataChanged::kEventName)) { |
42 std::unique_ptr<Event> event( | 42 std::unique_ptr<Event> event( |
43 new Event(events::CLIPBOARD_ON_CLIPBOARD_DATA_CHANGED, | 43 new Event(events::CLIPBOARD_ON_CLIPBOARD_DATA_CHANGED, |
44 clipboard::OnClipboardDataChanged::kEventName, | 44 clipboard::OnClipboardDataChanged::kEventName, |
45 base::MakeUnique<base::ListValue>())); | 45 base::MakeUnique<base::ListValue>())); |
46 router->BroadcastEvent(std::move(event)); | 46 router->BroadcastEvent(std::move(event)); |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
| 50 ClipboardSetImageDataFunction::~ClipboardSetImageDataFunction() {} |
| 51 |
| 52 ExtensionFunction::ResponseAction ClipboardSetImageDataFunction::Run() { |
| 53 std::unique_ptr<clipboard::SetImageData::Params> params( |
| 54 clipboard::SetImageData::Params::Create(*args_)); |
| 55 EXTENSION_FUNCTION_VALIDATE(params); |
| 56 SaveImageData(params->image_data, params->type); |
| 57 return RespondLater(); |
| 58 } |
| 59 |
| 60 void ClipboardSetImageDataFunction::SaveImageData( |
| 61 const std::vector<char>& image_data, |
| 62 clipboard::ImageType type) { |
| 63 ExtensionsAPIClient::Get()->SaveImageDataToClipboard( |
| 64 image_data, type, |
| 65 base::Bind(&ClipboardSetImageDataFunction::OnSaveImageDataSuccess, this), |
| 66 base::Bind(&ClipboardSetImageDataFunction::OnSaveImageDataError, this)); |
| 67 } |
| 68 |
| 69 void ClipboardSetImageDataFunction::OnSaveImageDataSuccess() { |
| 70 Respond(NoArguments()); |
| 71 } |
| 72 |
| 73 void ClipboardSetImageDataFunction::OnSaveImageDataError( |
| 74 const std::string& error) { |
| 75 Respond(Error(error)); |
| 76 } |
| 77 |
50 } // namespace extensions | 78 } // namespace extensions |
OLD | NEW |