Chromium Code Reviews| 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. | |
| 4 | |
| 5 #import "ios/web_view/internal/web_view_early_page_script_provider.h" | |
| 6 | |
| 7 #import <Foundation/Foundation.h> | |
| 8 | |
| 9 #include "ios/web/public/browser_state.h" | |
| 10 #include "ios/web/public/web_thread.h" | |
| 11 | |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 13 #error "This file requires ARC support." | |
| 14 #endif | |
| 15 | |
| 16 namespace ios_web_view { | |
| 17 | |
| 18 namespace { | |
| 19 // A key used to associate a WebViewEarlyPageScriptProvider with a BrowserState. | |
| 20 const char kWebViewEarlyPageScriptProviderKeyName[] = | |
| 21 "web_view_early_page_script_provider"; | |
| 22 | |
| 23 } // namespace | |
| 24 | |
| 25 // static | |
| 26 WebViewEarlyPageScriptProvider& | |
| 27 WebViewEarlyPageScriptProvider::FromBrowserState( | |
| 28 web::BrowserState* _Nonnull browser_state) { | |
| 29 DCHECK_CURRENTLY_ON(web::WebThread::UI); | |
| 30 DCHECK(browser_state); | |
| 31 if (!browser_state->GetUserData(kWebViewEarlyPageScriptProviderKeyName)) { | |
| 32 browser_state->SetUserData(kWebViewEarlyPageScriptProviderKeyName, | |
| 33 std::unique_ptr<WebViewEarlyPageScriptProvider>( | |
| 34 new WebViewEarlyPageScriptProvider())); | |
| 35 } | |
| 36 return *(static_cast<WebViewEarlyPageScriptProvider*>( | |
| 37 browser_state->GetUserData(kWebViewEarlyPageScriptProviderKeyName))); | |
| 38 } | |
| 39 | |
| 40 WebViewEarlyPageScriptProvider::~WebViewEarlyPageScriptProvider() = default; | |
| 41 | |
| 42 void WebViewEarlyPageScriptProvider::SetScript(NSString* _Nonnull script) { | |
| 43 script_.reset((NSString * _Nonnull)[script copy]); | |
|
michaeldo
2017/03/22 23:03:33
Is this cast needed? I would expect this to be OK:
Hiroshi Ichikawa
2017/03/23 02:18:40
It worked, thanks. Done.
| |
| 44 } | |
| 45 | |
| 46 WebViewEarlyPageScriptProvider::WebViewEarlyPageScriptProvider() | |
| 47 : script_([[NSString alloc] init]) {} | |
| 48 | |
| 49 } // namespace ios_web_view | |
| OLD | NEW |