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

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: Partial 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..de6d41ed59a1dd908a489e1902ab3f9024d20a46
--- /dev/null
+++ b/chrome/browser/ui/chrome_bubble_manager.cc
@@ -0,0 +1,113 @@
+// 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 {
please use gerrit instead 2015/08/07 23:02:26 newline after
hcarmona 2015/08/11 02:35:45 Done.
+class ChromeWebContentsObserver
please use gerrit instead 2015/08/07 23:02:26 BubbleManagerWebContentsObserver
hcarmona 2015/08/11 02:35:45 Done.
+ : public content::WebContentsObserver,
+ public content::WebContentsUserData<ChromeWebContentsObserver> {
+ public:
+ ~ChromeWebContentsObserver() override;
+
+ void SetBubbleManager(ChromeBubbleManager* manager);
please use gerrit instead 2015/08/07 23:02:26 Can get from webcontents->browser context, pass th
hcarmona 2015/08/11 02:35:45 Done.
+
+ // WebContentsObserver:
+ void NavigationEntryCommitted(
+ const content::LoadCommittedDetails& details) override;
+ void WebContentsDestroyed() override;
+
+ private:
+ friend class content::WebContentsUserData<ChromeWebContentsObserver>;
+
+ explicit ChromeWebContentsObserver(content::WebContents* web_contents);
+
+ ChromeBubbleManager* manager_; // Weak.
+
+ 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
please use gerrit instead 2015/08/07 23:02:26 newline before, two spaces before //
hcarmona 2015/08/11 02:35:45 Done.
+
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeWebContentsObserver);
+
+ChromeBubbleManager::ChromeBubbleManager() {}
+
+ChromeBubbleManager::~ChromeBubbleManager() {}
+
+void ChromeBubbleManager::ListenToWebContents(
+ 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);
please use gerrit instead 2015/08/07 23:02:26 enum instead of false to clarify what it means
hcarmona 2015/08/11 02:35:45 Done.
+}
+
+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) {
+ // 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 ||
+ 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(
please use gerrit instead 2015/08/07 23:02:26 OK to provide helper, but let's be on UI thread wh
hcarmona 2015/08/11 02:35:45 Done.
+ content::BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&BubbleController::Show,
+ controller));
+}

Powered by Google App Engine
This is Rietveld 408576698