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

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: Rebase 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(
451 PassRefPtr<const SharedBuffer> data, 451 const String& mimeType,
452 const KURL& url) { 452 ResourceHasCacheControlNoStoreHeader hasCacheControlNoStoreHeader,
453 if (m_delegate.shouldSkipResource(resource)) 453 PassRefPtr<const SharedBuffer> data,
454 const KURL& url) {
455 if (m_delegate.shouldSkipResource(hasCacheControlNoStoreHeader))
454 return; 456 return;
455 457
456 if (!data) { 458 if (!data) {
457 DLOG(ERROR) << "No data for resource " << url.getString(); 459 DLOG(ERROR) << "No data for resource " << url.getString();
458 return; 460 return;
459 } 461 }
460 462
461 String mimeType = resource.response().mimeType();
462 m_resources->append(SerializedResource(url, mimeType, std::move(data))); 463 m_resources->append(SerializedResource(url, mimeType, std::move(data)));
463 m_resourceURLs.add(url); 464 m_resourceURLs.add(url);
464 } 465 }
465 466
466 void FrameSerializer::addImageToResources(ImageResource* image, 467 void FrameSerializer::addImageToResources(ImageResourceContent* image,
467 const KURL& url) { 468 const KURL& url) {
468 if (!image || !image->hasImage() || image->errorOccurred() || 469 if (!image || !image->hasImage() || image->errorOccurred() ||
469 !shouldAddURL(url)) 470 !shouldAddURL(url))
470 return; 471 return;
471 472
472 TRACE_EVENT2("page-serialization", "FrameSerializer::addImageToResources", 473 TRACE_EVENT2("page-serialization", "FrameSerializer::addImageToResources",
473 "type", "image", "url", url.elidedString().utf8().data()); 474 "type", "image", "url", url.elidedString().utf8().data());
474 double imageStartTime = monotonicallyIncreasingTime(); 475 double imageStartTime = monotonicallyIncreasingTime();
475 476
476 RefPtr<const SharedBuffer> data = image->getImage()->data(); 477 RefPtr<const SharedBuffer> data = image->getImage()->data();
477 addToResources(*image, data, url); 478 addToResources(image->response().mimeType(),
479 image->hasCacheControlNoStoreHeader()
480 ? HasCacheControlNoStoreHeader
481 : NoCacheControlNoStoreHeader,
482 data, url);
478 483
479 // If we're already reporting time for CSS serialization don't report it for 484 // If we're already reporting time for CSS serialization don't report it for
480 // this image to avoid reporting the same time twice. 485 // this image to avoid reporting the same time twice.
481 if (!m_isSerializingCss) { 486 if (!m_isSerializingCss) {
482 DEFINE_STATIC_LOCAL(CustomCountHistogram, imageHistogram, 487 DEFINE_STATIC_LOCAL(CustomCountHistogram, imageHistogram,
483 ("PageSerialization.SerializationTime.ImageElement", 0, 488 ("PageSerialization.SerializationTime.ImageElement", 0,
484 maxSerializationTimeUmaMicroseconds, 50)); 489 maxSerializationTimeUmaMicroseconds, 50));
485 imageHistogram.count( 490 imageHistogram.count(
486 static_cast<int64_t>((monotonicallyIncreasingTime() - imageStartTime) * 491 static_cast<int64_t>((monotonicallyIncreasingTime() - imageStartTime) *
487 secondsToMicroseconds)); 492 secondsToMicroseconds));
488 } 493 }
489 } 494 }
490 495
491 void FrameSerializer::addFontToResources(FontResource* font) { 496 void FrameSerializer::addFontToResources(FontResource* font) {
492 if (!font || !font->isLoaded() || !font->resourceBuffer() || 497 if (!font || !font->isLoaded() || !font->resourceBuffer() ||
493 !shouldAddURL(font->url())) 498 !shouldAddURL(font->url()))
494 return; 499 return;
495 500
496 RefPtr<const SharedBuffer> data(font->resourceBuffer()); 501 RefPtr<const SharedBuffer> data(font->resourceBuffer());
497 502
498 addToResources(*font, data, font->url()); 503 addToResources(font->response().mimeType(),
504 font->hasCacheControlNoStoreHeader()
505 ? HasCacheControlNoStoreHeader
506 : NoCacheControlNoStoreHeader,
507 data, font->url());
499 } 508 }
500 509
501 void FrameSerializer::retrieveResourcesForProperties( 510 void FrameSerializer::retrieveResourcesForProperties(
502 const StylePropertySet* styleDeclaration, 511 const StylePropertySet* styleDeclaration,
503 Document& document) { 512 Document& document) {
504 if (!styleDeclaration) 513 if (!styleDeclaration)
505 return; 514 return;
506 515
507 // The background-image and list-style-image (for ul or ol) are the CSS 516 // 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 517 // 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 == '-'; 567 emitsMinus = ch == '-';
559 builder.append(ch); 568 builder.append(ch);
560 } 569 }
561 CString escapedUrl = builder.toString().ascii(); 570 CString escapedUrl = builder.toString().ascii();
562 return String::format("saved from url=(%04d)%s", 571 return String::format("saved from url=(%04d)%s",
563 static_cast<int>(escapedUrl.length()), 572 static_cast<int>(escapedUrl.length()),
564 escapedUrl.data()); 573 escapedUrl.data());
565 } 574 }
566 575
567 } // namespace blink 576 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698