OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/web_applications/web_app.h" | 5 #include "chrome/browser/web_applications/web_app.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <shellapi.h> | 8 #include <shellapi.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 #endif // defined(OS_WIN) | 10 #endif // defined(OS_WIN) |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/callback.h" | 16 #include "base/callback.h" |
17 #include "base/file_util.h" | 17 #include "base/file_util.h" |
18 #include "base/md5.h" | 18 #include "base/md5.h" |
19 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
20 #include "base/path_service.h" | 20 #include "base/path_service.h" |
21 #include "base/thread.h" | 21 #include "base/thread.h" |
22 #include "base/scoped_ptr.h" | 22 #include "base/scoped_ptr.h" |
23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| 24 #include "base/win/windows_version.h" |
24 #include "chrome/browser/browser_thread.h" | 25 #include "chrome/browser/browser_thread.h" |
25 #include "chrome/browser/download/download_util.h" | 26 #include "chrome/browser/download/download_util.h" |
26 #include "chrome/browser/profile.h" | 27 #include "chrome/browser/profile.h" |
27 #include "chrome/browser/tab_contents/tab_contents.h" | 28 #include "chrome/browser/tab_contents/tab_contents.h" |
28 #include "chrome/common/chrome_constants.h" | 29 #include "chrome/common/chrome_constants.h" |
29 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
30 #include "chrome/common/chrome_plugin_util.h" | 31 #include "chrome/common/chrome_plugin_util.h" |
31 #include "chrome/common/notification_registrar.h" | 32 #include "chrome/common/notification_registrar.h" |
32 #include "chrome/common/notification_service.h" | 33 #include "chrome/common/notification_service.h" |
33 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 chrome::DIR_USER_DESKTOP, | 287 chrome::DIR_USER_DESKTOP, |
287 NULL | 288 NULL |
288 }, { | 289 }, { |
289 shortcut_info_.create_in_applications_menu, | 290 shortcut_info_.create_in_applications_menu, |
290 base::DIR_START_MENU, | 291 base::DIR_START_MENU, |
291 NULL | 292 NULL |
292 }, { | 293 }, { |
293 shortcut_info_.create_in_quick_launch_bar, | 294 shortcut_info_.create_in_quick_launch_bar, |
294 // For Win7, create_in_quick_launch_bar means pinning to taskbar. Use | 295 // For Win7, create_in_quick_launch_bar means pinning to taskbar. Use |
295 // base::PATH_START as a flag for this case. | 296 // base::PATH_START as a flag for this case. |
296 (win_util::GetWinVersion() >= win_util::WINVERSION_WIN7) ? | 297 (base::win::GetVersion() >= base::win::VERSION_WIN7) ? |
297 base::PATH_START : base::DIR_APP_DATA, | 298 base::PATH_START : base::DIR_APP_DATA, |
298 (win_util::GetWinVersion() >= win_util::WINVERSION_WIN7) ? | 299 (base::win::GetVersion() >= base::win::VERSION_WIN7) ? |
299 NULL : L"Microsoft\\Internet Explorer\\Quick Launch" | 300 NULL : L"Microsoft\\Internet Explorer\\Quick Launch" |
300 } | 301 } |
301 }; | 302 }; |
302 | 303 |
303 // Populate shortcut_paths. | 304 // Populate shortcut_paths. |
304 for (int i = 0; i < arraysize(locations); ++i) { | 305 for (int i = 0; i < arraysize(locations); ++i) { |
305 if (locations[i].use_this_location) { | 306 if (locations[i].use_this_location) { |
306 FilePath path; | 307 FilePath path; |
307 | 308 |
308 // Skip the Win7 case. | 309 // Skip the Win7 case. |
309 if (locations[i].location_id == base::PATH_START) | 310 if (locations[i].location_id == base::PATH_START) |
310 continue; | 311 continue; |
311 | 312 |
312 if (!PathService::Get(locations[i].location_id, &path)) { | 313 if (!PathService::Get(locations[i].location_id, &path)) { |
313 NOTREACHED(); | 314 NOTREACHED(); |
314 return false; | 315 return false; |
315 } | 316 } |
316 | 317 |
317 if (locations[i].sub_dir != NULL) | 318 if (locations[i].sub_dir != NULL) |
318 path = path.Append(locations[i].sub_dir); | 319 path = path.Append(locations[i].sub_dir); |
319 | 320 |
320 shortcut_paths.push_back(path); | 321 shortcut_paths.push_back(path); |
321 } | 322 } |
322 } | 323 } |
323 | 324 |
324 bool pin_to_taskbar = | 325 bool pin_to_taskbar = |
325 shortcut_info_.create_in_quick_launch_bar && | 326 shortcut_info_.create_in_quick_launch_bar && |
326 (win_util::GetWinVersion() >= win_util::WINVERSION_WIN7); | 327 (base::win::GetVersion() >= base::win::VERSION_WIN7); |
327 | 328 |
328 // For Win7's pinning support, any shortcut could be used. So we only create | 329 // For Win7's pinning support, any shortcut could be used. So we only create |
329 // the shortcut file when there is no shortcut file will be created. That is, | 330 // the shortcut file when there is no shortcut file will be created. That is, |
330 // user only selects "Pin to taskbar". | 331 // user only selects "Pin to taskbar". |
331 if (pin_to_taskbar && shortcut_paths.empty()) { | 332 if (pin_to_taskbar && shortcut_paths.empty()) { |
332 // Creates the shortcut in web_app_path_ in this case. | 333 // Creates the shortcut in web_app_path_ in this case. |
333 shortcut_paths.push_back(web_app_path_); | 334 shortcut_paths.push_back(web_app_path_); |
334 } | 335 } |
335 | 336 |
336 if (shortcut_paths.empty()) { | 337 if (shortcut_paths.empty()) { |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 chrome::DIR_USER_DESKTOP, | 571 chrome::DIR_USER_DESKTOP, |
571 NULL | 572 NULL |
572 }, { | 573 }, { |
573 shortcut_info_.create_in_applications_menu, | 574 shortcut_info_.create_in_applications_menu, |
574 base::DIR_START_MENU, | 575 base::DIR_START_MENU, |
575 NULL | 576 NULL |
576 }, { | 577 }, { |
577 shortcut_info_.create_in_quick_launch_bar, | 578 shortcut_info_.create_in_quick_launch_bar, |
578 // For Win7, create_in_quick_launch_bar means pinning to taskbar. | 579 // For Win7, create_in_quick_launch_bar means pinning to taskbar. |
579 base::DIR_APP_DATA, | 580 base::DIR_APP_DATA, |
580 (win_util::GetWinVersion() >= win_util::WINVERSION_WIN7) ? | 581 (base::win::GetVersion() >= base::win::VERSION_WIN7) ? |
581 L"Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar" : | 582 L"Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar" : |
582 L"Microsoft\\Internet Explorer\\Quick Launch" | 583 L"Microsoft\\Internet Explorer\\Quick Launch" |
583 } | 584 } |
584 }; | 585 }; |
585 | 586 |
586 for (int i = 0; i < arraysize(locations); ++i) { | 587 for (int i = 0; i < arraysize(locations); ++i) { |
587 locations[i].use_this_location = false; | 588 locations[i].use_this_location = false; |
588 | 589 |
589 FilePath path; | 590 FilePath path; |
590 if (!PathService::Get(locations[i].location_id, &path)) { | 591 if (!PathService::Get(locations[i].location_id, &path)) { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 | 758 |
758 void UpdateShortcutForTabContents(TabContents* tab_contents) { | 759 void UpdateShortcutForTabContents(TabContents* tab_contents) { |
759 #if defined(OS_WIN) | 760 #if defined(OS_WIN) |
760 // UpdateShortcutWorker will delete itself when it's done. | 761 // UpdateShortcutWorker will delete itself when it's done. |
761 UpdateShortcutWorker* worker = new UpdateShortcutWorker(tab_contents); | 762 UpdateShortcutWorker* worker = new UpdateShortcutWorker(tab_contents); |
762 worker->Run(); | 763 worker->Run(); |
763 #endif // defined(OS_WIN) | 764 #endif // defined(OS_WIN) |
764 } | 765 } |
765 | 766 |
766 }; // namespace web_app | 767 }; // namespace web_app |
OLD | NEW |