OLD | NEW |
(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 #ifndef CHROME_FRAME_UTILS_H_ |
| 6 #define CHROME_FRAME_UTILS_H_ |
| 7 |
| 8 #include <atlbase.h> |
| 9 #include <string> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 |
| 13 // utils.h : Various utility functions and classes |
| 14 |
| 15 extern const wchar_t kChromeContentPrefix[]; |
| 16 extern const wchar_t kChromeProtocolPrefix[]; |
| 17 |
| 18 // This function is very similar to the AtlRegisterTypeLib function except |
| 19 // that it takes a parameter that specifies whether to register the typelib |
| 20 // for the current user only or on a machine-wide basis |
| 21 // Refer to the MSDN documentation for AtlRegisterTypeLib for a description of |
| 22 // the arguments |
| 23 HRESULT UtilRegisterTypeLib(HINSTANCE tlb_instance, |
| 24 LPCOLESTR index, |
| 25 bool for_current_user_only); |
| 26 |
| 27 // This function is very similar to the AtlUnRegisterTypeLib function except |
| 28 // that it takes a parameter that specifies whether to unregister the typelib |
| 29 // for the current user only or on a machine-wide basis |
| 30 // Refer to the MSDN documentation for AtlUnRegisterTypeLib for a description |
| 31 // of the arguments |
| 32 HRESULT UtilUnRegisterTypeLib(HINSTANCE tlb_instance, |
| 33 LPCOLESTR index, |
| 34 bool for_current_user_only); |
| 35 |
| 36 HRESULT UtilRegisterTypeLib(LPCWSTR typelib_path, bool for_current_user_only); |
| 37 |
| 38 HRESULT UtilUnRegisterTypeLib(LPCWSTR typelib_path, bool for_current_user_only); |
| 39 |
| 40 HRESULT UtilRegisterTypeLib(ITypeLib* typelib, |
| 41 LPCWSTR typelib_path, |
| 42 LPCWSTR help_dir, |
| 43 bool for_current_user_only); |
| 44 |
| 45 HRESULT UtilUnRegisterTypeLib(ITypeLib* typelib, |
| 46 bool for_current_user_only); |
| 47 |
| 48 // Given an HTML fragment, this function looks for the |
| 49 // <meta http-equiv="X-UA-Compatible"> tag and extracts the value of the |
| 50 // "content" attribute |
| 51 // This method will currently return a false positive if the tag appears |
| 52 // inside a string in a <SCRIPT> block. |
| 53 HRESULT UtilGetXUACompatContentValue(const std::wstring& html_string, |
| 54 std::wstring* content_value); |
| 55 |
| 56 |
| 57 // Appends |suffix| to the substring |channel_name| of |string| iff |
| 58 // the first instance of |channel_name| in |string| is not already followed by |
| 59 // |suffix|. |
| 60 // Returns true if |string| was modified. |
| 61 bool AppendSuffixToChannelName(std::wstring* string, |
| 62 const std::wstring& channel_name, |
| 63 const std::wstring& suffix); |
| 64 |
| 65 // Removes |suffix| from |string| if |string| contains |channel_name| followed |
| 66 // by |suffix|. |
| 67 // Returns true if |string| was modified. |
| 68 bool RemoveSuffixFromChannelName(std::wstring* string, |
| 69 const std::wstring& channel_name, |
| 70 const std::wstring& suffix); |
| 71 |
| 72 // Looks for and alters if found the Omaha configuration for Chrome in the |
| 73 // registry. This changes the auto-update release channel to prevent installed |
| 74 // builds of Chrome that include Chrome Frame from getting replaced by |
| 75 // Chrome updates without it. |
| 76 // Adds the Chrome Frame suffix if add_cf_suffix is true, removes it |
| 77 // otherwise. |
| 78 // Returns S_OK if the Chrome Omaha configuration was found and updated. |
| 79 // Returns S_FALSE if the configuration was found but didn't need updating. |
| 80 // Returns REGDB_E_READREGDB if the Chrome Omaha key could not be read. |
| 81 // Returns REGDB_E_WRITEREGDB if the Chrome Omaha key could not be written. |
| 82 HRESULT UtilUpdateOmahaConfig(bool add_cf_suffix); |
| 83 |
| 84 // Returns a string from ChromeFrame's string table by resource. Must be |
| 85 // provided with a valid resource id. |
| 86 std::wstring GetResourceString(int resource_id); |
| 87 |
| 88 // Displays a message box indicating that there was a version mismatch between |
| 89 // ChromeFrame and the running instance of Chrome. |
| 90 // server_version is the version of the running instance of Chrome. |
| 91 void DisplayVersionMismatchWarning(HWND parent, |
| 92 const std::string& server_version); |
| 93 |
| 94 // This class provides a base implementation for ATL modules which want to |
| 95 // perform all their registration under HKCU. This class overrides the |
| 96 // RegisterServer and UnregisterServer methods and registers the type libraries |
| 97 // under HKCU (the rest of the registation is made under HKCU by changing the |
| 98 // appropriate .RGS files) |
| 99 template < class BaseAtlModule > |
| 100 class AtlPerUserModule : public BaseAtlModule { |
| 101 public: |
| 102 HRESULT RegisterServer(BOOL reg_typelib = FALSE, |
| 103 const CLSID* clsid = NULL) throw() { |
| 104 HRESULT hr = BaseAtlModule::RegisterServer(FALSE, clsid); |
| 105 if (FAILED(hr)) { |
| 106 return hr; |
| 107 } |
| 108 if (reg_typelib) { |
| 109 hr = UtilRegisterTypeLib(_AtlComModule.m_hInstTypeLib, NULL, false); |
| 110 } |
| 111 return hr; |
| 112 } |
| 113 |
| 114 HRESULT UnregisterServer(BOOL unreg_typelib, |
| 115 const CLSID* clsid = NULL) throw() { |
| 116 HRESULT hr = BaseAtlModule::UnregisterServer(FALSE, clsid); |
| 117 if (FAILED(hr)) { |
| 118 return hr; |
| 119 } |
| 120 if (unreg_typelib) { |
| 121 hr = UtilUnRegisterTypeLib(_AtlComModule.m_hInstTypeLib, NULL, false); |
| 122 } |
| 123 return hr; |
| 124 } |
| 125 }; |
| 126 |
| 127 // Creates a javascript statement for execution from the function name and |
| 128 // arguments passed in. |
| 129 std::string CreateJavascript(const std::string& function_name, |
| 130 const std::string args); |
| 131 |
| 132 // Use to prevent the DLL from being unloaded while there are still living |
| 133 // objects with outstanding references. |
| 134 class AddRefModule { |
| 135 public: |
| 136 AddRefModule(); |
| 137 ~AddRefModule(); |
| 138 }; |
| 139 |
| 140 // Retrieves the executable name of the process hosting us. If |
| 141 // |include_extension| is false, then we strip the extension from the name. |
| 142 std::wstring GetHostProcessName(bool include_extension); |
| 143 |
| 144 typedef enum BrowserType { |
| 145 BROWSER_INVALID = -1, |
| 146 BROWSER_UNKNOWN, |
| 147 BROWSER_IE, |
| 148 BROWSER_FIREFOX, |
| 149 BROWSER_OPERA, |
| 150 }; |
| 151 |
| 152 BrowserType GetBrowserType(); |
| 153 |
| 154 typedef enum IEVersion { |
| 155 IE_INVALID, |
| 156 NON_IE, |
| 157 IE_UNSUPPORTED, |
| 158 IE_6, |
| 159 IE_7, |
| 160 IE_8, |
| 161 }; |
| 162 |
| 163 // To get the IE version when Chrome Frame is hosted in IE. Make sure that |
| 164 // the hosting browser is IE before calling this function, otherwise NON_IE |
| 165 // will be returned. |
| 166 IEVersion GetIEVersion(); |
| 167 |
| 168 // Retrieves the file version from a module handle without extra round trips |
| 169 // to the disk (as happens with the regular GetFileVersionInfo API). |
| 170 // |
| 171 // @param module A handle to the module for which to retrieve the version info. |
| 172 // @param high On successful return holds the most significant part of the |
| 173 // file version. Must be non-null. |
| 174 // @param low On successful return holds the least significant part of the |
| 175 // file version. May be NULL. |
| 176 // @returns true if the version info was successfully retrieved. |
| 177 bool GetModuleVersion(HMODULE module, uint32* high, uint32* low); |
| 178 |
| 179 // Return if the IEXPLORE is in private mode. The IEIsInPrivateBrowsing() checks |
| 180 // whether current process is IEXPLORE. |
| 181 bool IsIEInPrivate(); |
| 182 |
| 183 // Creates a copy of a menu. We need this when original menu comes from |
| 184 // a process with higher integrity. |
| 185 HMENU UtilCloneContextMenu(HMENU original_menu); |
| 186 |
| 187 // Uses GURL internally to append 'relative' to 'document' |
| 188 std::string ResolveURL(const std::string& document, |
| 189 const std::string& relative); |
| 190 |
| 191 // Returns true iff the two urls have the same scheme, same host and same port. |
| 192 bool HaveSameOrigin(const std::string& url1, const std::string& url2); |
| 193 |
| 194 // Get a boolean configuration value from registry. |
| 195 bool GetConfigBool(bool default_value, const wchar_t* value_name); |
| 196 |
| 197 // Gets an integer configuration value from the registry. |
| 198 int GetConfigInt(int default_value, const wchar_t* value_name); |
| 199 |
| 200 // Check if this url is opting into Chrome Frame based on static settings. |
| 201 bool IsOptInUrl(const wchar_t* url); |
| 202 |
| 203 // A shortcut for QueryService |
| 204 template <typename T> |
| 205 HRESULT DoQueryService(const CLSID& class_id, IUnknown* unk, T** service) { |
| 206 if (!unk) |
| 207 return E_INVALIDARG; |
| 208 ScopedComPtr<IServiceProvider> service_provider; |
| 209 HRESULT hr = service_provider.QueryFrom(unk); |
| 210 if (!service_provider) |
| 211 return hr; |
| 212 |
| 213 return service_provider->QueryService(class_id, service); |
| 214 } |
| 215 |
| 216 // Get url (display name) from a moniker, |bind_context| is optional |
| 217 HRESULT GetUrlFromMoniker(IMoniker* moniker, IBindCtx* bind_context, |
| 218 std::wstring* url); |
| 219 |
| 220 // Returns true if the URL passed in is something which can be handled by |
| 221 // Chrome. If this function returns false then we should fail the navigation. |
| 222 bool IsValidUrlScheme(const std::wstring& url); |
| 223 |
| 224 // This returns the base directory in which to store user profiles. |
| 225 bool GetUserProfileBaseDirectory(std::wstring* path); |
| 226 |
| 227 #endif // CHROME_FRAME_UTILS_H_ |
OLD | NEW |