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/common/api/clipboard.h" | 13 #include "extensions/browser/extensions_browser_client.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; | |
19 | |
20 static base::LazyInstance<BrowserContextKeyedAPIFactory<ClipboardAPI>> | 18 static base::LazyInstance<BrowserContextKeyedAPIFactory<ClipboardAPI>> |
21 g_factory = LAZY_INSTANCE_INITIALIZER; | 19 g_factory = LAZY_INSTANCE_INITIALIZER; |
22 | 20 |
23 // static | 21 // static |
24 BrowserContextKeyedAPIFactory<ClipboardAPI>* | 22 BrowserContextKeyedAPIFactory<ClipboardAPI>* |
25 ClipboardAPI::GetFactoryInstance() { | 23 ClipboardAPI::GetFactoryInstance() { |
26 return g_factory.Pointer(); | 24 return g_factory.Pointer(); |
27 } | 25 } |
28 | 26 |
29 ClipboardAPI::ClipboardAPI(content::BrowserContext* context) | 27 ClipboardAPI::ClipboardAPI(content::BrowserContext* context) |
(...skipping 10 matching lines...) Expand all Loading... | |
40 if (router && | 38 if (router && |
41 router->HasEventListener(clipboard::OnClipboardDataChanged::kEventName)) { | 39 router->HasEventListener(clipboard::OnClipboardDataChanged::kEventName)) { |
42 std::unique_ptr<Event> event( | 40 std::unique_ptr<Event> event( |
43 new Event(events::CLIPBOARD_ON_CLIPBOARD_DATA_CHANGED, | 41 new Event(events::CLIPBOARD_ON_CLIPBOARD_DATA_CHANGED, |
44 clipboard::OnClipboardDataChanged::kEventName, | 42 clipboard::OnClipboardDataChanged::kEventName, |
45 base::MakeUnique<base::ListValue>())); | 43 base::MakeUnique<base::ListValue>())); |
46 router->BroadcastEvent(std::move(event)); | 44 router->BroadcastEvent(std::move(event)); |
47 } | 45 } |
48 } | 46 } |
49 | 47 |
48 ClipboardSetImageDataFunction::~ClipboardSetImageDataFunction() {} | |
49 | |
50 ExtensionFunction::ResponseAction ClipboardSetImageDataFunction::Run() { | |
51 std::unique_ptr<clipboard::SetImageData::Params> params( | |
52 clipboard::SetImageData::Params::Create(*args_)); | |
53 EXTENSION_FUNCTION_VALIDATE(params); | |
54 SaveImageData(params->image_data, params->type); | |
55 return RespondLater(); | |
56 } | |
57 | |
58 void ClipboardSetImageDataFunction::SaveImageData( | |
59 const std::vector<char>& image_data, | |
60 clipboard::ImageType type) { | |
61 ExtensionsBrowserClient::Get()->SaveImageDataToClipboard( | |
62 image_data, type, | |
63 base::Bind(&ClipboardSetImageDataFunction::OnSaveImageDataSuccess, this), | |
64 base::Bind(&ClipboardSetImageDataFunction::OnSaveImageDataError, this)); | |
65 } | |
66 | |
67 void ClipboardSetImageDataFunction::OnSaveImageDataSuccess() { | |
68 Respond(NoArguments()); | |
69 } | |
70 | |
71 void ClipboardSetImageDataFunction::OnSaveImageDataError() { | |
72 Respond(Error("Failed to save image data on clipboard")); | |
Devlin
2016/12/09 15:23:53
Do we want to indicate why? This isn't a very hel
jennyz
2016/12/14 01:15:36
Changed to accept an error string for detailed err
| |
73 } | |
74 | |
50 } // namespace extensions | 75 } // namespace extensions |
OLD | NEW |