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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/metrics/user_metrics_action.h" | 9 #include "base/metrics/user_metrics_action.h" |
10 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | 10 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 if (group == kEnabled) | 71 if (group == kEnabled) |
72 return true; | 72 return true; |
73 if (group == kDisabled) | 73 if (group == kDisabled) |
74 return false; | 74 return false; |
75 | 75 |
76 return false; | 76 return false; |
77 } | 77 } |
78 | 78 |
79 PermissionBubbleManager::PermissionBubbleManager( | 79 PermissionBubbleManager::PermissionBubbleManager( |
80 content::WebContents* web_contents) | 80 content::WebContents* web_contents) |
81 : content::WebContentsObserver(web_contents), | 81 : content::WebContentsObserver(web_contents), |
82 require_user_gesture_(false), | 82 require_user_gesture_(false), |
83 bubble_showing_(false), | 83 bubble_showing_(false), |
84 view_(NULL), | 84 view_(NULL), |
85 request_url_has_loaded_(false), | 85 request_url_has_loaded_(false), |
86 weak_factory_(this) {} | 86 auto_response_for_test_(NONE), |
| 87 weak_factory_(this) { |
| 88 } |
87 | 89 |
88 PermissionBubbleManager::~PermissionBubbleManager() { | 90 PermissionBubbleManager::~PermissionBubbleManager() { |
89 if (view_ != NULL) | 91 if (view_ != NULL) |
90 view_->SetDelegate(NULL); | 92 view_->SetDelegate(NULL); |
91 | 93 |
92 std::vector<PermissionBubbleRequest*>::iterator requests_iter; | 94 std::vector<PermissionBubbleRequest*>::iterator requests_iter; |
93 for (requests_iter = requests_.begin(); | 95 for (requests_iter = requests_.begin(); |
94 requests_iter != requests_.end(); | 96 requests_iter != requests_.end(); |
95 requests_iter++) { | 97 requests_iter++) { |
96 (*requests_iter)->RequestFinished(); | 98 (*requests_iter)->RequestFinished(); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 // TODO(leng): Currently all requests default to true. If that changes: | 341 // TODO(leng): Currently all requests default to true. If that changes: |
340 // a) Add additional accept_state queues to store default values. | 342 // a) Add additional accept_state queues to store default values. |
341 // b) Change the request API to provide the default value. | 343 // b) Change the request API to provide the default value. |
342 accept_states_.resize(requests_.size(), true); | 344 accept_states_.resize(requests_.size(), true); |
343 } | 345 } |
344 | 346 |
345 // Note: this should appear above Show() for testing, since in that | 347 // Note: this should appear above Show() for testing, since in that |
346 // case we may do in-line calling of finalization. | 348 // case we may do in-line calling of finalization. |
347 bubble_showing_ = true; | 349 bubble_showing_ = true; |
348 view_->Show(requests_, accept_states_); | 350 view_->Show(requests_, accept_states_); |
| 351 |
| 352 // If in testing mode, automatically respond to the bubble that was shown. |
| 353 if (auto_response_for_test_ != NONE) |
| 354 DoAutoResponseForTesting(); |
349 } | 355 } |
350 | 356 |
351 void PermissionBubbleManager::FinalizeBubble() { | 357 void PermissionBubbleManager::FinalizeBubble() { |
352 if (view_) | 358 if (view_) |
353 view_->Hide(); | 359 view_->Hide(); |
354 bubble_showing_ = false; | 360 bubble_showing_ = false; |
355 | 361 |
356 std::vector<PermissionBubbleRequest*>::iterator requests_iter; | 362 std::vector<PermissionBubbleRequest*>::iterator requests_iter; |
357 for (requests_iter = requests_.begin(); | 363 for (requests_iter = requests_.begin(); |
358 requests_iter != requests_.end(); | 364 requests_iter != requests_.end(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 bool PermissionBubbleManager::HasUserGestureRequest( | 413 bool PermissionBubbleManager::HasUserGestureRequest( |
408 const std::vector<PermissionBubbleRequest*>& queue) { | 414 const std::vector<PermissionBubbleRequest*>& queue) { |
409 std::vector<PermissionBubbleRequest*>::const_iterator iter; | 415 std::vector<PermissionBubbleRequest*>::const_iterator iter; |
410 for (iter = queue.begin(); iter != queue.end(); iter++) { | 416 for (iter = queue.begin(); iter != queue.end(); iter++) { |
411 if ((*iter)->HasUserGesture()) | 417 if ((*iter)->HasUserGesture()) |
412 return true; | 418 return true; |
413 } | 419 } |
414 return false; | 420 return false; |
415 } | 421 } |
416 | 422 |
| 423 void PermissionBubbleManager::DoAutoResponseForTesting() { |
| 424 switch (auto_response_for_test_) { |
| 425 case ACCEPT_ALL: |
| 426 Accept(); |
| 427 break; |
| 428 case DENY_ALL: |
| 429 Deny(); |
| 430 break; |
| 431 case DISMISS: |
| 432 Closing(); |
| 433 break; |
| 434 case NONE: |
| 435 NOTREACHED(); |
| 436 } |
| 437 } |
OLD | NEW |