Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: chrome_frame/chrome_tab.cc

Issue 218019: Initial import of the Chrome Frame codebase. Integration in chrome.gyp coming... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome_frame/chrome_protocol.rgs ('k') | chrome_frame/chrome_tab.def » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // chrome_tab.cc : Implementation of DLL Exports.
6 #include "base/at_exit.h"
7 #include "base/command_line.h"
8 #include "base/file_util.h"
9 #include "base/file_version_info.h"
10 #include "base/logging.h"
11 #include "base/path_service.h"
12 #include "base/registry.h"
13 #include "base/string_piece.h"
14 #include "base/string_util.h"
15 #include "base/sys_string_conversions.h"
16 #include "chrome/common/chrome_constants.h"
17 #include "grit/chrome_frame_resources.h"
18 #include "chrome_frame/bho.h"
19 #include "chrome_frame/chrome_frame_automation.h"
20 #include "chrome_frame/chrome_launcher.h"
21 #include "chrome_frame/crash_report.h"
22 #include "chrome_frame/resource.h"
23 #include "chrome_frame/utils.h"
24
25 // Include without path to make GYP build see it.
26 #include "chrome_tab.h" // NOLINT
27
28 static const wchar_t kBhoRegistryPath[] =
29 L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"
30 L"\\Browser Helper Objects";
31
32 const wchar_t kBhoNoLoadExplorerValue[] = L"NoExplorer";
33
34 class ChromeTabModule
35 : public AtlPerUserModule<CAtlDllModuleT<ChromeTabModule> > {
36 public:
37 typedef AtlPerUserModule<CAtlDllModuleT<ChromeTabModule> > ParentClass;
38
39 DECLARE_LIBID(LIBID_ChromeTabLib)
40 DECLARE_REGISTRY_APPID_RESOURCEID(IDR_CHROMETAB,
41 "{FD9B1B31-F4D8-436A-8F4F-D3C2E36733D3}")
42
43 // Override to add our SYSTIME binary value to registry scripts.
44 // See chrome_frame_activex.rgs for usage.
45 virtual HRESULT AddCommonRGSReplacements(IRegistrarBase* registrar) throw() {
46 HRESULT hr = ParentClass::AddCommonRGSReplacements(registrar);
47
48 if (SUCCEEDED(hr)) {
49 SYSTEMTIME local_time;
50 ::GetSystemTime(&local_time);
51 std::string hex(HexEncode(&local_time, sizeof(local_time)));
52 base::StringPiece sp_hex(hex);
53 hr = registrar->AddReplacement(L"SYSTIME",
54 base::SysNativeMBToWide(sp_hex).c_str());
55 DCHECK(SUCCEEDED(hr));
56 }
57
58 if (SUCCEEDED(hr)) {
59 std::wstring app_path(
60 chrome_launcher::GetChromeExecutablePath());
61 app_path = file_util::GetDirectoryFromPath(app_path);
62 hr = registrar->AddReplacement(L"CHROME_APPPATH", app_path.c_str());
63 DCHECK(SUCCEEDED(hr));
64 }
65
66 if (SUCCEEDED(hr)) {
67 hr = registrar->AddReplacement(L"CHROME_APPNAME",
68 chrome::kBrowserProcessExecutableName);
69 DCHECK(SUCCEEDED(hr));
70
71 // Fill in VERSION from the VERSIONINFO stored in the DLL's resources.
72 scoped_ptr<FileVersionInfo> module_version_info(
73 FileVersionInfo::CreateFileVersionInfoForCurrentModule());
74 DCHECK(module_version_info != NULL);
75 std::wstring file_version(module_version_info->file_version());
76 hr = registrar->AddReplacement(L"VERSION", file_version.c_str());
77 DCHECK(SUCCEEDED(hr));
78 }
79
80 if (SUCCEEDED(hr)) {
81 // Add the directory of chrome_launcher.exe. This will be the same
82 // as the directory for the current DLL.
83 std::wstring module_dir;
84 FilePath module_path;
85 if (PathService::Get(base::FILE_MODULE, &module_path)) {
86 module_dir = module_path.DirName().ToWStringHack();
87 } else {
88 NOTREACHED();
89 }
90 hr = registrar->AddReplacement(L"CHROME_LAUNCHER_APPPATH",
91 module_dir.c_str());
92 DCHECK(SUCCEEDED(hr));
93 }
94
95 if (SUCCEEDED(hr)) {
96 // Add the filename of chrome_launcher.exe
97 hr = registrar->AddReplacement(L"CHROME_LAUNCHER_APPNAME",
98 chrome_launcher::kLauncherExeBaseName);
99 DCHECK(SUCCEEDED(hr));
100 }
101
102 return hr;
103 }
104 };
105
106 ChromeTabModule _AtlModule;
107
108 base::AtExitManager* g_exit_manager = NULL;
109
110 // DLL Entry Point
111 extern "C" BOOL WINAPI DllMain(HINSTANCE instance,
112 DWORD reason,
113 LPVOID reserved) {
114 UNREFERENCED_PARAMETER(instance);
115 if (reason == DLL_PROCESS_ATTACH) {
116 #ifndef NDEBUG
117 // Silence traces from the ATL registrar to reduce the log noise.
118 ATL::CTrace::s_trace.ChangeCategory(atlTraceRegistrar, 0,
119 ATLTRACESTATUS_DISABLED);
120 #endif
121 InitializeCrashReporting(false, false);
122 g_exit_manager = new base::AtExitManager();
123 CommandLine::Init(0, NULL);
124 logging::InitLogging(NULL, logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
125 logging::LOCK_LOG_FILE, logging::DELETE_OLD_LOG_FILE);
126 } else if (reason == DLL_PROCESS_DETACH) {
127 g_patch_helper.UnpatchIfNeeded();
128 delete g_exit_manager;
129 g_exit_manager = NULL;
130 ShutdownCrashReporting();
131 }
132 return _AtlModule.DllMain(reason, reserved);
133 }
134
135 #ifdef _MANAGED
136 #pragma managed(pop)
137 #endif
138
139 const wchar_t kPostPlatformUAKey[] =
140 L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\"
141 L"User Agent\\Post Platform";
142 const wchar_t kClockUserAgent[] = L"chromeframe";
143
144 // To delete the clock user agent, set value to NULL.
145 HRESULT SetClockUserAgent(const wchar_t* value) {
146 HRESULT hr;
147 RegKey ua_key;
148 if (ua_key.Create(HKEY_CURRENT_USER, kPostPlatformUAKey, KEY_WRITE)) {
149 if (value) {
150 ua_key.WriteValue(kClockUserAgent, value);
151 } else {
152 ua_key.DeleteValue(kClockUserAgent);
153 }
154 hr = S_OK;
155 } else {
156 DLOG(ERROR) << __FUNCTION__ << ": " << kPostPlatformUAKey;
157 hr = E_UNEXPECTED;
158 }
159
160 return hr;
161 }
162
163 HRESULT RefreshElevationPolicy() {
164 const wchar_t kIEFrameDll[] = L"ieframe.dll";
165 const char kIERefreshPolicy[] = "IERefreshElevationPolicy";
166 HRESULT hr = E_NOTIMPL;
167 HMODULE ieframe_module = LoadLibrary(kIEFrameDll);
168 if (ieframe_module) {
169 typedef HRESULT (__stdcall *IERefreshPolicy)();
170 IERefreshPolicy ie_refresh_policy = reinterpret_cast<IERefreshPolicy>(
171 GetProcAddress(ieframe_module, kIERefreshPolicy));
172
173 if (ie_refresh_policy) {
174 hr = ie_refresh_policy();
175 } else {
176 hr = HRESULT_FROM_WIN32(GetLastError());
177 }
178
179 FreeLibrary(ieframe_module);
180 } else {
181 hr = HRESULT_FROM_WIN32(GetLastError());
182 }
183
184 return hr;
185 }
186
187 HRESULT RegisterChromeTabBHO() {
188 RegKey ie_bho_key;
189 if (!ie_bho_key.Create(HKEY_LOCAL_MACHINE, kBhoRegistryPath,
190 KEY_CREATE_SUB_KEY)) {
191 DLOG(WARNING) << "Failed to open registry key "
192 << kBhoRegistryPath
193 << " for write";
194 return E_FAIL;
195 }
196
197 wchar_t bho_class_id_as_string[MAX_PATH] = {0};
198 StringFromGUID2(CLSID_ChromeFrameBHO, bho_class_id_as_string,
199 arraysize(bho_class_id_as_string));
200
201 if (!ie_bho_key.CreateKey(bho_class_id_as_string, KEY_READ | KEY_WRITE)) {
202 DLOG(WARNING) << "Failed to create bho registry key under "
203 << kBhoRegistryPath
204 << " for write";
205 return E_FAIL;
206 }
207
208 ie_bho_key.WriteValue(kBhoNoLoadExplorerValue, 1);
209 DLOG(INFO) << "Registered ChromeTab BHO";
210
211 SetClockUserAgent(L"1");
212 RefreshElevationPolicy();
213 return S_OK;
214 }
215
216 HRESULT UnregisterChromeTabBHO() {
217 SetClockUserAgent(NULL);
218
219 RegKey ie_bho_key;
220 if (!ie_bho_key.Open(HKEY_LOCAL_MACHINE, kBhoRegistryPath,
221 KEY_READ | KEY_WRITE)) {
222 DLOG(WARNING) << "Failed to open registry key "
223 << kBhoRegistryPath
224 << " for write.";
225 return E_FAIL;
226 }
227
228 wchar_t bho_class_id_as_string[MAX_PATH] = {0};
229 StringFromGUID2(CLSID_ChromeFrameBHO, bho_class_id_as_string,
230 arraysize(bho_class_id_as_string));
231
232 if (!ie_bho_key.DeleteKey(bho_class_id_as_string)) {
233 DLOG(WARNING) << "Failed to delete bho registry key "
234 << bho_class_id_as_string
235 << " under "
236 << kBhoRegistryPath;
237 return E_FAIL;
238 }
239
240 DLOG(INFO) << "Unregistered ChromeTab BHO";
241 return S_OK;
242 }
243
244 // Used to determine whether the DLL can be unloaded by OLE
245 STDAPI DllCanUnloadNow() {
246 return _AtlModule.DllCanUnloadNow();
247 }
248
249 // Returns a class factory to create an object of the requested type
250 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) {
251 if (g_patch_helper.state() == PatchHelper::UNKNOWN) {
252 g_patch_helper.InitializeAndPatchProtocolsIfNeeded();
253 UrlMkSetSessionOption(URLMON_OPTION_USERAGENT_REFRESH, NULL, 0, 0);
254 }
255
256 return _AtlModule.DllGetClassObject(rclsid, riid, ppv);
257 }
258
259 // DllRegisterServer - Adds entries to the system registry
260 STDAPI DllRegisterServer() {
261 // registers object, typelib and all interfaces in typelib
262 HRESULT hr = _AtlModule.DllRegisterServer(TRUE);
263
264 #ifdef GOOGLE_CHROME_BUILD
265 // Muck with the Omaha configuration so that we don't get updated by non-CF
266 // Google Chrome builds.
267 UtilUpdateOmahaConfig(true);
268 #endif
269
270 if (SUCCEEDED(hr)) {
271 // Best effort attempt to register the BHO. At this point we silently
272 // ignore any errors during registration. There are some traces emitted
273 // to the debug log.
274 RegisterChromeTabBHO();
275 }
276
277 return hr;
278 }
279
280 // DllUnregisterServer - Removes entries from the system registry
281 STDAPI DllUnregisterServer() {
282 HRESULT hr = _AtlModule.DllUnregisterServer(TRUE);
283
284 #ifdef GOOGLE_CHROME_BUILD
285 // Undo any prior mucking with the Omaha config.
286 UtilUpdateOmahaConfig(false);
287 #endif
288
289 if (SUCCEEDED(hr)) {
290 // Best effort attempt to unregister the BHO. At this point we silently
291 // ignore any errors during unregistration. There are some traces emitted
292 // to the debug log.
293 UnregisterChromeTabBHO();
294 }
295 return hr;
296 }
297
298 STDAPI RegisterNPAPIPlugin() {
299 HRESULT hr = _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_NPAPI,
300 TRUE);
301 return hr;
302 }
303
304 STDAPI UnregisterNPAPIPlugin() {
305 HRESULT hr = _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_NPAPI,
306 FALSE);
307 return hr;
308 }
OLDNEW
« no previous file with comments | « chrome_frame/chrome_protocol.rgs ('k') | chrome_frame/chrome_tab.def » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698