| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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/public/cwv.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/location.h" | |
| 10 #import "base/mac/bind_objc_block.h" | |
| 11 #include "base/memory/ptr_util.h" | |
| 12 #include "base/single_thread_task_runner.h" | |
| 13 #include "base/strings/sys_string_conversions.h" | |
| 14 #include "ios/web/public/app/web_main.h" | |
| 15 #include "ios/web/public/web_thread.h" | |
| 16 #import "ios/web_view/internal/web_view_web_main_delegate.h" | |
| 17 #import "ios/web_view/public/cwv_web_view.h" | |
| 18 #import "ios/web_view/public/cwv_web_view_configuration.h" | |
| 19 | |
| 20 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 21 #error "This file requires ARC support." | |
| 22 #endif | |
| 23 | |
| 24 namespace { | |
| 25 CWV* g_criwv = nil; | |
| 26 } | |
| 27 | |
| 28 @interface CWV () { | |
| 29 std::unique_ptr<ios_web_view::WebViewWebMainDelegate> _webMainDelegate; | |
| 30 std::unique_ptr<web::WebMain> _webMain; | |
| 31 } | |
| 32 @end | |
| 33 | |
| 34 @implementation CWV | |
| 35 | |
| 36 + (void)configureWithUserAgentProductName:(NSString*)productName { | |
| 37 g_criwv = [[CWV alloc] initWithUserAgentProductName:productName]; | |
| 38 } | |
| 39 | |
| 40 + (void)shutDown { | |
| 41 g_criwv = nil; | |
| 42 } | |
| 43 | |
| 44 + (CWVWebView*)webViewWithFrame:(CGRect)frame { | |
| 45 CWVWebViewConfiguration* configuration = | |
| 46 [CWVWebViewConfiguration defaultConfiguration]; | |
| 47 return [[CWVWebView alloc] initWithFrame:frame configuration:configuration]; | |
| 48 } | |
| 49 | |
| 50 - (instancetype)initWithUserAgentProductName:(NSString*)productName { | |
| 51 self = [super init]; | |
| 52 if (self) { | |
| 53 std::string userAgent = base::SysNSStringToUTF8(productName); | |
| 54 _webMainDelegate = | |
| 55 base::MakeUnique<ios_web_view::WebViewWebMainDelegate>(userAgent); | |
| 56 web::WebMainParams params(_webMainDelegate.get()); | |
| 57 _webMain = base::MakeUnique<web::WebMain>(params); | |
| 58 } | |
| 59 return self; | |
| 60 } | |
| 61 | |
| 62 - (void)dealloc { | |
| 63 _webMain.reset(); | |
| 64 _webMainDelegate.reset(); | |
| 65 } | |
| 66 | |
| 67 @end | |
| OLD | NEW |