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

Side by Side Diff: chrome/renderer/translate/page_translator.cc

Issue 552216: This CL makes the TranslationService class send the text to be translated to ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include "chrome/renderer/translate/page_translator.h" 5 #include "chrome/renderer/translate/page_translator.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/task.h" 11 #include "base/task.h"
12 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" 12 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
13 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" 13 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h"
14 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" 14 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
15 #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" 15 #include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
16 #include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h" 16 #include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
17 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" 17 #include "third_party/WebKit/WebKit/chromium/public/WebString.h"
18 18
19 namespace {
20
19 // The following elements are not supposed to be translated. 21 // The following elements are not supposed to be translated.
20 const char* const kSkippedTags[] = { "APPLET", "AREA", "BASE", "FRAME", 22 const char* const kSkippedTags[] = { "APPLET", "AREA", "BASE", "FRAME",
21 "FRAMESET", "HR", "IFRAME", "IMG", "INPUT", "LINK", "META", "MAP", 23 "FRAMESET", "HR", "IFRAME", "IMG", "INPUT", "LINK", "META", "MAP",
22 "OBJECT", "PARAM", "SCRIPT", "STYLE", "TEXTAREA" }; 24 "OBJECT", "PARAM", "SCRIPT", "STYLE", "TEXTAREA" };
23 25
24 // The following tags are not considered as breaking a block of text. 26 // The following tags are not considered as breaking a block of text.
25 // Notes: does SPAN belong to this list? 27 // Notes: does SPAN belong to this list?
26 const char* const kInlineTags[] = { "A", "ABBR", "ACRONYM", "B", "BIG", "DEL", 28 const char* const kInlineTags[] = { "A", "ABBR", "ACRONYM", "B", "BIG", "DEL",
27 "EM", "I", "INS", "S", "SPAN", "STRIKE", "STRONG", "SUB", "SUP", "U" }; 29 "EM", "I", "INS", "S", "SPAN", "STRIKE", "STRONG", "SUB", "SUP", "U" };
30 }
28 31
29 // Returns true when s1 < s2. 32 // Returns true when s1 < s2.
30 bool PageTranslator::WebStringCompare::operator()( 33 bool PageTranslator::WebStringCompare::operator()(
31 const WebKit::WebString& s1, const WebKit::WebString& s2) const { 34 const WebKit::WebString& s1, const WebKit::WebString& s2) const {
32 int len1 = s1.length(); 35 int len1 = s1.length();
33 int len2 = s2.length(); 36 int len2 = s2.length();
34 int r = base::strncmp16(s1.data(), s2.data(), std::min(len1, len2)); 37 int r = base::strncmp16(s1.data(), s2.data(), std::min(len1, len2));
35 38
36 if (r < 0) 39 if (r < 0)
37 return true; 40 return true;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 void PageTranslator::TranslationError(int work_id, int error_id) { 111 void PageTranslator::TranslationError(int work_id, int error_id) {
109 // TODO(jcampan): may be we should show somehow that something went wrong to 112 // TODO(jcampan): may be we should show somehow that something went wrong to
110 // the user? 113 // the user?
111 ClearNodeZone(work_id); 114 ClearNodeZone(work_id);
112 } 115 }
113 116
114 void PageTranslator::TextTranslated( 117 void PageTranslator::TextTranslated(
115 int work_id, const std::vector<string16>& translated_text_chunks) { 118 int work_id, const std::vector<string16>& translated_text_chunks) {
116 std::map<int, NodeList*>::iterator iter = pending_translations_.find(work_id); 119 std::map<int, NodeList*>::iterator iter = pending_translations_.find(work_id);
117 if (iter == pending_translations_.end()) { 120 if (iter == pending_translations_.end()) {
118 NOTREACHED() << "Translation results received for unknown node zone"; 121 // We received some translated text we were not expecting. It could be we
122 // navigated away from the page or that the translation was undone.
119 return; 123 return;
120 } 124 }
121 125
122 NodeList* nodes = iter->second; 126 NodeList* nodes = iter->second;
123 // Check the integrity of the response. 127 // Check the integrity of the response.
124 if (translated_text_chunks.size() != nodes->size()) { 128 if (translated_text_chunks.size() != nodes->size()) {
125 // TODO(jcampan) reenable when we figured out why the server messed up the 129 // TODO(jcampan) reenable when we figured out why the server messed up the
126 // anchor tags. 130 // anchor tags.
127 // NOTREACHED() << "Translation results received are inconsistent with the " 131 // NOTREACHED() << "Translation results received are inconsistent with the "
128 // "request"; 132 // "request";
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 179
176 if (new_text_block) { 180 if (new_text_block) {
177 NodeList* text_nodes = element_stack->top(); 181 NodeList* text_nodes = element_stack->top();
178 element_stack->pop(); 182 element_stack->pop();
179 // If no nodes were added to text_nodes, then it has not been added to 183 // If no nodes were added to text_nodes, then it has not been added to
180 // text_nodes_list and must be deleted. 184 // text_nodes_list and must be deleted.
181 if (text_nodes->empty()) 185 if (text_nodes->empty())
182 delete text_nodes; 186 delete text_nodes;
183 } 187 }
184 } 188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698