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

Side by Side Diff: ios/web_view/internal/cwv.mm

Issue 2800433002: Remove CWVDelegate. (Closed)
Patch Set: Respond to comments. Created 3 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
« no previous file with comments | « ios/web_view/BUILD.gn ('k') | ios/web_view/internal/web_view_web_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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_view/public/cwv.h" 5 #import "ios/web_view/public/cwv.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #import "base/mac/bind_objc_block.h" 10 #import "base/mac/bind_objc_block.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/strings/sys_string_conversions.h"
13 #include "ios/web/public/app/web_main.h" 14 #include "ios/web/public/app/web_main.h"
14 #include "ios/web/public/web_thread.h" 15 #include "ios/web/public/web_thread.h"
15 #import "ios/web_view/internal/web_view_web_main_delegate.h" 16 #import "ios/web_view/internal/web_view_web_main_delegate.h"
16 #import "ios/web_view/public/cwv_delegate.h"
17 #import "ios/web_view/public/cwv_web_view.h" 17 #import "ios/web_view/public/cwv_web_view.h"
18 #import "ios/web_view/public/cwv_web_view_configuration.h" 18 #import "ios/web_view/public/cwv_web_view_configuration.h"
19 19
20 #if !defined(__has_feature) || !__has_feature(objc_arc) 20 #if !defined(__has_feature) || !__has_feature(objc_arc)
21 #error "This file requires ARC support." 21 #error "This file requires ARC support."
22 #endif 22 #endif
23 23
24 namespace { 24 namespace {
25 CWV* g_criwv = nil; 25 CWV* g_criwv = nil;
26 } 26 }
27 27
28 @interface CWV () { 28 @interface CWV () {
29 std::unique_ptr<ios_web_view::WebViewWebMainDelegate> _webMainDelegate; 29 std::unique_ptr<ios_web_view::WebViewWebMainDelegate> _webMainDelegate;
30 std::unique_ptr<web::WebMain> _webMain; 30 std::unique_ptr<web::WebMain> _webMain;
31 } 31 }
32
33 @property(nonatomic, weak) id<CWVDelegate> delegate;
34
35 - (instancetype)initWithDelegate:(id<CWVDelegate>)delegate;
36 @end 32 @end
37 33
38 @implementation CWV 34 @implementation CWV
39 35
40 @synthesize delegate = _delegate; 36 + (void)configureWithUserAgentProductName:(NSString*)productName {
41 37 g_criwv = [[CWV alloc] initWithUserAgentProductName:productName];
42 + (void)configureWithDelegate:(id<CWVDelegate>)delegate {
43 g_criwv = [[CWV alloc] initWithDelegate:delegate];
44 } 38 }
45 39
46 + (void)shutDown { 40 + (void)shutDown {
47 g_criwv = nil; 41 g_criwv = nil;
48 } 42 }
49 43
50 + (CWVWebView*)webViewWithFrame:(CGRect)frame { 44 + (CWVWebView*)webViewWithFrame:(CGRect)frame {
51 CWVWebViewConfiguration* configuration = 45 CWVWebViewConfiguration* configuration =
52 [CWVWebViewConfiguration defaultConfiguration]; 46 [CWVWebViewConfiguration defaultConfiguration];
53 return [[CWVWebView alloc] initWithFrame:frame configuration:configuration]; 47 return [[CWVWebView alloc] initWithFrame:frame configuration:configuration];
54 } 48 }
55 49
56 - (instancetype)initWithDelegate:(id<CWVDelegate>)delegate { 50 - (instancetype)initWithUserAgentProductName:(NSString*)productName {
57 self = [super init]; 51 self = [super init];
58 if (self) { 52 if (self) {
59 _delegate = delegate; 53 std::string userAgent = base::SysNSStringToUTF8(productName);
60 _webMainDelegate = 54 _webMainDelegate =
61 base::MakeUnique<ios_web_view::WebViewWebMainDelegate>(_delegate); 55 base::MakeUnique<ios_web_view::WebViewWebMainDelegate>(userAgent);
62 web::WebMainParams params(_webMainDelegate.get()); 56 web::WebMainParams params(_webMainDelegate.get());
63 _webMain = base::MakeUnique<web::WebMain>(params); 57 _webMain = base::MakeUnique<web::WebMain>(params);
64 } 58 }
65 return self; 59 return self;
66 } 60 }
67 61
68 - (void)dealloc { 62 - (void)dealloc {
69 _webMain.reset(); 63 _webMain.reset();
70 _webMainDelegate.reset(); 64 _webMainDelegate.reset();
71 } 65 }
72 66
73 @end 67 @end
OLDNEW
« no previous file with comments | « ios/web_view/BUILD.gn ('k') | ios/web_view/internal/web_view_web_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698