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 |
49 // lower-case-transformed values. | 50 // lower-case-transformed values. |
| 51 const char kGCFProtocol[] = "gcf"; |
| 52 const wchar_t kBodyTag[] = L"body"; |
| 53 const wchar_t kContentAttribName[] = L"content"; |
| 54 const wchar_t kChromeContentPrefix[] = L"chrome="; |
| 55 const wchar_t kChromeMimeType[] = L"application/chromepage"; |
| 56 const wchar_t kChromeProtocolPrefix[] = L"gcf:"; |
| 57 const wchar_t kHttpEquivAttribName[] = L"http-equiv"; |
| 58 const wchar_t kIexploreProfileName[] = L"iexplore"; |
50 const wchar_t kMetaTag[] = L"meta"; | 59 const wchar_t kMetaTag[] = L"meta"; |
51 const wchar_t kHttpEquivAttribName[] = L"http-equiv"; | 60 const wchar_t kRundllProfileName[] = L"rundll32"; |
52 const wchar_t kContentAttribName[] = L"content"; | |
53 const wchar_t kXUACompatValue[] = L"x-ua-compatible"; | 61 const wchar_t kXUACompatValue[] = L"x-ua-compatible"; |
54 const wchar_t kBodyTag[] = L"body"; | 62 |
55 const wchar_t kChromeContentPrefix[] = L"chrome="; | 63 // Registry key and value names related to Chrome Frame configuration options. |
56 const char kGCFProtocol[] = "gcf"; | 64 const wchar_t kAllowUnsafeURLs[] = L"AllowUnsafeURLs"; |
57 const wchar_t kChromeProtocolPrefix[] = L"gcf:"; | 65 const wchar_t kChromeFrameConfigKey[] = L"Software\\Google\\ChromeFrame"; |
58 const wchar_t kChromeMimeType[] = L"application/chromepage"; | 66 const wchar_t kEnableBuggyBhoIntercept[] = L"EnableBuggyBhoIntercept"; |
| 67 const wchar_t kEnableGCFRendererByDefault[] = L"IsDefaultRenderer"; |
| 68 const wchar_t kExcludeUAFromDomainList[] = L"ExcludeUAFromDomain"; |
59 const wchar_t kPatchProtocols[] = L"PatchProtocols"; | 69 const wchar_t kPatchProtocols[] = L"PatchProtocols"; |
60 const wchar_t kChromeFrameConfigKey[] = L"Software\\Google\\ChromeFrame"; | |
61 const wchar_t kRenderInGCFUrlList[] = L"RenderInGcfUrls"; | 70 const wchar_t kRenderInGCFUrlList[] = L"RenderInGcfUrls"; |
62 const wchar_t kRenderInHostUrlList[] = L"RenderInHostUrls"; | 71 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"; | |
66 | |
67 const wchar_t kAllowUnsafeURLs[] = L"AllowUnsafeURLs"; | |
68 const wchar_t kEnableBuggyBhoIntercept[] = L"EnableBuggyBhoIntercept"; | |
69 | 72 |
70 static const wchar_t kChromeFramePersistNPAPIReg[] = L"PersistNPAPIReg"; | 73 static const wchar_t kChromeFramePersistNPAPIReg[] = L"PersistNPAPIReg"; |
71 | 74 |
72 const char kAttachExternalTabPrefix[] = "attach_external_tab"; | 75 const char kAttachExternalTabPrefix[] = "attach_external_tab"; |
73 | 76 |
74 // Indicates that we are running in a test environment, where execptions, etc | 77 // Indicates that we are running in a test environment, where execptions, etc |
75 // are handled by the chrome test crash server. | 78 // are handled by the chrome test crash server. |
76 const wchar_t kChromeFrameHeadlessMode[] = L"ChromeFrameHeadlessMode"; | 79 const wchar_t kChromeFrameHeadlessMode[] = L"ChromeFrameHeadlessMode"; |
77 | 80 |
78 // Indicates that we are running in an environment that expects chrome renderer | 81 // Indicates that we are running in an environment that expects chrome renderer |
(...skipping 27 matching lines...) Expand all Loading... |
106 | 109 |
107 namespace { | 110 namespace { |
108 | 111 |
109 // A flag used to signal when an active browser instance on the current thread | 112 // A flag used to signal when an active browser instance on the current thread |
110 // is loading a Chrome Frame document. There's no reference stored with the | 113 // is loading a Chrome Frame document. There's no reference stored with the |
111 // pointer so it should not be dereferenced and used for comparison against a | 114 // pointer so it should not be dereferenced and used for comparison against a |
112 // living instance only. | 115 // living instance only. |
113 base::LazyInstance<base::ThreadLocalPointer<IBrowserService> > | 116 base::LazyInstance<base::ThreadLocalPointer<IBrowserService> > |
114 g_tls_browser_for_cf_navigation = LAZY_INSTANCE_INITIALIZER; | 117 g_tls_browser_for_cf_navigation = LAZY_INSTANCE_INITIALIZER; |
115 | 118 |
| 119 // Holds the cached preferences for the per-url render type settings. |
| 120 base::LazyInstance<RegistryListPreferencesHolder>::Leaky |
| 121 g_render_type_for_url_holder; |
| 122 |
| 123 // Holds the cached preferences for the per-url user agent filter. |
| 124 base::LazyInstance<RegistryListPreferencesHolder>::Leaky |
| 125 g_user_agent_filter_holder; |
| 126 |
116 } // end anonymous namespace | 127 } // end anonymous namespace |
117 | 128 |
118 HRESULT UtilRegisterTypeLib(HINSTANCE tlb_instance, | 129 HRESULT UtilRegisterTypeLib(HINSTANCE tlb_instance, |
119 LPCOLESTR index, | 130 LPCOLESTR index, |
120 bool for_current_user_only) { | 131 bool for_current_user_only) { |
121 CComBSTR path; | 132 CComBSTR path; |
122 CComPtr<ITypeLib> type_lib; | 133 CComPtr<ITypeLib> type_lib; |
123 HRESULT hr = AtlLoadTypeLib(tlb_instance, index, &path, &type_lib); | 134 HRESULT hr = AtlLoadTypeLib(tlb_instance, index, &path, &type_lib); |
124 if (SUCCEEDED(hr)) { | 135 if (SUCCEEDED(hr)) { |
125 hr = UtilRegisterTypeLib(type_lib, path, NULL, for_current_user_only); | 136 hr = UtilRegisterTypeLib(type_lib, path, NULL, for_current_user_only); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 } | 178 } |
168 | 179 |
169 HRESULT UtilRegisterTypeLib(ITypeLib* typelib, | 180 HRESULT UtilRegisterTypeLib(ITypeLib* typelib, |
170 LPCWSTR typelib_path, | 181 LPCWSTR typelib_path, |
171 LPCWSTR help_dir, | 182 LPCWSTR help_dir, |
172 bool for_current_user_only) { | 183 bool for_current_user_only) { |
173 typedef HRESULT(WINAPI *RegisterTypeLibPrototype)(ITypeLib FAR* type_lib, | 184 typedef HRESULT(WINAPI *RegisterTypeLibPrototype)(ITypeLib FAR* type_lib, |
174 OLECHAR FAR* full_path, | 185 OLECHAR FAR* full_path, |
175 OLECHAR FAR* help_dir); | 186 OLECHAR FAR* help_dir); |
176 LPCSTR function_name = | 187 LPCSTR function_name = |
177 for_current_user_only ? "RegisterTypeLibForUser" : "RegisterTypeLib"; | 188 for_current_user_only ? "RegisterTypeLibForUser" : "RegisterTypeLib"; |
178 RegisterTypeLibPrototype reg_tlb = | 189 RegisterTypeLibPrototype reg_tlb = |
179 reinterpret_cast<RegisterTypeLibPrototype>( | 190 reinterpret_cast<RegisterTypeLibPrototype>( |
180 GetProcAddress(GetModuleHandle(_T("oleaut32.dll")), | 191 GetProcAddress(GetModuleHandle(_T("oleaut32.dll")), |
181 function_name)); | 192 function_name)); |
182 if (NULL == reg_tlb) { | 193 if (NULL == reg_tlb) { |
183 return E_FAIL; | 194 return E_FAIL; |
184 } | 195 } |
185 return reg_tlb(typelib, | 196 return reg_tlb(typelib, |
186 const_cast<OLECHAR*>(typelib_path), | 197 const_cast<OLECHAR*>(typelib_path), |
187 const_cast<OLECHAR*>(help_dir)); | 198 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()); | 720 PolicySettings::GetInstance()->GetRendererForUrl(url.c_str()); |
710 if (renderer != PolicySettings::RENDERER_NOT_SPECIFIED) { | 721 if (renderer != PolicySettings::RENDERER_NOT_SPECIFIED) { |
711 // We may know at this point that policy says do NOT render in Chrome Frame. | 722 // 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 | 723 // To maintain consistency, we return RENDERER_TYPE_UNDETERMINED so that |
713 // content sniffing, etc. still take place. | 724 // content sniffing, etc. still take place. |
714 // TODO(tommi): Clarify the intent here. | 725 // TODO(tommi): Clarify the intent here. |
715 return (renderer == PolicySettings::RENDER_IN_CHROME_FRAME) ? | 726 return (renderer == PolicySettings::RENDER_IN_CHROME_FRAME) ? |
716 RENDERER_TYPE_CHROME_OPT_IN_URL : RENDERER_TYPE_UNDETERMINED; | 727 RENDERER_TYPE_CHROME_OPT_IN_URL : RENDERER_TYPE_UNDETERMINED; |
717 } | 728 } |
718 | 729 |
719 RegKey config_key; | 730 // TODO(robertshield): Move this into a holder-type class that listens |
720 if (config_key.Open(HKEY_CURRENT_USER, kChromeFrameConfigKey, | 731 // for reg change events as well. |
721 KEY_READ) != ERROR_SUCCESS) { | 732 static int render_in_cf_by_default = FALSE; |
722 return RENDERER_TYPE_UNDETERMINED; | 733 |
| 734 RegistryListPreferencesHolder& render_type_for_url_holder = |
| 735 g_render_type_for_url_holder.Get(); |
| 736 if (!render_type_for_url_holder.Valid()) { |
| 737 const wchar_t* url_list_name = kRenderInGCFUrlList; |
| 738 if (IsGcfDefaultRenderer()) { |
| 739 url_list_name = kRenderInHostUrlList; |
| 740 render_in_cf_by_default = TRUE; |
| 741 } else { |
| 742 render_in_cf_by_default = FALSE; |
| 743 } |
| 744 |
| 745 render_type_for_url_holder.Init(HKEY_CURRENT_USER, |
| 746 kChromeFrameConfigKey, |
| 747 url_list_name); |
723 } | 748 } |
| 749 DCHECK(render_type_for_url_holder.Valid()); |
724 | 750 |
725 RendererType renderer_type = RENDERER_TYPE_UNDETERMINED; | 751 RendererType renderer_type = |
| 752 render_in_cf_by_default ? RENDERER_TYPE_CHROME_DEFAULT_RENDERER : |
| 753 RENDERER_TYPE_UNDETERMINED; |
726 | 754 |
727 const wchar_t* url_list_name = NULL; | 755 if (render_type_for_url_holder.ListMatches(url)) { |
728 int render_in_cf_by_default = FALSE; | |
729 config_key.ReadValueDW(kEnableGCFRendererByDefault, | |
730 reinterpret_cast<DWORD*>(&render_in_cf_by_default)); | |
731 if (render_in_cf_by_default) { | |
732 url_list_name = kRenderInHostUrlList; | |
733 renderer_type = RENDERER_TYPE_CHROME_DEFAULT_RENDERER; | |
734 } else { | |
735 url_list_name = kRenderInGCFUrlList; | |
736 } | |
737 | |
738 bool match_found = false; | |
739 base::win::RegistryValueIterator url_list(config_key.Handle(), url_list_name); | |
740 while (!match_found && url_list.Valid()) { | |
741 if (MatchPattern(url, url_list.Name())) { | |
742 match_found = true; | |
743 } else { | |
744 ++url_list; | |
745 } | |
746 } | |
747 | |
748 if (match_found) { | |
749 renderer_type = render_in_cf_by_default ? | 756 renderer_type = render_in_cf_by_default ? |
750 RENDERER_TYPE_UNDETERMINED : | 757 RENDERER_TYPE_UNDETERMINED : |
751 RENDERER_TYPE_CHROME_OPT_IN_URL; | 758 RENDERER_TYPE_CHROME_OPT_IN_URL; |
752 } | 759 } |
753 | 760 |
754 return renderer_type; | 761 return renderer_type; |
755 } | 762 } |
756 | 763 |
| 764 bool ShouldRemoveUAForUrl(const string16& url) { |
| 765 // TODO(robertshield): Wire up the stuff in PolicySettings here so the value |
| 766 // can be specified via group policy. |
| 767 // TODO(robertshield): Add a default list of exclusions here for site with |
| 768 // known bad UA parsing. |
| 769 RegistryListPreferencesHolder& user_agent_filter_holder = |
| 770 g_user_agent_filter_holder.Get(); |
| 771 if (!user_agent_filter_holder.Valid()) { |
| 772 user_agent_filter_holder.Init(HKEY_CURRENT_USER, |
| 773 kChromeFrameConfigKey, |
| 774 kExcludeUAFromDomainList); |
| 775 } |
| 776 DCHECK(user_agent_filter_holder.Valid()); |
| 777 |
| 778 return user_agent_filter_holder.ListMatches(url); |
| 779 } |
| 780 |
| 781 RegistryListPreferencesHolder& GetRendererTypePreferencesHolderForTesting() { |
| 782 return g_render_type_for_url_holder.Get(); |
| 783 } |
| 784 |
| 785 RegistryListPreferencesHolder& GetUserAgentPreferencesHolderForTesting() { |
| 786 return g_user_agent_filter_holder.Get(); |
| 787 } |
| 788 |
757 HRESULT NavigateBrowserToMoniker(IUnknown* browser, IMoniker* moniker, | 789 HRESULT NavigateBrowserToMoniker(IUnknown* browser, IMoniker* moniker, |
758 const wchar_t* headers, IBindCtx* bind_ctx, | 790 const wchar_t* headers, IBindCtx* bind_ctx, |
759 const wchar_t* fragment, IStream* post_data, | 791 const wchar_t* fragment, IStream* post_data, |
760 VARIANT* flags) { | 792 VARIANT* flags) { |
761 DCHECK(browser); | 793 DCHECK(browser); |
762 DCHECK(moniker); | 794 DCHECK(moniker); |
763 DCHECK(bind_ctx); | 795 DCHECK(bind_ctx); |
764 | 796 |
765 base::win::ScopedComPtr<IWebBrowser2> web_browser2; | 797 base::win::ScopedComPtr<IWebBrowser2> web_browser2; |
766 HRESULT hr = DoQueryService(SID_SWebBrowserApp, browser, | 798 HRESULT hr = DoQueryService(SID_SWebBrowserApp, browser, |
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1632 | 1664 |
1633 ret = InternetSetOption(NULL, connection_options[option_index], | 1665 ret = InternetSetOption(NULL, connection_options[option_index], |
1634 &connections, connection_value_size); | 1666 &connections, connection_value_size); |
1635 if (!ret) { | 1667 if (!ret) { |
1636 return false; | 1668 return false; |
1637 } | 1669 } |
1638 } | 1670 } |
1639 wininet_connection_count_updated = true; | 1671 wininet_connection_count_updated = true; |
1640 return true; | 1672 return true; |
1641 } | 1673 } |
OLD | NEW |