Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / ui / exclusive_access / exclusive_access_bubble.cc
blob5d9f554eec880e5b3584878a3d46513e6ef81156
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/exclusive_access/exclusive_access_bubble.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h"
11 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
12 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "extensions/browser/extension_registry.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/gfx/geometry/rect.h"
17 #include "ui/strings/grit/ui_strings.h"
19 // NOTE(koz): Linux doesn't use the thick shadowed border, so we add padding
20 // here.
21 #if defined(OS_LINUX)
22 const int ExclusiveAccessBubble::kPaddingPx = 8;
23 #else
24 const int ExclusiveAccessBubble::kPaddingPx = 15;
25 #endif
26 const int ExclusiveAccessBubble::kInitialDelayMs = 3800;
27 const int ExclusiveAccessBubble::kIdleTimeMs = 2300;
28 const int ExclusiveAccessBubble::kPositionCheckHz = 10;
29 const int ExclusiveAccessBubble::kSlideInRegionHeightPx = 4;
30 const int ExclusiveAccessBubble::kSlideInDurationMs = 350;
31 const int ExclusiveAccessBubble::kSlideOutDurationMs = 700;
32 const int ExclusiveAccessBubble::kPopupTopPx = 15;
34 ExclusiveAccessBubble::ExclusiveAccessBubble(
35 ExclusiveAccessManager* manager,
36 const GURL& url,
37 ExclusiveAccessBubbleType bubble_type)
38 : manager_(manager), url_(url), bubble_type_(bubble_type) {
39 DCHECK_NE(EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE, bubble_type_);
42 ExclusiveAccessBubble::~ExclusiveAccessBubble() {
45 void ExclusiveAccessBubble::StartWatchingMouse() {
46 // Start the initial delay timer and begin watching the mouse.
47 initial_delay_.Start(FROM_HERE,
48 base::TimeDelta::FromMilliseconds(kInitialDelayMs), this,
49 &ExclusiveAccessBubble::CheckMousePosition);
50 gfx::Point cursor_pos = GetCursorScreenPoint();
51 last_mouse_pos_ = cursor_pos;
52 mouse_position_checker_.Start(
53 FROM_HERE, base::TimeDelta::FromMilliseconds(1000 / kPositionCheckHz),
54 this, &ExclusiveAccessBubble::CheckMousePosition);
57 void ExclusiveAccessBubble::StopWatchingMouse() {
58 initial_delay_.Stop();
59 idle_timeout_.Stop();
60 mouse_position_checker_.Stop();
63 bool ExclusiveAccessBubble::IsWatchingMouse() const {
64 return mouse_position_checker_.IsRunning();
67 void ExclusiveAccessBubble::CheckMousePosition() {
68 // Desired behavior:
70 // +------------+-----------------------------+------------+
71 // | _ _ _ _ | Exit full screen mode (F11) | _ _ _ _ | Slide-in region
72 // | _ _ _ _ \_____________________________/ _ _ _ _ | Neutral region
73 // | | Slide-out region
74 // : :
76 // * If app is not active, we hide the popup.
77 // * If the mouse is offscreen or in the slide-out region, we hide the popup.
78 // * If the mouse goes idle, we hide the popup.
79 // * If the mouse is in the slide-in-region and not idle, we show the popup.
80 // * If the mouse is in the neutral region and not idle, and the popup is
81 // currently sliding out, we show it again. This facilitates users
82 // correcting us if they try to mouse horizontally towards the popup and
83 // unintentionally drop too low.
84 // * Otherwise, we do nothing, because the mouse is in the neutral region and
85 // either the popup is hidden or the mouse is not idle, so we don't want to
86 // change anything's state.
88 gfx::Point cursor_pos = GetCursorScreenPoint();
90 // Check to see whether the mouse is idle.
91 if (cursor_pos != last_mouse_pos_) {
92 // The mouse moved; reset the idle timer.
93 idle_timeout_.Stop(); // If the timer isn't running, this is a no-op.
94 idle_timeout_.Start(FROM_HERE,
95 base::TimeDelta::FromMilliseconds(kIdleTimeMs), this,
96 &ExclusiveAccessBubble::CheckMousePosition);
98 last_mouse_pos_ = cursor_pos;
100 if (!IsWindowActive() || !WindowContainsPoint(cursor_pos) ||
101 (cursor_pos.y() >= GetPopupRect(true).bottom()) ||
102 !idle_timeout_.IsRunning()) {
103 // The cursor is offscreen, in the slide-out region, or idle.
104 if (!initial_delay_.IsRunning()) {
105 Hide();
107 } else if (cursor_pos.y() < kSlideInRegionHeightPx &&
108 CanMouseTriggerSlideIn()) {
109 Show();
110 } else if (IsAnimating()) {
111 // The cursor is not idle and either it's in the slide-in region or it's in
112 // the neutral region and we're sliding in or out.
113 Show();
117 void ExclusiveAccessBubble::ExitExclusiveAccess() {
118 manager_->ExitExclusiveAccess();
121 void ExclusiveAccessBubble::Accept() {
122 manager_->OnAcceptExclusiveAccessPermission();
125 void ExclusiveAccessBubble::Cancel() {
126 manager_->OnDenyExclusiveAccessPermission();
129 base::string16 ExclusiveAccessBubble::GetCurrentMessageText() const {
130 return exclusive_access_bubble::GetLabelTextForType(
131 bubble_type_, url_,
132 extensions::ExtensionRegistry::Get(manager_->context()->GetProfile()));
135 base::string16 ExclusiveAccessBubble::GetCurrentDenyButtonText() const {
136 return exclusive_access_bubble::GetDenyButtonTextForType(bubble_type_);
139 base::string16 ExclusiveAccessBubble::GetCurrentAllowButtonText() const {
140 return exclusive_access_bubble::GetAllowButtonTextForType(bubble_type_, url_);
143 base::string16 ExclusiveAccessBubble::GetInstructionText() const {
144 return l10n_util::GetStringFUTF16(IDS_FULLSCREEN_PRESS_ESC_TO_EXIT,
145 l10n_util::GetStringUTF16(IDS_APP_ESC_KEY));