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

Unified Diff: third_party/WebKit/Source/web/WebLanguageDetectionDetails.cpp

Issue 2577203002: Remove use of WebNode/WebElement in translate_helper (Closed)
Patch Set: Move translate specific DOM operations into separate file 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: third_party/WebKit/Source/web/WebLanguageDetectionDetails.cpp
diff --git a/third_party/WebKit/Source/web/WebLanguageDetectionDetails.cpp b/third_party/WebKit/Source/web/WebLanguageDetectionDetails.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..657521a7cd5831b13089dbf4ca65d98af9120677
--- /dev/null
+++ b/third_party/WebKit/Source/web/WebLanguageDetectionDetails.cpp
@@ -0,0 +1,66 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "public/web/WebLanguageDetectionDetails.h"
+
+#include "core/dom/Document.h"
+#include "core/dom/Element.h"
+#include "core/dom/ElementTraversal.h"
+#include "core/html/HTMLHeadElement.h"
+#include "core/html/HTMLMetaElement.h"
+#include "public/web/WebDocument.h"
+
+namespace blink {
+
+namespace {
+
+const AtomicString& documentLanguage(const Document& document) {
+ Element* htmlElement = document.documentElement();
+ if (!htmlElement)
+ return nullAtom;
+ return htmlElement->getAttribute(HTMLNames::langAttr);
+}
+
+bool hasNoTranslate(const Document& document) {
+ Vector<AtomicString> results;
jbroman 2016/12/20 16:43:51 unused variable
adithyas 2017/01/09 15:40:02 Removed.
+ AtomicString google("google");
jbroman 2016/12/20 16:43:51 nit: Since you're making the same AtomicString eac
adithyas 2017/01/09 15:40:02 Done.
+
+ HTMLHeadElement* headElement = document.head();
+ if (!headElement)
+ return false;
+
+ for (const HTMLMetaElement& metaElement :
+ Traversal<HTMLMetaElement>::childrenOf(*headElement)) {
+ if (metaElement.name() != google)
+ continue;
+
+ // Check if the tag contains content="notranslate" or value="notranslate"
+ AtomicString content = metaElement.content();
+ if (content.isNull())
+ content = metaElement.getAttribute(HTMLNames::valueAttr);
+ if (equalIgnoringASCIICase(content, "notranslate"))
+ return true;
+ }
+
+ return false;
+}
+
+} // namespace
+
+WebLanguageDetectionDetails
+WebLanguageDetectionDetails::collectLanguageDetectionDetails(
+ const WebDocument& webDocument) {
+ WebLanguageDetectionDetails details;
+ const Document* document = webDocument.constUnwrap<Document>();
+
+ details.contentLanguage = document->contentLanguage();
+ details.htmlLanguage = documentLanguage(*document);
+ details.url = document->url();
+
jbroman 2016/12/20 16:43:51 super-nit: the spacing of these lines is a little
adithyas 2017/01/09 15:40:02 Fixed :)
+ details.hasNoTranslateMeta = hasNoTranslate(*document);
+
+ return details;
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698