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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 // class. | 184 // class. |
| 185 class RegistryEntry { | 185 class RegistryEntry { |
| 186 public: | 186 public: |
| 187 // A bit-field enum of places to look for this key in the Windows registry. | 187 // A bit-field enum of places to look for this key in the Windows registry. |
| 188 enum LookForIn { | 188 enum LookForIn { |
| 189 LOOK_IN_HKCU = 1 << 0, | 189 LOOK_IN_HKCU = 1 << 0, |
| 190 LOOK_IN_HKLM = 1 << 1, | 190 LOOK_IN_HKLM = 1 << 1, |
| 191 LOOK_IN_HKCU_THEN_HKLM = LOOK_IN_HKCU | LOOK_IN_HKLM, | 191 LOOK_IN_HKCU_THEN_HKLM = LOOK_IN_HKCU | LOOK_IN_HKLM, |
| 192 }; | 192 }; |
| 193 | 193 |
| 194 // Details about a Windows application, to be entered into the registry for | |
| 195 // the purpose of file associations. | |
| 196 struct ApplicationInfo { | |
| 197 ApplicationInfo() | |
| 198 : set_delegate_execute(false), | |
| 199 file_type_icon_index(0), | |
| 200 application_icon_index(0) {} | |
| 201 | |
| 202 // The unique internal name Windows will use for file associations with this | |
| 203 // application. | |
| 204 base::string16 prog_id; | |
| 205 // The friendly name, and the path of the icon that will be used for files | |
| 206 // of these types when associated with this application by default. (They | |
| 207 // are NOT the name/icon that will represent the application under the Open | |
| 208 // With menu.) | |
| 209 base::string16 file_type_name; | |
| 210 // TODO(mgiuca): |file_type_icon_path| should be a base::FilePath. | |
| 211 base::string16 file_type_icon_path; | |
| 212 int file_type_icon_index; | |
| 213 // The command to execute when opening a file via this association. It | |
| 214 // should contain "%1" to pass the filename as an argument. | |
| 215 // TODO(mgiuca): |command_line| should be a base::CommandLine. | |
| 216 base::string16 command_line; | |
| 217 | |
| 218 // User-visible details about this application. | |
| 219 base::string16 application_name; | |
| 220 // TODO(mgiuca): |application_icon_path| should be a base::FilePath. | |
| 221 base::string16 application_icon_path; | |
| 222 int application_icon_index; | |
| 223 base::string16 application_description; | |
| 224 base::string16 publisher_name; | |
| 225 | |
| 226 // Whether the application will have a DelegateExecute key. This should only | |
| 227 // be used by Windows 8 Metro web browsers (i.e. Chrome itself). All other | |
| 228 // fields in this section are ignored if this is false. | |
| 229 bool set_delegate_execute; | |
| 230 // The unique internal name used by Metro for this application. Distinct | |
| 231 // from |prog_id|. | |
| 232 base::string16 app_id; | |
| 233 // A GUID for this application. | |
| 234 base::string16 delegate_guid; | |
| 235 // The command to execute when opening this application via the Metro UI. | |
| 236 base::string16 delegate_command; | |
| 237 }; | |
| 238 | |
| 194 // Returns the Windows browser client registration key for Chrome. For | 239 // Returns the Windows browser client registration key for Chrome. For |
| 195 // example: "Software\Clients\StartMenuInternet\Chromium[.user]". Strictly | 240 // example: "Software\Clients\StartMenuInternet\Chromium[.user]". Strictly |
| 196 // speaking, we should use the name of the executable (e.g., "chrome.exe"), | 241 // speaking, we should use the name of the executable (e.g., "chrome.exe"), |
| 197 // but that ship has sailed. The cost of switching now is re-prompting users | 242 // but that ship has sailed. The cost of switching now is re-prompting users |
| 198 // to make Chrome their default browser, which isn't polite. |suffix| is the | 243 // to make Chrome their default browser, which isn't polite. |suffix| is the |
| 199 // user-specific registration suffix; see GetUserSpecificDefaultBrowserSuffix | 244 // user-specific registration suffix; see GetUserSpecificDefaultBrowserSuffix |
| 200 // in shell_util.h for details. | 245 // in shell_util.h for details. |
| 201 static base::string16 GetBrowserClientKey(BrowserDistribution* dist, | 246 static base::string16 GetBrowserClientKey(BrowserDistribution* dist, |
| 202 const base::string16& suffix) { | 247 const base::string16& suffix) { |
| 203 DCHECK(suffix.empty() || suffix[0] == L'.'); | 248 DCHECK(suffix.empty() || suffix[0] == L'.'); |
| 204 return base::string16(ShellUtil::kRegStartMenuInternet) | 249 return base::string16(ShellUtil::kRegStartMenuInternet) |
| 205 .append(1, L'\\') | 250 .append(1, L'\\') |
| 206 .append(dist->GetBaseAppName()) | 251 .append(dist->GetBaseAppName()) |
| 207 .append(suffix); | 252 .append(suffix); |
| 208 } | 253 } |
| 209 | 254 |
| 210 // Returns the Windows Default Programs capabilities key for Chrome. For | 255 // Returns the Windows Default Programs capabilities key for Chrome. For |
| 211 // example: | 256 // example: |
| 212 // "Software\Clients\StartMenuInternet\Chromium[.user]\Capabilities". | 257 // "Software\Clients\StartMenuInternet\Chromium[.user]\Capabilities". |
| 213 static base::string16 GetCapabilitiesKey(BrowserDistribution* dist, | 258 static base::string16 GetCapabilitiesKey(BrowserDistribution* dist, |
| 214 const base::string16& suffix) { | 259 const base::string16& suffix) { |
| 215 return GetBrowserClientKey(dist, suffix).append(L"\\Capabilities"); | 260 return GetBrowserClientKey(dist, suffix).append(L"\\Capabilities"); |
| 216 } | 261 } |
| 217 | 262 |
| 218 // This method returns a list of all the registry entries that | 263 // This method returns a list of all the registry entries that |
| 219 // are needed to register this installation's ProgId and AppId. | 264 // are needed to register this installation's ProgId and AppId. |
| 220 // These entries need to be registered in HKLM prior to Win8. | 265 // These entries need to be registered in HKLM prior to Win8. |
| 221 static void GetProgIdEntries(BrowserDistribution* dist, | 266 static void GetChromeProgIdEntries(BrowserDistribution* dist, |
| 222 const base::string16& chrome_exe, | 267 const base::string16& chrome_exe, |
| 223 const base::string16& suffix, | 268 const base::string16& suffix, |
| 224 ScopedVector<RegistryEntry>* entries) { | 269 ScopedVector<RegistryEntry>* entries) { |
| 225 base::string16 icon_path( | 270 ApplicationInfo app_info; |
| 226 ShellUtil::FormatIconLocation( | 271 app_info.prog_id = GetBrowserProgId(suffix); |
| 227 chrome_exe, | 272 app_info.file_type_name = dist->GetBrowserProgIdDesc(); |
| 228 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME))); | 273 app_info.file_type_icon_path = chrome_exe; |
| 229 base::string16 open_cmd(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); | 274 app_info.file_type_icon_index = |
| 230 base::string16 delegate_command( | 275 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME); |
| 231 ShellUtil::GetChromeDelegateCommand(chrome_exe)); | 276 app_info.command_line = ShellUtil::GetChromeShellOpenCmd(chrome_exe); |
| 232 // For user-level installs: entries for the app id and DelegateExecute verb | |
| 233 // handler will be in HKCU; thus we do not need a suffix on those entries. | |
| 234 base::string16 app_id( | |
| 235 ShellUtil::GetBrowserModelId( | |
| 236 dist, InstallUtil::IsPerUserInstall(chrome_exe.c_str()))); | |
| 237 base::string16 delegate_guid; | |
| 238 bool set_delegate_execute = | |
| 239 IsChromeMetroSupported() && | |
| 240 dist->GetCommandExecuteImplClsid(&delegate_guid); | |
| 241 | 277 |
| 242 // DelegateExecute ProgId. Needed for Chrome Metro in Windows 8. | 278 // DelegateExecute ProgId. Needed for Chrome Metro in Windows 8. |
| 243 if (set_delegate_execute) { | 279 app_info.set_delegate_execute = |
| 280 IsChromeMetroSupported() && | |
| 281 dist->GetCommandExecuteImplClsid(&app_info.delegate_guid); | |
| 282 if (app_info.set_delegate_execute) { | |
| 283 app_info.delegate_command = | |
| 284 ShellUtil::GetChromeDelegateCommand(chrome_exe); | |
| 285 // For user-level installs: entries for the app id and DelegateExecute | |
| 286 // verb handler will be in HKCU; thus we do not need a suffix on those | |
| 287 // entries. | |
| 288 app_info.app_id = ShellUtil::GetBrowserModelId( | |
| 289 dist, InstallUtil::IsPerUserInstall(chrome_exe.c_str())); | |
| 290 } | |
| 291 | |
| 292 // The Chrome app icon path is the same as its file type path. | |
| 293 app_info.application_name = dist->GetDisplayName(); | |
| 294 app_info.application_icon_path = app_info.file_type_icon_path; | |
| 295 app_info.application_icon_index = app_info.file_type_icon_index; | |
| 296 app_info.application_description = dist->GetAppDescription(); | |
| 297 app_info.publisher_name = dist->GetPublisherName(); | |
| 298 | |
| 299 GetProgIdEntries(app_info, entries); | |
| 300 } | |
| 301 | |
| 302 // Gets the registry entries to register an application in the Windows | |
| 303 // registry. |app_info| provides all of the information needed. | |
| 304 static void GetProgIdEntries(const ApplicationInfo& app_info, | |
| 305 ScopedVector<RegistryEntry>* entries) { | |
| 306 if (app_info.set_delegate_execute) { | |
| 244 base::string16 model_id_shell(ShellUtil::kRegClasses); | 307 base::string16 model_id_shell(ShellUtil::kRegClasses); |
| 245 model_id_shell.push_back(base::FilePath::kSeparators[0]); | 308 model_id_shell.push_back(base::FilePath::kSeparators[0]); |
| 246 model_id_shell.append(app_id); | 309 model_id_shell.append(app_info.app_id); |
| 247 model_id_shell.append(ShellUtil::kRegExePath); | 310 model_id_shell.append(ShellUtil::kRegExePath); |
| 248 model_id_shell.append(ShellUtil::kRegShellPath); | 311 model_id_shell.append(ShellUtil::kRegShellPath); |
| 249 | 312 |
| 250 // <root hkey>\Software\Classes\<app_id>\.exe\shell @=open | 313 // <root hkey>\Software\Classes\<app_id>\.exe\shell @=open |
| 251 entries->push_back(new RegistryEntry(model_id_shell, | 314 entries->push_back(new RegistryEntry(model_id_shell, |
| 252 ShellUtil::kRegVerbOpen)); | 315 ShellUtil::kRegVerbOpen)); |
| 253 | 316 |
| 254 // Each of Chrome's shortcuts has an appid; which, as of Windows 8, is | 317 // Each shortcut has an appid; which, as of Windows 8, is registered to |
| 255 // registered to handle some verbs. This registration has the side-effect | 318 // handle some verbs. This registration has the side-effect that these |
| 256 // that these verbs now show up in the shortcut's context menu. We | 319 // verbs now show up in the shortcut's context menu. We mitigate this |
| 257 // mitigate this side-effect by making the context menu entries | 320 // side-effect by making the context menu entries user readable/localized |
| 258 // user readable/localized strings. See relevant MSDN article: | 321 // strings. See relevant MSDN article: |
| 259 // http://msdn.microsoft.com/en-US/library/windows/desktop/cc144171.aspx | 322 // http://msdn.microsoft.com/en-US/library/windows/desktop/cc144171.aspx |
| 260 const struct { | 323 const struct { |
| 261 const wchar_t* verb; | 324 const wchar_t* verb; |
| 262 int name_id; | 325 int name_id; |
| 263 } verbs[] = { | 326 } verbs[] = { |
| 264 { ShellUtil::kRegVerbOpen, -1 }, | 327 { ShellUtil::kRegVerbOpen, -1 }, |
| 265 { ShellUtil::kRegVerbOpenNewWindow, IDS_SHORTCUT_NEW_WINDOW_BASE }, | 328 { ShellUtil::kRegVerbOpenNewWindow, IDS_SHORTCUT_NEW_WINDOW_BASE }, |
| 266 }; | 329 }; |
| 267 for (size_t i = 0; i < arraysize(verbs); ++i) { | 330 for (size_t i = 0; i < arraysize(verbs); ++i) { |
| 268 base::string16 sub_path(model_id_shell); | 331 base::string16 sub_path(model_id_shell); |
| 269 sub_path.push_back(base::FilePath::kSeparators[0]); | 332 sub_path.push_back(base::FilePath::kSeparators[0]); |
| 270 sub_path.append(verbs[i].verb); | 333 sub_path.append(verbs[i].verb); |
| 271 | 334 |
| 272 // <root hkey>\Software\Classes\<app_id>\.exe\shell\<verb> | 335 // <root hkey>\Software\Classes\<app_id>\.exe\shell\<verb> |
| 273 if (verbs[i].name_id != -1) { | 336 if (verbs[i].name_id != -1) { |
| 274 // TODO(grt): http://crbug.com/75152 Write a reference to a localized | 337 // TODO(grt): http://crbug.com/75152 Write a reference to a localized |
| 275 // resource. | 338 // resource. |
| 276 base::string16 verb_name( | 339 base::string16 verb_name( |
| 277 installer::GetLocalizedString(verbs[i].name_id)); | 340 installer::GetLocalizedString(verbs[i].name_id)); |
| 278 entries->push_back(new RegistryEntry(sub_path, verb_name.c_str())); | 341 entries->push_back(new RegistryEntry(sub_path, verb_name.c_str())); |
| 279 } | 342 } |
| 280 entries->push_back(new RegistryEntry( | 343 entries->push_back(new RegistryEntry( |
| 281 sub_path, L"CommandId", L"Browser.Launch")); | 344 sub_path, L"CommandId", L"Browser.Launch")); |
| 282 | 345 |
| 283 sub_path.push_back(base::FilePath::kSeparators[0]); | 346 sub_path.push_back(base::FilePath::kSeparators[0]); |
| 284 sub_path.append(ShellUtil::kRegCommand); | 347 sub_path.append(ShellUtil::kRegCommand); |
| 285 | 348 |
| 286 // <root hkey>\Software\Classes\<app_id>\.exe\shell\<verb>\command | 349 // <root hkey>\Software\Classes\<app_id>\.exe\shell\<verb>\command |
| 287 entries->push_back(new RegistryEntry(sub_path, delegate_command)); | 350 entries->push_back( |
| 351 new RegistryEntry(sub_path, app_info.delegate_command)); | |
| 288 entries->push_back(new RegistryEntry( | 352 entries->push_back(new RegistryEntry( |
| 289 sub_path, ShellUtil::kRegDelegateExecute, delegate_guid)); | 353 sub_path, ShellUtil::kRegDelegateExecute, app_info.delegate_guid)); |
| 290 } | 354 } |
| 291 } | 355 } |
| 292 | 356 |
| 293 // File association ProgId | 357 // File association ProgId |
| 294 base::string16 chrome_html_prog_id(ShellUtil::kRegClasses); | 358 base::string16 prog_id_path(ShellUtil::kRegClasses); |
| 295 chrome_html_prog_id.push_back(base::FilePath::kSeparators[0]); | 359 prog_id_path.push_back(base::FilePath::kSeparators[0]); |
| 296 chrome_html_prog_id.append(GetBrowserProgId(suffix)); | 360 prog_id_path.append(app_info.prog_id); |
| 361 entries->push_back( | |
| 362 new RegistryEntry(prog_id_path, app_info.file_type_name)); | |
| 297 entries->push_back(new RegistryEntry( | 363 entries->push_back(new RegistryEntry( |
| 298 chrome_html_prog_id, dist->GetBrowserProgIdDesc())); | 364 prog_id_path + ShellUtil::kRegDefaultIcon, |
| 365 ShellUtil::FormatIconLocation(app_info.file_type_icon_path, | |
| 366 app_info.file_type_icon_index))); | |
| 299 entries->push_back(new RegistryEntry( | 367 entries->push_back(new RegistryEntry( |
| 300 chrome_html_prog_id + ShellUtil::kRegDefaultIcon, icon_path)); | 368 prog_id_path + ShellUtil::kRegShellOpen, app_info.command_line)); |
| 301 entries->push_back(new RegistryEntry( | 369 if (app_info.set_delegate_execute) { |
| 302 chrome_html_prog_id + ShellUtil::kRegShellOpen, open_cmd)); | 370 entries->push_back( |
| 303 if (set_delegate_execute) { | 371 new RegistryEntry(prog_id_path + ShellUtil::kRegShellOpen, |
| 304 entries->push_back(new RegistryEntry( | 372 ShellUtil::kRegDelegateExecute, |
| 305 chrome_html_prog_id + ShellUtil::kRegShellOpen, | 373 app_info.delegate_guid)); |
| 306 ShellUtil::kRegDelegateExecute, delegate_guid)); | |
| 307 } | 374 } |
| 308 | 375 |
| 309 // The following entries are required as of Windows 8, but do not | 376 // The following entries are required as of Windows 8, but do not |
| 310 // depend on the DelegateExecute verb handler being set. | 377 // depend on the DelegateExecute verb handler being set. |
| 311 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | 378 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
| 379 if (app_info.set_delegate_execute) { | |
|
Matt Giuca
2014/09/11 08:23:54
Note: I've changed the behaviour here -- I don't t
Matt Giuca
2014/09/12 00:09:46
Actually, I think this was a bad idea -- you proba
gab
2014/09/12 13:32:36
Right, I forget the exact details here, but it fee
| |
| 380 entries->push_back(new RegistryEntry( | |
| 381 prog_id_path, ShellUtil::kRegAppUserModelId, app_info.app_id)); | |
| 382 } | |
| 383 | |
| 384 // Add \Software\Classes\<prog_id>\Application entries | |
| 385 base::string16 application_path(prog_id_path + | |
| 386 ShellUtil::kRegApplication); | |
| 387 if (app_info.set_delegate_execute) { | |
| 388 entries->push_back(new RegistryEntry( | |
| 389 application_path, ShellUtil::kRegAppUserModelId, app_info.app_id)); | |
| 390 } | |
| 312 entries->push_back(new RegistryEntry( | 391 entries->push_back(new RegistryEntry( |
| 313 chrome_html_prog_id, ShellUtil::kRegAppUserModelId, app_id)); | 392 application_path, |
| 314 | 393 ShellUtil::kRegApplicationIcon, |
| 315 // Add \Software\Classes\ChromeHTML\Application entries | 394 ShellUtil::FormatIconLocation(app_info.application_icon_path, |
| 316 base::string16 chrome_application(chrome_html_prog_id + | 395 app_info.application_icon_index))); |
| 317 ShellUtil::kRegApplication); | |
| 318 entries->push_back(new RegistryEntry( | |
| 319 chrome_application, ShellUtil::kRegAppUserModelId, app_id)); | |
| 320 entries->push_back(new RegistryEntry( | |
| 321 chrome_application, ShellUtil::kRegApplicationIcon, icon_path)); | |
| 322 // TODO(grt): http://crbug.com/75152 Write a reference to a localized | 396 // TODO(grt): http://crbug.com/75152 Write a reference to a localized |
| 323 // resource for name, description, and company. | 397 // resource for name, description, and company. |
| 324 entries->push_back(new RegistryEntry( | 398 entries->push_back(new RegistryEntry(application_path, |
| 325 chrome_application, ShellUtil::kRegApplicationName, | 399 ShellUtil::kRegApplicationName, |
| 326 dist->GetDisplayName())); | 400 app_info.application_name)); |
| 327 entries->push_back(new RegistryEntry( | 401 entries->push_back( |
| 328 chrome_application, ShellUtil::kRegApplicationDescription, | 402 new RegistryEntry(application_path, |
| 329 dist->GetAppDescription())); | 403 ShellUtil::kRegApplicationDescription, |
| 330 entries->push_back(new RegistryEntry( | 404 app_info.application_description)); |
| 331 chrome_application, ShellUtil::kRegApplicationCompany, | 405 entries->push_back(new RegistryEntry(application_path, |
| 332 dist->GetPublisherName())); | 406 ShellUtil::kRegApplicationCompany, |
| 407 app_info.publisher_name)); | |
| 333 } | 408 } |
| 334 } | 409 } |
| 335 | 410 |
| 336 // This method returns a list of the registry entries needed to declare a | 411 // This method returns a list of the registry entries needed to declare a |
| 337 // capability of handling a protocol on Windows. | 412 // capability of handling a protocol on Windows. |
| 338 static void GetProtocolCapabilityEntries( | 413 static void GetProtocolCapabilityEntries( |
| 339 BrowserDistribution* dist, | 414 BrowserDistribution* dist, |
| 340 const base::string16& suffix, | 415 const base::string16& suffix, |
| 341 const base::string16& protocol, | 416 const base::string16& protocol, |
| 342 ScopedVector<RegistryEntry>* entries) { | 417 ScopedVector<RegistryEntry>* entries) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 } | 501 } |
| 427 | 502 |
| 428 // This method returns a list of the registry entries required for this | 503 // This method returns a list of the registry entries required for this |
| 429 // installation to be registered in the Windows shell. | 504 // installation to be registered in the Windows shell. |
| 430 // In particular: | 505 // In particular: |
| 431 // - App Paths | 506 // - App Paths |
| 432 // http://msdn.microsoft.com/en-us/library/windows/desktop/ee872121 | 507 // http://msdn.microsoft.com/en-us/library/windows/desktop/ee872121 |
| 433 // - File Associations | 508 // - File Associations |
| 434 // http://msdn.microsoft.com/en-us/library/bb166549 | 509 // http://msdn.microsoft.com/en-us/library/bb166549 |
| 435 // These entries need to be registered in HKLM prior to Win8. | 510 // These entries need to be registered in HKLM prior to Win8. |
| 436 static void GetAppRegistrationEntries(const base::string16& chrome_exe, | 511 static void GetChromeAppRegistrationEntries( |
| 437 const base::string16& suffix, | 512 const base::string16& chrome_exe, |
| 438 ScopedVector<RegistryEntry>* entries) { | 513 const base::string16& suffix, |
| 514 ScopedVector<RegistryEntry>* entries) { | |
| 439 const base::FilePath chrome_path(chrome_exe); | 515 const base::FilePath chrome_path(chrome_exe); |
| 440 base::string16 app_path_key(ShellUtil::kAppPathsRegistryKey); | 516 base::string16 app_path_key(ShellUtil::kAppPathsRegistryKey); |
| 441 app_path_key.push_back(base::FilePath::kSeparators[0]); | 517 app_path_key.push_back(base::FilePath::kSeparators[0]); |
| 442 app_path_key.append(chrome_path.BaseName().value()); | 518 app_path_key.append(chrome_path.BaseName().value()); |
| 443 entries->push_back(new RegistryEntry(app_path_key, chrome_exe)); | 519 entries->push_back(new RegistryEntry(app_path_key, chrome_exe)); |
| 444 entries->push_back(new RegistryEntry(app_path_key, | 520 entries->push_back(new RegistryEntry(app_path_key, |
| 445 ShellUtil::kAppPathsRegistryPathName, chrome_path.DirName().value())); | 521 ShellUtil::kAppPathsRegistryPathName, chrome_path.DirName().value())); |
| 446 | 522 |
| 447 const base::string16 html_prog_id(GetBrowserProgId(suffix)); | 523 const base::string16 html_prog_id(GetBrowserProgId(suffix)); |
| 448 for (int i = 0; ShellUtil::kPotentialFileAssociations[i] != NULL; i++) { | 524 for (int i = 0; ShellUtil::kPotentialFileAssociations[i] != NULL; i++) { |
| 449 base::string16 key(ShellUtil::kRegClasses); | 525 GetAppExtRegistrationEntries( |
| 450 key.push_back(base::FilePath::kSeparators[0]); | 526 html_prog_id, ShellUtil::kPotentialFileAssociations[i], entries); |
| 451 key.append(ShellUtil::kPotentialFileAssociations[i]); | |
| 452 key.push_back(base::FilePath::kSeparators[0]); | |
| 453 key.append(ShellUtil::kRegOpenWithProgids); | |
| 454 entries->push_back( | |
| 455 new RegistryEntry(key, html_prog_id, base::string16())); | |
| 456 } | 527 } |
| 457 } | 528 } |
| 458 | 529 |
| 530 // Gets the registry entries to register an application as a handler for a | |
| 531 // particular file extension. |prog_id| is the unique internal name Windows | |
| 532 // uses for the application. |ext| is the file extension, which must begin | |
| 533 // with a '.'. | |
| 534 static void GetAppExtRegistrationEntries( | |
| 535 const base::string16& prog_id, | |
| 536 const base::string16& ext, | |
| 537 ScopedVector<RegistryEntry>* entries) { | |
| 538 // In HKEY_CLASSES_ROOT\EXT\OpenWithProgids, create an empty value with this | |
| 539 // class's name. | |
| 540 base::string16 key_name(ShellUtil::kRegClasses); | |
| 541 key_name.push_back(base::FilePath::kSeparators[0]); | |
| 542 key_name.append(ext); | |
| 543 key_name.push_back(base::FilePath::kSeparators[0]); | |
| 544 key_name.append(ShellUtil::kRegOpenWithProgids); | |
| 545 entries->push_back(new RegistryEntry(key_name, prog_id, base::string16())); | |
| 546 } | |
| 547 | |
| 548 // Gets the registry entries to register an application as the default handler | |
| 549 // for a particular file extension. |prog_id| is the unique internal name | |
| 550 // Windows uses for the application. |ext| is the file extension, which must | |
| 551 // begin with a '.'. If |overwrite_existing|, always sets the default handler; | |
| 552 // otherwise only sets if there is no existing default. | |
| 553 static void GetAppDefaultRegistrationEntries( | |
| 554 const base::string16& prog_id, | |
| 555 const base::string16& ext, | |
| 556 bool overwrite_existing, | |
| 557 ScopedVector<RegistryEntry>* entries) { | |
| 558 // Set the default value of HKEY_CLASSES_ROOT\EXT to this class's name. | |
| 559 base::string16 key_name(ShellUtil::kRegClasses); | |
| 560 key_name.push_back(base::FilePath::kSeparators[0]); | |
| 561 key_name.append(ext); | |
| 562 scoped_ptr<RegistryEntry> default_association( | |
| 563 new RegistryEntry(key_name, prog_id)); | |
| 564 if (overwrite_existing || | |
| 565 !default_association->KeyExistsInRegistry(RegistryEntry::LOOK_IN_HKCU)) | |
| 566 entries->push_back(default_association.release()); | |
| 567 } | |
| 568 | |
| 459 // This method returns a list of all the user level registry entries that | 569 // This method returns a list of all the user level registry entries that |
| 460 // are needed to make Chromium the default handler for a protocol on XP. | 570 // are needed to make Chromium the default handler for a protocol on XP. |
| 461 static void GetXPStyleUserProtocolEntries( | 571 static void GetXPStyleUserProtocolEntries( |
| 462 const base::string16& protocol, | 572 const base::string16& protocol, |
| 463 const base::string16& chrome_icon, | 573 const base::string16& chrome_icon, |
| 464 const base::string16& chrome_open, | 574 const base::string16& chrome_open, |
| 465 ScopedVector<RegistryEntry>* entries) { | 575 ScopedVector<RegistryEntry>* entries) { |
| 466 // Protocols associations. | 576 // Protocols associations. |
| 467 base::string16 url_key(ShellUtil::kRegClasses); | 577 base::string16 url_key(ShellUtil::kRegClasses); |
| 468 url_key.push_back(base::FilePath::kSeparators[0]); | 578 url_key.push_back(base::FilePath::kSeparators[0]); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 497 // we register them anyways as some legacy apps are hardcoded to lookup those | 607 // we register them anyways as some legacy apps are hardcoded to lookup those |
| 498 // values. | 608 // values. |
| 499 static void GetXPStyleDefaultBrowserUserEntries( | 609 static void GetXPStyleDefaultBrowserUserEntries( |
| 500 BrowserDistribution* dist, | 610 BrowserDistribution* dist, |
| 501 const base::string16& chrome_exe, | 611 const base::string16& chrome_exe, |
| 502 const base::string16& suffix, | 612 const base::string16& suffix, |
| 503 ScopedVector<RegistryEntry>* entries) { | 613 ScopedVector<RegistryEntry>* entries) { |
| 504 // File extension associations. | 614 // File extension associations. |
| 505 base::string16 html_prog_id(GetBrowserProgId(suffix)); | 615 base::string16 html_prog_id(GetBrowserProgId(suffix)); |
| 506 for (int i = 0; ShellUtil::kDefaultFileAssociations[i] != NULL; i++) { | 616 for (int i = 0; ShellUtil::kDefaultFileAssociations[i] != NULL; i++) { |
| 507 base::string16 ext_key(ShellUtil::kRegClasses); | 617 GetAppDefaultRegistrationEntries( |
| 508 ext_key.push_back(base::FilePath::kSeparators[0]); | 618 html_prog_id, ShellUtil::kDefaultFileAssociations[i], true, entries); |
| 509 ext_key.append(ShellUtil::kDefaultFileAssociations[i]); | |
| 510 entries->push_back(new RegistryEntry(ext_key, html_prog_id)); | |
| 511 } | 619 } |
| 512 | 620 |
| 513 // Protocols associations. | 621 // Protocols associations. |
| 514 base::string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); | 622 base::string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); |
| 515 base::string16 chrome_icon = | 623 base::string16 chrome_icon = |
| 516 ShellUtil::FormatIconLocation( | 624 ShellUtil::FormatIconLocation( |
| 517 chrome_exe, | 625 chrome_exe, |
| 518 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME)); | 626 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME)); |
| 519 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { | 627 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { |
| 520 GetXPStyleUserProtocolEntries(ShellUtil::kBrowserProtocolAssociations[i], | 628 GetXPStyleUserProtocolEntries(ShellUtil::kBrowserProtocolAssociations[i], |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 DCHECK(look_for_in); | 664 DCHECK(look_for_in); |
| 557 | 665 |
| 558 RegistryStatus status = DOES_NOT_EXIST; | 666 RegistryStatus status = DOES_NOT_EXIST; |
| 559 if (look_for_in & LOOK_IN_HKCU) | 667 if (look_for_in & LOOK_IN_HKCU) |
| 560 status = StatusInRegistryUnderRoot(HKEY_CURRENT_USER); | 668 status = StatusInRegistryUnderRoot(HKEY_CURRENT_USER); |
| 561 if (status == DOES_NOT_EXIST && (look_for_in & LOOK_IN_HKLM)) | 669 if (status == DOES_NOT_EXIST && (look_for_in & LOOK_IN_HKLM)) |
| 562 status = StatusInRegistryUnderRoot(HKEY_LOCAL_MACHINE); | 670 status = StatusInRegistryUnderRoot(HKEY_LOCAL_MACHINE); |
| 563 return status == SAME_VALUE; | 671 return status == SAME_VALUE; |
| 564 } | 672 } |
| 565 | 673 |
| 674 // Checks if the current registry entry exists in \|key_path_|\|name_|, | |
| 675 // regardless of value. Same lookup rules as ExistsInRegistry. | |
| 676 // Unlike ExistsInRegistry, this returns true if some other value is present | |
| 677 // with the same key. | |
| 678 bool KeyExistsInRegistry(uint32 look_for_in) const { | |
| 679 DCHECK(look_for_in); | |
| 680 | |
| 681 RegistryStatus status = DOES_NOT_EXIST; | |
| 682 if (look_for_in & LOOK_IN_HKCU) | |
| 683 status = StatusInRegistryUnderRoot(HKEY_CURRENT_USER); | |
| 684 if (status == DOES_NOT_EXIST && (look_for_in & LOOK_IN_HKLM)) | |
| 685 status = StatusInRegistryUnderRoot(HKEY_LOCAL_MACHINE); | |
| 686 return status != DOES_NOT_EXIST; | |
| 687 } | |
| 688 | |
| 566 private: | 689 private: |
| 567 // States this RegistryKey can be in compared to the registry. | 690 // States this RegistryKey can be in compared to the registry. |
| 568 enum RegistryStatus { | 691 enum RegistryStatus { |
| 569 // |name_| does not exist in the registry | 692 // |name_| does not exist in the registry |
| 570 DOES_NOT_EXIST, | 693 DOES_NOT_EXIST, |
| 571 // |name_| exists, but its value != |value_| | 694 // |name_| exists, but its value != |value_| |
| 572 DIFFERENT_VALUE, | 695 DIFFERENT_VALUE, |
| 573 // |name_| exists and its value is |value_| | 696 // |name_| exists and its value is |value_| |
| 574 SAME_VALUE, | 697 SAME_VALUE, |
| 575 }; | 698 }; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 669 // under a single registry root. Not doing so caused http://crbug.com/144910 for | 792 // under a single registry root. Not doing so caused http://crbug.com/144910 for |
| 670 // users who first-installed Chrome in that revision range (those users are | 793 // users who first-installed Chrome in that revision range (those users are |
| 671 // still impacted by http://crbug.com/144910). This method will keep returning | 794 // still impacted by http://crbug.com/144910). This method will keep returning |
| 672 // true for affected users (i.e. who have all the registrations, but over both | 795 // true for affected users (i.e. who have all the registrations, but over both |
| 673 // registry roots). | 796 // registry roots). |
| 674 bool IsChromeRegistered(BrowserDistribution* dist, | 797 bool IsChromeRegistered(BrowserDistribution* dist, |
| 675 const base::string16& chrome_exe, | 798 const base::string16& chrome_exe, |
| 676 const base::string16& suffix, | 799 const base::string16& suffix, |
| 677 uint32 look_for_in) { | 800 uint32 look_for_in) { |
| 678 ScopedVector<RegistryEntry> entries; | 801 ScopedVector<RegistryEntry> entries; |
| 679 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); | 802 RegistryEntry::GetChromeProgIdEntries(dist, chrome_exe, suffix, &entries); |
| 680 RegistryEntry::GetShellIntegrationEntries(dist, chrome_exe, suffix, &entries); | 803 RegistryEntry::GetShellIntegrationEntries(dist, chrome_exe, suffix, &entries); |
| 681 RegistryEntry::GetAppRegistrationEntries(chrome_exe, suffix, &entries); | 804 RegistryEntry::GetChromeAppRegistrationEntries(chrome_exe, suffix, &entries); |
| 682 return AreEntriesRegistered(entries, look_for_in); | 805 return AreEntriesRegistered(entries, look_for_in); |
| 683 } | 806 } |
| 684 | 807 |
| 685 // This method checks if Chrome is already registered on the local machine | 808 // This method checks if Chrome is already registered on the local machine |
| 686 // for the requested protocol. It just checks the one value required for this. | 809 // for the requested protocol. It just checks the one value required for this. |
| 687 // See RegistryEntry::ExistsInRegistry for the behavior of |look_for_in|. | 810 // See RegistryEntry::ExistsInRegistry for the behavior of |look_for_in|. |
| 688 bool IsChromeRegisteredForProtocol(BrowserDistribution* dist, | 811 bool IsChromeRegisteredForProtocol(BrowserDistribution* dist, |
| 689 const base::string16& suffix, | 812 const base::string16& suffix, |
| 690 const base::string16& protocol, | 813 const base::string16& protocol, |
| 691 uint32 look_for_in) { | 814 uint32 look_for_in) { |
| (...skipping 1364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2056 // Check if chrome is already registered with this suffix. | 2179 // Check if chrome is already registered with this suffix. |
| 2057 if (IsChromeRegistered(dist, chrome_exe, suffix, look_for_in)) | 2180 if (IsChromeRegistered(dist, chrome_exe, suffix, look_for_in)) |
| 2058 return true; | 2181 return true; |
| 2059 | 2182 |
| 2060 bool result = true; | 2183 bool result = true; |
| 2061 if (root == HKEY_CURRENT_USER || IsUserAnAdmin()) { | 2184 if (root == HKEY_CURRENT_USER || IsUserAnAdmin()) { |
| 2062 // Do the full registration if we can do it at user-level or if the user is | 2185 // Do the full registration if we can do it at user-level or if the user is |
| 2063 // an admin. | 2186 // an admin. |
| 2064 ScopedVector<RegistryEntry> progid_and_appreg_entries; | 2187 ScopedVector<RegistryEntry> progid_and_appreg_entries; |
| 2065 ScopedVector<RegistryEntry> shell_entries; | 2188 ScopedVector<RegistryEntry> shell_entries; |
| 2066 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, | 2189 RegistryEntry::GetChromeProgIdEntries( |
| 2067 &progid_and_appreg_entries); | 2190 dist, chrome_exe, suffix, &progid_and_appreg_entries); |
| 2068 RegistryEntry::GetAppRegistrationEntries(chrome_exe, suffix, | 2191 RegistryEntry::GetChromeAppRegistrationEntries( |
| 2069 &progid_and_appreg_entries); | 2192 chrome_exe, suffix, &progid_and_appreg_entries); |
| 2070 RegistryEntry::GetShellIntegrationEntries( | 2193 RegistryEntry::GetShellIntegrationEntries( |
| 2071 dist, chrome_exe, suffix, &shell_entries); | 2194 dist, chrome_exe, suffix, &shell_entries); |
| 2072 result = (AddRegistryEntries(root, progid_and_appreg_entries) && | 2195 result = (AddRegistryEntries(root, progid_and_appreg_entries) && |
| 2073 AddRegistryEntries(root, shell_entries)); | 2196 AddRegistryEntries(root, shell_entries)); |
| 2074 } else if (elevate_if_not_admin && | 2197 } else if (elevate_if_not_admin && |
| 2075 base::win::GetVersion() >= base::win::VERSION_VISTA && | 2198 base::win::GetVersion() >= base::win::VERSION_VISTA && |
| 2076 ElevateAndRegisterChrome(dist, chrome_exe, suffix, base::string16())) { | 2199 ElevateAndRegisterChrome(dist, chrome_exe, suffix, base::string16())) { |
| 2077 // If the user is not an admin and OS is between Vista and Windows 7 | 2200 // If the user is not an admin and OS is between Vista and Windows 7 |
| 2078 // inclusively, try to elevate and register. This is only intended for | 2201 // inclusively, try to elevate and register. This is only intended for |
| 2079 // user-level installs as system-level installs should always be run with | 2202 // user-level installs as system-level installs should always be run with |
| 2080 // admin rights. | 2203 // admin rights. |
| 2081 result = true; | 2204 result = true; |
| 2082 } else { | 2205 } else { |
| 2083 // If we got to this point then all we can do is create ProgId and basic app | 2206 // If we got to this point then all we can do is create ProgId and basic app |
| 2084 // registrations under HKCU. | 2207 // registrations under HKCU. |
| 2085 ScopedVector<RegistryEntry> entries; | 2208 ScopedVector<RegistryEntry> entries; |
| 2086 RegistryEntry::GetProgIdEntries( | 2209 RegistryEntry::GetChromeProgIdEntries( |
| 2087 dist, chrome_exe, base::string16(), &entries); | 2210 dist, chrome_exe, base::string16(), &entries); |
| 2088 // Prefer to use |suffix|; unless Chrome's ProgIds are already registered | 2211 // Prefer to use |suffix|; unless Chrome's ProgIds are already registered |
| 2089 // with no suffix (as per the old registration style): in which case some | 2212 // with no suffix (as per the old registration style): in which case some |
| 2090 // other registry entries could refer to them and since we were not able to | 2213 // other registry entries could refer to them and since we were not able to |
| 2091 // set our HKLM entries above, we are better off not altering these here. | 2214 // set our HKLM entries above, we are better off not altering these here. |
| 2092 if (!AreEntriesRegistered(entries, RegistryEntry::LOOK_IN_HKCU)) { | 2215 if (!AreEntriesRegistered(entries, RegistryEntry::LOOK_IN_HKCU)) { |
| 2093 if (!suffix.empty()) { | 2216 if (!suffix.empty()) { |
| 2094 entries.clear(); | 2217 entries.clear(); |
| 2095 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); | 2218 RegistryEntry::GetChromeProgIdEntries( |
| 2096 RegistryEntry::GetAppRegistrationEntries(chrome_exe, suffix, &entries); | 2219 dist, chrome_exe, suffix, &entries); |
| 2220 RegistryEntry::GetChromeAppRegistrationEntries( | |
| 2221 chrome_exe, suffix, &entries); | |
| 2097 } | 2222 } |
| 2098 result = AddRegistryEntries(HKEY_CURRENT_USER, entries); | 2223 result = AddRegistryEntries(HKEY_CURRENT_USER, entries); |
| 2099 } else { | 2224 } else { |
| 2100 // The ProgId is registered unsuffixed in HKCU, also register the app with | 2225 // The ProgId is registered unsuffixed in HKCU, also register the app with |
| 2101 // Windows in HKCU (this was not done in the old registration style and | 2226 // Windows in HKCU (this was not done in the old registration style and |
| 2102 // thus needs to be done after the above check for the unsuffixed | 2227 // thus needs to be done after the above check for the unsuffixed |
| 2103 // registration). | 2228 // registration). |
| 2104 entries.clear(); | 2229 entries.clear(); |
| 2105 RegistryEntry::GetAppRegistrationEntries(chrome_exe, base::string16(), | 2230 RegistryEntry::GetChromeAppRegistrationEntries( |
| 2106 &entries); | 2231 chrome_exe, base::string16(), &entries); |
| 2107 result = AddRegistryEntries(HKEY_CURRENT_USER, entries); | 2232 result = AddRegistryEntries(HKEY_CURRENT_USER, entries); |
| 2108 } | 2233 } |
| 2109 } | 2234 } |
| 2110 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); | 2235 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); |
| 2111 return result; | 2236 return result; |
| 2112 } | 2237 } |
| 2113 | 2238 |
| 2114 bool ShellUtil::RegisterChromeForProtocol(BrowserDistribution* dist, | 2239 bool ShellUtil::RegisterChromeForProtocol(BrowserDistribution* dist, |
| 2115 const base::string16& chrome_exe, | 2240 const base::string16& chrome_exe, |
| 2116 const base::string16& unique_suffix, | 2241 const base::string16& unique_suffix, |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2285 // are any left...). | 2410 // are any left...). |
| 2286 if (free_bits >= 8 && next_byte_index < size) { | 2411 if (free_bits >= 8 && next_byte_index < size) { |
| 2287 free_bits -= 8; | 2412 free_bits -= 8; |
| 2288 bit_stream += bytes[next_byte_index++] << free_bits; | 2413 bit_stream += bytes[next_byte_index++] << free_bits; |
| 2289 } | 2414 } |
| 2290 } | 2415 } |
| 2291 | 2416 |
| 2292 DCHECK_EQ(ret.length(), encoded_length); | 2417 DCHECK_EQ(ret.length(), encoded_length); |
| 2293 return ret; | 2418 return ret; |
| 2294 } | 2419 } |
| 2420 | |
| 2421 // static | |
| 2422 bool ShellUtil::AddFileAssociations( | |
| 2423 const base::string16& progid, | |
| 2424 const base::CommandLine& command_line, | |
| 2425 const base::string16& file_type_name, | |
| 2426 const base::FilePath& icon_path, | |
| 2427 const std::set<base::string16>& file_extensions) { | |
| 2428 ScopedVector<RegistryEntry> entries; | |
| 2429 | |
| 2430 // Create a class for this app. | |
| 2431 RegistryEntry::ApplicationInfo app_info; | |
| 2432 app_info.prog_id = progid; | |
| 2433 app_info.file_type_name = file_type_name; | |
| 2434 app_info.file_type_icon_path = icon_path.value(); | |
| 2435 app_info.file_type_icon_index = 0; | |
| 2436 app_info.command_line = command_line.GetCommandLineString(); | |
| 2437 RegistryEntry::GetProgIdEntries(app_info, &entries); | |
| 2438 | |
| 2439 // Associate each extension that the app can handle with the class. Set this | |
| 2440 // app as the default handler if and only if there is no existing default. | |
| 2441 for (std::set<base::string16>::const_iterator it = file_extensions.begin(); | |
| 2442 it != file_extensions.end(); | |
| 2443 ++it) { | |
| 2444 base::string16 ext(1, L'.'); | |
| 2445 ext.append(*it); | |
| 2446 RegistryEntry::GetAppExtRegistrationEntries(progid, ext, &entries); | |
| 2447 RegistryEntry::GetAppDefaultRegistrationEntries( | |
| 2448 progid, ext, false, &entries); | |
| 2449 } | |
| 2450 | |
| 2451 return AddRegistryEntries(HKEY_CURRENT_USER, entries); | |
| 2452 } | |
| 2453 | |
| 2454 // static | |
| 2455 bool ShellUtil::DeleteFileAssociations(const base::string16& progid) { | |
| 2456 // Delete the key HKEY_CLASSES_ROOT\PROGID. | |
| 2457 base::string16 key_path(ShellUtil::kRegClasses); | |
| 2458 key_path.push_back(base::FilePath::kSeparators[0]); | |
| 2459 key_path.append(progid); | |
| 2460 return InstallUtil::DeleteRegistryKey( | |
| 2461 HKEY_CURRENT_USER, key_path, WorkItem::kWow64Default); | |
| 2462 | |
| 2463 // Note: there is no need to remove the association from the extension to the | |
| 2464 // class, as Windows will ignore it. See: | |
| 2465 // http://msdn.microsoft.com/en-us/library/windows/desktop/cc144148.aspx | |
| 2466 } | |
| OLD | NEW |