| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 void UpdateAnchor(views::View* anchor_view, | 176 void UpdateAnchor(views::View* anchor_view, |
| 177 const gfx::Point& anchor_point, | 177 const gfx::Point& anchor_point, |
| 178 views::BubbleBorder::Arrow anchor_arrow); | 178 views::BubbleBorder::Arrow anchor_arrow); |
| 179 | 179 |
| 180 private: | 180 private: |
| 181 PermissionPromptImpl* owner_; | 181 PermissionPromptImpl* owner_; |
| 182 bool multiple_requests_; | 182 bool multiple_requests_; |
| 183 base::string16 display_origin_; | 183 base::string16 display_origin_; |
| 184 std::unique_ptr<PermissionMenuModel> menu_button_model_; | 184 std::unique_ptr<PermissionMenuModel> menu_button_model_; |
| 185 std::vector<PermissionCombobox*> customize_comboboxes_; | 185 std::vector<PermissionCombobox*> customize_comboboxes_; |
| 186 views::Checkbox* checkbox_; |
| 186 | 187 |
| 187 DISALLOW_COPY_AND_ASSIGN(PermissionsBubbleDialogDelegateView); | 188 DISALLOW_COPY_AND_ASSIGN(PermissionsBubbleDialogDelegateView); |
| 188 }; | 189 }; |
| 189 | 190 |
| 190 PermissionsBubbleDialogDelegateView::PermissionsBubbleDialogDelegateView( | 191 PermissionsBubbleDialogDelegateView::PermissionsBubbleDialogDelegateView( |
| 191 PermissionPromptImpl* owner, | 192 PermissionPromptImpl* owner, |
| 192 const std::vector<PermissionRequest*>& requests, | 193 const std::vector<PermissionRequest*>& requests, |
| 193 const std::vector<bool>& accept_state) | 194 const std::vector<bool>& accept_state) |
| 194 : owner_(owner), | 195 : owner_(owner), |
| 195 multiple_requests_(requests.size() > 1) { | 196 multiple_requests_(requests.size() > 1), |
| 197 checkbox_(nullptr) { |
| 196 DCHECK(!requests.empty()); | 198 DCHECK(!requests.empty()); |
| 197 | 199 |
| 198 set_close_on_deactivate(false); | 200 set_close_on_deactivate(false); |
| 199 | 201 |
| 200 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, | 202 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, |
| 201 kItemMajorSpacing)); | 203 kItemMajorSpacing)); |
| 202 | 204 |
| 203 display_origin_ = url_formatter::FormatUrlForSecurityDisplay( | 205 display_origin_ = url_formatter::FormatUrlForSecurityDisplay( |
| 204 requests[0]->GetOrigin(), | 206 requests[0]->GetOrigin(), |
| 205 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC); | 207 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC); |
| 206 | 208 |
| 207 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 209 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 210 bool show_persistence_toggle = true; |
| 208 for (size_t index = 0; index < requests.size(); index++) { | 211 for (size_t index = 0; index < requests.size(); index++) { |
| 209 DCHECK(index < accept_state.size()); | 212 DCHECK(index < accept_state.size()); |
| 210 // The row is laid out containing a leading-aligned label area and a | 213 // The row is laid out containing a leading-aligned label area and a |
| 211 // trailing column which will be filled if there are multiple permission | 214 // trailing column which will be filled if there are multiple permission |
| 212 // requests. | 215 // requests. |
| 213 views::View* row = new views::View(); | 216 views::View* row = new views::View(); |
| 214 views::GridLayout* row_layout = new views::GridLayout(row); | 217 views::GridLayout* row_layout = new views::GridLayout(row); |
| 215 row->SetLayoutManager(row_layout); | 218 row->SetLayoutManager(row_layout); |
| 216 views::ColumnSet* columns = row_layout->AddColumnSet(0); | 219 views::ColumnSet* columns = row_layout->AddColumnSet(0); |
| 217 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, | 220 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 234 icon->SetImageSize(gfx::Size(kIconSize, kIconSize)); | 237 icon->SetImageSize(gfx::Size(kIconSize, kIconSize)); |
| 235 } | 238 } |
| 236 icon->SetTooltipText(base::string16()); // Redundant with the text fragment | 239 icon->SetTooltipText(base::string16()); // Redundant with the text fragment |
| 237 label_container->AddChildView(icon); | 240 label_container->AddChildView(icon); |
| 238 views::Label* label = | 241 views::Label* label = |
| 239 new views::Label(requests.at(index)->GetMessageTextFragment()); | 242 new views::Label(requests.at(index)->GetMessageTextFragment()); |
| 240 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 243 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 241 label_container->AddChildView(label); | 244 label_container->AddChildView(label); |
| 242 row_layout->AddView(label_container); | 245 row_layout->AddView(label_container); |
| 243 | 246 |
| 247 // Only show the toggle if every request wants to show it. |
| 248 show_persistence_toggle = show_persistence_toggle && |
| 249 requests[index]->ShouldShowPersistenceToggle(); |
| 244 if (requests.size() > 1) { | 250 if (requests.size() > 1) { |
| 245 PermissionCombobox* combobox = new PermissionCombobox( | 251 PermissionCombobox* combobox = new PermissionCombobox( |
| 246 this, index, requests[index]->GetOrigin(), | 252 this, index, requests[index]->GetOrigin(), |
| 247 accept_state[index] ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); | 253 accept_state[index] ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); |
| 248 row_layout->AddView(combobox); | 254 row_layout->AddView(combobox); |
| 249 customize_comboboxes_.push_back(combobox); | 255 customize_comboboxes_.push_back(combobox); |
| 250 } else { | 256 } else { |
| 251 row_layout->AddView(new views::View()); | 257 row_layout->AddView(new views::View()); |
| 252 } | 258 } |
| 253 | 259 |
| 260 // Run this once at the end of the loop over the requests. |
| 261 if (index == (requests.size() - 1) && show_persistence_toggle) { |
| 262 row_layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 263 row_layout->StartRow(0, 0); |
| 264 checkbox_ = new views::Checkbox( |
| 265 l10n_util::GetStringUTF16(IDS_PERMISSIONS_BUBBLE_PERSIST_TEXT)); |
| 266 checkbox_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 267 checkbox_->SetChecked(true); |
| 268 row_layout->AddView(checkbox_); |
| 269 } |
| 270 |
| 254 AddChildView(row); | 271 AddChildView(row); |
| 255 } | 272 } |
| 256 } | 273 } |
| 257 | 274 |
| 258 PermissionsBubbleDialogDelegateView::~PermissionsBubbleDialogDelegateView() { | 275 PermissionsBubbleDialogDelegateView::~PermissionsBubbleDialogDelegateView() { |
| 259 if (owner_) | 276 if (owner_) |
| 260 owner_->Closing(); | 277 owner_->Closing(); |
| 261 } | 278 } |
| 262 | 279 |
| 263 void PermissionsBubbleDialogDelegateView::CloseBubble() { | 280 void PermissionsBubbleDialogDelegateView::CloseBubble() { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 if (button == ui::DIALOG_BUTTON_CANCEL) | 341 if (button == ui::DIALOG_BUTTON_CANCEL) |
| 325 return l10n_util::GetStringUTF16(IDS_PERMISSION_DENY); | 342 return l10n_util::GetStringUTF16(IDS_PERMISSION_DENY); |
| 326 | 343 |
| 327 // The text differs based on whether OK is the only visible button. | 344 // The text differs based on whether OK is the only visible button. |
| 328 return l10n_util::GetStringUTF16(GetDialogButtons() == ui::DIALOG_BUTTON_OK | 345 return l10n_util::GetStringUTF16(GetDialogButtons() == ui::DIALOG_BUTTON_OK |
| 329 ? IDS_OK | 346 ? IDS_OK |
| 330 : IDS_PERMISSION_ALLOW); | 347 : IDS_PERMISSION_ALLOW); |
| 331 } | 348 } |
| 332 | 349 |
| 333 bool PermissionsBubbleDialogDelegateView::Cancel() { | 350 bool PermissionsBubbleDialogDelegateView::Cancel() { |
| 334 if (owner_) | 351 if (owner_) { |
| 352 bool persist = !checkbox_ || checkbox_->checked(); |
| 353 owner_->TogglePersist(persist); |
| 335 owner_->Deny(); | 354 owner_->Deny(); |
| 355 } |
| 336 return true; | 356 return true; |
| 337 } | 357 } |
| 338 | 358 |
| 339 bool PermissionsBubbleDialogDelegateView::Accept() { | 359 bool PermissionsBubbleDialogDelegateView::Accept() { |
| 340 if (owner_) | 360 if (owner_) { |
| 361 bool persist = !checkbox_ || checkbox_->checked(); |
| 362 owner_->TogglePersist(persist); |
| 341 owner_->Accept(); | 363 owner_->Accept(); |
| 364 } |
| 342 return true; | 365 return true; |
| 343 } | 366 } |
| 344 | 367 |
| 345 bool PermissionsBubbleDialogDelegateView::Close() { | 368 bool PermissionsBubbleDialogDelegateView::Close() { |
| 346 // Neither explicit accept nor explicit deny. | 369 // Neither explicit accept nor explicit deny. |
| 347 return true; | 370 return true; |
| 348 } | 371 } |
| 349 | 372 |
| 350 void PermissionsBubbleDialogDelegateView::PermissionSelectionChanged( | 373 void PermissionsBubbleDialogDelegateView::PermissionSelectionChanged( |
| 351 int index, | 374 int index, |
| 352 bool allowed) { | 375 bool allowed) { |
| 353 owner_->Toggle(index, allowed); | 376 owner_->ToggleAccept(index, allowed); |
| 354 } | 377 } |
| 355 | 378 |
| 356 void PermissionsBubbleDialogDelegateView::UpdateAnchor( | 379 void PermissionsBubbleDialogDelegateView::UpdateAnchor( |
| 357 views::View* anchor_view, | 380 views::View* anchor_view, |
| 358 const gfx::Point& anchor_point, | 381 const gfx::Point& anchor_point, |
| 359 views::BubbleBorder::Arrow anchor_arrow) { | 382 views::BubbleBorder::Arrow anchor_arrow) { |
| 360 set_arrow(anchor_arrow); | 383 set_arrow(anchor_arrow); |
| 361 | 384 |
| 362 // Update the border in the bubble: will either add or remove the arrow. | 385 // Update the border in the bubble: will either add or remove the arrow. |
| 363 views::BubbleFrameView* frame = | 386 views::BubbleFrameView* frame = |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 return nullptr; | 466 return nullptr; |
| 444 } | 467 } |
| 445 | 468 |
| 446 void PermissionPromptImpl::Closing() { | 469 void PermissionPromptImpl::Closing() { |
| 447 if (bubble_delegate_) | 470 if (bubble_delegate_) |
| 448 bubble_delegate_ = nullptr; | 471 bubble_delegate_ = nullptr; |
| 449 if (delegate_) | 472 if (delegate_) |
| 450 delegate_->Closing(); | 473 delegate_->Closing(); |
| 451 } | 474 } |
| 452 | 475 |
| 453 void PermissionPromptImpl::Toggle(int index, bool value) { | 476 void PermissionPromptImpl::ToggleAccept(int index, bool value) { |
| 454 if (delegate_) | 477 if (delegate_) |
| 455 delegate_->ToggleAccept(index, value); | 478 delegate_->ToggleAccept(index, value); |
| 456 } | 479 } |
| 457 | 480 |
| 481 void PermissionPromptImpl::TogglePersist(bool value) { |
| 482 if (delegate_) |
| 483 delegate_->TogglePersist(value); |
| 484 } |
| 485 |
| 458 void PermissionPromptImpl::Accept() { | 486 void PermissionPromptImpl::Accept() { |
| 459 if (delegate_) | 487 if (delegate_) |
| 460 delegate_->Accept(); | 488 delegate_->Accept(); |
| 461 } | 489 } |
| 462 | 490 |
| 463 void PermissionPromptImpl::Deny() { | 491 void PermissionPromptImpl::Deny() { |
| 464 if (delegate_) | 492 if (delegate_) |
| 465 delegate_->Deny(); | 493 delegate_->Deny(); |
| 466 } | 494 } |
| OLD | NEW |