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

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..62c3f685370288adb73869cc251e270876d6a664
--- /dev/null
+++ b/chrome/browser/ui/chrome_bubble_manager.cc
@@ -0,0 +1,101 @@
+// 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/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.
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/chrome_bubble_manager_factory.h"
+#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.
+#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.
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/browser/web_contents_user_data.h"
+
+namespace {
+
+class BubbleManagerWebContentsObserver
+ : public content::WebContentsObserver,
+ 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
+ public:
+ ~BubbleManagerWebContentsObserver() override;
+
+ // WebContentsObserver:
+ void NavigationEntryCommitted(
+ const content::LoadCommittedDetails& details) override;
+ void WebContentsDestroyed() override;
+
+ private:
+ friend class content::WebContentsUserData<BubbleManagerWebContentsObserver>;
+
+ explicit BubbleManagerWebContentsObserver(content::WebContents* web_contents);
+
+ ChromeBubbleManager* manager_; // Weak.
msw 2015/08/13 03:37:21 Maybe keep a WeakPtr?
hcarmona 2015/08/15 02:03:18 Acknowledged.
+
+ DISALLOW_COPY_AND_ASSIGN(BubbleManagerWebContentsObserver);
+};
+
+BubbleManagerWebContentsObserver::~BubbleManagerWebContentsObserver() {}
+
+void BubbleManagerWebContentsObserver::NavigationEntryCommitted(
+ const content::LoadCommittedDetails& details) {
+ manager_->NavigationEntryCommitted(web_contents(), details);
+}
+
+void BubbleManagerWebContentsObserver::WebContentsDestroyed() {
+ manager_->WebContentsDestroyed(web_contents());
+}
+
+BubbleManagerWebContentsObserver::BubbleManagerWebContentsObserver(
+ content::WebContents* web_contents)
+ : content::WebContentsObserver(web_contents) {
+ Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
+ manager_ =
+ ChromeBubbleManagerFactory::GetForBrowserContext(browser->profile());
+}
+
+} // namespace
+
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(BubbleManagerWebContentsObserver);
+
+ChromeBubbleManager::ChromeBubbleManager() {}
+
+ChromeBubbleManager::~ChromeBubbleManager() {}
+
+void ChromeBubbleManager::FullscreenToggle(content::WebContents* context) {
+ MassUpdateBubbles(context, base::Bind(&ChromeBubbleManager::UpdateBubbleUI,
+ 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.
+}
+
+void ChromeBubbleManager::TabBlur(content::WebContents* context) {
+ CloseMatchingBubbles(context, ALLOW_HIDE, BUBBLE_CLOSE_TABSWITCH);
+}
+
+void ChromeBubbleManager::TabFocus(content::WebContents* context) {
+ BubbleManagerWebContentsObserver::CreateForWebContents(context);
+ MassUpdateBubbles(context, base::Bind(&ChromeBubbleManager::ShowBubbleUI,
+ this->AsWeakPtr()));
+}
+
+void ChromeBubbleManager::TabDetached(content::WebContents* context) {
+ CloseMatchingBubbles(context, ALLOW_HIDE, BUBBLE_CLOSE_TABSWITCH);
+}
+
+void ChromeBubbleManager::NavigationEntryCommitted(
+ content::WebContents* context,
+ const content::LoadCommittedDetails& details) {
+ // TODO(hcarmona): Get correct navigation logic here.
+ // Remove similar code from PermissionBubbleManager
+
+ // Hide bubbles if the URL changes or the page is refreshed.
+ if (!details.is_in_page ||
+ 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
+ details.type == content::NAVIGATION_TYPE_EXISTING_PAGE) {
+ CloseMatchingBubbles(context, FORCE_CLOSE, BUBBLE_CLOSE_IGNORE);
+ }
+}
+
+void ChromeBubbleManager::WebContentsDestroyed(content::WebContents* context) {
+ CloseMatchingBubbles(context, FORCE_CLOSE, BUBBLE_CLOSE_IGNORE);
+}

Powered by Google App Engine
This is Rietveld 408576698