Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(644)

Side by Side Diff: chrome/installer/util/shell_util.cc

Issue 487693002: ShellUtil: Add generic methods to add/delete Windows file associations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to grt's comments. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 // The unique internal name used by Windows 8 for this application. Distinct
218 // from |prog_id|. May be empty.
219 base::string16 app_id;
220
221 // User-visible details about this application. Any of these may be empty.
222 base::string16 application_name;
223 // TODO(mgiuca): |application_icon_path| should be a base::FilePath.
224 base::string16 application_icon_path;
225 int application_icon_index;
226 base::string16 application_description;
227 base::string16 publisher_name;
228
229 // Whether the application will have a DelegateExecute key. This should only
230 // be used by Windows 8 Metro web browsers (i.e. Chrome itself). All other
231 // fields in this section are ignored if this is false.
232 bool set_delegate_execute;
gab 2014/09/18 01:16:15 Since only Chrome should ever set this to true, ho
Matt Giuca 2014/09/30 10:21:12 I'm not sure... I prefer to keep all this logic to
gab 2014/10/01 14:31:11 Yea, I don't see the point of having Chrome specif
Matt Giuca 2014/10/02 09:36:33 OK, all this code has moved back to where it origi
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 int chrome_icon_index =
226 ShellUtil::FormatIconLocation( 271 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME);
227 chrome_exe, 272
228 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME))); 273 ApplicationInfo app_info;
229 base::string16 open_cmd(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); 274 app_info.prog_id = GetBrowserProgId(suffix);
230 base::string16 delegate_command( 275 app_info.file_type_name = dist->GetBrowserProgIdDesc();
231 ShellUtil::GetChromeDelegateCommand(chrome_exe)); 276 // File types associated with Chrome are just given the Chrome icon.
232 // For user-level installs: entries for the app id and DelegateExecute verb 277 app_info.file_type_icon_path = chrome_exe;
233 // handler will be in HKCU; thus we do not need a suffix on those entries. 278 app_info.file_type_icon_index = chrome_icon_index;
234 base::string16 app_id( 279 app_info.command_line = ShellUtil::GetChromeShellOpenCmd(chrome_exe);
235 ShellUtil::GetBrowserModelId( 280 // For user-level installs: entries for the app id will be in HKCU; thus we
236 dist, InstallUtil::IsPerUserInstall(chrome_exe.c_str()))); 281 // do not need a suffix on those entries.
237 base::string16 delegate_guid; 282 app_info.app_id = ShellUtil::GetBrowserModelId(
238 bool set_delegate_execute = 283 dist, InstallUtil::IsPerUserInstall(chrome_exe.c_str()));
239 IsChromeMetroSupported() &&
240 dist->GetCommandExecuteImplClsid(&delegate_guid);
241 284
242 // DelegateExecute ProgId. Needed for Chrome Metro in Windows 8. 285 // DelegateExecute ProgId. Needed for Chrome Metro in Windows 8.
243 if (set_delegate_execute) { 286 app_info.delegate_command = ShellUtil::GetChromeDelegateCommand(chrome_exe);
287 app_info.set_delegate_execute =
288 IsChromeMetroSupported() &&
289 dist->GetCommandExecuteImplClsid(&app_info.delegate_guid);
290
291 // TODO(grt): http://crbug.com/75152 Write a reference to a localized
292 // resource for name, description, and company.
293 app_info.application_name = dist->GetDisplayName();
294 app_info.application_icon_path = chrome_exe;
295 app_info.application_icon_index = chrome_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) {
312 entries->push_back(new RegistryEntry( 379 if (!app_info.app_id.empty()) {
313 chrome_html_prog_id, ShellUtil::kRegAppUserModelId, app_id)); 380 entries->push_back(new RegistryEntry(
381 prog_id_path, ShellUtil::kRegAppUserModelId, app_info.app_id));
382 }
314 383
315 // Add \Software\Classes\ChromeHTML\Application entries 384 // Add \Software\Classes\<prog_id>\Application entries
316 base::string16 chrome_application(chrome_html_prog_id + 385 base::string16 application_path(prog_id_path +
317 ShellUtil::kRegApplication); 386 ShellUtil::kRegApplication);
318 entries->push_back(new RegistryEntry( 387 if (!app_info.app_id.empty()) {
319 chrome_application, ShellUtil::kRegAppUserModelId, app_id)); 388 entries->push_back(new RegistryEntry(
320 entries->push_back(new RegistryEntry( 389 application_path, ShellUtil::kRegAppUserModelId, app_info.app_id));
321 chrome_application, ShellUtil::kRegApplicationIcon, icon_path)); 390 }
322 // TODO(grt): http://crbug.com/75152 Write a reference to a localized 391 if (!app_info.application_icon_path.empty()) {
323 // resource for name, description, and company. 392 entries->push_back(new RegistryEntry(
324 entries->push_back(new RegistryEntry( 393 application_path,
325 chrome_application, ShellUtil::kRegApplicationName, 394 ShellUtil::kRegApplicationIcon,
326 dist->GetDisplayName())); 395 ShellUtil::FormatIconLocation(app_info.application_icon_path,
327 entries->push_back(new RegistryEntry( 396 app_info.application_icon_index)));
328 chrome_application, ShellUtil::kRegApplicationDescription, 397 }
329 dist->GetAppDescription())); 398 if (!app_info.application_name.empty()) {
330 entries->push_back(new RegistryEntry( 399 entries->push_back(new RegistryEntry(application_path,
331 chrome_application, ShellUtil::kRegApplicationCompany, 400 ShellUtil::kRegApplicationName,
332 dist->GetPublisherName())); 401 app_info.application_name));
402 }
403 if (!app_info.application_description.empty()) {
404 entries->push_back(
405 new RegistryEntry(application_path,
406 ShellUtil::kRegApplicationDescription,
407 app_info.application_description));
408 }
409 if (!app_info.publisher_name.empty()) {
410 entries->push_back(new RegistryEntry(application_path,
411 ShellUtil::kRegApplicationCompany,
412 app_info.publisher_name));
413 }
333 } 414 }
334 } 415 }
335 416
336 // This method returns a list of the registry entries needed to declare a 417 // This method returns a list of the registry entries needed to declare a
337 // capability of handling a protocol on Windows. 418 // capability of handling a protocol on Windows.
338 static void GetProtocolCapabilityEntries( 419 static void GetProtocolCapabilityEntries(
339 BrowserDistribution* dist, 420 BrowserDistribution* dist,
340 const base::string16& suffix, 421 const base::string16& suffix,
341 const base::string16& protocol, 422 const base::string16& protocol,
342 ScopedVector<RegistryEntry>* entries) { 423 ScopedVector<RegistryEntry>* entries) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 } 507 }
427 508
428 // This method returns a list of the registry entries required for this 509 // This method returns a list of the registry entries required for this
429 // installation to be registered in the Windows shell. 510 // installation to be registered in the Windows shell.
430 // In particular: 511 // In particular:
431 // - App Paths 512 // - App Paths
432 // http://msdn.microsoft.com/en-us/library/windows/desktop/ee872121 513 // http://msdn.microsoft.com/en-us/library/windows/desktop/ee872121
433 // - File Associations 514 // - File Associations
434 // http://msdn.microsoft.com/en-us/library/bb166549 515 // http://msdn.microsoft.com/en-us/library/bb166549
435 // These entries need to be registered in HKLM prior to Win8. 516 // These entries need to be registered in HKLM prior to Win8.
436 static void GetAppRegistrationEntries(const base::string16& chrome_exe, 517 static void GetChromeAppRegistrationEntries(
437 const base::string16& suffix, 518 const base::string16& chrome_exe,
438 ScopedVector<RegistryEntry>* entries) { 519 const base::string16& suffix,
520 ScopedVector<RegistryEntry>* entries) {
439 const base::FilePath chrome_path(chrome_exe); 521 const base::FilePath chrome_path(chrome_exe);
440 base::string16 app_path_key(ShellUtil::kAppPathsRegistryKey); 522 base::string16 app_path_key(ShellUtil::kAppPathsRegistryKey);
441 app_path_key.push_back(base::FilePath::kSeparators[0]); 523 app_path_key.push_back(base::FilePath::kSeparators[0]);
442 app_path_key.append(chrome_path.BaseName().value()); 524 app_path_key.append(chrome_path.BaseName().value());
443 entries->push_back(new RegistryEntry(app_path_key, chrome_exe)); 525 entries->push_back(new RegistryEntry(app_path_key, chrome_exe));
444 entries->push_back(new RegistryEntry(app_path_key, 526 entries->push_back(new RegistryEntry(app_path_key,
445 ShellUtil::kAppPathsRegistryPathName, chrome_path.DirName().value())); 527 ShellUtil::kAppPathsRegistryPathName, chrome_path.DirName().value()));
446 528
447 const base::string16 html_prog_id(GetBrowserProgId(suffix)); 529 const base::string16 html_prog_id(GetBrowserProgId(suffix));
448 for (int i = 0; ShellUtil::kPotentialFileAssociations[i] != NULL; i++) { 530 for (int i = 0; ShellUtil::kPotentialFileAssociations[i] != NULL; i++) {
449 base::string16 key(ShellUtil::kRegClasses); 531 GetAppExtRegistrationEntries(
450 key.push_back(base::FilePath::kSeparators[0]); 532 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 } 533 }
457 } 534 }
458 535
536 // Gets the registry entries to register an application as a handler for a
537 // particular file extension. |prog_id| is the unique internal name Windows
538 // uses for the application. |ext| is the file extension, which must begin
539 // with a '.'.
540 static void GetAppExtRegistrationEntries(
541 const base::string16& prog_id,
542 const base::string16& ext,
543 ScopedVector<RegistryEntry>* entries) {
544 // In HKEY_CLASSES_ROOT\EXT\OpenWithProgids, create an empty value with this
545 // class's prog_id.
546 base::string16 key_name(ShellUtil::kRegClasses);
547 key_name.push_back(base::FilePath::kSeparators[0]);
548 key_name.append(ext);
549 key_name.push_back(base::FilePath::kSeparators[0]);
550 key_name.append(ShellUtil::kRegOpenWithProgids);
551 entries->push_back(new RegistryEntry(key_name, prog_id, base::string16()));
552 }
553
554 // Gets the registry entries to register an application as the default handler
555 // for a particular file extension. |prog_id| is the unique internal name
556 // Windows uses for the application. |ext| is the file extension, which must
557 // begin with a '.'. If |overwrite_existing|, always sets the default handler;
558 // otherwise only sets if there is no existing default.
559 static void GetAppDefaultRegistrationEntries(
560 const base::string16& prog_id,
561 const base::string16& ext,
562 bool overwrite_existing,
563 ScopedVector<RegistryEntry>* entries) {
564 // Set the default value of HKEY_CLASSES_ROOT\EXT to this class's name.
565 base::string16 key_name(ShellUtil::kRegClasses);
566 key_name.push_back(base::FilePath::kSeparators[0]);
567 key_name.append(ext);
568 scoped_ptr<RegistryEntry> default_association(
569 new RegistryEntry(key_name, prog_id));
570 if (overwrite_existing ||
571 !default_association->KeyExistsInRegistry(
572 RegistryEntry::LOOK_IN_HKCU)) {
573 entries->push_back(default_association.release());
574 }
575 }
576
459 // This method returns a list of all the user level registry entries that 577 // 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. 578 // are needed to make Chromium the default handler for a protocol on XP.
461 static void GetXPStyleUserProtocolEntries( 579 static void GetXPStyleUserProtocolEntries(
462 const base::string16& protocol, 580 const base::string16& protocol,
463 const base::string16& chrome_icon, 581 const base::string16& chrome_icon,
464 const base::string16& chrome_open, 582 const base::string16& chrome_open,
465 ScopedVector<RegistryEntry>* entries) { 583 ScopedVector<RegistryEntry>* entries) {
466 // Protocols associations. 584 // Protocols associations.
467 base::string16 url_key(ShellUtil::kRegClasses); 585 base::string16 url_key(ShellUtil::kRegClasses);
468 url_key.push_back(base::FilePath::kSeparators[0]); 586 url_key.push_back(base::FilePath::kSeparators[0]);
(...skipping 28 matching lines...) Expand all
497 // we register them anyways as some legacy apps are hardcoded to lookup those 615 // we register them anyways as some legacy apps are hardcoded to lookup those
498 // values. 616 // values.
499 static void GetXPStyleDefaultBrowserUserEntries( 617 static void GetXPStyleDefaultBrowserUserEntries(
500 BrowserDistribution* dist, 618 BrowserDistribution* dist,
501 const base::string16& chrome_exe, 619 const base::string16& chrome_exe,
502 const base::string16& suffix, 620 const base::string16& suffix,
503 ScopedVector<RegistryEntry>* entries) { 621 ScopedVector<RegistryEntry>* entries) {
504 // File extension associations. 622 // File extension associations.
505 base::string16 html_prog_id(GetBrowserProgId(suffix)); 623 base::string16 html_prog_id(GetBrowserProgId(suffix));
506 for (int i = 0; ShellUtil::kDefaultFileAssociations[i] != NULL; i++) { 624 for (int i = 0; ShellUtil::kDefaultFileAssociations[i] != NULL; i++) {
507 base::string16 ext_key(ShellUtil::kRegClasses); 625 GetAppDefaultRegistrationEntries(
508 ext_key.push_back(base::FilePath::kSeparators[0]); 626 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 } 627 }
512 628
513 // Protocols associations. 629 // Protocols associations.
514 base::string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); 630 base::string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe);
515 base::string16 chrome_icon = 631 base::string16 chrome_icon =
516 ShellUtil::FormatIconLocation( 632 ShellUtil::FormatIconLocation(
517 chrome_exe, 633 chrome_exe,
518 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME)); 634 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME));
519 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { 635 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) {
520 GetXPStyleUserProtocolEntries(ShellUtil::kBrowserProtocolAssociations[i], 636 GetXPStyleUserProtocolEntries(ShellUtil::kBrowserProtocolAssociations[i],
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 DCHECK(look_for_in); 672 DCHECK(look_for_in);
557 673
558 RegistryStatus status = DOES_NOT_EXIST; 674 RegistryStatus status = DOES_NOT_EXIST;
559 if (look_for_in & LOOK_IN_HKCU) 675 if (look_for_in & LOOK_IN_HKCU)
560 status = StatusInRegistryUnderRoot(HKEY_CURRENT_USER); 676 status = StatusInRegistryUnderRoot(HKEY_CURRENT_USER);
561 if (status == DOES_NOT_EXIST && (look_for_in & LOOK_IN_HKLM)) 677 if (status == DOES_NOT_EXIST && (look_for_in & LOOK_IN_HKLM))
562 status = StatusInRegistryUnderRoot(HKEY_LOCAL_MACHINE); 678 status = StatusInRegistryUnderRoot(HKEY_LOCAL_MACHINE);
563 return status == SAME_VALUE; 679 return status == SAME_VALUE;
564 } 680 }
565 681
682 // Checks if the current registry entry exists in \|key_path_|\|name_|,
683 // regardless of value. Same lookup rules as ExistsInRegistry.
684 // Unlike ExistsInRegistry, this returns true if some other value is present
685 // with the same key.
686 bool KeyExistsInRegistry(uint32 look_for_in) const {
687 DCHECK(look_for_in);
688
689 RegistryStatus status = DOES_NOT_EXIST;
690 if (look_for_in & LOOK_IN_HKCU)
691 status = StatusInRegistryUnderRoot(HKEY_CURRENT_USER);
692 if (status == DOES_NOT_EXIST && (look_for_in & LOOK_IN_HKLM))
693 status = StatusInRegistryUnderRoot(HKEY_LOCAL_MACHINE);
694 return status != DOES_NOT_EXIST;
695 }
696
566 private: 697 private:
567 // States this RegistryKey can be in compared to the registry. 698 // States this RegistryKey can be in compared to the registry.
568 enum RegistryStatus { 699 enum RegistryStatus {
569 // |name_| does not exist in the registry 700 // |name_| does not exist in the registry
570 DOES_NOT_EXIST, 701 DOES_NOT_EXIST,
571 // |name_| exists, but its value != |value_| 702 // |name_| exists, but its value != |value_|
572 DIFFERENT_VALUE, 703 DIFFERENT_VALUE,
573 // |name_| exists and its value is |value_| 704 // |name_| exists and its value is |value_|
574 SAME_VALUE, 705 SAME_VALUE,
575 }; 706 };
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 // under a single registry root. Not doing so caused http://crbug.com/144910 for 800 // 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 801 // 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 802 // 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 803 // true for affected users (i.e. who have all the registrations, but over both
673 // registry roots). 804 // registry roots).
674 bool IsChromeRegistered(BrowserDistribution* dist, 805 bool IsChromeRegistered(BrowserDistribution* dist,
675 const base::string16& chrome_exe, 806 const base::string16& chrome_exe,
676 const base::string16& suffix, 807 const base::string16& suffix,
677 uint32 look_for_in) { 808 uint32 look_for_in) {
678 ScopedVector<RegistryEntry> entries; 809 ScopedVector<RegistryEntry> entries;
679 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); 810 RegistryEntry::GetChromeProgIdEntries(dist, chrome_exe, suffix, &entries);
680 RegistryEntry::GetShellIntegrationEntries(dist, chrome_exe, suffix, &entries); 811 RegistryEntry::GetShellIntegrationEntries(dist, chrome_exe, suffix, &entries);
681 RegistryEntry::GetAppRegistrationEntries(chrome_exe, suffix, &entries); 812 RegistryEntry::GetChromeAppRegistrationEntries(chrome_exe, suffix, &entries);
682 return AreEntriesRegistered(entries, look_for_in); 813 return AreEntriesRegistered(entries, look_for_in);
683 } 814 }
684 815
685 // This method checks if Chrome is already registered on the local machine 816 // 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. 817 // for the requested protocol. It just checks the one value required for this.
687 // See RegistryEntry::ExistsInRegistry for the behavior of |look_for_in|. 818 // See RegistryEntry::ExistsInRegistry for the behavior of |look_for_in|.
688 bool IsChromeRegisteredForProtocol(BrowserDistribution* dist, 819 bool IsChromeRegisteredForProtocol(BrowserDistribution* dist,
689 const base::string16& suffix, 820 const base::string16& suffix,
690 const base::string16& protocol, 821 const base::string16& protocol,
691 uint32 look_for_in) { 822 uint32 look_for_in) {
(...skipping 1364 matching lines...) Expand 10 before | Expand all | Expand 10 after
2056 // Check if chrome is already registered with this suffix. 2187 // Check if chrome is already registered with this suffix.
2057 if (IsChromeRegistered(dist, chrome_exe, suffix, look_for_in)) 2188 if (IsChromeRegistered(dist, chrome_exe, suffix, look_for_in))
2058 return true; 2189 return true;
2059 2190
2060 bool result = true; 2191 bool result = true;
2061 if (root == HKEY_CURRENT_USER || IsUserAnAdmin()) { 2192 if (root == HKEY_CURRENT_USER || IsUserAnAdmin()) {
2062 // Do the full registration if we can do it at user-level or if the user is 2193 // Do the full registration if we can do it at user-level or if the user is
2063 // an admin. 2194 // an admin.
2064 ScopedVector<RegistryEntry> progid_and_appreg_entries; 2195 ScopedVector<RegistryEntry> progid_and_appreg_entries;
2065 ScopedVector<RegistryEntry> shell_entries; 2196 ScopedVector<RegistryEntry> shell_entries;
2066 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, 2197 RegistryEntry::GetChromeProgIdEntries(
2067 &progid_and_appreg_entries); 2198 dist, chrome_exe, suffix, &progid_and_appreg_entries);
2068 RegistryEntry::GetAppRegistrationEntries(chrome_exe, suffix, 2199 RegistryEntry::GetChromeAppRegistrationEntries(
2069 &progid_and_appreg_entries); 2200 chrome_exe, suffix, &progid_and_appreg_entries);
2070 RegistryEntry::GetShellIntegrationEntries( 2201 RegistryEntry::GetShellIntegrationEntries(
2071 dist, chrome_exe, suffix, &shell_entries); 2202 dist, chrome_exe, suffix, &shell_entries);
2072 result = (AddRegistryEntries(root, progid_and_appreg_entries) && 2203 result = (AddRegistryEntries(root, progid_and_appreg_entries) &&
2073 AddRegistryEntries(root, shell_entries)); 2204 AddRegistryEntries(root, shell_entries));
2074 } else if (elevate_if_not_admin && 2205 } else if (elevate_if_not_admin &&
2075 base::win::GetVersion() >= base::win::VERSION_VISTA && 2206 base::win::GetVersion() >= base::win::VERSION_VISTA &&
2076 ElevateAndRegisterChrome(dist, chrome_exe, suffix, base::string16())) { 2207 ElevateAndRegisterChrome(dist, chrome_exe, suffix, base::string16())) {
2077 // If the user is not an admin and OS is between Vista and Windows 7 2208 // 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 2209 // inclusively, try to elevate and register. This is only intended for
2079 // user-level installs as system-level installs should always be run with 2210 // user-level installs as system-level installs should always be run with
2080 // admin rights. 2211 // admin rights.
2081 result = true; 2212 result = true;
2082 } else { 2213 } else {
2083 // If we got to this point then all we can do is create ProgId and basic app 2214 // If we got to this point then all we can do is create ProgId and basic app
2084 // registrations under HKCU. 2215 // registrations under HKCU.
2085 ScopedVector<RegistryEntry> entries; 2216 ScopedVector<RegistryEntry> entries;
2086 RegistryEntry::GetProgIdEntries( 2217 RegistryEntry::GetChromeProgIdEntries(
2087 dist, chrome_exe, base::string16(), &entries); 2218 dist, chrome_exe, base::string16(), &entries);
2088 // Prefer to use |suffix|; unless Chrome's ProgIds are already registered 2219 // 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 2220 // 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 2221 // 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. 2222 // set our HKLM entries above, we are better off not altering these here.
2092 if (!AreEntriesRegistered(entries, RegistryEntry::LOOK_IN_HKCU)) { 2223 if (!AreEntriesRegistered(entries, RegistryEntry::LOOK_IN_HKCU)) {
2093 if (!suffix.empty()) { 2224 if (!suffix.empty()) {
2094 entries.clear(); 2225 entries.clear();
2095 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); 2226 RegistryEntry::GetChromeProgIdEntries(
2096 RegistryEntry::GetAppRegistrationEntries(chrome_exe, suffix, &entries); 2227 dist, chrome_exe, suffix, &entries);
2228 RegistryEntry::GetChromeAppRegistrationEntries(
2229 chrome_exe, suffix, &entries);
2097 } 2230 }
2098 result = AddRegistryEntries(HKEY_CURRENT_USER, entries); 2231 result = AddRegistryEntries(HKEY_CURRENT_USER, entries);
2099 } else { 2232 } else {
2100 // The ProgId is registered unsuffixed in HKCU, also register the app with 2233 // 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 2234 // 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 2235 // thus needs to be done after the above check for the unsuffixed
2103 // registration). 2236 // registration).
2104 entries.clear(); 2237 entries.clear();
2105 RegistryEntry::GetAppRegistrationEntries(chrome_exe, base::string16(), 2238 RegistryEntry::GetChromeAppRegistrationEntries(
2106 &entries); 2239 chrome_exe, base::string16(), &entries);
2107 result = AddRegistryEntries(HKEY_CURRENT_USER, entries); 2240 result = AddRegistryEntries(HKEY_CURRENT_USER, entries);
2108 } 2241 }
2109 } 2242 }
2110 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); 2243 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
2111 return result; 2244 return result;
2112 } 2245 }
2113 2246
2114 bool ShellUtil::RegisterChromeForProtocol(BrowserDistribution* dist, 2247 bool ShellUtil::RegisterChromeForProtocol(BrowserDistribution* dist,
2115 const base::string16& chrome_exe, 2248 const base::string16& chrome_exe,
2116 const base::string16& unique_suffix, 2249 const base::string16& unique_suffix,
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
2285 // are any left...). 2418 // are any left...).
2286 if (free_bits >= 8 && next_byte_index < size) { 2419 if (free_bits >= 8 && next_byte_index < size) {
2287 free_bits -= 8; 2420 free_bits -= 8;
2288 bit_stream += bytes[next_byte_index++] << free_bits; 2421 bit_stream += bytes[next_byte_index++] << free_bits;
2289 } 2422 }
2290 } 2423 }
2291 2424
2292 DCHECK_EQ(ret.length(), encoded_length); 2425 DCHECK_EQ(ret.length(), encoded_length);
2293 return ret; 2426 return ret;
2294 } 2427 }
2428
2429 // static
2430 bool ShellUtil::AddFileAssociations(
2431 const base::string16& progid,
2432 const base::CommandLine& command_line,
2433 const base::string16& file_type_name,
2434 const base::FilePath& icon_path,
2435 const std::set<base::string16>& file_extensions) {
2436 ScopedVector<RegistryEntry> entries;
2437
2438 // Create a class for this app.
2439 RegistryEntry::ApplicationInfo app_info;
2440 app_info.prog_id = progid;
2441 app_info.file_type_name = file_type_name;
2442 app_info.file_type_icon_path = icon_path.value();
2443 app_info.file_type_icon_index = 0;
2444 app_info.command_line = command_line.GetCommandLineString();
2445 RegistryEntry::GetProgIdEntries(app_info, &entries);
2446
2447 // Associate each extension that the app can handle with the class. Set this
2448 // app as the default handler if and only if there is no existing default.
2449 for (std::set<base::string16>::const_iterator it = file_extensions.begin();
2450 it != file_extensions.end();
2451 ++it) {
2452 // TODO(mgiuca): Do we allow empty file extensions?
2453 // TODO(mgiuca): Do we allow file extensions with a '.' in them?
2454 DCHECK(!it->empty());
2455 DCHECK((*it)[0] != L'.');
2456 base::string16 ext(1, L'.');
2457 ext.append(*it);
2458 RegistryEntry::GetAppExtRegistrationEntries(progid, ext, &entries);
2459 RegistryEntry::GetAppDefaultRegistrationEntries(
2460 progid, ext, false, &entries);
2461 }
2462
2463 return AddRegistryEntries(HKEY_CURRENT_USER, entries);
2464 }
2465
2466 // static
2467 bool ShellUtil::DeleteFileAssociations(const base::string16& progid) {
2468 // Delete the key HKEY_CLASSES_ROOT\PROGID.
2469 base::string16 key_path(ShellUtil::kRegClasses);
2470 key_path.push_back(base::FilePath::kSeparators[0]);
2471 key_path.append(progid);
2472 return InstallUtil::DeleteRegistryKey(
2473 HKEY_CURRENT_USER, key_path, WorkItem::kWow64Default);
2474
2475 // TODO(mgiuca): Remove the extension association entries. This requires that
2476 // the extensions associated with a particular prog_id are stored in that
2477 // prog_id's key.
2478 }
OLDNEW
« chrome/chrome_browser.gypi ('K') | « chrome/installer/util/shell_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698