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

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

Issue 1107083002: Upstream more leaf files in ios/web/web_state (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@web-resync
Patch Set: Created 5 years, 8 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 15
15 @implementation CRWJSInjectionManager { 16 @implementation CRWJSInjectionManager {
16 // JS to inject into the page. This may be nil if it has been purged due to 17 // JS to inject into the page. This may be nil if it has been purged due to
17 // low memory. 18 // low memory.
18 base::scoped_nsobject<NSString> _injectObject; 19 base::scoped_nsobject<NSString> _injectObject;
19 // An object the can receive JavaScript injection. 20 // An object the can receive JavaScript injection.
20 CRWJSInjectionReceiver* _receiver; // Weak. 21 CRWJSInjectionReceiver* _receiver; // Weak.
21 } 22 }
22 23
23 - (id)initWithReceiver:(CRWJSInjectionReceiver*)receiver { 24 - (id)initWithReceiver:(CRWJSInjectionReceiver*)receiver {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 return nil; 105 return nil;
105 } 106 }
106 107
107 - (NSString*)injectionContent { 108 - (NSString*)injectionContent {
108 if (!_injectObject) 109 if (!_injectObject)
109 _injectObject.reset([[self staticInjectionContent] copy]); 110 _injectObject.reset([[self staticInjectionContent] copy]);
110 return _injectObject.get(); 111 return _injectObject.get();
111 } 112 }
112 113
113 - (NSString*)staticInjectionContent { 114 - (NSString*)staticInjectionContent {
114 DCHECK(self.scriptPath); 115 return web::GetPageScript([self scriptPath]);
115 NSString* path = [base::mac::FrameworkBundle() pathForResource:self.scriptPath
116 ofType:@"js"];
117 DCHECK(path) << "Script file not found: "
118 << base::SysNSStringToUTF8(self.scriptPath) << ".js";
119 NSError* error = nil;
120 NSString* content = [NSString stringWithContentsOfFile:path
121 encoding:NSUTF8StringEncoding
122 error:&error];
123 DCHECK(!error) << "Error fetching script: " << [error.description UTF8String];
124 DCHECK(content);
125 return content;
126 } 116 }
127 117
128 - (void)injectDependenciesIfMissing { 118 - (void)injectDependenciesIfMissing {
129 for (Class dependencyClass in [self directDependencies]) { 119 for (Class dependencyClass in [self directDependencies]) {
130 CRWJSInjectionManager* dependency = 120 CRWJSInjectionManager* dependency =
131 [_receiver instanceOfClass:dependencyClass]; 121 [_receiver instanceOfClass:dependencyClass];
132 [dependency inject]; 122 [dependency inject];
133 } 123 }
134 } 124 }
135 125
136 @end 126 @end
OLDNEW
« no previous file with comments | « ios/web/web_state/js/credential_util.mm ('k') | ios/web/web_state/js/crw_js_invoke_parameter_queue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698