Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 { | |
|
please use gerrit instead
2015/08/07 23:02:26
newline after
hcarmona
2015/08/11 02:35:45
Done.
| |
| 15 class ChromeWebContentsObserver | |
|
please use gerrit instead
2015/08/07 23:02:26
BubbleManagerWebContentsObserver
hcarmona
2015/08/11 02:35:45
Done.
| |
| 16 : public content::WebContentsObserver, | |
| 17 public content::WebContentsUserData<ChromeWebContentsObserver> { | |
| 18 public: | |
| 19 ~ChromeWebContentsObserver() override; | |
| 20 | |
| 21 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.
| |
| 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>; | |
| 30 | |
| 31 explicit ChromeWebContentsObserver(content::WebContents* web_contents); | |
| 32 | |
| 33 ChromeBubbleManager* manager_; // Weak. | |
| 34 | |
| 35 DISALLOW_COPY_AND_ASSIGN(ChromeWebContentsObserver); | |
| 36 }; | |
| 37 | |
| 38 ChromeWebContentsObserver::~ChromeWebContentsObserver() {} | |
| 39 | |
| 40 void ChromeWebContentsObserver::ChromeWebContentsObserver::SetBubbleManager( | |
| 41 ChromeBubbleManager* manager) { | |
| 42 manager_ = manager; | |
| 43 } | |
| 44 | |
| 45 void ChromeWebContentsObserver::NavigationEntryCommitted( | |
| 46 const content::LoadCommittedDetails& details) { | |
| 47 manager_->NavigationEntryCommitted(web_contents(), details); | |
| 48 } | |
| 49 | |
| 50 void ChromeWebContentsObserver::WebContentsDestroyed() { | |
| 51 manager_->WebContentsDestroyed(web_contents()); | |
| 52 } | |
| 53 | |
| 54 ChromeWebContentsObserver::ChromeWebContentsObserver( | |
| 55 content::WebContents* web_contents) | |
| 56 : content::WebContentsObserver(web_contents), manager_(nullptr) {} | |
| 57 } // namespace | |
|
please use gerrit instead
2015/08/07 23:02:26
newline before, two spaces before //
hcarmona
2015/08/11 02:35:45
Done.
| |
| 58 | |
| 59 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeWebContentsObserver); | |
| 60 | |
| 61 ChromeBubbleManager::ChromeBubbleManager() {} | |
| 62 | |
| 63 ChromeBubbleManager::~ChromeBubbleManager() {} | |
| 64 | |
| 65 void ChromeBubbleManager::ListenToWebContents( | |
| 66 content::WebContents* web_contents) { | |
| 67 ChromeWebContentsObserver::CreateForWebContents(web_contents); | |
| 68 ChromeWebContentsObserver::FromWebContents(web_contents) | |
| 69 ->SetBubbleManager(this); | |
| 70 } | |
| 71 | |
| 72 void ChromeBubbleManager::FullscreenToggle(content::WebContents* context) { | |
| 73 UpdateMatchingBubbles(context); | |
| 74 } | |
| 75 | |
| 76 void ChromeBubbleManager::TabBlur(content::WebContents* context) { | |
| 77 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.
| |
| 78 } | |
| 79 | |
| 80 void ChromeBubbleManager::TabFocus(content::WebContents* context) { | |
| 81 ShowMatchingBubbles(context); | |
| 82 } | |
| 83 | |
| 84 void ChromeBubbleManager::TabDetached(content::WebContents* context) { | |
| 85 CloseMatchingBubbles(context, false, BUBBLE_CLOSE_TABSWITCH); | |
| 86 } | |
| 87 | |
| 88 void ChromeBubbleManager::NavigationEntryCommitted( | |
| 89 content::WebContents* context, | |
| 90 const content::LoadCommittedDetails& details) { | |
| 91 // TODO(hcarmona): Get correct navigation logic here. | |
| 92 // Remove similar code from PermissionBubbleManager | |
| 93 | |
| 94 // Hide bubbles if the URL changes or the page is refreshed. | |
| 95 if (!details.is_in_page || | |
| 96 details.type == content::NAVIGATION_TYPE_SAME_PAGE || | |
| 97 details.type == content::NAVIGATION_TYPE_EXISTING_PAGE) { | |
| 98 CloseMatchingBubbles(context, true, BUBBLE_CLOSE_IGNORE); | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 void ChromeBubbleManager::WebContentsDestroyed(content::WebContents* context) { | |
| 103 CloseMatchingBubbles(context, true, BUBBLE_CLOSE_IGNORE); | |
| 104 } | |
| 105 | |
| 106 void ChromeBubbleManager::ScheduleShowBubble( | |
| 107 base::WeakPtr<BubbleController> controller) { | |
| 108 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.
| |
| 109 content::BrowserThread::UI, | |
| 110 FROM_HERE, | |
| 111 base::Bind(&BubbleController::Show, | |
| 112 controller)); | |
| 113 } | |
| OLD | NEW |