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

Side by Side Diff: components/bubble/bubble_manager.cc

Issue 1572743002: Make sure bubbles in Views default to close before their RenderFrameHosts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Move DCHECK string into longer comment Created 4 years, 10 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
« no previous file with comments | « components/bubble/bubble_manager.h ('k') | components/bubble/bubble_manager_mocks.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/bubble/bubble_manager.h" 5 #include "components/bubble/bubble_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "components/bubble/bubble_controller.h" 10 #include "components/bubble/bubble_controller.h"
(...skipping 29 matching lines...) Expand all
40 break; 40 break;
41 } 41 }
42 42
43 return bubble_ref; 43 return bubble_ref;
44 } 44 }
45 45
46 bool BubbleManager::CloseBubble(BubbleReference bubble, 46 bool BubbleManager::CloseBubble(BubbleReference bubble,
47 BubbleCloseReason reason) { 47 BubbleCloseReason reason) {
48 DCHECK(thread_checker_.CalledOnValidThread()); 48 DCHECK(thread_checker_.CalledOnValidThread());
49 DCHECK_NE(manager_state_, ITERATING_BUBBLES); 49 DCHECK_NE(manager_state_, ITERATING_BUBBLES);
50 return CloseAllMatchingBubbles(bubble.get(), reason); 50 return CloseAllMatchingBubbles(bubble.get(), nullptr, reason);
51 } 51 }
52 52
53 void BubbleManager::CloseAllBubbles(BubbleCloseReason reason) { 53 void BubbleManager::CloseAllBubbles(BubbleCloseReason reason) {
54 // The following close reasons don't make sense for multiple bubbles: 54 // The following close reasons don't make sense for multiple bubbles:
55 DCHECK_NE(reason, BUBBLE_CLOSE_ACCEPTED); 55 DCHECK_NE(reason, BUBBLE_CLOSE_ACCEPTED);
56 DCHECK_NE(reason, BUBBLE_CLOSE_CANCELED); 56 DCHECK_NE(reason, BUBBLE_CLOSE_CANCELED);
57 DCHECK(thread_checker_.CalledOnValidThread()); 57 DCHECK(thread_checker_.CalledOnValidThread());
58 DCHECK_NE(manager_state_, ITERATING_BUBBLES); 58 DCHECK_NE(manager_state_, ITERATING_BUBBLES);
59 CloseAllMatchingBubbles(nullptr, reason); 59 CloseAllMatchingBubbles(nullptr, nullptr, reason);
60 } 60 }
61 61
62 void BubbleManager::UpdateAllBubbleAnchors() { 62 void BubbleManager::UpdateAllBubbleAnchors() {
63 DCHECK(thread_checker_.CalledOnValidThread()); 63 DCHECK(thread_checker_.CalledOnValidThread());
64 DCHECK_NE(manager_state_, ITERATING_BUBBLES); 64 DCHECK_NE(manager_state_, ITERATING_BUBBLES);
65 65
66 // Guard against bubbles being added or removed while iterating the bubbles. 66 // Guard against bubbles being added or removed while iterating the bubbles.
67 ManagerState original_state = manager_state_; 67 ManagerState original_state = manager_state_;
68 manager_state_ = ITERATING_BUBBLES; 68 manager_state_ = ITERATING_BUBBLES;
69 for (auto controller : controllers_) 69 for (auto controller : controllers_)
(...skipping 12 matching lines...) Expand all
82 82
83 void BubbleManager::FinalizePendingRequests() { 83 void BubbleManager::FinalizePendingRequests() {
84 // Return if already "Finalized". 84 // Return if already "Finalized".
85 if (manager_state_ == NO_MORE_BUBBLES) 85 if (manager_state_ == NO_MORE_BUBBLES)
86 return; 86 return;
87 87
88 manager_state_ = NO_MORE_BUBBLES; 88 manager_state_ = NO_MORE_BUBBLES;
89 CloseAllBubbles(BUBBLE_CLOSE_FORCED); 89 CloseAllBubbles(BUBBLE_CLOSE_FORCED);
90 } 90 }
91 91
92 bool BubbleManager::CloseAllMatchingBubbles(BubbleController* match, 92 void BubbleManager::CloseBubblesOwnedBy(const content::RenderFrameHost* frame) {
93 BubbleCloseReason reason) { 93 CloseAllMatchingBubbles(nullptr, frame, BUBBLE_CLOSE_FRAME_DESTROYED);
94 }
95
96 bool BubbleManager::CloseAllMatchingBubbles(
97 BubbleController* bubble,
98 const content::RenderFrameHost* owner,
99 BubbleCloseReason reason) {
100 // Specifying both an owning frame and a particular bubble to close doesn't
101 // make sense. If we have a frame, all bubbles owned by that frame need to
102 // have the opportunity to close. If we want to close a specific bubble, then
103 // it should get the close event regardless of which frame owns it. On the
104 // other hand, OR'ing the conditions needs a special case in order to be able
105 // to close all bubbles, so we disallow passing both until a need appears.
106 DCHECK(!bubble || !owner);
107
94 ScopedVector<BubbleController> close_queue; 108 ScopedVector<BubbleController> close_queue;
95 109
96 // Guard against bubbles being added or removed while iterating the bubbles. 110 // Guard against bubbles being added or removed while iterating the bubbles.
97 ManagerState original_state = manager_state_; 111 ManagerState original_state = manager_state_;
98 manager_state_ = ITERATING_BUBBLES; 112 manager_state_ = ITERATING_BUBBLES;
99 for (auto iter = controllers_.begin(); iter != controllers_.end();) { 113 for (auto i = controllers_.begin(); i != controllers_.end();) {
100 if ((!match || match == *iter) && (*iter)->ShouldClose(reason)) { 114 if ((!bubble || bubble == *i) && (!owner || (*i)->OwningFrameIs(owner)) &&
101 close_queue.push_back(*iter); 115 (*i)->ShouldClose(reason)) {
102 iter = controllers_.weak_erase(iter); 116 close_queue.push_back(*i);
117 i = controllers_.weak_erase(i);
103 } else { 118 } else {
104 ++iter; 119 ++i;
105 } 120 }
106 } 121 }
107 manager_state_ = original_state; 122 manager_state_ = original_state;
108 123
109 for (auto controller : close_queue) { 124 for (auto controller : close_queue) {
110 controller->DoClose(); 125 controller->DoClose();
111 126
112 FOR_EACH_OBSERVER(BubbleManagerObserver, observers_, 127 FOR_EACH_OBSERVER(BubbleManagerObserver, observers_,
113 OnBubbleClosed(controller->AsWeakPtr(), reason)); 128 OnBubbleClosed(controller->AsWeakPtr(), reason));
114 } 129 }
115 130
116 return !close_queue.empty(); 131 return !close_queue.empty();
117 } 132 }
OLDNEW
« no previous file with comments | « components/bubble/bubble_manager.h ('k') | components/bubble/bubble_manager_mocks.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698