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

Unified Diff: ios/web_view/shell/shell_view_controller.m

Issue 2917583002: Add a menu item to toggle the incognito mode in ios_web_view_shell. (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web_view/shell/shell_view_controller.m
diff --git a/ios/web_view/shell/shell_view_controller.m b/ios/web_view/shell/shell_view_controller.m
index 3815f50d1358f9898b42881d4c3c358682fd2d69..9483b06802a1bcda7349abf35819f8930841124b 100644
--- a/ios/web_view/shell/shell_view_controller.m
+++ b/ios/web_view/shell/shell_view_controller.m
@@ -37,12 +37,14 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier =
@property(nonatomic, strong) CWVWebView* webView;
// Handles the translation of the content displayed in |webView|.
@property(nonatomic, strong) ShellTranslationDelegate* translationDelegate;
+// Whether it's in the incognito mode.
+@property(nonatomic) BOOL isIncognito;
michaeldo 2017/05/31 21:21:10 I actually think it would be better to either use
Hiroshi Ichikawa 2017/06/01 01:20:37 Done.
- (void)back;
- (void)forward;
- (void)stopLoading;
// Disconnects and release the |webView|.
-- (void)resetWebView;
+- (void)removeWebView;
@end
@implementation ShellViewController
@@ -54,6 +56,7 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier =
@synthesize toolbar = _toolbar;
@synthesize webView = _webView;
@synthesize translationDelegate = _translationDelegate;
+@synthesize isIncognito = _isIncognito;
- (void)viewDidLoad {
[super viewDidLoad];
@@ -157,33 +160,7 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier =
[CWVWebView setUserAgentProduct:@"Dummy/1.0"];
- CWVWebViewConfiguration* configuration =
- [CWVWebViewConfiguration defaultConfiguration];
- self.webView = [[CWVWebView alloc] initWithFrame:[_containerView bounds]
- configuration:configuration];
- // Gives a restoration identifier so that state restoration works.
- _webView.restorationIdentifier = @"webView";
- _webView.navigationDelegate = self;
- _webView.UIDelegate = self;
- _translationDelegate = [[ShellTranslationDelegate alloc] init];
- _webView.translationController.delegate = _translationDelegate;
-
- [_webView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
- UIViewAutoresizingFlexibleHeight];
- [_containerView addSubview:_webView];
-
- [_webView addObserver:self
- forKeyPath:@"canGoBack"
- options:NSKeyValueObservingOptionNew
- context:nil];
- [_webView addObserver:self
- forKeyPath:@"canGoForward"
- options:NSKeyValueObservingOptionNew
- context:nil];
-
- NSURLRequest* request = [NSURLRequest
- requestWithURL:[NSURL URLWithString:@"https://www.google.com/"]];
- [_webView loadRequest:request];
+ [self createWebViewWithConfiguration:[self createConfiguration]];
michaeldo 2017/05/31 21:21:09 I think explicitly using [CWVWebViewConfiguration
Hiroshi Ichikawa 2017/06/01 01:20:37 Done.
}
- (void)observeValueForKeyPath:(NSString*)keyPath
@@ -239,20 +216,73 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier =
[weakSelf.webView reload];
}]];
- // Removes the web view from the view hierarchy and releases it. For
- // testing deallocation behavior, because there have been multiple crash bugs
- // on deallocation of CWVWebView.
+ // Toggles the incognito mode.
+ NSString* incognitoActionTitle =
+ _isIncognito ? @"Exit incognito" : @"Enter incognito";
[alertController
- addAction:[UIAlertAction actionWithTitle:@"Deallocate web view"
- style:UIAlertActionStyleDefault
- handler:^(UIAlertAction* action) {
- [weakSelf resetWebView];
- }]];
+ addAction:[UIAlertAction
+ actionWithTitle:incognitoActionTitle
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction* action) {
+ [weakSelf removeWebView];
+ weakSelf.isIncognito = !weakSelf.isIncognito;
+ [weakSelf createWebViewWithConfiguration:
+ [weakSelf createConfiguration]];
+ }]];
+
+ // Removes the web view from the view hierarchy, releases it, and recreates
+ // the web view with the same configuration. This is for testing deallocation
+ // and sharing configuration, because there have been multiple bugs on these
michaeldo 2017/05/31 21:21:10 I think you can remove the ", because there have b
Hiroshi Ichikawa 2017/06/01 01:20:36 Done.
+ // features.
+ [alertController
+ addAction:[UIAlertAction
+ actionWithTitle:@"Recreate web view"
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction* action) {
+ CWVWebViewConfiguration* configuration =
+ weakSelf.webView.configuration;
+ [weakSelf removeWebView];
+ [weakSelf
+ createWebViewWithConfiguration:configuration];
+ }]];
[self presentViewController:alertController animated:YES completion:nil];
}
-- (void)resetWebView {
+- (CWVWebViewConfiguration*)createConfiguration {
michaeldo 2017/05/31 21:21:10 Per comment above, I don't think we need this. We
Hiroshi Ichikawa 2017/06/01 01:20:37 Done. I also extracted -toggleIncognito as a metho
+ return _isIncognito ? [CWVWebViewConfiguration incognitoConfiguration]
+ : [CWVWebViewConfiguration defaultConfiguration];
+}
+
+- (void)createWebViewWithConfiguration:(CWVWebViewConfiguration*)configuration {
+ self.webView = [[CWVWebView alloc] initWithFrame:[_containerView bounds]
+ configuration:configuration];
+ // Gives a restoration identifier so that state restoration works.
+ _webView.restorationIdentifier = @"webView";
+ _webView.navigationDelegate = self;
+ _webView.UIDelegate = self;
+ _translationDelegate = [[ShellTranslationDelegate alloc] init];
+ _webView.translationController.delegate = _translationDelegate;
+
+ [_webView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
+ UIViewAutoresizingFlexibleHeight];
+ [_containerView addSubview:_webView];
+
+ [_webView addObserver:self
+ forKeyPath:@"canGoBack"
+ options:NSKeyValueObservingOptionNew
+ context:nil];
+ [_webView addObserver:self
+ forKeyPath:@"canGoForward"
+ options:NSKeyValueObservingOptionNew
+ context:nil];
+
+ NSURLRequest* request = [NSURLRequest
+ requestWithURL:[NSURL URLWithString:@"https://www.google.com/"]];
+ [_webView loadRequest:request];
+}
+
+- (void)removeWebView {
[_webView removeFromSuperview];
[_webView removeObserver:self forKeyPath:@"canGoBack"];
[_webView removeObserver:self forKeyPath:@"canGoForward"];
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698