| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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.h" | 5 #include "chrome/browser/jumplist.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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 result = property_store->Commit(); | 232 result = property_store->Commit(); |
| 233 if (FAILED(result)) | 233 if (FAILED(result)) |
| 234 return result; | 234 return result; |
| 235 | 235 |
| 236 // Add this IShellLink object to the given collection. | 236 // Add this IShellLink object to the given collection. |
| 237 return collection->AddObject(link); | 237 return collection->AddObject(link); |
| 238 } | 238 } |
| 239 | 239 |
| 240 // Creates a temporary icon file to be shown in JumpList. | 240 // Creates a temporary icon file to be shown in JumpList. |
| 241 bool CreateIconFile(const SkBitmap& bitmap, | 241 bool CreateIconFile(const SkBitmap& bitmap, |
| 242 const std::wstring& icon_dir, | 242 const FilePath& icon_dir, |
| 243 std::wstring* icon_path) { | 243 FilePath* icon_path) { |
| 244 // Retrieve the path to a temporary file. | 244 // Retrieve the path to a temporary file. |
| 245 // We don't have to care about the extension of this temporary file because | 245 // We don't have to care about the extension of this temporary file because |
| 246 // JumpList does not care about it. | 246 // JumpList does not care about it. |
| 247 FilePath path; | 247 FilePath path; |
| 248 if (!file_util::CreateTemporaryFileInDir(FilePath(icon_dir), &path)) | 248 if (!file_util::CreateTemporaryFileInDir(icon_dir, &path)) |
| 249 return false; | 249 return false; |
| 250 | 250 |
| 251 // Create an icon file from the favicon attached to the given |page|, and | 251 // Create an icon file from the favicon attached to the given |page|, and |
| 252 // save it as the temporary file. | 252 // save it as the temporary file. |
| 253 if (!IconUtil::CreateIconFileFromSkBitmap(bitmap, path.value())) | 253 if (!IconUtil::CreateIconFileFromSkBitmap(bitmap, path.value())) |
| 254 return false; | 254 return false; |
| 255 | 255 |
| 256 // Add this icon file to the list and return its absolute path. | 256 // Add this icon file to the list and return its absolute path. |
| 257 // The IShellLink::SetIcon() function needs the absolute path to an icon. | 257 // The IShellLink::SetIcon() function needs the absolute path to an icon. |
| 258 icon_path->assign(path.value()); | 258 *icon_path = path; |
| 259 return true; | 259 return true; |
| 260 } | 260 } |
| 261 | 261 |
| 262 // Updates a specified category of an application JumpList. | 262 // Updates a specified category of an application JumpList. |
| 263 // This function cannot update registered categories (such as "Tasks") because | 263 // This function cannot update registered categories (such as "Tasks") because |
| 264 // special steps are required for updating them. | 264 // special steps are required for updating them. |
| 265 // So, this function can be used only for adding an unregistered category. | 265 // So, this function can be used only for adding an unregistered category. |
| 266 // Parameters: | 266 // Parameters: |
| 267 // * category_id (int) | 267 // * category_id (int) |
| 268 // A string ID which contains the category name. | 268 // A string ID which contains the category name. |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 // 1. Prepare objects required by this task: | 451 // 1. Prepare objects required by this task: |
| 452 // * a std::wstring that contains a temporary icons; | 452 // * a std::wstring that contains a temporary icons; |
| 453 // * a ShellLinkItemList that contains the items of the "Most Visited" | 453 // * a ShellLinkItemList that contains the items of the "Most Visited" |
| 454 // category, and; | 454 // category, and; |
| 455 // * a ShellLinkItemList that contains the items of the "Recently Closed" | 455 // * a ShellLinkItemList that contains the items of the "Recently Closed" |
| 456 // category. | 456 // category. |
| 457 // 2. Create a JumpListUpdateTask instance, and; | 457 // 2. Create a JumpListUpdateTask instance, and; |
| 458 // 3. Post this task to the file thread. | 458 // 3. Post this task to the file thread. |
| 459 class JumpListUpdateTask : public Task { | 459 class JumpListUpdateTask : public Task { |
| 460 public: | 460 public: |
| 461 JumpListUpdateTask(const std::wstring& icon_dir, | 461 JumpListUpdateTask(const FilePath& icon_dir, |
| 462 const ShellLinkItemList& most_visited_pages, | 462 const ShellLinkItemList& most_visited_pages, |
| 463 const ShellLinkItemList& recently_closed_pages) | 463 const ShellLinkItemList& recently_closed_pages) |
| 464 : icon_dir_(icon_dir), | 464 : icon_dir_(icon_dir), |
| 465 most_visited_pages_(most_visited_pages), | 465 most_visited_pages_(most_visited_pages), |
| 466 recently_closed_pages_(recently_closed_pages) { | 466 recently_closed_pages_(recently_closed_pages) { |
| 467 } | 467 } |
| 468 | 468 |
| 469 private: | 469 private: |
| 470 // Represents an entry point of this task. | 470 // Represents an entry point of this task. |
| 471 // When we post this task to a file thread, the thread calls this function. | 471 // When we post this task to a file thread, the thread calls this function. |
| 472 void Run(); | 472 void Run(); |
| 473 | 473 |
| 474 // The directory which contains JumpList icons. | 474 // The directory which contains JumpList icons. |
| 475 std::wstring icon_dir_; | 475 FilePath icon_dir_; |
| 476 | 476 |
| 477 // Items in the "Most Visited" category of the application JumpList. | 477 // Items in the "Most Visited" category of the application JumpList. |
| 478 ShellLinkItemList most_visited_pages_; | 478 ShellLinkItemList most_visited_pages_; |
| 479 | 479 |
| 480 // Items in the "Recently Closed" category of the application JumpList. | 480 // Items in the "Recently Closed" category of the application JumpList. |
| 481 ShellLinkItemList recently_closed_pages_; | 481 ShellLinkItemList recently_closed_pages_; |
| 482 }; | 482 }; |
| 483 | 483 |
| 484 void JumpListUpdateTask::Run() { | 484 void JumpListUpdateTask::Run() { |
| 485 // Delete the directory which contains old icon files, rename the current | 485 // Delete the directory which contains old icon files, rename the current |
| 486 // icon directory, and create a new directory which contains new JumpList | 486 // icon directory, and create a new directory which contains new JumpList |
| 487 // icon files. | 487 // icon files. |
| 488 std::wstring icon_dir_old(icon_dir_ + L"Old"); | 488 FilePath icon_dir_old(icon_dir_.value() + L"Old"); |
| 489 if (file_util::PathExists(FilePath::FromWStringHack(icon_dir_old))) | 489 if (file_util::PathExists(icon_dir_old)) |
| 490 file_util::Delete(icon_dir_old, true); | 490 file_util::Delete(icon_dir_old, true); |
| 491 file_util::Move(FilePath::FromWStringHack(icon_dir_), | 491 file_util::Move(icon_dir_, icon_dir_old); |
| 492 FilePath::FromWStringHack(icon_dir_old)); | |
| 493 file_util::CreateDirectory(icon_dir_); | 492 file_util::CreateDirectory(icon_dir_); |
| 494 | 493 |
| 495 // Create temporary icon files for shortcuts in the "Most Visited" category. | 494 // Create temporary icon files for shortcuts in the "Most Visited" category. |
| 496 for (ShellLinkItemList::const_iterator item = most_visited_pages_.begin(); | 495 for (ShellLinkItemList::const_iterator item = most_visited_pages_.begin(); |
| 497 item != most_visited_pages_.end(); ++item) { | 496 item != most_visited_pages_.end(); ++item) { |
| 498 SkBitmap icon_bitmap; | 497 SkBitmap icon_bitmap; |
| 499 if ((*item)->data().get() && | 498 if ((*item)->data().get() && |
| 500 gfx::PNGCodec::Decode((*item)->data()->front(), | 499 gfx::PNGCodec::Decode((*item)->data()->front(), |
| 501 (*item)->data()->size(), | 500 (*item)->data()->size(), |
| 502 &icon_bitmap)) { | 501 &icon_bitmap)) { |
| 503 std::wstring icon_path; | 502 FilePath icon_path; |
| 504 if (CreateIconFile(icon_bitmap, icon_dir_, &icon_path)) | 503 if (CreateIconFile(icon_bitmap, icon_dir_, &icon_path)) |
| 505 (*item)->SetIcon(icon_path, 0, true); | 504 (*item)->SetIcon(icon_path.value(), 0, true); |
| 506 } | 505 } |
| 507 } | 506 } |
| 508 | 507 |
| 509 // Create temporary icon files for shortcuts in the "Recently Closed" | 508 // Create temporary icon files for shortcuts in the "Recently Closed" |
| 510 // category. | 509 // category. |
| 511 for (ShellLinkItemList::const_iterator item = recently_closed_pages_.begin(); | 510 for (ShellLinkItemList::const_iterator item = recently_closed_pages_.begin(); |
| 512 item != recently_closed_pages_.end(); ++item) { | 511 item != recently_closed_pages_.end(); ++item) { |
| 513 SkBitmap icon_bitmap; | 512 SkBitmap icon_bitmap; |
| 514 if ((*item)->data().get() && | 513 if ((*item)->data().get() && |
| 515 gfx::PNGCodec::Decode((*item)->data()->front(), | 514 gfx::PNGCodec::Decode((*item)->data()->front(), |
| 516 (*item)->data()->size(), | 515 (*item)->data()->size(), |
| 517 &icon_bitmap)) { | 516 &icon_bitmap)) { |
| 518 std::wstring icon_path; | 517 FilePath icon_path; |
| 519 if (CreateIconFile(icon_bitmap, icon_dir_, &icon_path)) | 518 if (CreateIconFile(icon_bitmap, icon_dir_, &icon_path)) |
| 520 (*item)->SetIcon(icon_path, 0, true); | 519 (*item)->SetIcon(icon_path.value(), 0, true); |
| 521 } | 520 } |
| 522 } | 521 } |
| 523 | 522 |
| 524 // We finished collecting all resources needed for updating an appliation | 523 // We finished collecting all resources needed for updating an appliation |
| 525 // JumpList. So, create a new JumpList and replace the current JumpList | 524 // JumpList. So, create a new JumpList and replace the current JumpList |
| 526 // with it. | 525 // with it. |
| 527 UpdateJumpList(most_visited_pages_, recently_closed_pages_); | 526 UpdateJumpList(most_visited_pages_, recently_closed_pages_); |
| 528 | 527 |
| 529 // Delete all items in these lists now since we don't need the ShellLinkItem | 528 // Delete all items in these lists now since we don't need the ShellLinkItem |
| 530 // objects in these lists. | 529 // objects in these lists. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 554 // When we add this object to the observer list, we save the pointer to this | 553 // When we add this object to the observer list, we save the pointer to this |
| 555 // TabRestoreService object. This pointer is used when we remove this object | 554 // TabRestoreService object. This pointer is used when we remove this object |
| 556 // from the observer list. | 555 // from the observer list. |
| 557 if (win_util::GetWinVersion() < win_util::WINVERSION_WIN7 || !profile) | 556 if (win_util::GetWinVersion() < win_util::WINVERSION_WIN7 || !profile) |
| 558 return false; | 557 return false; |
| 559 | 558 |
| 560 TabRestoreService* tab_restore_service = profile->GetTabRestoreService(); | 559 TabRestoreService* tab_restore_service = profile->GetTabRestoreService(); |
| 561 if (!tab_restore_service) | 560 if (!tab_restore_service) |
| 562 return false; | 561 return false; |
| 563 | 562 |
| 564 icon_dir_ = profile->GetPath().Append(chrome::kJumpListIconDirname).value(); | 563 icon_dir_ = profile->GetPath().Append(chrome::kJumpListIconDirname); |
| 565 profile_ = profile; | 564 profile_ = profile; |
| 566 tab_restore_service->AddObserver(this); | 565 tab_restore_service->AddObserver(this); |
| 567 return true; | 566 return true; |
| 568 } | 567 } |
| 569 | 568 |
| 570 void JumpList::RemoveObserver() { | 569 void JumpList::RemoveObserver() { |
| 571 if (profile_ && profile_->GetTabRestoreService()) | 570 if (profile_ && profile_->GetTabRestoreService()) |
| 572 profile_->GetTabRestoreService()->RemoveObserver(this); | 571 profile_->GetTabRestoreService()->RemoveObserver(this); |
| 573 profile_ = NULL; | 572 profile_ = NULL; |
| 574 } | 573 } |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 most_visited_pages_, | 735 most_visited_pages_, |
| 737 recently_closed_pages_); | 736 recently_closed_pages_); |
| 738 MessageLoop* file_loop = g_browser_process->file_thread()->message_loop(); | 737 MessageLoop* file_loop = g_browser_process->file_thread()->message_loop(); |
| 739 if (file_loop) | 738 if (file_loop) |
| 740 file_loop->PostTask(FROM_HERE, icon_task); | 739 file_loop->PostTask(FROM_HERE, icon_task); |
| 741 | 740 |
| 742 // Delete all items in these lists since we don't need these lists any longer. | 741 // Delete all items in these lists since we don't need these lists any longer. |
| 743 most_visited_pages_.clear(); | 742 most_visited_pages_.clear(); |
| 744 recently_closed_pages_.clear(); | 743 recently_closed_pages_.clear(); |
| 745 } | 744 } |
| OLD | NEW |