OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 String text = | 292 String text = |
293 SerializeNodes<EditingStrategy>(accumulator, document, kIncludeNode); | 293 SerializeNodes<EditingStrategy>(accumulator, document, kIncludeNode); |
294 | 294 |
295 CString frame_html = | 295 CString frame_html = |
296 document.Encoding().Encode(text, WTF::kEntitiesForUnencodables); | 296 document.Encoding().Encode(text, WTF::kEntitiesForUnencodables); |
297 resources_->push_back(SerializedResource( | 297 resources_->push_back(SerializedResource( |
298 url, document.SuggestedMIMEType(), | 298 url, document.SuggestedMIMEType(), |
299 SharedBuffer::Create(frame_html.data(), frame_html.length()))); | 299 SharedBuffer::Create(frame_html.data(), frame_html.length()))); |
300 } | 300 } |
301 | 301 |
302 int total_image_count = 0; | |
303 int missing_image_count = 0; | |
304 int total_css_count = 0; | |
305 int missing_css_count = 0; | |
306 bool should_collect_problem_metric = | |
307 delegate_.ShouldCollectProblemMetric() && frame.IsMainFrame(); | |
302 for (Node* node : serialized_nodes) { | 308 for (Node* node : serialized_nodes) { |
303 DCHECK(node); | 309 DCHECK(node); |
304 if (!node->IsElementNode()) | 310 if (!node->IsElementNode()) |
305 continue; | 311 continue; |
306 | 312 |
307 Element& element = ToElement(*node); | 313 Element& element = ToElement(*node); |
308 // We have to process in-line style as it might contain some resources | 314 // We have to process in-line style as it might contain some resources |
309 // (typically background images). | 315 // (typically background images). |
310 if (element.IsStyledElement()) { | 316 if (element.IsStyledElement()) { |
311 RetrieveResourcesForProperties(element.InlineStyle(), document); | 317 RetrieveResourcesForProperties(element.InlineStyle(), document); |
312 RetrieveResourcesForProperties(element.PresentationAttributeStyle(), | 318 RetrieveResourcesForProperties(element.PresentationAttributeStyle(), |
313 document); | 319 document); |
314 } | 320 } |
315 | 321 |
316 if (isHTMLImageElement(element)) { | 322 if (isHTMLImageElement(element)) { |
317 HTMLImageElement& image_element = toHTMLImageElement(element); | 323 HTMLImageElement& image_element = toHTMLImageElement(element); |
318 KURL url = | 324 KURL url = |
319 document.CompleteURL(image_element.getAttribute(HTMLNames::srcAttr)); | 325 document.CompleteURL(image_element.getAttribute(HTMLNames::srcAttr)); |
326 if (should_collect_problem_metric) { | |
327 total_image_count++; | |
328 if (!image_element.complete()) | |
329 missing_image_count++; | |
Pete Williamson
2017/06/06 22:27:25
I think it is better to count requested vs complet
| |
330 } | |
320 ImageResourceContent* cached_image = image_element.CachedImage(); | 331 ImageResourceContent* cached_image = image_element.CachedImage(); |
321 AddImageToResources(cached_image, url); | 332 AddImageToResources(cached_image, url); |
322 } else if (isHTMLInputElement(element)) { | 333 } else if (isHTMLInputElement(element)) { |
323 HTMLInputElement& input_element = toHTMLInputElement(element); | 334 HTMLInputElement& input_element = toHTMLInputElement(element); |
324 if (input_element.type() == InputTypeNames::image && | 335 if (input_element.type() == InputTypeNames::image && |
325 input_element.ImageLoader()) { | 336 input_element.ImageLoader()) { |
326 KURL url = input_element.Src(); | 337 KURL url = input_element.Src(); |
327 ImageResourceContent* cached_image = | 338 ImageResourceContent* cached_image = |
328 input_element.ImageLoader()->GetImage(); | 339 input_element.ImageLoader()->GetImage(); |
329 AddImageToResources(cached_image, url); | 340 AddImageToResources(cached_image, url); |
330 } | 341 } |
331 } else if (isHTMLLinkElement(element)) { | 342 } else if (isHTMLLinkElement(element)) { |
332 HTMLLinkElement& link_element = toHTMLLinkElement(element); | 343 HTMLLinkElement& link_element = toHTMLLinkElement(element); |
333 if (CSSStyleSheet* sheet = link_element.sheet()) { | 344 if (CSSStyleSheet* sheet = link_element.sheet()) { |
334 KURL url = document.CompleteURL( | 345 KURL url = document.CompleteURL( |
335 link_element.getAttribute(HTMLNames::hrefAttr)); | 346 link_element.getAttribute(HTMLNames::hrefAttr)); |
336 SerializeCSSStyleSheet(*sheet, url); | 347 SerializeCSSStyleSheet(*sheet, url); |
337 } | 348 } |
338 } else if (isHTMLStyleElement(element)) { | 349 } else if (isHTMLStyleElement(element)) { |
339 HTMLStyleElement& style_element = toHTMLStyleElement(element); | 350 HTMLStyleElement& style_element = toHTMLStyleElement(element); |
340 if (CSSStyleSheet* sheet = style_element.sheet()) | 351 CSSStyleSheet* sheet = style_element.sheet(); |
352 if (sheet) | |
341 SerializeCSSStyleSheet(*sheet, KURL()); | 353 SerializeCSSStyleSheet(*sheet, KURL()); |
354 if (should_collect_problem_metric) { | |
355 total_css_count++; | |
356 if (sheet && sheet->IsLoading()) | |
357 missing_css_count++; | |
358 } | |
342 } | 359 } |
343 } | 360 } |
361 if (should_collect_problem_metric) { | |
362 // Report detectors through UMA. | |
363 DCHECK_LE(missing_image_count, total_image_count); | |
364 UMA_HISTOGRAM_PERCENTAGE( | |
365 "PageSerialization.ProblemDetection.MissingImagePercentage", | |
Pete Williamson
2017/06/06 22:27:25
I think that stating this in the positive will be
| |
366 static_cast<int64_t>(missing_image_count * 100 / total_image_count)); | |
367 UMA_HISTOGRAM_COUNTS_100( | |
Pete Williamson
2017/06/06 22:27:25
Is 100 buckets too granular? Maybe about 20 bucke
| |
368 "PageSerialization.ProblemDetection.TotalImageCount", | |
369 static_cast<int64_t>(total_image_count)); | |
370 | |
371 DCHECK_LE(missing_css_count, total_css_count); | |
372 UMA_HISTOGRAM_PERCENTAGE( | |
373 "PageSerialization.ProblemDetection.MissingCSSPercentage", | |
374 static_cast<int64_t>(missing_css_count * 100 / total_css_count)); | |
375 UMA_HISTOGRAM_COUNTS_100("PageSerialization.ProblemDetection.TotalCSSCount", | |
376 static_cast<int64_t>(total_css_count)); | |
377 } | |
344 } | 378 } |
345 | 379 |
346 void FrameSerializer::SerializeCSSStyleSheet(CSSStyleSheet& style_sheet, | 380 void FrameSerializer::SerializeCSSStyleSheet(CSSStyleSheet& style_sheet, |
347 const KURL& url) { | 381 const KURL& url) { |
348 // If the URL is invalid or if it is a data URL this means that this CSS is | 382 // If the URL is invalid or if it is a data URL this means that this CSS is |
349 // defined inline, respectively in a <style> tag or in the data URL itself. | 383 // defined inline, respectively in a <style> tag or in the data URL itself. |
350 bool is_inline_css = !url.IsValid() || url.ProtocolIsData(); | 384 bool is_inline_css = !url.IsValid() || url.ProtocolIsData(); |
351 // If this CSS is not inline then it is identifiable by its URL. So just skip | 385 // If this CSS is not inline then it is identifiable by its URL. So just skip |
352 // it if it has already been analyzed before. | 386 // it if it has already been analyzed before. |
353 if (!is_inline_css && (resource_urls_.Contains(url) || | 387 if (!is_inline_css && (resource_urls_.Contains(url) || |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
579 emits_minus = ch == '-'; | 613 emits_minus = ch == '-'; |
580 builder.Append(ch); | 614 builder.Append(ch); |
581 } | 615 } |
582 CString escaped_url = builder.ToString().Ascii(); | 616 CString escaped_url = builder.ToString().Ascii(); |
583 return String::Format("saved from url=(%04d)%s", | 617 return String::Format("saved from url=(%04d)%s", |
584 static_cast<int>(escaped_url.length()), | 618 static_cast<int>(escaped_url.length()), |
585 escaped_url.data()); | 619 escaped_url.data()); |
586 } | 620 } |
587 | 621 |
588 } // namespace blink | 622 } // namespace blink |
OLD | NEW |