| 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. | |
| 48 UserAgentType user_agent_type = | |
| 49 use_desktop_user_agent ? UserAgentType::DESKTOP : UserAgentType::MOBILE; | |
| 50 web_view.customUserAgent = base::SysUTF8ToNSString( | 47 web_view.customUserAgent = base::SysUTF8ToNSString( |
| 51 web::GetWebClient()->GetUserAgent(user_agent_type)); | 48 web::GetWebClient()->GetUserAgent(user_agent_type)); |
| 52 | 49 |
| 53 // By default the web view uses a very sluggish scroll speed. Set it to a more | 50 // By default the web view uses a very sluggish scroll speed. Set it to a more |
| 54 // reasonable value. | 51 // reasonable value. |
| 55 web_view.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal; | 52 web_view.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal; |
| 56 | 53 |
| 57 // Starting in iOS10, |allowsLinkPreview| defaults to YES. This should be | 54 // Starting in iOS10, |allowsLinkPreview| defaults to YES. This should be |
| 58 // disabled since the default implementation will open the link in Safari. | 55 // disabled since the default implementation will open the link in Safari. |
| 59 // TODO(crbug.com/622746): Remove once web// link preview implementation is | 56 // TODO(crbug.com/622746): Remove once web// link preview implementation is |
| (...skipping 10 matching lines...) Expand all Loading... |
| 70 context_menu_controller.get(), | 67 context_menu_controller.get(), |
| 71 OBJC_ASSOCIATION_RETAIN_NONATOMIC); | 68 OBJC_ASSOCIATION_RETAIN_NONATOMIC); |
| 72 } | 69 } |
| 73 | 70 |
| 74 return [web_view autorelease]; | 71 return [web_view autorelease]; |
| 75 } | 72 } |
| 76 | 73 |
| 77 WKWebView* BuildWKWebView(CGRect frame, | 74 WKWebView* BuildWKWebView(CGRect frame, |
| 78 WKWebViewConfiguration* configuration, | 75 WKWebViewConfiguration* configuration, |
| 79 BrowserState* browser_state, | 76 BrowserState* browser_state, |
| 80 BOOL use_desktop_user_agent) { | 77 UserAgentType user_agent_type) { |
| 81 return BuildWKWebView(frame, configuration, browser_state, | 78 return BuildWKWebView(frame, configuration, browser_state, user_agent_type, |
| 82 use_desktop_user_agent, nil); | 79 nil); |
| 83 } | 80 } |
| 84 | 81 |
| 85 WKWebView* BuildWKWebView(CGRect frame, | 82 WKWebView* BuildWKWebView(CGRect frame, |
| 86 WKWebViewConfiguration* configuration, | 83 WKWebViewConfiguration* configuration, |
| 87 BrowserState* browser_state) { | 84 BrowserState* browser_state) { |
| 88 BOOL use_desktop_user_agent = NO; | |
| 89 return BuildWKWebView(frame, configuration, browser_state, | 85 return BuildWKWebView(frame, configuration, browser_state, |
| 90 use_desktop_user_agent); | 86 UserAgentType::MOBILE); |
| 91 } | 87 } |
| 92 | 88 |
| 93 } // namespace web | 89 } // namespace web |
| OLD | NEW |