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

Side by Side Diff: chrome_frame/vtable_patch_manager.h

Issue 259025: Add the chromeframe tag to the user agent header at runtime instead of static... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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
« no previous file with comments | « chrome_frame/utils.h ('k') | chrome_frame/vtable_patch_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 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_COMMON_VTABLE_PATCH_MANAGER_H_ 5 #ifndef CHROME_FRAME_VTABLE_PATCH_MANAGER_H_
6 #define CHROME_FRAME_COMMON_VTABLE_PATCH_MANAGER_H_ 6 #define CHROME_FRAME_VTABLE_PATCH_MANAGER_H_
7 7
8 #include <windows.h> 8 #include <windows.h>
9 9
10 #include <list>
11
12 #include "base/lock.h"
13
10 struct FunctionStub; 14 struct FunctionStub;
11 // This namespace provides methods to patch VTable methods of COM interfaces. 15 // This namespace provides methods to patch VTable methods of COM interfaces.
12 namespace vtable_patch { 16 namespace vtable_patch {
13 17
14 // This structure represents information about one VTable method. 18 // This structure represents information about one VTable method.
15 // We allocate an array of these structures per VTable that we patch to 19 // We allocate an array of these structures per VTable that we patch to
16 // remember the original method. We also use this structure to actually 20 // remember the original method. We also use this structure to actually
17 // describe the VTable patch functions 21 // describe the VTable patch functions
18 struct MethodPatchInfo { 22 struct MethodPatchInfo {
19 int index_; 23 int index_;
(...skipping 12 matching lines...) Expand all
32 36
33 // Using the patch info provided in |patches| the function goes through the 37 // Using the patch info provided in |patches| the function goes through the
34 // list of patched methods and modifies thunks so that they no longer point 38 // list of patched methods and modifies thunks so that they no longer point
35 // to a hook method but rather go straight through to the original target. 39 // to a hook method but rather go straight through to the original target.
36 // The thunk itself is not destroyed to support chaining. 40 // The thunk itself is not destroyed to support chaining.
37 // @param[in] patches An array of MethodPatchInfo structures describing 41 // @param[in] patches An array of MethodPatchInfo structures describing
38 // the methods to patch and the patch functions. 42 // the methods to patch and the patch functions.
39 // The last entry of patches must have index_ set to -1. 43 // The last entry of patches must have index_ set to -1.
40 HRESULT UnpatchInterfaceMethods(MethodPatchInfo* patches); 44 HRESULT UnpatchInterfaceMethods(MethodPatchInfo* patches);
41 45
46 // Disabled as we're not using it atm.
47 #if 0
48 // Used when dynamically patching zero or more (usually more than 1)
49 // implementations of a particular interface.
50 class DynamicPatchManager {
51 public:
52 explicit DynamicPatchManager(const MethodPatchInfo* patch_prototype);
53 ~DynamicPatchManager();
54
55 // Returns S_OK if the object was successfully patched, S_FALSE if it was
56 // already patched or an error value if something bad happened.
57 HRESULT PatchObject(void* unknown);
58
59 bool UnpatchAll();
60
61 protected:
62 struct PatchedObject {
63 void* vtable_;
64 MethodPatchInfo patch_info_[1];
65
66 // Used to match PatchedObject instances based on the vtable when
67 // searching through the patch list.
68 bool operator==(const PatchedObject& that) const {
69 return vtable_ == that.vtable_;
70 }
71 };
72
73 typedef std::list<PatchedObject*> PatchList;
74 const MethodPatchInfo* patch_prototype_;
75 mutable Lock patch_list_lock_;
76 PatchList patch_list_;
77 };
78 #endif // disable DynamicPatchManager
79
42 } // namespace vtable_patch 80 } // namespace vtable_patch
43 81
44 // Begins the declaration of a VTable patch 82 // Begins the declaration of a VTable patch
45 // @param IFName The name of the interface to patch 83 // @param IFName The name of the interface to patch
46 #define BEGIN_VTABLE_PATCHES(IFName) \ 84 #define BEGIN_VTABLE_PATCHES(IFName) \
47 vtable_patch::MethodPatchInfo IFName##_PatchInfo[] = { 85 vtable_patch::MethodPatchInfo IFName##_PatchInfo[] = {
48
49 // Defines a single method patch in a VTable 86 // Defines a single method patch in a VTable
50 // @param index The index of the method to patch 87 // @param index The index of the method to patch
51 // @param PatchFunction The patch function 88 // @param PatchFunction The patch function
52 #define VTABLE_PATCH_ENTRY(index, PatchFunction) {\ 89 #define VTABLE_PATCH_ENTRY(index, PatchFunction) {\
53 index, \ 90 index, \
54 reinterpret_cast<PROC>(PatchFunction), \ 91 reinterpret_cast<PROC>(PatchFunction), \
55 NULL, \ 92 NULL, \
56 }, 93 },
57 94
95 #define DCHECK_IS_NOT_PATCHED(IFName) \
96 for (vtable_patch::MethodPatchInfo* it = IFName##_PatchInfo; \
97 it->index_ != -1; ++it) { \
98 DCHECK(it->stub_ == NULL); \
99 }
100
101 #define DCHECK_IS_PATCHED(IFName) \
102 for (vtable_patch::MethodPatchInfo* it = IFName##_PatchInfo; \
103 it->index_ != -1; ++it) { \
104 DCHECK(it->stub_ != NULL); \
105 }
106
107 // Checks if the interface is patched. Note that only the first method
108 // is checked and subsequent methods are assumed to have the same state.
109 #define IS_PATCHED(IFName) \
110 (IFName##_PatchInfo[0].stub_ != NULL)
111
58 // Ends the declaration of a VTable patch by adding an entry with 112 // Ends the declaration of a VTable patch by adding an entry with
59 // index set to -1. 113 // index set to -1.
60 #define END_VTABLE_PATCHES() \ 114 #define END_VTABLE_PATCHES() \
61 -1, NULL, NULL \ 115 -1, NULL, NULL \
62 }; 116 };
63 117
64 #endif // CHROME_FRAME_COMMON_VTABLE_PATCH_MANAGER_H_ 118 #endif // CHROME_FRAME_VTABLE_PATCH_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome_frame/utils.h ('k') | chrome_frame/vtable_patch_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698