From d4f6d8b4a4847ccba1cf452e05847ac712099bd9 Mon Sep 17 00:00:00 2001 From: wutao Date: Mon, 6 May 2019 17:33:33 +0000 Subject: [PATCH] assistant: Check window property for AX tree We need to check window property first before uploading the AX tree. Bug: 959471 Test: manual Change-Id: I14ee0f1d5da34b06944b3113ab7a537fc05b39c9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1594286 Reviewed-by: Xiyuan Xia Reviewed-by: Xiaohui Chen Commit-Queue: Tao Wu Cr-Commit-Position: refs/heads/master@{#656850} --- .../ui/ash/assistant/assistant_context_util.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/chrome/browser/ui/ash/assistant/assistant_context_util.cc b/chrome/browser/ui/ash/assistant/assistant_context_util.cc index 7258f452f35e7b..16f396ef216330 100644 --- a/chrome/browser/ui/ash/assistant/assistant_context_util.cc +++ b/chrome/browser/ui/ash/assistant/assistant_context_util.cc @@ -6,6 +6,7 @@ #include +#include "ash/public/cpp/window_properties.h" #include "base/bind.h" #include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/ui/browser.h" @@ -62,9 +63,6 @@ void RequestAssistantStructureForActiveBrowserWindow( return; } - content::WebContents* web_contents = - browser->tab_strip_model()->GetActiveWebContents(); - // Only returns context from the profile with assistant, which is primary // profile. if (!chromeos::ProfileHelper::IsPrimaryProfile(browser->profile())) { @@ -72,18 +70,26 @@ void RequestAssistantStructureForActiveBrowserWindow( return; } + aura::Window* window = browser->window()->GetNativeWindow(); + // Ignore incognito window. + if (window->GetProperty(ash::kBlockedForAssistantSnapshotKey)) { + std::move(callback).Run(nullptr, nullptr); + return; + } + // We follow same convention as Clank and thus the contents are all in // pixels. The bounds of the window need to be converted to pixel in order // to be consistent with rest of the view hierarchy. gfx::Rect bounds = browser->window()->GetBounds(); gfx::Point top_left = bounds.origin(); gfx::Point bottom_right = bounds.bottom_right(); - auto* window_tree_host = - browser->window()->GetNativeWindow()->GetRootWindow()->GetHost(); + auto* window_tree_host = window->GetRootWindow()->GetHost(); // TODO: Revisit once multi-monitor support is planned. window_tree_host->ConvertDIPToScreenInPixels(&top_left); window_tree_host->ConvertDIPToScreenInPixels(&bottom_right); + content::WebContents* web_contents = + browser->tab_strip_model()->GetActiveWebContents(); web_contents->RequestAXTreeSnapshot( base::BindOnce( &CreateAssistantStructureAndRunCallback, std::move(callback),