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

Side by Side Diff: extensions/browser/api/clipboard/clipboard_api.cc

Issue 2379573008: Add SetImageData api to chrome.clipboard. (Closed)
Patch Set: Fix nits. Created 3 years, 11 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 (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
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 ExtensionsAPIClient::Get()->SaveImageDataToClipboard(
57 params->image_data, params->type,
58 base::Bind(&ClipboardSetImageDataFunction::OnSaveImageDataSuccess, this),
59 base::Bind(&ClipboardSetImageDataFunction::OnSaveImageDataError, this));
60 return RespondLater();
61 }
62
63 void ClipboardSetImageDataFunction::OnSaveImageDataSuccess() {
64 Respond(NoArguments());
65 }
66
67 void ClipboardSetImageDataFunction::OnSaveImageDataError(
68 const std::string& error) {
69 Respond(Error(error));
70 }
71
50 } // namespace extensions 72 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/clipboard/clipboard_api.h ('k') | extensions/browser/api/extensions_api_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698