diff options
author | shreyasv <shreyasv@chromium.org> | 2015-08-06 20:11:21 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-07 03:11:58 +0000 |
commit | 77c475e92057174e499223f350c31986a5f49d32 (patch) | |
tree | 6d5d85008648720b95fa73ef4418b89622bee19c /ios | |
parent | 8796cfabae6d59a33895e8ad6928b077b40a72eb (diff) | |
download | chromium_src-77c475e92057174e499223f350c31986a5f49d32.zip chromium_src-77c475e92057174e499223f350c31986a5f49d32.tar.gz chromium_src-77c475e92057174e499223f350c31986a5f49d32.tar.bz2 |
Adding 2 WebClient method
1) AllowWebViewAllocInit
This is a way to let the embedder choose if it wants to allow
creation of web views using alloc, init
2) WebViewsNeedActiveStateManager
This is a way to let the embedder choose if it wants
to implement modal data partitioning.
Modal data partitioning is a "mode" in web/
by which browsing data (incl. Cookies, LocalStorage) will
be separated between BrowserStates.
An embedder may choose to use web in this mode however
this comes with a set of caveats that the embedder needs to
adhere to. Not every web embedder may choose to do the extra
work involved in adopting this mode. This WebClient methods
is way to specify that.
BUG=480507
Review URL: https://codereview.chromium.org/1258413005
Cr-Commit-Position: refs/heads/master@{#342283}
Diffstat (limited to 'ios')
-rw-r--r-- | ios/web/public/web_client.h | 17 | ||||
-rw-r--r-- | ios/web/public/web_client.mm | 8 | ||||
-rw-r--r-- | ios/web/web_state/ui/wk_web_view_configuration_provider.mm | 3 | ||||
-rw-r--r-- | ios/web/web_state/web_view_internal_creation_util.h | 6 | ||||
-rw-r--r-- | ios/web/web_state/web_view_internal_creation_util.mm | 49 |
5 files changed, 73 insertions, 10 deletions
diff --git a/ios/web/public/web_client.h b/ios/web/public/web_client.h index 407308c..d1eba01 100644 --- a/ios/web/public/web_client.h +++ b/ios/web/public/web_client.h @@ -68,6 +68,23 @@ class WebClient { // browser would return true for "chrome://about" URL. virtual bool IsAppSpecificURL(const GURL& url) const; + // Returns true if web views can be created using an alloc, init call. + // Web view creation using an alloc, init call is disabled by default. + // If this is disallowed all web view creation must happen through the + // web view creation utils methods that vend a web view. + // This is called once (only in debug builds) before the first web view is + // created and not called repeatedly. + virtual bool AllowWebViewAllocInit() const; + + // Returns true if all web views that are created need to be associated with + // a BrowserState. + // This method is only called if the |AllowWebViewAllocInit| returns false. + // If this method returns true, web views can only be created + // with the BrowserState whose ActiveStateManager is active. + // This is called once (only in debug builds) when the first web view is + // created and not called repeatedly. + virtual bool WebViewsNeedActiveStateManager() const; + // Returns text to be displayed for an unsupported plugin. virtual base::string16 GetPluginNotSupportedText() const; diff --git a/ios/web/public/web_client.mm b/ios/web/public/web_client.mm index 1547f95..bf6985a 100644 --- a/ios/web/public/web_client.mm +++ b/ios/web/public/web_client.mm @@ -40,6 +40,14 @@ bool WebClient::IsAppSpecificURL(const GURL& url) const { return false; } +bool WebClient::AllowWebViewAllocInit() const { + return false; +} + +bool WebClient::WebViewsNeedActiveStateManager() const { + return false; +} + base::string16 WebClient::GetPluginNotSupportedText() const { return base::string16(); } diff --git a/ios/web/web_state/ui/wk_web_view_configuration_provider.mm b/ios/web/web_state/ui/wk_web_view_configuration_provider.mm index f5015a1..3f15213 100644 --- a/ios/web/web_state/ui/wk_web_view_configuration_provider.mm +++ b/ios/web/web_state/ui/wk_web_view_configuration_provider.mm @@ -12,6 +12,7 @@ #import "ios/web/alloc_with_zone_interceptor.h" #include "ios/web/public/browser_state.h" #import "ios/web/web_state/js/page_script_util.h" +#import "ios/web/web_state/web_view_internal_creation_util.h" #if !defined(NDEBUG) @@ -26,7 +27,7 @@ BOOL gAllowWKProcessPoolCreation = NO; + (void)load { id (^allocator)(Class klass, NSZone* zone) = ^id(Class klass, NSZone* zone) { - if (gAllowWKProcessPoolCreation) { + if (gAllowWKProcessPoolCreation || web::IsWebViewAllocInitAllowed()) { return NSAllocateObject(klass, 0, zone); } // You have hit this because you are trying to create a WKProcessPool diff --git a/ios/web/web_state/web_view_internal_creation_util.h b/ios/web/web_state/web_view_internal_creation_util.h index dc786d9..c53fae8 100644 --- a/ios/web/web_state/web_view_internal_creation_util.h +++ b/ios/web/web_state/web_view_internal_creation_util.h @@ -93,6 +93,12 @@ UIWebView* CreateStaticFileWebView(CGRect frame, BrowserState* browser_state); // Note: Callers are responsible for releasing the returned UIWebView. UIWebView* CreateStaticFileWebView(); +#if !defined(NDEBUG) +// Returns true if the creation of web views using alloc, init has been allowed +// by the embedder. +bool IsWebViewAllocInitAllowed(); +#endif + } // namespace web #endif // IOS_WEB_WEB_STATE_WEB_VIEW_INTERNAL_CREATION_UTIL_H_ diff --git a/ios/web/web_state/web_view_internal_creation_util.mm b/ios/web/web_state/web_view_internal_creation_util.mm index f92755b..c25283a 100644 --- a/ios/web/web_state/web_view_internal_creation_util.mm +++ b/ios/web/web_state/web_view_internal_creation_util.mm @@ -10,6 +10,7 @@ #include "base/logging.h" #include "base/mac/scoped_nsobject.h" #import "ios/web/alloc_with_zone_interceptor.h" +#include "ios/web/public/active_state_manager.h" #include "ios/web/public/browser_state.h" #import "ios/web/public/browsing_data_partition.h" #include "ios/web/public/web_client.h" @@ -38,8 +39,14 @@ web::WeakNSObjectCounter& GetActiveWKWebViewCounter() { static web::WeakNSObjectCounter active_wk_web_view_counter; return active_wk_web_view_counter; } -// Decides if WKWebView can be created. -BOOL gAllowWKWebViewCreation = NO; + +// Decides if web views can be created. +bool gAllowWebViewCreation = NO; + +// Decides if web views are associated with an ActiveStateManager which is +// active. +bool gWebViewsNeedActiveStateManager = NO; + } // namespace @interface WKWebView (CRWAdditions) @@ -49,7 +56,7 @@ BOOL gAllowWKWebViewCreation = NO; + (void)load { id (^allocator)(Class klass, NSZone* zone) = ^id(Class klass, NSZone* zone) { - if (gAllowWKWebViewCreation) { + if (web::IsWebViewAllocInitAllowed()) { return NSAllocateObject(klass, 0, zone); } // You have hit this because you are trying to create a WKWebView directly. @@ -85,12 +92,15 @@ void VerifyWKWebViewCreationPreConditions( } // Called before a WKWebView is created. -void PreWKWebViewCreation() { - DCHECK(web::GetWebClient()); - web::GetWebClient()->PreWebViewCreation(); +void PreWKWebViewCreation(BrowserState* browser_state) { + DCHECK(browser_state); + DCHECK(GetWebClient()); + GetWebClient()->PreWebViewCreation(); #if !defined(NDEBUG) - gAllowWKWebViewCreation = YES; + if (IsWebViewAllocInitAllowed() && gWebViewsNeedActiveStateManager) { + DCHECK(BrowserState::GetActiveStateManager(browser_state)->IsActive()); + } #endif } @@ -100,7 +110,6 @@ void PostWKWebViewCreation(WKWebView* web_view, BrowserState* browser_state) { #if !defined(NDEBUG) GetActiveWKWebViewCounter().Insert(web_view); - gAllowWKWebViewCreation = NO; #endif WebViewCounterImpl* web_view_counter = @@ -166,9 +175,16 @@ WKWebView* CreateWKWebView(CGRect frame, BrowserState* browser_state) { VerifyWKWebViewCreationPreConditions(browser_state, configuration); - PreWKWebViewCreation(); + PreWKWebViewCreation(browser_state); +#if !defined(NDEBUG) + bool previous_allow_web_view_creation_value = gAllowWebViewCreation; + gAllowWebViewCreation = true; +#endif WKWebView* result = [[WKWebView alloc] initWithFrame:frame configuration:configuration]; +#if !defined(NDEBUG) + gAllowWebViewCreation = previous_allow_web_view_creation_value; +#endif PostWKWebViewCreation(result, browser_state); return result; @@ -233,4 +249,19 @@ UIWebView* CreateStaticFileWebView() { return CreateStaticFileWebView(CGRectZero, nullptr); } +#if !defined(NDEBUG) +bool IsWebViewAllocInitAllowed() { + static dispatch_once_t once_token = 0; + dispatch_once(&once_token, ^{ + DCHECK(GetWebClient()); + gAllowWebViewCreation = GetWebClient()->AllowWebViewAllocInit(); + if (!gAllowWebViewCreation) { + gWebViewsNeedActiveStateManager = + GetWebClient()->WebViewsNeedActiveStateManager(); + } + }); + return gAllowWebViewCreation; +} +#endif + } // namespace web |