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 #include "chrome_frame/utils.h" | 5 #include "chrome_frame/utils.h" |
| 6 | 6 |
| 7 #include <atlsafe.h> | 7 #include <atlsafe.h> |
| 8 #include <atlsecurity.h> | 8 #include <atlsecurity.h> |
| 9 #include <htiframe.h> | 9 #include <htiframe.h> |
| 10 #include <mshtml.h> | 10 #include <mshtml.h> |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 #include "base/win/scoped_variant.h" | 28 #include "base/win/scoped_variant.h" |
| 29 #include "chrome/common/automation_messages.h" | 29 #include "chrome/common/automation_messages.h" |
| 30 #include "chrome/common/chrome_paths_internal.h" | 30 #include "chrome/common/chrome_paths_internal.h" |
| 31 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
| 32 #include "chrome/installer/util/chrome_frame_distribution.h" | 32 #include "chrome/installer/util/chrome_frame_distribution.h" |
| 33 #include "chrome_frame/chrome_tab.h" | 33 #include "chrome_frame/chrome_tab.h" |
| 34 #include "chrome_frame/extra_system_apis.h" | 34 #include "chrome_frame/extra_system_apis.h" |
| 35 #include "chrome_frame/html_utils.h" | 35 #include "chrome_frame/html_utils.h" |
| 36 #include "chrome_frame/navigation_constraints.h" | 36 #include "chrome_frame/navigation_constraints.h" |
| 37 #include "chrome_frame/policy_settings.h" | 37 #include "chrome_frame/policy_settings.h" |
| 38 #include "chrome_frame/registry_list_preferences_holder.h" | |
| 38 #include "chrome_frame/simple_resource_loader.h" | 39 #include "chrome_frame/simple_resource_loader.h" |
| 39 #include "googleurl/src/gurl.h" | 40 #include "googleurl/src/gurl.h" |
| 40 #include "googleurl/src/url_canon.h" | 41 #include "googleurl/src/url_canon.h" |
| 41 #include "grit/chromium_strings.h" | 42 #include "grit/chromium_strings.h" |
| 42 #include "net/base/escape.h" | 43 #include "net/base/escape.h" |
| 43 #include "net/http/http_util.h" | 44 #include "net/http/http_util.h" |
| 44 #include "ui/base/models/menu_model.h" | 45 #include "ui/base/models/menu_model.h" |
| 45 | 46 |
| 46 using base::win::RegKey; | 47 using base::win::RegKey; |
| 47 | 48 |
| 48 // Note that these values are all lower case and are compared to | 49 // Note that these values are all lower case and are compared to |
|
grt (UTC plus 2)
2012/03/20 17:27:45
from the "no good deed goes unpunished" department
robertshield
2012/03/26 02:43:33
Reordered and updated the comment.
| |
| 49 // lower-case-transformed values. | 50 // lower-case-transformed values. |
| 51 const char kGCFProtocol[] = "gcf"; | |
| 52 | |
| 53 const wchar_t kAllowUnsafeURLs[] = L"AllowUnsafeURLs"; | |
| 54 const wchar_t kBodyTag[] = L"body"; | |
| 55 const wchar_t kChromeFrameConfigKey[] = L"Software\\Google\\ChromeFrame"; | |
| 56 const wchar_t kContentAttribName[] = L"content"; | |
| 57 const wchar_t kChromeContentPrefix[] = L"chrome="; | |
| 58 const wchar_t kChromeMimeType[] = L"application/chromepage"; | |
| 59 const wchar_t kChromeProtocolPrefix[] = L"gcf:"; | |
| 60 const wchar_t kEnableBuggyBhoIntercept[] = L"EnableBuggyBhoIntercept"; | |
| 61 const wchar_t kEnableGCFRendererByDefault[] = L"IsDefaultRenderer"; | |
| 62 const wchar_t kExcludeUAFromDomainList[] = L"ExcludeUAFromDomain"; | |
| 63 const wchar_t kHttpEquivAttribName[] = L"http-equiv"; | |
| 64 const wchar_t kIexploreProfileName[] = L"iexplore"; | |
| 50 const wchar_t kMetaTag[] = L"meta"; | 65 const wchar_t kMetaTag[] = L"meta"; |
| 51 const wchar_t kHttpEquivAttribName[] = L"http-equiv"; | |
| 52 const wchar_t kContentAttribName[] = L"content"; | |
| 53 const wchar_t kXUACompatValue[] = L"x-ua-compatible"; | |
| 54 const wchar_t kBodyTag[] = L"body"; | |
| 55 const wchar_t kChromeContentPrefix[] = L"chrome="; | |
| 56 const char kGCFProtocol[] = "gcf"; | |
| 57 const wchar_t kChromeProtocolPrefix[] = L"gcf:"; | |
| 58 const wchar_t kChromeMimeType[] = L"application/chromepage"; | |
| 59 const wchar_t kPatchProtocols[] = L"PatchProtocols"; | 66 const wchar_t kPatchProtocols[] = L"PatchProtocols"; |
| 60 const wchar_t kChromeFrameConfigKey[] = L"Software\\Google\\ChromeFrame"; | |
| 61 const wchar_t kRenderInGCFUrlList[] = L"RenderInGcfUrls"; | 67 const wchar_t kRenderInGCFUrlList[] = L"RenderInGcfUrls"; |
| 62 const wchar_t kRenderInHostUrlList[] = L"RenderInHostUrls"; | 68 const wchar_t kRenderInHostUrlList[] = L"RenderInHostUrls"; |
| 63 const wchar_t kEnableGCFRendererByDefault[] = L"IsDefaultRenderer"; | |
| 64 const wchar_t kIexploreProfileName[] = L"iexplore"; | |
| 65 const wchar_t kRundllProfileName[] = L"rundll32"; | 69 const wchar_t kRundllProfileName[] = L"rundll32"; |
| 66 | 70 const wchar_t kXUACompatValue[] = L"x-ua-compatible"; |
| 67 const wchar_t kAllowUnsafeURLs[] = L"AllowUnsafeURLs"; | |
| 68 const wchar_t kEnableBuggyBhoIntercept[] = L"EnableBuggyBhoIntercept"; | |
| 69 | 71 |
| 70 static const wchar_t kChromeFramePersistNPAPIReg[] = L"PersistNPAPIReg"; | 72 static const wchar_t kChromeFramePersistNPAPIReg[] = L"PersistNPAPIReg"; |
| 71 | 73 |
| 72 const char kAttachExternalTabPrefix[] = "attach_external_tab"; | 74 const char kAttachExternalTabPrefix[] = "attach_external_tab"; |
| 73 | 75 |
| 74 // Indicates that we are running in a test environment, where execptions, etc | 76 // Indicates that we are running in a test environment, where execptions, etc |
| 75 // are handled by the chrome test crash server. | 77 // are handled by the chrome test crash server. |
| 76 const wchar_t kChromeFrameHeadlessMode[] = L"ChromeFrameHeadlessMode"; | 78 const wchar_t kChromeFrameHeadlessMode[] = L"ChromeFrameHeadlessMode"; |
| 77 | 79 |
| 78 // Indicates that we are running in an environment that expects chrome renderer | 80 // Indicates that we are running in an environment that expects chrome renderer |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 } | 169 } |
| 168 | 170 |
| 169 HRESULT UtilRegisterTypeLib(ITypeLib* typelib, | 171 HRESULT UtilRegisterTypeLib(ITypeLib* typelib, |
| 170 LPCWSTR typelib_path, | 172 LPCWSTR typelib_path, |
| 171 LPCWSTR help_dir, | 173 LPCWSTR help_dir, |
| 172 bool for_current_user_only) { | 174 bool for_current_user_only) { |
| 173 typedef HRESULT(WINAPI *RegisterTypeLibPrototype)(ITypeLib FAR* type_lib, | 175 typedef HRESULT(WINAPI *RegisterTypeLibPrototype)(ITypeLib FAR* type_lib, |
| 174 OLECHAR FAR* full_path, | 176 OLECHAR FAR* full_path, |
| 175 OLECHAR FAR* help_dir); | 177 OLECHAR FAR* help_dir); |
| 176 LPCSTR function_name = | 178 LPCSTR function_name = |
| 177 for_current_user_only ? "RegisterTypeLibForUser" : "RegisterTypeLib"; | 179 for_current_user_only ? "RegisterTypeLibForUser" : "RegisterTypeLib"; |
| 178 RegisterTypeLibPrototype reg_tlb = | 180 RegisterTypeLibPrototype reg_tlb = |
| 179 reinterpret_cast<RegisterTypeLibPrototype>( | 181 reinterpret_cast<RegisterTypeLibPrototype>( |
| 180 GetProcAddress(GetModuleHandle(_T("oleaut32.dll")), | 182 GetProcAddress(GetModuleHandle(_T("oleaut32.dll")), |
| 181 function_name)); | 183 function_name)); |
| 182 if (NULL == reg_tlb) { | 184 if (NULL == reg_tlb) { |
| 183 return E_FAIL; | 185 return E_FAIL; |
| 184 } | 186 } |
| 185 return reg_tlb(typelib, | 187 return reg_tlb(typelib, |
| 186 const_cast<OLECHAR*>(typelib_path), | 188 const_cast<OLECHAR*>(typelib_path), |
| 187 const_cast<OLECHAR*>(help_dir)); | 189 const_cast<OLECHAR*>(help_dir)); |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 PolicySettings::GetInstance()->GetRendererForUrl(url.c_str()); | 711 PolicySettings::GetInstance()->GetRendererForUrl(url.c_str()); |
| 710 if (renderer != PolicySettings::RENDERER_NOT_SPECIFIED) { | 712 if (renderer != PolicySettings::RENDERER_NOT_SPECIFIED) { |
| 711 // We may know at this point that policy says do NOT render in Chrome Frame. | 713 // We may know at this point that policy says do NOT render in Chrome Frame. |
| 712 // To maintain consistency, we return RENDERER_TYPE_UNDETERMINED so that | 714 // To maintain consistency, we return RENDERER_TYPE_UNDETERMINED so that |
| 713 // content sniffing, etc. still take place. | 715 // content sniffing, etc. still take place. |
| 714 // TODO(tommi): Clarify the intent here. | 716 // TODO(tommi): Clarify the intent here. |
| 715 return (renderer == PolicySettings::RENDER_IN_CHROME_FRAME) ? | 717 return (renderer == PolicySettings::RENDER_IN_CHROME_FRAME) ? |
| 716 RENDERER_TYPE_CHROME_OPT_IN_URL : RENDERER_TYPE_UNDETERMINED; | 718 RENDERER_TYPE_CHROME_OPT_IN_URL : RENDERER_TYPE_UNDETERMINED; |
| 717 } | 719 } |
| 718 | 720 |
| 719 RegKey config_key; | 721 static int render_in_cf_by_default = FALSE; |
| 720 if (config_key.Open(HKEY_CURRENT_USER, kChromeFrameConfigKey, | 722 static RegistryListPreferencesHolder render_type_for_url_holder; |
|
grt (UTC plus 2)
2012/03/20 17:27:45
this introduces an exit-time call to a dtor. if l
robertshield
2012/03/26 02:43:33
Done.
| |
| 721 KEY_READ) != ERROR_SUCCESS) { | |
| 722 return RENDERER_TYPE_UNDETERMINED; | |
| 723 } | |
| 724 | 723 |
| 725 RendererType renderer_type = RENDERER_TYPE_UNDETERMINED; | 724 RendererType renderer_type = RENDERER_TYPE_UNDETERMINED; |
| 725 if (!render_type_for_url_holder.Valid()) { | |
|
grt (UTC plus 2)
2012/03/20 17:27:45
i think this is equivalent, but smaller:
if (!re
robertshield
2012/03/26 02:43:33
Done.
| |
| 726 RegKey config_key; | |
| 727 if (config_key.Open(HKEY_CURRENT_USER, kChromeFrameConfigKey, | |
| 728 KEY_READ) == ERROR_SUCCESS) { | |
| 729 config_key.ReadValueDW( | |
| 730 kEnableGCFRendererByDefault, | |
| 731 reinterpret_cast<DWORD*>(&render_in_cf_by_default)); | |
| 726 | 732 |
| 727 const wchar_t* url_list_name = NULL; | 733 const wchar_t* url_list_name = NULL; |
| 728 int render_in_cf_by_default = FALSE; | 734 if (render_in_cf_by_default) { |
| 729 config_key.ReadValueDW(kEnableGCFRendererByDefault, | 735 url_list_name = kRenderInHostUrlList; |
| 730 reinterpret_cast<DWORD*>(&render_in_cf_by_default)); | 736 renderer_type = RENDERER_TYPE_CHROME_DEFAULT_RENDERER; |
| 731 if (render_in_cf_by_default) { | 737 } else { |
| 732 url_list_name = kRenderInHostUrlList; | 738 url_list_name = kRenderInGCFUrlList; |
| 733 renderer_type = RENDERER_TYPE_CHROME_DEFAULT_RENDERER; | 739 } |
| 734 } else { | |
| 735 url_list_name = kRenderInGCFUrlList; | |
| 736 } | |
| 737 | 740 |
| 738 bool match_found = false; | 741 render_type_for_url_holder.Init(HKEY_CURRENT_USER, |
| 739 base::win::RegistryValueIterator url_list(config_key.Handle(), url_list_name); | 742 kChromeFrameConfigKey, |
| 740 while (!match_found && url_list.Valid()) { | 743 url_list_name); |
| 741 if (MatchPattern(url, url_list.Name())) { | |
| 742 match_found = true; | |
| 743 } else { | |
| 744 ++url_list; | |
| 745 } | 744 } |
| 746 } | 745 } |
| 747 | 746 |
| 748 if (match_found) { | 747 if (render_type_for_url_holder.ListMatches(url)) { |
| 749 renderer_type = render_in_cf_by_default ? | 748 renderer_type = render_in_cf_by_default ? |
| 750 RENDERER_TYPE_UNDETERMINED : | 749 RENDERER_TYPE_UNDETERMINED : |
| 751 RENDERER_TYPE_CHROME_OPT_IN_URL; | 750 RENDERER_TYPE_CHROME_OPT_IN_URL; |
| 752 } | 751 } |
| 753 | 752 |
| 754 return renderer_type; | 753 return renderer_type; |
| 755 } | 754 } |
| 756 | 755 |
| 756 UserAgentAction ShouldRemoveUAForUrl(const string16& url) { | |
| 757 // TODO(robertshield): Wire up the stuff in PolicySettings here so the value | |
| 758 // can be specified via group policy. | |
| 759 static RegistryListPreferencesHolder user_agent_filter_holder; | |
|
grt (UTC plus 2)
2012/03/20 17:27:45
see note above about static dtors and threadsafety
robertshield
2012/03/26 02:43:33
Done.
| |
| 760 if (!user_agent_filter_holder.Valid()) { | |
| 761 user_agent_filter_holder.Init(HKEY_CURRENT_USER, | |
| 762 kChromeFrameConfigKey, | |
| 763 kExcludeUAFromDomainList); | |
|
slightlyoff1
2012/03/20 15:31:56
My biggest concern here is that we'll provide some
robertshield
2012/03/26 02:43:33
That sounds reasonable, but I'd like to tackle tha
| |
| 764 } | |
| 765 | |
| 766 if (user_agent_filter_holder.ListMatches(url)) { | |
|
grt (UTC plus 2)
2012/03/20 17:27:45
nit: remove braces
robertshield
2012/03/26 02:43:33
Done.
| |
| 767 return USER_AGENT_REMOVE; | |
| 768 } | |
| 769 return USER_AGENT_DEFAULT; | |
| 770 } | |
| 771 | |
| 757 HRESULT NavigateBrowserToMoniker(IUnknown* browser, IMoniker* moniker, | 772 HRESULT NavigateBrowserToMoniker(IUnknown* browser, IMoniker* moniker, |
| 758 const wchar_t* headers, IBindCtx* bind_ctx, | 773 const wchar_t* headers, IBindCtx* bind_ctx, |
| 759 const wchar_t* fragment, IStream* post_data, | 774 const wchar_t* fragment, IStream* post_data, |
| 760 VARIANT* flags) { | 775 VARIANT* flags) { |
| 761 DCHECK(browser); | 776 DCHECK(browser); |
| 762 DCHECK(moniker); | 777 DCHECK(moniker); |
| 763 DCHECK(bind_ctx); | 778 DCHECK(bind_ctx); |
| 764 | 779 |
| 765 base::win::ScopedComPtr<IWebBrowser2> web_browser2; | 780 base::win::ScopedComPtr<IWebBrowser2> web_browser2; |
| 766 HRESULT hr = DoQueryService(SID_SWebBrowserApp, browser, | 781 HRESULT hr = DoQueryService(SID_SWebBrowserApp, browser, |
| (...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1632 | 1647 |
| 1633 ret = InternetSetOption(NULL, connection_options[option_index], | 1648 ret = InternetSetOption(NULL, connection_options[option_index], |
| 1634 &connections, connection_value_size); | 1649 &connections, connection_value_size); |
| 1635 if (!ret) { | 1650 if (!ret) { |
| 1636 return false; | 1651 return false; |
| 1637 } | 1652 } |
| 1638 } | 1653 } |
| 1639 wininet_connection_count_updated = true; | 1654 wininet_connection_count_updated = true; |
| 1640 return true; | 1655 return true; |
| 1641 } | 1656 } |
| OLD | NEW |