Chromium Code Reviews| Index: ios/web_view/internal/web_view_early_page_script_provider.mm |
| diff --git a/ios/web_view/internal/web_view_early_page_script_provider.mm b/ios/web_view/internal/web_view_early_page_script_provider.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6cce7c1013f4d309b4d940f811499bf387c6165b |
| --- /dev/null |
| +++ b/ios/web_view/internal/web_view_early_page_script_provider.mm |
| @@ -0,0 +1,45 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "ios/web_view/internal/web_view_early_page_script_provider.h" |
| + |
| +#import <Foundation/Foundation.h> |
| + |
| +#include "ios/web/public/browser_state.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +namespace ios_web_view { |
| + |
| +namespace { |
| +// A key used to associate a WebViewEarlyPageScriptProvider with a BrowserState. |
| +const char kWebViewEarlyPageScriptProviderKeyName[] = |
| + "web_view_early_page_script_provider"; |
| + |
| +} // namespace |
| + |
| +// static |
| +WebViewEarlyPageScriptProvider& |
| +WebViewEarlyPageScriptProvider::FromBrowserState( |
| + web::BrowserState* browser_state) { |
| + DCHECK([NSThread isMainThread]); |
|
michaeldo
2017/03/21 16:12:34
Why is this bound to the main thread? Should we DC
Hiroshi Ichikawa
2017/03/22 04:52:52
Well, I just copied implementation of:
https://cs.
michaeldo
2017/03/22 23:03:32
Got it, that makes sense, either is likely ok. How
|
| + DCHECK(browser_state); |
| + if (!browser_state->GetUserData(kWebViewEarlyPageScriptProviderKeyName)) { |
| + browser_state->SetUserData(kWebViewEarlyPageScriptProviderKeyName, |
| + std::unique_ptr<WebViewEarlyPageScriptProvider>( |
|
michaeldo
2017/03/21 16:12:34
please use base::MakeUnique instead of new
Hiroshi Ichikawa
2017/03/22 04:52:52
MakeUnique() causes an error in this case because
michaeldo
2017/03/22 23:03:32
I see, no using new is OK then. However, is the st
Hiroshi Ichikawa
2017/03/23 02:18:40
That's true. But I found this comment:
https://cs.
|
| + new WebViewEarlyPageScriptProvider())); |
| + } |
| + return *(static_cast<WebViewEarlyPageScriptProvider*>( |
| + browser_state->GetUserData(kWebViewEarlyPageScriptProviderKeyName))); |
| +} |
| + |
| +WebViewEarlyPageScriptProvider::WebViewEarlyPageScriptProvider() { |
|
Eugene But (OOO till 7-30)
2017/03/21 16:47:55
WebViewEarlyPageScriptProvider::WebViewEarlyPageSc
Hiroshi Ichikawa
2017/03/22 04:52:52
Done. But just curious, why? Is [[NSString alloc]
Eugene But (OOO till 7-30)
2017/03/22 15:08:50
Sorry, my comment was mostly about using initializ
Hiroshi Ichikawa
2017/03/23 02:18:40
Thanks for clarification!
|
| + script_ = @""; |
| +} |
| + |
| +WebViewEarlyPageScriptProvider::~WebViewEarlyPageScriptProvider() {} |
|
michaeldo
2017/03/21 16:12:34
please use "= default;" instead of {}
Hiroshi Ichikawa
2017/03/22 04:52:52
Done.
|
| + |
| +} // namespace ios_web_view |