| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 5 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
| 6 | 6 |
| 7 #include "chrome/browser/bookmarks/bookmark_model.h" | 7 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_node_data.h" | 8 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper_delegate.h" | 10 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper_delegate.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 registrar_.Add(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, | 35 registrar_.Add(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, |
| 36 content::NotificationService::AllBrowserContextsAndSources()); | 36 content::NotificationService::AllBrowserContextsAndSources()); |
| 37 } | 37 } |
| 38 | 38 |
| 39 BookmarkTabHelper::~BookmarkTabHelper() { | 39 BookmarkTabHelper::~BookmarkTabHelper() { |
| 40 // We don't want any notifications while we're running our destructor. | 40 // We don't want any notifications while we're running our destructor. |
| 41 registrar_.RemoveAll(); | 41 registrar_.RemoveAll(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 bool BookmarkTabHelper::ShouldShowBookmarkBar() { | 44 bool BookmarkTabHelper::ShouldShowBookmarkBar() { |
| 45 if (tab_contents()->ShowingInterstitialPage()) | 45 if (web_contents()->ShowingInterstitialPage()) |
| 46 return false; | 46 return false; |
| 47 | 47 |
| 48 // See TabContents::GetWebUIForCurrentState() comment for more info. This case | 48 // See TabContents::GetWebUIForCurrentState() comment for more info. This case |
| 49 // is very similar, but for non-first loads, we want to use the committed | 49 // is very similar, but for non-first loads, we want to use the committed |
| 50 // entry. This is so the bookmarks bar disappears at the same time the page | 50 // entry. This is so the bookmarks bar disappears at the same time the page |
| 51 // does. | 51 // does. |
| 52 if (tab_contents()->GetController().GetLastCommittedEntry()) { | 52 if (web_contents()->GetController().GetLastCommittedEntry()) { |
| 53 // Not the first load, always use the committed Web UI. | 53 // Not the first load, always use the committed Web UI. |
| 54 return CanShowBookmarkBar(tab_contents()->GetCommittedWebUI()); | 54 return CanShowBookmarkBar(web_contents()->GetCommittedWebUI()); |
| 55 } | 55 } |
| 56 | 56 |
| 57 // When it's the first load, we know either the pending one or the committed | 57 // When it's the first load, we know either the pending one or the committed |
| 58 // one will have the Web UI in it (see GetWebUIForCurrentState), and only one | 58 // one will have the Web UI in it (see GetWebUIForCurrentState), and only one |
| 59 // of them will be valid, so we can just check both. | 59 // of them will be valid, so we can just check both. |
| 60 return CanShowBookmarkBar(tab_contents()->GetWebUI()); | 60 return CanShowBookmarkBar(web_contents()->GetWebUI()); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void BookmarkTabHelper::DidNavigateMainFrame( | 63 void BookmarkTabHelper::DidNavigateMainFrame( |
| 64 const content::LoadCommittedDetails& /*details*/, | 64 const content::LoadCommittedDetails& /*details*/, |
| 65 const content::FrameNavigateParams& /*params*/) { | 65 const content::FrameNavigateParams& /*params*/) { |
| 66 UpdateStarredStateForCurrentURL(); | 66 UpdateStarredStateForCurrentURL(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void BookmarkTabHelper::Observe(int type, | 69 void BookmarkTabHelper::Observe(int type, |
| 70 const content::NotificationSource& source, | 70 const content::NotificationSource& source, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 94 bookmark_drag_ = bookmark_drag; | 94 bookmark_drag_ = bookmark_drag; |
| 95 } | 95 } |
| 96 | 96 |
| 97 BookmarkTabHelper::BookmarkDrag* | 97 BookmarkTabHelper::BookmarkDrag* |
| 98 BookmarkTabHelper::GetBookmarkDragDelegate() { | 98 BookmarkTabHelper::GetBookmarkDragDelegate() { |
| 99 return bookmark_drag_; | 99 return bookmark_drag_; |
| 100 } | 100 } |
| 101 | 101 |
| 102 void BookmarkTabHelper::UpdateStarredStateForCurrentURL() { | 102 void BookmarkTabHelper::UpdateStarredStateForCurrentURL() { |
| 103 Profile* profile = | 103 Profile* profile = |
| 104 Profile::FromBrowserContext(tab_contents()->GetBrowserContext()); | 104 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 105 BookmarkModel* model = profile->GetBookmarkModel(); | 105 BookmarkModel* model = profile->GetBookmarkModel(); |
| 106 const bool old_state = is_starred_; | 106 const bool old_state = is_starred_; |
| 107 is_starred_ = (model && model->IsBookmarked(tab_contents()->GetURL())); | 107 is_starred_ = (model && model->IsBookmarked(web_contents()->GetURL())); |
| 108 | 108 |
| 109 if (is_starred_ != old_state && delegate()) | 109 if (is_starred_ != old_state && delegate()) |
| 110 delegate()->URLStarredChanged(tab_contents_wrapper_, is_starred_); | 110 delegate()->URLStarredChanged(tab_contents_wrapper_, is_starred_); |
| 111 } | 111 } |
| OLD | NEW |