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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/chrome_bubble_manager.cc
diff --git a/chrome/browser/ui/chrome_bubble_manager.cc b/chrome/browser/ui/chrome_bubble_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bd2ed2fe935a7f3e1b3f362efa6a3ebae2b65931
--- /dev/null
+++ b/chrome/browser/ui/chrome_bubble_manager.cc
@@ -0,0 +1,111 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/chrome_bubble_manager.h"
+
+#include "base/location.h"
+#include "chrome/browser/ui/chrome_bubble_manager.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/browser/web_contents_user_data.h"
+
+namespace {
+class ChromeWebContentsObserver
+ : public content::WebContentsObserver,
+ public content::WebContentsUserData<ChromeWebContentsObserver> {
+ public:
+ ~ChromeWebContentsObserver() override;
+
+ void SetBubbleManager(ChromeBubbleManager* manager);
+
+ // WebContentsObserver:
+ void NavigationEntryCommitted(
+ const content::LoadCommittedDetails& details) override;
+ void WebContentsDestroyed() override;
+
+ private:
+ 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
+
+ explicit ChromeWebContentsObserver(content::WebContents* web_contents);
+
+ // 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.
+ ChromeBubbleManager* manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromeWebContentsObserver);
+};
+
+ChromeWebContentsObserver::~ChromeWebContentsObserver() {}
+
+void ChromeWebContentsObserver::ChromeWebContentsObserver::SetBubbleManager(
+ ChromeBubbleManager* manager) {
+ manager_ = manager;
+}
+
+void ChromeWebContentsObserver::NavigationEntryCommitted(
+ const content::LoadCommittedDetails& details) {
+ manager_->NavigationEntryCommitted(web_contents(), details);
+}
+
+void ChromeWebContentsObserver::WebContentsDestroyed() {
+ manager_->WebContentsDestroyed(web_contents());
+}
+
+ChromeWebContentsObserver::ChromeWebContentsObserver(
+ content::WebContents* web_contents)
+ : content::WebContentsObserver(web_contents), manager_(nullptr) {}
+} // namespace
+
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeWebContentsObserver);
+
+ChromeBubbleManager::ChromeBubbleManager() {}
+
+ChromeBubbleManager::~ChromeBubbleManager() {}
+
+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
+ content::WebContents* web_contents) {
+ ChromeWebContentsObserver::CreateForWebContents(web_contents);
+ ChromeWebContentsObserver::FromWebContents(web_contents)
+ ->SetBubbleManager(this);
+}
+
+void ChromeBubbleManager::FullscreenToggle(content::WebContents* context) {
+ UpdateMatchingBubbles(context);
+}
+
+void ChromeBubbleManager::TabBlur(content::WebContents* context) {
+ CloseMatchingBubbles(context, false, BUBBLE_CLOSE_TABSWITCH);
+}
+
+void ChromeBubbleManager::TabFocus(content::WebContents* context) {
+ ShowMatchingBubbles(context);
+}
+
+void ChromeBubbleManager::TabDetached(content::WebContents* context) {
+ CloseMatchingBubbles(context, false, BUBBLE_CLOSE_TABSWITCH);
+}
+
+void ChromeBubbleManager::NavigationEntryCommitted(
+ content::WebContents* context,
+ const content::LoadCommittedDetails& details) {
+ // Hide bubbles if the URL changes or the page is refreshed.
+ if (!details.is_in_page ||
+ details.type == content::NAVIGATION_TYPE_SAME_PAGE ||
+ details.type == content::NAVIGATION_TYPE_EXISTING_PAGE) {
+ CloseMatchingBubbles(context, true, BUBBLE_CLOSE_IGNORE);
+ }
+}
+
+void ChromeBubbleManager::WebContentsDestroyed(content::WebContents* context) {
+ CloseMatchingBubbles(context, true, BUBBLE_CLOSE_IGNORE);
+}
+
+void ChromeBubbleManager::ScheduleShowBubble(
+ base::WeakPtr<BubbleController> controller) {
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&BubbleController::Show,
+ controller));
+}

Powered by Google App Engine
This is Rietveld 408576698