Index: ios/web/web_state/ui/wk_web_view_configuration_provider.h |
diff --git a/ios/web/web_state/ui/wk_web_view_configuration_provider.h b/ios/web/web_state/ui/wk_web_view_configuration_provider.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e65523f6edbaed0edd7316165603095d0ea3b383 |
--- /dev/null |
+++ b/ios/web/web_state/ui/wk_web_view_configuration_provider.h |
@@ -0,0 +1,65 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef IOS_WEB_WEB_STATE_UI_WK_WEB_VIEW_CONFIGURATION_PROVIDER_H_ |
+#define IOS_WEB_WEB_STATE_UI_WK_WEB_VIEW_CONFIGURATION_PROVIDER_H_ |
+ |
+#include "base/mac/scoped_nsobject.h" |
+#include "base/macros.h" |
+#include "base/supports_user_data.h" |
+ |
+@class CRWWKScriptMessageRouter; |
+@class WKWebViewConfiguration; |
+ |
+namespace web { |
+ |
+class BrowserState; |
+ |
+// A provider class associated with a single web::BrowserState object. Manages |
+// the lifetime and performs setup of WKWebViewConfiguration and |
+// CRWWKScriptMessageRouter instances. Not threadsafe. Must be used only on the |
+// main thread. |
+class WKWebViewConfigurationProvider : public base::SupportsUserData::Data { |
+ public: |
+ // Returns a provider for the given |browser_state|. Lazily attaches one if it |
+ // does not exist. |browser_state| can not be null. |
+ static web::WKWebViewConfigurationProvider& FromBrowserState( |
+ web::BrowserState* browser_state); |
+ |
+ // Returns an autoreleased copy of WKWebViewConfiguration associated with |
+ // browser state. Lazily creates the config. Configuration's |preferences| |
+ // will have scriptCanOpenWindowsAutomatically property set to YES. |
+ // Must be used instead of [[WKWebViewConfiguration alloc] init]. |
+ // Callers must not retain the returned object. |
+ WKWebViewConfiguration* GetWebViewConfiguration(); |
+ |
+ // Returns CRWWKScriptMessafeRouter associated with WKWebViewConfiguration. |
+ // Lazily creates the router. Callers must not retain the returned object |
+ // (this will be enforced in debug builds). |
+ CRWWKScriptMessageRouter* GetScriptMessageRouter(); |
Eugene But (OOO till 7-30)
2015/03/30 05:03:58
Optional: Could you please exclude this file from
stuartmorgan
2015/03/30 14:17:57
Done.
|
+ |
+ // Returns true if this object holds a valid config. false if |
+ // |GetWebViewConfiguration| was never called or configuration was purged by |
+ // calling |Purge|. |
+ bool HasWebViewConfiguration() const; |
+ |
+ // Purges config and router objects if they exist. When this method is called |
+ // config, config's process pool and router must not be retained by anyone |
+ // (this will be enforced in debug builds). |HasWebViewConfiguration| will |
+ // return false after config is purged. |
+ void Purge(); |
+ |
+ private: |
+ WKWebViewConfigurationProvider(); |
+ ~WKWebViewConfigurationProvider() override; |
+ |
+ base::scoped_nsobject<WKWebViewConfiguration> configuration_; |
+ base::scoped_nsobject<CRWWKScriptMessageRouter> router_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(WKWebViewConfigurationProvider); |
+}; |
+ |
+} // namespace web |
+ |
+#endif // IOS_WEB_WEB_STATE_UI_WK_WEB_VIEW_CONFIGURATION_PROVIDER_H_ |