| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_FRAME_BUGGY_BHO_HANDLING_H_ | 5 #ifndef CHROME_FRAME_BUGGY_BHO_HANDLING_H_ |
| 6 #define CHROME_FRAME_BUGGY_BHO_HANDLING_H_ | 6 #define CHROME_FRAME_BUGGY_BHO_HANDLING_H_ |
| 7 | 7 |
| 8 #include <atlbase.h> | 8 #include <atlbase.h> |
| 9 #include <atlcom.h> | 9 #include <atlcom.h> |
| 10 #include <exdisp.h> | 10 #include <exdisp.h> |
| 11 | 11 |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/threading/thread_local.h" | 14 #include "base/threading/thread_local.h" |
| 15 #include "base/win/scoped_comptr.h" |
| 15 | 16 |
| 16 namespace buggy_bho { | 17 namespace buggy_bho { |
| 17 | 18 |
| 18 // Method prototype for IDispatch::Invoke. | 19 // Method prototype for IDispatch::Invoke. |
| 19 typedef HRESULT (__stdcall* InvokeFunc)(IDispatch* me, DISPID dispid, | 20 typedef HRESULT (__stdcall* InvokeFunc)(IDispatch* me, DISPID dispid, |
| 20 REFIID riid, LCID lcid, WORD flags, | 21 REFIID riid, LCID lcid, WORD flags, |
| 21 DISPPARAMS* params, VARIANT* result, | 22 DISPPARAMS* params, VARIANT* result, |
| 22 EXCEPINFO* ei, UINT* err); | 23 EXCEPINFO* ei, UINT* err); |
| 23 | 24 |
| 24 // Construct an instance of this class on the stack when firing web browser | 25 // Construct a per thread instance of this class before firing web browser |
| 25 // events that can be sent to buggy BHOs. This class will intercept those | 26 // 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 // 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 // as long as ChromeFrame is the active view. |
| 28 class BuggyBhoTls { | 29 class BuggyBhoTls { |
| 29 public: | 30 public: |
| 31 // This method traverses the list of DWebBrowserEvents and DWebBrowserEvents2 |
| 32 // subscribers and checks if any of the sinks belong to a list of |
| 33 // known-to-be-buggy BHOs. |
| 34 // For each of those, a patch will be applied that temporarily ignores certain |
| 35 // invokes. |
| 36 HRESULT PatchBuggyBHOs(IWebBrowser2* browser); |
| 37 |
| 38 // Returns the instance of the BuggyBhoTls object for the current thread. |
| 39 static BuggyBhoTls* GetInstance(); |
| 40 |
| 41 // Destroys the BuggyBhoTls instance foe the current thread. |
| 42 static void DestroyInstance(); |
| 43 |
| 44 void set_web_browser(IWebBrowser2* web_browser2) { |
| 45 web_browser2_ = web_browser2; |
| 46 } |
| 47 |
| 48 protected: |
| 30 BuggyBhoTls(); | 49 BuggyBhoTls(); |
| 31 ~BuggyBhoTls(); | 50 ~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: | 51 // internal implementation: |
| 42 | 52 |
| 43 // Called when a buggy instance is found to be subscribing to browser events. | 53 // Called when a buggy instance is found to be subscribing to browser events. |
| 44 void AddBuggyObject(IDispatch* obj); | 54 void AddBuggyObject(IDispatch* obj); |
| 45 | 55 |
| 46 // Called from our patch to check if calls for this object should be ignored. | 56 // 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 | 57 // 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 | 58 // 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 | 59 // 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. | 60 // events fired by CF since these BHOs should handle MSHTML correctly. |
| 51 bool IsBuggyObject(IDispatch* obj) const; | 61 bool ShouldSkipInvoke(IDispatch* obj) const; |
| 52 | 62 |
| 53 // Static, protected member methods | 63 // Static, protected member methods |
| 54 | 64 |
| 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. | 65 // Patches a subscriber if it belongs to a buggy dll. |
| 59 static bool PatchIfBuggy(CONNECTDATA* cd, const IID& diid); | 66 bool PatchIfBuggy(IUnknown* unk, const IID& diid); |
| 60 | 67 |
| 61 // Patches the IDispatch::Invoke method. | 68 // Patches the IDispatch::Invoke method. |
| 62 static HRESULT PatchInvokeMethod(PROC* invoke); | 69 static HRESULT PatchInvokeMethod(PROC* invoke); |
| 63 | 70 |
| 64 // This is our substitute function that is called instead of the buggy DLLs. | 71 // 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 | 72 // Here we call IsBuggyObject to check if we should ignore invokes or allow |
| 66 // them to go through. | 73 // them to go through. |
| 67 static STDMETHODIMP BuggyBhoInvoke(InvokeFunc original, IDispatch* me, | 74 static STDMETHODIMP BuggyBhoInvoke(InvokeFunc original, IDispatch* me, |
| 68 DISPID dispid, REFIID riid, LCID lcid, WORD flags, DISPPARAMS* params, | 75 DISPID dispid, REFIID riid, LCID lcid, WORD flags, DISPPARAMS* params, |
| 69 VARIANT* result, EXCEPINFO* ei, UINT* err); | 76 VARIANT* result, EXCEPINFO* ei, UINT* err); |
| 70 | 77 |
| 71 protected: | 78 protected: |
| 72 // List of buggy subscribers. | 79 // List of buggy subscribers. |
| 73 std::vector<IDispatch*> bad_objects_; | 80 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 // Where we store the current thread's instance. |
| 81 static base::ThreadLocalPointer<BuggyBhoTls> s_bad_object_tls_; | 82 static base::ThreadLocalPointer<BuggyBhoTls> s_bad_object_tls_; |
| 83 // The IWebBrowser2 instance for this thread. |
| 84 base::win::ScopedComPtr<IWebBrowser2> web_browser2_; |
| 85 // Set to true when we are done patching the event sinks of buggy bho's. |
| 86 bool patched_; |
| 82 }; | 87 }; |
| 83 | 88 |
| 84 } // end namespace buggy_bho | 89 } // end namespace buggy_bho |
| 85 | 90 |
| 86 #endif // CHROME_FRAME_BUGGY_BHO_HANDLING_H_ | 91 #endif // CHROME_FRAME_BUGGY_BHO_HANDLING_H_ |
| OLD | NEW |