summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/translate/page_translator.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/renderer/translate/page_translator.cc')
-rw-r--r--chrome/renderer/translate/page_translator.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/chrome/renderer/translate/page_translator.cc b/chrome/renderer/translate/page_translator.cc
index 8119a8d..df0a59b 100644
--- a/chrome/renderer/translate/page_translator.cc
+++ b/chrome/renderer/translate/page_translator.cc
@@ -79,6 +79,8 @@ void PageTranslator::Translate(WebKit::WebFrame* web_frame,
string16 text = static_cast<string16>(text_nodes_iter->nodeValue());
DCHECK(!ContainsOnlyWhitespace(text));
text_chunks.push_back(text);
+ // Store the original text so we can undo the translation if requested.
+ text_nodes_.push_back(NodeTextPair(*text_nodes_iter, text));
}
// Send the text for translation.
bool secure = static_cast<GURL>(web_frame->top()->url()).SchemeIsSecure();
@@ -89,6 +91,21 @@ void PageTranslator::Translate(WebKit::WebFrame* web_frame,
}
}
+void PageTranslator::NavigatedToNewPage() {
+ // We can drop all our states, they were related to the previous page.
+ ResetPageState();
+}
+
+void PageTranslator::UndoTranslation() {
+ // Revert all text nodes to their original contents.
+ std::vector<NodeTextPair>::iterator iter;
+ for (iter = text_nodes_.begin(); iter != text_nodes_.end(); ++iter)
+ iter->first.setNodeValue(iter->second);
+
+ // The page is back to its original content, we can dop all our states.
+ ResetPageState();
+}
+
bool PageTranslator::ShouldElementBeTraversed(WebKit::WebElement element) {
return ignored_tags_.find(element.tagName()) == ignored_tags_.end();
}
@@ -108,6 +125,11 @@ void PageTranslator::ClearNodeZone(int work_id) {
pending_translations_.erase(iter);
}
+void PageTranslator::ResetPageState() {
+ pending_translations_.clear();
+ text_nodes_.clear();
+}
+
void PageTranslator::TranslationError(int work_id, int error_id) {
// TODO(jcampan): may be we should show somehow that something went wrong to
// the user?