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

Side by Side Diff: chrome/browser/ui/website_settings/permission_bubble_manager.cc

Issue 121113007: [WebsiteSettings] API for permissions bubbles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: destructor Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
(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 // TODO(gbillock): do we need to make default state a delegate property?
22 accept_state_.push_back(false);
23 if (bubble_showing_ && view_)
24 view_->AddPermissionBubbleDelegate(delegate);
25 }
26
27 void PermissionBubbleManager::RemovePermissionBubbleDelegate(
28 PermissionBubbleDelegate* delegate) {
29 std::vector<PermissionBubbleDelegate*>::iterator di;
30 std::vector<bool>::iterator ai;
31 for (di = delegates_.begin(), ai = accept_state_.begin();
32 di != delegates_.end(); di++, ai++) {
33 if (*di == delegate) {
34 if (bubble_showing_ && view_)
35 view_->RemovePermissionBubbleDelegate(delegate);
36 delegates_.erase(di);
37 accept_state_.erase(ai);
38 return;
39 }
40 }
41 }
42
43 void PermissionBubbleManager::SetView(PermissionBubbleView* view) {
44 view_ = view;
45 if (view_ == NULL)
46 return;
47
48 if (bubble_showing_) {
49 view_->Show(delegates_, accept_state_);
50 } else {
51 view_->Hide();
52 return;
53 }
54 }
55
56 PermissionBubbleManager::PermissionBubbleManager(
57 content::WebContents* web_contents)
58 : content::WebContentsObserver(web_contents),
59 bubble_showing_(false),
60 view_(NULL) {
61 }
62
63 PermissionBubbleManager::~PermissionBubbleManager() {}
64
65 void PermissionBubbleManager::WebContentsDestroyed(
66 content::WebContents* web_contents) {
67 // Synthetic cancel event if the user closes the WebContents.
68 Closing();
69
70 // The WebContents is going away; be aggressively paranoid and delete
71 // ourselves lest other parts of the system attempt to add permission bubbles
72 // or use us otherwise during the destruction.
73 web_contents->RemoveUserData(UserDataKey());
74 // That was the equivalent of "delete this". This object is now destroyed;
75 // returning from this function is the only safe thing to do.
76 }
77
78 void PermissionBubbleManager::ToggleAccept(int delegate_index, bool new_value) {
79 DCHECK(delegate_index < static_cast<int>(accept_state_.size()));
80 accept_state_[delegate_index] = new_value;
81 }
82
83 void PermissionBubbleManager::Accept() {
84 std::vector<PermissionBubbleDelegate*>::iterator di;
85 std::vector<bool>::iterator ai;
86 for (di = delegates_.begin(), ai = accept_state_.begin();
87 di != delegates_.end(); di++, ai++) {
88 if (*ai)
89 (*di)->PermissionGranted();
90 else
91 (*di)->PermissionDenied();
92 }
93 FinalizeBubble();
94 }
95
96 void PermissionBubbleManager::Deny() {
97 std::vector<PermissionBubbleDelegate*>::iterator di;
98 for (di = delegates_.begin(); di != delegates_.end(); di++)
99 (*di)->PermissionDenied();
100 FinalizeBubble();
101 }
102
103 void PermissionBubbleManager::Closing() {
104 std::vector<PermissionBubbleDelegate*>::iterator di;
105 for (di = delegates_.begin(); di != delegates_.end(); di++)
106 (*di)->Cancelled();
107 FinalizeBubble();
108 }
109
110 void PermissionBubbleManager::FinalizeBubble() {
111 std::vector<PermissionBubbleDelegate*>::iterator di;
112 for (di = delegates_.begin(); di != delegates_.end(); di++)
113 (*di)->RequestFinished();
114 delegates_.clear();
115 accept_state_.clear();
116 }
117
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698