[Android WebViewShell] Add inclusion test for webview exposed stable interfaces.
[chromium-blink-merge.git] / ios / web / alloc_with_zone_interceptor.mm
blobea86016561ec1c76d6104a93b98ec7afaafbded7
1 // Copyright 2015 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 #import "ios/web/alloc_with_zone_interceptor.h"
7 #import <objc/runtime.h>
9 #include "base/logging.h"
11 namespace web {
13 void AddAllocWithZoneMethod(Class target, id (^impl_block)(Class, NSZone*)) {
14   // Make sure |allocWithZone:| is not already implemented in the target class.
15   Class meta_class = object_getClass(target);
16   DCHECK_EQ(
17       class_getMethodImplementation(meta_class, @selector(allocWithZone:)),
18       class_getMethodImplementation(object_getClass([NSObject class]),
19                                     @selector(allocWithZone:)));
21   IMP new_impl = imp_implementationWithBlock(^(id self, NSZone* zone) {
22     return impl_block(self, zone);
23   });
24   class_addMethod(meta_class, @selector(allocWithZone:), new_impl, "v@:@");
27 }  // namespace web