Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | |
| 6 | |
| 7 #include "chrome/browser/ui/website_settings/permission_bubble_delegate.h" | |
| 8 | |
| 9 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PermissionBubbleManager); | |
| 10 | |
| 11 void PermissionBubbleManager::AddPermissionBubbleDelegate( | |
| 12 PermissionBubbleDelegate* delegate) { | |
| 13 // Don't re-add existing delegate. | |
| 14 std::vector<PermissionBubbleDelegate*>::iterator di; | |
| 15 for (di = delegates_.begin(); di != delegates_.end(); di++) { | |
| 16 if (*di == delegate) | |
| 17 return; | |
| 18 } | |
| 19 | |
| 20 delegates_.push_back(delegate); | |
| 21 accept_state_.push_back(false); // make default state a delegate property? | |
|
markusheintz_
2014/01/15 23:25:30
Nit: Is this comment a TODO? If so please mark it
Greg Billock
2014/01/16 19:32:50
The current plan is for these bubbles to be modal-
| |
| 22 if (bubble_showing_ && view_) | |
| 23 view_->AddPermissionBubbleDelegate(delegate); | |
| 24 } | |
| 25 | |
| 26 void PermissionBubbleManager::RemovePermissionBubbleDelegate( | |
| 27 PermissionBubbleDelegate* delegate) { | |
| 28 std::vector<PermissionBubbleDelegate*>::iterator di; | |
| 29 std::vector<bool>::iterator ai; | |
| 30 for (di = delegates_.begin(), ai = accept_state_.begin(); | |
| 31 di != delegates_.end(); di++, ai++) { | |
| 32 if (*di == delegate) { | |
| 33 if (bubble_showing_ && view_) | |
| 34 view_->RemovePermissionBubbleDelegate(delegate); | |
| 35 delegates_.erase(di); | |
| 36 accept_state_.erase(ai); | |
| 37 return; | |
| 38 } | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 void PermissionBubbleManager::SetView(PermissionBubbleView* view) { | |
| 43 view_ = view; | |
| 44 if (view_ == NULL) | |
| 45 return; | |
| 46 | |
| 47 if (bubble_showing_) { | |
| 48 view_->Show(delegates_, accept_state_); | |
| 49 } else { | |
| 50 view_->Hide(); | |
| 51 return; | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 PermissionBubbleManager::PermissionBubbleManager( | |
| 56 content::WebContents* web_contents) | |
| 57 : content::WebContentsObserver(web_contents), | |
| 58 bubble_showing_(false), | |
| 59 view_(NULL) { | |
| 60 } | |
| 61 | |
| 62 void PermissionBubbleManager::WebContentsDestroyed( | |
| 63 content::WebContents* web_contents) { | |
| 64 // Synthetic cancel event if the user closes the WebContents. | |
| 65 Closing(); | |
| 66 | |
| 67 // The WebContents is going away; be aggressively paranoid and delete | |
| 68 // ourselves lest other parts of the system attempt to add permission bubbles | |
| 69 // or use us otherwise during the destruction. | |
| 70 web_contents->RemoveUserData(UserDataKey()); | |
| 71 // That was the equivalent of "delete this". This object is now destroyed; | |
| 72 // returning from this function is the only safe thing to do. | |
| 73 } | |
| 74 | |
| 75 void PermissionBubbleManager::ToggleAccept(int delegate_index, bool new_value) { | |
| 76 DCHECK(delegate_index < static_cast<int>(accept_state_.size())); | |
| 77 accept_state_[delegate_index] = new_value; | |
| 78 } | |
| 79 | |
| 80 void PermissionBubbleManager::Accept() { | |
| 81 std::vector<PermissionBubbleDelegate*>::iterator di; | |
| 82 std::vector<bool>::iterator ai; | |
| 83 for (di = delegates_.begin(), ai = accept_state_.begin(); | |
| 84 di != delegates_.end(); di++, ai++) { | |
| 85 if (*ai) | |
| 86 (*di)->PermissionGranted(); | |
| 87 else | |
| 88 (*di)->PermissionDenied(); | |
| 89 } | |
| 90 FinalizeBubble(); | |
| 91 } | |
| 92 | |
| 93 void PermissionBubbleManager::Deny() { | |
| 94 std::vector<PermissionBubbleDelegate*>::iterator di; | |
| 95 for (di = delegates_.begin(); di != delegates_.end(); di++) | |
| 96 (*di)->PermissionDenied(); | |
| 97 FinalizeBubble(); | |
| 98 } | |
| 99 | |
| 100 void PermissionBubbleManager::Closing() { | |
| 101 std::vector<PermissionBubbleDelegate*>::iterator di; | |
| 102 for (di = delegates_.begin(); di != delegates_.end(); di++) | |
| 103 (*di)->Cancelled(); | |
| 104 FinalizeBubble(); | |
| 105 } | |
| 106 | |
| 107 void PermissionBubbleManager::FinalizeBubble() { | |
| 108 std::vector<PermissionBubbleDelegate*>::iterator di; | |
| 109 for (di = delegates_.begin(); di != delegates_.end(); di++) | |
| 110 (*di)->RequestFinished(); | |
| 111 delegates_.clear(); | |
| 112 accept_state_.clear(); | |
| 113 } | |
| 114 | |
| OLD | NEW |