Skip to content

Commit

Permalink
assistant: Check window property for AX tree
Browse files Browse the repository at this point in the history
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 <xiyuan@chromium.org>
Reviewed-by: Xiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: Tao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#656850}
  • Loading branch information
wutao authored and Commit Bot committed May 6, 2019
1 parent ec418ac commit d4f6d8b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions chrome/browser/ui/ash/assistant/assistant_context_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <utility>

#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"
Expand Down Expand Up @@ -62,28 +63,33 @@ 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())) {
std::move(callback).Run(nullptr, nullptr);
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),
Expand Down

0 comments on commit d4f6d8b

Please sign in to comment.