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

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

Issue 7464009: Removal of Profile from content part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: works now Created 9 years, 5 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/navigation_details.h" 15 #include "content/browser/tab_contents/navigation_details.h"
16 #include "content/browser/tab_contents/tab_contents_delegate.h" 16 #include "content/browser/tab_contents/tab_contents_delegate.h"
17 #include "content/browser/tab_contents/tab_contents.h" 17 #include "content/browser/tab_contents/tab_contents.h"
18 #include "content/browser/webui/web_ui.h" 18 #include "content/browser/webui/web_ui.h"
19 #include "content/common/notification_service.h" 19 #include "content/common/notification_service.h"
20 #include "ui/gfx/codec/png_codec.h" 20 #include "ui/gfx/codec/png_codec.h"
21 #include "ui/gfx/image/image.h" 21 #include "ui/gfx/image/image.h"
22 22
23 FaviconTabHelper::FaviconTabHelper(TabContents* tab_contents) 23 FaviconTabHelper::FaviconTabHelper(TabContents* tab_contents)
24 : TabContentsObserver(tab_contents) { 24 : TabContentsObserver(tab_contents) {
25 favicon_handler_.reset(new FaviconHandler(tab_contents->profile(), this, 25 Profile* profile = static_cast<Profile*>(tab_contents->context());
26 favicon_handler_.reset(new FaviconHandler(profile, this,
26 FaviconHandler::FAVICON)); 27 FaviconHandler::FAVICON));
27 if (chrome::kEnableTouchIcon) 28 if (chrome::kEnableTouchIcon)
28 touch_icon_handler_.reset(new FaviconHandler(tab_contents->profile(), this, 29 touch_icon_handler_.reset(new FaviconHandler(profile, this,
29 FaviconHandler::TOUCH)); 30 FaviconHandler::TOUCH));
30 } 31 }
31 32
32 FaviconTabHelper::~FaviconTabHelper() { 33 FaviconTabHelper::~FaviconTabHelper() {
33 } 34 }
34 35
35 void FaviconTabHelper::FetchFavicon(const GURL& url) { 36 void FaviconTabHelper::FetchFavicon(const GURL& url) {
36 favicon_handler_->FetchFavicon(url); 37 favicon_handler_->FetchFavicon(url);
37 if (touch_icon_handler_.get()) 38 if (touch_icon_handler_.get())
38 touch_icon_handler_->FetchFavicon(url); 39 touch_icon_handler_->FetchFavicon(url);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 return true; 78 return true;
78 } 79 }
79 80
80 void FaviconTabHelper::SaveFavicon() { 81 void FaviconTabHelper::SaveFavicon() {
81 NavigationEntry* entry = tab_contents()->controller().GetActiveEntry(); 82 NavigationEntry* entry = tab_contents()->controller().GetActiveEntry();
82 if (!entry || entry->url().is_empty()) 83 if (!entry || entry->url().is_empty())
83 return; 84 return;
84 85
85 // Make sure the page is in history, otherwise adding the favicon does 86 // Make sure the page is in history, otherwise adding the favicon does
86 // nothing. 87 // nothing.
87 HistoryService* history = tab_contents()->profile()-> 88 Profile* profile = static_cast<Profile*>(tab_contents()->context());
89 HistoryService* history = profile->
88 GetOriginalProfile()->GetHistoryService(Profile::IMPLICIT_ACCESS); 90 GetOriginalProfile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
89 if (!history) 91 if (!history)
90 return; 92 return;
91 history->AddPageNoVisitForBookmark(entry->url()); 93 history->AddPageNoVisitForBookmark(entry->url());
92 94
93 FaviconService* service = tab_contents()->profile()-> 95 FaviconService* service = profile->
94 GetOriginalProfile()->GetFaviconService(Profile::IMPLICIT_ACCESS); 96 GetOriginalProfile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
95 if (!service) 97 if (!service)
96 return; 98 return;
97 const NavigationEntry::FaviconStatus& favicon(entry->favicon()); 99 const NavigationEntry::FaviconStatus& favicon(entry->favicon());
98 if (!favicon.is_valid() || favicon.url().is_empty() || 100 if (!favicon.is_valid() || favicon.url().is_empty() ||
99 favicon.bitmap().empty()) { 101 favicon.bitmap().empty()) {
100 return; 102 return;
101 } 103 }
102 std::vector<unsigned char> image_data; 104 std::vector<unsigned char> image_data;
103 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data); 105 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 NotificationService::current()->Notify( 142 NotificationService::current()->Notify(
141 chrome::NOTIFICATION_FAVICON_UPDATED, 143 chrome::NOTIFICATION_FAVICON_UPDATED,
142 Source<TabContents>(tab_contents()), 144 Source<TabContents>(tab_contents()),
143 NotificationService::NoDetails()); 145 NotificationService::NoDetails());
144 tab_contents()->NotifyNavigationStateChanged(TabContents::INVALIDATE_TAB); 146 tab_contents()->NotifyNavigationStateChanged(TabContents::INVALIDATE_TAB);
145 } 147 }
146 148
147 void FaviconTabHelper::NavigateToPendingEntry( 149 void FaviconTabHelper::NavigateToPendingEntry(
148 const GURL& url, 150 const GURL& url,
149 NavigationController::ReloadType reload_type) { 151 NavigationController::ReloadType reload_type) {
152 Profile* profile = static_cast<Profile*>(tab_contents()->context());
150 if (reload_type != NavigationController::NO_RELOAD && 153 if (reload_type != NavigationController::NO_RELOAD &&
151 !tab_contents()->profile()->IsOffTheRecord()) { 154 !profile->IsOffTheRecord()) {
152 FaviconService* favicon_service = 155 FaviconService* favicon_service =
153 tab_contents()->profile()->GetFaviconService(Profile::IMPLICIT_ACCESS); 156 profile->GetFaviconService(Profile::IMPLICIT_ACCESS);
154 if (favicon_service) 157 if (favicon_service)
155 favicon_service->SetFaviconOutOfDateForPage(url); 158 favicon_service->SetFaviconOutOfDateForPage(url);
156 } 159 }
157 } 160 }
158 161
159 void FaviconTabHelper::DidNavigateMainFramePostCommit( 162 void FaviconTabHelper::DidNavigateMainFramePostCommit(
160 const content::LoadCommittedDetails& details, 163 const content::LoadCommittedDetails& details,
161 const ViewHostMsg_FrameNavigate_Params& params) { 164 const ViewHostMsg_FrameNavigate_Params& params) {
162 // Get the favicon, either from history or request it from the net. 165 // Get the favicon, either from history or request it from the net.
163 FetchFavicon(details.entry->url()); 166 FetchFavicon(details.entry->url());
(...skipping 11 matching lines...) Expand all
175 178
176 void FaviconTabHelper::OnDidDownloadFavicon(int id, 179 void FaviconTabHelper::OnDidDownloadFavicon(int id,
177 const GURL& image_url, 180 const GURL& image_url,
178 bool errored, 181 bool errored,
179 const SkBitmap& image) { 182 const SkBitmap& image) {
180 gfx::Image favicon(new SkBitmap(image)); 183 gfx::Image favicon(new SkBitmap(image));
181 favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); 184 favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon);
182 if (touch_icon_handler_.get()) 185 if (touch_icon_handler_.get())
183 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); 186 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon);
184 } 187 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698