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

Side by Side Diff: chrome_frame/chrome_tab.cc

Issue 3190005: Add two new entry points to the Chrome Frame DLL to allow for non-admin regis... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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
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 // chrome_tab.cc : Implementation of DLL Exports. 5 // chrome_tab.cc : Implementation of DLL Exports.
6 6
7 // Include without path to make GYP build see it. 7 // Include without path to make GYP build see it.
8 #include "chrome_tab.h" // NOLINT 8 #include "chrome_tab.h" // NOLINT
9 9
10 #include <atlsecurity.h> 10 #include <atlsecurity.h>
(...skipping 25 matching lines...) Expand all
36 #include "chrome_frame/chrome_launcher_utils.h" 36 #include "chrome_frame/chrome_launcher_utils.h"
37 #include "chrome_frame/chrome_protocol.h" 37 #include "chrome_frame/chrome_protocol.h"
38 #include "chrome_frame/module_utils.h" 38 #include "chrome_frame/module_utils.h"
39 #include "chrome_frame/resource.h" 39 #include "chrome_frame/resource.h"
40 #include "chrome_frame/utils.h" 40 #include "chrome_frame/utils.h"
41 #include "googleurl/src/url_util.h" 41 #include "googleurl/src/url_util.h"
42 42
43 namespace { 43 namespace {
44 // This function has the side effect of initializing an unprotected 44 // This function has the side effect of initializing an unprotected
45 // vector pointer inside GoogleUrl. If this is called during DLL loading, 45 // vector pointer inside GoogleUrl. If this is called during DLL loading,
46 // it has the effect of avoiding an initializiation race on that pointer. 46 // it has the effect of avoiding an initialization race on that pointer.
47 // TODO(siggi): fix GoogleUrl. 47 // TODO(siggi): fix GoogleUrl.
48 void InitGoogleUrl() { 48 void InitGoogleUrl() {
49 static const char kDummyUrl[] = "http://www.google.com"; 49 static const char kDummyUrl[] = "http://www.google.com";
50 50
51 url_util::IsStandard(kDummyUrl, 51 url_util::IsStandard(kDummyUrl,
52 url_parse::MakeRange(0, arraysize(kDummyUrl))); 52 url_parse::MakeRange(0, arraysize(kDummyUrl)));
53 } 53 }
54 } 54 }
55 55
56 static const wchar_t kBhoRegistryPath[] = 56 static const wchar_t kBhoRegistryPath[] =
(...skipping 24 matching lines...) Expand all
81 OBJECT_ENTRY_AUTO(__uuidof(ChromeProtocol), ChromeProtocol) 81 OBJECT_ENTRY_AUTO(__uuidof(ChromeProtocol), ChromeProtocol)
82 82
83 83
84 // See comments in DllGetClassObject. 84 // See comments in DllGetClassObject.
85 LPFNGETCLASSOBJECT g_dll_get_class_object_redir_ptr = NULL; 85 LPFNGETCLASSOBJECT g_dll_get_class_object_redir_ptr = NULL;
86 86
87 class ChromeTabModule : public CAtlDllModuleT<ChromeTabModule> { 87 class ChromeTabModule : public CAtlDllModuleT<ChromeTabModule> {
88 public: 88 public:
89 typedef CAtlDllModuleT<ChromeTabModule> ParentClass; 89 typedef CAtlDllModuleT<ChromeTabModule> ParentClass;
90 90
91 ChromeTabModule() : do_system_registration_(true) {}
92
91 DECLARE_LIBID(LIBID_ChromeTabLib) 93 DECLARE_LIBID(LIBID_ChromeTabLib)
92 DECLARE_REGISTRY_APPID_RESOURCEID(IDR_CHROMETAB, 94 DECLARE_REGISTRY_APPID_RESOURCEID(IDR_CHROMETAB,
93 "{FD9B1B31-F4D8-436A-8F4F-D3C2E36733D3}") 95 "{FD9B1B31-F4D8-436A-8F4F-D3C2E36733D3}")
94 96
95 // Override to add our SYSTIME binary value to registry scripts. 97 // Override to add our SYSTIME binary value to registry scripts.
96 // See chrome_frame_activex.rgs for usage. 98 // See chrome_frame_activex.rgs for usage.
97 virtual HRESULT AddCommonRGSReplacements(IRegistrarBase* registrar) throw() { 99 virtual HRESULT AddCommonRGSReplacements(IRegistrarBase* registrar) throw() {
98 HRESULT hr = ParentClass::AddCommonRGSReplacements(registrar); 100 HRESULT hr = ParentClass::AddCommonRGSReplacements(registrar);
99 101
100 if (SUCCEEDED(hr)) { 102 if (SUCCEEDED(hr)) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 DCHECK(SUCCEEDED(hr)); 146 DCHECK(SUCCEEDED(hr));
145 } 147 }
146 148
147 if (SUCCEEDED(hr)) { 149 if (SUCCEEDED(hr)) {
148 // Add the filename of chrome_launcher.exe 150 // Add the filename of chrome_launcher.exe
149 hr = registrar->AddReplacement(L"CHROME_LAUNCHER_APPNAME", 151 hr = registrar->AddReplacement(L"CHROME_LAUNCHER_APPNAME",
150 chrome_launcher::kLauncherExeBaseName); 152 chrome_launcher::kLauncherExeBaseName);
151 DCHECK(SUCCEEDED(hr)); 153 DCHECK(SUCCEEDED(hr));
152 } 154 }
153 155
156 if (SUCCEEDED(hr)) {
157 // Add the registry hive to use.
158 // Note: This is ugly as hell. I'd rather use the pMapEntries parameter
159 // to CAtlModule::UpdateRegistryFromResource, unfortunately we have a
160 // few components that are registered by calling their
161 // static T::UpdateRegistry() methods directly, which doesn't allow
162 // pMapEntries to be passed through :-(
163 if (do_system_registration_) {
164 hr = registrar->AddReplacement(L"HIVE", L"HKLM");
165 } else {
166 hr = registrar->AddReplacement(L"HIVE", L"HKCU");
167 }
168 DCHECK(SUCCEEDED(hr));
169 }
170
154 return hr; 171 return hr;
155 } 172 }
173
174 // See comments in AddCommonRGSReplacements
175 bool do_system_registration_;
156 }; 176 };
157 177
158 ChromeTabModule _AtlModule; 178 ChromeTabModule _AtlModule;
159 179
160 base::AtExitManager* g_exit_manager = NULL; 180 base::AtExitManager* g_exit_manager = NULL;
161 bool RegisterSecuredMimeHandler(bool enable); // forward 181 bool RegisterSecuredMimeHandler(bool enable, bool is_system); // forward
162 182
163 // DLL Entry Point 183 // DLL Entry Point
164 extern "C" BOOL WINAPI DllMain(HINSTANCE instance, 184 extern "C" BOOL WINAPI DllMain(HINSTANCE instance,
165 DWORD reason, 185 DWORD reason,
166 LPVOID reserved) { 186 LPVOID reserved) {
167 UNREFERENCED_PARAMETER(instance); 187 UNREFERENCED_PARAMETER(instance);
168 if (reason == DLL_PROCESS_ATTACH) { 188 if (reason == DLL_PROCESS_ATTACH) {
169 #ifndef NDEBUG 189 #ifndef NDEBUG
170 // Silence traces from the ATL registrar to reduce the log noise. 190 // Silence traces from the ATL registrar to reduce the log noise.
171 ATL::CTrace::s_trace.ChangeCategory(atlTraceRegistrar, 0, 191 ATL::CTrace::s_trace.ChangeCategory(atlTraceRegistrar, 0,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 GCF_PROTOCOL = 0x0004, 338 GCF_PROTOCOL = 0x0004,
319 BHO_CLSID = 0x0008, 339 BHO_CLSID = 0x0008,
320 BHO_REGISTRATION = 0x0010, 340 BHO_REGISTRATION = 0x0010,
321 TYPELIB = 0x0020, 341 TYPELIB = 0x0020,
322 342
323 NPAPI_PLUGIN = 0x1000, 343 NPAPI_PLUGIN = 0x1000,
324 344
325 ALL = 0xFFFF 345 ALL = 0xFFFF
326 }; 346 };
327 347
328 STDAPI CustomRegistration(UINT reg_flags, BOOL reg) { 348 STDAPI CustomRegistration(UINT reg_flags, BOOL reg, bool is_system) {
329 UINT flags = reg_flags; 349 UINT flags = reg_flags;
330 350
331 if (reg && (flags & (ACTIVEDOC | ACTIVEX))) 351 if (reg && (flags & (ACTIVEDOC | ACTIVEX)))
332 flags |= (TYPELIB |GCF_PROTOCOL); 352 flags |= (TYPELIB |GCF_PROTOCOL);
333 353
334 HRESULT hr = S_OK; 354 HRESULT hr = S_OK;
335 355
356 // Set the flag that gets checked in AddCommonRGSReplacements before doing
357 // registration work.
358 _AtlModule.do_system_registration_ = is_system;
359
336 if ((hr == S_OK) && (flags & ACTIVEDOC)) { 360 if ((hr == S_OK) && (flags & ACTIVEDOC)) {
337 if (!RegisterSecuredMimeHandler(reg? true : false)) 361 // Don't fail to unregister if we can't undo the secure mime
362 // handler registration. This was observed getting hit during
363 // uninstallation.
364 if (!RegisterSecuredMimeHandler(reg ? true : false, is_system) && reg)
338 return E_FAIL; 365 return E_FAIL;
339 hr = ChromeActiveDocument::UpdateRegistry(reg); 366 hr = ChromeActiveDocument::UpdateRegistry(reg);
340 } 367 }
341 368
342 if ((hr == S_OK) && (flags & ACTIVEX)) { 369 if ((hr == S_OK) && (flags & ACTIVEX)) {
343 // We have to call the static T::UpdateRegistry function instead of 370 // We have to call the static T::UpdateRegistry function instead of
344 // _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_ACTIVEX, reg) 371 // _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_ACTIVEX, reg)
345 // because there is specific OLEMISC replacement. 372 // because there is specific OLEMISC replacement.
346 hr = ChromeFrameActivex::UpdateRegistry(reg); 373 hr = ChromeFrameActivex::UpdateRegistry(reg);
347 // TODO(amit): Move elevation policy registration from ActiveX rgs 374 // TODO(amit): Move elevation policy registration from ActiveX rgs
348 // into a separate rgs. 375 // into a separate rgs.
349 RefreshElevationPolicy(); 376 RefreshElevationPolicy();
350 } 377 }
351 378
352 if ((hr == S_OK) && (flags & GCF_PROTOCOL)) { 379 if ((hr == S_OK) && (flags & GCF_PROTOCOL)) {
353 hr = _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEPROTOCOL, reg); 380 hr = _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEPROTOCOL, reg);
354 } 381 }
355 382
356 if ((hr == S_OK) && (flags & BHO_CLSID)) { 383 if ((hr == S_OK) && (flags & BHO_CLSID)) {
357 hr = Bho::UpdateRegistry(reg); 384 hr = Bho::UpdateRegistry(reg);
358 } 385 }
359 386
360 if ((hr == S_OK) && (flags & BHO_REGISTRATION)) { 387 if ((hr == S_OK) && (flags & BHO_REGISTRATION) && !is_system) {
361 _AtlModule.UpdateRegistryFromResourceS(IDR_REGISTER_BHO, reg); 388 _AtlModule.UpdateRegistryFromResourceS(IDR_REGISTER_BHO, reg);
362 } 389 }
363 390
364 if ((hr == S_OK) && (flags & TYPELIB)) { 391 if ((hr == S_OK) && (flags & TYPELIB)) {
365 hr = (reg)? _AtlComModule.RegisterTypeLib(): 392 hr = (reg)?
366 _AtlComModule.UnRegisterTypeLib(); 393 UtilRegisterTypeLib(_AtlComModule.m_hInstTypeLib, NULL, !is_system) :
394 UtilUnRegisterTypeLib(_AtlComModule.m_hInstTypeLib, NULL, !is_system);
367 } 395 }
368 396
369 if ((hr == S_OK) && (flags & NPAPI_PLUGIN)) { 397 if ((hr == S_OK) && (flags & NPAPI_PLUGIN)) {
370 hr = _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_NPAPI, reg); 398 hr = _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_NPAPI, reg);
371 } 399 }
372 400
373 if (hr == S_OK) { 401 if (hr == S_OK) {
374 hr = _AtlModule.UpdateRegistryAppId(reg); 402 hr = _AtlModule.UpdateRegistryAppId(reg);
375 } 403 }
376 404
377 return hr; 405 return hr;
378 } 406 }
379 407
380 408
381 409
382 // DllRegisterServer - Adds entries to the system registry 410 // DllRegisterServer - Adds entries to the system registry
383 STDAPI DllRegisterServer() { 411 STDAPI DllRegisterServer() {
384 UINT flags = ACTIVEX | ACTIVEDOC | TYPELIB | GCF_PROTOCOL | 412 UINT flags = ACTIVEX | ACTIVEDOC | TYPELIB | GCF_PROTOCOL |
385 BHO_CLSID | BHO_REGISTRATION; 413 BHO_CLSID | BHO_REGISTRATION;
386 414
387 if (UtilIsPersistentNPAPIMarkerSet()) { 415 if (UtilIsPersistentNPAPIMarkerSet()) {
388 flags |= IDR_CHROMEFRAME_NPAPI; 416 flags |= IDR_CHROMEFRAME_NPAPI;
389 } 417 }
390 418
391 HRESULT hr = CustomRegistration(flags, TRUE); 419 HRESULT hr = CustomRegistration(flags, TRUE, true);
392 if (SUCCEEDED(hr)) { 420 if (SUCCEEDED(hr)) {
393 SetupRunOnce(); 421 SetupRunOnce();
394 } 422 }
395 423
396 return hr; 424 return hr;
397 } 425 }
398 426
399 // DllUnregisterServer - Removes entries from the system registry 427 // DllUnregisterServer - Removes entries from the system registry
400 STDAPI DllUnregisterServer() { 428 STDAPI DllUnregisterServer() {
401 HRESULT hr = CustomRegistration(ALL, FALSE); 429 HRESULT hr = CustomRegistration(ALL, FALSE, true);
430 return hr;
431 }
432
433 // DllRegisterServer - Adds entries to the HKCU hive in the registry
434 STDAPI DllRegisterUserServer() {
435 UINT flags = ACTIVEX | ACTIVEDOC | TYPELIB | GCF_PROTOCOL | BHO_CLSID;
436
437 if (UtilIsPersistentNPAPIMarkerSet()) {
438 flags |= IDR_CHROMEFRAME_NPAPI;
439 }
440
441 HRESULT hr = CustomRegistration(flags, TRUE, false);
442 if (SUCCEEDED(hr)) {
443 SetupRunOnce();
444 }
445
446 return hr;
447 }
448
449 // DllRegisterServer - Removes entries from the HKCU hive in the registry.
450 STDAPI DllUnregisterUserServer() {
451 HRESULT hr = CustomRegistration(ALL, FALSE, false);
402 return hr; 452 return hr;
403 } 453 }
404 454
405 // Registers the NPAPI plugin and sets the persistent marker that tells us 455 // Registers the NPAPI plugin and sets the persistent marker that tells us
406 // to re-register it through updates. 456 // to re-register it through updates.
407 STDAPI RegisterNPAPIPlugin() { 457 STDAPI RegisterNPAPIPlugin() {
408 HRESULT hr = _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_NPAPI, 458 HRESULT hr = _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_NPAPI,
409 TRUE); 459 TRUE);
410 if (SUCCEEDED(hr)) { 460 if (SUCCEEDED(hr)) {
411 if (!UtilChangePersistentNPAPIMarker(true)) { 461 if (!UtilChangePersistentNPAPIMarker(true)) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 return user_; 585 return user_;
536 } 586 }
537 587
538 private: 588 private:
539 CAccessToken token_; 589 CAccessToken token_;
540 CTokenPrivileges take_ownership_; 590 CTokenPrivileges take_ownership_;
541 CTokenPrivileges restore_; 591 CTokenPrivileges restore_;
542 CSid user_; 592 CSid user_;
543 }; 593 };
544 594
545 static bool SetOrDeleteMimeHandlerKey(bool set) { 595 static bool SetOrDeleteMimeHandlerKey(bool set, HKEY root_key) {
546 std::wstring key_name = kInternetSettings; 596 std::wstring key_name = kInternetSettings;
547 key_name.append(L"\\Secure Mime Handlers"); 597 key_name.append(L"\\Secure Mime Handlers");
548 RegKey key(HKEY_LOCAL_MACHINE, key_name.c_str(), KEY_READ | KEY_WRITE); 598 RegKey key(root_key, key_name.c_str(), KEY_READ | KEY_WRITE);
549 if (!key.Valid()) 599 if (!key.Valid())
550 return false; 600 return false;
551 601
552 bool result; 602 bool result;
553 if (set) { 603 if (set) {
554 result = key.WriteValue(L"ChromeTab.ChromeActiveDocument", 1); 604 result = key.WriteValue(L"ChromeTab.ChromeActiveDocument", 1);
555 result = key.WriteValue(L"ChromeTab.ChromeActiveDocument.1", 1) && result; 605 result = key.WriteValue(L"ChromeTab.ChromeActiveDocument.1", 1) && result;
556 } else { 606 } else {
557 result = key.DeleteValue(L"ChromeTab.ChromeActiveDocument"); 607 result = key.DeleteValue(L"ChromeTab.ChromeActiveDocument");
558 result = key.DeleteValue(L"ChromeTab.ChromeActiveDocument.1") && result; 608 result = key.DeleteValue(L"ChromeTab.ChromeActiveDocument.1") && result;
559 } 609 }
560 610
561 return result; 611 return result;
562 } 612 }
563 613
564 bool RegisterSecuredMimeHandler(bool enable) { 614 bool RegisterSecuredMimeHandler(bool enable, bool is_system) {
565 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) { 615 if (!is_system) {
566 return SetOrDeleteMimeHandlerKey(enable); 616 return SetOrDeleteMimeHandlerKey(enable, HKEY_CURRENT_USER);
617 } else if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) {
618 return SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE);
567 } 619 }
568 620
569 std::wstring mime_key = kInternetSettings; 621 std::wstring mime_key = kInternetSettings;
570 mime_key.append(L"\\Secure Mime Handlers"); 622 mime_key.append(L"\\Secure Mime Handlers");
571 std::wstring backup_key = kInternetSettings; 623 std::wstring backup_key = kInternetSettings;
572 backup_key.append(L"\\__backup_SMH__"); 624 backup_key.append(L"\\__backup_SMH__");
573 std::wstring object_name = L"MACHINE\\"; 625 std::wstring object_name = L"MACHINE\\";
574 object_name.append(mime_key); 626 object_name.append(mime_key);
575 627
576 TokenWithPrivileges token_; 628 TokenWithPrivileges token_;
(...skipping 13 matching lines...) Expand all
590 642
591 backup.SaveSecurity(sd); 643 backup.SaveSecurity(sd);
592 bool result = false; 644 bool result = false;
593 // set new owner 645 // set new owner
594 if (AtlSetOwnerSid(object_name.c_str(), SE_REGISTRY_KEY, token_.GetUser())) { 646 if (AtlSetOwnerSid(object_name.c_str(), SE_REGISTRY_KEY, token_.GetUser())) {
595 // set new dacl 647 // set new dacl
596 CDacl new_dacl; 648 CDacl new_dacl;
597 sd.GetDacl(&new_dacl); 649 sd.GetDacl(&new_dacl);
598 new_dacl.AddAllowedAce(token_.GetUser(), GENERIC_WRITE | GENERIC_READ); 650 new_dacl.AddAllowedAce(token_.GetUser(), GENERIC_WRITE | GENERIC_READ);
599 if (AtlSetDacl(object_name.c_str(), SE_REGISTRY_KEY, new_dacl)) { 651 if (AtlSetDacl(object_name.c_str(), SE_REGISTRY_KEY, new_dacl)) {
600 result = SetOrDeleteMimeHandlerKey(enable); 652 result = SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE);
601 } 653 }
602 } 654 }
603 655
604 backup.RestoreSecurity(object_name.c_str()); 656 backup.RestoreSecurity(object_name.c_str());
605 return result; 657 return result;
606 } 658 }
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