Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: chrome/browser/ui/views/website_settings/permission_prompt_impl.cc

Issue 2182883002: Permissions: Rename PermissionBubbleView to PermissionPromptInterface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Further renames Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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(
388 const std::vector<PermissionRequest*>& requests, 388 const std::vector<PermissionRequest*>& requests,
389 const std::vector<bool>& values) { 389 const std::vector<bool>& values) {
390 if (bubble_delegate_) 390 if (bubble_delegate_)
391 bubble_delegate_->CloseBubble(); 391 bubble_delegate_->CloseBubble();
392 392
393 bubble_delegate_ = new PermissionsBubbleDialogDelegateView( 393 bubble_delegate_ = new PermissionsBubbleDialogDelegateView(
394 this, requests, values); 394 this, requests, values);
395 395
396 // Set |parent_window| because some valid anchors can become hidden. 396 // Set |parent_window| because some valid anchors can become hidden.
397 bubble_delegate_->set_parent_window( 397 bubble_delegate_->set_parent_window(
398 platform_util::GetViewForWindow(browser_->window()->GetNativeWindow())); 398 platform_util::GetViewForWindow(browser_->window()->GetNativeWindow()));
399 399
400 views::BubbleDialogDelegateView::CreateBubble(bubble_delegate_)->Show(); 400 views::BubbleDialogDelegateView::CreateBubble(bubble_delegate_)->Show();
401 bubble_delegate_->SizeToContents(); 401 bubble_delegate_->SizeToContents();
402 402
403 bubble_delegate_->UpdateAnchor(GetAnchorView(), 403 bubble_delegate_->UpdateAnchor(GetAnchorView(),
404 GetAnchorPoint(), 404 GetAnchorPoint(),
405 GetAnchorArrow()); 405 GetAnchorArrow());
406 } 406 }
407 407
408 bool PermissionBubbleViewViews::CanAcceptRequestUpdate() { 408 bool PermissionPromptImpl::CanAcceptRequestUpdate() {
409 return !(bubble_delegate_ && bubble_delegate_->IsMouseHovered()); 409 return !(bubble_delegate_ && bubble_delegate_->IsMouseHovered());
410 } 410 }
411 411
412 void PermissionBubbleViewViews::Hide() { 412 void PermissionPromptImpl::Hide() {
413 if (bubble_delegate_) { 413 if (bubble_delegate_) {
414 bubble_delegate_->CloseBubble(); 414 bubble_delegate_->CloseBubble();
415 bubble_delegate_ = nullptr; 415 bubble_delegate_ = nullptr;
416 } 416 }
417 } 417 }
418 418
419 bool PermissionBubbleViewViews::IsVisible() { 419 bool PermissionPromptImpl::IsVisible() {
420 return bubble_delegate_ != nullptr; 420 return bubble_delegate_ != nullptr;
421 } 421 }
422 422
423 void PermissionBubbleViewViews::UpdateAnchorPosition() { 423 void PermissionPromptImpl::UpdateAnchorPosition() {
424 if (IsVisible()) { 424 if (IsVisible()) {
425 bubble_delegate_->set_parent_window( 425 bubble_delegate_->set_parent_window(
426 platform_util::GetViewForWindow(browser_->window()->GetNativeWindow())); 426 platform_util::GetViewForWindow(browser_->window()->GetNativeWindow()));
427 bubble_delegate_->UpdateAnchor(GetAnchorView(), 427 bubble_delegate_->UpdateAnchor(GetAnchorView(),
428 GetAnchorPoint(), 428 GetAnchorPoint(),
429 GetAnchorArrow()); 429 GetAnchorArrow());
430 } 430 }
431 } 431 }
432 432
433 gfx::NativeWindow PermissionBubbleViewViews::GetNativeWindow() { 433 gfx::NativeWindow PermissionPromptImpl::GetNativeWindow() {
434 if (bubble_delegate_ && bubble_delegate_->GetWidget()) 434 if (bubble_delegate_ && bubble_delegate_->GetWidget())
435 return bubble_delegate_->GetWidget()->GetNativeWindow(); 435 return bubble_delegate_->GetWidget()->GetNativeWindow();
436 return nullptr; 436 return nullptr;
437 } 437 }
438 438
439 void PermissionBubbleViewViews::Closing() { 439 void PermissionPromptImpl::Closing() {
440 if (bubble_delegate_) 440 if (bubble_delegate_)
441 bubble_delegate_ = nullptr; 441 bubble_delegate_ = nullptr;
442 if (delegate_) 442 if (delegate_)
443 delegate_->Closing(); 443 delegate_->Closing();
444 } 444 }
445 445
446 void PermissionBubbleViewViews::Toggle(int index, bool value) { 446 void PermissionPromptImpl::Toggle(int index, bool value) {
447 if (delegate_) 447 if (delegate_)
448 delegate_->ToggleAccept(index, value); 448 delegate_->ToggleAccept(index, value);
449 } 449 }
450 450
451 void PermissionBubbleViewViews::Accept() { 451 void PermissionPromptImpl::Accept() {
452 if (delegate_) 452 if (delegate_)
453 delegate_->Accept(); 453 delegate_->Accept();
454 } 454 }
455 455
456 void PermissionBubbleViewViews::Deny() { 456 void PermissionPromptImpl::Deny() {
457 if (delegate_) 457 if (delegate_)
458 delegate_->Deny(); 458 delegate_->Deny();
459 } 459 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698