| 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/permission_prompt_impl.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" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // TODO(gbillock): refactor PermissionMenuButton to work like this and re-use? | 57 // TODO(gbillock): refactor PermissionMenuButton to work like this and re-use? |
| 58 class PermissionCombobox : public views::MenuButton, | 58 class PermissionCombobox : public views::MenuButton, |
| 59 public views::MenuButtonListener { | 59 public views::MenuButtonListener { |
| 60 public: | 60 public: |
| 61 // Get notifications when the selection changes. | 61 // Get notifications when the selection changes. |
| 62 class Listener { | 62 class Listener { |
| 63 public: | 63 public: |
| 64 virtual void PermissionSelectionChanged(int index, bool allowed) = 0; | 64 virtual void PermissionSelectionChanged(int index, bool allowed) = 0; |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 PermissionCombobox(Listener* listener, | 67 PermissionCombobox(Profile* profile, |
| 68 Listener* listener, |
| 68 int index, | 69 int index, |
| 69 const GURL& url, | 70 const GURL& url, |
| 70 ContentSetting setting); | 71 ContentSetting setting); |
| 71 ~PermissionCombobox() override; | 72 ~PermissionCombobox() override; |
| 72 | 73 |
| 73 int index() const { return index_; } | 74 int index() const { return index_; } |
| 74 | 75 |
| 75 void GetAccessibleState(ui::AXViewState* state) override; | 76 void GetAccessibleState(ui::AXViewState* state) override; |
| 76 | 77 |
| 77 // MenuButtonListener: | 78 // MenuButtonListener: |
| 78 void OnMenuButtonClicked(views::MenuButton* source, | 79 void OnMenuButtonClicked(views::MenuButton* source, |
| 79 const gfx::Point& point, | 80 const gfx::Point& point, |
| 80 const ui::Event* event) override; | 81 const ui::Event* event) override; |
| 81 | 82 |
| 82 // Callback when a permission's setting is changed. | 83 // Callback when a permission's setting is changed. |
| 83 void PermissionChanged(const WebsiteSettingsUI::PermissionInfo& permission); | 84 void PermissionChanged(const WebsiteSettingsUI::PermissionInfo& permission); |
| 84 | 85 |
| 85 private: | 86 private: |
| 86 int index_; | 87 int index_; |
| 87 Listener* listener_; | 88 Listener* listener_; |
| 88 std::unique_ptr<PermissionMenuModel> model_; | 89 std::unique_ptr<PermissionMenuModel> model_; |
| 89 std::unique_ptr<views::MenuRunner> menu_runner_; | 90 std::unique_ptr<views::MenuRunner> menu_runner_; |
| 90 }; | 91 }; |
| 91 | 92 |
| 92 PermissionCombobox::PermissionCombobox(Listener* listener, | 93 PermissionCombobox::PermissionCombobox(Profile* profile, |
| 94 Listener* listener, |
| 93 int index, | 95 int index, |
| 94 const GURL& url, | 96 const GURL& url, |
| 95 ContentSetting setting) | 97 ContentSetting setting) |
| 96 : MenuButton(base::string16(), this, true), | 98 : MenuButton(base::string16(), this, true), |
| 97 index_(index), | 99 index_(index), |
| 98 listener_(listener), | 100 listener_(listener), |
| 99 model_(new PermissionMenuModel( | 101 model_(new PermissionMenuModel( |
| 102 profile, |
| 100 url, | 103 url, |
| 101 setting, | 104 setting, |
| 102 base::Bind(&PermissionCombobox::PermissionChanged, | 105 base::Bind(&PermissionCombobox::PermissionChanged, |
| 103 base::Unretained(this)))) { | 106 base::Unretained(this)))) { |
| 104 SetText(model_->GetLabelAt(model_->GetIndexOfCommandId(setting))); | 107 SetText(model_->GetLabelAt(model_->GetIndexOfCommandId(setting))); |
| 105 SizeToPreferredSize(); | 108 SizeToPreferredSize(); |
| 106 } | 109 } |
| 107 | 110 |
| 108 PermissionCombobox::~PermissionCombobox() {} | 111 PermissionCombobox::~PermissionCombobox() {} |
| 109 | 112 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 new views::Label(requests.at(index)->GetMessageTextFragment()); | 241 new views::Label(requests.at(index)->GetMessageTextFragment()); |
| 239 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 242 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 240 label_container->AddChildView(label); | 243 label_container->AddChildView(label); |
| 241 row_layout->AddView(label_container); | 244 row_layout->AddView(label_container); |
| 242 | 245 |
| 243 // Only show the toggle if every request wants to show it. | 246 // Only show the toggle if every request wants to show it. |
| 244 show_persistence_toggle = show_persistence_toggle && | 247 show_persistence_toggle = show_persistence_toggle && |
| 245 requests[index]->ShouldShowPersistenceToggle(); | 248 requests[index]->ShouldShowPersistenceToggle(); |
| 246 if (requests.size() > 1) { | 249 if (requests.size() > 1) { |
| 247 PermissionCombobox* combobox = new PermissionCombobox( | 250 PermissionCombobox* combobox = new PermissionCombobox( |
| 248 this, index, requests[index]->GetOrigin(), | 251 owner->GetProfile(), this, index, requests[index]->GetOrigin(), |
| 249 accept_state[index] ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); | 252 accept_state[index] ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); |
| 250 row_layout->AddView(combobox); | 253 row_layout->AddView(combobox); |
| 251 customize_comboboxes_.push_back(combobox); | 254 customize_comboboxes_.push_back(combobox); |
| 252 } else { | 255 } else { |
| 253 row_layout->AddView(new views::View()); | 256 row_layout->AddView(new views::View()); |
| 254 } | 257 } |
| 255 | 258 |
| 256 AddChildView(row); | 259 AddChildView(row); |
| 257 } | 260 } |
| 258 | 261 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 479 |
| 477 void PermissionPromptImpl::Accept() { | 480 void PermissionPromptImpl::Accept() { |
| 478 if (delegate_) | 481 if (delegate_) |
| 479 delegate_->Accept(); | 482 delegate_->Accept(); |
| 480 } | 483 } |
| 481 | 484 |
| 482 void PermissionPromptImpl::Deny() { | 485 void PermissionPromptImpl::Deny() { |
| 483 if (delegate_) | 486 if (delegate_) |
| 484 delegate_->Deny(); | 487 delegate_->Deny(); |
| 485 } | 488 } |
| 489 |
| 490 Profile* PermissionPromptImpl::GetProfile() { |
| 491 return browser_->profile(); |
| 492 } |
| OLD | NEW |