Chromium Code Reviews| 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 Vector<AtomicString> results; | |
|
jbroman
2016/12/20 16:43:51
unused variable
adithyas
2017/01/09 15:40:02
Removed.
| |
| 27 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.
| |
| 28 | |
| 29 HTMLHeadElement* headElement = document.head(); | |
| 30 if (!headElement) | |
| 31 return false; | |
| 32 | |
| 33 for (const HTMLMetaElement& metaElement : | |
| 34 Traversal<HTMLMetaElement>::childrenOf(*headElement)) { | |
| 35 if (metaElement.name() != google) | |
| 36 continue; | |
| 37 | |
| 38 // Check if the tag contains content="notranslate" or value="notranslate" | |
| 39 AtomicString content = metaElement.content(); | |
| 40 if (content.isNull()) | |
| 41 content = metaElement.getAttribute(HTMLNames::valueAttr); | |
| 42 if (equalIgnoringASCIICase(content, "notranslate")) | |
| 43 return true; | |
| 44 } | |
| 45 | |
| 46 return false; | |
| 47 } | |
| 48 | |
| 49 } // namespace | |
| 50 | |
| 51 WebLanguageDetectionDetails | |
| 52 WebLanguageDetectionDetails::collectLanguageDetectionDetails( | |
| 53 const WebDocument& webDocument) { | |
| 54 WebLanguageDetectionDetails details; | |
| 55 const Document* document = webDocument.constUnwrap<Document>(); | |
| 56 | |
| 57 details.contentLanguage = document->contentLanguage(); | |
| 58 details.htmlLanguage = documentLanguage(*document); | |
| 59 details.url = document->url(); | |
| 60 | |
|
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 :)
| |
| 61 details.hasNoTranslateMeta = hasNoTranslate(*document); | |
| 62 | |
| 63 return details; | |
| 64 } | |
| 65 | |
| 66 } // namespace blink | |
| OLD | NEW |