| 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/permissions_bubble_view.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/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/views/exclusive_access_bubble_views.h" | 13 #include "chrome/browser/ui/views/exclusive_access_bubble_views.h" |
| 14 #include "chrome/browser/ui/views/frame/browser_view.h" | 14 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 15 #include "chrome/browser/ui/views/frame/top_container_view.h" | 15 #include "chrome/browser/ui/views/frame/top_container_view.h" |
| 16 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 16 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 17 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 17 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
| 18 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h" | 18 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h" |
| 19 #include "chrome/browser/ui/views/website_settings/permission_selector_view_obse
rver.h" | 19 #include "chrome/browser/ui/views/website_settings/permission_selector_view_obse
rver.h" |
| 20 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | 20 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
| 21 #include "chrome/common/pref_names.h" | |
| 22 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
| 23 #include "components/prefs/pref_service.h" | |
| 24 #include "components/url_formatter/elide_url.h" | 22 #include "components/url_formatter/elide_url.h" |
| 25 #include "grit/components_strings.h" | 23 #include "grit/components_strings.h" |
| 26 #include "ui/accessibility/ax_view_state.h" | 24 #include "ui/accessibility/ax_view_state.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/models/combobox_model.h" | 26 #include "ui/base/models/combobox_model.h" |
| 29 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| 30 #include "ui/gfx/color_palette.h" | 28 #include "ui/gfx/color_palette.h" |
| 31 #include "ui/gfx/paint_vector_icon.h" | 29 #include "ui/gfx/paint_vector_icon.h" |
| 32 #include "ui/gfx/text_constants.h" | 30 #include "ui/gfx/text_constants.h" |
| 33 #include "ui/gfx/vector_icons_public.h" | 31 #include "ui/gfx/vector_icons_public.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 /////////////////////////////////////////////////////////////////////////////// | 148 /////////////////////////////////////////////////////////////////////////////// |
| 151 // View implementation for the permissions bubble. | 149 // View implementation for the permissions bubble. |
| 152 class PermissionsBubbleDelegateView : public views::BubbleDelegateView, | 150 class PermissionsBubbleDelegateView : public views::BubbleDelegateView, |
| 153 public views::ButtonListener, | 151 public views::ButtonListener, |
| 154 public PermissionCombobox::Listener { | 152 public PermissionCombobox::Listener { |
| 155 public: | 153 public: |
| 156 PermissionsBubbleDelegateView( | 154 PermissionsBubbleDelegateView( |
| 157 views::View* anchor_view, | 155 views::View* anchor_view, |
| 158 views::BubbleBorder::Arrow anchor_arrow, | 156 views::BubbleBorder::Arrow anchor_arrow, |
| 159 PermissionBubbleViewViews* owner, | 157 PermissionBubbleViewViews* owner, |
| 160 const std::string& languages, | |
| 161 const std::vector<PermissionBubbleRequest*>& requests, | 158 const std::vector<PermissionBubbleRequest*>& requests, |
| 162 const std::vector<bool>& accept_state); | 159 const std::vector<bool>& accept_state); |
| 163 ~PermissionsBubbleDelegateView() override; | 160 ~PermissionsBubbleDelegateView() override; |
| 164 | 161 |
| 165 void Close(); | 162 void Close(); |
| 166 void SizeToContents(); | 163 void SizeToContents(); |
| 167 | 164 |
| 168 // BubbleDelegateView: | 165 // BubbleDelegateView: |
| 169 bool ShouldShowCloseButton() const override; | 166 bool ShouldShowCloseButton() const override; |
| 170 bool ShouldShowWindowTitle() const override; | 167 bool ShouldShowWindowTitle() const override; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 193 scoped_ptr<PermissionMenuModel> menu_button_model_; | 190 scoped_ptr<PermissionMenuModel> menu_button_model_; |
| 194 std::vector<PermissionCombobox*> customize_comboboxes_; | 191 std::vector<PermissionCombobox*> customize_comboboxes_; |
| 195 | 192 |
| 196 DISALLOW_COPY_AND_ASSIGN(PermissionsBubbleDelegateView); | 193 DISALLOW_COPY_AND_ASSIGN(PermissionsBubbleDelegateView); |
| 197 }; | 194 }; |
| 198 | 195 |
| 199 PermissionsBubbleDelegateView::PermissionsBubbleDelegateView( | 196 PermissionsBubbleDelegateView::PermissionsBubbleDelegateView( |
| 200 views::View* anchor_view, | 197 views::View* anchor_view, |
| 201 views::BubbleBorder::Arrow anchor_arrow, | 198 views::BubbleBorder::Arrow anchor_arrow, |
| 202 PermissionBubbleViewViews* owner, | 199 PermissionBubbleViewViews* owner, |
| 203 const std::string& languages, | |
| 204 const std::vector<PermissionBubbleRequest*>& requests, | 200 const std::vector<PermissionBubbleRequest*>& requests, |
| 205 const std::vector<bool>& accept_state) | 201 const std::vector<bool>& accept_state) |
| 206 : views::BubbleDelegateView(anchor_view, anchor_arrow), | 202 : views::BubbleDelegateView(anchor_view, anchor_arrow), |
| 207 owner_(owner), | 203 owner_(owner), |
| 208 allow_(nullptr), | 204 allow_(nullptr), |
| 209 deny_(nullptr) { | 205 deny_(nullptr) { |
| 210 DCHECK(!requests.empty()); | 206 DCHECK(!requests.empty()); |
| 211 | 207 |
| 212 set_close_on_esc(true); | 208 set_close_on_esc(true); |
| 213 set_close_on_deactivate(false); | 209 set_close_on_deactivate(false); |
| 214 | 210 |
| 215 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, | 211 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, |
| 216 kItemMajorSpacing)); | 212 kItemMajorSpacing)); |
| 217 | 213 |
| 218 display_origin_ = url_formatter::FormatUrlForSecurityDisplay( | 214 display_origin_ = url_formatter::FormatUrlForSecurityDisplay( |
| 219 requests[0]->GetOrigin(), languages); | 215 requests[0]->GetOrigin()); |
| 220 | 216 |
| 221 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 217 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 222 for (size_t index = 0; index < requests.size(); index++) { | 218 for (size_t index = 0; index < requests.size(); index++) { |
| 223 DCHECK(index < accept_state.size()); | 219 DCHECK(index < accept_state.size()); |
| 224 // The row is laid out containing a leading-aligned label area and a | 220 // The row is laid out containing a leading-aligned label area and a |
| 225 // trailing column which will be filled if there are multiple permission | 221 // trailing column which will be filled if there are multiple permission |
| 226 // requests. | 222 // requests. |
| 227 views::View* row = new views::View(); | 223 views::View* row = new views::View(); |
| 228 views::GridLayout* row_layout = new views::GridLayout(row); | 224 views::GridLayout* row_layout = new views::GridLayout(row); |
| 229 row->SetLayoutManager(row_layout); | 225 row->SetLayoutManager(row_layout); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 delegate_ = delegate; | 433 delegate_ = delegate; |
| 438 } | 434 } |
| 439 | 435 |
| 440 void PermissionBubbleViewViews::Show( | 436 void PermissionBubbleViewViews::Show( |
| 441 const std::vector<PermissionBubbleRequest*>& requests, | 437 const std::vector<PermissionBubbleRequest*>& requests, |
| 442 const std::vector<bool>& values) { | 438 const std::vector<bool>& values) { |
| 443 if (bubble_delegate_) | 439 if (bubble_delegate_) |
| 444 bubble_delegate_->Close(); | 440 bubble_delegate_->Close(); |
| 445 | 441 |
| 446 bubble_delegate_ = | 442 bubble_delegate_ = |
| 447 new PermissionsBubbleDelegateView( | 443 new PermissionsBubbleDelegateView(GetAnchorView(), GetAnchorArrow(), this, |
| 448 GetAnchorView(), GetAnchorArrow(), this, | |
| 449 browser_->profile()->GetPrefs()->GetString(prefs::kAcceptLanguages), | |
| 450 requests, values); | 444 requests, values); |
| 451 | 445 |
| 452 // Set |parent_window| because some valid anchors can become hidden. | 446 // Set |parent_window| because some valid anchors can become hidden. |
| 453 views::Widget* widget = views::Widget::GetWidgetForNativeWindow( | 447 views::Widget* widget = views::Widget::GetWidgetForNativeWindow( |
| 454 browser_->window()->GetNativeWindow()); | 448 browser_->window()->GetNativeWindow()); |
| 455 bubble_delegate_->set_parent_window(widget->GetNativeView()); | 449 bubble_delegate_->set_parent_window(widget->GetNativeView()); |
| 456 | 450 |
| 457 views::BubbleDelegateView::CreateBubble(bubble_delegate_)->Show(); | 451 views::BubbleDelegateView::CreateBubble(bubble_delegate_)->Show(); |
| 458 bubble_delegate_->SizeToContents(); | 452 bubble_delegate_->SizeToContents(); |
| 459 } | 453 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 | 492 |
| 499 void PermissionBubbleViewViews::Accept() { | 493 void PermissionBubbleViewViews::Accept() { |
| 500 if (delegate_) | 494 if (delegate_) |
| 501 delegate_->Accept(); | 495 delegate_->Accept(); |
| 502 } | 496 } |
| 503 | 497 |
| 504 void PermissionBubbleViewViews::Deny() { | 498 void PermissionBubbleViewViews::Deny() { |
| 505 if (delegate_) | 499 if (delegate_) |
| 506 delegate_->Deny(); | 500 delegate_->Deny(); |
| 507 } | 501 } |
| OLD | NEW |