| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_factory.h" | 7 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 8 #include "chrome/browser/defaults.h" | 8 #include "chrome/browser/defaults.h" |
| 9 #include "chrome/browser/prefs/pref_service_syncable.h" | 9 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/search/search.h" | 11 #include "chrome/browser/search/search.h" |
| 12 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper_delegate.h" | 12 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper_delegate.h" |
| 13 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" | 13 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" |
| 14 #include "chrome/browser/ui/sad_tab.h" | 14 #include "chrome/browser/ui/sad_tab.h" |
| 15 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 15 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "components/bookmarks/browser/bookmark_model.h" | 17 #include "components/bookmarks/browser/bookmark_model.h" |
| 18 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 | 20 |
| 21 using bookmarks::BookmarkModel; | 21 using bookmarks::BookmarkModel; |
| 22 using bookmarks::BookmarkNode; |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 bool IsNTPWebUI(content::WebContents* web_contents) { | 26 bool IsNTPWebUI(content::WebContents* web_contents) { |
| 26 content::WebUI* web_ui = NULL; | 27 content::WebUI* web_ui = NULL; |
| 27 // Use the committed entry so the bookmarks bar disappears at the same time | 28 // Use the committed entry so the bookmarks bar disappears at the same time |
| 28 // the page does. | 29 // the page does. |
| 29 if (web_contents->GetController().GetLastCommittedEntry()) | 30 if (web_contents->GetController().GetLastCommittedEntry()) |
| 30 web_ui = web_contents->GetCommittedWebUI(); | 31 web_ui = web_contents->GetCommittedWebUI(); |
| 31 else | 32 else |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } | 80 } |
| 80 | 81 |
| 81 BookmarkTabHelper::BookmarkTabHelper(content::WebContents* web_contents) | 82 BookmarkTabHelper::BookmarkTabHelper(content::WebContents* web_contents) |
| 82 : content::WebContentsObserver(web_contents), | 83 : content::WebContentsObserver(web_contents), |
| 83 is_starred_(false), | 84 is_starred_(false), |
| 84 bookmark_model_(NULL), | 85 bookmark_model_(NULL), |
| 85 delegate_(NULL), | 86 delegate_(NULL), |
| 86 bookmark_drag_(NULL) { | 87 bookmark_drag_(NULL) { |
| 87 Profile* profile = | 88 Profile* profile = |
| 88 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 89 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 89 bookmark_model_= BookmarkModelFactory::GetForProfile(profile); | 90 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile); |
| 90 if (bookmark_model_) | 91 if (bookmark_model_) |
| 91 bookmark_model_->AddObserver(this); | 92 bookmark_model_->AddObserver(this); |
| 92 } | 93 } |
| 93 | 94 |
| 94 void BookmarkTabHelper::UpdateStarredStateForCurrentURL() { | 95 void BookmarkTabHelper::UpdateStarredStateForCurrentURL() { |
| 95 const bool old_state = is_starred_; | 96 const bool old_state = is_starred_; |
| 96 is_starred_ = (bookmark_model_ && | 97 is_starred_ = (bookmark_model_ && |
| 97 bookmark_model_->IsBookmarked(chrome::GetURLToBookmark(web_contents()))); | 98 bookmark_model_->IsBookmarked(chrome::GetURLToBookmark(web_contents()))); |
| 98 | 99 |
| 99 if (is_starred_ != old_state && delegate_) | 100 if (is_starred_ != old_state && delegate_) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 const content::LoadCommittedDetails& /*details*/, | 139 const content::LoadCommittedDetails& /*details*/, |
| 139 const content::FrameNavigateParams& /*params*/) { | 140 const content::FrameNavigateParams& /*params*/) { |
| 140 UpdateStarredStateForCurrentURL(); | 141 UpdateStarredStateForCurrentURL(); |
| 141 } | 142 } |
| 142 | 143 |
| 143 void BookmarkTabHelper::DidStartNavigationToPendingEntry( | 144 void BookmarkTabHelper::DidStartNavigationToPendingEntry( |
| 144 const GURL& /*url*/, | 145 const GURL& /*url*/, |
| 145 content::NavigationController::ReloadType /*reload_type*/) { | 146 content::NavigationController::ReloadType /*reload_type*/) { |
| 146 UpdateStarredStateForCurrentURL(); | 147 UpdateStarredStateForCurrentURL(); |
| 147 } | 148 } |
| OLD | NEW |