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

Side by Side Diff: third_party/WebKit/Source/core/html/ImageDocument.cpp

Issue 1738553002: [ABANDONED] Move multipart/x-mixed-replace related code to ImageResource (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@multipart-cleanup-2
Patch Set: Created 4 years, 9 months 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) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 { 194 {
195 setCompatibilityMode(QuirksMode); 195 setCompatibilityMode(QuirksMode);
196 lockCompatibilityMode(); 196 lockCompatibilityMode();
197 } 197 }
198 198
199 PassRefPtrWillBeRawPtr<DocumentParser> ImageDocument::createParser() 199 PassRefPtrWillBeRawPtr<DocumentParser> ImageDocument::createParser()
200 { 200 {
201 return ImageDocumentParser::create(this); 201 return ImageDocumentParser::create(this);
202 } 202 }
203 203
204 void ImageDocument::createDocumentStructure(bool loadingMultipartContent) 204 void ImageDocument::createDocumentStructure()
205 { 205 {
206 RefPtrWillBeRawPtr<HTMLHtmlElement> rootElement = HTMLHtmlElement::create(*t his); 206 RefPtrWillBeRawPtr<HTMLHtmlElement> rootElement = HTMLHtmlElement::create(*t his);
207 appendChild(rootElement); 207 appendChild(rootElement);
208 rootElement->insertedByParser(); 208 rootElement->insertedByParser();
209 209
210 if (frame()) 210 if (frame())
211 frame()->loader().dispatchDocumentElementAvailable(); 211 frame()->loader().dispatchDocumentElementAvailable();
212 // Normally, ImageDocument creates an HTMLImageElement that doesn't actually load
213 // anything, and the ImageDocument routes the main resource data into the HT MLImageElement's
214 // ImageResource. However, the main resource pipeline doesn't know how to ha ndle multipart content.
215 // For multipart content, we instead stop streaming data through the main re source and re-request
216 // the data directly.
217 if (loadingMultipartContent)
218 loader()->stopLoading();
219 212
220 RefPtrWillBeRawPtr<HTMLHeadElement> head = HTMLHeadElement::create(*this); 213 RefPtrWillBeRawPtr<HTMLHeadElement> head = HTMLHeadElement::create(*this);
221 RefPtrWillBeRawPtr<HTMLMetaElement> meta = HTMLMetaElement::create(*this); 214 RefPtrWillBeRawPtr<HTMLMetaElement> meta = HTMLMetaElement::create(*this);
222 meta->setAttribute(nameAttr, "viewport"); 215 meta->setAttribute(nameAttr, "viewport");
223 meta->setAttribute(contentAttr, "width=device-width, minimum-scale=0.1"); 216 meta->setAttribute(contentAttr, "width=device-width, minimum-scale=0.1");
224 head->appendChild(meta); 217 head->appendChild(meta);
225 218
226 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*this); 219 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*this);
227 body->setAttribute(styleAttr, "margin: 0px;"); 220 body->setAttribute(styleAttr, "margin: 0px;");
228 221
229 if (frame()) 222 if (frame())
230 frame()->loader().client()->dispatchWillInsertBody(); 223 frame()->loader().client()->dispatchWillInsertBody();
231 224
232 m_imageElement = HTMLImageElement::create(*this); 225 m_imageElement = HTMLImageElement::create(*this);
233 m_imageElement->setAttribute(styleAttr, "-webkit-user-select: none"); 226 m_imageElement->setAttribute(styleAttr, "-webkit-user-select: none");
234 // If the image is multipart, we neglect to mention to the HTMLImageElement that it's in an 227 m_imageElement->setLoadingImageDocument();
235 // ImageDocument, so that it requests the image normally.
236 if (!loadingMultipartContent)
237 m_imageElement->setLoadingImageDocument();
238 m_imageElement->setSrc(url().string()); 228 m_imageElement->setSrc(url().string());
239 body->appendChild(m_imageElement.get()); 229 body->appendChild(m_imageElement.get());
230 if (loader())
231 m_imageElement->cachedImage()->responseReceived(loader()->response(), nu llptr);
240 232
241 if (shouldShrinkToFit()) { 233 if (shouldShrinkToFit()) {
242 // Add event listeners 234 // Add event listeners
243 RefPtrWillBeRawPtr<EventListener> listener = ImageEventListener::create( this); 235 RefPtrWillBeRawPtr<EventListener> listener = ImageEventListener::create( this);
244 if (LocalDOMWindow* domWindow = this->domWindow()) 236 if (LocalDOMWindow* domWindow = this->domWindow())
245 domWindow->addEventListener("resize", listener, false); 237 domWindow->addEventListener("resize", listener, false);
246 if (m_shrinkToFitMode == Desktop) 238 if (m_shrinkToFitMode == Desktop)
247 m_imageElement->addEventListener("click", listener.release(), false) ; 239 m_imageElement->addEventListener("click", listener.release(), false) ;
248 } 240 }
249 241
250 rootElement->appendChild(head); 242 rootElement->appendChild(head);
251 rootElement->appendChild(body); 243 rootElement->appendChild(body);
252 if (loadingMultipartContent)
253 finishedParsing();
254 } 244 }
255 245
256 float ImageDocument::scale() const 246 float ImageDocument::scale() const
257 { 247 {
258 if (!m_imageElement || m_imageElement->document() != this) 248 if (!m_imageElement || m_imageElement->document() != this)
259 return 1.0f; 249 return 1.0f;
260 250
261 FrameView* view = frame()->view(); 251 FrameView* view = frame()->view();
262 if (!view) 252 if (!view)
263 return 1; 253 return 1;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 // If the image isn't resized but needs to be, then resize it. 398 // If the image isn't resized but needs to be, then resize it.
409 if (!fitsInWindow) { 399 if (!fitsInWindow) {
410 resizeImageToFit(type); 400 resizeImageToFit(type);
411 m_didShrinkImage = true; 401 m_didShrinkImage = true;
412 } 402 }
413 } 403 }
414 } 404 }
415 405
416 ImageResource* ImageDocument::cachedImage() 406 ImageResource* ImageDocument::cachedImage()
417 { 407 {
418 bool loadingMultipartContent = loader() && loader()->loadingMultipartContent ();
419 if (!m_imageElement) 408 if (!m_imageElement)
420 createDocumentStructure(loadingMultipartContent); 409 createDocumentStructure();
421 410
422 return loadingMultipartContent ? nullptr : m_imageElement->cachedImage(); 411 return m_imageElement->cachedImage();
423 } 412 }
424 413
425 bool ImageDocument::shouldShrinkToFit() const 414 bool ImageDocument::shouldShrinkToFit() const
426 { 415 {
427 return frame()->isMainFrame(); 416 return frame()->isMainFrame();
428 } 417 }
429 418
430 #if !ENABLE(OILPAN) 419 #if !ENABLE(OILPAN)
431 void ImageDocument::dispose() 420 void ImageDocument::dispose()
432 { 421 {
(...skipping 21 matching lines...) Expand all
454 } 443 }
455 444
456 bool ImageEventListener::operator==(const EventListener& listener) const 445 bool ImageEventListener::operator==(const EventListener& listener) const
457 { 446 {
458 if (const ImageEventListener* imageEventListener = ImageEventListener::cast( &listener)) 447 if (const ImageEventListener* imageEventListener = ImageEventListener::cast( &listener))
459 return m_doc == imageEventListener->m_doc; 448 return m_doc == imageEventListener->m_doc;
460 return false; 449 return false;
461 } 450 }
462 451
463 } // namespace blink 452 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/ImageDocument.h ('k') | third_party/WebKit/Source/core/loader/DocumentLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698