| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_FRAME_UTILS_H_ | 5 #ifndef CHROME_FRAME_UTILS_H_ |
| 6 #define CHROME_FRAME_UTILS_H_ | 6 #define CHROME_FRAME_UTILS_H_ |
| 7 | 7 |
| 8 #include <atlbase.h> | 8 #include <atlbase.h> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/logging.h" |
| 12 | 13 |
| 13 // utils.h : Various utility functions and classes | 14 // utils.h : Various utility functions and classes |
| 14 | 15 |
| 15 extern const wchar_t kChromeContentPrefix[]; | 16 extern const wchar_t kChromeContentPrefix[]; |
| 16 extern const wchar_t kChromeProtocolPrefix[]; | 17 extern const wchar_t kChromeProtocolPrefix[]; |
| 17 | 18 |
| 18 // This function is very similar to the AtlRegisterTypeLib function except | 19 // This function is very similar to the AtlRegisterTypeLib function except |
| 19 // that it takes a parameter that specifies whether to register the typelib | 20 // 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 // for the current user only or on a machine-wide basis |
| 21 // Refer to the MSDN documentation for AtlRegisterTypeLib for a description of | 22 // Refer to the MSDN documentation for AtlRegisterTypeLib for a description of |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 bool GetConfigBool(bool default_value, const wchar_t* value_name); | 196 bool GetConfigBool(bool default_value, const wchar_t* value_name); |
| 196 | 197 |
| 197 // Gets an integer configuration value from the registry. | 198 // Gets an integer configuration value from the registry. |
| 198 int GetConfigInt(int default_value, const wchar_t* value_name); | 199 int GetConfigInt(int default_value, const wchar_t* value_name); |
| 199 | 200 |
| 200 // Check if this url is opting into Chrome Frame based on static settings. | 201 // Check if this url is opting into Chrome Frame based on static settings. |
| 201 bool IsOptInUrl(const wchar_t* url); | 202 bool IsOptInUrl(const wchar_t* url); |
| 202 | 203 |
| 203 // A shortcut for QueryService | 204 // A shortcut for QueryService |
| 204 template <typename T> | 205 template <typename T> |
| 205 HRESULT DoQueryService(const CLSID& class_id, IUnknown* unk, T** service) { | 206 HRESULT DoQueryService(const IID& service_id, IUnknown* unk, T** service) { |
| 207 DCHECK(service); |
| 206 if (!unk) | 208 if (!unk) |
| 207 return E_INVALIDARG; | 209 return E_INVALIDARG; |
| 208 ScopedComPtr<IServiceProvider> service_provider; | 210 ScopedComPtr<IServiceProvider> service_provider; |
| 209 HRESULT hr = service_provider.QueryFrom(unk); | 211 HRESULT hr = service_provider.QueryFrom(unk); |
| 210 if (!service_provider) | 212 if (!service_provider) |
| 211 return hr; | 213 return hr; |
| 212 | 214 |
| 213 return service_provider->QueryService(class_id, service); | 215 return service_provider->QueryService(service_id, service); |
| 214 } | 216 } |
| 215 | 217 |
| 216 // Get url (display name) from a moniker, |bind_context| is optional | 218 // Get url (display name) from a moniker, |bind_context| is optional |
| 217 HRESULT GetUrlFromMoniker(IMoniker* moniker, IBindCtx* bind_context, | 219 HRESULT GetUrlFromMoniker(IMoniker* moniker, IBindCtx* bind_context, |
| 218 std::wstring* url); | 220 std::wstring* url); |
| 219 | 221 |
| 220 // Returns true if the URL passed in is something which can be handled by | 222 // 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. | 223 // Chrome. If this function returns false then we should fail the navigation. |
| 222 // When is_privileged is true, chrome extension URLs will be considered valid. | 224 // When is_privileged is true, chrome extension URLs will be considered valid. |
| 223 bool IsValidUrlScheme(const std::wstring& url, bool is_privileged); | 225 bool IsValidUrlScheme(const std::wstring& url, bool is_privileged); |
| 224 | 226 |
| 225 // This returns the base directory in which to store user profiles. | 227 // This returns the base directory in which to store user profiles. |
| 226 bool GetUserProfileBaseDirectory(std::wstring* path); | 228 bool GetUserProfileBaseDirectory(std::wstring* path); |
| 227 | 229 |
| 230 // See COM_INTERFACE_BLIND_DELEGATE below for details. |
| 231 template <class T> |
| 232 STDMETHODIMP CheckOutgoingInterface(void* obj, REFIID iid, void** ret, |
| 233 DWORD cookie) { |
| 234 T* instance = reinterpret_cast<T*>(obj); |
| 235 HRESULT hr = E_NOINTERFACE; |
| 236 IUnknown* delegate = instance ? instance->delegate() : NULL; |
| 237 if (delegate) { |
| 238 hr = delegate->QueryInterface(iid, ret); |
| 239 #if !defined(NDEBUG) |
| 240 if (SUCCEEDED(hr)) { |
| 241 wchar_t iid_string[64] = {0}; |
| 242 StringFromGUID2(iid, iid_string, arraysize(iid_string)); |
| 243 DLOG(INFO) << __FUNCTION__ << " Giving out wrapped interface: " |
| 244 << iid_string; |
| 245 } |
| 246 #endif |
| 247 } |
| 248 |
| 249 return hr; |
| 250 } |
| 251 |
| 252 // See COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS below for details. |
| 253 template <class T> |
| 254 STDMETHODIMP QueryInterfaceIfDelegateSupports(void* obj, REFIID iid, |
| 255 void** ret, DWORD cookie) { |
| 256 HRESULT hr = E_NOINTERFACE; |
| 257 T* instance = reinterpret_cast<T*>(obj); |
| 258 IUnknown* delegate = instance ? instance->delegate() : NULL; |
| 259 if (delegate) { |
| 260 ScopedComPtr<IUnknown> original; |
| 261 hr = delegate->QueryInterface(iid, |
| 262 reinterpret_cast<void**>(original.Receive())); |
| 263 if (original) { |
| 264 IUnknown* supported_interface = reinterpret_cast<IUnknown*>( |
| 265 reinterpret_cast<DWORD_PTR>(obj) + cookie); |
| 266 supported_interface->AddRef(); |
| 267 *ret = supported_interface; |
| 268 hr = S_OK; |
| 269 } |
| 270 } |
| 271 |
| 272 return hr; |
| 273 } |
| 274 |
| 275 // Same as COM_INTERFACE_ENTRY but relies on the class to implement a |
| 276 // delegate() method that returns a pointer to the delegated COM object. |
| 277 #define COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS(x) \ |
| 278 COM_INTERFACE_ENTRY_FUNC(_ATL_IIDOF(x), \ |
| 279 offsetofclass(x, _ComMapClass), \ |
| 280 QueryInterfaceIfDelegateSupports<_ComMapClass>) |
| 281 |
| 282 // Queries the delegated COM object for an interface, bypassing the wrapper. |
| 283 #define COM_INTERFACE_BLIND_DELEGATE() \ |
| 284 COM_INTERFACE_ENTRY_FUNC_BLIND(0, CheckOutgoingInterface<_ComMapClass>) |
| 285 |
| 228 #endif // CHROME_FRAME_UTILS_H_ | 286 #endif // CHROME_FRAME_UTILS_H_ |
| OLD | NEW |