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