| 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/website_settings/permission_bubble_manager.h" | 5 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/user_metrics_action.h" | 10 #include "base/metrics/user_metrics_action.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 } else { | 137 } else { |
| 138 content::RecordAction( | 138 content::RecordAction( |
| 139 base::UserMetricsAction("PermissionBubbleIFrameRequestQueued")); | 139 base::UserMetricsAction("PermissionBubbleIFrameRequestQueued")); |
| 140 queued_frame_requests_.push_back(request); | 140 queued_frame_requests_.push_back(request); |
| 141 } | 141 } |
| 142 return; | 142 return; |
| 143 } | 143 } |
| 144 | 144 |
| 145 if (is_main_frame) { | 145 if (is_main_frame) { |
| 146 requests_.push_back(request); | 146 requests_.push_back(request); |
| 147 // TODO(gbillock): do we need to make default state a request property? | |
| 148 accept_states_.push_back(true); | 147 accept_states_.push_back(true); |
| 149 } else { | 148 } else { |
| 150 content::RecordAction( | 149 content::RecordAction( |
| 151 base::UserMetricsAction("PermissionBubbleIFrameRequestQueued")); | 150 base::UserMetricsAction("PermissionBubbleIFrameRequestQueued")); |
| 152 queued_frame_requests_.push_back(request); | 151 queued_frame_requests_.push_back(request); |
| 153 } | 152 } |
| 154 | 153 |
| 155 ScheduleShowBubble(); | 154 ScheduleShowBubble(); |
| 156 } | 155 } |
| 157 | 156 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 // That was the equivalent of "delete this". This object is now destroyed; | 302 // That was the equivalent of "delete this". This object is now destroyed; |
| 304 // returning from this function is the only safe thing to do. | 303 // returning from this function is the only safe thing to do. |
| 305 } | 304 } |
| 306 | 305 |
| 307 void PermissionBubbleManager::ToggleAccept(int request_index, bool new_value) { | 306 void PermissionBubbleManager::ToggleAccept(int request_index, bool new_value) { |
| 308 DCHECK(request_index < static_cast<int>(accept_states_.size())); | 307 DCHECK(request_index < static_cast<int>(accept_states_.size())); |
| 309 accept_states_[request_index] = new_value; | 308 accept_states_[request_index] = new_value; |
| 310 } | 309 } |
| 311 | 310 |
| 312 void PermissionBubbleManager::Accept() { | 311 void PermissionBubbleManager::Accept() { |
| 312 PermissionUmaUtil::PermissionPromptAccepted(requests_, accept_states_); |
| 313 |
| 313 std::vector<PermissionBubbleRequest*>::iterator requests_iter; | 314 std::vector<PermissionBubbleRequest*>::iterator requests_iter; |
| 314 std::vector<bool>::iterator accepts_iter = accept_states_.begin(); | 315 std::vector<bool>::iterator accepts_iter = accept_states_.begin(); |
| 315 for (requests_iter = requests_.begin(), accepts_iter = accept_states_.begin(); | 316 for (requests_iter = requests_.begin(), accepts_iter = accept_states_.begin(); |
| 316 requests_iter != requests_.end(); | 317 requests_iter != requests_.end(); |
| 317 requests_iter++, accepts_iter++) { | 318 requests_iter++, accepts_iter++) { |
| 318 if (*accepts_iter) { | 319 if (*accepts_iter) { |
| 319 PermissionGrantedIncludingDuplicates(*requests_iter); | 320 PermissionGrantedIncludingDuplicates(*requests_iter); |
| 320 } else { | 321 } else { |
| 321 PermissionDeniedIncludingDuplicates(*requests_iter); | 322 PermissionDeniedIncludingDuplicates(*requests_iter); |
| 322 } | 323 } |
| 323 } | 324 } |
| 324 FinalizeBubble(); | 325 FinalizeBubble(); |
| 325 } | 326 } |
| 326 | 327 |
| 327 void PermissionBubbleManager::Deny() { | 328 void PermissionBubbleManager::Deny() { |
| 329 PermissionUmaUtil::PermissionPromptDenied(requests_); |
| 330 |
| 328 std::vector<PermissionBubbleRequest*>::iterator requests_iter; | 331 std::vector<PermissionBubbleRequest*>::iterator requests_iter; |
| 329 for (requests_iter = requests_.begin(); | 332 for (requests_iter = requests_.begin(); |
| 330 requests_iter != requests_.end(); | 333 requests_iter != requests_.end(); |
| 331 requests_iter++) { | 334 requests_iter++) { |
| 332 PermissionDeniedIncludingDuplicates(*requests_iter); | 335 PermissionDeniedIncludingDuplicates(*requests_iter); |
| 333 } | 336 } |
| 334 FinalizeBubble(); | 337 FinalizeBubble(); |
| 335 } | 338 } |
| 336 | 339 |
| 337 void PermissionBubbleManager::Closing() { | 340 void PermissionBubbleManager::Closing() { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 return; | 372 return; |
| 370 } | 373 } |
| 371 | 374 |
| 372 if (requests_.empty()) { | 375 if (requests_.empty()) { |
| 373 if (queued_requests_.size()) | 376 if (queued_requests_.size()) |
| 374 requests_.swap(queued_requests_); | 377 requests_.swap(queued_requests_); |
| 375 else | 378 else |
| 376 requests_.swap(queued_frame_requests_); | 379 requests_.swap(queued_frame_requests_); |
| 377 | 380 |
| 378 // Sets the default value for each request to be 'accept'. | 381 // Sets the default value for each request to be 'accept'. |
| 379 // TODO(leng): Currently all requests default to true. If that changes: | |
| 380 // a) Add additional accept_state queues to store default values. | |
| 381 // b) Change the request API to provide the default value. | |
| 382 accept_states_.resize(requests_.size(), true); | 382 accept_states_.resize(requests_.size(), true); |
| 383 } | 383 } |
| 384 | 384 |
| 385 view_->Show(requests_, accept_states_); | 385 view_->Show(requests_, accept_states_); |
| 386 PermissionUmaUtil::PermissionPromptShown(requests_); | 386 PermissionUmaUtil::PermissionPromptShown(requests_); |
| 387 NotifyBubbleAdded(); | 387 NotifyBubbleAdded(); |
| 388 | 388 |
| 389 // If in testing mode, automatically respond to the bubble that was shown. | 389 // If in testing mode, automatically respond to the bubble that was shown. |
| 390 if (auto_response_for_test_ != NONE) | 390 if (auto_response_for_test_ != NONE) |
| 391 DoAutoResponseForTesting(); | 391 DoAutoResponseForTesting(); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 case DENY_ALL: | 505 case DENY_ALL: |
| 506 Deny(); | 506 Deny(); |
| 507 break; | 507 break; |
| 508 case DISMISS: | 508 case DISMISS: |
| 509 Closing(); | 509 Closing(); |
| 510 break; | 510 break; |
| 511 case NONE: | 511 case NONE: |
| 512 NOTREACHED(); | 512 NOTREACHED(); |
| 513 } | 513 } |
| 514 } | 514 } |
| OLD | NEW |