Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_helper.h" | 5 #include "chrome/renderer/translate_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 // language of the intended audience (a distinction really only | 71 // language of the intended audience (a distinction really only |
| 72 // relevant for things like langauge textbooks). This distinction | 72 // relevant for things like langauge textbooks). This distinction |
| 73 // shouldn't affect translation. | 73 // shouldn't affect translation. |
| 74 std::string language = document.contentLanguage().utf8(); | 74 std::string language = document.contentLanguage().utf8(); |
| 75 size_t coma_index = language.find(','); | 75 size_t coma_index = language.find(','); |
| 76 if (coma_index != std::string::npos) { | 76 if (coma_index != std::string::npos) { |
| 77 // There are more than 1 language specified, just keep the first one. | 77 // There are more than 1 language specified, just keep the first one. |
| 78 language = language.substr(0, coma_index); | 78 language = language.substr(0, coma_index); |
| 79 } | 79 } |
| 80 TrimWhitespaceASCII(language, TRIM_ALL, &language); | 80 TrimWhitespaceASCII(language, TRIM_ALL, &language); |
| 81 language = StringToLowerASCII(language); | 81 |
| 82 // Underscores instead of dashes are a frequent mistake. | |
| 83 size_t underscore_index = language.find('_'); | |
| 84 if (underscore_index != std::string::npos) { | |
| 85 language[underscore_index] = '-'; | |
|
MAD
2012/11/06 18:00:20
No need for {} here...
bcwhite
2012/11/06 18:37:49
Doh! I am going to do that _every_ time!
Fixed.
| |
| 86 } | |
|
MAD
2012/11/06 18:00:20
Add a DCHECK that there are not other '_' in the s
bcwhite
2012/11/06 18:37:49
We're parsing user-supplied input here. Is crashi
MAD
2012/11/06 18:39:30
OK, fine...
| |
| 87 | |
| 88 // Change everything up to a dash to lower-case and everything after to upper. | |
| 89 size_t dash_index = language.find('-'); | |
| 90 if (dash_index != std::string::npos) { | |
| 91 language = StringToLowerASCII(language.substr(0, dash_index)) + | |
|
MAD
2012/11/06 18:00:20
Add a DCHECK that there are no other '-' in the st
bcwhite
2012/11/06 18:37:49
Same as above. I don't think it's a problem as ma
| |
| 92 StringToUpperASCII(language.substr(dash_index)); | |
| 93 } else { | |
| 94 language = StringToLowerASCII(language); | |
| 95 } | |
| 82 | 96 |
| 83 if (language.empty()) { | 97 if (language.empty()) { |
| 84 base::TimeTicks begin_time = base::TimeTicks::Now(); | 98 base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 85 language = DetermineTextLanguage(contents); | 99 language = DetermineTextLanguage(contents); |
| 86 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection", | 100 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection", |
| 87 base::TimeTicks::Now() - begin_time); | 101 base::TimeTicks::Now() - begin_time); |
| 88 } else { | 102 } else { |
| 89 VLOG(9) << "PageLanguageFromMetaTag: " << language; | 103 VLOG(9) << "PageLanguageFromMetaTag: " << language; |
| 90 } | 104 } |
| 91 | 105 |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 WebView* web_view = render_view()->GetWebView(); | 440 WebView* web_view = render_view()->GetWebView(); |
| 427 if (!web_view) { | 441 if (!web_view) { |
| 428 // When the WebView is going away, the render view should have called | 442 // When the WebView is going away, the render view should have called |
| 429 // CancelPendingTranslation() which should have stopped any pending work, so | 443 // CancelPendingTranslation() which should have stopped any pending work, so |
| 430 // that case should not happen. | 444 // that case should not happen. |
| 431 NOTREACHED(); | 445 NOTREACHED(); |
| 432 return NULL; | 446 return NULL; |
| 433 } | 447 } |
| 434 return web_view->mainFrame(); | 448 return web_view->mainFrame(); |
| 435 } | 449 } |
| OLD | NEW |