Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Unified Diff: ios/web_view/internal/cwv_web_view_configuration.mm

Issue 2791403005: Remove CWV class and move setting User Agent to CWVWebViewConfiguration. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/web_view/internal/cwv_web_view_configuration.mm
diff --git a/ios/web_view/internal/cwv_web_view_configuration.mm b/ios/web_view/internal/cwv_web_view_configuration.mm
index d8916d719da520424576cd898b40c9e11e064559..2e18a9dbb6458a5c615a29aab2475d876f68a408 100644
--- a/ios/web_view/internal/cwv_web_view_configuration.mm
+++ b/ios/web_view/internal/cwv_web_view_configuration.mm
@@ -5,9 +5,13 @@
#import "ios/web_view/public/cwv_web_view_configuration.h"
#import "ios/web_view/internal/cwv_web_view_configuration_internal.h"
+#include "base/memory/ptr_util.h"
+#include "base/strings/sys_string_conversions.h"
+#include "ios/web/public/app/web_main.h"
#import "ios/web_view/internal/cwv_user_content_controller_internal.h"
#import "ios/web_view/internal/web_view_browser_state.h"
#import "ios/web_view/internal/web_view_web_client.h"
+#import "ios/web_view/internal/web_view_web_main_delegate.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
@@ -19,6 +23,9 @@
(ios_web_view::WebViewBrowserState*)browserState;
@end
+// The name of the product to be used in the User Agent string.
+static NSString* userAgentProductName;
+
@implementation CWVWebViewConfiguration {
// TODO(crbug.com/690182): CWVWebViewConfiguration should own _browserState.
ios_web_view::WebViewBrowserState* _browserState;
@@ -30,6 +37,8 @@
static dispatch_once_t once;
static CWVWebViewConfiguration* configuration;
dispatch_once(&once, ^{
+ [self setupWebClientIfNeeded];
+
ios_web_view::WebViewWebClient* client =
static_cast<ios_web_view::WebViewWebClient*>(web::GetWebClient());
configuration = [[self alloc] initWithBrowserState:client->browser_state()];
@@ -41,6 +50,8 @@
static dispatch_once_t once;
static CWVWebViewConfiguration* configuration;
dispatch_once(&once, ^{
+ [self setupWebClientIfNeeded];
+
ios_web_view::WebViewWebClient* client =
static_cast<ios_web_view::WebViewWebClient*>(web::GetWebClient());
configuration = [[self alloc]
@@ -49,6 +60,23 @@
return configuration;
}
++ (void)setupWebClientIfNeeded {
Eugene But (OOO till 7-30) 2017/04/04 21:50:26 Does this method need a different name? It does no
Eugene But (OOO till 7-30) 2017/04/04 21:50:26 Please add comments.
michaeldo 2017/04/07 22:31:35 PTAL, in newest patch, I renamed to webClient and
+ static std::unique_ptr<ios_web_view::WebViewWebMainDelegate> webMainDelegate;
+ static std::unique_ptr<web::WebMain> webMain;
+
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ webMainDelegate = base::MakeUnique<ios_web_view::WebViewWebMainDelegate>(
+ base::SysNSStringToUTF8(userAgentProductName));
+ web::WebMainParams params(webMainDelegate.get());
+ webMain = base::MakeUnique<web::WebMain>(params);
+ });
+}
+
++ (void)setUserAgentProductName:(NSString*)productName {
+ userAgentProductName = productName;
+}
+
- (instancetype)initWithBrowserState:
(ios_web_view::WebViewBrowserState*)browserState {
self = [super init];

Powered by Google App Engine
This is Rietveld 408576698