| OLD | NEW |
| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 LocalFrame* frame = document()->frame(); | 139 LocalFrame* frame = document()->frame(); |
| 140 Settings* settings = frame->settings(); | 140 Settings* settings = frame->settings(); |
| 141 if (!frame->loader().client()->allowImage(!settings || settings->imagesEnabl
ed(), document()->url())) | 141 if (!frame->loader().client()->allowImage(!settings || settings->imagesEnabl
ed(), document()->url())) |
| 142 return; | 142 return; |
| 143 | 143 |
| 144 if (document()->cachedImage()) { | 144 if (document()->cachedImage()) { |
| 145 RELEASE_ASSERT(length <= std::numeric_limits<unsigned>::max()); | 145 RELEASE_ASSERT(length <= std::numeric_limits<unsigned>::max()); |
| 146 document()->cachedImage()->appendData(data, length); | 146 document()->cachedImage()->appendData(data, length); |
| 147 } | 147 } |
| 148 | 148 |
| 149 // TODO(esprehn): These null checks on Document don't make sense, document() | 149 if (!isDetached()) |
| 150 // will ASSERT if it was null. Do these want to check isDetached() ? | |
| 151 if (document()) | |
| 152 document()->imageUpdated(); | 150 document()->imageUpdated(); |
| 153 } | 151 } |
| 154 | 152 |
| 155 void ImageDocumentParser::finish() | 153 void ImageDocumentParser::finish() |
| 156 { | 154 { |
| 157 if (!isStopped() && document()->imageElement() && document()->cachedImage())
{ | 155 if (!isStopped() && document()->imageElement() && document()->cachedImage())
{ |
| 158 ImageResource* cachedImage = document()->cachedImage(); | 156 ImageResource* cachedImage = document()->cachedImage(); |
| 159 DocumentLoader* loader = document()->loader(); | 157 DocumentLoader* loader = document()->loader(); |
| 160 cachedImage->setResponse(loader->response()); | 158 cachedImage->setResponse(loader->response()); |
| 161 cachedImage->setLoadFinishTime(loader->timing().responseEnd()); | 159 cachedImage->setLoadFinishTime(loader->timing().responseEnd()); |
| 162 cachedImage->finish(); | 160 cachedImage->finish(); |
| 163 | 161 |
| 164 // Report the natural image size in the page title, regardless of zoom l
evel. | 162 // Report the natural image size in the page title, regardless of zoom l
evel. |
| 165 // At a zoom level of 1 the image is guaranteed to have an integer size. | 163 // At a zoom level of 1 the image is guaranteed to have an integer size. |
| 166 IntSize size = flooredIntSize(cachedImage->imageSize(LayoutObject::shoul
dRespectImageOrientation(document()->imageElement()->layoutObject()), 1.0f)); | 164 IntSize size = flooredIntSize(cachedImage->imageSize(LayoutObject::shoul
dRespectImageOrientation(document()->imageElement()->layoutObject()), 1.0f)); |
| 167 if (size.width()) { | 165 if (size.width()) { |
| 168 // Compute the title, we use the decoded filename of the resource, f
alling | 166 // Compute the title, we use the decoded filename of the resource, f
alling |
| 169 // back on the (decoded) hostname if there is no path. | 167 // back on the (decoded) hostname if there is no path. |
| 170 String fileName = decodeURLEscapeSequences(document()->url().lastPat
hComponent()); | 168 String fileName = decodeURLEscapeSequences(document()->url().lastPat
hComponent()); |
| 171 if (fileName.isEmpty()) | 169 if (fileName.isEmpty()) |
| 172 fileName = document()->url().host(); | 170 fileName = document()->url().host(); |
| 173 document()->setTitle(imageTitle(fileName, size)); | 171 document()->setTitle(imageTitle(fileName, size)); |
| 172 if (isDetached()) |
| 173 return; |
| 174 } | 174 } |
| 175 | 175 |
| 176 document()->imageUpdated(); | 176 document()->imageUpdated(); |
| 177 } | 177 } |
| 178 | 178 |
| 179 // TODO(esprehn): These null checks on Document don't make sense, document() | 179 if (!isDetached()) |
| 180 // will ASSERT if it was null. Do these want to check isDetached() ? | |
| 181 if (document()) | |
| 182 document()->finishedParsing(); | 180 document()->finishedParsing(); |
| 183 } | 181 } |
| 184 | 182 |
| 185 // -------- | 183 // -------- |
| 186 | 184 |
| 187 ImageDocument::ImageDocument(const DocumentInit& initializer) | 185 ImageDocument::ImageDocument(const DocumentInit& initializer) |
| 188 : HTMLDocument(initializer, ImageDocumentClass) | 186 : HTMLDocument(initializer, ImageDocumentClass) |
| 189 , m_imageElement(nullptr) | 187 , m_imageElement(nullptr) |
| 190 , m_imageSizeIsKnown(false) | 188 , m_imageSizeIsKnown(false) |
| 191 , m_didShrinkImage(false) | 189 , m_didShrinkImage(false) |
| 192 , m_shouldShrinkImage(shouldShrinkToFit()) | 190 , m_shouldShrinkImage(shouldShrinkToFit()) |
| 193 , m_shrinkToFitMode(frame()->settings()->viewportEnabled() ? Viewport : Desk
top) | 191 , m_shrinkToFitMode(frame()->settings()->viewportEnabled() ? Viewport : Desk
top) |
| 194 { | 192 { |
| 195 setCompatibilityMode(QuirksMode); | 193 setCompatibilityMode(QuirksMode); |
| 196 lockCompatibilityMode(); | 194 lockCompatibilityMode(); |
| 197 } | 195 } |
| 198 | 196 |
| 199 PassRefPtrWillBeRawPtr<DocumentParser> ImageDocument::createParser() | 197 PassRefPtrWillBeRawPtr<DocumentParser> ImageDocument::createParser() |
| 200 { | 198 { |
| 201 return ImageDocumentParser::create(this); | 199 return ImageDocumentParser::create(this); |
| 202 } | 200 } |
| 203 | 201 |
| 204 void ImageDocument::createDocumentStructure(bool loadingMultipartContent) | 202 void ImageDocument::createDocumentStructure(bool loadingMultipartContent) |
| 205 { | 203 { |
| 206 RefPtrWillBeRawPtr<HTMLHtmlElement> rootElement = HTMLHtmlElement::create(*t
his); | 204 RefPtrWillBeRawPtr<HTMLHtmlElement> rootElement = HTMLHtmlElement::create(*t
his); |
| 207 appendChild(rootElement); | 205 appendChild(rootElement); |
| 208 rootElement->insertedByParser(); | 206 rootElement->insertedByParser(); |
| 209 | 207 |
| 210 if (frame()) | 208 frame()->loader().dispatchDocumentElementAvailable(); |
| 211 frame()->loader().dispatchDocumentElementAvailable(); | 209 frame()->loader().runScriptsAtDocumentElementAvailable(); |
| 210 if (isStopped()) |
| 211 return; // runScriptsAtDocumentElementAvailable can detach the frame. |
| 212 // Normally, ImageDocument creates an HTMLImageElement that doesn't actually
load | 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 | 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. | 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 | 215 // For multipart content, we instead stop streaming data through the main re
source and re-request |
| 216 // the data directly. | 216 // the data directly. |
| 217 if (loadingMultipartContent) | 217 if (loadingMultipartContent) |
| 218 loader()->stopLoading(); | 218 loader()->stopLoading(); |
| 219 | 219 |
| 220 RefPtrWillBeRawPtr<HTMLHeadElement> head = HTMLHeadElement::create(*this); | 220 RefPtrWillBeRawPtr<HTMLHeadElement> head = HTMLHeadElement::create(*this); |
| 221 RefPtrWillBeRawPtr<HTMLMetaElement> meta = HTMLMetaElement::create(*this); | 221 RefPtrWillBeRawPtr<HTMLMetaElement> meta = HTMLMetaElement::create(*this); |
| 222 meta->setAttribute(nameAttr, "viewport"); | 222 meta->setAttribute(nameAttr, "viewport"); |
| 223 meta->setAttribute(contentAttr, "width=device-width, minimum-scale=0.1"); | 223 meta->setAttribute(contentAttr, "width=device-width, minimum-scale=0.1"); |
| 224 head->appendChild(meta); | 224 head->appendChild(meta); |
| 225 | 225 |
| 226 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*this); | 226 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*this); |
| 227 body->setAttribute(styleAttr, "margin: 0px;"); | 227 body->setAttribute(styleAttr, "margin: 0px;"); |
| 228 | 228 |
| 229 if (frame()) | 229 frame()->loader().client()->dispatchWillInsertBody(); |
| 230 frame()->loader().client()->dispatchWillInsertBody(); | |
| 231 | 230 |
| 232 m_imageElement = HTMLImageElement::create(*this); | 231 m_imageElement = HTMLImageElement::create(*this); |
| 233 m_imageElement->setAttribute(styleAttr, "-webkit-user-select: none"); | 232 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 | 233 // If the image is multipart, we neglect to mention to the HTMLImageElement
that it's in an |
| 235 // ImageDocument, so that it requests the image normally. | 234 // ImageDocument, so that it requests the image normally. |
| 236 if (!loadingMultipartContent) | 235 if (!loadingMultipartContent) |
| 237 m_imageElement->setLoadingImageDocument(); | 236 m_imageElement->setLoadingImageDocument(); |
| 238 m_imageElement->setSrc(url().string()); | 237 m_imageElement->setSrc(url().string()); |
| 239 body->appendChild(m_imageElement.get()); | 238 body->appendChild(m_imageElement.get()); |
| 240 | 239 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 if (!fitsInWindow) { | 408 if (!fitsInWindow) { |
| 410 resizeImageToFit(type); | 409 resizeImageToFit(type); |
| 411 m_didShrinkImage = true; | 410 m_didShrinkImage = true; |
| 412 } | 411 } |
| 413 } | 412 } |
| 414 } | 413 } |
| 415 | 414 |
| 416 ImageResource* ImageDocument::cachedImage() | 415 ImageResource* ImageDocument::cachedImage() |
| 417 { | 416 { |
| 418 bool loadingMultipartContent = loader() && loader()->loadingMultipartContent
(); | 417 bool loadingMultipartContent = loader() && loader()->loadingMultipartContent
(); |
| 419 if (!m_imageElement) | 418 if (!m_imageElement) { |
| 420 createDocumentStructure(loadingMultipartContent); | 419 createDocumentStructure(loadingMultipartContent); |
| 420 if (isStopped()) { |
| 421 m_imageElement = nullptr; |
| 422 return nullptr; |
| 423 } |
| 424 } |
| 421 | 425 |
| 422 return loadingMultipartContent ? nullptr : m_imageElement->cachedImage(); | 426 return loadingMultipartContent ? nullptr : m_imageElement->cachedImage(); |
| 423 } | 427 } |
| 424 | 428 |
| 425 bool ImageDocument::shouldShrinkToFit() const | 429 bool ImageDocument::shouldShrinkToFit() const |
| 426 { | 430 { |
| 427 return frame()->isMainFrame(); | 431 return frame()->isMainFrame(); |
| 428 } | 432 } |
| 429 | 433 |
| 430 #if !ENABLE(OILPAN) | 434 #if !ENABLE(OILPAN) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 454 } | 458 } |
| 455 | 459 |
| 456 bool ImageEventListener::operator==(const EventListener& listener) const | 460 bool ImageEventListener::operator==(const EventListener& listener) const |
| 457 { | 461 { |
| 458 if (const ImageEventListener* imageEventListener = ImageEventListener::cast(
&listener)) | 462 if (const ImageEventListener* imageEventListener = ImageEventListener::cast(
&listener)) |
| 459 return m_doc == imageEventListener->m_doc; | 463 return m_doc == imageEventListener->m_doc; |
| 460 return false; | 464 return false; |
| 461 } | 465 } |
| 462 | 466 |
| 463 } // namespace blink | 467 } // namespace blink |
| OLD | NEW |