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 "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h" | 8 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h" |
9 #include "chrome/browser/ui/views/website_settings/permission_selector_view_obse
rver.h" | 9 #include "chrome/browser/ui/views/website_settings/permission_selector_view_obse
rver.h" |
10 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | 10 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 /////////////////////////////////////////////////////////////////////////////// | 168 /////////////////////////////////////////////////////////////////////////////// |
169 // View implementation for the permissions bubble. | 169 // View implementation for the permissions bubble. |
170 class PermissionsBubbleDelegateView : public views::BubbleDelegateView, | 170 class PermissionsBubbleDelegateView : public views::BubbleDelegateView, |
171 public views::ButtonListener, | 171 public views::ButtonListener, |
172 public views::ComboboxListener, | 172 public views::ComboboxListener, |
173 public PermissionCombobox::Listener { | 173 public PermissionCombobox::Listener { |
174 public: | 174 public: |
175 PermissionsBubbleDelegateView( | 175 PermissionsBubbleDelegateView( |
176 views::View* anchor, | 176 views::View* anchor, |
177 PermissionBubbleViewViews* owner, | 177 PermissionBubbleViewViews* owner, |
| 178 const std::string& languages, |
178 const std::vector<PermissionBubbleRequest*>& requests, | 179 const std::vector<PermissionBubbleRequest*>& requests, |
179 const std::vector<bool>& accept_state, | 180 const std::vector<bool>& accept_state, |
180 bool customization_mode); | 181 bool customization_mode); |
181 ~PermissionsBubbleDelegateView() override; | 182 ~PermissionsBubbleDelegateView() override; |
182 | 183 |
183 void Close(); | 184 void Close(); |
184 void SizeToContents(); | 185 void SizeToContents(); |
185 | 186 |
186 // BubbleDelegateView: | 187 // BubbleDelegateView: |
187 bool ShouldShowCloseButton() const override; | 188 bool ShouldShowCloseButton() const override; |
(...skipping 19 matching lines...) Expand all Loading... |
207 base::string16 hostname_; | 208 base::string16 hostname_; |
208 scoped_ptr<PermissionMenuModel> menu_button_model_; | 209 scoped_ptr<PermissionMenuModel> menu_button_model_; |
209 std::vector<PermissionCombobox*> customize_comboboxes_; | 210 std::vector<PermissionCombobox*> customize_comboboxes_; |
210 | 211 |
211 DISALLOW_COPY_AND_ASSIGN(PermissionsBubbleDelegateView); | 212 DISALLOW_COPY_AND_ASSIGN(PermissionsBubbleDelegateView); |
212 }; | 213 }; |
213 | 214 |
214 PermissionsBubbleDelegateView::PermissionsBubbleDelegateView( | 215 PermissionsBubbleDelegateView::PermissionsBubbleDelegateView( |
215 views::View* anchor, | 216 views::View* anchor, |
216 PermissionBubbleViewViews* owner, | 217 PermissionBubbleViewViews* owner, |
| 218 const std::string& languages, |
217 const std::vector<PermissionBubbleRequest*>& requests, | 219 const std::vector<PermissionBubbleRequest*>& requests, |
218 const std::vector<bool>& accept_state, | 220 const std::vector<bool>& accept_state, |
219 bool customization_mode) | 221 bool customization_mode) |
220 : views::BubbleDelegateView(anchor, views::BubbleBorder::TOP_LEFT), | 222 : views::BubbleDelegateView(anchor, views::BubbleBorder::TOP_LEFT), |
221 owner_(owner), | 223 owner_(owner), |
222 allow_(NULL), | 224 allow_(NULL), |
223 deny_(NULL), | 225 deny_(NULL), |
224 allow_combobox_(NULL) { | 226 allow_combobox_(NULL) { |
225 DCHECK(!requests.empty()); | 227 DCHECK(!requests.empty()); |
226 | 228 |
227 RemoveAllChildViews(true); | 229 RemoveAllChildViews(true); |
228 customize_comboboxes_.clear(); | 230 customize_comboboxes_.clear(); |
229 set_close_on_esc(false); | 231 set_close_on_esc(false); |
230 set_close_on_deactivate(false); | 232 set_close_on_deactivate(false); |
231 | 233 |
232 SetLayoutManager(new views::BoxLayout( | 234 SetLayoutManager(new views::BoxLayout( |
233 views::BoxLayout::kVertical, kBubbleOuterMargin, 0, kItemMajorSpacing)); | 235 views::BoxLayout::kVertical, kBubbleOuterMargin, 0, kItemMajorSpacing)); |
234 | 236 |
235 // TODO(gbillock): support other languages than English. | |
236 hostname_ = net::FormatUrl(requests[0]->GetRequestingHostname(), | 237 hostname_ = net::FormatUrl(requests[0]->GetRequestingHostname(), |
237 "en", | 238 languages, |
238 net::kFormatUrlOmitUsernamePassword | | 239 net::kFormatUrlOmitUsernamePassword | |
239 net::kFormatUrlOmitTrailingSlashOnBareHostname, | 240 net::kFormatUrlOmitTrailingSlashOnBareHostname, |
240 net::UnescapeRule::SPACES, NULL, NULL, NULL); | 241 net::UnescapeRule::SPACES, NULL, NULL, NULL); |
241 | 242 |
242 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 243 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
243 for (size_t index = 0; index < requests.size(); index++) { | 244 for (size_t index = 0; index < requests.size(); index++) { |
244 DCHECK(index < accept_state.size()); | 245 DCHECK(index < accept_state.size()); |
245 // The row is laid out containing a leading-aligned label area and a | 246 // The row is laid out containing a leading-aligned label area and a |
246 // trailing column which will be filled during customization with a | 247 // trailing column which will be filled during customization with a |
247 // combobox. | 248 // combobox. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 owner_->SetCustomizationMode(); | 411 owner_->SetCustomizationMode(); |
411 else if (combobox->selected_index() == | 412 else if (combobox->selected_index() == |
412 CustomizeAllowComboboxModel::INDEX_ALLOW) | 413 CustomizeAllowComboboxModel::INDEX_ALLOW) |
413 owner_->Accept(); | 414 owner_->Accept(); |
414 } | 415 } |
415 } | 416 } |
416 | 417 |
417 ////////////////////////////////////////////////////////////////////////////// | 418 ////////////////////////////////////////////////////////////////////////////// |
418 // PermissionBubbleViewViews | 419 // PermissionBubbleViewViews |
419 | 420 |
420 PermissionBubbleViewViews::PermissionBubbleViewViews(views::View* anchor_view) | 421 PermissionBubbleViewViews::PermissionBubbleViewViews( |
| 422 views::View* anchor_view, |
| 423 const std::string& languages) |
421 : anchor_view_(anchor_view), | 424 : anchor_view_(anchor_view), |
422 delegate_(NULL), | 425 delegate_(NULL), |
423 bubble_delegate_(NULL) {} | 426 bubble_delegate_(NULL), |
| 427 languages_(languages) {} |
424 | 428 |
425 PermissionBubbleViewViews::~PermissionBubbleViewViews() { | 429 PermissionBubbleViewViews::~PermissionBubbleViewViews() { |
426 if (delegate_) | 430 if (delegate_) |
427 delegate_->SetView(NULL); | 431 delegate_->SetView(NULL); |
428 } | 432 } |
429 | 433 |
430 void PermissionBubbleViewViews::SetDelegate(Delegate* delegate) { | 434 void PermissionBubbleViewViews::SetDelegate(Delegate* delegate) { |
431 delegate_ = delegate; | 435 delegate_ = delegate; |
432 } | 436 } |
433 | 437 |
434 void PermissionBubbleViewViews::Show( | 438 void PermissionBubbleViewViews::Show( |
435 const std::vector<PermissionBubbleRequest*>& requests, | 439 const std::vector<PermissionBubbleRequest*>& requests, |
436 const std::vector<bool>& values, | 440 const std::vector<bool>& values, |
437 bool customization_mode) { | 441 bool customization_mode) { |
438 if (bubble_delegate_ != NULL) | 442 if (bubble_delegate_ != NULL) |
439 bubble_delegate_->Close(); | 443 bubble_delegate_->Close(); |
440 | 444 |
441 bubble_delegate_ = | 445 bubble_delegate_ = |
442 new PermissionsBubbleDelegateView(anchor_view_, this, | 446 new PermissionsBubbleDelegateView(anchor_view_, this, languages_, |
443 requests, values, customization_mode); | 447 requests, values, customization_mode); |
444 views::BubbleDelegateView::CreateBubble(bubble_delegate_)->Show(); | 448 views::BubbleDelegateView::CreateBubble(bubble_delegate_)->Show(); |
445 bubble_delegate_->SizeToContents(); | 449 bubble_delegate_->SizeToContents(); |
446 } | 450 } |
447 | 451 |
448 bool PermissionBubbleViewViews::CanAcceptRequestUpdate() { | 452 bool PermissionBubbleViewViews::CanAcceptRequestUpdate() { |
449 return !(bubble_delegate_ && bubble_delegate_->IsMouseHovered()); | 453 return !(bubble_delegate_ && bubble_delegate_->IsMouseHovered()); |
450 } | 454 } |
451 | 455 |
452 void PermissionBubbleViewViews::Hide() { | 456 void PermissionBubbleViewViews::Hide() { |
(...skipping 26 matching lines...) Expand all Loading... |
479 | 483 |
480 void PermissionBubbleViewViews::Deny() { | 484 void PermissionBubbleViewViews::Deny() { |
481 if (delegate_) | 485 if (delegate_) |
482 delegate_->Deny(); | 486 delegate_->Deny(); |
483 } | 487 } |
484 | 488 |
485 void PermissionBubbleViewViews::SetCustomizationMode() { | 489 void PermissionBubbleViewViews::SetCustomizationMode() { |
486 if (delegate_) | 490 if (delegate_) |
487 delegate_->SetCustomizationMode(); | 491 delegate_->SetCustomizationMode(); |
488 } | 492 } |
OLD | NEW |