Chromium Code Reviews| 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> |
| 11 #include <vector> | |
| 11 | 12 |
| 12 #include "base/at_exit.h" | 13 #include "base/at_exit.h" |
| 13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 14 #include "base/file_util.h" | 15 #include "base/file_util.h" |
| 15 #include "base/file_version_info.h" | 16 #include "base/file_version_info.h" |
| 16 #include "base/lock.h" | 17 #include "base/lock.h" |
| 17 #include "base/logging.h" | 18 #include "base/logging.h" |
| 18 #include "base/logging_win.h" | 19 #include "base/logging_win.h" |
| 19 #include "base/path_service.h" | 20 #include "base/path_service.h" |
| 20 #include "base/string_number_conversions.h" | 21 #include "base/string_number_conversions.h" |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 } | 420 } |
| 420 | 421 |
| 421 return _AtlModule.DllGetClassObject(rclsid, riid, ppv); | 422 return _AtlModule.DllGetClassObject(rclsid, riid, ppv); |
| 422 } | 423 } |
| 423 | 424 |
| 424 const wchar_t kPostPlatformUAKey[] = | 425 const wchar_t kPostPlatformUAKey[] = |
| 425 L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\" | 426 L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\" |
| 426 L"User Agent\\Post Platform"; | 427 L"User Agent\\Post Platform"; |
| 427 const wchar_t kChromeFramePrefix[] = L"chromeframe/"; | 428 const wchar_t kChromeFramePrefix[] = L"chromeframe/"; |
| 428 | 429 |
| 430 // Returns the list of chrome frame UA agents registered under the | |
| 431 // kPostPlatformUAKey registry key. | |
| 432 void GetRegisteredChromeFrameUAStrings(HKEY parent_hive, | |
| 433 std::vector<std::wstring>* ua_values) { | |
| 434 base::win::RegistryValueIterator ua_registration(parent_hive, | |
| 435 kPostPlatformUAKey); | |
| 436 std::wstring chrome_frame_ua_pattern = kChromeFramePrefix; | |
| 437 chrome_frame_ua_pattern += L"*"; | |
| 438 while (ua_registration.Valid()) { | |
| 439 if (MatchPattern(ua_registration.Name(), | |
| 440 chrome_frame_ua_pattern)) { | |
| 441 ua_values->push_back(ua_registration.Name()); | |
| 442 } | |
| 443 ++ua_registration; | |
| 444 } | |
| 445 } | |
| 446 | |
| 429 // To delete the user agent, set value to NULL. | 447 // To delete the user agent, set value to NULL. |
| 430 // The is_system parameter indicates whether this is a per machine or a per | 448 // The is_system parameter indicates whether this is a per machine or a per |
| 431 // user installation. | 449 // user installation. |
| 432 HRESULT SetChromeFrameUA(bool is_system, const wchar_t* value) { | 450 HRESULT SetChromeFrameUA(bool is_system, const wchar_t* value) { |
| 433 HRESULT hr = E_FAIL; | 451 HRESULT hr = E_FAIL; |
| 434 HKEY parent_hive = is_system ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 452 HKEY parent_hive = is_system ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 435 | 453 |
| 454 // If we are registering the ChromeFrame UA in the kPostPlatformUAKey key | |
|
amit
2011/01/14 05:26:01
why not delete all the matching values anyway? If
| |
| 455 // make sure that we unregister ChromeFrame UA strings registered by previous | |
| 456 // ChromeFrame versions. | |
| 457 std::vector<std::wstring> cf_ua_list; | |
| 458 if (value) { | |
| 459 GetRegisteredChromeFrameUAStrings(parent_hive, &cf_ua_list); | |
| 460 } | |
| 436 RegKey ua_key; | 461 RegKey ua_key; |
| 437 if (ua_key.Create(parent_hive, kPostPlatformUAKey, KEY_WRITE)) { | 462 if (ua_key.Create(parent_hive, kPostPlatformUAKey, KEY_WRITE)) { |
| 438 std::wstring chrome_frame_ua_value_name = kChromeFramePrefix; | 463 std::wstring chrome_frame_ua_value_name = kChromeFramePrefix; |
| 439 chrome_frame_ua_value_name += GetCurrentModuleVersion(); | 464 chrome_frame_ua_value_name += GetCurrentModuleVersion(); |
| 440 if (value) { | 465 if (value) { |
| 466 for (size_t ua_idx = 0; ua_idx < cf_ua_list.size(); ua_idx++) { | |
| 467 ua_key.DeleteValue(cf_ua_list[ua_idx].c_str()); | |
| 468 } | |
| 441 ua_key.WriteValue(chrome_frame_ua_value_name.c_str(), value); | 469 ua_key.WriteValue(chrome_frame_ua_value_name.c_str(), value); |
| 442 } else { | 470 } else { |
| 443 ua_key.DeleteValue(chrome_frame_ua_value_name.c_str()); | 471 ua_key.DeleteValue(chrome_frame_ua_value_name.c_str()); |
| 444 } | 472 } |
| 445 hr = S_OK; | 473 hr = S_OK; |
| 446 } else { | 474 } else { |
| 447 DLOG(ERROR) << __FUNCTION__ << ": " << kPostPlatformUAKey; | 475 DLOG(ERROR) << __FUNCTION__ << ": " << kPostPlatformUAKey; |
| 448 hr = E_UNEXPECTED; | 476 hr = E_UNEXPECTED; |
| 449 } | 477 } |
| 450 return hr; | 478 return hr; |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 788 sd.GetDacl(&new_dacl); | 816 sd.GetDacl(&new_dacl); |
| 789 new_dacl.AddAllowedAce(token_.GetUser(), GENERIC_WRITE | GENERIC_READ); | 817 new_dacl.AddAllowedAce(token_.GetUser(), GENERIC_WRITE | GENERIC_READ); |
| 790 if (AtlSetDacl(object_name.c_str(), SE_REGISTRY_KEY, new_dacl)) { | 818 if (AtlSetDacl(object_name.c_str(), SE_REGISTRY_KEY, new_dacl)) { |
| 791 result = SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE); | 819 result = SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE); |
| 792 } | 820 } |
| 793 } | 821 } |
| 794 | 822 |
| 795 backup.RestoreSecurity(object_name.c_str()); | 823 backup.RestoreSecurity(object_name.c_str()); |
| 796 return result; | 824 return result; |
| 797 } | 825 } |
| OLD | NEW |