Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(727)

Side by Side Diff: chrome/browser/favicon/favicon_tab_helper.cc

Issue 8956059: Rename NavigationController to NavigationControllerImpl and put it into the content namespace. Al... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/favicon/favicon_tab_helper.h" 5 #include "chrome/browser/favicon/favicon_tab_helper.h"
6 6
7 #include "chrome/browser/favicon/favicon_handler.h" 7 #include "chrome/browser/favicon/favicon_handler.h"
8 #include "chrome/browser/history/history.h" 8 #include "chrome/browser/history/history.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/chrome_constants.h" 10 #include "chrome/common/chrome_constants.h"
11 #include "chrome/common/chrome_notification_types.h" 11 #include "chrome/common/chrome_notification_types.h"
12 #include "chrome/common/icon_messages.h" 12 #include "chrome/common/icon_messages.h"
13 #include "content/browser/renderer_host/render_view_host.h" 13 #include "content/browser/renderer_host/render_view_host.h"
14 #include "content/browser/tab_contents/navigation_controller.h" 14 #include "content/browser/tab_contents/navigation_controller.h"
15 #include "content/browser/tab_contents/tab_contents.h" 15 #include "content/browser/tab_contents/tab_contents.h"
16 #include "content/browser/webui/web_ui.h" 16 #include "content/browser/webui/web_ui.h"
17 #include "content/public/browser/favicon_status.h" 17 #include "content/public/browser/favicon_status.h"
18 #include "content/public/browser/navigation_details.h" 18 #include "content/public/browser/navigation_details.h"
19 #include "content/public/browser/navigation_entry.h" 19 #include "content/public/browser/navigation_entry.h"
20 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
21 #include "content/public/browser/web_contents_delegate.h" 21 #include "content/public/browser/web_contents_delegate.h"
22 #include "ui/gfx/codec/png_codec.h" 22 #include "ui/gfx/codec/png_codec.h"
23 #include "ui/gfx/image/image.h" 23 #include "ui/gfx/image/image.h"
24 24
25 using content::FaviconStatus; 25 using content::FaviconStatus;
26 using content::NavigationEntry;
26 using content::WebContents; 27 using content::WebContents;
27 28
28 FaviconTabHelper::FaviconTabHelper(TabContents* tab_contents) 29 FaviconTabHelper::FaviconTabHelper(TabContents* tab_contents)
29 : content::WebContentsObserver(tab_contents), 30 : content::WebContentsObserver(tab_contents),
30 profile_(Profile::FromBrowserContext(tab_contents->GetBrowserContext())) { 31 profile_(Profile::FromBrowserContext(tab_contents->GetBrowserContext())) {
31 favicon_handler_.reset(new FaviconHandler(profile_, this, 32 favicon_handler_.reset(new FaviconHandler(profile_, this,
32 FaviconHandler::FAVICON)); 33 FaviconHandler::FAVICON));
33 if (chrome::kEnableTouchIcon) 34 if (chrome::kEnableTouchIcon)
34 touch_icon_handler_.reset(new FaviconHandler(profile_, this, 35 touch_icon_handler_.reset(new FaviconHandler(profile_, this,
35 FaviconHandler::TOUCH)); 36 FaviconHandler::TOUCH));
36 } 37 }
37 38
38 FaviconTabHelper::~FaviconTabHelper() { 39 FaviconTabHelper::~FaviconTabHelper() {
39 } 40 }
40 41
41 void FaviconTabHelper::FetchFavicon(const GURL& url) { 42 void FaviconTabHelper::FetchFavicon(const GURL& url) {
42 favicon_handler_->FetchFavicon(url); 43 favicon_handler_->FetchFavicon(url);
43 if (touch_icon_handler_.get()) 44 if (touch_icon_handler_.get())
44 touch_icon_handler_->FetchFavicon(url); 45 touch_icon_handler_->FetchFavicon(url);
45 } 46 }
46 47
47 SkBitmap FaviconTabHelper::GetFavicon() const { 48 SkBitmap FaviconTabHelper::GetFavicon() const {
48 // Like GetTitle(), we also want to use the favicon for the last committed 49 // Like GetTitle(), we also want to use the favicon for the last committed
49 // entry rather than a pending navigation entry. 50 // entry rather than a pending navigation entry.
50 const NavigationController& controller = web_contents()->GetController(); 51 const NavigationController& controller = web_contents()->GetController();
51 content::NavigationEntry* entry = controller.GetTransientEntry(); 52 NavigationEntry* entry = controller.GetTransientEntry();
52 if (entry) 53 if (entry)
53 return entry->GetFavicon().bitmap; 54 return entry->GetFavicon().bitmap;
54 55
55 entry = controller.GetLastCommittedEntry(); 56 entry = controller.GetLastCommittedEntry();
56 if (entry) 57 if (entry)
57 return entry->GetFavicon().bitmap; 58 return entry->GetFavicon().bitmap;
58 return SkBitmap(); 59 return SkBitmap();
59 } 60 }
60 61
61 bool FaviconTabHelper::FaviconIsValid() const { 62 bool FaviconTabHelper::FaviconIsValid() const {
62 const NavigationController& controller = web_contents()->GetController(); 63 const NavigationController& controller = web_contents()->GetController();
63 content::NavigationEntry* entry = controller.GetTransientEntry(); 64 NavigationEntry* entry = controller.GetTransientEntry();
64 if (entry) 65 if (entry)
65 return entry->GetFavicon().valid; 66 return entry->GetFavicon().valid;
66 67
67 entry = controller.GetLastCommittedEntry(); 68 entry = controller.GetLastCommittedEntry();
68 if (entry) 69 if (entry)
69 return entry->GetFavicon().valid; 70 return entry->GetFavicon().valid;
70 71
71 return false; 72 return false;
72 } 73 }
73 74
74 bool FaviconTabHelper::ShouldDisplayFavicon() { 75 bool FaviconTabHelper::ShouldDisplayFavicon() {
75 // Always display a throbber during pending loads. 76 // Always display a throbber during pending loads.
76 const NavigationController& controller = web_contents()->GetController(); 77 const NavigationController& controller = web_contents()->GetController();
77 if (controller.GetLastCommittedEntry() && controller.GetPendingEntry()) 78 if (controller.GetLastCommittedEntry() && controller.GetPendingEntry())
78 return true; 79 return true;
79 80
80 WebUI* web_ui = web_contents()->GetWebUIForCurrentState(); 81 WebUI* web_ui = web_contents()->GetWebUIForCurrentState();
81 if (web_ui) 82 if (web_ui)
82 return !web_ui->hide_favicon(); 83 return !web_ui->hide_favicon();
83 return true; 84 return true;
84 } 85 }
85 86
86 void FaviconTabHelper::SaveFavicon() { 87 void FaviconTabHelper::SaveFavicon() {
87 content::NavigationEntry* entry = 88 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry();
88 web_contents()->GetController().GetActiveEntry();
89 if (!entry || entry->GetURL().is_empty()) 89 if (!entry || entry->GetURL().is_empty())
90 return; 90 return;
91 91
92 // Make sure the page is in history, otherwise adding the favicon does 92 // Make sure the page is in history, otherwise adding the favicon does
93 // nothing. 93 // nothing.
94 HistoryService* history = profile_-> 94 HistoryService* history = profile_->
95 GetOriginalProfile()->GetHistoryService(Profile::IMPLICIT_ACCESS); 95 GetOriginalProfile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
96 if (!history) 96 if (!history)
97 return; 97 return;
98 history->AddPageNoVisitForBookmark(entry->GetURL()); 98 history->AddPageNoVisitForBookmark(entry->GetURL());
(...skipping 27 matching lines...) Expand all
126 } 126 }
127 127
128 void FaviconTabHelper::OnUpdateFaviconURL( 128 void FaviconTabHelper::OnUpdateFaviconURL(
129 int32 page_id, 129 int32 page_id,
130 const std::vector<FaviconURL>& candidates) { 130 const std::vector<FaviconURL>& candidates) {
131 favicon_handler_->OnUpdateFaviconURL(page_id, candidates); 131 favicon_handler_->OnUpdateFaviconURL(page_id, candidates);
132 if (touch_icon_handler_.get()) 132 if (touch_icon_handler_.get())
133 touch_icon_handler_->OnUpdateFaviconURL(page_id, candidates); 133 touch_icon_handler_->OnUpdateFaviconURL(page_id, candidates);
134 } 134 }
135 135
136 content::NavigationEntry* FaviconTabHelper::GetActiveEntry() { 136 NavigationEntry* FaviconTabHelper::GetActiveEntry() {
137 return web_contents()->GetController().GetActiveEntry(); 137 return web_contents()->GetController().GetActiveEntry();
138 } 138 }
139 139
140 void FaviconTabHelper::StartDownload(int id, const GURL& url, int image_size) { 140 void FaviconTabHelper::StartDownload(int id, const GURL& url, int image_size) {
141 RenderViewHost* host = web_contents()->GetRenderViewHost(); 141 RenderViewHost* host = web_contents()->GetRenderViewHost();
142 host->Send(new IconMsg_DownloadFavicon( 142 host->Send(new IconMsg_DownloadFavicon(
143 host->routing_id(), id, url, image_size)); 143 host->routing_id(), id, url, image_size));
144 } 144 }
145 145
146 void FaviconTabHelper::NotifyFaviconUpdated() { 146 void FaviconTabHelper::NotifyFaviconUpdated() {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 182
183 void FaviconTabHelper::OnDidDownloadFavicon(int id, 183 void FaviconTabHelper::OnDidDownloadFavicon(int id,
184 const GURL& image_url, 184 const GURL& image_url,
185 bool errored, 185 bool errored,
186 const SkBitmap& image) { 186 const SkBitmap& image) {
187 gfx::Image favicon(new SkBitmap(image)); 187 gfx::Image favicon(new SkBitmap(image));
188 favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); 188 favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon);
189 if (touch_icon_handler_.get()) 189 if (touch_icon_handler_.get())
190 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); 190 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon);
191 } 191 }
OLDNEW
« no previous file with comments | « chrome/browser/favicon/favicon_tab_helper.h ('k') | chrome/browser/geolocation/chrome_geolocation_permission_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698