Clean up extension confirmation prompts and make them consistent between Views and...
[chromium-blink-merge.git] / base / mac / scoped_objc_class_swizzler.h
blobe18e4abfda553fcbab6787a0315c128a3c92e3f1
1 // Copyright 2014 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.
5 #ifndef BASE_MAC_SCOPED_OBJC_CLASS_SWIZZLER_H_
6 #define BASE_MAC_SCOPED_OBJC_CLASS_SWIZZLER_H_
8 #import <objc/runtime.h>
10 #include "base/base_export.h"
11 #include "base/macros.h"
13 namespace base {
14 namespace mac {
16 // Within a given scope, swaps method implementations of a class interface, or
17 // between two class interfaces. The argument and return types must match.
18 class BASE_EXPORT ScopedObjCClassSwizzler {
19 public:
20 // Given two classes that each respond to |selector|, swap the implementations
21 // of those methods.
22 ScopedObjCClassSwizzler(Class target, Class source, SEL selector);
24 // Given two selectors on the same class interface, |target| (e.g. via
25 // inheritance or categories), swap the implementations of methods |original|
26 // and |alternate|.
27 ScopedObjCClassSwizzler(Class target, SEL original, SEL alternate);
29 ~ScopedObjCClassSwizzler();
31 // Return a callable function pointer for the replaced method. To call this
32 // from the replacing function, the first two arguments should be |self| and
33 // |_cmd|. These are followed by the (variadic) method arguments.
34 IMP GetOriginalImplementation();
36 private:
37 // Delegated constructor.
38 void Init(Class target, Class source, SEL original, SEL alternate);
40 Method old_selector_impl_;
41 Method new_selector_impl_;
43 DISALLOW_COPY_AND_ASSIGN(ScopedObjCClassSwizzler);
46 } // namespace mac
47 } // namespace base
49 #endif // BASE_MAC_SCOPED_OBJC_CLASS_SWIZZLER_H_