| 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/web_state/web_view_internal_creation_util.h" | 5 #import "ios/web/web_state/web_view_internal_creation_util.h" |
| 6 | 6 |
| 7 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
| 8 #import <WebKit/WebKit.h> | 8 #import <WebKit/WebKit.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/mac/scoped_nsobject.h" | 11 #include "base/mac/scoped_nsobject.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 13 #import "ios/web/alloc_with_zone_interceptor.h" | 13 #import "ios/web/alloc_with_zone_interceptor.h" |
| 14 #include "ios/web/public/active_state_manager.h" | 14 #include "ios/web/public/active_state_manager.h" |
| 15 #include "ios/web/public/browser_state.h" | 15 #include "ios/web/public/browser_state.h" |
| 16 #import "ios/web/public/browsing_data_partition.h" | 16 #import "ios/web/public/browsing_data_partition.h" |
| 17 #include "ios/web/public/web_client.h" | 17 #include "ios/web/public/web_client.h" |
| 18 #import "ios/web/public/web_view_counter.h" | 18 #import "ios/web/public/web_view_counter.h" |
| 19 #import "ios/web/public/web_view_creation_util.h" | 19 #import "ios/web/public/web_view_creation_util.h" |
| 20 #include "ios/web/ui_web_view_util.h" | 20 #include "ios/web/ui_web_view_util.h" |
| 21 #import "ios/web/weak_nsobject_counter.h" | 21 #import "ios/web/weak_nsobject_counter.h" |
| 22 #import "ios/web/web_state/ui/crw_static_file_web_view.h" | |
| 23 #import "ios/web/web_state/ui/crw_ui_simple_web_view_controller.h" | |
| 24 #import "ios/web/web_state/ui/crw_wk_simple_web_view_controller.h" | 22 #import "ios/web/web_state/ui/crw_wk_simple_web_view_controller.h" |
| 25 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" | 23 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" |
| 26 #import "ios/web/web_view_counter_impl.h" | 24 #import "ios/web/web_view_counter_impl.h" |
| 27 | 25 |
| 28 #if !defined(NDEBUG) | 26 #if !defined(NDEBUG) |
| 29 | 27 |
| 30 namespace { | 28 namespace { |
| 31 // Returns the counter of all the active WKWebViews. | 29 // Returns the counter of all the active WKWebViews. |
| 32 // DEPRECATED. Please use web::WebViewCounter instead. | 30 // DEPRECATED. Please use web::WebViewCounter instead. |
| 33 // TODO(shreyasv): Remove this once all callers have stopped using it. | 31 // TODO(shreyasv): Remove this once all callers have stopped using it. |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 // This should not be used in release builds. | 186 // This should not be used in release builds. |
| 189 CHECK(0); | 187 CHECK(0); |
| 190 return 0; | 188 return 0; |
| 191 #else | 189 #else |
| 192 return GetActiveWKWebViewCounter().Size(); | 190 return GetActiveWKWebViewCounter().Size(); |
| 193 #endif | 191 #endif |
| 194 } | 192 } |
| 195 | 193 |
| 196 id<CRWSimpleWebViewController> CreateSimpleWebViewController( | 194 id<CRWSimpleWebViewController> CreateSimpleWebViewController( |
| 197 CGRect frame, | 195 CGRect frame, |
| 198 BrowserState* browser_state, | 196 BrowserState* browser_state) { |
| 199 WebViewType web_view_type) { | |
| 200 DCHECK(web::BrowsingDataPartition::IsSynchronized()); | 197 DCHECK(web::BrowsingDataPartition::IsSynchronized()); |
| 201 | 198 base::scoped_nsobject<WKWebView> web_view( |
| 202 // Transparently return the correct subclass. | 199 web::CreateWKWebView(frame, browser_state)); |
| 203 if (web_view_type == WK_WEB_VIEW_TYPE) { | 200 return [[CRWWKSimpleWebViewController alloc] initWithWKWebView:web_view]; |
| 204 base::scoped_nsobject<WKWebView> web_view( | |
| 205 web::CreateWKWebView(frame, browser_state)); | |
| 206 return [[CRWWKSimpleWebViewController alloc] initWithWKWebView:web_view]; | |
| 207 } | |
| 208 base::scoped_nsobject<UIWebView> web_view(web::CreateWebView(frame)); | |
| 209 return [[CRWUISimpleWebViewController alloc] initWithUIWebView:web_view]; | |
| 210 } | |
| 211 | |
| 212 id<CRWSimpleWebViewController> CreateStaticFileSimpleWebViewController( | |
| 213 CGRect frame, | |
| 214 BrowserState* browser_state, | |
| 215 WebViewType web_view_type) { | |
| 216 DCHECK(web::BrowsingDataPartition::IsSynchronized()); | |
| 217 | |
| 218 // Transparently return the correct subclass. | |
| 219 if (web_view_type == WK_WEB_VIEW_TYPE) { | |
| 220 // TOOD(shreyasv): Create a new util function vending a WKWebView, wrap that | |
| 221 // now return the UIWebView version. crbug.com/403634. | |
| 222 } | |
| 223 base::scoped_nsobject<UIWebView> staticFileWebView( | |
| 224 CreateStaticFileWebView(frame, browser_state)); | |
| 225 return [[CRWUISimpleWebViewController alloc] | |
| 226 initWithUIWebView:staticFileWebView]; | |
| 227 } | |
| 228 | |
| 229 UIWebView* CreateStaticFileWebView(CGRect frame, BrowserState* browser_state) { | |
| 230 DCHECK(web::GetWebClient()); | |
| 231 web::GetWebClient()->PreWebViewCreation(); | |
| 232 | |
| 233 UIWebView* result = | |
| 234 [[CRWStaticFileWebView alloc] initWithFrame:frame | |
| 235 browserState:browser_state]; | |
| 236 | |
| 237 web::GetWebClient()->PostWebViewCreation(result); | |
| 238 return result; | |
| 239 } | |
| 240 | |
| 241 UIWebView* CreateStaticFileWebView() { | |
| 242 return CreateStaticFileWebView(CGRectZero, nullptr); | |
| 243 } | 201 } |
| 244 | 202 |
| 245 #if !defined(NDEBUG) | 203 #if !defined(NDEBUG) |
| 246 bool IsWebViewAllocInitAllowed() { | 204 bool IsWebViewAllocInitAllowed() { |
| 247 static dispatch_once_t once_token = 0; | 205 static dispatch_once_t once_token = 0; |
| 248 dispatch_once(&once_token, ^{ | 206 dispatch_once(&once_token, ^{ |
| 249 DCHECK(GetWebClient()); | 207 DCHECK(GetWebClient()); |
| 250 gAllowWebViewCreation = GetWebClient()->AllowWebViewAllocInit(); | 208 gAllowWebViewCreation = GetWebClient()->AllowWebViewAllocInit(); |
| 251 if (!gAllowWebViewCreation) { | 209 if (!gAllowWebViewCreation) { |
| 252 gWebViewsNeedActiveStateManager = | 210 gWebViewsNeedActiveStateManager = |
| 253 GetWebClient()->WebViewsNeedActiveStateManager(); | 211 GetWebClient()->WebViewsNeedActiveStateManager(); |
| 254 } | 212 } |
| 255 }); | 213 }); |
| 256 return gAllowWebViewCreation; | 214 return gAllowWebViewCreation; |
| 257 } | 215 } |
| 258 #endif | 216 #endif |
| 259 | 217 |
| 260 } // namespace web | 218 } // namespace web |
| OLD | NEW |