Chromium Code Reviews| 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/permissions/permission_request_manager.h" | 5 #include "chrome/browser/permissions/permission_request_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/feature_list.h" | 10 #include "base/feature_list.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 return; | 126 return; |
| 127 auto range = duplicate_requests_.equal_range(existing_request); | 127 auto range = duplicate_requests_.equal_range(existing_request); |
| 128 for (auto it = range.first; it != range.second; ++it) { | 128 for (auto it = range.first; it != range.second; ++it) { |
| 129 if (request == it->second) | 129 if (request == it->second) |
| 130 return; | 130 return; |
| 131 } | 131 } |
| 132 duplicate_requests_.insert(std::make_pair(existing_request, request)); | 132 duplicate_requests_.insert(std::make_pair(existing_request, request)); |
| 133 return; | 133 return; |
| 134 } | 134 } |
| 135 | 135 |
| 136 if (IsBubbleVisible()) { | |
| 137 if (is_main_frame) { | |
| 138 base::RecordAction( | |
| 139 base::UserMetricsAction("PermissionBubbleRequestQueued")); | |
| 140 queued_requests_.push_back(request); | |
| 141 } else { | |
| 142 base::RecordAction( | |
| 143 base::UserMetricsAction("PermissionBubbleIFrameRequestQueued")); | |
| 144 queued_frame_requests_.push_back(request); | |
| 145 } | |
| 146 return; | |
| 147 } | |
| 148 | |
| 149 if (is_main_frame) { | 136 if (is_main_frame) { |
| 150 requests_.push_back(request); | 137 if (IsBubbleVisible()) { |
| 151 accept_states_.push_back(true); | 138 base::RecordAction( |
| 139 base::UserMetricsAction("PermissionBubbleRequestQueued")); | |
| 140 } | |
| 141 queued_requests_.push_back(request); | |
| 152 } else { | 142 } else { |
| 153 base::RecordAction( | 143 base::RecordAction( |
| 154 base::UserMetricsAction("PermissionBubbleIFrameRequestQueued")); | 144 base::UserMetricsAction("PermissionBubbleIFrameRequestQueued")); |
|
raymes
2017/05/04 05:00:04
this used to only happen if IsBubbleVisible. Shoul
Timothy Loh
2017/05/04 08:22:30
Logic shouldn't be changed here, it was being call
| |
| 155 queued_frame_requests_.push_back(request); | 145 queued_frame_requests_.push_back(request); |
| 156 } | 146 } |
| 157 | 147 |
| 158 ScheduleShowBubble(); | 148 if (!IsBubbleVisible()) |
| 149 ScheduleShowBubble(); | |
| 159 } | 150 } |
| 160 | 151 |
| 161 void PermissionRequestManager::CancelRequest(PermissionRequest* request) { | 152 void PermissionRequestManager::CancelRequest(PermissionRequest* request) { |
| 162 // First look in the queued requests, where we can simply finish the request | 153 // First look in the queued requests, where we can simply finish the request |
| 163 // and go on. | 154 // and go on. |
| 164 std::vector<PermissionRequest*>::iterator requests_iter; | 155 std::vector<PermissionRequest*>::iterator requests_iter; |
| 165 for (requests_iter = queued_requests_.begin(); | 156 for (requests_iter = queued_requests_.begin(); |
| 166 requests_iter != queued_requests_.end(); | 157 requests_iter != queued_requests_.end(); |
| 167 requests_iter++) { | 158 requests_iter++) { |
| 168 if (*requests_iter == request) { | 159 if (*requests_iter == request) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 182 | 173 |
| 183 std::vector<bool>::iterator accepts_iter = accept_states_.begin(); | 174 std::vector<bool>::iterator accepts_iter = accept_states_.begin(); |
| 184 for (requests_iter = requests_.begin(), accepts_iter = accept_states_.begin(); | 175 for (requests_iter = requests_.begin(), accepts_iter = accept_states_.begin(); |
| 185 requests_iter != requests_.end(); | 176 requests_iter != requests_.end(); |
| 186 requests_iter++, accepts_iter++) { | 177 requests_iter++, accepts_iter++) { |
| 187 if (*requests_iter != request) | 178 if (*requests_iter != request) |
| 188 continue; | 179 continue; |
| 189 | 180 |
| 190 // We can simply erase the current entry in the request table if we aren't | 181 // We can simply erase the current entry in the request table if we aren't |
| 191 // showing the dialog, or if we are showing it and it can accept the update. | 182 // showing the dialog, or if we are showing it and it can accept the update. |
| 192 bool can_erase = !IsBubbleVisible() || view_->CanAcceptRequestUpdate(); | 183 bool can_erase = !view_ || view_->CanAcceptRequestUpdate(); |
| 193 if (can_erase) { | 184 if (can_erase) { |
| 194 RequestFinishedIncludingDuplicates(*requests_iter); | 185 RequestFinishedIncludingDuplicates(*requests_iter); |
| 195 requests_.erase(requests_iter); | 186 requests_.erase(requests_iter); |
| 196 accept_states_.erase(accepts_iter); | 187 accept_states_.erase(accepts_iter); |
| 197 | 188 |
| 198 if (IsBubbleVisible()) { | 189 if (view_) { |
| 199 view_->Hide(); | 190 view_->Hide(); |
| 200 // Will redraw the bubble if it is being shown. | 191 // Will redraw the bubble if it is being shown. |
| 201 TriggerShowBubble(); | 192 TriggerShowBubble(); |
| 202 } | 193 } |
| 203 return; | 194 return; |
| 204 } | 195 } |
| 205 | 196 |
| 206 // Cancel the existing request and replace it with a dummy. | 197 // Cancel the existing request and replace it with a dummy. |
| 207 PermissionRequest* cancelled_request = | 198 PermissionRequest* cancelled_request = |
| 208 new CancelledRequest(*requests_iter); | 199 new CancelledRequest(*requests_iter); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 239 view_.reset(); | 230 view_.reset(); |
| 240 } | 231 } |
| 241 | 232 |
| 242 void PermissionRequestManager::DisplayPendingRequests() { | 233 void PermissionRequestManager::DisplayPendingRequests() { |
| 243 if (IsBubbleVisible()) | 234 if (IsBubbleVisible()) |
| 244 return; | 235 return; |
| 245 | 236 |
| 246 view_ = view_factory_.Run(web_contents()); | 237 view_ = view_factory_.Run(web_contents()); |
| 247 view_->SetDelegate(this); | 238 view_->SetDelegate(this); |
| 248 | 239 |
| 240 if (!main_frame_has_fully_loaded_) | |
| 241 return; | |
| 242 if (!requests_.empty()) { | |
| 243 // The previous prompt was hidden due to tab switching. | |
| 244 view_->Show(requests_, accept_states_); | |
| 245 PermissionUmaUtil::PermissionPromptShown(requests_); | |
| 246 NotifyBubbleAdded(); | |
| 247 return; | |
| 248 } | |
|
raymes
2017/05/04 05:00:05
I think it could be better to move this into a sep
Timothy Loh
2017/05/04 08:22:30
Done.
| |
| 249 | |
| 249 TriggerShowBubble(); | 250 TriggerShowBubble(); |
| 250 } | 251 } |
| 251 | 252 |
| 252 void PermissionRequestManager::UpdateAnchorPosition() { | 253 void PermissionRequestManager::UpdateAnchorPosition() { |
| 253 if (view_) | 254 if (view_) |
| 254 view_->UpdateAnchorPosition(); | 255 view_->UpdateAnchorPosition(); |
| 255 } | 256 } |
| 256 | 257 |
| 257 bool PermissionRequestManager::IsBubbleVisible() { | 258 bool PermissionRequestManager::IsBubbleVisible() { |
| 258 return view_ && view_->IsVisible(); | 259 return view_ && !requests_.empty(); |
| 259 } | 260 } |
| 260 | 261 |
| 261 // static | 262 // static |
| 262 bool PermissionRequestManager::IsEnabled() { | 263 bool PermissionRequestManager::IsEnabled() { |
| 263 #if defined(OS_ANDROID) | 264 #if defined(OS_ANDROID) |
| 264 return base::FeatureList::IsEnabled(features::kUseGroupedPermissionInfobars); | 265 return base::FeatureList::IsEnabled(features::kUseGroupedPermissionInfobars); |
| 265 #else | 266 #else |
| 266 return true; | 267 return true; |
| 267 #endif | 268 #endif |
| 268 } | 269 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 | 371 |
| 371 content::BrowserThread::PostTask( | 372 content::BrowserThread::PostTask( |
| 372 content::BrowserThread::UI, FROM_HERE, | 373 content::BrowserThread::UI, FROM_HERE, |
| 373 base::BindOnce(&PermissionRequestManager::TriggerShowBubble, | 374 base::BindOnce(&PermissionRequestManager::TriggerShowBubble, |
| 374 weak_factory_.GetWeakPtr())); | 375 weak_factory_.GetWeakPtr())); |
| 375 } | 376 } |
| 376 | 377 |
| 377 void PermissionRequestManager::TriggerShowBubble() { | 378 void PermissionRequestManager::TriggerShowBubble() { |
| 378 if (!view_) | 379 if (!view_) |
| 379 return; | 380 return; |
| 380 if (IsBubbleVisible()) | 381 if (!requests_.empty()) |
| 381 return; | 382 return; |
|
raymes
2017/05/04 05:00:04
Why not get rid of the above 2 checks and just cal
Timothy Loh
2017/05/04 08:22:30
Just checking IsBubbleVisible won't exit the !view
| |
| 382 if (!main_frame_has_fully_loaded_) | 383 if (!main_frame_has_fully_loaded_) |
| 383 return; | 384 return; |
| 384 if (requests_.empty() && queued_requests_.empty() && | 385 if (queued_requests_.empty() && queued_frame_requests_.empty()) |
| 385 queued_frame_requests_.empty()) { | |
| 386 return; | 386 return; |
| 387 } | |
| 388 | 387 |
| 389 if (requests_.empty()) { | 388 if (queued_requests_.size()) |
| 390 if (queued_requests_.size()) | 389 requests_.swap(queued_requests_); |
| 391 requests_.swap(queued_requests_); | 390 else |
| 392 else | 391 requests_.swap(queued_frame_requests_); |
| 393 requests_.swap(queued_frame_requests_); | |
| 394 | 392 |
| 395 // Sets the default value for each request to be 'accept'. | 393 // Sets the default value for each request to be 'accept'. |
| 396 accept_states_.resize(requests_.size(), true); | 394 accept_states_.resize(requests_.size(), true); |
| 397 } | |
| 398 | 395 |
| 399 view_->Show(requests_, accept_states_); | 396 view_->Show(requests_, accept_states_); |
| 400 PermissionUmaUtil::PermissionPromptShown(requests_); | 397 PermissionUmaUtil::PermissionPromptShown(requests_); |
| 401 NotifyBubbleAdded(); | 398 NotifyBubbleAdded(); |
| 402 | 399 |
| 403 // If in testing mode, automatically respond to the bubble that was shown. | 400 // If in testing mode, automatically respond to the bubble that was shown. |
| 404 if (auto_response_for_test_ != NONE) | 401 if (auto_response_for_test_ != NONE) |
| 405 DoAutoResponseForTesting(); | 402 DoAutoResponseForTesting(); |
| 406 } | 403 } |
| 407 | 404 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 case DENY_ALL: | 523 case DENY_ALL: |
| 527 Deny(); | 524 Deny(); |
| 528 break; | 525 break; |
| 529 case DISMISS: | 526 case DISMISS: |
| 530 Closing(); | 527 Closing(); |
| 531 break; | 528 break; |
| 532 case NONE: | 529 case NONE: |
| 533 NOTREACHED(); | 530 NOTREACHED(); |
| 534 } | 531 } |
| 535 } | 532 } |
| OLD | NEW |