| 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/website_settings/permissions_bubble_view.h" | 5 #include "chrome/browser/ui/views/website_settings/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" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "chrome/browser/permissions/permission_request.h" | 12 #include "chrome/browser/permissions/permission_request.h" |
| 13 #include "chrome/browser/platform_util.h" | 13 #include "chrome/browser/platform_util.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 index_, permission.setting == CONTENT_SETTING_ALLOW); | 139 index_, permission.setting == CONTENT_SETTING_ALLOW); |
| 140 } | 140 } |
| 141 | 141 |
| 142 /////////////////////////////////////////////////////////////////////////////// | 142 /////////////////////////////////////////////////////////////////////////////// |
| 143 // View implementation for the permissions bubble. | 143 // View implementation for the permissions bubble. |
| 144 class PermissionsBubbleDialogDelegateView | 144 class PermissionsBubbleDialogDelegateView |
| 145 : public views::BubbleDialogDelegateView, | 145 : public views::BubbleDialogDelegateView, |
| 146 public PermissionCombobox::Listener { | 146 public PermissionCombobox::Listener { |
| 147 public: | 147 public: |
| 148 PermissionsBubbleDialogDelegateView( | 148 PermissionsBubbleDialogDelegateView( |
| 149 PermissionBubbleViewViews* owner, | 149 PermissionPromptImpl* owner, |
| 150 const std::vector<PermissionRequest*>& requests, | 150 const std::vector<PermissionRequest*>& requests, |
| 151 const std::vector<bool>& accept_state); | 151 const std::vector<bool>& accept_state); |
| 152 ~PermissionsBubbleDialogDelegateView() override; | 152 ~PermissionsBubbleDialogDelegateView() override; |
| 153 | 153 |
| 154 void CloseBubble(); | 154 void CloseBubble(); |
| 155 void SizeToContents(); | 155 void SizeToContents(); |
| 156 | 156 |
| 157 // BubbleDialogDelegateView: | 157 // BubbleDialogDelegateView: |
| 158 bool ShouldShowCloseButton() const override; | 158 bool ShouldShowCloseButton() const override; |
| 159 const gfx::FontList& GetTitleFontList() const override; | 159 const gfx::FontList& GetTitleFontList() const override; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 170 // PermissionCombobox::Listener: | 170 // PermissionCombobox::Listener: |
| 171 void PermissionSelectionChanged(int index, bool allowed) override; | 171 void PermissionSelectionChanged(int index, bool allowed) override; |
| 172 | 172 |
| 173 // Updates the anchor's arrow and view. Also repositions the bubble so it's | 173 // Updates the anchor's arrow and view. Also repositions the bubble so it's |
| 174 // displayed in the correct location. | 174 // displayed in the correct location. |
| 175 void UpdateAnchor(views::View* anchor_view, | 175 void UpdateAnchor(views::View* anchor_view, |
| 176 const gfx::Point& anchor_point, | 176 const gfx::Point& anchor_point, |
| 177 views::BubbleBorder::Arrow anchor_arrow); | 177 views::BubbleBorder::Arrow anchor_arrow); |
| 178 | 178 |
| 179 private: | 179 private: |
| 180 PermissionBubbleViewViews* owner_; | 180 PermissionPromptImpl* owner_; |
| 181 bool multiple_requests_; | 181 bool multiple_requests_; |
| 182 base::string16 display_origin_; | 182 base::string16 display_origin_; |
| 183 std::unique_ptr<PermissionMenuModel> menu_button_model_; | 183 std::unique_ptr<PermissionMenuModel> menu_button_model_; |
| 184 std::vector<PermissionCombobox*> customize_comboboxes_; | 184 std::vector<PermissionCombobox*> customize_comboboxes_; |
| 185 | 185 |
| 186 DISALLOW_COPY_AND_ASSIGN(PermissionsBubbleDialogDelegateView); | 186 DISALLOW_COPY_AND_ASSIGN(PermissionsBubbleDialogDelegateView); |
| 187 }; | 187 }; |
| 188 | 188 |
| 189 PermissionsBubbleDialogDelegateView::PermissionsBubbleDialogDelegateView( | 189 PermissionsBubbleDialogDelegateView::PermissionsBubbleDialogDelegateView( |
| 190 PermissionBubbleViewViews* owner, | 190 PermissionPromptImpl* owner, |
| 191 const std::vector<PermissionRequest*>& requests, | 191 const std::vector<PermissionRequest*>& requests, |
| 192 const std::vector<bool>& accept_state) | 192 const std::vector<bool>& accept_state) |
| 193 : owner_(owner), | 193 : owner_(owner), |
| 194 multiple_requests_(requests.size() > 1) { | 194 multiple_requests_(requests.size() > 1) { |
| 195 DCHECK(!requests.empty()); | 195 DCHECK(!requests.empty()); |
| 196 | 196 |
| 197 set_close_on_deactivate(false); | 197 set_close_on_deactivate(false); |
| 198 | 198 |
| 199 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, | 199 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, |
| 200 kItemMajorSpacing)); | 200 kItemMajorSpacing)); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 frame->SetBubbleBorder(std::unique_ptr<views::BubbleBorder>( | 360 frame->SetBubbleBorder(std::unique_ptr<views::BubbleBorder>( |
| 361 new views::BubbleBorder(adjusted_arrow, shadow(), color()))); | 361 new views::BubbleBorder(adjusted_arrow, shadow(), color()))); |
| 362 | 362 |
| 363 // Reposition the bubble based on the updated arrow and view. | 363 // Reposition the bubble based on the updated arrow and view. |
| 364 SetAnchorView(anchor_view); | 364 SetAnchorView(anchor_view); |
| 365 // The anchor rect is ignored unless |anchor_view| is nullptr. | 365 // The anchor rect is ignored unless |anchor_view| is nullptr. |
| 366 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); | 366 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); |
| 367 } | 367 } |
| 368 | 368 |
| 369 ////////////////////////////////////////////////////////////////////////////// | 369 ////////////////////////////////////////////////////////////////////////////// |
| 370 // PermissionBubbleViewViews | 370 // PermissionPromptImpl |
| 371 | 371 |
| 372 PermissionBubbleViewViews::PermissionBubbleViewViews(Browser* browser) | 372 PermissionPromptImpl::PermissionPromptImpl(Browser* browser) |
| 373 : browser_(browser), | 373 : browser_(browser), |
| 374 delegate_(nullptr), | 374 delegate_(nullptr), |
| 375 bubble_delegate_(nullptr) { | 375 bubble_delegate_(nullptr) { |
| 376 DCHECK(browser); | 376 DCHECK(browser); |
| 377 DCHECK(browser->window()); | 377 DCHECK(browser->window()); |
| 378 } | 378 } |
| 379 | 379 |
| 380 PermissionBubbleViewViews::~PermissionBubbleViewViews() { | 380 PermissionPromptImpl::~PermissionPromptImpl() { |
| 381 } | 381 } |
| 382 | 382 |
| 383 void PermissionBubbleViewViews::SetDelegate(Delegate* delegate) { | 383 void PermissionPromptImpl::SetDelegate(Delegate* delegate) { |
| 384 delegate_ = delegate; | 384 delegate_ = delegate; |
| 385 } | 385 } |
| 386 | 386 |
| 387 void PermissionBubbleViewViews::Show( | 387 void PermissionPromptImpl::Show(const std::vector<PermissionRequest*>& requests, |
| 388 const std::vector<PermissionRequest*>& requests, | 388 const std::vector<bool>& values) { |
| 389 const std::vector<bool>& values) { | |
| 390 if (bubble_delegate_) | 389 if (bubble_delegate_) |
| 391 bubble_delegate_->CloseBubble(); | 390 bubble_delegate_->CloseBubble(); |
| 392 | 391 |
| 393 bubble_delegate_ = new PermissionsBubbleDialogDelegateView( | 392 bubble_delegate_ = |
| 394 this, requests, values); | 393 new PermissionsBubbleDialogDelegateView(this, requests, values); |
| 395 | 394 |
| 396 // Set |parent_window| because some valid anchors can become hidden. | 395 // Set |parent_window| because some valid anchors can become hidden. |
| 397 bubble_delegate_->set_parent_window( | 396 bubble_delegate_->set_parent_window( |
| 398 platform_util::GetViewForWindow(browser_->window()->GetNativeWindow())); | 397 platform_util::GetViewForWindow(browser_->window()->GetNativeWindow())); |
| 399 | 398 |
| 400 views::BubbleDialogDelegateView::CreateBubble(bubble_delegate_)->Show(); | 399 views::BubbleDialogDelegateView::CreateBubble(bubble_delegate_)->Show(); |
| 401 bubble_delegate_->SizeToContents(); | 400 bubble_delegate_->SizeToContents(); |
| 402 | 401 |
| 403 bubble_delegate_->UpdateAnchor(GetAnchorView(), | 402 bubble_delegate_->UpdateAnchor(GetAnchorView(), |
| 404 GetAnchorPoint(), | 403 GetAnchorPoint(), |
| 405 GetAnchorArrow()); | 404 GetAnchorArrow()); |
| 406 } | 405 } |
| 407 | 406 |
| 408 bool PermissionBubbleViewViews::CanAcceptRequestUpdate() { | 407 bool PermissionPromptImpl::CanAcceptRequestUpdate() { |
| 409 return !(bubble_delegate_ && bubble_delegate_->IsMouseHovered()); | 408 return !(bubble_delegate_ && bubble_delegate_->IsMouseHovered()); |
| 410 } | 409 } |
| 411 | 410 |
| 412 void PermissionBubbleViewViews::Hide() { | 411 void PermissionPromptImpl::Hide() { |
| 413 if (bubble_delegate_) { | 412 if (bubble_delegate_) { |
| 414 bubble_delegate_->CloseBubble(); | 413 bubble_delegate_->CloseBubble(); |
| 415 bubble_delegate_ = nullptr; | 414 bubble_delegate_ = nullptr; |
| 416 } | 415 } |
| 417 } | 416 } |
| 418 | 417 |
| 419 bool PermissionBubbleViewViews::IsVisible() { | 418 bool PermissionPromptImpl::IsVisible() { |
| 420 return bubble_delegate_ != nullptr; | 419 return bubble_delegate_ != nullptr; |
| 421 } | 420 } |
| 422 | 421 |
| 423 void PermissionBubbleViewViews::UpdateAnchorPosition() { | 422 void PermissionPromptImpl::UpdateAnchorPosition() { |
| 424 if (IsVisible()) { | 423 if (IsVisible()) { |
| 425 bubble_delegate_->set_parent_window( | 424 bubble_delegate_->set_parent_window( |
| 426 platform_util::GetViewForWindow(browser_->window()->GetNativeWindow())); | 425 platform_util::GetViewForWindow(browser_->window()->GetNativeWindow())); |
| 427 bubble_delegate_->UpdateAnchor(GetAnchorView(), | 426 bubble_delegate_->UpdateAnchor(GetAnchorView(), |
| 428 GetAnchorPoint(), | 427 GetAnchorPoint(), |
| 429 GetAnchorArrow()); | 428 GetAnchorArrow()); |
| 430 } | 429 } |
| 431 } | 430 } |
| 432 | 431 |
| 433 gfx::NativeWindow PermissionBubbleViewViews::GetNativeWindow() { | 432 gfx::NativeWindow PermissionPromptImpl::GetNativeWindow() { |
| 434 if (bubble_delegate_ && bubble_delegate_->GetWidget()) | 433 if (bubble_delegate_ && bubble_delegate_->GetWidget()) |
| 435 return bubble_delegate_->GetWidget()->GetNativeWindow(); | 434 return bubble_delegate_->GetWidget()->GetNativeWindow(); |
| 436 return nullptr; | 435 return nullptr; |
| 437 } | 436 } |
| 438 | 437 |
| 439 void PermissionBubbleViewViews::Closing() { | 438 void PermissionPromptImpl::Closing() { |
| 440 if (bubble_delegate_) | 439 if (bubble_delegate_) |
| 441 bubble_delegate_ = nullptr; | 440 bubble_delegate_ = nullptr; |
| 442 if (delegate_) | 441 if (delegate_) |
| 443 delegate_->Closing(); | 442 delegate_->Closing(); |
| 444 } | 443 } |
| 445 | 444 |
| 446 void PermissionBubbleViewViews::Toggle(int index, bool value) { | 445 void PermissionPromptImpl::Toggle(int index, bool value) { |
| 447 if (delegate_) | 446 if (delegate_) |
| 448 delegate_->ToggleAccept(index, value); | 447 delegate_->ToggleAccept(index, value); |
| 449 } | 448 } |
| 450 | 449 |
| 451 void PermissionBubbleViewViews::Accept() { | 450 void PermissionPromptImpl::Accept() { |
| 452 if (delegate_) | 451 if (delegate_) |
| 453 delegate_->Accept(); | 452 delegate_->Accept(); |
| 454 } | 453 } |
| 455 | 454 |
| 456 void PermissionBubbleViewViews::Deny() { | 455 void PermissionPromptImpl::Deny() { |
| 457 if (delegate_) | 456 if (delegate_) |
| 458 delegate_->Deny(); | 457 delegate_->Deny(); |
| 459 } | 458 } |
| OLD | NEW |