| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "public/web/WebLanguageDetectionDetails.h" |
| 6 |
| 7 #include "core/dom/Document.h" |
| 8 #include "core/dom/Element.h" |
| 9 #include "core/dom/ElementTraversal.h" |
| 10 #include "core/html/HTMLHeadElement.h" |
| 11 #include "core/html/HTMLMetaElement.h" |
| 12 #include "public/web/WebDocument.h" |
| 13 |
| 14 namespace blink { |
| 15 |
| 16 namespace { |
| 17 |
| 18 const AtomicString& documentLanguage(const Document& document) { |
| 19 Element* htmlElement = document.documentElement(); |
| 20 if (!htmlElement) |
| 21 return nullAtom; |
| 22 return htmlElement->getAttribute(HTMLNames::langAttr); |
| 23 } |
| 24 |
| 25 bool hasNoTranslate(const Document& document) { |
| 26 DEFINE_STATIC_LOCAL(const AtomicString, google, ("google")); |
| 27 |
| 28 HTMLHeadElement* headElement = document.head(); |
| 29 if (!headElement) |
| 30 return false; |
| 31 |
| 32 for (const HTMLMetaElement& metaElement : |
| 33 Traversal<HTMLMetaElement>::childrenOf(*headElement)) { |
| 34 if (metaElement.name() != google) |
| 35 continue; |
| 36 |
| 37 // Check if the tag contains content="notranslate" or value="notranslate" |
| 38 AtomicString content = metaElement.content(); |
| 39 if (content.isNull()) |
| 40 content = metaElement.getAttribute(HTMLNames::valueAttr); |
| 41 if (equalIgnoringASCIICase(content, "notranslate")) |
| 42 return true; |
| 43 } |
| 44 |
| 45 return false; |
| 46 } |
| 47 |
| 48 } // namespace |
| 49 |
| 50 WebLanguageDetectionDetails |
| 51 WebLanguageDetectionDetails::collectLanguageDetectionDetails( |
| 52 const WebDocument& webDocument) { |
| 53 const Document* document = webDocument.constUnwrap<Document>(); |
| 54 |
| 55 WebLanguageDetectionDetails details; |
| 56 details.contentLanguage = document->contentLanguage(); |
| 57 details.htmlLanguage = documentLanguage(*document); |
| 58 details.url = document->url(); |
| 59 details.hasNoTranslateMeta = hasNoTranslate(*document); |
| 60 |
| 61 return details; |
| 62 } |
| 63 |
| 64 } // namespace blink |
| OLD | NEW |