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

Side by Side Diff: chrome/browser/ui/chrome_bubble_manager.cc

Issue 1251633002: Add BubbleManager to manage bubbles and ChromeBubbleManager for events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Apply Feedback Created 5 years, 4 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/chrome_bubble_manager.h"
6
7 #include "base/location.h"
8 #include "chrome/browser/profiles/profile.h"
msw 2015/08/13 03:37:21 nit: is this really needed? (passing the pointer t
hcarmona 2015/08/15 02:03:18 Done.
9 #include "chrome/browser/ui/browser_finder.h"
10 #include "chrome/browser/ui/chrome_bubble_manager_factory.h"
11 #include "content/public/browser/browser_thread.h"
msw 2015/08/13 03:37:21 nit: is this used?
hcarmona 2015/08/15 02:03:18 Done.
12 #include "content/public/browser/web_contents.h"
msw 2015/08/13 03:37:20 nit: this may not be needed if don't dereference t
hcarmona 2015/08/15 02:03:18 Done.
13 #include "content/public/browser/web_contents_observer.h"
14 #include "content/public/browser/web_contents_user_data.h"
15
16 namespace {
17
18 class BubbleManagerWebContentsObserver
19 : public content::WebContentsObserver,
20 public content::WebContentsUserData<BubbleManagerWebContentsObserver> {
msw 2015/08/13 03:37:21 This pattern seems unnecessary if nothing uses Fro
hcarmona 2015/08/15 02:03:18 Removed
21 public:
22 ~BubbleManagerWebContentsObserver() override;
23
24 // WebContentsObserver:
25 void NavigationEntryCommitted(
26 const content::LoadCommittedDetails& details) override;
27 void WebContentsDestroyed() override;
28
29 private:
30 friend class content::WebContentsUserData<BubbleManagerWebContentsObserver>;
31
32 explicit BubbleManagerWebContentsObserver(content::WebContents* web_contents);
33
34 ChromeBubbleManager* manager_; // Weak.
msw 2015/08/13 03:37:21 Maybe keep a WeakPtr?
hcarmona 2015/08/15 02:03:18 Acknowledged.
35
36 DISALLOW_COPY_AND_ASSIGN(BubbleManagerWebContentsObserver);
37 };
38
39 BubbleManagerWebContentsObserver::~BubbleManagerWebContentsObserver() {}
40
41 void BubbleManagerWebContentsObserver::NavigationEntryCommitted(
42 const content::LoadCommittedDetails& details) {
43 manager_->NavigationEntryCommitted(web_contents(), details);
44 }
45
46 void BubbleManagerWebContentsObserver::WebContentsDestroyed() {
47 manager_->WebContentsDestroyed(web_contents());
48 }
49
50 BubbleManagerWebContentsObserver::BubbleManagerWebContentsObserver(
51 content::WebContents* web_contents)
52 : content::WebContentsObserver(web_contents) {
53 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
54 manager_ =
55 ChromeBubbleManagerFactory::GetForBrowserContext(browser->profile());
56 }
57
58 } // namespace
59
60 DEFINE_WEB_CONTENTS_USER_DATA_KEY(BubbleManagerWebContentsObserver);
61
62 ChromeBubbleManager::ChromeBubbleManager() {}
63
64 ChromeBubbleManager::~ChromeBubbleManager() {}
65
66 void ChromeBubbleManager::FullscreenToggle(content::WebContents* context) {
67 MassUpdateBubbles(context, base::Bind(&ChromeBubbleManager::UpdateBubbleUI,
68 this->AsWeakPtr()));
groby-ooo-7-16 2015/08/13 18:44:38 Why does this require WeakPtr? Can the bubble mana
hcarmona 2015/08/15 02:03:18 No longer necessary.
69 }
70
71 void ChromeBubbleManager::TabBlur(content::WebContents* context) {
72 CloseMatchingBubbles(context, ALLOW_HIDE, BUBBLE_CLOSE_TABSWITCH);
73 }
74
75 void ChromeBubbleManager::TabFocus(content::WebContents* context) {
76 BubbleManagerWebContentsObserver::CreateForWebContents(context);
77 MassUpdateBubbles(context, base::Bind(&ChromeBubbleManager::ShowBubbleUI,
78 this->AsWeakPtr()));
79 }
80
81 void ChromeBubbleManager::TabDetached(content::WebContents* context) {
82 CloseMatchingBubbles(context, ALLOW_HIDE, BUBBLE_CLOSE_TABSWITCH);
83 }
84
85 void ChromeBubbleManager::NavigationEntryCommitted(
86 content::WebContents* context,
87 const content::LoadCommittedDetails& details) {
88 // TODO(hcarmona): Get correct navigation logic here.
89 // Remove similar code from PermissionBubbleManager
90
91 // Hide bubbles if the URL changes or the page is refreshed.
92 if (!details.is_in_page ||
93 details.type == content::NAVIGATION_TYPE_SAME_PAGE ||
msw 2015/08/13 03:37:21 q: did you mean != here?
hcarmona 2015/08/13 20:50:35 I will revert any changes to this logic from what
94 details.type == content::NAVIGATION_TYPE_EXISTING_PAGE) {
95 CloseMatchingBubbles(context, FORCE_CLOSE, BUBBLE_CLOSE_IGNORE);
96 }
97 }
98
99 void ChromeBubbleManager::WebContentsDestroyed(content::WebContents* context) {
100 CloseMatchingBubbles(context, FORCE_CLOSE, BUBBLE_CLOSE_IGNORE);
101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698