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

Side by Side Diff: chrome/renderer/translate_helper.cc

Issue 10916316: Add support for non-all-lower-case meta tags. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Alternate method of handling case-insensitivity that doesn't require changes to WebKit Created 8 years, 2 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) 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 translation_pending_ = false; 81 translation_pending_ = false;
82 page_id_ = -1; 82 page_id_ = -1;
83 source_lang_.clear(); 83 source_lang_.clear();
84 target_lang_.clear(); 84 target_lang_.clear();
85 } 85 }
86 86
87 // static 87 // static
88 bool TranslateHelper::IsPageTranslatable(WebDocument* document) { 88 bool TranslateHelper::IsPageTranslatable(WebDocument* document) {
89 std::vector<WebElement> meta_elements; 89 std::vector<WebElement> meta_elements;
90 webkit_glue::GetMetaElementsWithAttribute(document, 90 webkit_glue::GetMetaElementsWithAttribute(document,
91 ASCIIToUTF16("name"), 91 "name",
92 ASCIIToUTF16("google"), 92 "google",
93 &meta_elements); 93 &meta_elements);
94 std::vector<WebElement>::const_iterator iter; 94 std::vector<WebElement>::const_iterator iter;
95 for (iter = meta_elements.begin(); iter != meta_elements.end(); ++iter) { 95 for (iter = meta_elements.begin(); iter != meta_elements.end(); ++iter) {
96 WebString attribute = iter->getAttribute("value"); 96 WebString attribute = iter->getAttribute("value");
97 if (attribute.isNull()) // We support both 'value' and 'content'. 97 if (attribute.isNull()) // We support both 'value' and 'content'.
98 attribute = iter->getAttribute("content"); 98 attribute = iter->getAttribute("content");
99 if (attribute.isNull()) 99 if (attribute.isNull())
100 continue; 100 continue;
101 if (LowerCaseEqualsASCII(attribute, "notranslate")) 101 if (LowerCaseEqualsASCII(attribute, "notranslate"))
102 return false; 102 return false;
103 } 103 }
104 return true; 104 return true;
105 } 105 }
106 106
107 // static 107 // static
108 std::string TranslateHelper::GetPageLanguageFromMetaTag(WebDocument* document) { 108 std::string TranslateHelper::GetPageLanguageFromMetaTag(WebDocument* document) {
109 // The META language tag looks like: 109 // The META language tag looks like:
110 // <meta http-equiv="content-language" content="en"> 110 // <meta http-equiv="content-language" content="en">
111 // It can contain more than one language: 111 // It can contain more than one language:
112 // <meta http-equiv="content-language" content="en, fr"> 112 // <meta http-equiv="content-language" content="en, fr">
113 std::vector<WebElement> meta_elements; 113 std::vector<WebElement> meta_elements;
114 webkit_glue::GetMetaElementsWithAttribute(document, 114 webkit_glue::GetMetaElementsWithAttribute(document,
115 ASCIIToUTF16("http-equiv"), 115 "http-equiv",
116 ASCIIToUTF16("content-language"), 116 "content-language",
117 &meta_elements); 117 &meta_elements);
118 if (meta_elements.empty()) 118 if (meta_elements.empty())
119 return std::string(); 119 return std::string();
120 120
121 // We don't expect more than one such tag. If there are several, just use the 121 // We don't expect more than one such tag. If there are several, just use the
122 // first one. 122 // first one.
123 WebString attribute = meta_elements[0].getAttribute("content"); 123 WebString attribute = meta_elements[0].getAttribute("content");
124 if (attribute.isEmpty()) 124 if (attribute.isEmpty())
125 return std::string(); 125 return std::string();
126 126
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 WebView* web_view = render_view()->GetWebView(); 443 WebView* web_view = render_view()->GetWebView();
444 if (!web_view) { 444 if (!web_view) {
445 // When the WebView is going away, the render view should have called 445 // When the WebView is going away, the render view should have called
446 // CancelPendingTranslation() which should have stopped any pending work, so 446 // CancelPendingTranslation() which should have stopped any pending work, so
447 // that case should not happen. 447 // that case should not happen.
448 NOTREACHED(); 448 NOTREACHED();
449 return NULL; 449 return NULL;
450 } 450 }
451 return web_view->mainFrame(); 451 return web_view->mainFrame();
452 } 452 }
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/translate_helper_browsertest.cc » ('j') | webkit/glue/dom_operations.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698