| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/document_metadata/CopylessPasteExtractor.h" | 5 #include "modules/document_metadata/CopylessPasteExtractor.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include "core/HTMLNames.h" | 10 #include "core/HTMLNames.h" |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 default: | 261 default: |
| 262 return false; | 262 return false; |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 return !entities.isEmpty(); | 266 return !entities.isEmpty(); |
| 267 } | 267 } |
| 268 | 268 |
| 269 } // namespace | 269 } // namespace |
| 270 | 270 |
| 271 bool CopylessPasteExtractor::extract(const Document& document, | 271 mojom::blink::WebPagePtr CopylessPasteExtractor::extract( |
| 272 mojom::blink::WebPage& page) { | 272 const Document& document) { |
| 273 TRACE_EVENT0("blink", "CopylessPasteExtractor::extract"); | 273 TRACE_EVENT0("blink", "CopylessPasteExtractor::extract"); |
| 274 | 274 |
| 275 if (!document.frame() || !document.frame()->isMainFrame()) | 275 if (!document.frame() || !document.frame()->isMainFrame()) |
| 276 return false; | 276 return nullptr; |
| 277 | 277 |
| 278 DCHECK(document.hasFinishedParsing()); | 278 DCHECK(document.hasFinishedParsing()); |
| 279 | 279 |
| 280 Element* html = document.documentElement(); | 280 Element* html = document.documentElement(); |
| 281 if (!html) | 281 if (!html) |
| 282 return false; | 282 return nullptr; |
| 283 | 283 |
| 284 double startTime = monotonicallyIncreasingTime(); | 284 double startTime = monotonicallyIncreasingTime(); |
| 285 | 285 |
| 286 mojom::blink::WebPagePtr page = mojom::blink::WebPage::New(); |
| 286 // Traverse the DOM tree and extract the metadata. | 287 // Traverse the DOM tree and extract the metadata. |
| 287 if (!extractMetadata(*html, page.entities)) | 288 if (!extractMetadata(*html, page->entities)) |
| 288 return false; | 289 return nullptr; |
| 289 page.url = document.url(); | 290 page->url = document.url(); |
| 290 page.title = document.title(); | 291 page->title = document.title(); |
| 291 | 292 |
| 292 double elapsedTime = monotonicallyIncreasingTime() - startTime; | 293 double elapsedTime = monotonicallyIncreasingTime() - startTime; |
| 293 | 294 |
| 294 DEFINE_STATIC_LOCAL(CustomCountHistogram, extractionHistogram, | 295 DEFINE_STATIC_LOCAL(CustomCountHistogram, extractionHistogram, |
| 295 ("CopylessPaste.ExtractionUs", 1, 1000000, 50)); | 296 ("CopylessPaste.ExtractionUs", 1, 1000000, 50)); |
| 296 extractionHistogram.count(static_cast<int>(1e6 * elapsedTime)); | 297 extractionHistogram.count(static_cast<int>(1e6 * elapsedTime)); |
| 297 return true; | 298 return page; |
| 298 } | 299 } |
| 299 | 300 |
| 300 } // namespace blink | 301 } // namespace blink |
| OLD | NEW |