OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // chrome_tab.cc : Implementation of DLL Exports. | 5 // chrome_tab.cc : Implementation of DLL Exports. |
6 | 6 |
7 // Include without path to make GYP build see it. | 7 // Include without path to make GYP build see it. |
8 #include "chrome_tab.h" // NOLINT | 8 #include "chrome_tab.h" // NOLINT |
9 | 9 |
10 #include <atlsecurity.h> | 10 #include <atlsecurity.h> |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 const wchar_t kChromeFramePrefix[] = L"chromeframe/"; | 427 const wchar_t kChromeFramePrefix[] = L"chromeframe/"; |
428 | 428 |
429 // To delete the user agent, set value to NULL. | 429 // To delete the user agent, set value to NULL. |
430 // The is_system parameter indicates whether this is a per machine or a per | 430 // The is_system parameter indicates whether this is a per machine or a per |
431 // user installation. | 431 // user installation. |
432 HRESULT SetChromeFrameUA(bool is_system, const wchar_t* value) { | 432 HRESULT SetChromeFrameUA(bool is_system, const wchar_t* value) { |
433 HRESULT hr = E_FAIL; | 433 HRESULT hr = E_FAIL; |
434 HKEY parent_hive = is_system ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 434 HKEY parent_hive = is_system ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
435 | 435 |
436 RegKey ua_key; | 436 RegKey ua_key; |
437 if (ua_key.Create(parent_hive, kPostPlatformUAKey, KEY_WRITE)) { | 437 if (ua_key.Create(parent_hive, kPostPlatformUAKey, KEY_READ | KEY_WRITE)) { |
| 438 // Make sure that we unregister ChromeFrame UA strings registered previously |
| 439 wchar_t name[MAX_PATH + 1] = {}; |
| 440 wchar_t value[MAX_PATH + 1] = {}; |
| 441 |
| 442 DWORD value_index = 0; |
| 443 while (value_index < ua_key.ValueCount()) { |
| 444 DWORD name_size = arraysize(name); |
| 445 DWORD value_size = arraysize(value); |
| 446 DWORD type = 0; |
| 447 LRESULT ret = ::RegEnumValue(ua_key.Handle(), value_index, name, |
| 448 &name_size, NULL, &type, |
| 449 reinterpret_cast<BYTE*>(value), |
| 450 &value_size); |
| 451 if (ret == ERROR_SUCCESS) { |
| 452 if (StartsWith(name, kChromeFramePrefix, false)) { |
| 453 ua_key.DeleteValue(name); |
| 454 } else { |
| 455 ++value_index; |
| 456 } |
| 457 } else { |
| 458 break; |
| 459 } |
| 460 } |
| 461 |
438 std::wstring chrome_frame_ua_value_name = kChromeFramePrefix; | 462 std::wstring chrome_frame_ua_value_name = kChromeFramePrefix; |
439 chrome_frame_ua_value_name += GetCurrentModuleVersion(); | 463 chrome_frame_ua_value_name += GetCurrentModuleVersion(); |
440 if (value) { | 464 if (value) { |
441 ua_key.WriteValue(chrome_frame_ua_value_name.c_str(), value); | 465 ua_key.WriteValue(chrome_frame_ua_value_name.c_str(), value); |
442 } else { | |
443 ua_key.DeleteValue(chrome_frame_ua_value_name.c_str()); | |
444 } | 466 } |
445 hr = S_OK; | 467 hr = S_OK; |
446 } else { | 468 } else { |
447 DLOG(ERROR) << __FUNCTION__ << ": " << kPostPlatformUAKey; | 469 DLOG(ERROR) << __FUNCTION__ << ": " << kPostPlatformUAKey; |
448 hr = E_UNEXPECTED; | 470 hr = E_UNEXPECTED; |
449 } | 471 } |
450 return hr; | 472 return hr; |
451 } | 473 } |
452 | 474 |
453 enum RegistrationFlags { | 475 enum RegistrationFlags { |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 sd.GetDacl(&new_dacl); | 810 sd.GetDacl(&new_dacl); |
789 new_dacl.AddAllowedAce(token_.GetUser(), GENERIC_WRITE | GENERIC_READ); | 811 new_dacl.AddAllowedAce(token_.GetUser(), GENERIC_WRITE | GENERIC_READ); |
790 if (AtlSetDacl(object_name.c_str(), SE_REGISTRY_KEY, new_dacl)) { | 812 if (AtlSetDacl(object_name.c_str(), SE_REGISTRY_KEY, new_dacl)) { |
791 result = SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE); | 813 result = SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE); |
792 } | 814 } |
793 } | 815 } |
794 | 816 |
795 backup.RestoreSecurity(object_name.c_str()); | 817 backup.RestoreSecurity(object_name.c_str()); |
796 return result; | 818 return result; |
797 } | 819 } |
OLD | NEW |