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> | 7 #include <set> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/ref_counted_memory.h" | 15 #include "base/memory/ref_counted_memory.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
19 #include "base/win/metro.h" | 19 #include "base/win/metro.h" |
20 #include "chrome/browser/favicon/favicon_download_helper.h" | |
21 #include "chrome/browser/favicon/favicon_tab_helper.h" | 20 #include "chrome/browser/favicon/favicon_tab_helper.h" |
22 #include "chrome/browser/favicon/favicon_util.h" | 21 #include "chrome/browser/favicon/favicon_util.h" |
23 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 22 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
24 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
25 #include "chrome/common/icon_messages.h" | |
26 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
28 #include "crypto/sha2.h" | 26 #include "crypto/sha2.h" |
29 #include "third_party/skia/include/core/SkCanvas.h" | 27 #include "third_party/skia/include/core/SkCanvas.h" |
30 #include "third_party/skia/include/core/SkColor.h" | 28 #include "third_party/skia/include/core/SkColor.h" |
31 #include "ui/gfx/canvas.h" | 29 #include "ui/gfx/canvas.h" |
32 #include "ui/gfx/codec/png_codec.h" | 30 #include "ui/gfx/codec/png_codec.h" |
33 #include "ui/gfx/color_analysis.h" | 31 #include "ui/gfx/color_analysis.h" |
34 #include "ui/gfx/color_utils.h" | 32 #include "ui/gfx/color_utils.h" |
35 #include "ui/gfx/image/image.h" | 33 #include "ui/gfx/image/image.h" |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 // Once this happens this downloader has done its job, so delete it. | 341 // Once this happens this downloader has done its job, so delete it. |
344 if (in_progress_requests_.empty()) | 342 if (in_progress_requests_.empty()) |
345 UseChosenCandidate(); | 343 UseChosenCandidate(); |
346 } | 344 } |
347 | 345 |
348 void MetroPinTabHelper::FaviconChooser::AddPendingRequest(int request_id) { | 346 void MetroPinTabHelper::FaviconChooser::AddPendingRequest(int request_id) { |
349 in_progress_requests_.insert(request_id); | 347 in_progress_requests_.insert(request_id); |
350 } | 348 } |
351 | 349 |
352 MetroPinTabHelper::MetroPinTabHelper(content::WebContents* web_contents) | 350 MetroPinTabHelper::MetroPinTabHelper(content::WebContents* web_contents) |
353 : content::WebContentsObserver(web_contents), | 351 : content::WebContentsObserver(web_contents) { |
354 ALLOW_THIS_IN_INITIALIZER_LIST( | 352 web_contents->RegisterFaviconDelegate(this); |
355 favicon_download_helper_(web_contents, this)) { | |
356 } | 353 } |
357 | 354 |
358 MetroPinTabHelper::~MetroPinTabHelper() {} | 355 MetroPinTabHelper::~MetroPinTabHelper() {} |
359 | 356 |
360 bool MetroPinTabHelper::IsPinned() const { | 357 bool MetroPinTabHelper::IsPinned() const { |
361 HMODULE metro_module = base::win::GetMetroModule(); | 358 HMODULE metro_module = base::win::GetMetroModule(); |
362 if (!metro_module) | 359 if (!metro_module) |
363 return false; | 360 return false; |
364 | 361 |
365 typedef BOOL (*MetroIsPinnedToStartScreen)(const string16&); | 362 typedef BOOL (*MetroIsPinnedToStartScreen)(const string16&); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 return; | 396 return; |
400 } | 397 } |
401 | 398 |
402 // Request all the candidates. | 399 // Request all the candidates. |
403 int image_size = 0; // Request the full sized image. | 400 int image_size = 0; // Request the full sized image. |
404 for (std::vector<FaviconURL>::const_iterator iter = | 401 for (std::vector<FaviconURL>::const_iterator iter = |
405 favicon_url_candidates_.begin(); | 402 favicon_url_candidates_.begin(); |
406 iter != favicon_url_candidates_.end(); | 403 iter != favicon_url_candidates_.end(); |
407 ++iter) { | 404 ++iter) { |
408 favicon_chooser_->AddPendingRequest( | 405 favicon_chooser_->AddPendingRequest( |
409 favicon_download_helper_.DownloadFavicon(iter->icon_url, image_size)); | 406 web_contents()->DownloadFavicon(iter->icon_url, image_size)); |
410 } | 407 } |
411 | 408 |
412 } | 409 } |
413 | 410 |
414 void MetroPinTabHelper::DidNavigateMainFrame( | 411 void MetroPinTabHelper::DidNavigateMainFrame( |
415 const content::LoadCommittedDetails& /*details*/, | 412 const content::LoadCommittedDetails& /*details*/, |
416 const content::FrameNavigateParams& /*params*/) { | 413 const content::FrameNavigateParams& /*params*/) { |
417 // Cancel any outstanding pin operations once the user navigates away from | 414 // Cancel any outstanding pin operations once the user navigates away from |
418 // the page. | 415 // the page. |
419 if (favicon_chooser_.get()) | 416 if (favicon_chooser_.get()) |
420 favicon_chooser_.reset(); | 417 favicon_chooser_.reset(); |
421 // Any candidate favicons we have are now out of date so clear them. | 418 // Any candidate favicons we have are now out of date so clear them. |
422 favicon_url_candidates_.clear(); | 419 favicon_url_candidates_.clear(); |
423 } | 420 } |
424 | 421 |
425 void MetroPinTabHelper::OnUpdateFaviconURL( | 422 void MetroPinTabHelper::UpdateFaviconURL( |
426 int32 page_id, | 423 int32 page_id, |
427 const std::vector<FaviconURL>& candidates) { | 424 const std::vector<FaviconURL>& candidates) { |
428 favicon_url_candidates_ = candidates; | 425 favicon_url_candidates_ = candidates; |
429 } | 426 } |
430 | 427 |
431 void MetroPinTabHelper::OnDidDownloadFavicon( | 428 void MetroPinTabHelper::DidDownloadFavicon( |
432 int id, | 429 int id, |
433 const GURL& image_url, | 430 const GURL& image_url, |
434 bool errored, | 431 bool errored, |
435 int requested_size, | 432 int requested_size, |
436 const std::vector<SkBitmap>& bitmaps) { | 433 const std::vector<SkBitmap>& bitmaps) { |
437 if (favicon_chooser_.get()) { | 434 if (favicon_chooser_.get()) { |
438 favicon_chooser_->UpdateCandidate(id, image_url, errored, | 435 favicon_chooser_->UpdateCandidate(id, image_url, errored, |
439 requested_size, bitmaps); | 436 requested_size, bitmaps); |
440 } | 437 } |
441 } | 438 } |
(...skipping 13 matching lines...) Expand all Loading... |
455 } | 452 } |
456 | 453 |
457 GURL url = web_contents()->GetURL(); | 454 GURL url = web_contents()->GetURL(); |
458 string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec())); | 455 string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec())); |
459 metro_un_pin_from_start_screen(tile_id); | 456 metro_un_pin_from_start_screen(tile_id); |
460 } | 457 } |
461 | 458 |
462 void MetroPinTabHelper::FaviconDownloaderFinished() { | 459 void MetroPinTabHelper::FaviconDownloaderFinished() { |
463 favicon_chooser_.reset(); | 460 favicon_chooser_.reset(); |
464 } | 461 } |
OLD | NEW |