OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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_BUGGY_BHO_HANDLING_H_ |
| 6 #define CHROME_FRAME_BUGGY_BHO_HANDLING_H_ |
| 7 |
| 8 #include <atlbase.h> |
| 9 #include <atlcom.h> |
| 10 #include <exdisp.h> |
| 11 |
| 12 #include <vector> |
| 13 |
| 14 #include "base/thread_local.h" |
| 15 |
| 16 namespace buggy_bho { |
| 17 |
| 18 // Method prototype for IDispatch::Invoke. |
| 19 typedef HRESULT (__stdcall* InvokeFunc)(IDispatch* me, DISPID dispid, |
| 20 REFIID riid, LCID lcid, WORD flags, |
| 21 DISPPARAMS* params, VARIANT* result, |
| 22 EXCEPINFO* ei, UINT* err); |
| 23 |
| 24 // Construct an instance of this class on the stack when firing web browser |
| 25 // events that can be sent to buggy BHOs. This class will intercept those |
| 26 // BHOs (see list in cc file) and ignore notifications to those components |
| 27 // for as long as the BuggyBhoTls instance on the stack lives. |
| 28 class BuggyBhoTls { |
| 29 public: |
| 30 BuggyBhoTls(); |
| 31 ~BuggyBhoTls(); |
| 32 |
| 33 // Call after instantiating an instance of BuggyBhoTls. This method traverses |
| 34 // the list of DWebBrowserEvents and DWebBrowserEvents2 subscribers and checks |
| 35 // if any of the sinks belong to a list of known-to-be-buggy BHOs. |
| 36 // For each of those, a patch will be applied that temporarily ignores certain |
| 37 // invokes. |
| 38 static HRESULT PatchBuggyBHOs(IWebBrowser2* browser); |
| 39 |
| 40 protected: |
| 41 // internal implementation: |
| 42 |
| 43 // Called when a buggy instance is found to be subscribing to browser events. |
| 44 void AddBuggyObject(IDispatch* obj); |
| 45 |
| 46 // Called from our patch to check if calls for this object should be ignored. |
| 47 // The reason we do this check is because there might be more than one browser |
| 48 // object running on the same thread (e.g. IE6) with one running CF and the |
| 49 // other MSHTML. We don't want to drop events being fired by MSHTML, only |
| 50 // events fired by CF since these BHOs should handle MSHTML correctly. |
| 51 bool IsBuggyObject(IDispatch* obj) const; |
| 52 |
| 53 // Static, protected member methods |
| 54 |
| 55 // Returns the currently registered (TLS) BuggyBhoTls instance or NULL. |
| 56 static BuggyBhoTls* FromCurrentThread(); |
| 57 |
| 58 // Patches a subscriber if it belongs to a buggy dll. |
| 59 static bool PatchIfBuggy(CONNECTDATA* cd, const IID& diid); |
| 60 |
| 61 // Patches the IDispatch::Invoke method. |
| 62 static HRESULT PatchInvokeMethod(PROC* invoke); |
| 63 |
| 64 // This is our substitute function that is called instead of the buggy DLLs. |
| 65 // Here we call IsBuggyObject to check if we should ignore invokes or allow |
| 66 // them to go through. |
| 67 static STDMETHODIMP BuggyBhoInvoke(InvokeFunc original, IDispatch* me, |
| 68 DISPID dispid, REFIID riid, LCID lcid, WORD flags, DISPPARAMS* params, |
| 69 VARIANT* result, EXCEPINFO* ei, UINT* err); |
| 70 |
| 71 protected: |
| 72 // List of buggy subscribers. |
| 73 std::vector<IDispatch*> bad_objects_; |
| 74 |
| 75 // Pointer to a previous instance of BuggyBhoTls on this thread if any. |
| 76 // Under regular circumstances, this will be NULL. However, there's a chance |
| 77 // that we could get reentrant calls, hence we maintain a stack. |
| 78 BuggyBhoTls* previous_instance_; |
| 79 |
| 80 // Where we store the current thread's instance. |
| 81 static base::ThreadLocalPointer<BuggyBhoTls> s_bad_object_tls_; |
| 82 }; |
| 83 |
| 84 } // end namespace buggy_bho |
| 85 |
| 86 #endif // CHROME_FRAME_BUGGY_BHO_HANDLING_H_ |
| 87 |
OLD | NEW |