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 "components/translate/ios/browser/translate_controller.h" | 5 #import "components/translate/ios/browser/translate_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #import "components/translate/ios/browser/js_translate_manager.h" | 12 #import "components/translate/ios/browser/js_translate_manager.h" |
13 #include "ios/web/public/web_state/web_state.h" | 13 #include "ios/web/public/web_state/web_state.h" |
14 | 14 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 16 #error "This file requires ARC support." |
| 17 #endif |
| 18 |
15 namespace translate { | 19 namespace translate { |
16 | 20 |
17 namespace { | 21 namespace { |
18 // Prefix for the translate javascript commands. Must be kept in sync with | 22 // Prefix for the translate javascript commands. Must be kept in sync with |
19 // translate_ios.js. | 23 // translate_ios.js. |
20 const char kCommandPrefix[] = "translate"; | 24 const char kCommandPrefix[] = "translate"; |
21 } | 25 } |
22 | 26 |
23 TranslateController::TranslateController(web::WebState* web_state, | 27 TranslateController::TranslateController(web::WebState* web_state, |
24 JsTranslateManager* manager) | 28 JsTranslateManager* manager) |
25 : web::WebStateObserver(web_state), | 29 : web::WebStateObserver(web_state), |
26 observer_(nullptr), | 30 observer_(nullptr), |
27 js_manager_([manager retain]), | 31 js_manager_(manager), |
28 weak_method_factory_(this) { | 32 weak_method_factory_(this) { |
29 DCHECK(js_manager_); | 33 DCHECK(js_manager_); |
30 DCHECK(web::WebStateObserver::web_state()); | 34 DCHECK(web::WebStateObserver::web_state()); |
31 web_state->AddScriptCommandCallback( | 35 web_state->AddScriptCommandCallback( |
32 base::Bind(&TranslateController::OnJavascriptCommandReceived, | 36 base::Bind(&TranslateController::OnJavascriptCommandReceived, |
33 base::Unretained(this)), | 37 base::Unretained(this)), |
34 kCommandPrefix); | 38 kCommandPrefix); |
35 } | 39 } |
36 | 40 |
37 TranslateController::~TranslateController() { | 41 TranslateController::~TranslateController() { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 return true; | 135 return true; |
132 } | 136 } |
133 | 137 |
134 // web::WebStateObserver implementation. | 138 // web::WebStateObserver implementation. |
135 | 139 |
136 void TranslateController::WebStateDestroyed() { | 140 void TranslateController::WebStateDestroyed() { |
137 web_state()->RemoveScriptCommandCallback(kCommandPrefix); | 141 web_state()->RemoveScriptCommandCallback(kCommandPrefix); |
138 } | 142 } |
139 | 143 |
140 } // namespace translate | 144 } // namespace translate |
OLD | NEW |