Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: chrome_frame/buggy_bho_handling.h

Issue 6493002: A number of poorly written IE BHO's crash IE if ChromeFrame is the currently ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/synchronization/lock.h"
15 #include "base/threading/platform_thread.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 an instance of this class before firing web browser events that
25 // events that can be sent to buggy BHOs. This class will intercept those 26 // 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 BuggyBhoHandler {
29 public: 30 public:
30 BuggyBhoTls(); 31 BuggyBhoHandler();
31 ~BuggyBhoTls(); 32 ~BuggyBhoHandler();
32 33
33 // Call after instantiating an instance of BuggyBhoTls. This method traverses 34 // Call after instantiating an instance of BuggyBhoHandler. This method
34 // the list of DWebBrowserEvents and DWebBrowserEvents2 subscribers and checks 35 // traverses the list of DWebBrowserEvents and DWebBrowserEvents2 subscribers
35 // if any of the sinks belong to a list of known-to-be-buggy BHOs. 36 // and checks 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 // For each of those, a patch will be applied that temporarily ignores
37 // invokes. 38 // certain invokes.
38 static HRESULT PatchBuggyBHOs(IWebBrowser2* browser); 39 static HRESULT PatchBuggyBHOs(IWebBrowser2* browser);
39 40
41 // Returns a pointer to the global BuggyBhoHandler instance.
42 static BuggyBhoHandler* GetInstance();
43
44 // Removes buggy object information for the thread passed in.
45 static void ClearBuggyObjectsForThread(base::PlatformThreadId thread_id);
46
40 protected: 47 protected:
41 // internal implementation: 48 // internal implementation:
42 49
43 // Called when a buggy instance is found to be subscribing to browser events. 50 // Called when a buggy instance is found to be subscribing to browser events.
44 void AddBuggyObject(IDispatch* obj); 51 void AddBuggyObject(IDispatch* obj);
45 52
46 // Called from our patch to check if calls for this object should be ignored. 53 // 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 54 // 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 55 // 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 56 // 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. 57 // events fired by CF since these BHOs should handle MSHTML correctly.
51 bool IsBuggyObject(IDispatch* obj) const; 58 bool ShouldSkipInvoke(IDispatch* obj);
52 59
53 // Static, protected member methods 60 // Static, protected member methods
54 61
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. 62 // Patches a subscriber if it belongs to a buggy dll.
59 static bool PatchIfBuggy(CONNECTDATA* cd, const IID& diid); 63 static bool PatchIfBuggy(CONNECTDATA* cd, const IID& diid);
60 64
61 // Patches the IDispatch::Invoke method. 65 // Patches the IDispatch::Invoke method.
62 static HRESULT PatchInvokeMethod(PROC* invoke); 66 static HRESULT PatchInvokeMethod(PROC* invoke);
63 67
64 // This is our substitute function that is called instead of the buggy DLLs. 68 // 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 69 // Here we call IsBuggyObject to check if we should ignore invokes or allow
66 // them to go through. 70 // them to go through.
67 static STDMETHODIMP BuggyBhoInvoke(InvokeFunc original, IDispatch* me, 71 static STDMETHODIMP BuggyBhoInvoke(InvokeFunc original, IDispatch* me,
68 DISPID dispid, REFIID riid, LCID lcid, WORD flags, DISPPARAMS* params, 72 DISPID dispid, REFIID riid, LCID lcid, WORD flags, DISPPARAMS* params,
69 VARIANT* result, EXCEPINFO* ei, UINT* err); 73 VARIANT* result, EXCEPINFO* ei, UINT* err);
70 74
71 protected: 75 protected:
76 struct ObjectInfo {
77 // The object interface pointer.
78 IDispatch* disp_interface;
79 // The thread with which the object interface is associated.
80 base::PlatformThreadId object_thread_id;
81 };
72 // List of buggy subscribers. 82 // List of buggy subscribers.
73 std::vector<IDispatch*> bad_objects_; 83 std::vector<ObjectInfo> bad_objects_;
74 84 // used to serialize access to the list of buggy bho's as these could be
75 // Pointer to a previous instance of BuggyBhoTls on this thread if any. 85 // accessed from multiple IE UI threads.
tommi (sloooow) - chröme 2011/02/11 14:49:02 Would it be better to store this list with the TLS
76 // Under regular circumstances, this will be NULL. However, there's a chance 86 base::Lock lock_;
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 }; 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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698