Chromium Code Reviews| 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 // This file defines functions that integrate Chrome in Windows shell. These | 5 // This file defines functions that integrate Chrome in Windows shell. These |
| 6 // functions can be used by Chrome as well as Chrome installer. All of the | 6 // functions can be used by Chrome as well as Chrome installer. All of the |
| 7 // work is done by the local functions defined in anonymous namespace in | 7 // work is done by the local functions defined in anonymous namespace in |
| 8 // this class. | 8 // this class. |
| 9 | 9 |
| 10 #include "chrome/installer/util/shell_util.h" | 10 #include "chrome/installer/util/shell_util.h" |
| (...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1250 } | 1250 } |
| 1251 return success; | 1251 return success; |
| 1252 } | 1252 } |
| 1253 | 1253 |
| 1254 // Removes folder spsecified by {|location|, |dist|, |level|}. | 1254 // Removes folder spsecified by {|location|, |dist|, |level|}. |
| 1255 bool RemoveShortcutFolder(ShellUtil::ShortcutLocation location, | 1255 bool RemoveShortcutFolder(ShellUtil::ShortcutLocation location, |
| 1256 BrowserDistribution* dist, | 1256 BrowserDistribution* dist, |
| 1257 ShellUtil::ShellChange level) { | 1257 ShellUtil::ShellChange level) { |
| 1258 | 1258 |
| 1259 // Explicitly whitelist locations, since accidental calls can be very harmful. | 1259 // Explicitly whitelist locations, since accidental calls can be very harmful. |
| 1260 if (location != ShellUtil::SHORTCUT_LOCATION_START_MENU && | 1260 if (location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR && |
| 1261 location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR && | |
| 1261 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) { | 1262 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) { |
| 1262 NOTREACHED(); | 1263 NOTREACHED(); |
| 1263 return false; | 1264 return false; |
| 1264 } | 1265 } |
| 1265 | 1266 |
| 1266 base::FilePath shortcut_folder; | 1267 base::FilePath shortcut_folder; |
| 1267 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { | 1268 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { |
| 1268 LOG(WARNING) << "Cannot find path at location " << location; | 1269 LOG(WARNING) << "Cannot find path at location " << location; |
| 1269 return false; | 1270 return false; |
| 1270 } | 1271 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1339 CONFIRM_SHELL_REGISTRATION_IN_HKLM); | 1340 CONFIRM_SHELL_REGISTRATION_IN_HKLM); |
| 1340 } | 1341 } |
| 1341 | 1342 |
| 1342 bool ShellUtil::ShortcutLocationIsSupported( | 1343 bool ShellUtil::ShortcutLocationIsSupported( |
| 1343 ShellUtil::ShortcutLocation location) { | 1344 ShellUtil::ShortcutLocation location) { |
| 1344 switch (location) { | 1345 switch (location) { |
| 1345 case SHORTCUT_LOCATION_DESKTOP: | 1346 case SHORTCUT_LOCATION_DESKTOP: |
| 1346 return true; | 1347 return true; |
| 1347 case SHORTCUT_LOCATION_QUICK_LAUNCH: | 1348 case SHORTCUT_LOCATION_QUICK_LAUNCH: |
| 1348 return true; | 1349 return true; |
| 1349 case SHORTCUT_LOCATION_START_MENU: | 1350 case SHORTCUT_LOCATION_START_MENU_ROOT: |
| 1351 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR: | |
| 1352 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: | |
| 1350 return true; | 1353 return true; |
| 1351 case SHORTCUT_LOCATION_TASKBAR_PINS: | 1354 case SHORTCUT_LOCATION_TASKBAR_PINS: |
| 1352 return base::win::GetVersion() >= base::win::VERSION_WIN7; | 1355 return base::win::GetVersion() >= base::win::VERSION_WIN7; |
| 1353 case SHORTCUT_LOCATION_APP_SHORTCUTS: | 1356 case SHORTCUT_LOCATION_APP_SHORTCUTS: |
| 1354 return base::win::GetVersion() >= base::win::VERSION_WIN8; | 1357 return base::win::GetVersion() >= base::win::VERSION_WIN8; |
| 1355 default: | 1358 default: |
| 1356 NOTREACHED(); | 1359 NOTREACHED(); |
| 1357 return false; | 1360 return false; |
| 1358 } | 1361 } |
| 1359 } | 1362 } |
| 1360 | 1363 |
| 1361 bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location, | 1364 bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location, |
| 1362 BrowserDistribution* dist, | 1365 BrowserDistribution* dist, |
| 1363 ShellChange level, | 1366 ShellChange level, |
| 1364 base::FilePath* path) { | 1367 base::FilePath* path) { |
| 1365 DCHECK(path); | 1368 DCHECK(path); |
| 1366 int dir_key = -1; | 1369 int dir_key = -1; |
| 1367 bool add_folder_for_dist = false; | |
| 1368 switch (location) { | 1370 switch (location) { |
| 1369 case SHORTCUT_LOCATION_DESKTOP: | 1371 case SHORTCUT_LOCATION_DESKTOP: |
| 1370 dir_key = (level == CURRENT_USER) ? base::DIR_USER_DESKTOP : | 1372 dir_key = (level == CURRENT_USER) ? base::DIR_USER_DESKTOP : |
| 1371 base::DIR_COMMON_DESKTOP; | 1373 base::DIR_COMMON_DESKTOP; |
| 1372 break; | 1374 break; |
| 1373 case SHORTCUT_LOCATION_QUICK_LAUNCH: | 1375 case SHORTCUT_LOCATION_QUICK_LAUNCH: |
| 1374 dir_key = (level == CURRENT_USER) ? base::DIR_USER_QUICK_LAUNCH : | 1376 dir_key = (level == CURRENT_USER) ? base::DIR_USER_QUICK_LAUNCH : |
| 1375 base::DIR_DEFAULT_USER_QUICK_LAUNCH; | 1377 base::DIR_DEFAULT_USER_QUICK_LAUNCH; |
| 1376 break; | 1378 break; |
| 1377 case SHORTCUT_LOCATION_START_MENU: | 1379 case SHORTCUT_LOCATION_START_MENU_ROOT: |
| 1380 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR: | |
| 1381 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: | |
| 1378 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : | 1382 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : |
| 1379 base::DIR_COMMON_START_MENU; | 1383 base::DIR_COMMON_START_MENU; |
| 1380 add_folder_for_dist = true; | |
| 1381 break; | 1384 break; |
| 1382 case SHORTCUT_LOCATION_TASKBAR_PINS: | 1385 case SHORTCUT_LOCATION_TASKBAR_PINS: |
| 1383 dir_key = base::DIR_TASKBAR_PINS; | 1386 dir_key = base::DIR_TASKBAR_PINS; |
| 1384 break; | 1387 break; |
| 1385 case SHORTCUT_LOCATION_APP_SHORTCUTS: | 1388 case SHORTCUT_LOCATION_APP_SHORTCUTS: |
| 1386 // TODO(huangs): Move GetAppShortcutsFolder() logic into base_paths_win. | 1389 // TODO(huangs): Move GetAppShortcutsFolder() logic into base_paths_win. |
| 1387 return GetAppShortcutsFolder(dist, level, path); | 1390 return GetAppShortcutsFolder(dist, level, path); |
| 1388 | 1391 |
| 1389 default: | 1392 default: |
| 1390 NOTREACHED(); | 1393 NOTREACHED(); |
| 1391 return false; | 1394 return false; |
| 1392 } | 1395 } |
| 1393 | |
|
gab
2013/05/15 21:26:38
nit: I'd leave this empty line to separate from th
calamity
2013/08/27 07:59:35
Done.
| |
| 1394 if (!PathService::Get(dir_key, path) || path->empty()) { | 1396 if (!PathService::Get(dir_key, path) || path->empty()) { |
| 1395 NOTREACHED() << dir_key; | 1397 NOTREACHED() << dir_key; |
| 1396 return false; | 1398 return false; |
| 1397 } | 1399 } |
| 1398 | 1400 |
| 1399 if (add_folder_for_dist) | 1401 // Append application menu subdirectory. |
| 1400 *path = path->Append(dist->GetAppShortCutName()); | 1402 string16 folder_to_append; |
| 1403 if (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR) { | |
|
Matt Giuca
2013/05/15 05:19:45
Can you do this in the switch instead of having th
gab
2013/05/15 21:26:38
Should be easier with single GetStartMenuSubfolder
calamity
2013/08/27 07:59:35
Done.
| |
| 1404 folder_to_append = dist->GetAppShortCutName(); | |
| 1405 } else if (location == SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR) { | |
| 1406 folder_to_append = dist->GetAppShortcutsSubdirName(); | |
| 1407 } | |
| 1408 if (!folder_to_append.empty()) | |
| 1409 *path = path->Append(folder_to_append); | |
| 1401 | 1410 |
| 1402 return true; | 1411 return true; |
| 1403 } | 1412 } |
| 1404 | 1413 |
| 1405 bool ShellUtil::CreateOrUpdateShortcut( | 1414 bool ShellUtil::CreateOrUpdateShortcut( |
| 1406 ShellUtil::ShortcutLocation location, | 1415 ShellUtil::ShortcutLocation location, |
| 1407 BrowserDistribution* dist, | 1416 BrowserDistribution* dist, |
| 1408 const ShellUtil::ShortcutProperties& properties, | 1417 const ShellUtil::ShortcutProperties& properties, |
| 1409 ShellUtil::ShortcutOperation operation) { | 1418 ShellUtil::ShortcutOperation operation) { |
| 1410 // Explicitly whitelist locations to which this is applicable. | 1419 // Explicitly whitelist locations to which this is applicable. |
| 1411 if (location != SHORTCUT_LOCATION_DESKTOP && | 1420 if (location != SHORTCUT_LOCATION_DESKTOP && |
| 1412 location != SHORTCUT_LOCATION_QUICK_LAUNCH && | 1421 location != SHORTCUT_LOCATION_QUICK_LAUNCH && |
| 1413 location != SHORTCUT_LOCATION_START_MENU) { | 1422 location != SHORTCUT_LOCATION_START_MENU_ROOT && |
| 1423 location != SHORTCUT_LOCATION_START_MENU_CHROME_DIR && | |
| 1424 location != SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR) { | |
| 1414 NOTREACHED(); | 1425 NOTREACHED(); |
| 1415 return false; | 1426 return false; |
| 1416 } | 1427 } |
| 1417 | 1428 |
| 1418 DCHECK(dist); | 1429 DCHECK(dist); |
| 1419 // |pin_to_taskbar| is only acknowledged when first creating the shortcut. | 1430 // |pin_to_taskbar| is only acknowledged when first creating the shortcut. |
| 1420 DCHECK(!properties.pin_to_taskbar || | 1431 DCHECK(!properties.pin_to_taskbar || |
| 1421 operation == SHELL_SHORTCUT_CREATE_ALWAYS || | 1432 operation == SHELL_SHORTCUT_CREATE_ALWAYS || |
| 1422 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); | 1433 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); |
| 1423 | 1434 |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1983 | 1994 |
| 1984 // static | 1995 // static |
| 1985 bool ShellUtil::RemoveShortcuts(ShellUtil::ShortcutLocation location, | 1996 bool ShellUtil::RemoveShortcuts(ShellUtil::ShortcutLocation location, |
| 1986 BrowserDistribution* dist, | 1997 BrowserDistribution* dist, |
| 1987 ShellChange level, | 1998 ShellChange level, |
| 1988 const base::FilePath& target_exe) { | 1999 const base::FilePath& target_exe) { |
| 1989 if (!ShellUtil::ShortcutLocationIsSupported(location)) | 2000 if (!ShellUtil::ShortcutLocationIsSupported(location)) |
| 1990 return true; // Vacuous success. | 2001 return true; // Vacuous success. |
| 1991 | 2002 |
| 1992 switch (location) { | 2003 switch (location) { |
| 1993 case SHORTCUT_LOCATION_START_MENU: // Falls through. | 2004 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR: // Falls through. |
| 2005 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: | |
| 1994 case SHORTCUT_LOCATION_APP_SHORTCUTS: | 2006 case SHORTCUT_LOCATION_APP_SHORTCUTS: |
| 1995 return RemoveShortcutFolder(location, dist, level); | 2007 return RemoveShortcutFolder(location, dist, level); |
| 1996 | 2008 |
| 1997 case SHORTCUT_LOCATION_TASKBAR_PINS: | 2009 case SHORTCUT_LOCATION_TASKBAR_PINS: |
| 1998 return BatchShortcutAction(base::Bind(&ShortcutOpUnpin), location, dist, | 2010 return BatchShortcutAction(base::Bind(&ShortcutOpUnpin), location, dist, |
| 1999 level, target_exe); | 2011 level, target_exe); |
| 2000 | 2012 |
| 2001 default: | 2013 default: |
| 2002 return BatchShortcutAction(base::Bind(&ShortcutOpDelete), location, dist, | 2014 return BatchShortcutAction(base::Bind(&ShortcutOpDelete), location, dist, |
| 2003 level, target_exe); | 2015 level, target_exe); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2080 // are any left...). | 2092 // are any left...). |
| 2081 if (free_bits >= 8 && next_byte_index < size) { | 2093 if (free_bits >= 8 && next_byte_index < size) { |
| 2082 free_bits -= 8; | 2094 free_bits -= 8; |
| 2083 bit_stream += bytes[next_byte_index++] << free_bits; | 2095 bit_stream += bytes[next_byte_index++] << free_bits; |
| 2084 } | 2096 } |
| 2085 } | 2097 } |
| 2086 | 2098 |
| 2087 DCHECK_EQ(ret.length(), encoded_length); | 2099 DCHECK_EQ(ret.length(), encoded_length); |
| 2088 return ret; | 2100 return ret; |
| 2089 } | 2101 } |
| OLD | NEW |