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

Unified Diff: ios/web_view/shell/translate_controller.mm

Issue 2653083002: Cleanup ios/web_view. (Closed)
Patch Set: Respond to more comments. Created 3 years, 11 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 | « ios/web_view/shell/translate_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web_view/shell/translate_controller.mm
diff --git a/ios/web_view/shell/translate_controller.mm b/ios/web_view/shell/translate_controller.mm
new file mode 100644
index 0000000000000000000000000000000000000000..8306de6298de1b76d5a8d5ff79d5ff23c03b6401
--- /dev/null
+++ b/ios/web_view/shell/translate_controller.mm
@@ -0,0 +1,69 @@
+// Copyright 2014 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/translate_controller.h"
+
+#import <UIKit/UIKit.h>
+
+#include "base/logging.h"
+#import "base/mac/scoped_nsobject.h"
+#import "ios/web_view/public/criwv_translate_manager.h"
+
+@interface TranslateController () {
+ base::scoped_nsobject<UIAlertController> _beforeTranslateActionSheet;
+ base::scoped_nsprotocol<id<CRIWVTranslateManager>> _translateManager;
+}
+@end
+
+@implementation TranslateController
+
+- (void)dealloc {
+ [_beforeTranslateActionSheet dismissViewControllerAnimated:YES
+ completion:nil];
+ [super dealloc];
+}
+
+#pragma mark CRIWVTranslateDelegate methods
+
+- (void)translateStepChanged:(ios_web_view::CRIWVTransateStep)step
+ manager:(id<CRIWVTranslateManager>)manager {
+ if (step == ios_web_view::CRIWVTransateStepBeforeTranslate) {
+ DCHECK(!_translateManager);
+ DCHECK(!_beforeTranslateActionSheet);
+ _translateManager.reset([manager retain]);
+ _beforeTranslateActionSheet.reset([[UIAlertController
+ alertControllerWithTitle:nil
+ message:@"Translate?"
+ preferredStyle:UIAlertControllerStyleActionSheet] retain]);
+ UIAlertAction* cancelAction =
+ [UIAlertAction actionWithTitle:@"Nope."
+ style:UIAlertActionStyleCancel
+ handler:^(UIAlertAction* action) {
+ DCHECK(_beforeTranslateActionSheet);
+ _beforeTranslateActionSheet.reset();
+ DCHECK(_translateManager);
+ _translateManager.reset();
+ }];
+ [_beforeTranslateActionSheet addAction:cancelAction];
+
+ UIAlertAction* translateAction =
+ [UIAlertAction actionWithTitle:@"Yes!"
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction* action) {
+ DCHECK(_beforeTranslateActionSheet);
+ _beforeTranslateActionSheet.reset();
+ DCHECK(_translateManager);
+ [_translateManager translate];
+ _translateManager.reset();
+ }];
+ [_beforeTranslateActionSheet addAction:translateAction];
+
+ [[UIApplication sharedApplication].keyWindow.rootViewController
+ presentViewController:_beforeTranslateActionSheet
+ animated:YES
+ completion:nil];
+ }
+}
+
+@end
« no previous file with comments | « ios/web_view/shell/translate_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698