| 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/jumplist_win.h" | 5 #include "chrome/browser/jumplist_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shobjidl.h> | 8 #include <shobjidl.h> |
| 9 #include <propkey.h> | 9 #include <propkey.h> |
| 10 #include <propvarutil.h> | 10 #include <propvarutil.h> |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
| 38 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
| 39 #include "content/public/browser/browser_thread.h" | 39 #include "content/public/browser/browser_thread.h" |
| 40 #include "content/public/browser/notification_source.h" | 40 #include "content/public/browser/notification_source.h" |
| 41 #include "googleurl/src/gurl.h" | 41 #include "googleurl/src/gurl.h" |
| 42 #include "grit/chromium_strings.h" | 42 #include "grit/chromium_strings.h" |
| 43 #include "grit/generated_resources.h" | 43 #include "grit/generated_resources.h" |
| 44 #include "third_party/skia/include/core/SkBitmap.h" | 44 #include "third_party/skia/include/core/SkBitmap.h" |
| 45 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
| 46 #include "ui/gfx/codec/png_codec.h" | 46 #include "ui/gfx/codec/png_codec.h" |
| 47 #include "ui/gfx/favicon_size.h" |
| 47 #include "ui/gfx/icon_util.h" | 48 #include "ui/gfx/icon_util.h" |
| 48 | 49 |
| 49 using content::BrowserThread; | 50 using content::BrowserThread; |
| 50 | 51 |
| 51 namespace { | 52 namespace { |
| 52 | 53 |
| 53 // COM interfaces used in this file. | 54 // COM interfaces used in this file. |
| 54 // These interface declarations are copied from Windows SDK 7.0. | 55 // These interface declarations are copied from Windows SDK 7.0. |
| 55 // TODO(hbono): Bug 16903: delete them when we use Windows SDK 7.0. | 56 // TODO(hbono): Bug 16903: delete them when we use Windows SDK 7.0. |
| 56 #ifndef __IObjectArray_INTERFACE_DEFINED__ | 57 #ifndef __IObjectArray_INTERFACE_DEFINED__ |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 { | 695 { |
| 695 base::AutoLock auto_lock(list_lock_); | 696 base::AutoLock auto_lock(list_lock_); |
| 696 if (icon_urls_.empty()) | 697 if (icon_urls_.empty()) |
| 697 return false; | 698 return false; |
| 698 // Ask FaviconService if it has a favicon of a URL. | 699 // Ask FaviconService if it has a favicon of a URL. |
| 699 // When FaviconService has one, it will call OnFaviconDataAvailable(). | 700 // When FaviconService has one, it will call OnFaviconDataAvailable(). |
| 700 url = GURL(icon_urls_.front().first); | 701 url = GURL(icon_urls_.front().first); |
| 701 } | 702 } |
| 702 FaviconService* favicon_service = | 703 FaviconService* favicon_service = |
| 703 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 704 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 704 handle_ = favicon_service->GetFaviconForURL( | 705 handle_ = favicon_service->GetFaviconImageForURL( |
| 705 profile_, url, history::FAVICON, &favicon_consumer_, | 706 profile_, url, history::FAVICON, gfx::kFaviconSize, &favicon_consumer_, |
| 706 base::Bind(&JumpList::OnFaviconDataAvailable, base::Unretained(this))); | 707 base::Bind(&JumpList::OnFaviconDataAvailable, base::Unretained(this))); |
| 707 return true; | 708 return true; |
| 708 } | 709 } |
| 709 | 710 |
| 710 void JumpList::OnFaviconDataAvailable( | 711 void JumpList::OnFaviconDataAvailable( |
| 711 FaviconService::Handle handle, | 712 FaviconService::Handle handle, |
| 712 history::FaviconData favicon) { | 713 const history::FaviconImageResult& image_result) { |
| 713 // If there is currently a favicon request in progress, it is now outdated, | 714 // If there is currently a favicon request in progress, it is now outdated, |
| 714 // as we have received another, so nullify the handle from the old request. | 715 // as we have received another, so nullify the handle from the old request. |
| 715 handle_ = NULL; | 716 handle_ = NULL; |
| 716 // lock the list to set icon data and pop the url | 717 // lock the list to set icon data and pop the url |
| 717 { | 718 { |
| 718 base::AutoLock auto_lock(list_lock_); | 719 base::AutoLock auto_lock(list_lock_); |
| 719 // Attach the received data to the ShellLinkItem object. | 720 // Attach the received data to the ShellLinkItem object. |
| 720 // This data will be decoded by the RunUpdate method. | 721 // This data will be decoded by the RunUpdate method. |
| 721 if (favicon.is_valid()) { | 722 if (!image_result.image.IsEmpty()) { |
| 722 if (!icon_urls_.empty() && icon_urls_.front().second) | 723 if (!icon_urls_.empty() && icon_urls_.front().second) |
| 723 icon_urls_.front().second->SetIconData(favicon.image_data); | 724 icon_urls_.front().second->SetIconData(image_result.image.AsBitmap()); |
| 724 } | 725 } |
| 725 | 726 |
| 726 if (!icon_urls_.empty()) | 727 if (!icon_urls_.empty()) |
| 727 icon_urls_.pop_front(); | 728 icon_urls_.pop_front(); |
| 728 } | 729 } |
| 729 // if we need to load more favicons, we send another query and exit. | 730 // if we need to load more favicons, we send another query and exit. |
| 730 if (StartLoadingFavicon()) | 731 if (StartLoadingFavicon()) |
| 731 return; | 732 return; |
| 732 | 733 |
| 733 // Finished loading all favicons needed by the application JumpList. | 734 // Finished loading all favicons needed by the application JumpList. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 757 // Delete the directory which contains old icon files, rename the current | 758 // Delete the directory which contains old icon files, rename the current |
| 758 // icon directory, and create a new directory which contains new JumpList | 759 // icon directory, and create a new directory which contains new JumpList |
| 759 // icon files. | 760 // icon files. |
| 760 FilePath icon_dir_old(icon_dir_.value() + L"Old"); | 761 FilePath icon_dir_old(icon_dir_.value() + L"Old"); |
| 761 if (file_util::PathExists(icon_dir_old)) | 762 if (file_util::PathExists(icon_dir_old)) |
| 762 file_util::Delete(icon_dir_old, true); | 763 file_util::Delete(icon_dir_old, true); |
| 763 file_util::Move(icon_dir_, icon_dir_old); | 764 file_util::Move(icon_dir_, icon_dir_old); |
| 764 file_util::CreateDirectory(icon_dir_); | 765 file_util::CreateDirectory(icon_dir_); |
| 765 | 766 |
| 766 // Create temporary icon files for shortcuts in the "Most Visited" category. | 767 // Create temporary icon files for shortcuts in the "Most Visited" category. |
| 767 DecodeIconData(local_most_visited_pages); | 768 CreateIconFiles(local_most_visited_pages); |
| 768 | 769 |
| 769 // Create temporary icon files for shortcuts in the "Recently Closed" | 770 // Create temporary icon files for shortcuts in the "Recently Closed" |
| 770 // category. | 771 // category. |
| 771 DecodeIconData(local_recently_closed_pages); | 772 CreateIconFiles(local_recently_closed_pages); |
| 772 | 773 |
| 773 // We finished collecting all resources needed for updating an appliation | 774 // We finished collecting all resources needed for updating an appliation |
| 774 // JumpList. So, create a new JumpList and replace the current JumpList | 775 // JumpList. So, create a new JumpList and replace the current JumpList |
| 775 // with it. | 776 // with it. |
| 776 UpdateJumpList(app_id_.c_str(), local_most_visited_pages, | 777 UpdateJumpList(app_id_.c_str(), local_most_visited_pages, |
| 777 local_recently_closed_pages); | 778 local_recently_closed_pages); |
| 778 } | 779 } |
| 779 | 780 |
| 780 void JumpList::DecodeIconData(const ShellLinkItemList& item_list) { | 781 void JumpList::CreateIconFiles(const ShellLinkItemList& item_list) { |
| 781 for (ShellLinkItemList::const_iterator item = item_list.begin(); | 782 for (ShellLinkItemList::const_iterator item = item_list.begin(); |
| 782 item != item_list.end(); ++item) { | 783 item != item_list.end(); ++item) { |
| 783 SkBitmap icon_bitmap; | 784 FilePath icon_path; |
| 784 if ((*item)->data().get() && | 785 if (CreateIconFile((*item)->data(), icon_dir_, &icon_path)) |
| 785 gfx::PNGCodec::Decode((*item)->data()->front(), | 786 (*item)->SetIcon(icon_path.value(), 0, true); |
| 786 (*item)->data()->size(), | |
| 787 &icon_bitmap)) { | |
| 788 FilePath icon_path; | |
| 789 if (CreateIconFile(icon_bitmap, icon_dir_, &icon_path)) | |
| 790 (*item)->SetIcon(icon_path.value(), 0, true); | |
| 791 } | |
| 792 } | 787 } |
| 793 } | 788 } |
| OLD | NEW |