#include "chrome_frame/chrome_tab.h"
#include <atlsecurity.h>
#include <objbase.h>
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/file_version_info.h"
#include "base/logging.h"
#include "base/logging_win.h"
#include "base/metrics/field_trial.h"
#include "base/path_service.h"
#include "base/string16.h"
#include "base/string_number_conversions.h"
#include "base/string_piece.h"
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
#include "base/win/registry.h"
#include "base/win/windows_version.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/metrics/entropy_provider.h"
#include "chrome/installer/util/google_update_settings.h"
#include "chrome_frame/bho.h"
#include "chrome_frame/chrome_active_document.h"
#include "chrome_frame/chrome_frame_activex.h"
#include "chrome_frame/chrome_frame_automation.h"
#include "chrome_frame/chrome_frame_reporting.h"
#include "chrome_frame/chrome_launcher_utils.h"
#include "chrome_frame/chrome_protocol.h"
#include "chrome_frame/dll_redirector.h"
#include "chrome_frame/exception_barrier.h"
#include "chrome_frame/metrics_service.h"
#include "chrome_frame/resource.h"
#include "chrome_frame/utils.h"
#include "googleurl/src/url_util.h"
#include "grit/chrome_frame_resources.h"
using base::win::RegKey;
namespace {
void InitGoogleUrl() {
static const char kDummyUrl[] = "http://www.google.com";
url_util::IsStandard(kDummyUrl,
url_parse::MakeRange(0, arraysize(kDummyUrl)));
}
const wchar_t kInternetSettings[] =
L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
const wchar_t kProtocolHandlers[] =
L"Software\\Classes\\Protocols\\Handler";
const wchar_t kRunOnce[] =
L"Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce";
const wchar_t kRunKeyName[] = L"ChromeFrameHelper";
const wchar_t kChromeFrameHelperExe[] = L"chrome_frame_helper.exe";
const wchar_t kChromeFrameHelperStartupArg[] = L"--startup";
const wchar_t kChromeFrameHelperWindowClassName[] =
L"ChromeFrameHelperWindowClass";
const wchar_t kChromeFrameHelperWindowName[] =
L"ChromeFrameHelperWindowName";
static const GUID kChromeFrameProvider =
{ 0x562bfc3, 0x2550, 0x45b4,
{ 0xbd, 0x8e, 0xa3, 0x10, 0x58, 0x3d, 0x3a, 0x6f } };
const wchar_t kPostPlatformUAKey[] =
L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\"
L"User Agent\\Post Platform";
const wchar_t kChromeFramePrefix[] = L"chromeframe/";
LPFNGETCLASSOBJECT g_dll_get_class_object_redir_ptr = NULL;
class ChromeTabModule : public CAtlDllModuleT<ChromeTabModule> {
public:
typedef CAtlDllModuleT<ChromeTabModule> ParentClass;
ChromeTabModule() : do_system_registration_(true) {}
DECLARE_LIBID(LIBID_ChromeTabLib)
DECLARE_REGISTRY_APPID_RESOURCEID(IDR_CHROMETAB,
"{FD9B1B31-F4D8-436A-8F4F-D3C2E36733D3}")
virtual HRESULT AddCommonRGSReplacements(IRegistrarBase* registrar) throw() {
HRESULT hr = ParentClass::AddCommonRGSReplacements(registrar);
if (SUCCEEDED(hr)) {
SYSTEMTIME local_time;
::GetSystemTime(&local_time);
std::string hex(base::HexEncode(&local_time, sizeof(local_time)));
base::StringPiece sp_hex(hex);
hr = registrar->AddReplacement(L"SYSTIME",
base::SysNativeMBToWide(sp_hex).c_str());
DCHECK(SUCCEEDED(hr));
}
if (SUCCEEDED(hr)) {
FilePath app_path =
chrome_launcher::GetChromeExecutablePath().DirName();
hr = registrar->AddReplacement(L"CHROME_APPPATH",
app_path.value().c_str());
DCHECK(SUCCEEDED(hr));
}
if (SUCCEEDED(hr)) {
hr = registrar->AddReplacement(L"CHROME_APPNAME",
chrome::kBrowserProcessExecutableName);
DCHECK(SUCCEEDED(hr));
scoped_ptr<FileVersionInfo> module_version_info(
FileVersionInfo::CreateFileVersionInfoForCurrentModule());
DCHECK(module_version_info != NULL);
std::wstring file_version(module_version_info->file_version());
hr = registrar->AddReplacement(L"VERSION", file_version.c_str());
DCHECK(SUCCEEDED(hr));
}
if (SUCCEEDED(hr)) {
std::wstring module_dir;
FilePath module_path;
if (PathService::Get(base::FILE_MODULE, &module_path)) {
module_dir = module_path.DirName().value();
} else {
NOTREACHED();
}
hr = registrar->AddReplacement(L"CHROME_LAUNCHER_APPPATH",
module_dir.c_str());
DCHECK(SUCCEEDED(hr));
}
if (SUCCEEDED(hr)) {
hr = registrar->AddReplacement(L"CHROME_LAUNCHER_APPNAME",
chrome_launcher::kLauncherExeBaseName);
DCHECK(SUCCEEDED(hr));
}
if (SUCCEEDED(hr)) {
if (do_system_registration_) {
hr = registrar->AddReplacement(L"HIVE", L"HKLM");
} else {
hr = registrar->AddReplacement(L"HIVE", L"HKCU");
}
DCHECK(SUCCEEDED(hr));
}
if (SUCCEEDED(hr)) {
wchar_t cf_clsid[64];
StringFromGUID2(CLSID_ChromeFrame, &cf_clsid[0], arraysize(cf_clsid));
hr = registrar->AddReplacement(L"CHROME_FRAME_CLSID", &cf_clsid[0]);
}
return hr;
}
bool do_system_registration_;
};
ChromeTabModule _AtlModule;
base::AtExitManager* g_exit_manager = NULL;
base::FieldTrialList* g_field_trial_list = NULL;
HRESULT RefreshElevationPolicy() {
const wchar_t kIEFrameDll[] = L"ieframe.dll";
const char kIERefreshPolicy[] = "IERefreshElevationPolicy";
HRESULT hr = E_NOTIMPL;
ExceptionBarrier barrier;
HMODULE ieframe_module = LoadLibrary(kIEFrameDll);
if (ieframe_module) {
typedef HRESULT (__stdcall *IERefreshPolicy)();
IERefreshPolicy ie_refresh_policy = reinterpret_cast<IERefreshPolicy>(
GetProcAddress(ieframe_module, kIERefreshPolicy));
if (ie_refresh_policy) {
hr = ie_refresh_policy();
} else {
hr = HRESULT_FROM_WIN32(GetLastError());
}
FreeLibrary(ieframe_module);
} else {
hr = HRESULT_FROM_WIN32(GetLastError());
}
return hr;
}
HRESULT SetupRunOnce() {
HRESULT result = E_FAIL;
string16 channel_name;
if (base::win::GetVersion() < base::win::VERSION_VISTA &&
GoogleUpdateSettings::GetChromeChannelAndModifiers(true, &channel_name)) {
std::transform(channel_name.begin(), channel_name.end(),
channel_name.begin(), tolower);
if (channel_name.find(L"dev") != string16::npos) {
HKEY hive = HKEY_CURRENT_USER;
if (IsSystemProcess()) {
hive = HKEY_LOCAL_MACHINE;
}
RegKey run_once;
LONG ret = run_once.Create(hive, kRunOnce, KEY_READ | KEY_WRITE);
if (ret == ERROR_SUCCESS) {
CommandLine run_once_cmd(chrome_launcher::GetChromeExecutablePath());
run_once_cmd.AppendSwitchASCII(switches::kAutomationClientChannelID,
"0");
run_once_cmd.AppendSwitch(switches::kChromeFrame);
ret = run_once.WriteValue(L"A",
run_once_cmd.GetCommandLineString().c_str());
}
result = HRESULT_FROM_WIN32(ret);
} else {
result = S_FALSE;
}
} else {
result = S_FALSE;
}
return result;
}
HRESULT SetupUserLevelHelper() {
HRESULT hr = S_OK;
base::win::RemoveCommandFromAutoRun(HKEY_CURRENT_USER, kRunKeyName);
FilePath module_path;
FilePath helper_path;
if (PathService::Get(base::FILE_MODULE, &module_path)) {
module_path = module_path.DirName();
helper_path = module_path.Append(kChromeFrameHelperExe);
if (!file_util::PathExists(helper_path)) {
module_path = module_path.DirName();
helper_path = module_path.Append(kChromeFrameHelperExe);
DCHECK(file_util::PathExists(helper_path)) <<
"Could not find chrome_frame_helper.exe.";
}
HWND old_window = FindWindow(kChromeFrameHelperWindowClassName,
kChromeFrameHelperWindowName);
if (file_util::PathExists(helper_path)) {
std::wstring helper_path_cmd(L"\"");
helper_path_cmd += helper_path.value();
helper_path_cmd += L"\" ";
helper_path_cmd += kChromeFrameHelperStartupArg;
if (!base::win::AddCommandToAutoRun(HKEY_CURRENT_USER, kRunKeyName,
helper_path_cmd)) {
hr = E_FAIL;
LOG(ERROR) << "Could not add helper process to auto run key.";
}
base::LaunchOptions options;
options.start_hidden = true;
bool launched = base::LaunchProcess(helper_path.value(), options, NULL);
if (!launched) {
hr = E_FAIL;
PLOG(DFATAL) << "Could not launch helper process.";
}
if (IsWindow(old_window)) {
BOOL result = PostMessage(old_window, WM_CLOSE, 0, 0);
if (!result) {
PLOG(ERROR) << "Failed to post close message to old helper process: ";
}
}
} else {
hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
}
} else {
hr = E_UNEXPECTED;
NOTREACHED();
}
return hr;
}
HRESULT SetChromeFrameUA(bool is_system, const wchar_t* value) {
HRESULT hr = E_FAIL;
HKEY parent_hive = is_system ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
RegKey ua_key;
LONG reg_result = ua_key.Create(parent_hive, kPostPlatformUAKey,
KEY_READ | KEY_WRITE);
if (reg_result == ERROR_SUCCESS) {
wchar_t value_name[MAX_PATH + 1] = {};
wchar_t value_data[MAX_PATH + 1] = {};
DWORD value_index = 0;
while (value_index < ua_key.GetValueCount()) {
DWORD name_size = arraysize(value_name);
DWORD value_size = arraysize(value_data);
DWORD type = 0;
LRESULT ret = ::RegEnumValue(ua_key.Handle(), value_index, value_name,
&name_size, NULL, &type,
reinterpret_cast<BYTE*>(value_data),
&value_size);
if (ret == ERROR_SUCCESS) {
if (StartsWith(value_name, kChromeFramePrefix, false)) {
ua_key.DeleteValue(value_name);
} else {
++value_index;
}
} else {
break;
}
}
std::wstring chrome_frame_ua_value_name = kChromeFramePrefix;
chrome_frame_ua_value_name += GetCurrentModuleVersion();
if (value) {
ua_key.WriteValue(chrome_frame_ua_value_name.c_str(), value);
}
hr = S_OK;
} else {
DLOG(ERROR) << __FUNCTION__ << ": " << kPostPlatformUAKey
<< ", error code = " << reg_result;
hr = HRESULT_FROM_WIN32(reg_result);
}
return hr;
}
class SecurityDescBackup {
public:
explicit SecurityDescBackup(const std::wstring& backup_key)
: backup_key_name_(backup_key) {}
~SecurityDescBackup() {}
bool SaveSecurity(const CSecurityDesc& sd) {
CString str;
if (!sd.ToString(&str))
return false;
RegKey backup_key(HKEY_LOCAL_MACHINE, backup_key_name_.c_str(),
KEY_READ | KEY_WRITE);
if (backup_key.Valid()) {
return backup_key.WriteValue(NULL, str.GetString()) == ERROR_SUCCESS;
}
return false;
}
bool RestoreSecurity(const wchar_t* key_name) {
std::wstring sddl;
if (!ReadBackupKey(&sddl))
return false;
CSecurityDesc sd;
if (!sd.FromString(sddl.c_str()))
return false;
bool result = true;
CDacl dacl;
CSid owner;
sd.GetDacl(&dacl);
sd.GetOwner(&owner);
DWORD error = ::SetNamedSecurityInfo(const_cast<wchar_t*>(key_name),
SE_REGISTRY_KEY, OWNER_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
const_cast<SID*>(owner.GetPSID()), NULL,
const_cast<ACL*>(dacl.GetPACL()), NULL);
DeleteBackupKey();
return (error == ERROR_SUCCESS);
}
private:
bool ReadBackupKey(std::wstring* sddl) {
RegKey backup_key(HKEY_LOCAL_MACHINE, backup_key_name_.c_str(), KEY_READ);
if (!backup_key.Valid())
return false;
DWORD len = 0;
DWORD reg_type = REG_NONE;
if (backup_key.ReadValue(NULL, NULL, &len, ®_type) != ERROR_SUCCESS)
return false;
DCHECK_EQ(0u, len % sizeof(wchar_t));
if ((len == 0) || (reg_type != REG_SZ))
return false;
size_t wchar_count = 1 + len / sizeof(wchar_t);
if (backup_key.ReadValue(NULL, WriteInto(sddl, wchar_count), &len,
®_type) != ERROR_SUCCESS) {
return false;
}
return true;
}
void DeleteBackupKey() {
::RegDeleteKey(HKEY_LOCAL_MACHINE, backup_key_name_.c_str());
}
std::wstring backup_key_name_;
};
struct TokenWithPrivileges {
TokenWithPrivileges() {
token_.GetEffectiveToken(TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY);
token_.GetUser(&user_);
}
~TokenWithPrivileges() {
token_.EnableDisablePrivileges(take_ownership_);
token_.EnableDisablePrivileges(restore_);
}
bool EnablePrivileges() {
if (take_ownership_.GetCount() == 0)
if (!token_.EnablePrivilege(L"SeTakeOwnershipPrivilege",
&take_ownership_))
return false;
if (restore_.GetCount() == 0)
if (!token_.EnablePrivilege(L"SeRestorePrivilege", &restore_))
return false;
return true;
}
const CSid& GetUser() const {
return user_;
}
private:
CAccessToken token_;
CTokenPrivileges take_ownership_;
CTokenPrivileges restore_;
CSid user_;
};
HRESULT SetOrDeleteMimeHandlerKey(bool set, HKEY root_key) {
std::wstring key_name = kInternetSettings;
key_name.append(L"\\Secure Mime Handlers");
RegKey key(root_key, key_name.c_str(), KEY_READ | KEY_WRITE);
if (!key.Valid())
return false;
LONG result1 = ERROR_SUCCESS;
LONG result2 = ERROR_SUCCESS;
if (set) {
result1 = key.WriteValue(L"ChromeTab.ChromeActiveDocument", 1);
result2 = key.WriteValue(L"ChromeTab.ChromeActiveDocument.1", 1);
} else {
result1 = key.DeleteValue(L"ChromeTab.ChromeActiveDocument");
result2 = key.DeleteValue(L"ChromeTab.ChromeActiveDocument.1");
}
return result1 != ERROR_SUCCESS ? HRESULT_FROM_WIN32(result1) :
HRESULT_FROM_WIN32(result2);
}
HRESULT RegisterSecuredMimeHandler(bool enable, bool is_system) {
if (!is_system) {
return SetOrDeleteMimeHandlerKey(enable, HKEY_CURRENT_USER);
} else if (base::win::GetVersion() < base::win::VERSION_VISTA) {
return SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE);
}
std::wstring mime_key = kInternetSettings;
mime_key.append(L"\\Secure Mime Handlers");
std::wstring backup_key = kInternetSettings;
backup_key.append(L"\\__backup_SMH__");
std::wstring object_name = L"MACHINE\\";
object_name.append(mime_key);
TokenWithPrivileges token_;
if (!token_.EnablePrivileges())
return E_ACCESSDENIED;
SecurityDescBackup backup(backup_key);
backup.RestoreSecurity(object_name.c_str());
CSecurityDesc sd;
if (!AtlGetSecurityDescriptor(object_name.c_str(), SE_REGISTRY_KEY, &sd)) {
return E_FAIL;
}
backup.SaveSecurity(sd);
HRESULT hr = E_FAIL;
if (AtlSetOwnerSid(object_name.c_str(), SE_REGISTRY_KEY, token_.GetUser())) {
CDacl new_dacl;
sd.GetDacl(&new_dacl);
new_dacl.AddAllowedAce(token_.GetUser(), GENERIC_WRITE | GENERIC_READ);
if (AtlSetDacl(object_name.c_str(), SE_REGISTRY_KEY, new_dacl)) {
hr = SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE);
}
}
backup.RestoreSecurity(object_name.c_str());
return hr;
}
HRESULT RegisterActiveDoc(bool reg, bool is_system) {
return ChromeActiveDocument::UpdateRegistry(reg);
}
HRESULT RegisterActiveX(bool reg, bool is_system) {
return ChromeFrameActivex::UpdateRegistry(reg);
}
HRESULT RegisterElevationPolicy(bool reg, bool is_system) {
HRESULT hr = S_OK;
if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
hr = _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_ELEVATION, reg);
if (SUCCEEDED(hr)) {
RefreshElevationPolicy();
}
}
return hr;
}
HRESULT RegisterProtocol(bool reg, bool is_system) {
return _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEPROTOCOL, reg);
}
HRESULT RegisterBhoClsid(bool reg, bool is_system) {
return Bho::UpdateRegistry(reg);
}
HRESULT RegisterBhoIE(bool reg, bool is_system) {
if (is_system) {
return _AtlModule.UpdateRegistryFromResourceS(IDR_REGISTER_BHO, reg);
} else {
if (reg) {
return SetupUserLevelHelper();
} else {
return base::win::RemoveCommandFromAutoRun(HKEY_CURRENT_USER,
kRunKeyName) ? S_OK : E_FAIL;
}
}
}
HRESULT RegisterTypeLib(bool reg, bool is_system) {
if (reg && !is_system) {
typedef void (WINAPI* OaEnablePerUserTypeLibReg)(void);
OaEnablePerUserTypeLibReg per_user_typelib_func =
reinterpret_cast<OaEnablePerUserTypeLibReg>(
GetProcAddress(GetModuleHandle(L"oleaut32.dll"),
"OaEnablePerUserTLibRegistration"));
if (per_user_typelib_func) {
(*per_user_typelib_func)();
}
}
return reg ?
UtilRegisterTypeLib(_AtlComModule.m_hInstTypeLib,
NULL, !is_system) :
UtilUnRegisterTypeLib(_AtlComModule.m_hInstTypeLib,
NULL, !is_system);
}
HRESULT RegisterLegacyNPAPICleanup(bool reg, bool is_system) {
if (!reg) {
_AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_NPAPI, reg);
UtilRemovePersistentNPAPIMarker();
}
return S_OK;
}
HRESULT RegisterAppId(bool reg, bool is_system) {
return _AtlModule.UpdateRegistryAppId(reg);
}
HRESULT RegisterUserAgent(bool reg, bool is_system) {
if (reg) {
return SetChromeFrameUA(is_system, L"1");
} else {
return SetChromeFrameUA(is_system, NULL);
}
}
enum RegistrationStepId {
kStepSecuredMimeHandler = 0,
kStepActiveDoc = 1,
kStepActiveX = 2,
kStepElevationPolicy = 3,
kStepProtocol = 4,
kStepBhoClsid = 5,
kStepBhoRegistration = 6,
kStepRegisterTypeLib = 7,
kStepNpapiCleanup = 8,
kStepAppId = 9,
kStepUserAgent = 10,
kStepEnd = 11
};
enum RegistrationFlags {
ACTIVEX = 0x0001,
ACTIVEDOC = 0x0002,
GCF_PROTOCOL = 0x0004,
BHO_CLSID = 0x0008,
BHO_REGISTRATION = 0x0010,
TYPELIB = 0x0020,
ALL = 0xFFFF
};
HRESULT MuxErrorIntoHRESULT(HRESULT hr, int error_code) {
DCHECK_GE(error_code, 0);
DCHECK_LT(error_code, kStepEnd);
COMPILE_ASSERT(kStepEnd <= 0xF, update_error_muxing_too_many_steps);
DCHECK_EQ(static_cast<HRESULT>(hr & 0xF87FFFFF), hr);
HRESULT fiddled_hr = ((error_code & 0xF) << 23) | hr;
fiddled_hr |= 1 << 29;
return fiddled_hr;
}
HRESULT CustomRegistration(uint16 reg_flags, bool reg, bool is_system) {
if (reg && (reg_flags & (ACTIVEDOC | ACTIVEX)))
reg_flags |= (TYPELIB | GCF_PROTOCOL);
_AtlModule.do_system_registration_ = is_system;
typedef HRESULT (*RegistrationFn)(bool reg, bool is_system);
struct RegistrationStep {
RegistrationStepId id;
uint16 condition;
RegistrationFn func;
};
static const RegistrationStep registration_steps[] = {
{ kStepSecuredMimeHandler, ACTIVEDOC, &RegisterSecuredMimeHandler },
{ kStepActiveDoc, ACTIVEDOC, &RegisterActiveDoc },
{ kStepActiveX, ACTIVEX, &RegisterActiveX },
{ kStepElevationPolicy, (ACTIVEDOC | ACTIVEX), &RegisterElevationPolicy },
{ kStepProtocol, GCF_PROTOCOL, &RegisterProtocol },
{ kStepBhoClsid, BHO_CLSID, &RegisterBhoClsid },
{ kStepBhoRegistration, BHO_REGISTRATION, &RegisterBhoIE },
{ kStepRegisterTypeLib, TYPELIB, &RegisterTypeLib },
{ kStepNpapiCleanup, ALL, &RegisterLegacyNPAPICleanup },
{ kStepAppId, ALL, &RegisterAppId },
{ kStepUserAgent, ALL, &RegisterUserAgent }
};
HRESULT hr = S_OK;
bool rollback = false;
int failure_step = 0;
HRESULT step_hr = S_OK;
for (int step = 0; step < arraysize(registration_steps); ++step) {
if ((reg_flags & registration_steps[step].condition) != 0) {
step_hr = registration_steps[step].func(reg, is_system);
if (FAILED(step_hr)) {
if (hr == S_OK) {
hr = MuxErrorIntoHRESULT(step_hr, step);
}
if (reg) {
rollback = true;
failure_step = step;
break;
}
}
}
}
if (rollback) {
DCHECK(reg);
for (int step = failure_step; step >= 0; --step) {
registration_steps[step].func(!reg, is_system);
}
}
return hr;
}
}
extern "C" BOOL WINAPI DllMain(HINSTANCE instance,
DWORD reason,
LPVOID reserved) {
UNREFERENCED_PARAMETER(instance);
if (reason == DLL_PROCESS_ATTACH) {
#ifndef NDEBUG
ATL::CTrace::s_trace.ChangeCategory(atlTraceRegistrar, 0,
ATLTRACESTATUS_DISABLED);
#endif
InitGoogleUrl();
g_exit_manager = new base::AtExitManager();
CommandLine::Init(0, NULL);
InitializeCrashReporting();
logging::InitLogging(
NULL,
logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
logging::LOCK_LOG_FILE,
logging::DELETE_OLD_LOG_FILE,
logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS);
logging::SetLogItems(true,
true,
false,
true);
DllRedirector* dll_redirector = DllRedirector::GetInstance();
DCHECK(dll_redirector);
if (!dll_redirector->RegisterAsFirstCFModule()) {
g_dll_get_class_object_redir_ptr =
dll_redirector->GetDllGetClassObjectPtr();
DCHECK(g_dll_get_class_object_redir_ptr != NULL)
<< "Found CF module with no DllGetClassObject export.";
}
logging::LogEventProvider::Initialize(kChromeFrameProvider);
g_field_trial_list = new base::FieldTrialList(
new metrics::SHA1EntropyProvider(MetricsService::GetClientID()));
} else if (reason == DLL_PROCESS_DETACH) {
delete g_field_trial_list;
g_field_trial_list = NULL;
DllRedirector* dll_redirector = DllRedirector::GetInstance();
DCHECK(dll_redirector);
dll_redirector->UnregisterAsFirstCFModule();
g_patch_helper.UnpatchIfNeeded();
delete g_exit_manager;
g_exit_manager = NULL;
ShutdownCrashReporting();
}
return _AtlModule.DllMain(reason, reserved);
}
STDAPI DllCanUnloadNow() {
return _AtlModule.DllCanUnloadNow();
}
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) {
if (g_dll_get_class_object_redir_ptr) {
return g_dll_get_class_object_redir_ptr(rclsid, riid, ppv);
}
if (rclsid == CLSID_ChromeFrameBHO) {
g_patch_helper.InitializeAndPatchProtocolsIfNeeded();
}
return _AtlModule.DllGetClassObject(rclsid, riid, ppv);
}
STDAPI DllRegisterServer() {
uint16 flags = ACTIVEX | ACTIVEDOC | TYPELIB | GCF_PROTOCOL |
BHO_CLSID | BHO_REGISTRATION;
HRESULT hr = CustomRegistration(flags, true, true);
if (SUCCEEDED(hr)) {
SetupRunOnce();
}
return hr;
}
STDAPI DllUnregisterServer() {
HRESULT hr = CustomRegistration(ALL, false, true);
return hr;
}
STDAPI DllRegisterUserServer() {
UINT flags = ACTIVEX | ACTIVEDOC | TYPELIB | GCF_PROTOCOL |
BHO_CLSID | BHO_REGISTRATION;
HRESULT hr = CustomRegistration(flags, TRUE, false);
if (SUCCEEDED(hr)) {
SetupRunOnce();
}
return hr;
}
STDAPI DllUnregisterUserServer() {
HRESULT hr = CustomRegistration(ALL, FALSE, false);
return hr;
}
OBJECT_ENTRY_AUTO(CLSID_ChromeFrameBHO, Bho)
OBJECT_ENTRY_AUTO(__uuidof(ChromeActiveDocument), ChromeActiveDocument)
OBJECT_ENTRY_AUTO(__uuidof(ChromeFrame), ChromeFrameActivex)
OBJECT_ENTRY_AUTO(__uuidof(ChromeProtocol), ChromeProtocol)