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.
5 #ifndef IOS_WEB_WEB_STATE_WEB_VIEW_INTERNAL_CREATION_UTIL_H_
6 #define IOS_WEB_WEB_STATE_WEB_VIEW_INTERNAL_CREATION_UTIL_H_
8 #import <UIKit/UIKit.h>
10 #include "ios/web/public/web_view_type.h"
12 @protocol CRWSimpleWebViewController
;
14 @
class WKWebViewConfiguration
;
16 // This file is a collection of functions that vend web views.
20 // Returns a new UIWebView for displaying regular web content and registers a
21 // user agent for it. The returned UIWebView will have a user agent string that
22 // includes the |request_group_id|.
23 // Note: Callers are responsible for releasing the returned UIWebView.
24 // TODO(shreyasv): Rename to CreateUIWebView.
25 UIWebView
* CreateWebView(CGRect frame
,
26 NSString
* request_group_id
,
27 BOOL use_desktop_user_agent
);
29 // Returns a new UIWebView for displaying regular web content.
30 // Note: Callers are responsible for releasing the returned UIWebView.
31 // TODO(shreyasv): Rename to CreateUIWebView.
32 UIWebView
* CreateWebView(CGRect frame
);
34 // Creates and returns a WKWebView. The returned WKWebView will have a
35 // user agent string that includes the |request_group_id|.
37 // Preconditions for creation of a WKWebView:
38 // 1) |browser_state|, |configuration| are not null.
39 // 2) web::BrowsingDataPartition is synchronized.
40 // 3) The WKProcessPool of the configuration is the same as the WKProcessPool
41 // of the WKWebViewConfiguration associated with |browser_state|.
43 // Note: Callers are responsible for releasing the returned WKWebView.
44 WKWebView
* CreateWKWebView(CGRect frame
,
45 WKWebViewConfiguration
* configuration
,
46 BrowserState
* browser_state
,
47 NSString
* request_group_id
,
48 BOOL use_desktop_user_agent
);
50 // Creates and returns a new WKWebView for displaying regular web content.
51 // The preconditions for the creation of a WKWebView are the same as the
53 // Note: Callers are responsible for releasing the returned WKWebView.
54 WKWebView
* CreateWKWebView(CGRect frame
,
55 WKWebViewConfiguration
* configuration
,
56 BrowserState
* browser_state
);
58 // Returns the total number of WKWebViews that are currently present.
59 // NOTE: This only works in Debug builds and should not be used in Release
61 // DEPRECATED. Please use web::WebViewCounter instead.
62 // TODO(shreyasv): Remove this once all callers have stopped using it.
64 NSUInteger
GetActiveWKWebViewsCount();
66 // Returns a CRWSimpleWebViewController for managing/showing a web view.
67 // The BrowsingDataPartition must be synchronized before this method is called.
68 // Note: Callers are responsible for releasing the CRWSimpleWebViewController.
69 id
<CRWSimpleWebViewController
> CreateSimpleWebViewController(
71 BrowserState
* browser_state
,
72 WebViewType web_view_type
);
74 // Returns a new CRWSimpleWebViewController subclass displaying static HTML file
75 // content stored in the application bundle.
76 // The BrowsingDataPartition must be synchronized before this method is called.
77 // Note: Callers are responsible for releasing the returned ViewController.
78 id
<CRWSimpleWebViewController
> CreateStaticFileSimpleWebViewController(
80 BrowserState
* browser_state
,
81 WebViewType web_view_type
);
83 // Returns a new UIWebView subclass for displaying static HTML file content
84 // stored in the application bundle. if |browser_state| is nullptr, requests
85 // from the returned UIWebView will be done with global request context. When
86 // requests are made with global request context, requests such as file://
88 // Note: Callers are responsible for releasing the returned UIWebView.
89 UIWebView
* CreateStaticFileWebView(CGRect frame
, BrowserState
* browser_state
);
91 // A convenience method that returns a static file web view with
92 // CGRectZero and |nullptr| browser state.
93 // Note: Callers are responsible for releasing the returned UIWebView.
94 UIWebView
* CreateStaticFileWebView();
97 // Returns true if the creation of web views using alloc, init has been allowed
99 bool IsWebViewAllocInitAllowed();
104 #endif // IOS_WEB_WEB_STATE_WEB_VIEW_INTERNAL_CREATION_UTIL_H_