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_
13 #include <shdeprecated.h>
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"
25 enum State
{ UNKNOWN
, PATCH_IBROWSER
, PATCH_PROTOCOL
};
26 PatchHelper() : state_(UNKNOWN
) {
33 // Returns true if protocols were patched, false if patching has already
35 bool InitializeAndPatchProtocolsIfNeeded();
37 void PatchBrowserService(IBrowserService
* p
);
38 void UnpatchIfNeeded();
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
> {
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()
61 COM_INTERFACE_ENTRY(IObjectWithSite
)
65 SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2
, DISPID_BEFORENAVIGATE2
,
66 BeforeNavigate2
, &kBeforeNavigate2Info
)
69 // Lifetime management methods
72 HRESULT
FinalConstruct();
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 {
99 const std::wstring
& url() const {
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
112 static Bho
* GetCurrentThreadBhoInstance();
114 static void ProcessOptInUrls(IWebBrowser2
* browser
, BSTR url
);
117 bool PatchProtocolHandler(const CLSID
& handler_clsid
);
119 std::string referrer_
;
122 static base::LazyInstance
<base::ThreadLocalPointer
<Bho
> >
123 bho_current_thread_instance_
;
124 static _ATL_FUNC_INFO kBeforeNavigate2Info
;
127 #endif // CHROME_FRAME_BHO_H_