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

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/ui/chrome_bubble_manager.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/web_contents.h"
11 #include "content/public/browser/web_contents_observer.h"
12 #include "content/public/browser/web_contents_user_data.h"
13
14 namespace {
15 class ChromeWebContentsObserver
16 : public content::WebContentsObserver,
17 public content::WebContentsUserData<ChromeWebContentsObserver> {
18 public:
19 ~ChromeWebContentsObserver() override;
20
21 void SetBubbleManager(ChromeBubbleManager* manager);
22
23 // WebContentsObserver:
24 void NavigationEntryCommitted(
25 const content::LoadCommittedDetails& details) override;
26 void WebContentsDestroyed() override;
27
28 private:
29 friend class content::WebContentsUserData<ChromeWebContentsObserver>;
groby-ooo-7-16 2015/08/06 21:32:55 We public inherit from that - why do we need to fr
hcarmona 2015/08/07 02:12:58 This is done because the constructor is private.
please use gerrit instead 2015/08/07 20:34:28 That's the API they seem to recommend here: https
30
31 explicit ChromeWebContentsObserver(content::WebContents* web_contents);
32
33 // Weak.
groby-ooo-7-16 2015/08/06 21:32:55 Just add comment at the end. Save a line :)
hcarmona 2015/08/07 02:12:58 Line saved.
34 ChromeBubbleManager* manager_;
35
36 DISALLOW_COPY_AND_ASSIGN(ChromeWebContentsObserver);
37 };
38
39 ChromeWebContentsObserver::~ChromeWebContentsObserver() {}
40
41 void ChromeWebContentsObserver::ChromeWebContentsObserver::SetBubbleManager(
42 ChromeBubbleManager* manager) {
43 manager_ = manager;
44 }
45
46 void ChromeWebContentsObserver::NavigationEntryCommitted(
47 const content::LoadCommittedDetails& details) {
48 manager_->NavigationEntryCommitted(web_contents(), details);
49 }
50
51 void ChromeWebContentsObserver::WebContentsDestroyed() {
52 manager_->WebContentsDestroyed(web_contents());
53 }
54
55 ChromeWebContentsObserver::ChromeWebContentsObserver(
56 content::WebContents* web_contents)
57 : content::WebContentsObserver(web_contents), manager_(nullptr) {}
58 } // namespace
59
60 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeWebContentsObserver);
61
62 ChromeBubbleManager::ChromeBubbleManager() {}
63
64 ChromeBubbleManager::~ChromeBubbleManager() {}
65
66 void ChromeBubbleManager::ListenToWebContents(
groby-ooo-7-16 2015/08/06 21:32:55 Who invokes that? Shouldn't bubbles at least on Ch
hcarmona 2015/08/07 02:12:58 Currently used in the BrowserView. How do we set t
67 content::WebContents* web_contents) {
68 ChromeWebContentsObserver::CreateForWebContents(web_contents);
69 ChromeWebContentsObserver::FromWebContents(web_contents)
70 ->SetBubbleManager(this);
71 }
72
73 void ChromeBubbleManager::FullscreenToggle(content::WebContents* context) {
74 UpdateMatchingBubbles(context);
75 }
76
77 void ChromeBubbleManager::TabBlur(content::WebContents* context) {
78 CloseMatchingBubbles(context, false, BUBBLE_CLOSE_TABSWITCH);
79 }
80
81 void ChromeBubbleManager::TabFocus(content::WebContents* context) {
82 ShowMatchingBubbles(context);
83 }
84
85 void ChromeBubbleManager::TabDetached(content::WebContents* context) {
86 CloseMatchingBubbles(context, false, BUBBLE_CLOSE_TABSWITCH);
87 }
88
89 void ChromeBubbleManager::NavigationEntryCommitted(
90 content::WebContents* context,
91 const content::LoadCommittedDetails& details) {
92 // Hide bubbles if the URL changes or the page is refreshed.
93 if (!details.is_in_page ||
94 details.type == content::NAVIGATION_TYPE_SAME_PAGE ||
95 details.type == content::NAVIGATION_TYPE_EXISTING_PAGE) {
96 CloseMatchingBubbles(context, true, BUBBLE_CLOSE_IGNORE);
97 }
98 }
99
100 void ChromeBubbleManager::WebContentsDestroyed(content::WebContents* context) {
101 CloseMatchingBubbles(context, true, BUBBLE_CLOSE_IGNORE);
102 }
103
104 void ChromeBubbleManager::ScheduleShowBubble(
105 base::WeakPtr<BubbleController> controller) {
106 content::BrowserThread::PostTask(
107 content::BrowserThread::UI,
108 FROM_HERE,
109 base::Bind(&BubbleController::Show,
110 controller));
111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698