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

Side by Side Diff: ios/web/web_state/js/crw_js_injection_manager.mm

Issue 2396553002: [ARC] Converts part of ios/web/ui to ARC.
Patch Set: co Created 4 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 #import "ios/web/public/web_state/js/crw_js_injection_manager.h" 5 #import "ios/web/public/web_state/js/crw_js_injection_manager.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/bundle_locations.h" 10 #include "base/mac/bundle_locations.h"
11 #import "base/mac/scoped_nsobject.h" 11 #import "base/mac/scoped_nsobject.h"
12 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
13 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" 13 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h"
14 #import "ios/web/web_state/js/page_script_util.h" 14 #import "ios/web/web_state/js/page_script_util.h"
15 15
16 #if !defined(__has_feature) || !__has_feature(objc_arc)
17 #error "This file requires ARC support."
18 #endif
19
16 @implementation CRWJSInjectionManager { 20 @implementation CRWJSInjectionManager {
17 // JS to inject into the page. This may be nil if it has been purged due to 21 // JS to inject into the page. This may be nil if it has been purged due to
18 // low memory. 22 // low memory.
19 base::scoped_nsobject<NSString> _injectObject; 23 base::scoped_nsobject<NSString> _injectObject;
20 // An object the can receive JavaScript injection. 24 // An object the can receive JavaScript injection.
21 CRWJSInjectionReceiver* _receiver; // Weak. 25 __weak CRWJSInjectionReceiver* _receiver;
22 } 26 }
23 27
24 - (id)initWithReceiver:(CRWJSInjectionReceiver*)receiver { 28 - (id)initWithReceiver:(CRWJSInjectionReceiver*)receiver {
25 DCHECK(receiver); 29 DCHECK(receiver);
26 self = [super init]; 30 self = [super init];
27 if (self) { 31 if (self) {
28 _receiver = receiver; 32 _receiver = receiver;
29 // Register for low-memory warnings. 33 // Register for low-memory warnings.
30 [[NSNotificationCenter defaultCenter] 34 [[NSNotificationCenter defaultCenter]
31 addObserver:self 35 addObserver:self
32 selector:@selector(lowMemoryWarning:) 36 selector:@selector(lowMemoryWarning:)
33 name:UIApplicationDidReceiveMemoryWarningNotification 37 name:UIApplicationDidReceiveMemoryWarningNotification
34 object:nil]; 38 object:nil];
35 } 39 }
36 return self; 40 return self;
37 } 41 }
38 42
39 - (void)dealloc { 43 - (void)dealloc {
40 [[NSNotificationCenter defaultCenter] removeObserver:self]; 44 [[NSNotificationCenter defaultCenter] removeObserver:self];
41 [super dealloc];
42 } 45 }
43 46
44 - (BOOL)hasBeenInjected { 47 - (BOOL)hasBeenInjected {
45 return [_receiver scriptHasBeenInjectedForClass:[self class]]; 48 return [_receiver scriptHasBeenInjectedForClass:[self class]];
46 } 49 }
47 50
48 - (void)inject { 51 - (void)inject {
49 if ([self hasBeenInjected]) 52 if ([self hasBeenInjected])
50 return; 53 return;
51 [_receiver injectScript:[self injectionContent] forClass:[self class]]; 54 [_receiver injectScript:[self injectionContent] forClass:[self class]];
(...skipping 25 matching lines...) Expand all
77 if (!_injectObject) 80 if (!_injectObject)
78 _injectObject.reset([[self staticInjectionContent] copy]); 81 _injectObject.reset([[self staticInjectionContent] copy]);
79 return _injectObject.get(); 82 return _injectObject.get();
80 } 83 }
81 84
82 - (NSString*)staticInjectionContent { 85 - (NSString*)staticInjectionContent {
83 return web::GetPageScript([self scriptPath]); 86 return web::GetPageScript([self scriptPath]);
84 } 87 }
85 88
86 @end 89 @end
OLDNEW
« no previous file with comments | « ios/web/web_state/js/credential_util.mm ('k') | ios/web/web_state/js/crw_js_injection_receiver.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698