| 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" |
| 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" |
| 16 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 17 #include "chrome/browser/ui/views/exclusive_access_bubble_views.h" | 17 #include "chrome/browser/ui/views/exclusive_access_bubble_views.h" |
| 18 #include "chrome/browser/ui/views/website_settings/permission_selector_row.h" | 18 #include "chrome/browser/ui/views/website_settings/permission_selector_row.h" |
| 19 #include "chrome/browser/ui/views/website_settings/permission_selector_row_obser
ver.h" | 19 #include "chrome/browser/ui/views/website_settings/permission_selector_row_obser
ver.h" |
| 20 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
| 21 #include "components/strings/grit/components_strings.h" | 21 #include "components/strings/grit/components_strings.h" |
| 22 #include "components/url_formatter/elide_url.h" | 22 #include "components/url_formatter/elide_url.h" |
| 23 #include "ui/accessibility/ax_view_state.h" | 23 #include "ui/accessibility/ax_node_data.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/base/models/combobox_model.h" | 25 #include "ui/base/models/combobox_model.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
| 27 #include "ui/gfx/color_palette.h" | 27 #include "ui/gfx/color_palette.h" |
| 28 #include "ui/gfx/paint_vector_icon.h" | 28 #include "ui/gfx/paint_vector_icon.h" |
| 29 #include "ui/gfx/text_constants.h" | 29 #include "ui/gfx/text_constants.h" |
| 30 #include "ui/gfx/vector_icons_public.h" | 30 #include "ui/gfx/vector_icons_public.h" |
| 31 #include "ui/views/bubble/bubble_dialog_delegate.h" | 31 #include "ui/views/bubble/bubble_dialog_delegate.h" |
| 32 #include "ui/views/bubble/bubble_frame_view.h" | 32 #include "ui/views/bubble/bubble_frame_view.h" |
| 33 #include "ui/views/controls/button/checkbox.h" | 33 #include "ui/views/controls/button/checkbox.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 PermissionCombobox(Profile* profile, | 67 PermissionCombobox(Profile* profile, |
| 68 Listener* listener, | 68 Listener* listener, |
| 69 int index, | 69 int index, |
| 70 const GURL& url, | 70 const GURL& url, |
| 71 ContentSetting setting); | 71 ContentSetting setting); |
| 72 ~PermissionCombobox() override; | 72 ~PermissionCombobox() override; |
| 73 | 73 |
| 74 int index() const { return index_; } | 74 int index() const { return index_; } |
| 75 | 75 |
| 76 void GetAccessibleState(ui::AXViewState* state) override; | 76 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; |
| 77 | 77 |
| 78 // MenuButtonListener: | 78 // MenuButtonListener: |
| 79 void OnMenuButtonClicked(views::MenuButton* source, | 79 void OnMenuButtonClicked(views::MenuButton* source, |
| 80 const gfx::Point& point, | 80 const gfx::Point& point, |
| 81 const ui::Event* event) override; | 81 const ui::Event* event) override; |
| 82 | 82 |
| 83 // Callback when a permission's setting is changed. | 83 // Callback when a permission's setting is changed. |
| 84 void PermissionChanged(const WebsiteSettingsUI::PermissionInfo& permission); | 84 void PermissionChanged(const WebsiteSettingsUI::PermissionInfo& permission); |
| 85 | 85 |
| 86 private: | 86 private: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 103 url, | 103 url, |
| 104 setting, | 104 setting, |
| 105 base::Bind(&PermissionCombobox::PermissionChanged, | 105 base::Bind(&PermissionCombobox::PermissionChanged, |
| 106 base::Unretained(this)))) { | 106 base::Unretained(this)))) { |
| 107 SetText(model_->GetLabelAt(model_->GetIndexOfCommandId(setting))); | 107 SetText(model_->GetLabelAt(model_->GetIndexOfCommandId(setting))); |
| 108 SizeToPreferredSize(); | 108 SizeToPreferredSize(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 PermissionCombobox::~PermissionCombobox() {} | 111 PermissionCombobox::~PermissionCombobox() {} |
| 112 | 112 |
| 113 void PermissionCombobox::GetAccessibleState(ui::AXViewState* state) { | 113 void PermissionCombobox::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 114 MenuButton::GetAccessibleState(state); | 114 MenuButton::GetAccessibleNodeData(node_data); |
| 115 state->value = GetText(); | 115 node_data->SetValue(GetText()); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void PermissionCombobox::OnMenuButtonClicked(views::MenuButton* source, | 118 void PermissionCombobox::OnMenuButtonClicked(views::MenuButton* source, |
| 119 const gfx::Point& point, | 119 const gfx::Point& point, |
| 120 const ui::Event* event) { | 120 const ui::Event* event) { |
| 121 menu_runner_.reset(new views::MenuRunner( | 121 menu_runner_.reset(new views::MenuRunner( |
| 122 model_.get(), | 122 model_.get(), |
| 123 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::ASYNC)); | 123 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::ASYNC)); |
| 124 | 124 |
| 125 gfx::Point p(point); | 125 gfx::Point p(point); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 152 | 152 |
| 153 void CloseBubble(); | 153 void CloseBubble(); |
| 154 void SizeToContents(); | 154 void SizeToContents(); |
| 155 | 155 |
| 156 // BubbleDialogDelegateView: | 156 // BubbleDialogDelegateView: |
| 157 bool ShouldShowCloseButton() const override; | 157 bool ShouldShowCloseButton() const override; |
| 158 const gfx::FontList& GetTitleFontList() const override; | 158 const gfx::FontList& GetTitleFontList() const override; |
| 159 base::string16 GetWindowTitle() const override; | 159 base::string16 GetWindowTitle() const override; |
| 160 void OnWidgetDestroying(views::Widget* widget) override; | 160 void OnWidgetDestroying(views::Widget* widget) override; |
| 161 gfx::Size GetPreferredSize() const override; | 161 gfx::Size GetPreferredSize() const override; |
| 162 void GetAccessibleState(ui::AXViewState* state) override; | 162 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; |
| 163 bool Cancel() override; | 163 bool Cancel() override; |
| 164 bool Accept() override; | 164 bool Accept() override; |
| 165 bool Close() override; | 165 bool Close() override; |
| 166 int GetDefaultDialogButton() const override; | 166 int GetDefaultDialogButton() const override; |
| 167 int GetDialogButtons() const override; | 167 int GetDialogButtons() const override; |
| 168 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; | 168 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; |
| 169 | 169 |
| 170 // PermissionCombobox::Listener: | 170 // PermissionCombobox::Listener: |
| 171 void PermissionSelectionChanged(int index, bool allowed) override; | 171 void PermissionSelectionChanged(int index, bool allowed) override; |
| 172 | 172 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 owner_ = nullptr; | 301 owner_ = nullptr; |
| 302 } | 302 } |
| 303 } | 303 } |
| 304 | 304 |
| 305 gfx::Size PermissionsBubbleDialogDelegateView::GetPreferredSize() const { | 305 gfx::Size PermissionsBubbleDialogDelegateView::GetPreferredSize() const { |
| 306 // TODO(estade): bubbles should default to this width. | 306 // TODO(estade): bubbles should default to this width. |
| 307 const int kWidth = 320 - GetInsets().width(); | 307 const int kWidth = 320 - GetInsets().width(); |
| 308 return gfx::Size(kWidth, GetHeightForWidth(kWidth)); | 308 return gfx::Size(kWidth, GetHeightForWidth(kWidth)); |
| 309 } | 309 } |
| 310 | 310 |
| 311 void PermissionsBubbleDialogDelegateView::GetAccessibleState( | 311 void PermissionsBubbleDialogDelegateView::GetAccessibleNodeData( |
| 312 ui::AXViewState* state) { | 312 ui::AXNodeData* node_data) { |
| 313 views::BubbleDialogDelegateView::GetAccessibleState(state); | 313 views::BubbleDialogDelegateView::GetAccessibleNodeData(node_data); |
| 314 state->role = ui::AX_ROLE_ALERT_DIALOG; | 314 node_data->role = ui::AX_ROLE_ALERT_DIALOG; |
| 315 } | 315 } |
| 316 | 316 |
| 317 int PermissionsBubbleDialogDelegateView::GetDefaultDialogButton() const { | 317 int PermissionsBubbleDialogDelegateView::GetDefaultDialogButton() const { |
| 318 // To prevent permissions being accepted accidentally, and as a security | 318 // To prevent permissions being accepted accidentally, and as a security |
| 319 // measure against crbug.com/619429, permission prompts should not be accepted | 319 // measure against crbug.com/619429, permission prompts should not be accepted |
| 320 // as the default action. | 320 // as the default action. |
| 321 return ui::DIALOG_BUTTON_NONE; | 321 return ui::DIALOG_BUTTON_NONE; |
| 322 } | 322 } |
| 323 | 323 |
| 324 int PermissionsBubbleDialogDelegateView::GetDialogButtons() const { | 324 int PermissionsBubbleDialogDelegateView::GetDialogButtons() const { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 } | 479 } |
| 480 | 480 |
| 481 void PermissionPromptImpl::Deny() { | 481 void PermissionPromptImpl::Deny() { |
| 482 if (delegate_) | 482 if (delegate_) |
| 483 delegate_->Deny(); | 483 delegate_->Deny(); |
| 484 } | 484 } |
| 485 | 485 |
| 486 Profile* PermissionPromptImpl::GetProfile() { | 486 Profile* PermissionPromptImpl::GetProfile() { |
| 487 return browser_->profile(); | 487 return browser_->profile(); |
| 488 } | 488 } |
| OLD | NEW |