Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: third_party/WebKit/Source/core/frame/FrameSerializer.cpp

Issue 2469873002: [ImageResource 4] Split ImageResource into Resource and Image parts (Closed)
Patch Set: fix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 29 matching lines...) Expand all
40 #include "core/css/CSSStyleDeclaration.h" 40 #include "core/css/CSSStyleDeclaration.h"
41 #include "core/css/CSSStyleRule.h" 41 #include "core/css/CSSStyleRule.h"
42 #include "core/css/CSSValueList.h" 42 #include "core/css/CSSValueList.h"
43 #include "core/css/StylePropertySet.h" 43 #include "core/css/StylePropertySet.h"
44 #include "core/css/StyleRule.h" 44 #include "core/css/StyleRule.h"
45 #include "core/css/StyleSheetContents.h" 45 #include "core/css/StyleSheetContents.h"
46 #include "core/dom/Document.h" 46 #include "core/dom/Document.h"
47 #include "core/dom/Element.h" 47 #include "core/dom/Element.h"
48 #include "core/dom/Text.h" 48 #include "core/dom/Text.h"
49 #include "core/editing/serializers/MarkupAccumulator.h" 49 #include "core/editing/serializers/MarkupAccumulator.h"
50 #include "core/fetch/ImageResource.h" 50 #include "core/fetch/ImageResourceContent.h"
51 #include "core/frame/LocalFrame.h" 51 #include "core/frame/LocalFrame.h"
52 #include "core/html/HTMLFrameElementBase.h" 52 #include "core/html/HTMLFrameElementBase.h"
53 #include "core/html/HTMLImageElement.h" 53 #include "core/html/HTMLImageElement.h"
54 #include "core/html/HTMLInputElement.h" 54 #include "core/html/HTMLInputElement.h"
55 #include "core/html/HTMLLinkElement.h" 55 #include "core/html/HTMLLinkElement.h"
56 #include "core/html/HTMLMetaElement.h" 56 #include "core/html/HTMLMetaElement.h"
57 #include "core/html/HTMLStyleElement.h" 57 #include "core/html/HTMLStyleElement.h"
58 #include "core/html/ImageDocument.h" 58 #include "core/html/ImageDocument.h"
59 #include "core/loader/resource/FontResource.h" 59 #include "core/loader/resource/FontResource.h"
60 #include "core/style/StyleFetchedImage.h" 60 #include "core/style/StyleFetchedImage.h"
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 if (element.isStyledElement()) { 299 if (element.isStyledElement()) {
300 retrieveResourcesForProperties(element.inlineStyle(), document); 300 retrieveResourcesForProperties(element.inlineStyle(), document);
301 retrieveResourcesForProperties(element.presentationAttributeStyle(), 301 retrieveResourcesForProperties(element.presentationAttributeStyle(),
302 document); 302 document);
303 } 303 }
304 304
305 if (isHTMLImageElement(element)) { 305 if (isHTMLImageElement(element)) {
306 HTMLImageElement& imageElement = toHTMLImageElement(element); 306 HTMLImageElement& imageElement = toHTMLImageElement(element);
307 KURL url = 307 KURL url =
308 document.completeURL(imageElement.getAttribute(HTMLNames::srcAttr)); 308 document.completeURL(imageElement.getAttribute(HTMLNames::srcAttr));
309 ImageResource* cachedImage = imageElement.cachedImage(); 309 ImageResourceContent* cachedImage = imageElement.cachedImage();
310 addImageToResources(cachedImage, url); 310 addImageToResources(cachedImage, url);
311 } else if (isHTMLInputElement(element)) { 311 } else if (isHTMLInputElement(element)) {
312 HTMLInputElement& inputElement = toHTMLInputElement(element); 312 HTMLInputElement& inputElement = toHTMLInputElement(element);
313 if (inputElement.type() == InputTypeNames::image && 313 if (inputElement.type() == InputTypeNames::image &&
314 inputElement.imageLoader()) { 314 inputElement.imageLoader()) {
315 KURL url = inputElement.src(); 315 KURL url = inputElement.src();
316 ImageResource* cachedImage = inputElement.imageLoader()->image(); 316 ImageResourceContent* cachedImage = inputElement.imageLoader()->image();
317 addImageToResources(cachedImage, url); 317 addImageToResources(cachedImage, url);
318 } 318 }
319 } else if (isHTMLLinkElement(element)) { 319 } else if (isHTMLLinkElement(element)) {
320 HTMLLinkElement& linkElement = toHTMLLinkElement(element); 320 HTMLLinkElement& linkElement = toHTMLLinkElement(element);
321 if (CSSStyleSheet* sheet = linkElement.sheet()) { 321 if (CSSStyleSheet* sheet = linkElement.sheet()) {
322 KURL url = 322 KURL url =
323 document.completeURL(linkElement.getAttribute(HTMLNames::hrefAttr)); 323 document.completeURL(linkElement.getAttribute(HTMLNames::hrefAttr));
324 serializeCSSStyleSheet(*sheet, url); 324 serializeCSSStyleSheet(*sheet, url);
325 } 325 }
326 } else if (isHTMLStyleElement(element)) { 326 } else if (isHTMLStyleElement(element)) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 case CSSRule::kViewportRule: 440 case CSSRule::kViewportRule:
441 break; 441 break;
442 } 442 }
443 } 443 }
444 444
445 bool FrameSerializer::shouldAddURL(const KURL& url) { 445 bool FrameSerializer::shouldAddURL(const KURL& url) {
446 return url.isValid() && !m_resourceURLs.contains(url) && 446 return url.isValid() && !m_resourceURLs.contains(url) &&
447 !url.protocolIsData() && !m_delegate.shouldSkipResourceWithURL(url); 447 !url.protocolIsData() && !m_delegate.shouldSkipResourceWithURL(url);
448 } 448 }
449 449
450 void FrameSerializer::addToResources(const Resource& resource, 450 void FrameSerializer::addToResources(const String& mimeType,
451 bool hasCacheControlNoStoreHeader,
451 PassRefPtr<const SharedBuffer> data, 452 PassRefPtr<const SharedBuffer> data,
452 const KURL& url) { 453 const KURL& url) {
453 if (m_delegate.shouldSkipResource(resource)) 454 if (m_delegate.shouldSkipResource(hasCacheControlNoStoreHeader))
454 return; 455 return;
455 456
456 if (!data) { 457 if (!data) {
457 DLOG(ERROR) << "No data for resource " << url.getString(); 458 DLOG(ERROR) << "No data for resource " << url.getString();
458 return; 459 return;
459 } 460 }
460 461
461 String mimeType = resource.response().mimeType();
462 m_resources->append(SerializedResource(url, mimeType, std::move(data))); 462 m_resources->append(SerializedResource(url, mimeType, std::move(data)));
463 m_resourceURLs.add(url); 463 m_resourceURLs.add(url);
464 } 464 }
465 465
466 void FrameSerializer::addImageToResources(ImageResource* image, 466 void FrameSerializer::addImageToResources(ImageResourceContent* image,
467 const KURL& url) { 467 const KURL& url) {
468 if (!image || !image->hasImage() || image->errorOccurred() || 468 if (!image || !image->hasImage() || image->errorOccurred() ||
469 !shouldAddURL(url)) 469 !shouldAddURL(url))
470 return; 470 return;
471 471
472 TRACE_EVENT2("page-serialization", "FrameSerializer::addImageToResources", 472 TRACE_EVENT2("page-serialization", "FrameSerializer::addImageToResources",
473 "type", "image", "url", url.elidedString().utf8().data()); 473 "type", "image", "url", url.elidedString().utf8().data());
474 double imageStartTime = monotonicallyIncreasingTime(); 474 double imageStartTime = monotonicallyIncreasingTime();
475 475
476 RefPtr<const SharedBuffer> data = image->getImage()->data(); 476 RefPtr<const SharedBuffer> data = image->getImage()->data();
477 addToResources(*image, data, url); 477 addToResources(image->response().mimeType(),
478 image->hasCacheControlNoStoreHeader(), data, url);
478 479
479 // If we're already reporting time for CSS serialization don't report it for 480 // If we're already reporting time for CSS serialization don't report it for
480 // this image to avoid reporting the same time twice. 481 // this image to avoid reporting the same time twice.
481 if (!m_isSerializingCss) { 482 if (!m_isSerializingCss) {
482 DEFINE_STATIC_LOCAL(CustomCountHistogram, imageHistogram, 483 DEFINE_STATIC_LOCAL(CustomCountHistogram, imageHistogram,
483 ("PageSerialization.SerializationTime.ImageElement", 0, 484 ("PageSerialization.SerializationTime.ImageElement", 0,
484 maxSerializationTimeUmaMicroseconds, 50)); 485 maxSerializationTimeUmaMicroseconds, 50));
485 imageHistogram.count( 486 imageHistogram.count(
486 static_cast<int64_t>((monotonicallyIncreasingTime() - imageStartTime) * 487 static_cast<int64_t>((monotonicallyIncreasingTime() - imageStartTime) *
487 secondsToMicroseconds)); 488 secondsToMicroseconds));
488 } 489 }
489 } 490 }
490 491
491 void FrameSerializer::addFontToResources(FontResource* font) { 492 void FrameSerializer::addFontToResources(FontResource* font) {
492 if (!font || !font->isLoaded() || !font->resourceBuffer() || 493 if (!font || !font->isLoaded() || !font->resourceBuffer() ||
493 !shouldAddURL(font->url())) 494 !shouldAddURL(font->url()))
494 return; 495 return;
495 496
496 RefPtr<const SharedBuffer> data(font->resourceBuffer()); 497 RefPtr<const SharedBuffer> data(font->resourceBuffer());
497 498
498 addToResources(*font, data, font->url()); 499 addToResources(font->response().mimeType(),
500 font->hasCacheControlNoStoreHeader(), data, font->url());
499 } 501 }
500 502
501 void FrameSerializer::retrieveResourcesForProperties( 503 void FrameSerializer::retrieveResourcesForProperties(
502 const StylePropertySet* styleDeclaration, 504 const StylePropertySet* styleDeclaration,
503 Document& document) { 505 Document& document) {
504 if (!styleDeclaration) 506 if (!styleDeclaration)
505 return; 507 return;
506 508
507 // The background-image and list-style-image (for ul or ol) are the CSS 509 // The background-image and list-style-image (for ul or ol) are the CSS
508 // properties that make use of images. We iterate to make sure we include any 510 // properties that make use of images. We iterate to make sure we include any
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 emitsMinus = ch == '-'; 560 emitsMinus = ch == '-';
559 builder.append(ch); 561 builder.append(ch);
560 } 562 }
561 CString escapedUrl = builder.toString().ascii(); 563 CString escapedUrl = builder.toString().ascii();
562 return String::format("saved from url=(%04d)%s", 564 return String::format("saved from url=(%04d)%s",
563 static_cast<int>(escapedUrl.length()), 565 static_cast<int>(escapedUrl.length()),
564 escapedUrl.data()); 566 escapedUrl.data());
565 } 567 }
566 568
567 } // namespace blink 569 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698