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" |
11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
12 #include "chrome/browser/ui/webui/chrome_web_ui.h" | 12 #include "chrome/browser/ui/webui/chrome_web_ui.h" |
| 13 #include "chrome/common/chrome_notification_types.h" |
13 #include "content/browser/tab_contents/navigation_controller.h" | 14 #include "content/browser/tab_contents/navigation_controller.h" |
14 #include "content/browser/tab_contents/tab_contents.h" | 15 #include "content/browser/tab_contents/tab_contents.h" |
15 #include "content/common/notification_service.h" | 16 #include "content/common/notification_service.h" |
16 | 17 |
17 static bool ForceBookmarkBarVisible(WebUI* ui) { | 18 static bool ForceBookmarkBarVisible(WebUI* ui) { |
18 return ui && static_cast<ChromeWebUI*>(ui)->force_bookmark_bar_visible(); | 19 return ui && static_cast<ChromeWebUI*>(ui)->force_bookmark_bar_visible(); |
19 } | 20 } |
20 | 21 |
21 BookmarkTabHelper::BookmarkTabHelper(TabContentsWrapper* tab_contents) | 22 BookmarkTabHelper::BookmarkTabHelper(TabContentsWrapper* tab_contents) |
22 : TabContentsObserver(tab_contents->tab_contents()), | 23 : TabContentsObserver(tab_contents->tab_contents()), |
23 is_starred_(false), | 24 is_starred_(false), |
24 tab_contents_wrapper_(tab_contents), | 25 tab_contents_wrapper_(tab_contents), |
25 delegate_(NULL), | 26 delegate_(NULL), |
26 bookmark_drag_(NULL) { | 27 bookmark_drag_(NULL) { |
27 // Register for notifications about URL starredness changing on any profile. | 28 // Register for notifications about URL starredness changing on any profile. |
28 registrar_.Add(this, NotificationType::URLS_STARRED, | 29 registrar_.Add(this, chrome::NOTIFICATION_URLS_STARRED, |
29 NotificationService::AllSources()); | 30 NotificationService::AllSources()); |
30 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED, | 31 registrar_.Add(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, |
31 NotificationService::AllSources()); | 32 NotificationService::AllSources()); |
32 } | 33 } |
33 | 34 |
34 BookmarkTabHelper::~BookmarkTabHelper() { | 35 BookmarkTabHelper::~BookmarkTabHelper() { |
35 // We don't want any notifications while we're running our destructor. | 36 // We don't want any notifications while we're running our destructor. |
36 registrar_.RemoveAll(); | 37 registrar_.RemoveAll(); |
37 } | 38 } |
38 | 39 |
39 bool BookmarkTabHelper::ShouldShowBookmarkBar() { | 40 bool BookmarkTabHelper::ShouldShowBookmarkBar() { |
40 if (tab_contents()->showing_interstitial_page()) | 41 if (tab_contents()->showing_interstitial_page()) |
(...skipping 13 matching lines...) Expand all Loading... |
54 // of them will be valid, so we can just check both. | 55 // of them will be valid, so we can just check both. |
55 return ForceBookmarkBarVisible(tab_contents()->web_ui()); | 56 return ForceBookmarkBarVisible(tab_contents()->web_ui()); |
56 } | 57 } |
57 | 58 |
58 void BookmarkTabHelper::DidNavigateMainFramePostCommit( | 59 void BookmarkTabHelper::DidNavigateMainFramePostCommit( |
59 const content::LoadCommittedDetails& /*details*/, | 60 const content::LoadCommittedDetails& /*details*/, |
60 const ViewHostMsg_FrameNavigate_Params& /*params*/) { | 61 const ViewHostMsg_FrameNavigate_Params& /*params*/) { |
61 UpdateStarredStateForCurrentURL(); | 62 UpdateStarredStateForCurrentURL(); |
62 } | 63 } |
63 | 64 |
64 void BookmarkTabHelper::Observe(NotificationType type, | 65 void BookmarkTabHelper::Observe(int type, |
65 const NotificationSource& source, | 66 const NotificationSource& source, |
66 const NotificationDetails& details) { | 67 const NotificationDetails& details) { |
67 switch (type.value) { | 68 switch (type) { |
68 case NotificationType::BOOKMARK_MODEL_LOADED: | 69 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED: |
69 // BookmarkModel finished loading, fall through to update starred state. | 70 // BookmarkModel finished loading, fall through to update starred state. |
70 case NotificationType::URLS_STARRED: { | 71 case chrome::NOTIFICATION_URLS_STARRED: { |
71 // Somewhere, a URL has been starred. | 72 // Somewhere, a URL has been starred. |
72 // Ignore notifications for profiles other than our current one. | 73 // Ignore notifications for profiles other than our current one. |
73 Profile* source_profile = Source<Profile>(source).ptr(); | 74 Profile* source_profile = Source<Profile>(source).ptr(); |
74 if (!source_profile || | 75 if (!source_profile || |
75 !source_profile->IsSameProfile(tab_contents_wrapper_->profile())) | 76 !source_profile->IsSameProfile(tab_contents_wrapper_->profile())) |
76 return; | 77 return; |
77 | 78 |
78 UpdateStarredStateForCurrentURL(); | 79 UpdateStarredStateForCurrentURL(); |
79 break; | 80 break; |
80 } | 81 } |
(...skipping 14 matching lines...) Expand all Loading... |
95 } | 96 } |
96 | 97 |
97 void BookmarkTabHelper::UpdateStarredStateForCurrentURL() { | 98 void BookmarkTabHelper::UpdateStarredStateForCurrentURL() { |
98 BookmarkModel* model = tab_contents()->profile()->GetBookmarkModel(); | 99 BookmarkModel* model = tab_contents()->profile()->GetBookmarkModel(); |
99 const bool old_state = is_starred_; | 100 const bool old_state = is_starred_; |
100 is_starred_ = (model && model->IsBookmarked(tab_contents()->GetURL())); | 101 is_starred_ = (model && model->IsBookmarked(tab_contents()->GetURL())); |
101 | 102 |
102 if (is_starred_ != old_state && delegate()) | 103 if (is_starred_ != old_state && delegate()) |
103 delegate()->URLStarredChanged(tab_contents_wrapper_, is_starred_); | 104 delegate()->URLStarredChanged(tab_contents_wrapper_, is_starred_); |
104 } | 105 } |
OLD | NEW |