| OLD | NEW |
| 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/criwv.h" | 5 #import "ios/web_view/public/criwv.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/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "ios/web/public/app/web_main.h" | 12 #include "ios/web/public/app/web_main.h" |
| 13 #include "ios/web/public/web_thread.h" | 13 #include "ios/web/public/web_thread.h" |
| 14 #include "ios/web_view/internal/criwv_browser_state.h" | 14 #include "ios/web_view/internal/criwv_browser_state.h" |
| 15 #import "ios/web_view/internal/criwv_web_client.h" | 15 #import "ios/web_view/internal/criwv_web_client.h" |
| 16 #import "ios/web_view/internal/criwv_web_main_delegate.h" | 16 #import "ios/web_view/internal/criwv_web_main_delegate.h" |
| 17 #import "ios/web_view/internal/criwv_web_view_impl.h" | 17 #import "ios/web_view/internal/criwv_web_view_internal.h" |
| 18 #import "ios/web_view/public/criwv_delegate.h" | 18 #import "ios/web_view/public/criwv_delegate.h" |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 CRIWV* g_criwv = nil; | 21 CRIWV* g_criwv = nil; |
| 22 } | 22 } |
| 23 | 23 |
| 24 @interface CRIWV () { | 24 @interface CRIWV () { |
| 25 id<CRIWVDelegate> _delegate; | 25 id<CRIWVDelegate> _delegate; |
| 26 std::unique_ptr<ios_web_view::CRIWVWebMainDelegate> _webMainDelegate; | 26 std::unique_ptr<ios_web_view::CRIWVWebMainDelegate> _webMainDelegate; |
| 27 std::unique_ptr<web::WebMain> _webMain; | 27 std::unique_ptr<web::WebMain> _webMain; |
| 28 } | 28 } |
| 29 | 29 |
| 30 - (instancetype)initWithDelegate:(id<CRIWVDelegate>)delegate; | 30 - (instancetype)initWithDelegate:(id<CRIWVDelegate>)delegate; |
| 31 - (ios_web_view::CRIWVBrowserState*)browserState; | 31 - (ios_web_view::CRIWVBrowserState*)browserState; |
| 32 @end | 32 @end |
| 33 | 33 |
| 34 @implementation CRIWV | 34 @implementation CRIWV |
| 35 | 35 |
| 36 + (void)configureWithDelegate:(id<CRIWVDelegate>)delegate { | 36 + (void)configureWithDelegate:(id<CRIWVDelegate>)delegate { |
| 37 g_criwv = [[CRIWV alloc] initWithDelegate:delegate]; | 37 g_criwv = [[CRIWV alloc] initWithDelegate:delegate]; |
| 38 } | 38 } |
| 39 | 39 |
| 40 + (void)shutDown { | 40 + (void)shutDown { |
| 41 [g_criwv release]; | 41 [g_criwv release]; |
| 42 g_criwv = nil; | 42 g_criwv = nil; |
| 43 } | 43 } |
| 44 | 44 |
| 45 + (id<CRIWVWebView>)webView { | 45 + (CRIWVWebView*)webViewWithFrame:(CGRect)frame { |
| 46 return [[[CRIWVWebViewImpl alloc] initWithBrowserState:[g_criwv browserState]] | 46 return |
| 47 autorelease]; | 47 [[[CRIWVWebView alloc] initWithFrame:frame |
| 48 browserState:[g_criwv browserState]] autorelease]; |
| 48 } | 49 } |
| 49 | 50 |
| 50 - (instancetype)initWithDelegate:(id<CRIWVDelegate>)delegate { | 51 - (instancetype)initWithDelegate:(id<CRIWVDelegate>)delegate { |
| 51 self = [super init]; | 52 self = [super init]; |
| 52 if (self) { | 53 if (self) { |
| 53 _delegate = delegate; | 54 _delegate = delegate; |
| 54 _webMainDelegate.reset(new ios_web_view::CRIWVWebMainDelegate(_delegate)); | 55 _webMainDelegate.reset(new ios_web_view::CRIWVWebMainDelegate(_delegate)); |
| 55 web::WebMainParams params(_webMainDelegate.get()); | 56 web::WebMainParams params(_webMainDelegate.get()); |
| 56 _webMain.reset(new web::WebMain(params)); | 57 _webMain.reset(new web::WebMain(params)); |
| 57 } | 58 } |
| 58 return self; | 59 return self; |
| 59 } | 60 } |
| 60 | 61 |
| 61 - (void)dealloc { | 62 - (void)dealloc { |
| 62 _webMain.reset(); | 63 _webMain.reset(); |
| 63 _webMainDelegate.reset(); | 64 _webMainDelegate.reset(); |
| 64 [super dealloc]; | 65 [super dealloc]; |
| 65 } | 66 } |
| 66 | 67 |
| 67 - (ios_web_view::CRIWVBrowserState*)browserState { | 68 - (ios_web_view::CRIWVBrowserState*)browserState { |
| 68 ios_web_view::CRIWVWebClient* client = | 69 ios_web_view::CRIWVWebClient* client = |
| 69 static_cast<ios_web_view::CRIWVWebClient*>(web::GetWebClient()); | 70 static_cast<ios_web_view::CRIWVWebClient*>(web::GetWebClient()); |
| 70 return client->browser_state(); | 71 return client->browser_state(); |
| 71 } | 72 } |
| 72 | 73 |
| 73 @end | 74 @end |
| OLD | NEW |