blob: a741b6501be506b827af65ea37a758a0dbcd9d0e [file] [log] [blame]
[email protected]9a182832012-02-10 18:45:581// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]f7817822009-09-24 05:11:582// 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
[email protected]b57f03232010-10-25 14:14:398#include <OAidl.h>
[email protected]f4fbae682011-02-28 22:18:339#include <objidl.h>
[email protected]b57f03232010-10-25 14:14:3910#include <windows.h>
[email protected]80b5a8d2010-03-19 16:50:4311#include <wininet.h>
[email protected]7ae80742010-03-25 22:02:2712#include <string>
[email protected]b57f03232010-10-25 14:14:3913#include <vector>
[email protected]7ae80742010-03-25 22:02:2714
[email protected]f7817822009-09-24 05:11:5815#include "base/basictypes.h"
[email protected]3f55e872009-10-17 04:48:3716#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3817#include "base/metrics/histogram.h"
[email protected]57319e12012-03-30 22:52:3418#include "base/string16.h"
[email protected]34b99632011-01-01 01:01:0619#include "base/threading/thread.h"
[email protected]0152b512010-12-21 00:52:0320#include "base/win/scoped_comptr.h"
[email protected]e33f99a12010-04-13 01:27:2221#include "googleurl/src/gurl.h"
[email protected]08397d52011-02-05 01:53:3822#include "ui/gfx/rect.h"
[email protected]e33f99a12010-04-13 01:27:2223
[email protected]864b1362010-08-19 03:49:3824class FilePath;
[email protected]57319e12012-03-30 22:52:3425class RegistryListPreferencesHolder;
[email protected]b57f03232010-10-25 14:14:3926interface IBrowserService;
[email protected]a17930d82011-02-11 23:12:3527interface IWebBrowser2;
[email protected]b516e2d2011-07-12 16:54:1228struct ContextMenuModel;
[email protected]864b1362010-08-19 03:49:3829
[email protected]f7817822009-09-24 05:11:5830// utils.h : Various utility functions and classes
[email protected]d266ce82010-08-13 21:33:4031extern const char kGCFProtocol[];
[email protected]57319e12012-03-30 22:52:3432
[email protected]d266ce82010-08-13 21:33:4033extern const wchar_t kAllowUnsafeURLs[];
[email protected]57319e12012-03-30 22:52:3434extern const wchar_t kChromeContentPrefix[];
35extern const wchar_t kChromeFrameAccessibleMode[];
[email protected]c4e45b32010-07-28 21:15:1536extern const wchar_t kChromeFrameAttachTabPattern[];
[email protected]e67a73f42010-08-31 15:05:0237extern const wchar_t kChromeFrameConfigKey[];
[email protected]57319e12012-03-30 22:52:3438extern const wchar_t kChromeFrameHeadlessMode[];
39extern const wchar_t kChromeFrameUnpinnedMode[];
40extern const wchar_t kChromeMimeType[];
41extern const wchar_t kChromeProtocolPrefix[];
42extern const wchar_t kEnableBuggyBhoIntercept[];
43extern const wchar_t kEnableGCFRendererByDefault[];
44extern const wchar_t kExcludeUAFromDomainList[];
45extern const wchar_t kIexploreProfileName[];
[email protected]e67a73f42010-08-31 15:05:0246extern const wchar_t kRenderInGCFUrlList[];
47extern const wchar_t kRenderInHostUrlList[];
[email protected]e67a73f42010-08-31 15:05:0248extern const wchar_t kRundllProfileName[];
[email protected]b0938a42011-10-05 20:59:3849extern const wchar_t kUseBackgroundThreadForSubResources[];
[email protected]051236f2010-03-12 22:06:1450
[email protected]f7817822009-09-24 05:11:5851// This function is very similar to the AtlRegisterTypeLib function except
52// that it takes a parameter that specifies whether to register the typelib
53// for the current user only or on a machine-wide basis
54// Refer to the MSDN documentation for AtlRegisterTypeLib for a description of
55// the arguments
56HRESULT UtilRegisterTypeLib(HINSTANCE tlb_instance,
57 LPCOLESTR index,
58 bool for_current_user_only);
59
60// This function is very similar to the AtlUnRegisterTypeLib function except
61// that it takes a parameter that specifies whether to unregister the typelib
62// for the current user only or on a machine-wide basis
63// Refer to the MSDN documentation for AtlUnRegisterTypeLib for a description
64// of the arguments
65HRESULT UtilUnRegisterTypeLib(HINSTANCE tlb_instance,
66 LPCOLESTR index,
67 bool for_current_user_only);
68
69HRESULT UtilRegisterTypeLib(LPCWSTR typelib_path, bool for_current_user_only);
70
71HRESULT UtilUnRegisterTypeLib(LPCWSTR typelib_path, bool for_current_user_only);
72
73HRESULT UtilRegisterTypeLib(ITypeLib* typelib,
74 LPCWSTR typelib_path,
75 LPCWSTR help_dir,
76 bool for_current_user_only);
77
78HRESULT UtilUnRegisterTypeLib(ITypeLib* typelib,
79 bool for_current_user_only);
80
[email protected]99d81e52011-06-29 02:29:5381// Clears a marker that causes legacy NPAPI registration to persist across
82// updates. Returns false if the marker could not be removed.
83bool UtilRemovePersistentNPAPIMarker();
[email protected]c41468f2009-11-11 20:39:1884
[email protected]f7817822009-09-24 05:11:5885// Given an HTML fragment, this function looks for the
86// <meta http-equiv="X-UA-Compatible"> tag and extracts the value of the
87// "content" attribute
88// This method will currently return a false positive if the tag appears
89// inside a string in a <SCRIPT> block.
90HRESULT UtilGetXUACompatContentValue(const std::wstring& html_string,
91 std::wstring* content_value);
92
[email protected]f7817822009-09-24 05:11:5893// Returns a string from ChromeFrame's string table by resource. Must be
94// provided with a valid resource id.
95std::wstring GetResourceString(int resource_id);
96
97// Displays a message box indicating that there was a version mismatch between
98// ChromeFrame and the running instance of Chrome.
99// server_version is the version of the running instance of Chrome.
100void DisplayVersionMismatchWarning(HWND parent,
101 const std::string& server_version);
102
103// This class provides a base implementation for ATL modules which want to
104// perform all their registration under HKCU. This class overrides the
105// RegisterServer and UnregisterServer methods and registers the type libraries
[email protected]e67a73f42010-08-31 15:05:02106// under HKCU (the rest of the registration is made under HKCU by changing the
[email protected]f7817822009-09-24 05:11:58107// appropriate .RGS files)
108template < class BaseAtlModule >
109class AtlPerUserModule : public BaseAtlModule {
[email protected]e67a73f42010-08-31 15:05:02110 public:
[email protected]f7817822009-09-24 05:11:58111 HRESULT RegisterServer(BOOL reg_typelib = FALSE,
112 const CLSID* clsid = NULL) throw() {
113 HRESULT hr = BaseAtlModule::RegisterServer(FALSE, clsid);
114 if (FAILED(hr)) {
115 return hr;
116 }
117 if (reg_typelib) {
118 hr = UtilRegisterTypeLib(_AtlComModule.m_hInstTypeLib, NULL, false);
119 }
120 return hr;
121 }
122
123 HRESULT UnregisterServer(BOOL unreg_typelib,
124 const CLSID* clsid = NULL) throw() {
125 HRESULT hr = BaseAtlModule::UnregisterServer(FALSE, clsid);
126 if (FAILED(hr)) {
127 return hr;
128 }
129 if (unreg_typelib) {
130 hr = UtilUnRegisterTypeLib(_AtlComModule.m_hInstTypeLib, NULL, false);
131 }
132 return hr;
133 }
134};
135
136// Creates a javascript statement for execution from the function name and
137// arguments passed in.
138std::string CreateJavascript(const std::string& function_name,
139 const std::string args);
140
141// Use to prevent the DLL from being unloaded while there are still living
142// objects with outstanding references.
143class AddRefModule {
144 public:
145 AddRefModule();
146 ~AddRefModule();
147};
148
149// Retrieves the executable name of the process hosting us. If
150// |include_extension| is false, then we strip the extension from the name.
151std::wstring GetHostProcessName(bool include_extension);
152
153typedef enum BrowserType {
154 BROWSER_INVALID = -1,
155 BROWSER_UNKNOWN,
156 BROWSER_IE,
[email protected]f7817822009-09-24 05:11:58157};
158
159BrowserType GetBrowserType();
160
161typedef enum IEVersion {
162 IE_INVALID,
163 NON_IE,
164 IE_UNSUPPORTED,
165 IE_6,
166 IE_7,
167 IE_8,
[email protected]d8e13512010-09-22 17:02:58168 IE_9,
[email protected]5ba4b8a92011-09-29 05:09:42169 IE_10,
[email protected]f7817822009-09-24 05:11:58170};
171
[email protected]d8e13512010-09-22 17:02:58172// The renderer to be used for a page. Values for Chrome also convey the
173// reason why Chrome is used.
174enum RendererType {
175 RENDERER_TYPE_UNDETERMINED = 0,
176 RENDERER_TYPE_CHROME_MIN,
177 // NOTE: group all _CHROME_ values together below here, as they are used for
178 // generating metrics reported via UMA (adjust MIN/MAX as needed).
179 RENDERER_TYPE_CHROME_GCF_PROTOCOL = RENDERER_TYPE_CHROME_MIN,
180 RENDERER_TYPE_CHROME_HTTP_EQUIV,
181 RENDERER_TYPE_CHROME_RESPONSE_HEADER,
182 RENDERER_TYPE_CHROME_DEFAULT_RENDERER,
183 RENDERER_TYPE_CHROME_OPT_IN_URL,
184 RENDERER_TYPE_CHROME_WIDGET,
185 // NOTE: all _CHOME_ values must go above here (adjust MIN/MAX as needed).
186 RENDERER_TYPE_CHROME_MAX = RENDERER_TYPE_CHROME_WIDGET,
187 RENDERER_TYPE_OTHER,
188};
189
190// Returns true if the given RendererType represents Chrome.
191bool IsChrome(RendererType renderer_type);
192
193// Convenience macro for logging a sample for the launch type metric.
[email protected]92c79d32011-04-06 18:41:15194#define UMA_LAUNCH_TYPE_COUNT(sample) \
195 UMA_HISTOGRAM_CUSTOM_COUNTS("ChromeFrame.LaunchType", sample, \
[email protected]d8e13512010-09-22 17:02:58196 RENDERER_TYPE_CHROME_MIN, RENDERER_TYPE_CHROME_MAX, \
197 RENDERER_TYPE_CHROME_MAX + 1 - RENDERER_TYPE_CHROME_MIN)
198
[email protected]f7817822009-09-24 05:11:58199// To get the IE version when Chrome Frame is hosted in IE. Make sure that
200// the hosting browser is IE before calling this function, otherwise NON_IE
201// will be returned.
[email protected]b57f03232010-10-25 14:14:39202//
203// Versions newer than the newest supported version are reported as the newest
204// supported version.
[email protected]f7817822009-09-24 05:11:58205IEVersion GetIEVersion();
206
[email protected]b57f03232010-10-25 14:14:39207// Returns the actual major version of the IE in which the current process is
208// hosted. Returns 0 if the current process is not IE or any other error occurs.
209uint32 GetIEMajorVersion();
210
[email protected]bc73b4e52010-03-26 04:16:20211FilePath GetIETemporaryFilesFolder();
212
[email protected]f7817822009-09-24 05:11:58213// Retrieves the file version from a module handle without extra round trips
214// to the disk (as happens with the regular GetFileVersionInfo API).
215//
216// @param module A handle to the module for which to retrieve the version info.
[email protected]b57f03232010-10-25 14:14:39217// @param high On successful return holds the most significant part of the file
218// version. Must be non-null.
219// @param low On successful return holds the least significant part of the file
220// version. May be NULL.
[email protected]f7817822009-09-24 05:11:58221// @returns true if the version info was successfully retrieved.
222bool GetModuleVersion(HMODULE module, uint32* high, uint32* low);
223
224// Return if the IEXPLORE is in private mode. The IEIsInPrivateBrowsing() checks
225// whether current process is IEXPLORE.
226bool IsIEInPrivate();
227
[email protected]35f13ab2009-12-16 23:59:17228// Calls [ieframe|shdocvw]!DoFileDownload to initiate a download.
229HRESULT DoFileDownloadInIE(const wchar_t* url);
230
[email protected]b516e2d2011-07-12 16:54:12231// Construct a menu from the model sent from Chrome.
232HMENU BuildContextMenu(const ContextMenuModel& menu_model);
[email protected]f7817822009-09-24 05:11:58233
234// Uses GURL internally to append 'relative' to 'document'
235std::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.
239bool HaveSameOrigin(const std::string& url1, const std::string& url2);
240
241// Get a boolean configuration value from registry.
242bool GetConfigBool(bool default_value, const wchar_t* value_name);
243
244// Gets an integer configuration value from the registry.
245int GetConfigInt(int default_value, const wchar_t* value_name);
246
[email protected]7bc272f2009-12-09 01:09:28247// Sets an integer configuration value in the registry.
248bool SetConfigInt(const wchar_t* value_name, int value);
249
250// Sets a boolean integer configuration value in the registry.
251bool SetConfigBool(const wchar_t* value_name, bool value);
252
253// Deletes the configuration value passed in.
254bool DeleteConfigValue(const wchar_t* value_name);
255
256// Returns true if we are running in headless mode in which case we need to
257// gather crash dumps, etc to send them to the crash server.
258bool IsHeadlessMode();
259
[email protected]67700a92010-09-18 07:43:58260// Returns true if we are running in accessible mode in which we need to enable
261// renderer accessibility for use in automation.
262bool IsAccessibleMode();
263
[email protected]11903b0d2010-03-26 23:54:34264// Returns true if we are running in unpinned mode in which case DLL
265// eviction should be possible.
266bool IsUnpinnedMode();
267
[email protected]e67a73f42010-08-31 15:05:02268// Returns true if all HTML pages should be rendered in GCF by default.
269bool IsGcfDefaultRenderer();
270
[email protected]f7817822009-09-24 05:11:58271// Check if this url is opting into Chrome Frame based on static settings.
[email protected]d8e13512010-09-22 17:02:58272// Returns one of:
273// - RENDERER_TYPE_UNDETERMINED if not opt-in or if explicit opt-out
274// - RENDERER_TYPE_CHROME_DEFAULT_RENDERER
275// - RENDERER_TYPE_CHROME_OPT_IN_URL
276RendererType RendererTypeForUrl(const std::wstring& url);
[email protected]f7817822009-09-24 05:11:58277
[email protected]57319e12012-03-30 22:52:34278// Check if we should try to remove the CF user agent based on registry
279// settings.
280bool ShouldRemoveUAForUrl(const string16& url);
281
282// Testing methods that return the backing stores behind RendererTypeForUrl and
283// ShouldRemoveUAForUrl. Intended to allow unit testing code that calls the
284// above methods.
285// TODO(robertshield): All of the FooForUrl code should be removed from here
286// and further refactored.
287RegistryListPreferencesHolder& GetRendererTypePreferencesHolderForTesting();
288RegistryListPreferencesHolder& GetUserAgentPreferencesHolderForTesting();
289
[email protected]f7817822009-09-24 05:11:58290// A shortcut for QueryService
291template <typename T>
[email protected]3f55e872009-10-17 04:48:37292HRESULT DoQueryService(const IID& service_id, IUnknown* unk, T** service) {
293 DCHECK(service);
[email protected]f7817822009-09-24 05:11:58294 if (!unk)
295 return E_INVALIDARG;
[email protected]2b3102be2010-04-21 20:07:35296
[email protected]0152b512010-12-21 00:52:03297 base::win::ScopedComPtr<IServiceProvider> service_provider;
[email protected]f7817822009-09-24 05:11:58298 HRESULT hr = service_provider.QueryFrom(unk);
[email protected]2b3102be2010-04-21 20:07:35299 if (service_provider)
300 hr = service_provider->QueryService(service_id, service);
[email protected]f7817822009-09-24 05:11:58301
[email protected]2b3102be2010-04-21 20:07:35302 DCHECK(FAILED(hr) || *service);
[email protected]172acc42009-12-28 22:10:17303 return hr;
[email protected]f7817822009-09-24 05:11:58304}
305
[email protected]b22ef282009-12-11 19:31:56306// Navigates an IWebBrowser2 object to a moniker.
[email protected]a542e822010-01-16 00:30:04307// |headers| can be NULL.
[email protected]4736610c2011-03-04 06:43:35308HRESULT NavigateBrowserToMoniker(IUnknown* browser, IMoniker* moniker,
309 const wchar_t* headers, IBindCtx* bind_ctx,
[email protected]93b792792011-06-07 23:00:01310 const wchar_t* fragment, IStream* post_data,
311 VARIANT* flags);
[email protected]b22ef282009-12-11 19:31:56312
313// Raises a flag on the current thread (using TLS) to indicate that an
314// in-progress navigation should be rendered in chrome frame.
315void MarkBrowserOnThreadForCFNavigation(IBrowserService* browser);
316
317// Checks if this browser instance has been marked as currently navigating
318// to a CF document. If clear_flag is set to true, the tls flag is cleared but
319// only if the browser has been marked.
320bool CheckForCFNavigation(IBrowserService* browser, bool clear_flag);
321
[email protected]f7817822009-09-24 05:11:58322// Returns true if the URL passed in is something which can be handled by
323// Chrome. If this function returns false then we should fail the navigation.
[email protected]10bf1a72009-10-01 16:00:21324// When is_privileged is true, chrome extension URLs will be considered valid.
[email protected]d266ce82010-08-13 21:33:40325bool IsValidUrlScheme(const GURL& url, bool is_privileged);
[email protected]f7817822009-09-24 05:11:58326
[email protected]b55aaa62009-12-03 00:21:50327// Returns the raw http headers for the current request given an
328// IWinInetHttpInfo pointer.
329std::string GetRawHttpHeaders(IWinInetHttpInfo* info);
330
[email protected]723f29922009-12-04 20:42:33331// Can be used to determine whether a given request is being performed for
332// a sub-frame or iframe in Internet Explorer. This can be called
333// from various places, notably in request callbacks and the like.
334//
335// |service_provider| must not be NULL and should be a pointer to something
336// that implements IServiceProvider (if it isn't this method returns false).
337//
338// Returns true if this method can determine with some certainty that the
339// request did NOT originate from a top level frame, returns false otherwise.
340bool IsSubFrameRequest(IUnknown* service_provider);
341
[email protected]3f55e872009-10-17 04:48:37342// See COM_INTERFACE_BLIND_DELEGATE below for details.
343template <class T>
344STDMETHODIMP CheckOutgoingInterface(void* obj, REFIID iid, void** ret,
345 DWORD cookie) {
346 T* instance = reinterpret_cast<T*>(obj);
347 HRESULT hr = E_NOINTERFACE;
348 IUnknown* delegate = instance ? instance->delegate() : NULL;
349 if (delegate) {
350 hr = delegate->QueryInterface(iid, ret);
351#if !defined(NDEBUG)
352 if (SUCCEEDED(hr)) {
353 wchar_t iid_string[64] = {0};
354 StringFromGUID2(iid, iid_string, arraysize(iid_string));
[email protected]2b9a9f162010-10-19 20:30:45355 DVLOG(1) << __FUNCTION__ << " Giving out wrapped interface: "
356 << iid_string;
[email protected]3f55e872009-10-17 04:48:37357 }
358#endif
359 }
360
361 return hr;
362}
363
364// See COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS below for details.
365template <class T>
366STDMETHODIMP QueryInterfaceIfDelegateSupports(void* obj, REFIID iid,
367 void** ret, DWORD cookie) {
368 HRESULT hr = E_NOINTERFACE;
369 T* instance = reinterpret_cast<T*>(obj);
370 IUnknown* delegate = instance ? instance->delegate() : NULL;
371 if (delegate) {
[email protected]0152b512010-12-21 00:52:03372 base::win::ScopedComPtr<IUnknown> original;
[email protected]3f55e872009-10-17 04:48:37373 hr = delegate->QueryInterface(iid,
374 reinterpret_cast<void**>(original.Receive()));
375 if (original) {
376 IUnknown* supported_interface = reinterpret_cast<IUnknown*>(
377 reinterpret_cast<DWORD_PTR>(obj) + cookie);
378 supported_interface->AddRef();
379 *ret = supported_interface;
380 hr = S_OK;
381 }
382 }
383
384 return hr;
385}
386
387// Same as COM_INTERFACE_ENTRY but relies on the class to implement a
388// delegate() method that returns a pointer to the delegated COM object.
389#define COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS(x) \
390 COM_INTERFACE_ENTRY_FUNC(_ATL_IIDOF(x), \
391 offsetofclass(x, _ComMapClass), \
392 QueryInterfaceIfDelegateSupports<_ComMapClass>)
393
394// Queries the delegated COM object for an interface, bypassing the wrapper.
395#define COM_INTERFACE_BLIND_DELEGATE() \
396 COM_INTERFACE_ENTRY_FUNC_BLIND(0, CheckOutgoingInterface<_ComMapClass>)
397
[email protected]3eb07da2010-02-01 19:48:36398// Thread that enters STA and has a UI message loop.
399class STAThread : public base::Thread {
400 public:
401 explicit STAThread(const char *name) : Thread(name) {}
[email protected]d583c3a2011-11-02 15:31:56402 ~STAThread() {
403 Stop();
404 }
[email protected]3eb07da2010-02-01 19:48:36405 bool Start() {
406 return StartWithOptions(Options(MessageLoop::TYPE_UI, 0));
407 }
408 protected:
409 // Called just prior to starting the message loop
410 virtual void Init() {
411 ::CoInitialize(0);
412 }
413
414 // Called just after the message loop ends
415 virtual void CleanUp() {
416 ::CoUninitialize();
417 }
418};
419
[email protected]ecd9aa32010-03-01 19:34:39420std::wstring GuidToString(const GUID& guid);
421
[email protected]7e3544b2010-01-22 00:02:34422// The urls retrieved from the IMoniker interface don't contain the anchor
423// portion of the actual url navigated to. This function checks whether the
424// url passed in the bho_url parameter contains an anchor and if yes checks
425// whether it matches the url retrieved from the moniker. If yes it returns
426// the bho url, if not the moniker url.
427std::wstring GetActualUrlFromMoniker(IMoniker* moniker,
428 IBindCtx* bind_context,
429 const std::wstring& bho_url);
430
[email protected]4e676aa2010-02-12 18:19:07431// Checks if a window is a top level window
432bool IsTopLevelWindow(HWND window);
433
[email protected]051236f2010-03-12 22:06:14434// Seeks a stream back to position 0.
435HRESULT RewindStream(IStream* stream);
436
[email protected]80b5a8d2010-03-19 16:50:43437// Fired when we want to notify IE about privacy changes.
438#define WM_FIRE_PRIVACY_CHANGE_NOTIFICATION (WM_APP + 1)
439
[email protected]7ae80742010-03-25 22:02:27440// Sent (not posted) when a request needs to be downloaded in the host browser
441// instead of Chrome. WPARAM is 0 and LPARAM is a pointer to an IMoniker
442// object.
443// NOTE: Since the message is sent synchronously, the handler should only
444// start asynchronous operations in order to not block the sender unnecessarily.
445#define WM_DOWNLOAD_IN_HOST (WM_APP + 2)
446
[email protected]f4fbae682011-02-28 22:18:33447// This structure contains the parameters sent over to initiate a download
448// request in the host browser.
449struct DownloadInHostParams {
[email protected]7af08f62011-03-11 00:03:55450 base::win::ScopedComPtr<IBindCtx> bind_ctx;
451 base::win::ScopedComPtr<IMoniker> moniker;
452 base::win::ScopedComPtr<IStream> post_data;
[email protected]f4fbae682011-02-28 22:18:33453 std::string request_headers;
454};
455
[email protected]80b5a8d2010-03-19 16:50:43456// Maps the InternetCookieState enum to the corresponding CookieAction values
457// used for IE privacy stuff.
458int32 MapCookieStateToCookieAction(InternetCookieState cookie_state);
459
[email protected]e33f99a12010-04-13 01:27:22460// Parses the url passed in and returns a GURL instance without the fragment.
461GURL GetUrlWithoutFragment(const wchar_t* url);
462
463// Compares the URLs passed in after removing the fragments from them.
464bool CompareUrlsWithoutFragment(const wchar_t* url1, const wchar_t* url2);
465
[email protected]6ee88532010-04-16 01:10:47466// Returns the Referrer from the HTTP headers and additional headers.
467std::string FindReferrerFromHeaders(const wchar_t* headers,
468 const wchar_t* additional_headers);
469
470// Returns the HTTP headers from the binding passed in.
471std::string GetHttpHeadersFromBinding(IBinding* binding);
472
473// Returns the HTTP response code from the binding passed in.
474int GetHttpResponseStatusFromBinding(IBinding* binding);
475
[email protected]2b3102be2010-04-21 20:07:35476// Returns the clipboard format for text/html.
477CLIPFORMAT GetTextHtmlClipboardFormat();
478
479// Returns true iff the mime type is text/html.
480bool IsTextHtmlMimeType(const wchar_t* mime_type);
481
482// Returns true iff the clipboard format is text/html.
483bool IsTextHtmlClipFormat(CLIPFORMAT cf);
484
[email protected]74ecb5a42010-09-03 00:44:35485// Returns true if we can detect that we are running as SYSTEM, false otherwise.
486bool IsSystemProcess();
487
[email protected]77d7aee2010-05-14 20:31:55488// STL helper class that implements a functor to delete objects.
489// E.g: std::for_each(v.begin(), v.end(), utils::DeleteObject());
490namespace utils {
491class DeleteObject {
492 public:
493 template <typename T>
494 void operator()(T* obj) {
495 delete obj;
496 }
497};
498}
499
[email protected]ce2b9f92010-06-09 16:54:12500// Convert various protocol flags to text representation. Used for logging.
501std::string BindStatus2Str(ULONG bind_status);
502std::string PiFlags2Str(DWORD flags);
503std::string Bscf2Str(DWORD flags);
504
[email protected]897b26272010-06-11 02:23:44505// Reads data from a stream into a string.
506HRESULT ReadStream(IStream* stream, size_t size, std::string* data);
507
[email protected]e67a73f42010-08-31 15:05:02508// Parses urls targeted at ChromeFrame. This class maintains state like
[email protected]c4e45b32010-07-28 21:15:15509// whether a url is prefixed with the gcf: prefix, whether it is being
510// attached to an existing external tab, etc.
511class ChromeFrameUrl {
512 public:
513 ChromeFrameUrl();
514
515 // Parses the url passed in. Returns true on success.
516 bool Parse(const std::wstring& url);
517
518 bool is_chrome_protocol() const {
519 return is_chrome_protocol_;
520 }
521
522 bool attach_to_external_tab() const {
523 return attach_to_external_tab_;
524 }
525
526 uint64 cookie() const {
527 return cookie_;
528 }
529
530 int disposition() const {
531 return disposition_;
532 }
533
534 const gfx::Rect& dimensions() const {
535 return dimensions_;
536 }
537
[email protected]d266ce82010-08-13 21:33:40538 const GURL& gurl() const {
539 return parsed_url_;
[email protected]c4e45b32010-07-28 21:15:15540 }
541
[email protected]8103c7f2010-09-08 22:36:09542 const std::string& profile_name() const {
543 return profile_name_;
544 }
545
[email protected]c4e45b32010-07-28 21:15:15546 private:
547 // If we are attaching to an existing external tab, this function parses the
548 // suffix portion of the URL which contains the attach_external_tab prefix.
549 bool ParseAttachExternalTabUrl();
550
[email protected]d266ce82010-08-13 21:33:40551 // Clear state.
552 void Reset();
553
[email protected]c4e45b32010-07-28 21:15:15554 bool attach_to_external_tab_;
555 bool is_chrome_protocol_;
[email protected]c4e45b32010-07-28 21:15:15556 uint64 cookie_;
557 gfx::Rect dimensions_;
558 int disposition_;
[email protected]d266ce82010-08-13 21:33:40559
560 GURL parsed_url_;
[email protected]8103c7f2010-09-08 22:36:09561 std::string profile_name_;
[email protected]c4e45b32010-07-28 21:15:15562};
563
[email protected]354bcba2010-12-14 04:34:43564class NavigationConstraints;
[email protected]c4e45b32010-07-28 21:15:15565// Returns true if we can navigate to this URL.
[email protected]354bcba2010-12-14 04:34:43566// These decisions are controlled by the NavigationConstraints object passed
567// in.
568bool CanNavigate(const GURL& url,
569 NavigationConstraints* navigation_constraints);
[email protected]e3a91e72010-06-17 01:19:04570
[email protected]ec18ca672010-09-02 13:39:50571// Utility function that prevents the current module from ever being unloaded.
572// Call if you make irreversible patches.
573void PinModule();
574
[email protected]d9d8f0c2010-09-17 21:47:16575// Helper function to spin a message loop and dispatch messages while waiting
576// for a handle to be signaled.
577void WaitWithMessageLoop(HANDLE* handles, int count, DWORD timeout);
578
[email protected]5ac670a2010-10-04 23:07:40579// Enumerates values in a key and adds them to an array.
580// The names of the values are not returned.
581void EnumerateKeyValues(HKEY parent_key, const wchar_t* sub_key_name,
582 std::vector<std::wstring>* values);
583
[email protected]b57f03232010-10-25 14:14:39584// Interprets the value of an X-UA-Compatible header (or <meta> tag equivalent)
585// and indicates whether the header value contains a Chrome Frame directive
586// matching a given host browser version.
587//
588// The header is a series of name-value pairs, with the names being HTTP tokens
589// and the values being either tokens or quoted-strings. Names and values are
[email protected]8e698b6c2010-10-26 20:29:12590// joined by '=' and pairs are delimited by either ';' or ','. LWS may be used
591// liberally before and between names, values, '=', and ';' or ','. See RFC 2616
592// for definitions of token, quoted-string, and LWS. See Microsoft's
593// documentation of the X-UA-COMPATIBLE header here:
[email protected]b57f03232010-10-25 14:14:39594// http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx
595//
596// At most one 'Chrome=<FILTER>' entry is expected in the header value. The
597// first valid instance is used. The value of "<FILTER>" (possibly after
598// unquoting) is interpreted as follows:
599//
600// "1" - Always active
601// "IE7" - Active for IE major version 7 or lower
602//
603// For example:
604// X-UA-Compatible: IE=8; Chrome=IE6
[email protected]8e698b6c2010-10-26 20:29:12605//
606// The string is first interpreted using ';' as a delimiter. It is reevaluated
607// using ',' iff no valid 'chrome=' value is found.
[email protected]b57f03232010-10-25 14:14:39608bool CheckXUaCompatibleDirective(const std::string& directive,
609 int ie_major_version);
610
[email protected]6a8515e42010-12-16 19:38:52611// Returns the version of the current module as a string.
612std::wstring GetCurrentModuleVersion();
613
[email protected]a17930d82011-02-11 23:12:35614// Returns true if ChromeFrame is the currently loaded document.
615bool IsChromeFrameDocument(IWebBrowser2* web_browser);
616
[email protected]fb123bc2011-02-16 19:38:27617// Increases the wininet connection limit for HTTP 1.0/1.1 connections to the
618// value passed in. This is only done if the existing connection limit is
619// lesser than the connection limit passed in. This function attempts to
620// increase the connection count once per process.
621// Returns true on success.
622bool IncreaseWinInetConnections(DWORD connections);
623
[email protected]6a46c342012-05-03 14:49:04624// Sets |profile_path| to the path for the Chrome Frame |profile_name|
625// profile.
626void GetChromeFrameProfilePath(const string16& profile_name,
627 FilePath* profile_path);
628
[email protected]f7817822009-09-24 05:11:58629#endif // CHROME_FRAME_UTILS_H_