Chromium Code Reviews| 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 |