| 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( | |
| 355 favicon_download_helper_(web_contents, this)) { | |
| 356 } | 352 } |
| 357 | 353 |
| 358 MetroPinTabHelper::~MetroPinTabHelper() {} | 354 MetroPinTabHelper::~MetroPinTabHelper() {} |
| 359 | 355 |
| 360 bool MetroPinTabHelper::IsPinned() const { | 356 bool MetroPinTabHelper::IsPinned() const { |
| 361 HMODULE metro_module = base::win::GetMetroModule(); | 357 HMODULE metro_module = base::win::GetMetroModule(); |
| 362 if (!metro_module) | 358 if (!metro_module) |
| 363 return false; | 359 return false; |
| 364 | 360 |
| 365 typedef BOOL (*MetroIsPinnedToStartScreen)(const string16&); | 361 typedef BOOL (*MetroIsPinnedToStartScreen)(const string16&); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 return; | 395 return; |
| 400 } | 396 } |
| 401 | 397 |
| 402 // Request all the candidates. | 398 // Request all the candidates. |
| 403 int image_size = 0; // Request the full sized image. | 399 int image_size = 0; // Request the full sized image. |
| 404 for (std::vector<FaviconURL>::const_iterator iter = | 400 for (std::vector<FaviconURL>::const_iterator iter = |
| 405 favicon_url_candidates_.begin(); | 401 favicon_url_candidates_.begin(); |
| 406 iter != favicon_url_candidates_.end(); | 402 iter != favicon_url_candidates_.end(); |
| 407 ++iter) { | 403 ++iter) { |
| 408 favicon_chooser_->AddPendingRequest( | 404 favicon_chooser_->AddPendingRequest( |
| 409 favicon_download_helper_.DownloadFavicon(iter->icon_url, image_size)); | 405 web_contents()->DownloadFavicon(iter->icon_url, image_size, |
| 406 base::Bind(&MetroPinTabHelper::DidDownloadFavicon, |
| 407 base::Unretained(this)))); |
| 410 } | 408 } |
| 411 | 409 |
| 412 } | 410 } |
| 413 | 411 |
| 414 void MetroPinTabHelper::DidNavigateMainFrame( | 412 void MetroPinTabHelper::DidNavigateMainFrame( |
| 415 const content::LoadCommittedDetails& /*details*/, | 413 const content::LoadCommittedDetails& /*details*/, |
| 416 const content::FrameNavigateParams& /*params*/) { | 414 const content::FrameNavigateParams& /*params*/) { |
| 417 // Cancel any outstanding pin operations once the user navigates away from | 415 // Cancel any outstanding pin operations once the user navigates away from |
| 418 // the page. | 416 // the page. |
| 419 if (favicon_chooser_.get()) | 417 if (favicon_chooser_.get()) |
| 420 favicon_chooser_.reset(); | 418 favicon_chooser_.reset(); |
| 421 // Any candidate favicons we have are now out of date so clear them. | 419 // Any candidate favicons we have are now out of date so clear them. |
| 422 favicon_url_candidates_.clear(); | 420 favicon_url_candidates_.clear(); |
| 423 } | 421 } |
| 424 | 422 |
| 425 void MetroPinTabHelper::OnUpdateFaviconURL( | 423 void MetroPinTabHelper::DidUpdateFaviconURL( |
| 426 int32 page_id, | 424 int32 page_id, |
| 427 const std::vector<FaviconURL>& candidates) { | 425 const std::vector<FaviconURL>& candidates) { |
| 428 favicon_url_candidates_ = candidates; | 426 favicon_url_candidates_ = candidates; |
| 429 } | 427 } |
| 430 | 428 |
| 431 void MetroPinTabHelper::OnDidDownloadFavicon( | 429 void MetroPinTabHelper::DidDownloadFavicon( |
| 432 int id, | 430 int id, |
| 433 const GURL& image_url, | 431 const GURL& image_url, |
| 434 bool errored, | 432 bool errored, |
| 435 int requested_size, | 433 int requested_size, |
| 436 const std::vector<SkBitmap>& bitmaps) { | 434 const std::vector<SkBitmap>& bitmaps) { |
| 437 if (favicon_chooser_.get()) { | 435 if (favicon_chooser_.get()) { |
| 438 favicon_chooser_->UpdateCandidate(id, image_url, errored, | 436 favicon_chooser_->UpdateCandidate(id, image_url, errored, |
| 439 requested_size, bitmaps); | 437 requested_size, bitmaps); |
| 440 } | 438 } |
| 441 } | 439 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 455 } | 453 } |
| 456 | 454 |
| 457 GURL url = web_contents()->GetURL(); | 455 GURL url = web_contents()->GetURL(); |
| 458 string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec())); | 456 string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec())); |
| 459 metro_un_pin_from_start_screen(tile_id); | 457 metro_un_pin_from_start_screen(tile_id); |
| 460 } | 458 } |
| 461 | 459 |
| 462 void MetroPinTabHelper::FaviconDownloaderFinished() { | 460 void MetroPinTabHelper::FaviconDownloaderFinished() { |
| 463 favicon_chooser_.reset(); | 461 favicon_chooser_.reset(); |
| 464 } | 462 } |
| OLD | NEW |