| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 <OAidl.h> | |
| 9 #include <objidl.h> | |
| 10 #include <windows.h> | |
| 11 #include <wininet.h> | |
| 12 #include <string> | |
| 13 #include <vector> | |
| 14 | |
| 15 #include "base/basictypes.h" | |
| 16 #include "base/logging.h" | |
| 17 #include "base/metrics/histogram.h" | |
| 18 #include "base/strings/string16.h" | |
| 19 #include "base/win/scoped_comptr.h" | |
| 20 #include "ui/gfx/rect.h" | |
| 21 #include "url/gurl.h" | |
| 22 | |
| 23 class RegistryListPreferencesHolder; | |
| 24 interface IBrowserService; | |
| 25 interface IWebBrowser2; | |
| 26 struct ContextMenuModel; | |
| 27 | |
| 28 namespace base { | |
| 29 class FilePath; | |
| 30 } | |
| 31 | |
| 32 // utils.h : Various utility functions and classes | |
| 33 extern const char kGCFProtocol[]; | |
| 34 | |
| 35 extern const wchar_t kAllowUnsafeURLs[]; | |
| 36 extern const wchar_t kChromeContentPrefix[]; | |
| 37 extern const wchar_t kChromeFrameAccessibleMode[]; | |
| 38 extern const wchar_t kChromeFrameAttachTabPattern[]; | |
| 39 extern const wchar_t kChromeFrameConfigKey[]; | |
| 40 extern const wchar_t kChromeFrameHeadlessMode[]; | |
| 41 extern const wchar_t kChromeFrameUnpinnedMode[]; | |
| 42 extern const wchar_t kChromeMimeType[]; | |
| 43 extern const wchar_t kChromeProtocolPrefix[]; | |
| 44 extern const wchar_t kEnableBuggyBhoIntercept[]; | |
| 45 extern const wchar_t kEnableGCFRendererByDefault[]; | |
| 46 extern const wchar_t kExcludeUAFromDomainList[]; | |
| 47 extern const wchar_t kIexploreProfileName[]; | |
| 48 extern const wchar_t kRenderInGCFUrlList[]; | |
| 49 extern const wchar_t kRenderInHostUrlList[]; | |
| 50 extern const wchar_t kRundllProfileName[]; | |
| 51 extern const wchar_t kUseBackgroundThreadForSubResources[]; | |
| 52 | |
| 53 // This function is very similar to the AtlRegisterTypeLib function except | |
| 54 // that it takes a parameter that specifies whether to register the typelib | |
| 55 // for the current user only or on a machine-wide basis | |
| 56 // Refer to the MSDN documentation for AtlRegisterTypeLib for a description of | |
| 57 // the arguments | |
| 58 HRESULT UtilRegisterTypeLib(HINSTANCE tlb_instance, | |
| 59 LPCOLESTR index, | |
| 60 bool for_current_user_only); | |
| 61 | |
| 62 // This function is very similar to the AtlUnRegisterTypeLib function except | |
| 63 // that it takes a parameter that specifies whether to unregister the typelib | |
| 64 // for the current user only or on a machine-wide basis | |
| 65 // Refer to the MSDN documentation for AtlUnRegisterTypeLib for a description | |
| 66 // of the arguments | |
| 67 HRESULT UtilUnRegisterTypeLib(HINSTANCE tlb_instance, | |
| 68 LPCOLESTR index, | |
| 69 bool for_current_user_only); | |
| 70 | |
| 71 HRESULT UtilRegisterTypeLib(LPCWSTR typelib_path, bool for_current_user_only); | |
| 72 | |
| 73 HRESULT UtilUnRegisterTypeLib(LPCWSTR typelib_path, bool for_current_user_only); | |
| 74 | |
| 75 HRESULT UtilRegisterTypeLib(ITypeLib* typelib, | |
| 76 LPCWSTR typelib_path, | |
| 77 LPCWSTR help_dir, | |
| 78 bool for_current_user_only); | |
| 79 | |
| 80 HRESULT UtilUnRegisterTypeLib(ITypeLib* typelib, | |
| 81 bool for_current_user_only); | |
| 82 | |
| 83 // Clears a marker that causes legacy NPAPI registration to persist across | |
| 84 // updates. Returns false if the marker could not be removed. | |
| 85 bool UtilRemovePersistentNPAPIMarker(); | |
| 86 | |
| 87 // Given an HTML fragment, this function looks for the | |
| 88 // <meta http-equiv="X-UA-Compatible"> tag and extracts the value of the | |
| 89 // "content" attribute | |
| 90 // This method will currently return a false positive if the tag appears | |
| 91 // inside a string in a <SCRIPT> block. | |
| 92 HRESULT UtilGetXUACompatContentValue(const std::wstring& html_string, | |
| 93 std::wstring* content_value); | |
| 94 | |
| 95 // Returns a string from ChromeFrame's string table by resource. Must be | |
| 96 // provided with a valid resource id. | |
| 97 std::wstring GetResourceString(int resource_id); | |
| 98 | |
| 99 // Displays a message box indicating that there was a version mismatch between | |
| 100 // ChromeFrame and the running instance of Chrome. | |
| 101 // server_version is the version of the running instance of Chrome. | |
| 102 void DisplayVersionMismatchWarning(HWND parent, | |
| 103 const std::string& server_version); | |
| 104 | |
| 105 // This class provides a base implementation for ATL modules which want to | |
| 106 // perform all their registration under HKCU. This class overrides the | |
| 107 // RegisterServer and UnregisterServer methods and registers the type libraries | |
| 108 // under HKCU (the rest of the registration is made under HKCU by changing the | |
| 109 // appropriate .RGS files) | |
| 110 template < class BaseAtlModule > | |
| 111 class AtlPerUserModule : public BaseAtlModule { | |
| 112 public: | |
| 113 HRESULT RegisterServer(BOOL reg_typelib = FALSE, | |
| 114 const CLSID* clsid = NULL) throw() { | |
| 115 HRESULT hr = BaseAtlModule::RegisterServer(FALSE, clsid); | |
| 116 if (FAILED(hr)) { | |
| 117 return hr; | |
| 118 } | |
| 119 if (reg_typelib) { | |
| 120 hr = UtilRegisterTypeLib(_AtlComModule.m_hInstTypeLib, NULL, false); | |
| 121 } | |
| 122 return hr; | |
| 123 } | |
| 124 | |
| 125 HRESULT UnregisterServer(BOOL unreg_typelib, | |
| 126 const CLSID* clsid = NULL) throw() { | |
| 127 HRESULT hr = BaseAtlModule::UnregisterServer(FALSE, clsid); | |
| 128 if (FAILED(hr)) { | |
| 129 return hr; | |
| 130 } | |
| 131 if (unreg_typelib) { | |
| 132 hr = UtilUnRegisterTypeLib(_AtlComModule.m_hInstTypeLib, NULL, false); | |
| 133 } | |
| 134 return hr; | |
| 135 } | |
| 136 }; | |
| 137 | |
| 138 // Creates a javascript statement for execution from the function name and | |
| 139 // arguments passed in. | |
| 140 std::string CreateJavascript(const std::string& function_name, | |
| 141 const std::string args); | |
| 142 | |
| 143 // Use to prevent the DLL from being unloaded while there are still living | |
| 144 // objects with outstanding references. | |
| 145 class AddRefModule { | |
| 146 public: | |
| 147 AddRefModule(); | |
| 148 ~AddRefModule(); | |
| 149 }; | |
| 150 | |
| 151 // Retrieves the executable name of the process hosting us. If | |
| 152 // |include_extension| is false, then we strip the extension from the name. | |
| 153 std::wstring GetHostProcessName(bool include_extension); | |
| 154 | |
| 155 typedef enum BrowserType { | |
| 156 BROWSER_INVALID = -1, | |
| 157 BROWSER_UNKNOWN, | |
| 158 BROWSER_IE, | |
| 159 }; | |
| 160 | |
| 161 BrowserType GetBrowserType(); | |
| 162 | |
| 163 typedef enum IEVersion { | |
| 164 IE_INVALID, | |
| 165 NON_IE, | |
| 166 IE_UNSUPPORTED, | |
| 167 IE_6, | |
| 168 IE_7, | |
| 169 IE_8, | |
| 170 IE_9, | |
| 171 IE_10, | |
| 172 IE_11, | |
| 173 }; | |
| 174 | |
| 175 // The renderer to be used for a page. Values for Chrome also convey the | |
| 176 // reason why Chrome is used. | |
| 177 enum RendererType { | |
| 178 RENDERER_TYPE_UNDETERMINED = 0, | |
| 179 RENDERER_TYPE_CHROME_MIN, | |
| 180 // NOTE: group all _CHROME_ values together below here, as they are used for | |
| 181 // generating metrics reported via UMA (adjust MIN/MAX as needed). | |
| 182 RENDERER_TYPE_CHROME_GCF_PROTOCOL = RENDERER_TYPE_CHROME_MIN, | |
| 183 RENDERER_TYPE_CHROME_HTTP_EQUIV, | |
| 184 RENDERER_TYPE_CHROME_RESPONSE_HEADER, | |
| 185 RENDERER_TYPE_CHROME_DEFAULT_RENDERER, | |
| 186 RENDERER_TYPE_CHROME_OPT_IN_URL, | |
| 187 RENDERER_TYPE_CHROME_WIDGET, | |
| 188 // NOTE: all _CHOME_ values must go above here (adjust MIN/MAX as needed). | |
| 189 RENDERER_TYPE_CHROME_MAX = RENDERER_TYPE_CHROME_WIDGET, | |
| 190 RENDERER_TYPE_OTHER, | |
| 191 }; | |
| 192 | |
| 193 // Returns true if the given RendererType represents Chrome. | |
| 194 bool IsChrome(RendererType renderer_type); | |
| 195 | |
| 196 // Convenience macro for logging a sample for the launch type metric. | |
| 197 #define UMA_LAUNCH_TYPE_COUNT(sample) \ | |
| 198 UMA_HISTOGRAM_CUSTOM_COUNTS("ChromeFrame.LaunchType", sample, \ | |
| 199 RENDERER_TYPE_CHROME_MIN, RENDERER_TYPE_CHROME_MAX, \ | |
| 200 RENDERER_TYPE_CHROME_MAX + 1 - RENDERER_TYPE_CHROME_MIN) | |
| 201 | |
| 202 // To get the IE version when Chrome Frame is hosted in IE. Make sure that | |
| 203 // the hosting browser is IE before calling this function, otherwise NON_IE | |
| 204 // will be returned. | |
| 205 // | |
| 206 // Versions newer than the newest supported version are reported as the newest | |
| 207 // supported version. | |
| 208 IEVersion GetIEVersion(); | |
| 209 | |
| 210 // Returns the actual major version of the IE in which the current process is | |
| 211 // hosted. Returns 0 if the current process is not IE or any other error occurs. | |
| 212 uint32 GetIEMajorVersion(); | |
| 213 | |
| 214 base::FilePath GetIETemporaryFilesFolder(); | |
| 215 | |
| 216 // Retrieves the file version from a module handle without extra round trips | |
| 217 // to the disk (as happens with the regular GetFileVersionInfo API). | |
| 218 // | |
| 219 // @param module A handle to the module for which to retrieve the version info. | |
| 220 // @param high On successful return holds the most significant part of the file | |
| 221 // version. Must be non-null. | |
| 222 // @param low On successful return holds the least significant part of the file | |
| 223 // version. May be NULL. | |
| 224 // @returns true if the version info was successfully retrieved. | |
| 225 bool GetModuleVersion(HMODULE module, uint32* high, uint32* low); | |
| 226 | |
| 227 // Return if the IEXPLORE is in private mode. The IEIsInPrivateBrowsing() checks | |
| 228 // whether current process is IEXPLORE. | |
| 229 bool IsIEInPrivate(); | |
| 230 | |
| 231 // Calls [ieframe|shdocvw]!DoFileDownload to initiate a download. | |
| 232 HRESULT DoFileDownloadInIE(const wchar_t* url); | |
| 233 | |
| 234 // Uses GURL internally to append 'relative' to 'document' | |
| 235 std::string ResolveURL(const std::string& document, | |
| 236 const std::string& relative); | |
| 237 | |
| 238 // Returns true iff the two urls have the same scheme, same host and same port. | |
| 239 bool HaveSameOrigin(const std::string& url1, const std::string& url2); | |
| 240 | |
| 241 // Get a boolean configuration value from registry. | |
| 242 bool GetConfigBool(bool default_value, const wchar_t* value_name); | |
| 243 | |
| 244 // Gets an integer configuration value from the registry. | |
| 245 int GetConfigInt(int default_value, const wchar_t* value_name); | |
| 246 | |
| 247 // Gets a 64-bit integer configuration value from the registry. | |
| 248 int64 GetConfigInt64(int64 default_value, const wchar_t* value_name); | |
| 249 | |
| 250 // Sets an integer configuration value in the registry. | |
| 251 bool SetConfigInt(const wchar_t* value_name, int value); | |
| 252 | |
| 253 // Sets a boolean integer configuration value in the registry. | |
| 254 bool SetConfigBool(const wchar_t* value_name, bool value); | |
| 255 | |
| 256 // Sets a 64-bit integer configuration value in the registry. | |
| 257 bool SetConfigInt64(const wchar_t* value_name, int64 value); | |
| 258 | |
| 259 // Deletes the configuration value passed in. | |
| 260 bool DeleteConfigValue(const wchar_t* value_name); | |
| 261 | |
| 262 // Returns true if we are running in headless mode in which case we need to | |
| 263 // gather crash dumps, etc to send them to the crash server. | |
| 264 bool IsHeadlessMode(); | |
| 265 | |
| 266 // Returns true if we are running in accessible mode in which we need to enable | |
| 267 // renderer accessibility for use in automation. | |
| 268 bool IsAccessibleMode(); | |
| 269 | |
| 270 // Returns true if we are running in unpinned mode in which case DLL | |
| 271 // eviction should be possible. | |
| 272 bool IsUnpinnedMode(); | |
| 273 | |
| 274 // Returns true if all HTML pages should be rendered in GCF by default. | |
| 275 bool IsGcfDefaultRenderer(); | |
| 276 | |
| 277 // Returns true if the presence of | |
| 278 // <meta http-equiv="X-UA-Compatible" content="chrome=1"> | |
| 279 // in HTML pages should be ignored | |
| 280 bool SkipMetadataCheck(); | |
| 281 | |
| 282 // Check if this url is opting into Chrome Frame based on static settings. | |
| 283 // Returns one of: | |
| 284 // - RENDERER_TYPE_UNDETERMINED if not opt-in or if explicit opt-out | |
| 285 // - RENDERER_TYPE_CHROME_DEFAULT_RENDERER | |
| 286 // - RENDERER_TYPE_CHROME_OPT_IN_URL | |
| 287 RendererType RendererTypeForUrl(const std::wstring& url); | |
| 288 | |
| 289 // Check if we should try to remove the CF user agent based on registry | |
| 290 // settings. | |
| 291 bool ShouldRemoveUAForUrl(const base::string16& url); | |
| 292 | |
| 293 // Testing methods that return the backing stores behind RendererTypeForUrl and | |
| 294 // ShouldRemoveUAForUrl. Intended to allow unit testing code that calls the | |
| 295 // above methods. | |
| 296 // TODO(robertshield): All of the FooForUrl code should be removed from here | |
| 297 // and further refactored. | |
| 298 RegistryListPreferencesHolder& GetRendererTypePreferencesHolderForTesting(); | |
| 299 RegistryListPreferencesHolder& GetUserAgentPreferencesHolderForTesting(); | |
| 300 | |
| 301 // A shortcut for QueryService | |
| 302 template <typename T> | |
| 303 HRESULT DoQueryService(const IID& service_id, IUnknown* unk, T** service) { | |
| 304 DCHECK(service); | |
| 305 if (!unk) | |
| 306 return E_INVALIDARG; | |
| 307 | |
| 308 base::win::ScopedComPtr<IServiceProvider> service_provider; | |
| 309 HRESULT hr = service_provider.QueryFrom(unk); | |
| 310 if (service_provider) | |
| 311 hr = service_provider->QueryService(service_id, service); | |
| 312 | |
| 313 DCHECK(FAILED(hr) || *service); | |
| 314 return hr; | |
| 315 } | |
| 316 | |
| 317 // Navigates an IWebBrowser2 object to a moniker. | |
| 318 // |headers| can be NULL. | |
| 319 HRESULT NavigateBrowserToMoniker(IUnknown* browser, IMoniker* moniker, | |
| 320 const wchar_t* headers, IBindCtx* bind_ctx, | |
| 321 const wchar_t* fragment, IStream* post_data, | |
| 322 VARIANT* flags); | |
| 323 | |
| 324 // Raises a flag on the current thread (using TLS) to indicate that an | |
| 325 // in-progress navigation should be rendered in chrome frame. | |
| 326 void MarkBrowserOnThreadForCFNavigation(IBrowserService* browser); | |
| 327 | |
| 328 // Checks if this browser instance has been marked as currently navigating | |
| 329 // to a CF document. If clear_flag is set to true, the tls flag is cleared but | |
| 330 // only if the browser has been marked. | |
| 331 bool CheckForCFNavigation(IBrowserService* browser, bool clear_flag); | |
| 332 | |
| 333 // Returns true if the URL passed in is something which can be handled by | |
| 334 // Chrome. If this function returns false then we should fail the navigation. | |
| 335 // When is_privileged is true, chrome extension URLs will be considered valid. | |
| 336 bool IsValidUrlScheme(const GURL& url, bool is_privileged); | |
| 337 | |
| 338 // Returns the raw http headers for the current request given an | |
| 339 // IWinInetHttpInfo pointer. | |
| 340 std::string GetRawHttpHeaders(IWinInetHttpInfo* info); | |
| 341 | |
| 342 // Can be used to determine whether a given request is being performed for | |
| 343 // a sub-frame or iframe in Internet Explorer. This can be called | |
| 344 // from various places, notably in request callbacks and the like. | |
| 345 // | |
| 346 // |service_provider| must not be NULL and should be a pointer to something | |
| 347 // that implements IServiceProvider (if it isn't this method returns false). | |
| 348 // | |
| 349 // Returns true if this method can determine with some certainty that the | |
| 350 // request did NOT originate from a top level frame, returns false otherwise. | |
| 351 bool IsSubFrameRequest(IUnknown* service_provider); | |
| 352 | |
| 353 // See COM_INTERFACE_BLIND_DELEGATE below for details. | |
| 354 template <class T> | |
| 355 STDMETHODIMP CheckOutgoingInterface(void* obj, REFIID iid, void** ret, | |
| 356 DWORD cookie) { | |
| 357 T* instance = reinterpret_cast<T*>(obj); | |
| 358 HRESULT hr = E_NOINTERFACE; | |
| 359 IUnknown* delegate = instance ? instance->delegate() : NULL; | |
| 360 if (delegate) { | |
| 361 hr = delegate->QueryInterface(iid, ret); | |
| 362 #if !defined(NDEBUG) | |
| 363 if (SUCCEEDED(hr)) { | |
| 364 wchar_t iid_string[64] = {0}; | |
| 365 StringFromGUID2(iid, iid_string, arraysize(iid_string)); | |
| 366 DVLOG(1) << __FUNCTION__ << " Giving out wrapped interface: " | |
| 367 << iid_string; | |
| 368 } | |
| 369 #endif | |
| 370 } | |
| 371 | |
| 372 return hr; | |
| 373 } | |
| 374 | |
| 375 // See COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS below for details. | |
| 376 template <class T> | |
| 377 STDMETHODIMP QueryInterfaceIfDelegateSupports(void* obj, REFIID iid, | |
| 378 void** ret, DWORD cookie) { | |
| 379 HRESULT hr = E_NOINTERFACE; | |
| 380 T* instance = reinterpret_cast<T*>(obj); | |
| 381 IUnknown* delegate = instance ? instance->delegate() : NULL; | |
| 382 if (delegate) { | |
| 383 base::win::ScopedComPtr<IUnknown> original; | |
| 384 hr = delegate->QueryInterface(iid, | |
| 385 reinterpret_cast<void**>(original.Receive())); | |
| 386 if (original) { | |
| 387 IUnknown* supported_interface = reinterpret_cast<IUnknown*>( | |
| 388 reinterpret_cast<DWORD_PTR>(obj) + cookie); | |
| 389 supported_interface->AddRef(); | |
| 390 *ret = supported_interface; | |
| 391 hr = S_OK; | |
| 392 } | |
| 393 } | |
| 394 | |
| 395 return hr; | |
| 396 } | |
| 397 | |
| 398 // Same as COM_INTERFACE_ENTRY but relies on the class to implement a | |
| 399 // delegate() method that returns a pointer to the delegated COM object. | |
| 400 #define COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS(x) \ | |
| 401 COM_INTERFACE_ENTRY_FUNC(_ATL_IIDOF(x), \ | |
| 402 offsetofclass(x, _ComMapClass), \ | |
| 403 QueryInterfaceIfDelegateSupports<_ComMapClass>) | |
| 404 | |
| 405 // Queries the delegated COM object for an interface, bypassing the wrapper. | |
| 406 #define COM_INTERFACE_BLIND_DELEGATE() \ | |
| 407 COM_INTERFACE_ENTRY_FUNC_BLIND(0, CheckOutgoingInterface<_ComMapClass>) | |
| 408 | |
| 409 std::wstring GuidToString(const GUID& guid); | |
| 410 | |
| 411 // The urls retrieved from the IMoniker interface don't contain the anchor | |
| 412 // portion of the actual url navigated to. This function checks whether the | |
| 413 // url passed in the bho_url parameter contains an anchor and if yes checks | |
| 414 // whether it matches the url retrieved from the moniker. If yes it returns | |
| 415 // the bho url, if not the moniker url. | |
| 416 std::wstring GetActualUrlFromMoniker(IMoniker* moniker, | |
| 417 IBindCtx* bind_context, | |
| 418 const std::wstring& bho_url); | |
| 419 | |
| 420 // Checks if a window is a top level window | |
| 421 bool IsTopLevelWindow(HWND window); | |
| 422 | |
| 423 // Seeks a stream back to position 0. | |
| 424 HRESULT RewindStream(IStream* stream); | |
| 425 | |
| 426 // Fired when we want to notify IE about privacy changes. | |
| 427 #define WM_FIRE_PRIVACY_CHANGE_NOTIFICATION (WM_APP + 1) | |
| 428 | |
| 429 // This structure contains the parameters sent over to initiate a download | |
| 430 // request in the host browser. | |
| 431 struct DownloadInHostParams { | |
| 432 base::win::ScopedComPtr<IBindCtx> bind_ctx; | |
| 433 base::win::ScopedComPtr<IMoniker> moniker; | |
| 434 base::win::ScopedComPtr<IStream> post_data; | |
| 435 std::string request_headers; | |
| 436 }; | |
| 437 | |
| 438 // Maps the InternetCookieState enum to the corresponding CookieAction values | |
| 439 // used for IE privacy stuff. | |
| 440 int32 MapCookieStateToCookieAction(InternetCookieState cookie_state); | |
| 441 | |
| 442 // Parses the url passed in and returns a GURL instance without the fragment. | |
| 443 GURL GetUrlWithoutFragment(const wchar_t* url); | |
| 444 | |
| 445 // Compares the URLs passed in after removing the fragments from them. | |
| 446 bool CompareUrlsWithoutFragment(const wchar_t* url1, const wchar_t* url2); | |
| 447 | |
| 448 // Returns the Referrer from the HTTP headers and additional headers. | |
| 449 std::string FindReferrerFromHeaders(const wchar_t* headers, | |
| 450 const wchar_t* additional_headers); | |
| 451 | |
| 452 // Returns the HTTP headers from the binding passed in. | |
| 453 std::string GetHttpHeadersFromBinding(IBinding* binding); | |
| 454 | |
| 455 // Returns the HTTP response code from the binding passed in. | |
| 456 int GetHttpResponseStatusFromBinding(IBinding* binding); | |
| 457 | |
| 458 // Returns the clipboard format for text/html. | |
| 459 CLIPFORMAT GetTextHtmlClipboardFormat(); | |
| 460 | |
| 461 // Returns true iff the mime type is text/html. | |
| 462 bool IsTextHtmlMimeType(const wchar_t* mime_type); | |
| 463 | |
| 464 // Returns true iff the clipboard format is text/html. | |
| 465 bool IsTextHtmlClipFormat(CLIPFORMAT cf); | |
| 466 | |
| 467 // Returns true if we can detect that we are running as SYSTEM, false otherwise. | |
| 468 bool IsSystemProcess(); | |
| 469 | |
| 470 // STL helper class that implements a functor to delete objects. | |
| 471 // E.g: std::for_each(v.begin(), v.end(), utils::DeleteObject()); | |
| 472 namespace utils { | |
| 473 class DeleteObject { | |
| 474 public: | |
| 475 template <typename T> | |
| 476 void operator()(T* obj) { | |
| 477 delete obj; | |
| 478 } | |
| 479 }; | |
| 480 } | |
| 481 | |
| 482 // Convert various protocol flags to text representation. Used for logging. | |
| 483 std::string BindStatus2Str(ULONG bind_status); | |
| 484 std::string PiFlags2Str(DWORD flags); | |
| 485 std::string Bscf2Str(DWORD flags); | |
| 486 | |
| 487 // Reads data from a stream into a string. | |
| 488 HRESULT ReadStream(IStream* stream, size_t size, std::string* data); | |
| 489 | |
| 490 // Parses urls targeted at ChromeFrame. This class maintains state like | |
| 491 // whether a url is prefixed with the gcf: prefix, whether it is being | |
| 492 // attached to an existing external tab, etc. | |
| 493 class ChromeFrameUrl { | |
| 494 public: | |
| 495 ChromeFrameUrl(); | |
| 496 | |
| 497 // Parses the url passed in. Returns true on success. | |
| 498 bool Parse(const std::wstring& url); | |
| 499 | |
| 500 bool is_chrome_protocol() const { | |
| 501 return is_chrome_protocol_; | |
| 502 } | |
| 503 | |
| 504 bool attach_to_external_tab() const { | |
| 505 return attach_to_external_tab_; | |
| 506 } | |
| 507 | |
| 508 uint64 cookie() const { | |
| 509 return cookie_; | |
| 510 } | |
| 511 | |
| 512 int disposition() const { | |
| 513 return disposition_; | |
| 514 } | |
| 515 | |
| 516 const gfx::Rect& dimensions() const { | |
| 517 return dimensions_; | |
| 518 } | |
| 519 | |
| 520 const GURL& gurl() const { | |
| 521 return parsed_url_; | |
| 522 } | |
| 523 | |
| 524 const std::string& profile_name() const { | |
| 525 return profile_name_; | |
| 526 } | |
| 527 | |
| 528 private: | |
| 529 // If we are attaching to an existing external tab, this function parses the | |
| 530 // suffix portion of the URL which contains the attach_external_tab prefix. | |
| 531 bool ParseAttachExternalTabUrl(); | |
| 532 | |
| 533 // Clear state. | |
| 534 void Reset(); | |
| 535 | |
| 536 bool attach_to_external_tab_; | |
| 537 bool is_chrome_protocol_; | |
| 538 uint64 cookie_; | |
| 539 gfx::Rect dimensions_; | |
| 540 int disposition_; | |
| 541 | |
| 542 GURL parsed_url_; | |
| 543 std::string profile_name_; | |
| 544 }; | |
| 545 | |
| 546 class NavigationConstraints; | |
| 547 // Returns true if we can navigate to this URL. | |
| 548 // These decisions are controlled by the NavigationConstraints object passed | |
| 549 // in. | |
| 550 bool CanNavigate(const GURL& url, | |
| 551 NavigationConstraints* navigation_constraints); | |
| 552 | |
| 553 // Helper function to spin a message loop and dispatch messages while waiting | |
| 554 // for a handle to be signaled. | |
| 555 void WaitWithMessageLoop(HANDLE* handles, int count, DWORD timeout); | |
| 556 | |
| 557 // Enumerates values in a key and adds them to an array. | |
| 558 // The names of the values are not returned. | |
| 559 void EnumerateKeyValues(HKEY parent_key, const wchar_t* sub_key_name, | |
| 560 std::vector<std::wstring>* values); | |
| 561 | |
| 562 // Interprets the value of an X-UA-Compatible header (or <meta> tag equivalent) | |
| 563 // and indicates whether the header value contains a Chrome Frame directive | |
| 564 // matching a given host browser version. | |
| 565 // | |
| 566 // The header is a series of name-value pairs, with the names being HTTP tokens | |
| 567 // and the values being either tokens or quoted-strings. Names and values are | |
| 568 // joined by '=' and pairs are delimited by either ';' or ','. LWS may be used | |
| 569 // liberally before and between names, values, '=', and ';' or ','. See RFC 2616 | |
| 570 // for definitions of token, quoted-string, and LWS. See Microsoft's | |
| 571 // documentation of the X-UA-COMPATIBLE header here: | |
| 572 // http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx | |
| 573 // | |
| 574 // At most one 'Chrome=<FILTER>' entry is expected in the header value. The | |
| 575 // first valid instance is used. The value of "<FILTER>" (possibly after | |
| 576 // unquoting) is interpreted as follows: | |
| 577 // | |
| 578 // "1" - Always active | |
| 579 // "IE7" - Active for IE major version 7 or lower | |
| 580 // | |
| 581 // For example: | |
| 582 // X-UA-Compatible: IE=8; Chrome=IE6 | |
| 583 // | |
| 584 // The string is first interpreted using ';' as a delimiter. It is reevaluated | |
| 585 // using ',' iff no valid 'chrome=' value is found. | |
| 586 bool CheckXUaCompatibleDirective(const std::string& directive, | |
| 587 int ie_major_version); | |
| 588 | |
| 589 // Returns the version of the current module as a string. | |
| 590 std::wstring GetCurrentModuleVersion(); | |
| 591 | |
| 592 // Returns true if ChromeFrame is the currently loaded document. | |
| 593 bool IsChromeFrameDocument(IWebBrowser2* web_browser); | |
| 594 | |
| 595 // Increases the wininet connection limit for HTTP 1.0/1.1 connections to the | |
| 596 // value passed in. This is only done if the existing connection limit is | |
| 597 // lesser than the connection limit passed in. This function attempts to | |
| 598 // increase the connection count once per process. | |
| 599 // Returns true on success. | |
| 600 bool IncreaseWinInetConnections(DWORD connections); | |
| 601 | |
| 602 // Sets |profile_path| to the path for the Chrome Frame |profile_name| | |
| 603 // profile. | |
| 604 void GetChromeFrameProfilePath(const base::string16& profile_name, | |
| 605 base::FilePath* profile_path); | |
| 606 | |
| 607 #endif // CHROME_FRAME_UTILS_H_ | |
| OLD | NEW |