Chromium Code Reviews| 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" | 22 #import "ios/web/web_state/ui/crw_ui_simple_web_view_controller.h" |
|
Eugene But (OOO till 7-30)
2016/03/14 22:52:45
Do you still need this include?
shreyasv1
2016/03/14 22:54:16
Good catch. Done.
| |
| 24 #import "ios/web/web_state/ui/crw_wk_simple_web_view_controller.h" | 23 #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" | 24 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" |
| 26 #import "ios/web/web_view_counter_impl.h" | 25 #import "ios/web/web_view_counter_impl.h" |
| 27 | 26 |
| 28 #if !defined(NDEBUG) | 27 #if !defined(NDEBUG) |
| 29 | 28 |
| 30 namespace { | 29 namespace { |
| 31 // Returns the counter of all the active WKWebViews. | 30 // Returns the counter of all the active WKWebViews. |
| 32 // DEPRECATED. Please use web::WebViewCounter instead. | 31 // DEPRECATED. Please use web::WebViewCounter instead. |
| 33 // TODO(shreyasv): Remove this once all callers have stopped using it. | 32 // 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. | 187 // This should not be used in release builds. |
| 189 CHECK(0); | 188 CHECK(0); |
| 190 return 0; | 189 return 0; |
| 191 #else | 190 #else |
| 192 return GetActiveWKWebViewCounter().Size(); | 191 return GetActiveWKWebViewCounter().Size(); |
| 193 #endif | 192 #endif |
| 194 } | 193 } |
| 195 | 194 |
| 196 id<CRWSimpleWebViewController> CreateSimpleWebViewController( | 195 id<CRWSimpleWebViewController> CreateSimpleWebViewController( |
| 197 CGRect frame, | 196 CGRect frame, |
| 198 BrowserState* browser_state, | 197 BrowserState* browser_state) { |
| 199 WebViewType web_view_type) { | |
| 200 DCHECK(web::BrowsingDataPartition::IsSynchronized()); | 198 DCHECK(web::BrowsingDataPartition::IsSynchronized()); |
| 201 | 199 base::scoped_nsobject<WKWebView> web_view( |
| 202 // Transparently return the correct subclass. | 200 web::CreateWKWebView(frame, browser_state)); |
| 203 if (web_view_type == WK_WEB_VIEW_TYPE) { | 201 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 } | 202 } |
| 244 | 203 |
| 245 #if !defined(NDEBUG) | 204 #if !defined(NDEBUG) |
| 246 bool IsWebViewAllocInitAllowed() { | 205 bool IsWebViewAllocInitAllowed() { |
| 247 static dispatch_once_t once_token = 0; | 206 static dispatch_once_t once_token = 0; |
| 248 dispatch_once(&once_token, ^{ | 207 dispatch_once(&once_token, ^{ |
| 249 DCHECK(GetWebClient()); | 208 DCHECK(GetWebClient()); |
| 250 gAllowWebViewCreation = GetWebClient()->AllowWebViewAllocInit(); | 209 gAllowWebViewCreation = GetWebClient()->AllowWebViewAllocInit(); |
| 251 if (!gAllowWebViewCreation) { | 210 if (!gAllowWebViewCreation) { |
| 252 gWebViewsNeedActiveStateManager = | 211 gWebViewsNeedActiveStateManager = |
| 253 GetWebClient()->WebViewsNeedActiveStateManager(); | 212 GetWebClient()->WebViewsNeedActiveStateManager(); |
| 254 } | 213 } |
| 255 }); | 214 }); |
| 256 return gAllowWebViewCreation; | 215 return gAllowWebViewCreation; |
| 257 } | 216 } |
| 258 #endif | 217 #endif |
| 259 | 218 |
| 260 } // namespace web | 219 } // namespace web |
| OLD | NEW |