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

Unified Diff: chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_framework_service.cc

Issue 2795693005: Taking screenshot of current focused window. (Closed)
Patch Set: check null for screenshot data Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_framework_service.cc
diff --git a/chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_framework_service.cc b/chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_framework_service.cc
index dd535d9b85a8d69b4a75eed3ae2a007b9c30d361..081b7ca73facb21fe9162f162293196f02af9d82 100644
--- a/chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_framework_service.cc
+++ b/chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_framework_service.cc
@@ -12,13 +12,35 @@
#include "ash/shell.h"
#include "base/command_line.h"
#include "base/logging.h"
+#include "base/memory/ref_counted.h"
+#include "base/task_scheduler/post_task.h"
#include "chromeos/chromeos_switches.h"
#include "components/arc/arc_bridge_service.h"
#include "components/arc/instance_holder.h"
#include "content/public/browser/browser_thread.h"
+#include "ui/aura/window.h"
+#include "ui/snapshot/snapshot.h"
+#include "ui/wm/public/activation_client.h"
namespace arc {
+namespace {
+
+void ScreenshotCallback(
+ const mojom::VoiceInteractionFrameworkHost::CaptureFocusedWindowCallback&
+ callback,
+ scoped_refptr<base::RefCountedMemory> png_data) {
+ if (png_data.get() == nullptr) {
+ callback.Run(std::vector<uint8_t>{});
+ return;
+ }
+ std::vector<uint8_t> result(png_data->front(),
+ png_data->front() + png_data->size());
+ callback.Run(result);
+}
+
+} // namespace
+
// static
bool ArcVoiceInteractionFrameworkService::IsVoiceInteractionEnabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
@@ -72,10 +94,18 @@ bool ArcVoiceInteractionFrameworkService::CanHandleAccelerators() const {
void ArcVoiceInteractionFrameworkService::CaptureFocusedWindow(
const CaptureFocusedWindowCallback& callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- NOTIMPLEMENTED();
- // TODO(muyuanli): The logic below is only there to prevent blocking.
- // details needs to be implemented in the future.
- callback.Run(std::vector<uint8_t>{});
+ aura::Window* window =
+ ash::Shell::GetInstance()->activation_client()->GetActiveWindow();
+
+ if (window == nullptr) {
+ callback.Run(std::vector<uint8_t>{});
+ return;
+ }
+ ui::GrabWindowSnapshotAsyncPNG(window, gfx::Rect(window->bounds().size()),
+ base::CreateTaskRunnerWithTraits(
+ base::TaskTraits().MayBlock().WithPriority(
+ base::TaskPriority::USER_BLOCKING)),
+ base::Bind(&ScreenshotCallback, callback));
}
} // namespace arc
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698