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

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 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* persist_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 persist_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
250 AddChildView(row); 256 AddChildView(row);
251 } 257 }
258
259 if (show_persistence_toggle) {
260 persist_checkbox_ = new views::Checkbox(
261 l10n_util::GetStringUTF16(IDS_PERMISSIONS_BUBBLE_PERSIST_TEXT));
262 persist_checkbox_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
263 persist_checkbox_->SetChecked(true);
264 AddChildView(persist_checkbox_);
265 }
252 } 266 }
253 267
254 PermissionsBubbleDialogDelegateView::~PermissionsBubbleDialogDelegateView() { 268 PermissionsBubbleDialogDelegateView::~PermissionsBubbleDialogDelegateView() {
255 if (owner_) 269 if (owner_)
256 owner_->Closing(); 270 owner_->Closing();
257 } 271 }
258 272
259 void PermissionsBubbleDialogDelegateView::CloseBubble() { 273 void PermissionsBubbleDialogDelegateView::CloseBubble() {
260 owner_ = nullptr; 274 owner_ = nullptr;
261 GetWidget()->Close(); 275 GetWidget()->Close();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 if (button == ui::DIALOG_BUTTON_CANCEL) 334 if (button == ui::DIALOG_BUTTON_CANCEL)
321 return l10n_util::GetStringUTF16(IDS_PERMISSION_DENY); 335 return l10n_util::GetStringUTF16(IDS_PERMISSION_DENY);
322 336
323 // The text differs based on whether OK is the only visible button. 337 // The text differs based on whether OK is the only visible button.
324 return l10n_util::GetStringUTF16(GetDialogButtons() == ui::DIALOG_BUTTON_OK 338 return l10n_util::GetStringUTF16(GetDialogButtons() == ui::DIALOG_BUTTON_OK
325 ? IDS_OK 339 ? IDS_OK
326 : IDS_PERMISSION_ALLOW); 340 : IDS_PERMISSION_ALLOW);
327 } 341 }
328 342
329 bool PermissionsBubbleDialogDelegateView::Cancel() { 343 bool PermissionsBubbleDialogDelegateView::Cancel() {
330 if (owner_) 344 if (owner_) {
345 owner_->TogglePersist(!persist_checkbox_ || persist_checkbox_->checked());
331 owner_->Deny(); 346 owner_->Deny();
347 }
332 return true; 348 return true;
333 } 349 }
334 350
335 bool PermissionsBubbleDialogDelegateView::Accept() { 351 bool PermissionsBubbleDialogDelegateView::Accept() {
336 if (owner_) 352 if (owner_) {
353 owner_->TogglePersist(!persist_checkbox_ || persist_checkbox_->checked());
337 owner_->Accept(); 354 owner_->Accept();
355 }
338 return true; 356 return true;
339 } 357 }
340 358
341 bool PermissionsBubbleDialogDelegateView::Close() { 359 bool PermissionsBubbleDialogDelegateView::Close() {
342 // Neither explicit accept nor explicit deny. 360 // Neither explicit accept nor explicit deny.
343 return true; 361 return true;
344 } 362 }
345 363
346 void PermissionsBubbleDialogDelegateView::PermissionSelectionChanged( 364 void PermissionsBubbleDialogDelegateView::PermissionSelectionChanged(
347 int index, 365 int index,
348 bool allowed) { 366 bool allowed) {
349 owner_->Toggle(index, allowed); 367 owner_->ToggleAccept(index, allowed);
350 } 368 }
351 369
352 void PermissionsBubbleDialogDelegateView::UpdateAnchor( 370 void PermissionsBubbleDialogDelegateView::UpdateAnchor(
353 views::View* anchor_view, 371 views::View* anchor_view,
354 const gfx::Point& anchor_point, 372 const gfx::Point& anchor_point,
355 views::BubbleBorder::Arrow anchor_arrow) { 373 views::BubbleBorder::Arrow anchor_arrow) {
356 set_arrow(anchor_arrow); 374 set_arrow(anchor_arrow);
357 375
358 // Update the border in the bubble: will either add or remove the arrow. 376 // Update the border in the bubble: will either add or remove the arrow.
359 views::BubbleFrameView* frame = 377 views::BubbleFrameView* frame =
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 return nullptr; 457 return nullptr;
440 } 458 }
441 459
442 void PermissionPromptImpl::Closing() { 460 void PermissionPromptImpl::Closing() {
443 if (bubble_delegate_) 461 if (bubble_delegate_)
444 bubble_delegate_ = nullptr; 462 bubble_delegate_ = nullptr;
445 if (delegate_) 463 if (delegate_)
446 delegate_->Closing(); 464 delegate_->Closing();
447 } 465 }
448 466
449 void PermissionPromptImpl::Toggle(int index, bool value) { 467 void PermissionPromptImpl::ToggleAccept(int index, bool value) {
450 if (delegate_) 468 if (delegate_)
451 delegate_->ToggleAccept(index, value); 469 delegate_->ToggleAccept(index, value);
452 } 470 }
453 471
472 void PermissionPromptImpl::TogglePersist(bool value) {
473 if (delegate_)
474 delegate_->TogglePersist(value);
475 }
476
454 void PermissionPromptImpl::Accept() { 477 void PermissionPromptImpl::Accept() {
455 if (delegate_) 478 if (delegate_)
456 delegate_->Accept(); 479 delegate_->Accept();
457 } 480 }
458 481
459 void PermissionPromptImpl::Deny() { 482 void PermissionPromptImpl::Deny() {
460 if (delegate_) 483 if (delegate_)
461 delegate_->Deny(); 484 delegate_->Deny();
462 } 485 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698