Update expectations after WebKit roll.
[chromium-blink-merge.git] / chrome_frame / bho.h
blobc82f000c433cfb9e176f7c63dd6c9fb5dadc3aea
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.
5 #ifndef CHROME_FRAME_BHO_H_
6 #define CHROME_FRAME_BHO_H_
8 #include <atlbase.h>
9 #include <atlcom.h>
10 #include <exdisp.h>
11 #include <exdispid.h>
12 #include <mshtml.h>
13 #include <shdeprecated.h>
15 #include <string>
17 #include "base/lazy_instance.h"
18 #include "base/thread_local.h"
19 #include "chrome_tab.h" // NOLINT
20 #include "chrome_frame/resource.h"
21 #include "grit/chrome_frame_resources.h"
23 class PatchHelper {
24 public:
25 enum State { UNKNOWN, PATCH_IBROWSER, PATCH_PROTOCOL };
26 PatchHelper() : state_(UNKNOWN) {
29 State state() const {
30 return state_;
33 // Returns true if protocols were patched, false if patching has already
34 // been done.
35 bool InitializeAndPatchProtocolsIfNeeded();
37 void PatchBrowserService(IBrowserService* p);
38 void UnpatchIfNeeded();
39 protected:
40 State state_;
43 // Single global variable
44 extern PatchHelper g_patch_helper;
46 class ATL_NO_VTABLE Bho
47 : public CComObjectRootEx<CComSingleThreadModel>,
48 public CComCoClass<Bho, &CLSID_ChromeFrameBHO>,
49 public IObjectWithSiteImpl<Bho>,
50 public IDispEventSimpleImpl<0, Bho, &DIID_DWebBrowserEvents2> {
51 public:
52 typedef HRESULT (STDMETHODCALLTYPE* IBrowserService_OnHttpEquiv_Fn)(
53 IBrowserService* browser, IShellView* shell_view, BOOL done,
54 VARIANT* in_arg, VARIANT* out_arg);
56 DECLARE_REGISTRY_RESOURCEID(IDR_BHO)
57 DECLARE_NOT_AGGREGATABLE(Bho)
58 DECLARE_PROTECT_FINAL_CONSTRUCT()
60 BEGIN_COM_MAP(Bho)
61 COM_INTERFACE_ENTRY(IObjectWithSite)
62 END_COM_MAP()
64 BEGIN_SINK_MAP(Bho)
65 SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_BEFORENAVIGATE2,
66 BeforeNavigate2, &kBeforeNavigate2Info)
67 END_SINK_MAP()
69 // Lifetime management methods
70 Bho();
72 HRESULT FinalConstruct();
73 void FinalRelease();
75 // IObjectWithSite
76 STDMETHODIMP SetSite(IUnknown* site);
77 STDMETHOD(BeforeNavigate2)(IDispatch* dispatch, VARIANT* url, VARIANT* flags,
78 VARIANT* target_frame_name, VARIANT* post_data, VARIANT* headers,
79 VARIANT_BOOL* cancel);
81 HRESULT NavigateToCurrentUrlInCF(IBrowserService* browser);
83 // mshtml sends an IOleCommandTarget::Exec of OLECMDID_HTTPEQUIV
84 // (and OLECMDID_HTTPEQUIV_DONE) as soon as it parses a meta tag.
85 // It also sends contents of the meta tag as an argument. IEFrame
86 // handles this in IBrowserService::OnHttpEquiv. So this allows
87 // us to sniff the META tag by simply patching it. The renderer
88 // switching can be achieved by cancelling original navigation
89 // and issuing a new one using IWebBrowser2->Navigate2.
90 static HRESULT STDMETHODCALLTYPE OnHttpEquiv(
91 IBrowserService_OnHttpEquiv_Fn original_httpequiv,
92 IBrowserService* browser, IShellView* shell_view, BOOL done,
93 VARIANT* in_arg, VARIANT* out_arg);
95 const std::string& referrer() const {
96 return referrer_;
99 const std::wstring& url() const {
100 return url_;
103 // Called from HttpNegotiatePatch::BeginningTransaction when a request is
104 // being issued. We check the url and headers and see if there is a referrer
105 // header that we need to cache.
106 void OnBeginningTransaction(IWebBrowser2* browser, const wchar_t* url,
107 const wchar_t* headers,
108 const wchar_t* additional_headers);
110 // Returns the Bho instance for the current thread. This is returned from
111 // TLS.
112 static Bho* GetCurrentThreadBhoInstance();
114 static void ProcessOptInUrls(IWebBrowser2* browser, BSTR url);
116 protected:
117 bool PatchProtocolHandler(const CLSID& handler_clsid);
119 std::string referrer_;
120 std::wstring url_;
122 static base::LazyInstance<base::ThreadLocalPointer<Bho> >
123 bho_current_thread_instance_;
124 static _ATL_FUNC_INFO kBeforeNavigate2Info;
127 #endif // CHROME_FRAME_BHO_H_