| 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/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 18 #include "base/string_number_conversions.h" | 18 #include "base/string_number_conversions.h" |
| 19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "base/win/metro.h" | 20 #include "base/win/metro.h" |
| 21 #include "chrome/browser/favicon/favicon_download_helper.h" | |
| 22 #include "chrome/browser/favicon/favicon_tab_helper.h" | 21 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 23 #include "chrome/browser/favicon/favicon_util.h" | 22 #include "chrome/browser/favicon/favicon_util.h" |
| 24 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 23 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 25 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/icon_messages.h" | |
| 27 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 29 #include "crypto/sha2.h" | 27 #include "crypto/sha2.h" |
| 30 #include "third_party/skia/include/core/SkCanvas.h" | 28 #include "third_party/skia/include/core/SkCanvas.h" |
| 31 #include "third_party/skia/include/core/SkColor.h" | 29 #include "third_party/skia/include/core/SkColor.h" |
| 32 #include "ui/gfx/canvas.h" | 30 #include "ui/gfx/canvas.h" |
| 33 #include "ui/gfx/codec/png_codec.h" | 31 #include "ui/gfx/codec/png_codec.h" |
| 34 #include "ui/gfx/color_analysis.h" | 32 #include "ui/gfx/color_analysis.h" |
| 35 #include "ui/gfx/color_utils.h" | 33 #include "ui/gfx/color_utils.h" |
| 36 #include "ui/gfx/image/image.h" | 34 #include "ui/gfx/image/image.h" |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 // Once this happens this downloader has done its job, so delete it. | 359 // Once this happens this downloader has done its job, so delete it. |
| 362 if (in_progress_requests_.empty()) | 360 if (in_progress_requests_.empty()) |
| 363 UseChosenCandidate(); | 361 UseChosenCandidate(); |
| 364 } | 362 } |
| 365 | 363 |
| 366 void MetroPinTabHelper::FaviconChooser::AddPendingRequest(int request_id) { | 364 void MetroPinTabHelper::FaviconChooser::AddPendingRequest(int request_id) { |
| 367 in_progress_requests_.insert(request_id); | 365 in_progress_requests_.insert(request_id); |
| 368 } | 366 } |
| 369 | 367 |
| 370 MetroPinTabHelper::MetroPinTabHelper(content::WebContents* web_contents) | 368 MetroPinTabHelper::MetroPinTabHelper(content::WebContents* web_contents) |
| 371 : content::WebContentsObserver(web_contents), | 369 : content::WebContentsObserver(web_contents) { |
| 372 ALLOW_THIS_IN_INITIALIZER_LIST( | |
| 373 favicon_download_helper_(web_contents, this)) { | |
| 374 } | 370 } |
| 375 | 371 |
| 376 MetroPinTabHelper::~MetroPinTabHelper() {} | 372 MetroPinTabHelper::~MetroPinTabHelper() {} |
| 377 | 373 |
| 378 bool MetroPinTabHelper::IsPinned() const { | 374 bool MetroPinTabHelper::IsPinned() const { |
| 379 HMODULE metro_module = base::win::GetMetroModule(); | 375 HMODULE metro_module = base::win::GetMetroModule(); |
| 380 if (!metro_module) | 376 if (!metro_module) |
| 381 return false; | 377 return false; |
| 382 | 378 |
| 383 typedef BOOL (*MetroIsPinnedToStartScreen)(const string16&); | 379 typedef BOOL (*MetroIsPinnedToStartScreen)(const string16&); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 | 414 |
| 419 favicon_chooser_.reset(new FaviconChooser(this, title, url_str, favicon)); | 415 favicon_chooser_.reset(new FaviconChooser(this, title, url_str, favicon)); |
| 420 | 416 |
| 421 if (favicon_url_candidates_.empty()) { | 417 if (favicon_url_candidates_.empty()) { |
| 422 favicon_chooser_->UseChosenCandidate(); | 418 favicon_chooser_->UseChosenCandidate(); |
| 423 return; | 419 return; |
| 424 } | 420 } |
| 425 | 421 |
| 426 // Request all the candidates. | 422 // Request all the candidates. |
| 427 int image_size = 0; // Request the full sized image. | 423 int image_size = 0; // Request the full sized image. |
| 428 for (std::vector<FaviconURL>::const_iterator iter = | 424 for (std::vector<content::FaviconURL>::const_iterator iter = |
| 429 favicon_url_candidates_.begin(); | 425 favicon_url_candidates_.begin(); |
| 430 iter != favicon_url_candidates_.end(); | 426 iter != favicon_url_candidates_.end(); |
| 431 ++iter) { | 427 ++iter) { |
| 432 favicon_chooser_->AddPendingRequest( | 428 favicon_chooser_->AddPendingRequest( |
| 433 favicon_download_helper_.DownloadFavicon(iter->icon_url, image_size)); | 429 web_contents()->DownloadFavicon(iter->icon_url, image_size, |
| 430 base::Bind(&MetroPinTabHelper::DidDownloadFavicon, |
| 431 base::Unretained(this)))); |
| 434 } | 432 } |
| 435 | 433 |
| 436 } | 434 } |
| 437 | 435 |
| 438 void MetroPinTabHelper::DidNavigateMainFrame( | 436 void MetroPinTabHelper::DidNavigateMainFrame( |
| 439 const content::LoadCommittedDetails& /*details*/, | 437 const content::LoadCommittedDetails& /*details*/, |
| 440 const content::FrameNavigateParams& /*params*/) { | 438 const content::FrameNavigateParams& /*params*/) { |
| 441 // Cancel any outstanding pin operations once the user navigates away from | 439 // Cancel any outstanding pin operations once the user navigates away from |
| 442 // the page. | 440 // the page. |
| 443 if (favicon_chooser_.get()) | 441 if (favicon_chooser_.get()) |
| 444 favicon_chooser_.reset(); | 442 favicon_chooser_.reset(); |
| 445 // Any candidate favicons we have are now out of date so clear them. | 443 // Any candidate favicons we have are now out of date so clear them. |
| 446 favicon_url_candidates_.clear(); | 444 favicon_url_candidates_.clear(); |
| 447 } | 445 } |
| 448 | 446 |
| 449 void MetroPinTabHelper::OnUpdateFaviconURL( | 447 void MetroPinTabHelper::DidUpdateFaviconURL( |
| 450 int32 page_id, | 448 int32 page_id, |
| 451 const std::vector<FaviconURL>& candidates) { | 449 const std::vector<content::FaviconURL>& candidates) { |
| 452 favicon_url_candidates_ = candidates; | 450 favicon_url_candidates_ = candidates; |
| 453 } | 451 } |
| 454 | 452 |
| 455 void MetroPinTabHelper::OnDidDownloadFavicon( | 453 void MetroPinTabHelper::DidDownloadFavicon( |
| 456 int id, | 454 int id, |
| 457 const GURL& image_url, | 455 const GURL& image_url, |
| 458 bool errored, | 456 bool errored, |
| 459 int requested_size, | 457 int requested_size, |
| 460 const std::vector<SkBitmap>& bitmaps) { | 458 const std::vector<SkBitmap>& bitmaps) { |
| 461 if (favicon_chooser_.get()) { | 459 if (favicon_chooser_.get()) { |
| 462 favicon_chooser_->UpdateCandidate(id, image_url, errored, | 460 favicon_chooser_->UpdateCandidate(id, image_url, errored, |
| 463 requested_size, bitmaps); | 461 requested_size, bitmaps); |
| 464 } | 462 } |
| 465 } | 463 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 479 | 477 |
| 480 GURL url = web_contents()->GetURL(); | 478 GURL url = web_contents()->GetURL(); |
| 481 string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec())); | 479 string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec())); |
| 482 metro_un_pin_from_start_screen(tile_id, | 480 metro_un_pin_from_start_screen(tile_id, |
| 483 base::Bind(&PinPageReportUmaCallback)); | 481 base::Bind(&PinPageReportUmaCallback)); |
| 484 } | 482 } |
| 485 | 483 |
| 486 void MetroPinTabHelper::FaviconDownloaderFinished() { | 484 void MetroPinTabHelper::FaviconDownloaderFinished() { |
| 487 favicon_chooser_.reset(); | 485 favicon_chooser_.reset(); |
| 488 } | 486 } |
| OLD | NEW |