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

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

Issue 2379573008: Add SetImageData api to chrome.clipboard. (Closed)
Patch Set: Fix interactive_ui_tests issue. Created 4 years, 1 month 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/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
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.get());
Devlin 2016/11/16 02:34:33 s/params.get()/params
jennyz 2016/12/07 01:21:48 Done.
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(OneArgument(base::MakeUnique<base::FundamentalValue>(true)));
69 }
70
71 void ClipboardSetImageDataFunction::OnSaveImageDataError() {
72 Respond(OneArgument(base::MakeUnique<base::FundamentalValue>(false)));
Devlin 2016/11/16 02:34:33 Do we want to convey the error to the extension at
jennyz 2016/12/07 01:21:48 Changed to use lastError to convey the error.
73 }
74
50 } // namespace extensions 75 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698