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