Index: base/mac/scoped_objc_class_swizzler.h |
diff --git a/base/mac/scoped_objc_class_swizzler.h b/base/mac/scoped_objc_class_swizzler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..03c131d1b4e4ab32ebded28d487af640c6bbc2fa |
--- /dev/null |
+++ b/base/mac/scoped_objc_class_swizzler.h |
@@ -0,0 +1,38 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef BASE_MAC_SCOPED_OBJC_CLASS_SWIZZLER_H_ |
+#define BASE_MAC_SCOPED_OBJC_CLASS_SWIZZLER_H_ |
+ |
+#import <objc/runtime.h> |
+ |
+#include "base/base_export.h" |
+#include "base/macros.h" |
+ |
+namespace base { |
+namespace mac { |
+ |
+// Within a given scope, replace the selector |selector| on |target| with that |
+// from |source|. |
+class BASE_EXPORT ScopedObjCClassSwizzler { |
+ public: |
+ ScopedObjCClassSwizzler(Class target, Class source, SEL selector); |
+ ~ScopedObjCClassSwizzler(); |
+ |
+ // Return a callable function pointer for the replaced method. To call this |
+ // from the replacing function, the first two arguments should be |self| and |
+ // |_cmd|. These are followed by the (variadic) method arguments. |
+ IMP GetOriginalImplementation(); |
+ |
+ private: |
+ Method old_selector_impl_; |
+ Method new_selector_impl_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ScopedObjCClassSwizzler); |
+}; |
+ |
+} // namespace mac |
+} // namespace base |
+ |
+#endif // BASE_MAC_SCOPED_OBJC_CLASS_SWIZZLER_H_ |