OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROME_FRAME_BHO_H_ |
| 6 #define CHROME_FRAME_BHO_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include <atlbase.h> |
| 11 #include <atlcom.h> |
| 12 #include <exdisp.h> |
| 13 #include <exdispid.h> |
| 14 #include <mshtml.h> |
| 15 #include <shdeprecated.h> |
| 16 |
| 17 #include "chrome_tab.h" // NOLINT |
| 18 #include "chrome_frame/resource.h" |
| 19 #include "grit/chrome_frame_resources.h" |
| 20 |
| 21 class PatchHelper { |
| 22 public: |
| 23 enum State { UNKNOWN, PATCH_IBROWSER, PATCH_IBROWSER_OK, PATCH_PROTOCOL }; |
| 24 PatchHelper() : state_(UNKNOWN) { |
| 25 } |
| 26 |
| 27 State state() const { |
| 28 return state_; |
| 29 } |
| 30 |
| 31 void InitializeAndPatchProtocolsIfNeeded(); |
| 32 void PatchBrowserService(IBrowserService* p); |
| 33 void UnpatchIfNeeded(); |
| 34 protected: |
| 35 State state_; |
| 36 }; |
| 37 |
| 38 // Single global variable |
| 39 extern PatchHelper g_patch_helper; |
| 40 |
| 41 class ATL_NO_VTABLE Bho |
| 42 : public CComObjectRootEx<CComSingleThreadModel>, |
| 43 public CComCoClass<Bho, &CLSID_ChromeFrameBHO>, |
| 44 public IObjectWithSiteImpl<Bho>, |
| 45 public IDispEventSimpleImpl<0, Bho, &DIID_DWebBrowserEvents2> { |
| 46 public: |
| 47 typedef HRESULT (STDMETHODCALLTYPE* IBrowserService_OnHttpEquiv_Fn)( |
| 48 IBrowserService* browser, IShellView* shell_view, BOOL done, |
| 49 VARIANT* in_arg, VARIANT* out_arg); |
| 50 |
| 51 DECLARE_REGISTRY_RESOURCEID(IDR_BHO) |
| 52 DECLARE_NOT_AGGREGATABLE(Bho) |
| 53 DECLARE_PROTECT_FINAL_CONSTRUCT() |
| 54 |
| 55 BEGIN_COM_MAP(Bho) |
| 56 COM_INTERFACE_ENTRY(IObjectWithSite) |
| 57 END_COM_MAP() |
| 58 |
| 59 BEGIN_SINK_MAP(Bho) |
| 60 SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_BEFORENAVIGATE2, |
| 61 BeforeNavigate2, &kBeforeNavigate2Info) |
| 62 END_SINK_MAP() |
| 63 |
| 64 // Lifetime management methods |
| 65 Bho(); |
| 66 |
| 67 HRESULT FinalConstruct(); |
| 68 void FinalRelease(); |
| 69 |
| 70 // IObjectWithSite |
| 71 STDMETHODIMP SetSite(IUnknown* site); |
| 72 STDMETHOD(BeforeNavigate2)(IDispatch* dispatch, VARIANT* url, VARIANT* flags, |
| 73 VARIANT* target_frame_name, VARIANT* post_data, VARIANT* headers, |
| 74 VARIANT_BOOL* cancel); |
| 75 |
| 76 // mshtml sends an IOleCommandTarget::Exec of OLECMDID_HTTPEQUIV |
| 77 // (and OLECMDID_HTTPEQUIV_DONE) as soon as it parses a meta tag. |
| 78 // It also sends contents of the meta tag as an argument. IEFrame |
| 79 // handles this in IBrowserService::OnHttpEquiv. So this allows |
| 80 // us to sniff the META tag by simply patching it. The renderer |
| 81 // switching can be achieved by cancelling original navigation |
| 82 // and issuing a new one using IWebBrowser2->Navigate2. |
| 83 static HRESULT STDMETHODCALLTYPE OnHttpEquiv( |
| 84 IBrowserService_OnHttpEquiv_Fn original_httpequiv, |
| 85 IBrowserService* browser, IShellView* shell_view, BOOL done, |
| 86 VARIANT* in_arg, VARIANT* out_arg); |
| 87 |
| 88 protected: |
| 89 bool PatchProtocolHandler(const CLSID& handler_clsid); |
| 90 static bool HasSubFrames(IWebBrowser2* web_browser2); |
| 91 static HRESULT SwitchRenderer(IWebBrowser2* web_browser2, |
| 92 IBrowserService* browser, IShellView* shell_view, |
| 93 const wchar_t* meta_tag); |
| 94 |
| 95 static _ATL_FUNC_INFO kBeforeNavigate2Info; |
| 96 }; |
| 97 |
| 98 // Add Bho to class library table so IE can CoCreate it. |
| 99 OBJECT_ENTRY_AUTO(CLSID_ChromeFrameBHO, Bho); |
| 100 |
| 101 #endif // CHROME_FRAME_BHO_H_ |
| 102 |
OLD | NEW |