| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_fr
amework_service.h" | 5 #include "chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_fr
amework_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/accelerators/accelerator_controller.h" | 10 #include "ash/accelerators/accelerator_controller.h" |
| 11 #include "ash/public/cpp/shell_window_ids.h" | 11 #include "ash/public/cpp/shell_window_ids.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/containers/flat_set.h" | 15 #include "base/containers/flat_set.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/task_scheduler/post_task.h" | 18 #include "base/task_scheduler/post_task.h" |
| 19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_list.h" | 20 #include "chrome/browser/ui/browser_list.h" |
| 21 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
| 22 #include "chromeos/chromeos_switches.h" | 22 #include "chromeos/chromeos_switches.h" |
| 23 #include "components/arc/arc_bridge_service.h" | 23 #include "components/arc/arc_bridge_service.h" |
| 24 #include "components/arc/instance_holder.h" | 24 #include "components/arc/instance_holder.h" |
| 25 #include "components/exo/surface.h" |
| 25 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 27 #include "ui/aura/client/aura_constants.h" |
| 26 #include "ui/aura/window.h" | 28 #include "ui/aura/window.h" |
| 27 #include "ui/compositor/layer.h" | 29 #include "ui/compositor/layer.h" |
| 28 #include "ui/compositor/layer_owner.h" | 30 #include "ui/compositor/layer_owner.h" |
| 29 #include "ui/compositor/layer_tree_owner.h" | 31 #include "ui/compositor/layer_tree_owner.h" |
| 30 #include "ui/gfx/image/image.h" | 32 #include "ui/gfx/image/image.h" |
| 31 #include "ui/gfx/image/image_util.h" | 33 #include "ui/gfx/image/image_util.h" |
| 32 #include "ui/gfx/native_widget_types.h" | 34 #include "ui/gfx/native_widget_types.h" |
| 33 #include "ui/snapshot/snapshot.h" | 35 #include "ui/snapshot/snapshot.h" |
| 34 #include "ui/snapshot/snapshot_aura.h" | 36 #include "ui/snapshot/snapshot_aura.h" |
| 35 #include "ui/wm/core/window_util.h" | 37 #include "ui/wm/core/window_util.h" |
| 36 #include "ui/wm/public/activation_client.h" | 38 #include "ui/wm/public/activation_client.h" |
| 37 | 39 |
| 38 namespace arc { | 40 namespace arc { |
| 39 | 41 |
| 40 namespace { | 42 namespace { |
| 41 | 43 |
| 44 using LayerSet = base::flat_set<const ui::Layer*>; |
| 45 |
| 42 void ScreenshotCallback( | 46 void ScreenshotCallback( |
| 43 const mojom::VoiceInteractionFrameworkHost::CaptureFocusedWindowCallback& | 47 const mojom::VoiceInteractionFrameworkHost::CaptureFocusedWindowCallback& |
| 44 callback, | 48 callback, |
| 45 scoped_refptr<base::RefCountedMemory> data) { | 49 scoped_refptr<base::RefCountedMemory> data) { |
| 46 if (data.get() == nullptr) { | 50 if (data.get() == nullptr) { |
| 47 callback.Run(std::vector<uint8_t>{}); | 51 callback.Run(std::vector<uint8_t>{}); |
| 48 return; | 52 return; |
| 49 } | 53 } |
| 50 std::vector<uint8_t> result(data->front(), data->front() + data->size()); | 54 std::vector<uint8_t> result(data->front(), data->front() + data->size()); |
| 51 callback.Run(result); | 55 callback.Run(result); |
| 52 } | 56 } |
| 53 | 57 |
| 58 bool IsMetalayerWindow(aura::Window* window) { |
| 59 exo::Surface* surface = exo::Surface::AsSurface(window); |
| 60 return surface != nullptr && surface->IsStylusOnly(); |
| 61 } |
| 62 |
| 63 void CollectLayers(LayerSet& layers, |
| 64 aura::Window* root_window, |
| 65 base::Callback<bool(aura::Window*)> matcher_func) { |
| 66 if (matcher_func.Run(root_window)) |
| 67 layers.insert(root_window->layer()); |
| 68 |
| 69 aura::Window::Windows children = root_window->children(); |
| 70 for (aura::Window::Windows::iterator iter = children.begin(); |
| 71 iter != children.end(); ++iter) { |
| 72 CollectLayers(layers, *iter, matcher_func); |
| 73 } |
| 74 } |
| 75 |
| 54 std::unique_ptr<ui::LayerTreeOwner> CreateLayerTreeForSnapshot( | 76 std::unique_ptr<ui::LayerTreeOwner> CreateLayerTreeForSnapshot( |
| 55 aura::Window* root_window) { | 77 aura::Window* root_window) { |
| 56 using LayerSet = base::flat_set<const ui::Layer*>; | |
| 57 LayerSet blocked_layers; | 78 LayerSet blocked_layers; |
| 58 for (auto* browser : *BrowserList::GetInstance()) { | 79 for (auto* browser : *BrowserList::GetInstance()) { |
| 59 if (browser->profile()->IsOffTheRecord()) | 80 if (browser->profile()->IsOffTheRecord()) |
| 60 blocked_layers.insert(browser->window()->GetNativeWindow()->layer()); | 81 blocked_layers.insert(browser->window()->GetNativeWindow()->layer()); |
| 61 } | 82 } |
| 62 | 83 |
| 63 LayerSet excluded_layers; | 84 LayerSet excluded_layers; |
| 64 // For the best UX the metalayer has to be excluded from the snapshot. | 85 CollectLayers(excluded_layers, root_window, base::Bind(IsMetalayerWindow)); |
| 65 // It is currently impossible to identify the metalayer among others layers | |
| 66 // under kShellWindowId_SystemModalContainer. Other layers in this container | |
| 67 // are not relevant for this kind of snapshot, so it is safe to exclude all | |
| 68 // of them. | |
| 69 aura::Window* modal_container = ash::Shell::GetContainer( | |
| 70 root_window, ash::kShellWindowId_SystemModalContainer); | |
| 71 if (modal_container != nullptr) | |
| 72 excluded_layers.insert(modal_container->layer()); | |
| 73 | 86 |
| 74 auto layer_tree_owner = ::wm::RecreateLayersWithClosure( | 87 auto layer_tree_owner = ::wm::RecreateLayersWithClosure( |
| 75 root_window, base::BindRepeating( | 88 root_window, base::BindRepeating( |
| 76 [](LayerSet blocked_layers, LayerSet excluded_layers, | 89 [](LayerSet blocked_layers, LayerSet excluded_layers, |
| 77 ui::LayerOwner* owner) -> std::unique_ptr<ui::Layer> { | 90 ui::LayerOwner* owner) -> std::unique_ptr<ui::Layer> { |
| 78 // Parent layer is excluded meaning that it's pointless | 91 // Parent layer is excluded meaning that it's pointless |
| 79 // to clone current child and all its descendants. This | 92 // to clone current child and all its descendants. This |
| 80 // reduces the number of layers to create. | 93 // reduces the number of layers to create. |
| 81 if (blocked_layers.count(owner->layer()->parent())) | 94 if (blocked_layers.count(owner->layer()->parent())) |
| 82 return nullptr; | 95 return nullptr; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 SetMetalayerVisibility); | 289 SetMetalayerVisibility); |
| 277 if (!framework_instance) { | 290 if (!framework_instance) { |
| 278 if (!metalayer_closed_callback_.is_null()) | 291 if (!metalayer_closed_callback_.is_null()) |
| 279 base::ResetAndReturn(&metalayer_closed_callback_).Run(); | 292 base::ResetAndReturn(&metalayer_closed_callback_).Run(); |
| 280 return; | 293 return; |
| 281 } | 294 } |
| 282 framework_instance->SetMetalayerVisibility(visible); | 295 framework_instance->SetMetalayerVisibility(visible); |
| 283 } | 296 } |
| 284 | 297 |
| 285 } // namespace arc | 298 } // namespace arc |
| OLD | NEW |