Commit 3af9e36a authored by Hiroshi Ichikawa's avatar Hiroshi Ichikawa Committed by Commit Bot

Fake Sync implementation in ios_web_view_shell.

Change-Id: I6187c15d04b5c1df5d3fc520a2647b2499d2720c
Reviewed-on: https://chromium-review.googlesource.com/c/1345711
Commit-Queue: Hiroshi Ichikawa <ichikawa@chromium.org>
Reviewed-by: default avatarJohn Wu <jzw@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610311}
parent 96bad709
...@@ -4,6 +4,19 @@ ...@@ -4,6 +4,19 @@
import("//build/config/ios/rules.gni") import("//build/config/ios/rules.gni")
declare_args() {
# Authorization service implementation used in ios_web_view_shell. Uses a fake
# implementation by default. Override this with a real implementation to make
# Sync feature work in the shell. The real implementation must provide
# implementation of ShellAuthService class.
ios_web_view_shell_auth_service =
"//ios/web_view/shell:shell_auth_service_fake_impl"
# Path to an entitlements file used in ios_web_view_shell. Can be overridden
# to provide an alternative.
ios_web_view_shell_entitlements_path = "//build/config/ios/entitlements.plist"
}
ios_app_bundle("ios_web_view_shell") { ios_app_bundle("ios_web_view_shell") {
info_plist = "Info.plist" info_plist = "Info.plist"
...@@ -11,6 +24,32 @@ ios_app_bundle("ios_web_view_shell") { ...@@ -11,6 +24,32 @@ ios_app_bundle("ios_web_view_shell") {
":shell", ":shell",
] ]
bundle_deps = [ "//ios/web_view:web_view+bundle" ] bundle_deps = [ "//ios/web_view:web_view+bundle" ]
entitlements_path = ios_web_view_shell_entitlements_path
configs += [ "//build/config/compiler:enable_arc" ]
}
source_set("shell_auth_service_interface") {
sources = [
"shell_auth_service.h",
]
deps = [
"//ios/web_view:web_view+link",
]
configs += [ "//build/config/compiler:enable_arc" ]
}
source_set("shell_auth_service_fake_impl") {
sources = [
"shell_auth_service_fake.m",
]
deps = [
":shell_auth_service_interface",
"//ios/web_view:web_view+link",
]
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
} }
...@@ -30,7 +69,9 @@ source_set("shell") { ...@@ -30,7 +69,9 @@ source_set("shell") {
deps = [ deps = [
":resources", ":resources",
":shell_auth_service_interface",
"//ios/web_view:web_view+link", "//ios/web_view:web_view+link",
ios_web_view_shell_auth_service,
] ]
libs = [ libs = [
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_VIEW_SHELL_SHELL_AUTH_SERVICE_H_
#define IOS_WEB_VIEW_SHELL_SHELL_AUTH_SERVICE_H_
#import <ChromeWebView/ChromeWebView.h>
NS_ASSUME_NONNULL_BEGIN
// Authorization service for ios_web_view_shell.
@interface ShellAuthService : NSObject<CWVSyncControllerDataSource>
// Returns available identities.
- (NSArray<CWVIdentity*>*)identities;
@end
NS_ASSUME_NONNULL_END
#endif // IOS_WEB_VIEW_SHELL_SHELL_AUTH_SERVICE_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/web_view/shell/shell_auth_service.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// Fake implementation of ShellAuthService.
@implementation ShellAuthService
- (NSArray<CWVIdentity*>*)identities {
return @[];
}
#pragma mark CWVSyncControllerDataSource
- (void)syncController:(CWVSyncController*)syncController
getAccessTokenForScopes:(NSArray<NSString*>*)scopes
completionHandler:(void (^)(NSString* accessToken,
NSDate* expirationDate,
NSError* error))completionHandler {
// Always returns an error.
if (completionHandler) {
completionHandler(
nil, nil,
[NSError errorWithDomain:@"org.chromium.chromewebview.shell"
code:0
userInfo:nil]);
}
}
@end
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#import <MobileCoreServices/MobileCoreServices.h> #import <MobileCoreServices/MobileCoreServices.h>
#import "ios/web_view/shell/shell_auth_service.h"
#import "ios/web_view/shell/shell_autofill_delegate.h" #import "ios/web_view/shell/shell_autofill_delegate.h"
#import "ios/web_view/shell/shell_translation_delegate.h" #import "ios/web_view/shell/shell_translation_delegate.h"
...@@ -24,6 +25,7 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier = ...@@ -24,6 +25,7 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier =
CWVNavigationDelegate, CWVNavigationDelegate,
CWVUIDelegate, CWVUIDelegate,
CWVScriptCommandHandler, CWVScriptCommandHandler,
CWVSyncControllerDelegate,
UITextFieldDelegate> UITextFieldDelegate>
// Container for |webView|. // Container for |webView|.
@property(nonatomic, strong) UIView* containerView; @property(nonatomic, strong) UIView* containerView;
...@@ -46,6 +48,7 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier = ...@@ -46,6 +48,7 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier =
// A controller to show a "Share" menu for the downloaded file. // A controller to show a "Share" menu for the downloaded file.
@property(nonatomic, strong, nullable) @property(nonatomic, strong, nullable)
UIDocumentInteractionController* documentInteractionController; UIDocumentInteractionController* documentInteractionController;
@property(nonatomic, strong) ShellAuthService* authService;
- (void)back; - (void)back;
- (void)forward; - (void)forward;
...@@ -69,6 +72,7 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier = ...@@ -69,6 +72,7 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier =
@synthesize downloadTask = _downloadTask; @synthesize downloadTask = _downloadTask;
@synthesize downloadFilePath = _downloadFilePath; @synthesize downloadFilePath = _downloadFilePath;
@synthesize documentInteractionController = _documentInteractionController; @synthesize documentInteractionController = _documentInteractionController;
@synthesize authService = _authService;
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
...@@ -160,8 +164,12 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier = ...@@ -160,8 +164,12 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier =
[CWVWebView setUserAgentProduct:@"Dummy/1.0"]; [CWVWebView setUserAgentProduct:@"Dummy/1.0"];
[self createWebViewWithConfiguration:[CWVWebViewConfiguration CWVWebViewConfiguration* configuration =
defaultConfiguration]]; [CWVWebViewConfiguration defaultConfiguration];
configuration.syncController.delegate = self;
[self createWebViewWithConfiguration:configuration];
_authService = [[ShellAuthService alloc] init];
} }
- (void)observeValueForKeyPath:(NSString*)keyPath - (void)observeValueForKeyPath:(NSString*)keyPath
...@@ -251,6 +259,32 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier = ...@@ -251,6 +259,32 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier =
[weakSelf resetTranslateSettings]; [weakSelf resetTranslateSettings];
}]]; }]];
for (CWVIdentity* identity in [_authService identities]) {
NSString* title =
[NSString stringWithFormat:@"Start sync with %@", identity.email];
[alertController
addAction:[UIAlertAction
actionWithTitle:title
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action) {
CWVSyncController* syncController =
weakSelf.webView.configuration
.syncController;
[syncController
startSyncWithIdentity:identity
dataSource:_authService];
}]];
}
[alertController
addAction:[UIAlertAction
actionWithTitle:@"Stop sync"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* action) {
[weakSelf.webView.configuration
.syncController stopSyncAndClearIdentity];
}]];
[self presentViewController:alertController animated:YES completion:nil]; [self presentViewController:alertController animated:YES completion:nil];
} }
...@@ -571,4 +605,20 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier = ...@@ -571,4 +605,20 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier =
NSLog(@"%@", NSStringFromSelector(_cmd)); NSLog(@"%@", NSStringFromSelector(_cmd));
} }
#pragma mark CWVSyncControllerDelegate
- (void)syncControllerDidStartSync:(CWVSyncController*)syncController {
NSLog(@"%@", NSStringFromSelector(_cmd));
}
- (void)syncController:(CWVSyncController*)syncController
didFailWithError:(NSError*)error {
NSLog(@"%@:%@", NSStringFromSelector(_cmd), error);
}
- (void)syncController:(CWVSyncController*)syncController
didStopSyncWithReason:(CWVStopSyncReason)reason {
NSLog(@"%@:%ld", NSStringFromSelector(_cmd), reason);
}
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment