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

Unified Diff: components/translate/content/renderer/translate_helper.cc

Issue 2577203002: Remove use of WebNode/WebElement in translate_helper (Closed)
Patch Set: Minor changes Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: components/translate/content/renderer/translate_helper.cc
diff --git a/components/translate/content/renderer/translate_helper.cc b/components/translate/content/renderer/translate_helper.cc
index 23c251943d3078cf75376e9f5ae7fff5cce9847c..c8dd0ef2099a27afc3d22933eb657bd58bba41bb 100644
--- a/components/translate/content/renderer/translate_helper.cc
+++ b/components/translate/content/renderer/translate_helper.cc
@@ -24,18 +24,14 @@
#include "content/public/renderer/render_thread.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/WebKit/public/web/WebDocument.h"
-#include "third_party/WebKit/public/web/WebElement.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
-#include "third_party/WebKit/public/web/WebNode.h"
#include "third_party/WebKit/public/web/WebScriptSource.h"
#include "url/gurl.h"
#include "v8/include/v8.h"
using base::ASCIIToUTF16;
using blink::WebDocument;
-using blink::WebElement;
using blink::WebLocalFrame;
-using blink::WebNode;
using blink::WebScriptSource;
using blink::WebSecurityOrigin;
using blink::WebString;
@@ -66,36 +62,9 @@ const char kContentSecurityPolicy[] = "script-src 'self' 'unsafe-eval'";
// should not be translated.
// TODO(dglazkov): This logic should be moved into Blink.
jbroman 2016/12/16 16:17:42 I think this CL fixes what this comment as looking
adithyas 2016/12/16 21:57:17 Done.
bool HasNoTranslateMeta(WebDocument* document) {
- WebElement head = document->head();
- if (head.isNull() || head.firstChild().isNull())
- return false;
-
- const WebString meta(ASCIIToUTF16("meta"));
- const WebString name(ASCIIToUTF16("name"));
- const WebString google(ASCIIToUTF16("google"));
- const WebString value(ASCIIToUTF16("value"));
- const WebString content(ASCIIToUTF16("content"));
-
- for (WebNode child = head.firstChild(); !child.isNull();
- child = child.nextSibling()) {
- if (!child.isElementNode())
- continue;
- WebElement element = child.to<WebElement>();
- // Check if a tag is <meta>.
- if (!element.hasHTMLTagName(meta))
- continue;
- // Check if the tag contains name="google".
- WebString attribute = element.getAttribute(name);
- if (attribute.isNull() || attribute != google)
- continue;
- // Check if the tag contains value="notranslate", or content="notranslate".
- attribute = element.getAttribute(value);
- if (attribute.isNull())
- attribute = element.getAttribute(content);
- if (attribute.isNull())
- continue;
- if (base::LowerCaseEqualsASCII(base::StringPiece16(attribute),
- "notranslate"))
+ WebVector<WebString> values = document->getMetaValues(ASCIIToUTF16("google"));
jbroman 2016/12/16 16:17:42 super-nit: ASCIIToUTF16 shouldn't be necessary her
adithyas 2016/12/16 21:57:17 Okay, changed it.
+ for (auto value : values) {
jbroman 2016/12/16 16:17:42 nit: this unnecessarily copies WebString (which re
adithyas 2016/12/16 21:57:17 Changed to use a const reference and any_of.
+ if (base::LowerCaseEqualsASCII(base::StringPiece16(value), "notranslate"))
return true;
}
return false;
@@ -142,12 +111,7 @@ void TranslateHelper::PageCaptured(const base::string16& contents) {
WebDocument document = main_frame->document();
std::string content_language = document.contentLanguage().utf8();
- WebElement html_element = document.documentElement();
- std::string html_lang;
- // |html_element| can be null element, e.g. in
- // BrowserTest.WindowOpenClose.
- if (!html_element.isNull())
- html_lang = html_element.getAttribute("lang").utf8();
+ std::string html_lang = document.documentLanguage().utf8();
std::string cld_language;
bool is_cld_reliable;
std::string language = DeterminePageLanguage(
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/dom/Document.h » ('j') | third_party/WebKit/Source/core/dom/Document.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698