| 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" | 10 #import "base/mac/scoped_nsobject.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 WKWebViewConfigurationProvider::FromBrowserState(browser_state); | 29 WKWebViewConfigurationProvider::FromBrowserState(browser_state); |
| 30 DCHECK_EQ([config_provider.GetWebViewConfiguration() processPool], | 30 DCHECK_EQ([config_provider.GetWebViewConfiguration() processPool], |
| 31 [configuration processPool]); | 31 [configuration processPool]); |
| 32 } | 32 } |
| 33 | 33 |
| 34 } // namespace | 34 } // namespace |
| 35 | 35 |
| 36 WKWebView* BuildWKWebView(CGRect frame, | 36 WKWebView* BuildWKWebView(CGRect frame, |
| 37 WKWebViewConfiguration* configuration, | 37 WKWebViewConfiguration* configuration, |
| 38 BrowserState* browser_state, | 38 BrowserState* browser_state, |
| 39 BOOL use_desktop_user_agent, | 39 UserAgentType user_agent_type, |
| 40 id<CRWContextMenuDelegate> context_menu_delegate) { | 40 id<CRWContextMenuDelegate> context_menu_delegate) { |
| 41 VerifyWKWebViewCreationPreConditions(browser_state, configuration); | 41 VerifyWKWebViewCreationPreConditions(browser_state, configuration); |
| 42 | 42 |
| 43 GetWebClient()->PreWebViewCreation(); | 43 GetWebClient()->PreWebViewCreation(); |
| 44 WKWebView* web_view = | 44 WKWebView* web_view = |
| 45 [[WKWebView alloc] initWithFrame:frame configuration:configuration]; | 45 [[WKWebView alloc] initWithFrame:frame configuration:configuration]; |
| 46 | 46 |
| 47 // Set the user agent. | 47 if (user_agent_type != web::UserAgentType::NONE) { |
| 48 UserAgentType user_agent_type = | 48 web_view.customUserAgent = base::SysUTF8ToNSString( |
| 49 use_desktop_user_agent ? UserAgentType::DESKTOP : UserAgentType::MOBILE; | 49 web::GetWebClient()->GetUserAgent(user_agent_type)); |
| 50 web_view.customUserAgent = base::SysUTF8ToNSString( | 50 } |
| 51 web::GetWebClient()->GetUserAgent(user_agent_type)); | |
| 52 | 51 |
| 53 // By default the web view uses a very sluggish scroll speed. Set it to a more | 52 // By default the web view uses a very sluggish scroll speed. Set it to a more |
| 54 // reasonable value. | 53 // reasonable value. |
| 55 web_view.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal; | 54 web_view.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal; |
| 56 | 55 |
| 57 // Starting in iOS10, |allowsLinkPreview| defaults to YES. This should be | 56 // Starting in iOS10, |allowsLinkPreview| defaults to YES. This should be |
| 58 // disabled since the default implementation will open the link in Safari. | 57 // disabled since the default implementation will open the link in Safari. |
| 59 // TODO(crbug.com/622746): Remove once web// link preview implementation is | 58 // TODO(crbug.com/622746): Remove once web// link preview implementation is |
| 60 // created. | 59 // created. |
| 61 web_view.allowsLinkPreview = NO; | 60 web_view.allowsLinkPreview = NO; |
| 62 | 61 |
| 63 if (context_menu_delegate) { | 62 if (context_menu_delegate) { |
| 64 base::scoped_nsobject<CRWContextMenuController> context_menu_controller( | 63 base::scoped_nsobject<CRWContextMenuController> context_menu_controller( |
| 65 [[CRWContextMenuController alloc] | 64 [[CRWContextMenuController alloc] |
| 66 initWithWebView:web_view | 65 initWithWebView:web_view |
| 67 injectionEvaluator:nil | 66 injectionEvaluator:nil |
| 68 delegate:context_menu_delegate]); | 67 delegate:context_menu_delegate]); |
| 69 objc_setAssociatedObject(web_view, context_menu_controller.get(), | 68 objc_setAssociatedObject(web_view, context_menu_controller.get(), |
| 70 context_menu_controller.get(), | 69 context_menu_controller.get(), |
| 71 OBJC_ASSOCIATION_RETAIN_NONATOMIC); | 70 OBJC_ASSOCIATION_RETAIN_NONATOMIC); |
| 72 } | 71 } |
| 73 | 72 |
| 74 return [web_view autorelease]; | 73 return [web_view autorelease]; |
| 75 } | 74 } |
| 76 | 75 |
| 77 WKWebView* BuildWKWebView(CGRect frame, | 76 WKWebView* BuildWKWebView(CGRect frame, |
| 78 WKWebViewConfiguration* configuration, | 77 WKWebViewConfiguration* configuration, |
| 79 BrowserState* browser_state, | 78 BrowserState* browser_state, |
| 80 BOOL use_desktop_user_agent) { | 79 UserAgentType user_agent_type) { |
| 81 return BuildWKWebView(frame, configuration, browser_state, | 80 return BuildWKWebView(frame, configuration, browser_state, user_agent_type, |
| 82 use_desktop_user_agent, nil); | 81 nil); |
| 83 } | 82 } |
| 84 | 83 |
| 85 WKWebView* BuildWKWebView(CGRect frame, | 84 WKWebView* BuildWKWebView(CGRect frame, |
| 86 WKWebViewConfiguration* configuration, | 85 WKWebViewConfiguration* configuration, |
| 87 BrowserState* browser_state) { | 86 BrowserState* browser_state) { |
| 88 BOOL use_desktop_user_agent = NO; | |
| 89 return BuildWKWebView(frame, configuration, browser_state, | 87 return BuildWKWebView(frame, configuration, browser_state, |
| 90 use_desktop_user_agent); | 88 UserAgentType::MOBILE); |
| 91 } | 89 } |
| 92 | 90 |
| 93 } // namespace web | 91 } // namespace web |
| OLD | NEW |