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/metro_pin_tab_helper_win.h" | 5 #include "chrome/browser/ui/metro_pin_tab_helper_win.h" |
6 | 6 |
7 #include <set> | |
8 | |
7 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
8 #include "base/bind.h" | 10 #include "base/bind.h" |
9 #include "base/file_path.h" | 11 #include "base/file_path.h" |
10 #include "base/file_util.h" | 12 #include "base/file_util.h" |
11 #include "base/logging.h" | 13 #include "base/logging.h" |
12 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
13 #include "base/memory/ref_counted_memory.h" | 15 #include "base/memory/ref_counted_memory.h" |
14 #include "base/path_service.h" | 16 #include "base/path_service.h" |
15 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
16 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
17 #include "base/win/metro.h" | 19 #include "base/win/metro.h" |
18 #include "chrome/browser/favicon/favicon_tab_helper.h" | 20 #include "chrome/browser/favicon/favicon_tab_helper.h" |
21 #include "chrome/browser/favicon/favicon_util.h" | |
19 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 22 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
20 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
24 #include "chrome/common/icon_messages.h" | |
21 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
23 #include "crypto/sha2.h" | 27 #include "crypto/sha2.h" |
28 #include "third_party/skia/include/core/SkCanvas.h" | |
29 #include "third_party/skia/include/core/SkColor.h" | |
24 #include "ui/gfx/canvas.h" | 30 #include "ui/gfx/canvas.h" |
25 #include "ui/gfx/codec/png_codec.h" | 31 #include "ui/gfx/codec/png_codec.h" |
26 #include "ui/gfx/color_analysis.h" | 32 #include "ui/gfx/color_analysis.h" |
27 #include "ui/gfx/color_utils.h" | 33 #include "ui/gfx/color_utils.h" |
28 #include "ui/gfx/image/image.h" | 34 #include "ui/gfx/image/image.h" |
29 #include "ui/gfx/rect.h" | 35 #include "ui/gfx/rect.h" |
30 #include "ui/gfx/size.h" | 36 #include "ui/gfx/size.h" |
31 | 37 |
32 DEFINE_WEB_CONTENTS_USER_DATA_KEY(MetroPinTabHelper) | 38 DEFINE_WEB_CONTENTS_USER_DATA_KEY(MetroPinTabHelper) |
33 | 39 |
(...skipping 27 matching lines...) Expand all Loading... | |
61 const string16& tile_id, | 67 const string16& tile_id, |
62 const FilePath& logo_dir, | 68 const FilePath& logo_dir, |
63 FilePath* logo_path) { | 69 FilePath* logo_path) { |
64 const int kLogoWidth = 120; | 70 const int kLogoWidth = 120; |
65 const int kLogoHeight = 120; | 71 const int kLogoHeight = 120; |
66 const int kBoxWidth = 40; | 72 const int kBoxWidth = 40; |
67 const int kBoxHeight = 40; | 73 const int kBoxHeight = 40; |
68 const int kCaptionHeight = 20; | 74 const int kCaptionHeight = 20; |
69 const double kBoxFade = 0.75; | 75 const double kBoxFade = 0.75; |
70 const int kColorMeanDarknessLimit = 100; | 76 const int kColorMeanDarknessLimit = 100; |
71 const int kColorMeanLightnessLimit = 100; | 77 const int kColorMeanLightnessLimit = 650; |
72 | 78 |
73 if (image.isNull()) | 79 if (image.isNull()) |
74 return false; | 80 return false; |
75 | 81 |
76 *logo_path = logo_dir.Append(tile_id).ReplaceExtension(L".png"); | 82 // First paint the image onto an opaque background to get rid of transparency. |
77 | 83 // White is used as it will be disregarded in the mean calculation because of |
78 // Use a canvas to paint the tile logo. | 84 // lightness limit. |
79 gfx::Canvas canvas(gfx::Size(kLogoWidth, kLogoHeight), ui::SCALE_FACTOR_100P, | 85 SkPaint paint; |
80 true); | 86 paint.setColor(SK_ColorWHITE); |
87 gfx::Canvas favicon_canvas(gfx::Size(image.width(), image.height()), | |
88 ui::SCALE_FACTOR_100P, true); | |
89 favicon_canvas.DrawRect(gfx::Rect(0, 0, image.width(), image.height()), | |
90 paint); | |
91 favicon_canvas.DrawImageInt(image, 0, 0); | |
81 | 92 |
82 // Fill the tile logo with the average color from bitmap. To do this we need | 93 // Fill the tile logo with the average color from bitmap. To do this we need |
83 // to work out the 'average color' which is calculated using PNG encoded data | 94 // to work out the 'average color' which is calculated using PNG encoded data |
84 // of the bitmap. | 95 // of the bitmap. |
85 SkPaint paint; | |
86 std::vector<unsigned char> icon_png; | 96 std::vector<unsigned char> icon_png; |
87 if (!gfx::PNGCodec::EncodeBGRASkBitmap(*image.bitmap(), true, &icon_png)) | 97 if (!gfx::PNGCodec::EncodeBGRASkBitmap( |
98 favicon_canvas.ExtractImageRep().sk_bitmap(), false, &icon_png)) { | |
88 return false; | 99 return false; |
100 } | |
89 | 101 |
90 scoped_refptr<base::RefCountedStaticMemory> icon_mem( | 102 scoped_refptr<base::RefCountedStaticMemory> icon_mem( |
91 new base::RefCountedStaticMemory(&icon_png.front(), icon_png.size())); | 103 new base::RefCountedStaticMemory(&icon_png.front(), icon_png.size())); |
92 color_utils::GridSampler sampler; | 104 color_utils::GridSampler sampler; |
93 SkColor mean_color = color_utils::CalculateKMeanColorOfPNG( | 105 SkColor mean_color = color_utils::CalculateKMeanColorOfPNG( |
94 icon_mem, kColorMeanDarknessLimit, kColorMeanLightnessLimit, sampler); | 106 icon_mem, kColorMeanDarknessLimit, kColorMeanLightnessLimit, sampler); |
95 paint.setColor(mean_color); | 107 paint.setColor(mean_color); |
108 gfx::Canvas canvas(gfx::Size(kLogoWidth, kLogoHeight), ui::SCALE_FACTOR_100P, | |
109 true); | |
96 canvas.DrawRect(gfx::Rect(0, 0, kLogoWidth, kLogoHeight), paint); | 110 canvas.DrawRect(gfx::Rect(0, 0, kLogoWidth, kLogoHeight), paint); |
97 | 111 |
98 // Now paint a faded square for the favicon to go in. | 112 // Now paint a faded square for the favicon to go in. |
99 color_utils::HSL shift = {-1, -1, kBoxFade}; | 113 color_utils::HSL shift = {-1, -1, kBoxFade}; |
100 paint.setColor(color_utils::HSLShift(mean_color, shift)); | 114 paint.setColor(color_utils::HSLShift(mean_color, shift)); |
101 int box_left = (kLogoWidth - kBoxWidth) / 2; | 115 int box_left = (kLogoWidth - kBoxWidth) / 2; |
102 int box_top = (kLogoHeight - kCaptionHeight - kBoxHeight) / 2; | 116 int box_top = (kLogoHeight - kCaptionHeight - kBoxHeight) / 2; |
103 canvas.DrawRect(gfx::Rect(box_left, box_top, kBoxWidth, kBoxHeight), paint); | 117 canvas.DrawRect(gfx::Rect(box_left, box_top, kBoxWidth, kBoxHeight), paint); |
104 | 118 |
105 // Now paint the favicon into the tile, leaving some room at the bottom for | 119 // Now paint the favicon into the tile, leaving some room at the bottom for |
106 // the caption. | 120 // the caption. |
107 int left = (kLogoWidth - image.width()) / 2; | 121 int left = (kLogoWidth - image.width()) / 2; |
108 int top = (kLogoHeight - kCaptionHeight - image.height()) / 2; | 122 int top = (kLogoHeight - kCaptionHeight - image.height()) / 2; |
109 canvas.DrawImageInt(image, left, top); | 123 canvas.DrawImageInt(image, left, top); |
110 | 124 |
111 SkBitmap logo_bitmap = canvas.ExtractImageRep().sk_bitmap(); | 125 SkBitmap logo_bitmap = canvas.ExtractImageRep().sk_bitmap(); |
112 std::vector<unsigned char> logo_png; | 126 std::vector<unsigned char> logo_png; |
113 if (!gfx::PNGCodec::EncodeBGRASkBitmap(logo_bitmap, true, &logo_png)) | 127 if (!gfx::PNGCodec::EncodeBGRASkBitmap(logo_bitmap, true, &logo_png)) |
114 return false; | 128 return false; |
115 | 129 |
130 *logo_path = logo_dir.Append(tile_id).ReplaceExtension(L".png"); | |
116 return file_util::WriteFile(*logo_path, | 131 return file_util::WriteFile(*logo_path, |
117 reinterpret_cast<char*>(&logo_png[0]), | 132 reinterpret_cast<char*>(&logo_png[0]), |
118 logo_png.size()) > 0; | 133 logo_png.size()) > 0; |
119 } | 134 } |
120 | 135 |
121 // Get the path to the backup logo. If the backup logo already exists in | 136 // Get the path to the backup logo. If the backup logo already exists in |
122 // |logo_dir|, it will be used, otherwise it will be copied out of the install | 137 // |logo_dir|, it will be used, otherwise it will be copied out of the install |
123 // folder. (The version in the install folder is not used as it may disappear | 138 // folder. (The version in the install folder is not used as it may disappear |
124 // after an upgrade, causing tiles to lose their images if Windows rebuilds | 139 // after an upgrade, causing tiles to lose their images if Windows rebuilds |
125 // its tile image cache.) | 140 // its tile image cache.) |
126 // The path to the logo is returned in |logo_path|, with the return value | 141 // The path to the logo is returned in |logo_path|, with the return value |
127 // indicating success. | 142 // indicating success. |
128 bool GetPathToBackupLogo(const FilePath& logo_dir, | 143 bool GetPathToBackupLogo(const FilePath& logo_dir, |
129 FilePath* logo_path) { | 144 FilePath* logo_path) { |
130 const wchar_t kDefaultLogoFileName[] = L"SecondaryTile.png"; | 145 const wchar_t kDefaultLogoFileName[] = L"SecondaryTile.png"; |
131 *logo_path = logo_dir.Append(kDefaultLogoFileName); | 146 *logo_path = logo_dir.Append(kDefaultLogoFileName); |
132 if (file_util::PathExists(*logo_path)) | 147 if (file_util::PathExists(*logo_path)) |
133 return true; | 148 return true; |
134 | 149 |
135 FilePath default_logo_path; | 150 FilePath default_logo_path; |
136 DCHECK(PathService::Get(base::DIR_MODULE, &default_logo_path)); | 151 DCHECK(PathService::Get(base::DIR_MODULE, &default_logo_path)); |
137 default_logo_path = default_logo_path.Append(kDefaultLogoFileName); | 152 default_logo_path = default_logo_path.Append(kDefaultLogoFileName); |
138 return file_util::CopyFile(default_logo_path, *logo_path); | 153 return file_util::CopyFile(default_logo_path, *logo_path); |
139 } | 154 } |
140 | 155 |
141 } // namespace | 156 } // namespace |
142 | 157 |
143 class MetroPinTabHelper::TaskRunner | 158 class MetroPinTabHelper::PagePinner |
sky
2012/10/26 20:01:15
How come this is ref counted?
benwells
2012/10/29 06:38:41
This class is now split into two. One half is not
| |
144 : public base::RefCountedThreadSafe<TaskRunner> { | 159 : public base::RefCountedThreadSafe<PagePinner> { |
145 public: | 160 public: |
146 TaskRunner() {} | 161 PagePinner() {} |
147 | 162 |
163 // Updated when we have a new set of candidate favicon URLs for the current | |
164 // page. | |
165 void SetFaviconCandidates(const std::vector<FaviconURL>& candidates); | |
166 | |
167 // This will clear any information we have about the current page's favicon, | |
168 // and also cancel any pin requests that are still having favicons downloaded. | |
169 void ClearCurrentPageInfo(); | |
sky
2012/10/26 20:01:15
Why do we need this?
benwells
2012/10/29 06:38:41
This still exists, kind of, but is now in MetroPin
| |
170 | |
171 // Start downloading favicons from the candidate URLs, and then proceed on | |
172 // to create a secondary tile. |history_image| is the favicon we get from | |
173 // the history service. It is too small so we try to get a bigger one | |
174 // directly. | |
175 void StartDownloadingFavicons(content::RenderViewHost* host, | |
176 const string16& title, | |
177 const string16& url, | |
178 const gfx::ImageSkia& history_image); | |
179 | |
180 // Callback for when a favicon has been downloaded. The best bitmap so far | |
181 // will be stored in best_candidate_. If this is the last URL that was being | |
sky
2012/10/26 20:01:15
|s around references to parameters and fields.
benwells
2012/10/29 06:38:41
Done.
| |
182 // downloaded, the page is pinned by calling PinPageToStartScreen on the FILE | |
183 // thread. | |
184 void OnDidDownloadFavicon(int id, | |
185 const GURL& image_url, | |
186 bool errored, | |
187 int requested_size, | |
188 const std::vector<SkBitmap>& bitmaps); | |
189 | |
190 // We now have found the best favicon we can, so create the tile. This is | |
191 // executed on the FILE thread. | |
148 void PinPageToStartScreen(const string16& title, | 192 void PinPageToStartScreen(const string16& title, |
149 const string16& url, | 193 const string16& url, |
150 const gfx::ImageSkia& image); | 194 const gfx::ImageSkia& image); |
151 | 195 |
152 private: | 196 private: |
153 ~TaskRunner() {} | 197 ~PagePinner() {} |
154 | 198 |
155 friend class base::RefCountedThreadSafe<TaskRunner>; | 199 // The best candidate we have so far for the current pin operation. |
156 DISALLOW_COPY_AND_ASSIGN(TaskRunner); | 200 gfx::ImageSkia best_candidate_; |
201 | |
202 // Title and URL of the page being pinned. | |
203 string16 title_; | |
204 string16 url_; | |
205 | |
206 // Candidate Favicon URLs for the current page. | |
207 std::vector<FaviconURL> favicon_url_candidates_; | |
208 | |
209 // Favicon URLs that are being downloaded. While this is not empty there | |
210 // is a pin request being processed, if any others are started they will | |
211 // be ignored. | |
212 std::set<GURL> in_progress_urls_; | |
213 | |
214 friend class base::RefCountedThreadSafe<PagePinner>; | |
215 DISALLOW_COPY_AND_ASSIGN(PagePinner); | |
157 }; | 216 }; |
158 | 217 |
159 void MetroPinTabHelper::TaskRunner::PinPageToStartScreen( | 218 void MetroPinTabHelper::PagePinner::SetFaviconCandidates( |
219 const std::vector<FaviconURL>& candidates) { | |
220 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
221 favicon_url_candidates_ = candidates; | |
222 } | |
223 | |
224 void MetroPinTabHelper::PagePinner::ClearCurrentPageInfo() { | |
225 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
226 favicon_url_candidates_.clear(); | |
227 in_progress_urls_.clear(); | |
228 } | |
229 | |
230 void MetroPinTabHelper::PagePinner::StartDownloadingFavicons( | |
231 content::RenderViewHost* host, | |
232 const string16& title, | |
233 const string16& url, | |
234 const gfx::ImageSkia& history_image) { | |
235 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
236 // If the PagePinner is already pinning the current page, ignore any more | |
237 // requests. | |
238 if (!in_progress_urls_.empty()) | |
sky
2012/10/26 20:01:15
Should we create a pinner per url? Seems like it w
benwells
2012/10/29 06:38:41
I've separated out the logic into a MetroPinTabHel
| |
239 return; | |
240 | |
241 // If there are no candidate URLs, progress straight to pinning. | |
242 if (favicon_url_candidates_.empty()) { | |
243 content::BrowserThread::PostTask( | |
244 content::BrowserThread::FILE, | |
245 FROM_HERE, | |
246 base::Bind(&PagePinner::PinPageToStartScreen, | |
247 this, | |
248 title, | |
249 url, | |
250 history_image)); | |
251 return; | |
252 } | |
253 | |
254 best_candidate_ = history_image; | |
255 title_ = title; | |
256 url_ = url; | |
257 | |
258 // Request all the candidates. | |
259 int image_size = 0; // Request the full sized image. | |
260 for (std::vector<FaviconURL>::const_iterator iter = | |
261 favicon_url_candidates_.begin(); | |
262 iter != favicon_url_candidates_.end(); | |
263 ++iter) { | |
264 // Ignore any duplicate URLs in the candidates. | |
265 if (in_progress_urls_.find(iter->icon_url) != in_progress_urls_.end()) | |
266 continue; | |
267 | |
268 in_progress_urls_.insert(iter->icon_url); | |
269 FaviconUtil::DownloadFavicon(host, iter->icon_url, image_size); | |
sky
2012/10/26 20:01:15
You need to cache the return value and compare tha
benwells
2012/10/29 06:38:41
Done. Yeah I was checking the URLs when they come
| |
270 } | |
271 } | |
272 | |
273 void MetroPinTabHelper::PagePinner::OnDidDownloadFavicon( | |
274 int id, | |
275 const GURL& image_url, | |
276 bool errored, | |
277 int requested_size, | |
278 const std::vector<SkBitmap>& bitmaps) { | |
279 const int kMaxIconSize = 32; | |
280 | |
281 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
282 std::set<GURL>::iterator iter = in_progress_urls_.find(image_url); | |
283 // If this URL isn't in the in progress list, the page must have been | |
284 // navigated since the request started, cancelling this request. | |
285 if (iter == in_progress_urls_.end()) | |
286 return; | |
287 | |
288 in_progress_urls_.erase(iter); | |
289 | |
290 // Process the bitmaps, keeping the one that is best so far. | |
291 if (!errored) { | |
292 for (std::vector<SkBitmap>::const_iterator iter = bitmaps.begin(); | |
293 iter != bitmaps.end(); | |
294 ++iter) { | |
295 | |
296 // If we don't have a best candidate yet, this is better so just grab it. | |
297 if (best_candidate_.isNull()) { | |
298 best_candidate_ = gfx::ImageSkia(*iter).DeepCopy(); | |
299 continue; | |
300 } | |
301 // If the new bitmap is bigger than the best candidate, and not greater | |
302 // than the max size, grab it. | |
303 if (iter->height() > kMaxIconSize || iter->width() > kMaxIconSize) | |
304 continue; | |
305 | |
306 if (iter->height() <= best_candidate_.height() || | |
307 iter->width() <= best_candidate_.width()) { | |
308 continue; | |
309 } | |
310 | |
311 best_candidate_ = gfx::ImageSkia(*iter).DeepCopy(); | |
312 } | |
313 } | |
314 | |
315 // If there are no more URLs to download, pin the page on the FILE thread. | |
316 if (in_progress_urls_.empty()) { | |
317 content::BrowserThread::PostTask( | |
318 content::BrowserThread::FILE, | |
319 FROM_HERE, | |
320 base::Bind(&PagePinner::PinPageToStartScreen, | |
321 this, | |
322 title_, | |
323 url_, | |
324 best_candidate_)); | |
325 return; | |
326 } | |
327 } | |
328 | |
329 void MetroPinTabHelper::PagePinner::PinPageToStartScreen( | |
160 const string16& title, | 330 const string16& title, |
161 const string16& url, | 331 const string16& url, |
162 const gfx::ImageSkia& image) { | 332 const gfx::ImageSkia& image) { |
163 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 333 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
164 | 334 |
165 string16 tile_id = GenerateTileId(url); | 335 string16 tile_id = GenerateTileId(url); |
166 FilePath logo_dir = GetTileImagesDir(); | 336 FilePath logo_dir = GetTileImagesDir(); |
167 if (logo_dir.empty()) { | 337 if (logo_dir.empty()) { |
168 LOG(ERROR) << "Could not create directory to store tile image."; | 338 LOG(ERROR) << "Could not create directory to store tile image."; |
169 return; | 339 return; |
(...skipping 21 matching lines...) Expand all Loading... | |
191 } | 361 } |
192 | 362 |
193 VLOG(1) << __FUNCTION__ << " calling pin with title: " << title | 363 VLOG(1) << __FUNCTION__ << " calling pin with title: " << title |
194 << " and url: " << url; | 364 << " and url: " << url; |
195 metro_pin_to_start_screen(tile_id, title, url, logo_path); | 365 metro_pin_to_start_screen(tile_id, title, url, logo_path); |
196 } | 366 } |
197 | 367 |
198 MetroPinTabHelper::MetroPinTabHelper(content::WebContents* web_contents) | 368 MetroPinTabHelper::MetroPinTabHelper(content::WebContents* web_contents) |
199 : content::WebContentsObserver(web_contents), | 369 : content::WebContentsObserver(web_contents), |
200 is_pinned_(false), | 370 is_pinned_(false), |
201 task_runner_(new TaskRunner) {} | 371 page_pinner_(new PagePinner) {} |
202 | 372 |
203 MetroPinTabHelper::~MetroPinTabHelper() {} | 373 MetroPinTabHelper::~MetroPinTabHelper() {} |
204 | 374 |
205 void MetroPinTabHelper::TogglePinnedToStartScreen() { | 375 void MetroPinTabHelper::TogglePinnedToStartScreen() { |
206 UpdatePinnedStateForCurrentURL(); | 376 UpdatePinnedStateForCurrentURL(); |
207 bool was_pinned = is_pinned_; | 377 bool was_pinned = is_pinned_; |
208 | 378 |
209 // TODO(benwells): This will update the state incorrectly if the user | 379 // TODO(benwells): This will update the state incorrectly if the user |
210 // cancels. To fix this some sort of callback needs to be introduced as | 380 // cancels. To fix this some sort of callback needs to be introduced as |
211 // the pinning happens on another thread. | 381 // the pinning happens on another thread. |
212 is_pinned_ = !is_pinned_; | 382 is_pinned_ = !is_pinned_; |
213 | 383 |
214 if (was_pinned) { | 384 if (was_pinned) { |
215 UnPinPageFromStartScreen(); | 385 UnPinPageFromStartScreen(); |
216 return; | 386 return; |
217 } | 387 } |
218 | 388 |
219 // TODO(benwells): Handle downloading a larger favicon if there is one. | |
220 GURL url = web_contents()->GetURL(); | 389 GURL url = web_contents()->GetURL(); |
221 string16 url_str = UTF8ToUTF16(url.spec()); | 390 string16 url_str = UTF8ToUTF16(url.spec()); |
222 string16 title = web_contents()->GetTitle(); | 391 string16 title = web_contents()->GetTitle(); |
223 TabContents* tab_contents = TabContents::FromWebContents(web_contents()); | |
224 DCHECK(tab_contents); | |
225 FaviconTabHelper* favicon_tab_helper = FaviconTabHelper::FromWebContents( | 392 FaviconTabHelper* favicon_tab_helper = FaviconTabHelper::FromWebContents( |
226 tab_contents->web_contents()); | 393 web_contents()); |
227 if (favicon_tab_helper->FaviconIsValid()) { | 394 if (favicon_tab_helper->FaviconIsValid()) { |
228 gfx::Image favicon = favicon_tab_helper->GetFavicon(); | 395 gfx::Image favicon = favicon_tab_helper->GetFavicon(); |
229 gfx::ImageSkia favicon_skia = favicon.AsImageSkia().DeepCopy(); | 396 gfx::ImageSkia favicon_skia = favicon.AsImageSkia().DeepCopy(); |
230 content::BrowserThread::PostTask( | 397 page_pinner_->StartDownloadingFavicons(web_contents()->GetRenderViewHost(), |
231 content::BrowserThread::FILE, | 398 title, |
232 FROM_HERE, | 399 url_str, |
233 base::Bind(&TaskRunner::PinPageToStartScreen, | 400 favicon_skia); |
234 task_runner_, | |
235 title, | |
236 url_str, | |
237 favicon_skia)); | |
238 return; | 401 return; |
239 } | 402 } |
240 | 403 |
241 content::BrowserThread::PostTask( | 404 page_pinner_->StartDownloadingFavicons(web_contents()->GetRenderViewHost(), |
242 content::BrowserThread::FILE, | 405 title, |
243 FROM_HERE, | 406 url_str, |
244 base::Bind(&TaskRunner::PinPageToStartScreen, | 407 gfx::ImageSkia()); |
245 task_runner_, | |
246 title, | |
247 url_str, | |
248 gfx::ImageSkia())); | |
249 } | 408 } |
250 | 409 |
251 void MetroPinTabHelper::DidNavigateMainFrame( | 410 void MetroPinTabHelper::DidNavigateMainFrame( |
252 const content::LoadCommittedDetails& /*details*/, | 411 const content::LoadCommittedDetails& /*details*/, |
253 const content::FrameNavigateParams& /*params*/) { | 412 const content::FrameNavigateParams& /*params*/) { |
254 UpdatePinnedStateForCurrentURL(); | 413 UpdatePinnedStateForCurrentURL(); |
414 page_pinner_->ClearCurrentPageInfo(); | |
415 } | |
416 | |
417 bool MetroPinTabHelper::OnMessageReceived(const IPC::Message& message) { | |
418 bool message_handled = false; // Allow other handlers to receive these. | |
419 IPC_BEGIN_MESSAGE_MAP(MetroPinTabHelper, message) | |
420 IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) | |
421 IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon) | |
422 IPC_MESSAGE_UNHANDLED(message_handled = false) | |
423 IPC_END_MESSAGE_MAP() | |
424 return message_handled; | |
425 } | |
426 | |
427 void MetroPinTabHelper::OnUpdateFaviconURL( | |
428 int32 page_id, | |
429 const std::vector<FaviconURL>& candidates) { | |
430 page_pinner_->SetFaviconCandidates(candidates); | |
431 } | |
432 | |
433 void MetroPinTabHelper::OnDidDownloadFavicon( | |
434 int id, | |
435 const GURL& image_url, | |
436 bool errored, | |
437 int requested_size, | |
438 const std::vector<SkBitmap>& bitmaps) { | |
439 page_pinner_->OnDidDownloadFavicon(id, image_url, errored, requested_size, | |
440 bitmaps); | |
255 } | 441 } |
256 | 442 |
257 void MetroPinTabHelper::UpdatePinnedStateForCurrentURL() { | 443 void MetroPinTabHelper::UpdatePinnedStateForCurrentURL() { |
258 HMODULE metro_module = base::win::GetMetroModule(); | 444 HMODULE metro_module = base::win::GetMetroModule(); |
259 if (!metro_module) | 445 if (!metro_module) |
260 return; | 446 return; |
261 | 447 |
262 typedef BOOL (*MetroIsPinnedToStartScreen)(const string16&); | 448 typedef BOOL (*MetroIsPinnedToStartScreen)(const string16&); |
263 MetroIsPinnedToStartScreen metro_is_pinned_to_start_screen = | 449 MetroIsPinnedToStartScreen metro_is_pinned_to_start_screen = |
264 reinterpret_cast<MetroIsPinnedToStartScreen>( | 450 reinterpret_cast<MetroIsPinnedToStartScreen>( |
(...skipping 23 matching lines...) Expand all Loading... | |
288 NOTREACHED(); | 474 NOTREACHED(); |
289 return; | 475 return; |
290 } | 476 } |
291 | 477 |
292 GURL url = web_contents()->GetURL(); | 478 GURL url = web_contents()->GetURL(); |
293 VLOG(1) << __FUNCTION__ << " calling unpin with url: " | 479 VLOG(1) << __FUNCTION__ << " calling unpin with url: " |
294 << UTF8ToUTF16(url.spec()); | 480 << UTF8ToUTF16(url.spec()); |
295 string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec())); | 481 string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec())); |
296 metro_un_pin_from_start_screen(tile_id); | 482 metro_un_pin_from_start_screen(tile_id); |
297 } | 483 } |
OLD | NEW |