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 #include "chrome_frame/utils.h" | 5 #include "chrome_frame/utils.h" |
| 6 | 6 |
| 7 #include <htiframe.h> | 7 #include <htiframe.h> |
| 8 #include <mshtml.h> | 8 #include <mshtml.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 | 10 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 bool UtilChangePersistentNPAPIMarker(bool set) { | 226 bool UtilChangePersistentNPAPIMarker(bool set) { |
| 227 BrowserDistribution* cf_dist = BrowserDistribution::GetDistribution(); | 227 BrowserDistribution* cf_dist = BrowserDistribution::GetDistribution(); |
| 228 std::wstring cf_state_key_path(cf_dist->GetStateKey()); | 228 std::wstring cf_state_key_path(cf_dist->GetStateKey()); |
| 229 | 229 |
| 230 RegKey cf_state_key(HKEY_LOCAL_MACHINE, cf_state_key_path.c_str(), | 230 RegKey cf_state_key(HKEY_LOCAL_MACHINE, cf_state_key_path.c_str(), |
| 231 KEY_READ | KEY_WRITE); | 231 KEY_READ | KEY_WRITE); |
| 232 | 232 |
| 233 bool success = false; | 233 bool success = false; |
| 234 if (cf_state_key.Valid()) { | 234 if (cf_state_key.Valid()) { |
| 235 if (set) { | 235 if (set) { |
| 236 success = cf_state_key.WriteValue(kChromeFramePersistNPAPIReg, 1); | 236 success = (cf_state_key.WriteValue(kChromeFramePersistNPAPIReg, 1) |
| 237 == ERROR_SUCCESS); | |
|
grt (UTC plus 2)
2011/01/16 04:19:48
Wrapping and indentation
amit
2011/01/16 07:54:28
Done.
| |
| 237 } else { | 238 } else { |
| 238 // Unfortunately, DeleteValue returns true only if the value | 239 // Unfortunately, DeleteValue returns true only if the value |
| 239 // previously existed, so we do a separate existence check to | 240 // previously existed, so we do a separate existence check to |
| 240 // validate success. | 241 // validate success. |
| 241 cf_state_key.DeleteValue(kChromeFramePersistNPAPIReg); | 242 cf_state_key.DeleteValue(kChromeFramePersistNPAPIReg); |
| 242 success = !cf_state_key.ValueExists(kChromeFramePersistNPAPIReg); | 243 success = !cf_state_key.ValueExists(kChromeFramePersistNPAPIReg); |
| 243 } | 244 } |
| 244 } | 245 } |
| 245 return success; | 246 return success; |
| 246 } | 247 } |
| 247 | 248 |
| 248 bool UtilIsPersistentNPAPIMarkerSet() { | 249 bool UtilIsPersistentNPAPIMarkerSet() { |
| 249 BrowserDistribution* cf_dist = BrowserDistribution::GetDistribution(); | 250 BrowserDistribution* cf_dist = BrowserDistribution::GetDistribution(); |
| 250 std::wstring cf_state_key_path(cf_dist->GetStateKey()); | 251 std::wstring cf_state_key_path(cf_dist->GetStateKey()); |
| 251 | 252 |
| 252 RegKey cf_state_key(HKEY_LOCAL_MACHINE, cf_state_key_path.c_str(), | 253 RegKey cf_state_key(HKEY_LOCAL_MACHINE, cf_state_key_path.c_str(), |
| 253 KEY_QUERY_VALUE); | 254 KEY_QUERY_VALUE); |
| 254 | 255 |
| 255 bool success = false; | 256 bool success = false; |
| 256 if (cf_state_key.Valid()) { | 257 if (cf_state_key.Valid()) { |
| 257 DWORD val = 0; | 258 DWORD val = 0; |
| 258 if (cf_state_key.ReadValueDW(kChromeFramePersistNPAPIReg, &val)) { | 259 if (cf_state_key.ReadValueDW(kChromeFramePersistNPAPIReg, &val) |
| 260 == ERROR_SUCCESS) { | |
|
grt (UTC plus 2)
2011/01/16 04:19:48
Wrapping
amit
2011/01/16 07:54:28
Done.
| |
| 259 success = (val != 0); | 261 success = (val != 0); |
| 260 } | 262 } |
| 261 } | 263 } |
| 262 return success; | 264 return success; |
| 263 } | 265 } |
| 264 | 266 |
| 265 | 267 |
| 266 HRESULT UtilGetXUACompatContentValue(const std::wstring& html_string, | 268 HRESULT UtilGetXUACompatContentValue(const std::wstring& html_string, |
| 267 std::wstring* content_value) { | 269 std::wstring* content_value) { |
| 268 if (!content_value) { | 270 if (!content_value) { |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 669 ret = true; | 671 ret = true; |
| 670 } | 672 } |
| 671 | 673 |
| 672 return ret; | 674 return ret; |
| 673 } | 675 } |
| 674 | 676 |
| 675 int GetConfigInt(int default_value, const wchar_t* value_name) { | 677 int GetConfigInt(int default_value, const wchar_t* value_name) { |
| 676 int ret = default_value; | 678 int ret = default_value; |
| 677 RegKey config_key; | 679 RegKey config_key; |
| 678 if (config_key.Open(HKEY_CURRENT_USER, kChromeFrameConfigKey, | 680 if (config_key.Open(HKEY_CURRENT_USER, kChromeFrameConfigKey, |
| 679 KEY_QUERY_VALUE)) { | 681 KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
| 680 int value = FALSE; | 682 config_key.ReadValueDW(value_name, reinterpret_cast<DWORD*>(&ret)); |
| 681 if (config_key.ReadValueDW(value_name, reinterpret_cast<DWORD*>(&value))) { | |
| 682 ret = value; | |
| 683 } | |
| 684 } | 683 } |
| 685 | 684 |
| 686 return ret; | 685 return ret; |
| 687 } | 686 } |
| 688 | 687 |
| 689 bool GetConfigBool(bool default_value, const wchar_t* value_name) { | 688 bool GetConfigBool(bool default_value, const wchar_t* value_name) { |
| 690 DWORD value = GetConfigInt(default_value, value_name); | 689 DWORD value = GetConfigInt(default_value, value_name); |
| 691 return (value != FALSE); | 690 return (value != FALSE); |
| 692 } | 691 } |
| 693 | 692 |
| 694 bool SetConfigInt(const wchar_t* value_name, int value) { | 693 bool SetConfigInt(const wchar_t* value_name, int value) { |
| 695 RegKey config_key; | 694 RegKey config_key; |
| 696 if (config_key.Create(HKEY_CURRENT_USER, kChromeFrameConfigKey, | 695 if (config_key.Create(HKEY_CURRENT_USER, kChromeFrameConfigKey, |
| 697 KEY_SET_VALUE)) { | 696 KEY_SET_VALUE) == ERROR_SUCCESS) { |
| 698 if (config_key.WriteValue(value_name, value)) { | 697 if (config_key.WriteValue(value_name, value) == ERROR_SUCCESS) { |
| 699 return true; | 698 return true; |
| 700 } | 699 } |
| 701 } | 700 } |
| 702 | 701 |
| 703 return false; | 702 return false; |
| 704 } | 703 } |
| 705 | 704 |
| 706 bool SetConfigBool(const wchar_t* value_name, bool value) { | 705 bool SetConfigBool(const wchar_t* value_name, bool value) { |
| 707 return SetConfigInt(value_name, value); | 706 return SetConfigInt(value_name, value); |
| 708 } | 707 } |
| 709 | 708 |
| 710 bool DeleteConfigValue(const wchar_t* value_name) { | 709 bool DeleteConfigValue(const wchar_t* value_name) { |
| 711 RegKey config_key; | 710 RegKey config_key; |
| 712 if (config_key.Open(HKEY_CURRENT_USER, kChromeFrameConfigKey, | 711 if (config_key.Open(HKEY_CURRENT_USER, kChromeFrameConfigKey, |
| 713 KEY_WRITE)) { | 712 KEY_WRITE) == ERROR_SUCCESS) { |
| 714 return config_key.DeleteValue(value_name); | 713 if (config_key.DeleteValue(value_name) == ERROR_SUCCESS) { |
| 714 return true; | |
| 715 } | |
| 715 } | 716 } |
| 716 return false; | 717 return false; |
| 717 } | 718 } |
| 718 | 719 |
| 719 bool IsGcfDefaultRenderer() { | 720 bool IsGcfDefaultRenderer() { |
| 720 DWORD is_default = 0; // NOLINT | 721 DWORD is_default = 0; // NOLINT |
| 721 | 722 |
| 722 // First check policy settings | 723 // First check policy settings |
| 723 PolicySettings::RendererForUrl renderer = | 724 PolicySettings::RendererForUrl renderer = |
| 724 PolicySettings::GetInstance()->default_renderer(); | 725 PolicySettings::GetInstance()->default_renderer(); |
| 725 if (renderer != PolicySettings::RENDERER_NOT_SPECIFIED) { | 726 if (renderer != PolicySettings::RENDERER_NOT_SPECIFIED) { |
| 726 is_default = (renderer == PolicySettings::RENDER_IN_CHROME_FRAME); | 727 is_default = (renderer == PolicySettings::RENDER_IN_CHROME_FRAME); |
| 727 } else { | 728 } else { |
| 728 // TODO(tommi): Implement caching for this config value as it gets | 729 // TODO(tommi): Implement caching for this config value as it gets |
| 729 // checked frequently. | 730 // checked frequently. |
| 730 RegKey config_key; | 731 RegKey config_key; |
| 731 if (config_key.Open(HKEY_CURRENT_USER, kChromeFrameConfigKey, KEY_READ)) { | 732 if (config_key.Open(HKEY_CURRENT_USER, kChromeFrameConfigKey, |
| 733 KEY_READ) == ERROR_SUCCESS) { | |
| 732 config_key.ReadValueDW(kEnableGCFRendererByDefault, &is_default); | 734 config_key.ReadValueDW(kEnableGCFRendererByDefault, &is_default); |
| 733 } | 735 } |
| 734 } | 736 } |
| 735 | 737 |
| 736 return is_default != 0; | 738 return is_default != 0; |
| 737 } | 739 } |
| 738 | 740 |
| 739 RendererType RendererTypeForUrl(const std::wstring& url) { | 741 RendererType RendererTypeForUrl(const std::wstring& url) { |
| 740 // First check if the default renderer settings are specified by policy. | 742 // First check if the default renderer settings are specified by policy. |
| 741 // If so, then that overrides the user settings. | 743 // If so, then that overrides the user settings. |
| 742 PolicySettings::RendererForUrl renderer = | 744 PolicySettings::RendererForUrl renderer = |
| 743 PolicySettings::GetInstance()->GetRendererForUrl(url.c_str()); | 745 PolicySettings::GetInstance()->GetRendererForUrl(url.c_str()); |
| 744 if (renderer != PolicySettings::RENDERER_NOT_SPECIFIED) { | 746 if (renderer != PolicySettings::RENDERER_NOT_SPECIFIED) { |
| 745 // We may know at this point that policy says do NOT render in Chrome Frame. | 747 // We may know at this point that policy says do NOT render in Chrome Frame. |
| 746 // To maintain consistency, we return RENDERER_TYPE_UNDETERMINED so that | 748 // To maintain consistency, we return RENDERER_TYPE_UNDETERMINED so that |
| 747 // content sniffing, etc. still take place. | 749 // content sniffing, etc. still take place. |
| 748 // TODO(tommi): Clarify the intent here. | 750 // TODO(tommi): Clarify the intent here. |
| 749 return (renderer == PolicySettings::RENDER_IN_CHROME_FRAME) ? | 751 return (renderer == PolicySettings::RENDER_IN_CHROME_FRAME) ? |
| 750 RENDERER_TYPE_CHROME_OPT_IN_URL : RENDERER_TYPE_UNDETERMINED; | 752 RENDERER_TYPE_CHROME_OPT_IN_URL : RENDERER_TYPE_UNDETERMINED; |
| 751 } | 753 } |
| 752 | 754 |
| 753 RegKey config_key; | 755 RegKey config_key; |
| 754 if (!config_key.Open(HKEY_CURRENT_USER, kChromeFrameConfigKey, KEY_READ)) | 756 if (config_key.Open(HKEY_CURRENT_USER, kChromeFrameConfigKey, |
| 757 KEY_READ) != ERROR_SUCCESS) | |
| 755 return RENDERER_TYPE_UNDETERMINED; | 758 return RENDERER_TYPE_UNDETERMINED; |
|
grt (UTC plus 2)
2011/01/16 04:19:48
Add braces around this line since the if spans mul
amit
2011/01/16 07:54:28
Done.
| |
| 756 | 759 |
| 757 RendererType renderer_type = RENDERER_TYPE_UNDETERMINED; | 760 RendererType renderer_type = RENDERER_TYPE_UNDETERMINED; |
| 758 | 761 |
| 759 const wchar_t* url_list_name = NULL; | 762 const wchar_t* url_list_name = NULL; |
| 760 int render_in_cf_by_default = FALSE; | 763 int render_in_cf_by_default = FALSE; |
| 761 config_key.ReadValueDW(kEnableGCFRendererByDefault, | 764 config_key.ReadValueDW(kEnableGCFRendererByDefault, |
| 762 reinterpret_cast<DWORD*>(&render_in_cf_by_default)); | 765 reinterpret_cast<DWORD*>(&render_in_cf_by_default)); |
| 763 if (render_in_cf_by_default) { | 766 if (render_in_cf_by_default) { |
| 764 url_list_name = kRenderInHostUrlList; | 767 url_list_name = kRenderInHostUrlList; |
| 765 renderer_type = RENDERER_TYPE_CHROME_DEFAULT_RENDERER; | 768 renderer_type = RENDERER_TYPE_CHROME_DEFAULT_RENDERER; |
| (...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1573 ++url_list; | 1576 ++url_list; |
| 1574 } | 1577 } |
| 1575 } | 1578 } |
| 1576 | 1579 |
| 1577 std::wstring GetCurrentModuleVersion() { | 1580 std::wstring GetCurrentModuleVersion() { |
| 1578 scoped_ptr<FileVersionInfo> module_version_info( | 1581 scoped_ptr<FileVersionInfo> module_version_info( |
| 1579 FileVersionInfo::CreateFileVersionInfoForCurrentModule()); | 1582 FileVersionInfo::CreateFileVersionInfoForCurrentModule()); |
| 1580 DCHECK(module_version_info.get() != NULL); | 1583 DCHECK(module_version_info.get() != NULL); |
| 1581 return module_version_info->file_version(); | 1584 return module_version_info->file_version(); |
| 1582 } | 1585 } |
| OLD | NEW |