| 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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 const std::wstring& application, | 267 const std::wstring& application, |
| 268 const std::wstring& switches, | 268 const std::wstring& switches, |
| 269 const ShellLinkItemList& data, | 269 const ShellLinkItemList& data, |
| 270 int max_slots) { | 270 int max_slots) { |
| 271 // Exit this function when the given vector does not contain any items | 271 // Exit this function when the given vector does not contain any items |
| 272 // because an ICustomDestinationList::AppendCategory() call fails in this | 272 // because an ICustomDestinationList::AppendCategory() call fails in this |
| 273 // case. | 273 // case. |
| 274 if (data.empty() || !max_slots) | 274 if (data.empty() || !max_slots) |
| 275 return S_OK; | 275 return S_OK; |
| 276 | 276 |
| 277 std::wstring category = | 277 std::wstring category = UTF16ToWide(l10n_util::GetStringUTF16(category_id)); |
| 278 base::UTF16ToWide(l10n_util::GetStringUTF16(category_id)); | |
| 279 | 278 |
| 280 // Create an EnumerableObjectCollection object. | 279 // Create an EnumerableObjectCollection object. |
| 281 // We once add the given items to this collection object and add this | 280 // We once add the given items to this collection object and add this |
| 282 // collection to the JumpList. | 281 // collection to the JumpList. |
| 283 base::win::ScopedComPtr<IObjectCollection> collection; | 282 base::win::ScopedComPtr<IObjectCollection> collection; |
| 284 HRESULT result = collection.CreateInstance(CLSID_EnumerableObjectCollection, | 283 HRESULT result = collection.CreateInstance(CLSID_EnumerableObjectCollection, |
| 285 NULL, CLSCTX_INPROC_SERVER); | 284 NULL, CLSCTX_INPROC_SERVER); |
| 286 if (FAILED(result)) | 285 if (FAILED(result)) |
| 287 return false; | 286 return false; |
| 288 | 287 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 NULL, CLSCTX_INPROC_SERVER); | 323 NULL, CLSCTX_INPROC_SERVER); |
| 325 if (FAILED(result)) | 324 if (FAILED(result)) |
| 326 return result; | 325 return result; |
| 327 | 326 |
| 328 // Create an IShellLink object which launches Chrome, and add it to the | 327 // Create an IShellLink object which launches Chrome, and add it to the |
| 329 // collection. We use our application icon as the icon for this item. | 328 // collection. We use our application icon as the icon for this item. |
| 330 // We remove '&' characters from this string so we can share it with our | 329 // We remove '&' characters from this string so we can share it with our |
| 331 // system menu. | 330 // system menu. |
| 332 scoped_refptr<ShellLinkItem> chrome(new ShellLinkItem); | 331 scoped_refptr<ShellLinkItem> chrome(new ShellLinkItem); |
| 333 std::wstring chrome_title = | 332 std::wstring chrome_title = |
| 334 base::UTF16ToWide(l10n_util::GetStringUTF16(IDS_NEW_WINDOW)); | 333 UTF16ToWide(l10n_util::GetStringUTF16(IDS_NEW_WINDOW)); |
| 335 ReplaceSubstringsAfterOffset(&chrome_title, 0, L"&", L""); | 334 ReplaceSubstringsAfterOffset(&chrome_title, 0, L"&", L""); |
| 336 chrome->SetTitle(chrome_title); | 335 chrome->SetTitle(chrome_title); |
| 337 chrome->SetIcon(chrome_path, 0, false); | 336 chrome->SetIcon(chrome_path, 0, false); |
| 338 AddShellLink(collection, chrome_path, chrome_switches, chrome); | 337 AddShellLink(collection, chrome_path, chrome_switches, chrome); |
| 339 | 338 |
| 340 // Create an IShellLink object which launches Chrome in incognito mode, and | 339 // Create an IShellLink object which launches Chrome in incognito mode, and |
| 341 // add it to the collection. We use our application icon as the icon for | 340 // add it to the collection. We use our application icon as the icon for |
| 342 // this item. | 341 // this item. |
| 343 scoped_refptr<ShellLinkItem> incognito(new ShellLinkItem); | 342 scoped_refptr<ShellLinkItem> incognito(new ShellLinkItem); |
| 344 incognito->SetArguments( | 343 incognito->SetArguments( |
| 345 base::ASCIIToWide(std::string("--") + switches::kIncognito)); | 344 ASCIIToWide(std::string("--") + switches::kIncognito)); |
| 346 std::wstring incognito_title = | 345 std::wstring incognito_title = |
| 347 base::UTF16ToWide(l10n_util::GetStringUTF16(IDS_NEW_INCOGNITO_WINDOW)); | 346 UTF16ToWide(l10n_util::GetStringUTF16(IDS_NEW_INCOGNITO_WINDOW)); |
| 348 ReplaceSubstringsAfterOffset(&incognito_title, 0, L"&", L""); | 347 ReplaceSubstringsAfterOffset(&incognito_title, 0, L"&", L""); |
| 349 incognito->SetTitle(incognito_title); | 348 incognito->SetTitle(incognito_title); |
| 350 incognito->SetIcon(chrome_path, 0, false); | 349 incognito->SetIcon(chrome_path, 0, false); |
| 351 AddShellLink(collection, chrome_path, chrome_switches, incognito); | 350 AddShellLink(collection, chrome_path, chrome_switches, incognito); |
| 352 | 351 |
| 353 // We can now add the new list to the JumpList. | 352 // We can now add the new list to the JumpList. |
| 354 // ICustomDestinationList::AddUserTasks() also uses the IObjectArray | 353 // ICustomDestinationList::AddUserTasks() also uses the IObjectArray |
| 355 // interface to retrieve each item in the list. So, we retrieve the | 354 // interface to retrieve each item in the list. So, we retrieve the |
| 356 // IObjectArray interface from the EnumerableObjectCollection object. | 355 // IObjectArray interface from the EnumerableObjectCollection object. |
| 357 base::win::ScopedComPtr<IObjectArray> object_array; | 356 base::win::ScopedComPtr<IObjectArray> object_array; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 // If we have a pending favicon request, cancel it here (it is out of date). | 565 // If we have a pending favicon request, cancel it here (it is out of date). |
| 567 CancelPendingUpdate(); | 566 CancelPendingUpdate(); |
| 568 | 567 |
| 569 { | 568 { |
| 570 base::AutoLock auto_lock(list_lock_); | 569 base::AutoLock auto_lock(list_lock_); |
| 571 most_visited_pages_.clear(); | 570 most_visited_pages_.clear(); |
| 572 for (size_t i = 0; i < data.size(); i++) { | 571 for (size_t i = 0; i < data.size(); i++) { |
| 573 const history::MostVisitedURL& url = data[i]; | 572 const history::MostVisitedURL& url = data[i]; |
| 574 scoped_refptr<ShellLinkItem> link(new ShellLinkItem); | 573 scoped_refptr<ShellLinkItem> link(new ShellLinkItem); |
| 575 std::string url_string = url.url.spec(); | 574 std::string url_string = url.url.spec(); |
| 576 link->SetArguments(base::UTF8ToWide(url_string)); | 575 link->SetArguments(UTF8ToWide(url_string)); |
| 577 link->SetTitle(!url.title.empty()? url.title : link->arguments()); | 576 link->SetTitle(!url.title.empty()? url.title : link->arguments()); |
| 578 most_visited_pages_.push_back(link); | 577 most_visited_pages_.push_back(link); |
| 579 icon_urls_.push_back(make_pair(url_string, link)); | 578 icon_urls_.push_back(make_pair(url_string, link)); |
| 580 } | 579 } |
| 581 } | 580 } |
| 582 | 581 |
| 583 // Send a query that retrieves the first favicon. | 582 // Send a query that retrieves the first favicon. |
| 584 StartLoadingFavicon(); | 583 StartLoadingFavicon(); |
| 585 } | 584 } |
| 586 | 585 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 size_t max_items) { | 634 size_t max_items) { |
| 636 // This code adds the URL and the title strings of the given tab to the | 635 // This code adds the URL and the title strings of the given tab to the |
| 637 // specified list. | 636 // specified list. |
| 638 if (list->size() >= max_items) | 637 if (list->size() >= max_items) |
| 639 return false; | 638 return false; |
| 640 | 639 |
| 641 scoped_refptr<ShellLinkItem> link(new ShellLinkItem); | 640 scoped_refptr<ShellLinkItem> link(new ShellLinkItem); |
| 642 const TabNavigation& current_navigation = | 641 const TabNavigation& current_navigation = |
| 643 tab->navigations.at(tab->current_navigation_index); | 642 tab->navigations.at(tab->current_navigation_index); |
| 644 std::string url = current_navigation.virtual_url().spec(); | 643 std::string url = current_navigation.virtual_url().spec(); |
| 645 link->SetArguments(base::UTF8ToWide(url)); | 644 link->SetArguments(UTF8ToWide(url)); |
| 646 link->SetTitle(current_navigation.title()); | 645 link->SetTitle(current_navigation.title()); |
| 647 list->push_back(link); | 646 list->push_back(link); |
| 648 icon_urls_.push_back(make_pair(url, link)); | 647 icon_urls_.push_back(make_pair(url, link)); |
| 649 return true; | 648 return true; |
| 650 } | 649 } |
| 651 | 650 |
| 652 void JumpList::AddWindow(const TabRestoreService::Window* window, | 651 void JumpList::AddWindow(const TabRestoreService::Window* window, |
| 653 ShellLinkItemList* list, | 652 ShellLinkItemList* list, |
| 654 size_t max_items) { | 653 size_t max_items) { |
| 655 // This code enumerates al the tabs in the given window object and add their | 654 // This code enumerates al the tabs in the given window object and add their |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 } | 751 } |
| 753 | 752 |
| 754 void JumpList::CreateIconFiles(const ShellLinkItemList& item_list) { | 753 void JumpList::CreateIconFiles(const ShellLinkItemList& item_list) { |
| 755 for (ShellLinkItemList::const_iterator item = item_list.begin(); | 754 for (ShellLinkItemList::const_iterator item = item_list.begin(); |
| 756 item != item_list.end(); ++item) { | 755 item != item_list.end(); ++item) { |
| 757 base::FilePath icon_path; | 756 base::FilePath icon_path; |
| 758 if (CreateIconFile((*item)->data(), icon_dir_, &icon_path)) | 757 if (CreateIconFile((*item)->data(), icon_dir_, &icon_path)) |
| 759 (*item)->SetIcon(icon_path.value(), 0, true); | 758 (*item)->SetIcon(icon_path.value(), 0, true); |
| 760 } | 759 } |
| 761 } | 760 } |
| OLD | NEW |