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 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #import "base/mac/scoped_nsobject.h" | |
11 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
12 #import "ios/web/public/web_client.h" | 11 #import "ios/web/public/web_client.h" |
13 #import "ios/web/web_state/ui/crw_context_menu_controller.h" | 12 #import "ios/web/web_state/ui/crw_context_menu_controller.h" |
14 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" | 13 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" |
15 | 14 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 16 #error "This file requires ARC support." |
| 17 #endif |
| 18 |
16 namespace web { | 19 namespace web { |
17 | 20 |
18 namespace { | 21 namespace { |
19 | 22 |
20 // Verifies the preconditions for creating a WKWebView. Must be called before | 23 // Verifies the preconditions for creating a WKWebView. Must be called before |
21 // a WKWebView is allocated. Not verifying the preconditions before creating | 24 // a WKWebView is allocated. Not verifying the preconditions before creating |
22 // a WKWebView will lead to undefined behavior. | 25 // a WKWebView will lead to undefined behavior. |
23 void VerifyWKWebViewCreationPreConditions( | 26 void VerifyWKWebViewCreationPreConditions( |
24 BrowserState* browser_state, | 27 BrowserState* browser_state, |
25 WKWebViewConfiguration* configuration) { | 28 WKWebViewConfiguration* configuration) { |
(...skipping 27 matching lines...) Expand all Loading... |
53 // reasonable value. | 56 // reasonable value. |
54 web_view.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal; | 57 web_view.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal; |
55 | 58 |
56 // Starting in iOS10, |allowsLinkPreview| defaults to YES. This should be | 59 // Starting in iOS10, |allowsLinkPreview| defaults to YES. This should be |
57 // disabled since the default implementation will open the link in Safari. | 60 // disabled since the default implementation will open the link in Safari. |
58 // TODO(crbug.com/622746): Remove once web// link preview implementation is | 61 // TODO(crbug.com/622746): Remove once web// link preview implementation is |
59 // created. | 62 // created. |
60 web_view.allowsLinkPreview = NO; | 63 web_view.allowsLinkPreview = NO; |
61 | 64 |
62 if (context_menu_delegate) { | 65 if (context_menu_delegate) { |
63 base::scoped_nsobject<CRWContextMenuController> context_menu_controller( | 66 CRWContextMenuController* context_menu_controller = [ |
64 [[CRWContextMenuController alloc] | 67 [CRWContextMenuController alloc] initWithWebView:web_view |
65 initWithWebView:web_view | 68 injectionEvaluator:nil |
66 injectionEvaluator:nil | 69 delegate:context_menu_delegate]; |
67 delegate:context_menu_delegate]); | 70 void* associatedObjectKey = (__bridge void*)context_menu_controller; |
68 objc_setAssociatedObject(web_view, context_menu_controller.get(), | 71 objc_setAssociatedObject(web_view, associatedObjectKey, |
69 context_menu_controller.get(), | 72 context_menu_controller, |
70 OBJC_ASSOCIATION_RETAIN_NONATOMIC); | 73 OBJC_ASSOCIATION_RETAIN_NONATOMIC); |
71 } | 74 } |
72 | 75 |
73 return [web_view autorelease]; | 76 return web_view; |
74 } | 77 } |
75 | 78 |
76 WKWebView* BuildWKWebView(CGRect frame, | 79 WKWebView* BuildWKWebView(CGRect frame, |
77 WKWebViewConfiguration* configuration, | 80 WKWebViewConfiguration* configuration, |
78 BrowserState* browser_state, | 81 BrowserState* browser_state, |
79 UserAgentType user_agent_type) { | 82 UserAgentType user_agent_type) { |
80 return BuildWKWebView(frame, configuration, browser_state, user_agent_type, | 83 return BuildWKWebView(frame, configuration, browser_state, user_agent_type, |
81 nil); | 84 nil); |
82 } | 85 } |
83 | 86 |
84 WKWebView* BuildWKWebView(CGRect frame, | 87 WKWebView* BuildWKWebView(CGRect frame, |
85 WKWebViewConfiguration* configuration, | 88 WKWebViewConfiguration* configuration, |
86 BrowserState* browser_state) { | 89 BrowserState* browser_state) { |
87 return BuildWKWebView(frame, configuration, browser_state, | 90 return BuildWKWebView(frame, configuration, browser_state, |
88 UserAgentType::MOBILE); | 91 UserAgentType::MOBILE); |
89 } | 92 } |
90 | 93 |
91 } // namespace web | 94 } // namespace web |
OLD | NEW |