OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/views/permission_bubble/permission_prompt_impl.h" | 5 #include "chrome/browser/ui/views/permission_bubble/permission_prompt_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 | 400 |
401 void PermissionPromptImpl::SetDelegate(Delegate* delegate) { | 401 void PermissionPromptImpl::SetDelegate(Delegate* delegate) { |
402 delegate_ = delegate; | 402 delegate_ = delegate; |
403 } | 403 } |
404 | 404 |
405 void PermissionPromptImpl::Show(const std::vector<PermissionRequest*>& requests, | 405 void PermissionPromptImpl::Show(const std::vector<PermissionRequest*>& requests, |
406 const std::vector<bool>& values) { | 406 const std::vector<bool>& values) { |
407 DCHECK(browser_); | 407 DCHECK(browser_); |
408 DCHECK(browser_->window()); | 408 DCHECK(browser_->window()); |
409 | 409 |
410 if (bubble_delegate_) | 410 if (IsVisible()) { |
411 bubble_delegate_->CloseBubble(); | 411 // We just rejected a MaybeCancelRequest() call. |
| 412 return; |
| 413 } |
412 | 414 |
413 bubble_delegate_ = | 415 bubble_delegate_ = |
414 new PermissionsBubbleDialogDelegateView(this, requests, values); | 416 new PermissionsBubbleDialogDelegateView(this, requests, values); |
415 | 417 |
416 // Set |parent_window| because some valid anchors can become hidden. | 418 // Set |parent_window| because some valid anchors can become hidden. |
417 bubble_delegate_->set_parent_window( | 419 bubble_delegate_->set_parent_window( |
418 platform_util::GetViewForWindow(browser_->window()->GetNativeWindow())); | 420 platform_util::GetViewForWindow(browser_->window()->GetNativeWindow())); |
419 | 421 |
420 // Compensate for vertical padding in the anchor view's image. Note this is | 422 // Compensate for vertical padding in the anchor view's image. Note this is |
421 // ignored whenever the anchor view is null. | 423 // ignored whenever the anchor view is null. |
422 bubble_delegate_->set_anchor_view_insets(gfx::Insets( | 424 bubble_delegate_->set_anchor_view_insets(gfx::Insets( |
423 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); | 425 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); |
424 | 426 |
425 views::BubbleDialogDelegateView::CreateBubble(bubble_delegate_)->Show(); | 427 views::BubbleDialogDelegateView::CreateBubble(bubble_delegate_)->Show(); |
426 bubble_delegate_->SizeToContents(); | 428 bubble_delegate_->SizeToContents(); |
427 | 429 |
428 bubble_delegate_->UpdateAnchor(GetAnchorView(), | 430 bubble_delegate_->UpdateAnchor(GetAnchorView(), |
429 GetAnchorPoint(), | 431 GetAnchorPoint(), |
430 GetAnchorArrow()); | 432 GetAnchorArrow()); |
431 } | 433 } |
432 | 434 |
433 bool PermissionPromptImpl::CanAcceptRequestUpdate() { | 435 bool PermissionPromptImpl::MaybeCancelRequest() { |
434 return !(bubble_delegate_ && bubble_delegate_->IsMouseHovered()); | 436 if (bubble_delegate_->IsMouseHovered()) |
| 437 return false; |
| 438 Hide(); |
| 439 return true; |
435 } | 440 } |
436 | 441 |
437 bool PermissionPromptImpl::HidesAutomatically() { | 442 bool PermissionPromptImpl::HidesAutomatically() { |
438 return false; | 443 return false; |
439 } | 444 } |
440 | 445 |
441 void PermissionPromptImpl::Hide() { | 446 void PermissionPromptImpl::Hide() { |
442 if (bubble_delegate_) { | 447 if (bubble_delegate_) { |
443 bubble_delegate_->CloseBubble(); | 448 bubble_delegate_->CloseBubble(); |
444 bubble_delegate_ = nullptr; | 449 bubble_delegate_ = nullptr; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 } | 496 } |
492 | 497 |
493 void PermissionPromptImpl::Deny() { | 498 void PermissionPromptImpl::Deny() { |
494 if (delegate_) | 499 if (delegate_) |
495 delegate_->Deny(); | 500 delegate_->Deny(); |
496 } | 501 } |
497 | 502 |
498 Profile* PermissionPromptImpl::GetProfile() { | 503 Profile* PermissionPromptImpl::GetProfile() { |
499 return browser_->profile(); | 504 return browser_->profile(); |
500 } | 505 } |
OLD | NEW |