OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef IOS_WEB_WEB_STATE_UI_WK_WEB_VIEW_CONFIGURATION_PROVIDER_H_ | 5 #ifndef IOS_WEB_WEB_STATE_UI_WK_WEB_VIEW_CONFIGURATION_PROVIDER_H_ |
6 #define IOS_WEB_WEB_STATE_UI_WK_WEB_VIEW_CONFIGURATION_PROVIDER_H_ | 6 #define IOS_WEB_WEB_STATE_UI_WK_WEB_VIEW_CONFIGURATION_PROVIDER_H_ |
7 | 7 |
8 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/supports_user_data.h" | 10 #include "base/supports_user_data.h" |
11 | 11 |
12 @class CRWWKScriptMessageRouter; | 12 @class CRWWKScriptMessageRouter; |
13 @class WKWebViewConfiguration; | 13 @class WKWebViewConfiguration; |
14 | 14 |
15 namespace web { | 15 namespace web { |
16 | 16 |
17 class BrowserState; | 17 class BrowserState; |
18 | 18 |
19 // A provider class associated with a single web::BrowserState object. Manages | 19 // A provider class associated with a single web::BrowserState object. Manages |
20 // the lifetime and performs setup of WKWebViewConfiguration and | 20 // the lifetime and performs setup of WKWebViewConfiguration and |
21 // CRWWKScriptMessageRouter instances. Not threadsafe. Must be used only on the | 21 // CRWWKScriptMessageRouter instances. Not threadsafe. Must be used only on the |
22 // main thread. | 22 // main thread. |
23 class WKWebViewConfigurationProvider : public base::SupportsUserData::Data { | 23 class WKWebViewConfigurationProvider : public base::SupportsUserData::Data { |
24 public: | 24 public: |
| 25 ~WKWebViewConfigurationProvider() override; |
| 26 |
25 // Returns a provider for the given |browser_state|. Lazily attaches one if it | 27 // Returns a provider for the given |browser_state|. Lazily attaches one if it |
26 // does not exist. |browser_state| can not be null. | 28 // does not exist. |browser_state| can not be null. |
27 static web::WKWebViewConfigurationProvider& FromBrowserState( | 29 static web::WKWebViewConfigurationProvider& FromBrowserState( |
28 web::BrowserState* browser_state); | 30 web::BrowserState* browser_state); |
29 | 31 |
30 // Returns an autoreleased copy of WKWebViewConfiguration associated with | 32 // Returns an autoreleased copy of WKWebViewConfiguration associated with |
31 // browser state. Lazily creates the config. Configuration's |preferences| | 33 // browser state. Lazily creates the config. Configuration's |preferences| |
32 // will have scriptCanOpenWindowsAutomatically property set to YES. | 34 // will have scriptCanOpenWindowsAutomatically property set to YES. |
33 // Must be used instead of [[WKWebViewConfiguration alloc] init]. | 35 // Must be used instead of [[WKWebViewConfiguration alloc] init]. |
34 // Callers must not retain the returned object. | 36 // Callers must not retain the returned object. |
35 WKWebViewConfiguration* GetWebViewConfiguration(); | 37 WKWebViewConfiguration* GetWebViewConfiguration(); |
36 | 38 |
37 // Returns CRWWKScriptMessafeRouter associated with WKWebViewConfiguration. | 39 // Returns CRWWKScriptMessafeRouter associated with WKWebViewConfiguration. |
38 // Lazily creates the router. Callers must not retain the returned object | 40 // Lazily creates the router. Callers must not retain the returned object |
39 // (this will be enforced in debug builds). | 41 // (this will be enforced in debug builds). |
40 CRWWKScriptMessageRouter* GetScriptMessageRouter(); | 42 CRWWKScriptMessageRouter* GetScriptMessageRouter(); |
41 | 43 |
42 // Purges config and router objects if they exist. When this method is called | 44 // Purges config and router objects if they exist. When this method is called |
43 // config and config's process pool must not be retained by anyone (this will | 45 // config and config's process pool must not be retained by anyone (this will |
44 // be enforced in debug builds). | 46 // be enforced in debug builds). |
45 void Purge(); | 47 void Purge(); |
46 | 48 |
47 private: | 49 private: |
48 explicit WKWebViewConfigurationProvider(BrowserState* browser_state); | 50 explicit WKWebViewConfigurationProvider(BrowserState* browser_state); |
49 WKWebViewConfigurationProvider() = delete; | 51 WKWebViewConfigurationProvider() = delete; |
50 ~WKWebViewConfigurationProvider() override; | |
51 | 52 |
52 base::scoped_nsobject<WKWebViewConfiguration> configuration_; | 53 base::scoped_nsobject<WKWebViewConfiguration> configuration_; |
53 base::scoped_nsobject<CRWWKScriptMessageRouter> router_; | 54 base::scoped_nsobject<CRWWKScriptMessageRouter> router_; |
54 BrowserState* browser_state_; | 55 BrowserState* browser_state_; |
55 | 56 |
56 DISALLOW_COPY_AND_ASSIGN(WKWebViewConfigurationProvider); | 57 DISALLOW_COPY_AND_ASSIGN(WKWebViewConfigurationProvider); |
57 }; | 58 }; |
58 | 59 |
59 } // namespace web | 60 } // namespace web |
60 | 61 |
61 #endif // IOS_WEB_WEB_STATE_UI_WK_WEB_VIEW_CONFIGURATION_PROVIDER_H_ | 62 #endif // IOS_WEB_WEB_STATE_UI_WK_WEB_VIEW_CONFIGURATION_PROVIDER_H_ |
OLD | NEW |