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 // chrome_tab.cc : Implementation of DLL Exports. | 5 // chrome_tab.cc : Implementation of DLL Exports. |
6 | 6 |
7 // Need to include this before the ATL headers below. | 7 // Need to include this before the ATL headers below. |
8 #include "chrome_frame/chrome_tab.h" | 8 #include "chrome_frame/chrome_tab.h" |
9 | 9 |
10 #include <atlsecurity.h> | 10 #include <atlsecurity.h> |
11 #include <objbase.h> | 11 #include <objbase.h> |
12 | 12 |
13 #include "base/at_exit.h" | 13 #include "base/at_exit.h" |
14 #include "base/basictypes.h" | |
14 #include "base/command_line.h" | 15 #include "base/command_line.h" |
15 #include "base/file_util.h" | 16 #include "base/file_util.h" |
16 #include "base/file_version_info.h" | 17 #include "base/file_version_info.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/metrics/field_trial.h" | 20 #include "base/metrics/field_trial.h" |
20 #include "base/path_service.h" | 21 #include "base/path_service.h" |
21 #include "base/string16.h" | 22 #include "base/string16.h" |
22 #include "base/string_number_conversions.h" | 23 #include "base/string_number_conversions.h" |
23 #include "base/string_piece.h" | 24 #include "base/string_piece.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
41 #include "chrome_frame/exception_barrier.h" | 42 #include "chrome_frame/exception_barrier.h" |
42 #include "chrome_frame/metrics_service.h" | 43 #include "chrome_frame/metrics_service.h" |
43 #include "chrome_frame/resource.h" | 44 #include "chrome_frame/resource.h" |
44 #include "chrome_frame/utils.h" | 45 #include "chrome_frame/utils.h" |
45 #include "googleurl/src/url_util.h" | 46 #include "googleurl/src/url_util.h" |
46 #include "grit/chrome_frame_resources.h" | 47 #include "grit/chrome_frame_resources.h" |
47 | 48 |
48 using base::win::RegKey; | 49 using base::win::RegKey; |
49 | 50 |
50 namespace { | 51 namespace { |
51 // This function has the side effect of initializing an unprotected | |
52 // vector pointer inside GoogleUrl. If this is called during DLL loading, | |
53 // it has the effect of avoiding an initialization race on that pointer. | |
54 // TODO(siggi): fix GoogleUrl. | |
55 void InitGoogleUrl() { | |
56 static const char kDummyUrl[] = "http://www.google.com"; | |
57 | |
58 url_util::IsStandard(kDummyUrl, | |
59 url_parse::MakeRange(0, arraysize(kDummyUrl))); | |
60 } | |
61 | 52 |
62 const wchar_t kInternetSettings[] = | 53 const wchar_t kInternetSettings[] = |
63 L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"; | 54 L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"; |
64 | 55 |
65 const wchar_t kProtocolHandlers[] = | 56 const wchar_t kProtocolHandlers[] = |
66 L"Software\\Classes\\Protocols\\Handler"; | 57 L"Software\\Classes\\Protocols\\Handler"; |
67 | 58 |
68 const wchar_t kRunOnce[] = | 59 const wchar_t kRunOnce[] = |
69 L"Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce"; | 60 L"Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce"; |
70 | 61 |
71 const wchar_t kRunKeyName[] = L"ChromeFrameHelper"; | 62 const wchar_t kRunKeyName[] = L"ChromeFrameHelper"; |
72 | 63 |
73 const wchar_t kChromeFrameHelperExe[] = L"chrome_frame_helper.exe"; | 64 const wchar_t kChromeFrameHelperExe[] = L"chrome_frame_helper.exe"; |
74 const wchar_t kChromeFrameHelperStartupArg[] = L"--startup"; | 65 const wchar_t kChromeFrameHelperStartupArg[] = L"--startup"; |
75 | 66 |
76 // Window class and window names. | 67 // Window class and window names. |
77 // TODO(robertshield): These and other constants need to be refactored into | 68 // TODO(robertshield): These and other constants need to be refactored into |
78 // a common chrome_frame_constants.h|cc and built into a separate lib | 69 // a common chrome_frame_constants.h|cc and built into a separate lib |
79 // (either chrome_frame_utils or make another one). | 70 // (either chrome_frame_utils or make another one). |
80 const wchar_t kChromeFrameHelperWindowClassName[] = | 71 const wchar_t kChromeFrameHelperWindowClassName[] = |
81 L"ChromeFrameHelperWindowClass"; | 72 L"ChromeFrameHelperWindowClass"; |
82 const wchar_t kChromeFrameHelperWindowName[] = | 73 const wchar_t kChromeFrameHelperWindowName[] = |
83 L"ChromeFrameHelperWindowName"; | 74 L"ChromeFrameHelperWindowName"; |
84 | 75 |
85 // {0562BFC3-2550-45b4-BD8E-A310583D3A6F} | 76 // {0562BFC3-2550-45b4-BD8E-A310583D3A6F} |
86 static const GUID kChromeFrameProvider = | 77 const GUID kChromeFrameProvider = |
87 { 0x562bfc3, 0x2550, 0x45b4, | 78 { 0x562bfc3, 0x2550, 0x45b4, |
88 { 0xbd, 0x8e, 0xa3, 0x10, 0x58, 0x3d, 0x3a, 0x6f } }; | 79 { 0xbd, 0x8e, 0xa3, 0x10, 0x58, 0x3d, 0x3a, 0x6f } }; |
89 | 80 |
90 const wchar_t kPostPlatformUAKey[] = | 81 const wchar_t kPostPlatformUAKey[] = |
91 L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\" | 82 L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\" |
92 L"User Agent\\Post Platform"; | 83 L"User Agent\\Post Platform"; |
93 const wchar_t kChromeFramePrefix[] = L"chromeframe/"; | 84 const wchar_t kChromeFramePrefix[] = L"chromeframe/"; |
94 | 85 |
95 // See comments in DllGetClassObject. | 86 // See comments in DllGetClassObject. |
96 LPFNGETCLASSOBJECT g_dll_get_class_object_redir_ptr = NULL; | 87 LPFNGETCLASSOBJECT g_dll_get_class_object_redir_ptr = NULL; |
97 | 88 |
89 // This function has the side effect of initializing an unprotected | |
90 // vector pointer inside GoogleUrl. If this is called during DLL loading, | |
91 // it has the effect of avoiding an initialization race on that pointer. | |
92 // TODO(siggi): fix GoogleUrl. | |
93 void InitGoogleUrl() { | |
94 static const char kDummyUrl[] = "http://www.google.com"; | |
95 | |
96 url_util::IsStandard(kDummyUrl, | |
97 url_parse::MakeRange(0, arraysize(kDummyUrl))); | |
98 } | |
99 | |
98 class ChromeTabModule : public CAtlDllModuleT<ChromeTabModule> { | 100 class ChromeTabModule : public CAtlDllModuleT<ChromeTabModule> { |
99 public: | 101 public: |
100 typedef CAtlDllModuleT<ChromeTabModule> ParentClass; | 102 typedef CAtlDllModuleT<ChromeTabModule> ParentClass; |
101 | 103 |
102 ChromeTabModule() : do_system_registration_(true) {} | 104 ChromeTabModule() : do_system_registration_(true) {} |
103 | 105 |
104 DECLARE_LIBID(LIBID_ChromeTabLib) | 106 DECLARE_LIBID(LIBID_ChromeTabLib) |
105 DECLARE_REGISTRY_APPID_RESOURCEID(IDR_CHROMETAB, | 107 DECLARE_REGISTRY_APPID_RESOURCEID(IDR_CHROMETAB, |
106 "{FD9B1B31-F4D8-436A-8F4F-D3C2E36733D3}") | 108 "{FD9B1B31-F4D8-436A-8F4F-D3C2E36733D3}") |
107 | 109 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 if (SUCCEEDED(hr)) { | 184 if (SUCCEEDED(hr)) { |
183 // Add the Chrome Frame CLSID. | 185 // Add the Chrome Frame CLSID. |
184 wchar_t cf_clsid[64]; | 186 wchar_t cf_clsid[64]; |
185 StringFromGUID2(CLSID_ChromeFrame, &cf_clsid[0], arraysize(cf_clsid)); | 187 StringFromGUID2(CLSID_ChromeFrame, &cf_clsid[0], arraysize(cf_clsid)); |
186 hr = registrar->AddReplacement(L"CHROME_FRAME_CLSID", &cf_clsid[0]); | 188 hr = registrar->AddReplacement(L"CHROME_FRAME_CLSID", &cf_clsid[0]); |
187 } | 189 } |
188 | 190 |
189 return hr; | 191 return hr; |
190 } | 192 } |
191 | 193 |
194 virtual LONG Unlock() throw() | |
195 { | |
robertshield
2013/03/12 03:16:49
nit: should the { not be on the previous line?
grt (UTC plus 2)
2013/03/12 14:45:51
Done.
| |
196 // Stop crash reporting if the module is fully unlocked. Reporting is | |
197 // started in DllGetClassObject. | |
198 LONG result = ParentClass::Unlock(); | |
199 if (!result) | |
200 chrome_frame::ScopedCrashReporting().Decommit(); | |
201 return result; | |
202 } | |
203 | |
192 // See comments in AddCommonRGSReplacements | 204 // See comments in AddCommonRGSReplacements |
193 bool do_system_registration_; | 205 bool do_system_registration_; |
194 }; | 206 }; |
195 | 207 |
196 ChromeTabModule _AtlModule; | 208 ChromeTabModule _AtlModule; |
197 | 209 |
198 base::AtExitManager* g_exit_manager = NULL; | 210 base::AtExitManager* g_exit_manager = NULL; |
199 base::FieldTrialList* g_field_trial_list = NULL; | 211 base::FieldTrialList* g_field_trial_list = NULL; |
200 | 212 |
201 HRESULT RefreshElevationPolicy() { | 213 HRESULT RefreshElevationPolicy() { |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
822 if (reason == DLL_PROCESS_ATTACH) { | 834 if (reason == DLL_PROCESS_ATTACH) { |
823 #ifndef NDEBUG | 835 #ifndef NDEBUG |
824 // Silence traces from the ATL registrar to reduce the log noise. | 836 // Silence traces from the ATL registrar to reduce the log noise. |
825 ATL::CTrace::s_trace.ChangeCategory(atlTraceRegistrar, 0, | 837 ATL::CTrace::s_trace.ChangeCategory(atlTraceRegistrar, 0, |
826 ATLTRACESTATUS_DISABLED); | 838 ATLTRACESTATUS_DISABLED); |
827 #endif | 839 #endif |
828 InitGoogleUrl(); | 840 InitGoogleUrl(); |
829 | 841 |
830 g_exit_manager = new base::AtExitManager(); | 842 g_exit_manager = new base::AtExitManager(); |
831 CommandLine::Init(0, NULL); | 843 CommandLine::Init(0, NULL); |
832 InitializeCrashReporting(); | |
833 logging::InitLogging( | 844 logging::InitLogging( |
834 NULL, | 845 NULL, |
835 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, | 846 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, |
836 logging::LOCK_LOG_FILE, | 847 logging::LOCK_LOG_FILE, |
837 logging::DELETE_OLD_LOG_FILE, | 848 logging::DELETE_OLD_LOG_FILE, |
838 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); | 849 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); |
839 | 850 |
840 // Log the same items as Chrome. | 851 // Log the same items as Chrome. |
841 logging::SetLogItems(true, // enable_process_id | 852 logging::SetLogItems(true, // enable_process_id |
842 true, // enable_thread_id | 853 true, // enable_thread_id |
(...skipping 24 matching lines...) Expand all Loading... | |
867 g_field_trial_list = NULL; | 878 g_field_trial_list = NULL; |
868 | 879 |
869 DllRedirector* dll_redirector = DllRedirector::GetInstance(); | 880 DllRedirector* dll_redirector = DllRedirector::GetInstance(); |
870 DCHECK(dll_redirector); | 881 DCHECK(dll_redirector); |
871 dll_redirector->UnregisterAsFirstCFModule(); | 882 dll_redirector->UnregisterAsFirstCFModule(); |
872 | 883 |
873 g_patch_helper.UnpatchIfNeeded(); | 884 g_patch_helper.UnpatchIfNeeded(); |
874 | 885 |
875 delete g_exit_manager; | 886 delete g_exit_manager; |
876 g_exit_manager = NULL; | 887 g_exit_manager = NULL; |
877 | |
878 ShutdownCrashReporting(); | |
879 } | 888 } |
880 return _AtlModule.DllMain(reason, reserved); | 889 return _AtlModule.DllMain(reason, reserved); |
881 } | 890 } |
882 | 891 |
883 // Used to determine whether the DLL can be unloaded by OLE | 892 // Used to determine whether the DLL can be unloaded by OLE |
884 STDAPI DllCanUnloadNow() { | 893 STDAPI DllCanUnloadNow() { |
885 return _AtlModule.DllCanUnloadNow(); | 894 return _AtlModule.DllCanUnloadNow(); |
886 } | 895 } |
887 | 896 |
888 // Returns a class factory to create an object of the requested type | 897 // Returns a class factory to create an object of the requested type |
889 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) { | 898 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) { |
899 chrome_frame::ScopedCrashReporting crash_reporting; | |
900 | |
890 // If we found another module present when we were loaded, then delegate to | 901 // If we found another module present when we were loaded, then delegate to |
891 // that: | 902 // that: |
892 if (g_dll_get_class_object_redir_ptr) { | 903 if (g_dll_get_class_object_redir_ptr) { |
893 return g_dll_get_class_object_redir_ptr(rclsid, riid, ppv); | 904 return g_dll_get_class_object_redir_ptr(rclsid, riid, ppv); |
894 } | 905 } |
895 | 906 |
896 // Enable sniffing and switching only if asked for BHO | 907 // Enable sniffing and switching only if asked for BHO |
897 // (we use BHO to get loaded in IE). | 908 // (we use BHO to get loaded in IE). |
898 if (rclsid == CLSID_ChromeFrameBHO) { | 909 if (rclsid == CLSID_ChromeFrameBHO) |
899 g_patch_helper.InitializeAndPatchProtocolsIfNeeded(); | 910 g_patch_helper.InitializeAndPatchProtocolsIfNeeded(); |
900 } | |
901 | 911 |
902 return _AtlModule.DllGetClassObject(rclsid, riid, ppv); | 912 HRESULT hr = _AtlModule.DllGetClassObject(rclsid, riid, ppv); |
913 | |
914 // Keep crash reporting going if an instance is being returned. It will be | |
915 // stopped in ChromeTabModule::Unlock when the last object is destroyed. | |
916 if (SUCCEEDED(hr) && *ppv) | |
917 crash_reporting.Commit(); | |
918 | |
919 return hr; | |
903 } | 920 } |
904 | 921 |
905 // DllRegisterServer - Adds entries to the system registry | 922 // DllRegisterServer - Adds entries to the system registry |
906 STDAPI DllRegisterServer() { | 923 STDAPI DllRegisterServer() { |
924 chrome_frame::ScopedCrashReporting crash_reporting; | |
907 uint16 flags = ACTIVEX | ACTIVEDOC | TYPELIB | GCF_PROTOCOL | | 925 uint16 flags = ACTIVEX | ACTIVEDOC | TYPELIB | GCF_PROTOCOL | |
908 BHO_CLSID | BHO_REGISTRATION; | 926 BHO_CLSID | BHO_REGISTRATION; |
909 | 927 |
910 HRESULT hr = CustomRegistration(flags, true, true); | 928 HRESULT hr = CustomRegistration(flags, true, true); |
911 if (SUCCEEDED(hr)) { | 929 if (SUCCEEDED(hr)) { |
912 SetupRunOnce(); | 930 SetupRunOnce(); |
913 } | 931 } |
914 | 932 |
915 return hr; | 933 return hr; |
916 } | 934 } |
917 | 935 |
918 // DllUnregisterServer - Removes entries from the system registry | 936 // DllUnregisterServer - Removes entries from the system registry |
919 STDAPI DllUnregisterServer() { | 937 STDAPI DllUnregisterServer() { |
938 chrome_frame::ScopedCrashReporting crash_reporting; | |
920 HRESULT hr = CustomRegistration(ALL, false, true); | 939 HRESULT hr = CustomRegistration(ALL, false, true); |
921 return hr; | 940 return hr; |
922 } | 941 } |
923 | 942 |
924 // DllRegisterUserServer - Adds entries to the HKCU hive in the registry. | 943 // DllRegisterUserServer - Adds entries to the HKCU hive in the registry. |
925 STDAPI DllRegisterUserServer() { | 944 STDAPI DllRegisterUserServer() { |
945 chrome_frame::ScopedCrashReporting crash_reporting; | |
926 UINT flags = ACTIVEX | ACTIVEDOC | TYPELIB | GCF_PROTOCOL | | 946 UINT flags = ACTIVEX | ACTIVEDOC | TYPELIB | GCF_PROTOCOL | |
927 BHO_CLSID | BHO_REGISTRATION; | 947 BHO_CLSID | BHO_REGISTRATION; |
928 | 948 |
929 HRESULT hr = CustomRegistration(flags, TRUE, false); | 949 HRESULT hr = CustomRegistration(flags, TRUE, false); |
930 if (SUCCEEDED(hr)) { | 950 if (SUCCEEDED(hr)) { |
931 SetupRunOnce(); | 951 SetupRunOnce(); |
932 } | 952 } |
933 | 953 |
934 return hr; | 954 return hr; |
935 } | 955 } |
936 | 956 |
937 // DllUnregisterUserServer - Removes entries from the HKCU hive in the registry. | 957 // DllUnregisterUserServer - Removes entries from the HKCU hive in the registry. |
938 STDAPI DllUnregisterUserServer() { | 958 STDAPI DllUnregisterUserServer() { |
959 chrome_frame::ScopedCrashReporting crash_reporting; | |
939 HRESULT hr = CustomRegistration(ALL, FALSE, false); | 960 HRESULT hr = CustomRegistration(ALL, FALSE, false); |
940 return hr; | 961 return hr; |
941 } | 962 } |
942 | 963 |
943 // Object entries go here instead of with each object, so that we can move | 964 // Object entries go here instead of with each object, so that we can move |
944 // the objects to a lib. Also reduces magic. | 965 // the objects to a lib. Also reduces magic. |
945 OBJECT_ENTRY_AUTO(CLSID_ChromeFrameBHO, Bho) | 966 OBJECT_ENTRY_AUTO(CLSID_ChromeFrameBHO, Bho) |
946 OBJECT_ENTRY_AUTO(__uuidof(ChromeActiveDocument), ChromeActiveDocument) | 967 OBJECT_ENTRY_AUTO(__uuidof(ChromeActiveDocument), ChromeActiveDocument) |
947 OBJECT_ENTRY_AUTO(__uuidof(ChromeFrame), ChromeFrameActivex) | 968 OBJECT_ENTRY_AUTO(__uuidof(ChromeFrame), ChromeFrameActivex) |
948 OBJECT_ENTRY_AUTO(__uuidof(ChromeProtocol), ChromeProtocol) | 969 OBJECT_ENTRY_AUTO(__uuidof(ChromeProtocol), ChromeProtocol) |
OLD | NEW |