OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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. | |
michaeldo
2017/03/21 16:12:34
Please add new line after license.
Hiroshi Ichikawa
2017/03/22 04:52:52
Done.
| |
4 #import "ios/web_view/public/cwv_user_content_controller.h" | |
5 #import "ios/web_view/internal/cwv_user_content_controller_internal.h" | |
6 | |
7 #import "ios/web_view/internal/cwv_web_view_configuration_internal.h" | |
8 #include "ios/web_view/internal/web_view_browser_state.h" | |
9 #import "ios/web_view/internal/web_view_early_page_script_provider.h" | |
10 #import "ios/web_view/public/cwv_user_script.h" | |
11 | |
12 @implementation CWVUserContentController { | |
13 __weak CWVWebViewConfiguration* _configuration; | |
michaeldo
2017/03/21 16:12:34
Please use properties here
Ref: https://google.gi
Hiroshi Ichikawa
2017/03/22 04:52:52
Done.
| |
14 NSMutableArray<CWVUserScript*>* _userScripts; | |
15 } | |
16 | |
17 @synthesize userScripts = _userScripts; | |
18 | |
19 - (instancetype)initWithConfiguration: | |
20 (__weak CWVWebViewConfiguration*)configuration { | |
21 self = [super init]; | |
22 if (self) { | |
23 _configuration = configuration; | |
Eugene But (OOO till 7-30)
2017/03/21 16:47:55
nit: Consider adding DCHECK(configuration)
Hiroshi Ichikawa
2017/03/22 04:52:52
Done. But I also added nonnull annotation for |con
michaeldo
2017/03/22 23:03:32
We commonly use DCHECKS where we expect a nonnull
Eugene But (OOO till 7-30)
2017/03/22 23:09:50
That's a good point. Maybe DCHECKs are indeed unne
Hiroshi Ichikawa
2017/03/23 02:48:05
Thanks. Deleted the DCHECKs.
| |
24 _userScripts = [[NSMutableArray alloc] init]; | |
25 } | |
26 return self; | |
27 } | |
28 | |
29 - (void)addUserScript:(CWVUserScript*)userScript { | |
30 [_userScripts addObject:userScript]; | |
Eugene But (OOO till 7-30)
2017/03/21 16:47:55
nit: Consider adding DCHECK(userScript)
Hiroshi Ichikawa
2017/03/22 04:52:52
Done.
| |
31 [self updateEarlyPageScript]; | |
32 } | |
33 | |
34 - (void)removeAllUserScripts { | |
35 [_userScripts removeAllObjects]; | |
36 [self updateEarlyPageScript]; | |
37 } | |
38 | |
39 - (void)updateEarlyPageScript { | |
Eugene But (OOO till 7-30)
2017/03/21 16:47:55
nit: Could you please add comment.
Hiroshi Ichikawa
2017/03/22 04:52:52
Done.
| |
40 NSMutableString* joinedScript = [NSMutableString string]; | |
michaeldo
2017/03/21 16:12:34
please use alloc/init instead of "string"
Hiroshi Ichikawa
2017/03/22 04:52:52
Done. Just curious, why? Is it just a preferred st
michaeldo
2017/03/22 23:03:32
Correct, I suggested this because our style prefer
Hiroshi Ichikawa
2017/03/23 02:48:05
Acknowledged.
| |
41 for (CWVUserScript* script in _userScripts) { | |
42 [joinedScript appendString:script.source]; | |
Eugene But (OOO till 7-30)
2017/03/21 16:47:55
This can potentially be a performance problem. Do
Hiroshi Ichikawa
2017/03/22 04:52:52
Done. I believe it would be rare that it becomes a
| |
43 // Inserts "\n" between scripts to make it safer to join multiple scripts, | |
44 // in case the first script doesn't end with ";" or "\n". | |
45 [joinedScript appendString:@"\n"]; | |
46 } | |
47 ios_web_view::WebViewEarlyPageScriptProvider::FromBrowserState( | |
48 _configuration.browserState) | |
49 .SetScript(joinedScript); | |
50 } | |
51 | |
52 @end | |
OLD | NEW |