Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: chrome/browser/ui/views/website_settings/permission_prompt_impl.cc

Issue 2258763002: Add a feature-controlled persistence checkbox to geolocation prompts on desktop Views platforms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission-infobardelegate-clean
Patch Set: Rebase, add dependent Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 void UpdateAnchor(views::View* anchor_view, 172 void UpdateAnchor(views::View* anchor_view,
173 const gfx::Point& anchor_point, 173 const gfx::Point& anchor_point,
174 views::BubbleBorder::Arrow anchor_arrow); 174 views::BubbleBorder::Arrow anchor_arrow);
175 175
176 private: 176 private:
177 PermissionPromptImpl* owner_; 177 PermissionPromptImpl* owner_;
178 bool multiple_requests_; 178 bool multiple_requests_;
179 base::string16 display_origin_; 179 base::string16 display_origin_;
180 std::unique_ptr<PermissionMenuModel> menu_button_model_; 180 std::unique_ptr<PermissionMenuModel> menu_button_model_;
181 std::vector<PermissionCombobox*> customize_comboboxes_; 181 std::vector<PermissionCombobox*> customize_comboboxes_;
182 views::Checkbox* checkbox_;
182 183
183 DISALLOW_COPY_AND_ASSIGN(PermissionsBubbleDialogDelegateView); 184 DISALLOW_COPY_AND_ASSIGN(PermissionsBubbleDialogDelegateView);
184 }; 185 };
185 186
186 PermissionsBubbleDialogDelegateView::PermissionsBubbleDialogDelegateView( 187 PermissionsBubbleDialogDelegateView::PermissionsBubbleDialogDelegateView(
187 PermissionPromptImpl* owner, 188 PermissionPromptImpl* owner,
188 const std::vector<PermissionRequest*>& requests, 189 const std::vector<PermissionRequest*>& requests,
189 const std::vector<bool>& accept_state) 190 const std::vector<bool>& accept_state)
190 : owner_(owner), 191 : owner_(owner),
191 multiple_requests_(requests.size() > 1) { 192 multiple_requests_(requests.size() > 1),
193 checkbox_(nullptr) {
192 DCHECK(!requests.empty()); 194 DCHECK(!requests.empty());
193 195
194 set_close_on_deactivate(false); 196 set_close_on_deactivate(false);
195 197
196 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 198 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0,
197 kItemMajorSpacing)); 199 kItemMajorSpacing));
198 200
199 display_origin_ = url_formatter::FormatUrlForSecurityDisplay( 201 display_origin_ = url_formatter::FormatUrlForSecurityDisplay(
200 requests[0]->GetOrigin(), 202 requests[0]->GetOrigin(),
201 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC); 203 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
202 204
203 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 205 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
206 bool show_persistence_toggle = true;
204 for (size_t index = 0; index < requests.size(); index++) { 207 for (size_t index = 0; index < requests.size(); index++) {
205 DCHECK(index < accept_state.size()); 208 DCHECK(index < accept_state.size());
206 // The row is laid out containing a leading-aligned label area and a 209 // The row is laid out containing a leading-aligned label area and a
207 // trailing column which will be filled if there are multiple permission 210 // trailing column which will be filled if there are multiple permission
208 // requests. 211 // requests.
209 views::View* row = new views::View(); 212 views::View* row = new views::View();
210 views::GridLayout* row_layout = new views::GridLayout(row); 213 views::GridLayout* row_layout = new views::GridLayout(row);
211 row->SetLayoutManager(row_layout); 214 row->SetLayoutManager(row_layout);
212 views::ColumnSet* columns = row_layout->AddColumnSet(0); 215 views::ColumnSet* columns = row_layout->AddColumnSet(0);
213 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 216 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL,
(...skipping 16 matching lines...) Expand all
230 icon->SetImageSize(gfx::Size(kIconSize, kIconSize)); 233 icon->SetImageSize(gfx::Size(kIconSize, kIconSize));
231 } 234 }
232 icon->SetTooltipText(base::string16()); // Redundant with the text fragment 235 icon->SetTooltipText(base::string16()); // Redundant with the text fragment
233 label_container->AddChildView(icon); 236 label_container->AddChildView(icon);
234 views::Label* label = 237 views::Label* label =
235 new views::Label(requests.at(index)->GetMessageTextFragment()); 238 new views::Label(requests.at(index)->GetMessageTextFragment());
236 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 239 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
237 label_container->AddChildView(label); 240 label_container->AddChildView(label);
238 row_layout->AddView(label_container); 241 row_layout->AddView(label_container);
239 242
243 // Only show the toggle if every request wants to show it.
244 show_persistence_toggle = show_persistence_toggle &&
245 requests[index]->ShouldShowPersistenceToggle();
240 if (requests.size() > 1) { 246 if (requests.size() > 1) {
241 PermissionCombobox* combobox = new PermissionCombobox( 247 PermissionCombobox* combobox = new PermissionCombobox(
242 this, index, requests[index]->GetOrigin(), 248 this, index, requests[index]->GetOrigin(),
243 accept_state[index] ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); 249 accept_state[index] ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK);
244 row_layout->AddView(combobox); 250 row_layout->AddView(combobox);
245 customize_comboboxes_.push_back(combobox); 251 customize_comboboxes_.push_back(combobox);
246 } else { 252 } else {
247 row_layout->AddView(new views::View()); 253 row_layout->AddView(new views::View());
248 } 254 }
249 255
256 // Run this once at the end of the loop over the requests.
257 if (index == (requests.size() - 1) && show_persistence_toggle) {
258 row_layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
259 row_layout->StartRow(0, 0);
260 checkbox_ = new views::Checkbox(
261 l10n_util::GetStringUTF16(IDS_PERMISSIONS_BUBBLE_PERSIST_TEXT));
262 checkbox_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
263 checkbox_->SetChecked(true);
264 row_layout->AddView(checkbox_);
265 }
raymes 2016/08/24 04:00:18 I'm no views expert so we should get someone with
dominickn 2016/08/24 06:30:57 Definitely - I didn't want to land this without a
266
250 AddChildView(row); 267 AddChildView(row);
251 } 268 }
252 } 269 }
253 270
254 PermissionsBubbleDialogDelegateView::~PermissionsBubbleDialogDelegateView() { 271 PermissionsBubbleDialogDelegateView::~PermissionsBubbleDialogDelegateView() {
255 if (owner_) 272 if (owner_)
256 owner_->Closing(); 273 owner_->Closing();
257 } 274 }
258 275
259 void PermissionsBubbleDialogDelegateView::CloseBubble() { 276 void PermissionsBubbleDialogDelegateView::CloseBubble() {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 if (button == ui::DIALOG_BUTTON_CANCEL) 337 if (button == ui::DIALOG_BUTTON_CANCEL)
321 return l10n_util::GetStringUTF16(IDS_PERMISSION_DENY); 338 return l10n_util::GetStringUTF16(IDS_PERMISSION_DENY);
322 339
323 // The text differs based on whether OK is the only visible button. 340 // The text differs based on whether OK is the only visible button.
324 return l10n_util::GetStringUTF16(GetDialogButtons() == ui::DIALOG_BUTTON_OK 341 return l10n_util::GetStringUTF16(GetDialogButtons() == ui::DIALOG_BUTTON_OK
325 ? IDS_OK 342 ? IDS_OK
326 : IDS_PERMISSION_ALLOW); 343 : IDS_PERMISSION_ALLOW);
327 } 344 }
328 345
329 bool PermissionsBubbleDialogDelegateView::Cancel() { 346 bool PermissionsBubbleDialogDelegateView::Cancel() {
330 if (owner_) 347 if (owner_) {
348 bool persist = !checkbox_ || checkbox_->checked();
349 owner_->TogglePersist(persist);
331 owner_->Deny(); 350 owner_->Deny();
351 }
332 return true; 352 return true;
333 } 353 }
334 354
335 bool PermissionsBubbleDialogDelegateView::Accept() { 355 bool PermissionsBubbleDialogDelegateView::Accept() {
336 if (owner_) 356 if (owner_) {
357 bool persist = !checkbox_ || checkbox_->checked();
358 owner_->TogglePersist(persist);
337 owner_->Accept(); 359 owner_->Accept();
360 }
338 return true; 361 return true;
339 } 362 }
340 363
341 bool PermissionsBubbleDialogDelegateView::Close() { 364 bool PermissionsBubbleDialogDelegateView::Close() {
342 // Neither explicit accept nor explicit deny. 365 // Neither explicit accept nor explicit deny.
343 return true; 366 return true;
344 } 367 }
345 368
346 void PermissionsBubbleDialogDelegateView::PermissionSelectionChanged( 369 void PermissionsBubbleDialogDelegateView::PermissionSelectionChanged(
347 int index, 370 int index,
348 bool allowed) { 371 bool allowed) {
349 owner_->Toggle(index, allowed); 372 owner_->ToggleAccept(index, allowed);
350 } 373 }
351 374
352 void PermissionsBubbleDialogDelegateView::UpdateAnchor( 375 void PermissionsBubbleDialogDelegateView::UpdateAnchor(
353 views::View* anchor_view, 376 views::View* anchor_view,
354 const gfx::Point& anchor_point, 377 const gfx::Point& anchor_point,
355 views::BubbleBorder::Arrow anchor_arrow) { 378 views::BubbleBorder::Arrow anchor_arrow) {
356 set_arrow(anchor_arrow); 379 set_arrow(anchor_arrow);
357 380
358 // Update the border in the bubble: will either add or remove the arrow. 381 // Update the border in the bubble: will either add or remove the arrow.
359 views::BubbleFrameView* frame = 382 views::BubbleFrameView* frame =
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 return nullptr; 462 return nullptr;
440 } 463 }
441 464
442 void PermissionPromptImpl::Closing() { 465 void PermissionPromptImpl::Closing() {
443 if (bubble_delegate_) 466 if (bubble_delegate_)
444 bubble_delegate_ = nullptr; 467 bubble_delegate_ = nullptr;
445 if (delegate_) 468 if (delegate_)
446 delegate_->Closing(); 469 delegate_->Closing();
447 } 470 }
448 471
449 void PermissionPromptImpl::Toggle(int index, bool value) { 472 void PermissionPromptImpl::ToggleAccept(int index, bool value) {
450 if (delegate_) 473 if (delegate_)
451 delegate_->ToggleAccept(index, value); 474 delegate_->ToggleAccept(index, value);
452 } 475 }
453 476
477 void PermissionPromptImpl::TogglePersist(bool value) {
478 if (delegate_)
479 delegate_->TogglePersist(value);
480 }
481
454 void PermissionPromptImpl::Accept() { 482 void PermissionPromptImpl::Accept() {
455 if (delegate_) 483 if (delegate_)
456 delegate_->Accept(); 484 delegate_->Accept();
457 } 485 }
458 486
459 void PermissionPromptImpl::Deny() { 487 void PermissionPromptImpl::Deny() {
460 if (delegate_) 488 if (delegate_)
461 delegate_->Deny(); 489 delegate_->Deny();
462 } 490 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698