Chromium Code Reviews| 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); |
| +} |