| 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 if (isStopped()) |
| 210 return; |
| 212 // Normally, ImageDocument creates an HTMLImageElement that doesn't actually
load | 211 // 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 | 212 // 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. | 213 // 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 | 214 // For multipart content, we instead stop streaming data through the main re
source and re-request |
| 216 // the data directly. | 215 // the data directly. |
| 217 if (loadingMultipartContent) | 216 if (loadingMultipartContent) |
| 218 loader()->stopLoading(); | 217 loader()->stopLoading(); |
| 219 | 218 |
| 220 RefPtrWillBeRawPtr<HTMLHeadElement> head = HTMLHeadElement::create(*this); | 219 RefPtrWillBeRawPtr<HTMLHeadElement> head = HTMLHeadElement::create(*this); |
| 221 RefPtrWillBeRawPtr<HTMLMetaElement> meta = HTMLMetaElement::create(*this); | 220 RefPtrWillBeRawPtr<HTMLMetaElement> meta = HTMLMetaElement::create(*this); |
| 222 meta->setAttribute(nameAttr, "viewport"); | 221 meta->setAttribute(nameAttr, "viewport"); |
| 223 meta->setAttribute(contentAttr, "width=device-width, minimum-scale=0.1"); | 222 meta->setAttribute(contentAttr, "width=device-width, minimum-scale=0.1"); |
| 224 head->appendChild(meta); | 223 head->appendChild(meta); |
| 225 | 224 |
| 226 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*this); | 225 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*this); |
| 227 body->setAttribute(styleAttr, "margin: 0px;"); | 226 body->setAttribute(styleAttr, "margin: 0px;"); |
| 228 | 227 |
| 229 if (frame()) | 228 frame()->loader().client()->dispatchWillInsertBody(); |
| 230 frame()->loader().client()->dispatchWillInsertBody(); | |
| 231 | 229 |
| 232 m_imageElement = HTMLImageElement::create(*this); | 230 m_imageElement = HTMLImageElement::create(*this); |
| 233 m_imageElement->setAttribute(styleAttr, "-webkit-user-select: none"); | 231 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 | 232 // 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. | 233 // ImageDocument, so that it requests the image normally. |
| 236 if (!loadingMultipartContent) | 234 if (!loadingMultipartContent) |
| 237 m_imageElement->setLoadingImageDocument(); | 235 m_imageElement->setLoadingImageDocument(); |
| 238 m_imageElement->setSrc(url().string()); | 236 m_imageElement->setSrc(url().string()); |
| 239 body->appendChild(m_imageElement.get()); | 237 body->appendChild(m_imageElement.get()); |
| 240 | 238 |
| 241 if (shouldShrinkToFit()) { | 239 if (shouldShrinkToFit()) { |
| 242 // Add event listeners | 240 // Add event listeners |
| 243 RefPtrWillBeRawPtr<EventListener> listener = ImageEventListener::create(
this); | 241 RefPtrWillBeRawPtr<EventListener> listener = ImageEventListener::create(
this); |
| 244 if (LocalDOMWindow* domWindow = this->domWindow()) | 242 if (LocalDOMWindow* domWindow = this->domWindow()) |
| 245 domWindow->addEventListener("resize", listener, false); | 243 domWindow->addEventListener("resize", listener, false); |
| 246 if (m_shrinkToFitMode == Desktop) | 244 if (m_shrinkToFitMode == Desktop) |
| 247 m_imageElement->addEventListener("click", listener.release(), false)
; | 245 m_imageElement->addEventListener("click", listener.release(), false)
; |
| 248 } | 246 } |
| 249 | 247 |
| 250 rootElement->appendChild(head); | 248 rootElement->appendChild(head); |
| 249 if (isStopped()) |
| 250 return; |
| 251 rootElement->appendChild(body); | 251 rootElement->appendChild(body); |
| 252 if (isStopped()) |
| 253 return; |
| 252 if (loadingMultipartContent) | 254 if (loadingMultipartContent) |
| 253 finishedParsing(); | 255 finishedParsing(); |
| 254 } | 256 } |
| 255 | 257 |
| 256 float ImageDocument::scale() const | 258 float ImageDocument::scale() const |
| 257 { | 259 { |
| 258 if (!m_imageElement || m_imageElement->document() != this) | 260 if (!m_imageElement || m_imageElement->document() != this) |
| 259 return 1.0f; | 261 return 1.0f; |
| 260 | 262 |
| 261 FrameView* view = frame()->view(); | 263 FrameView* view = frame()->view(); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 if (!fitsInWindow) { | 411 if (!fitsInWindow) { |
| 410 resizeImageToFit(type); | 412 resizeImageToFit(type); |
| 411 m_didShrinkImage = true; | 413 m_didShrinkImage = true; |
| 412 } | 414 } |
| 413 } | 415 } |
| 414 } | 416 } |
| 415 | 417 |
| 416 ImageResource* ImageDocument::cachedImage() | 418 ImageResource* ImageDocument::cachedImage() |
| 417 { | 419 { |
| 418 bool loadingMultipartContent = loader() && loader()->loadingMultipartContent
(); | 420 bool loadingMultipartContent = loader() && loader()->loadingMultipartContent
(); |
| 419 if (!m_imageElement) | 421 if (!m_imageElement) { |
| 420 createDocumentStructure(loadingMultipartContent); | 422 createDocumentStructure(loadingMultipartContent); |
| 423 if (isStopped()) { |
| 424 m_imageElement = nullptr; |
| 425 return nullptr; |
| 426 } |
| 427 } |
| 421 | 428 |
| 422 return loadingMultipartContent ? nullptr : m_imageElement->cachedImage(); | 429 return loadingMultipartContent ? nullptr : m_imageElement->cachedImage(); |
| 423 } | 430 } |
| 424 | 431 |
| 425 bool ImageDocument::shouldShrinkToFit() const | 432 bool ImageDocument::shouldShrinkToFit() const |
| 426 { | 433 { |
| 427 return frame()->isMainFrame(); | 434 return frame()->isMainFrame(); |
| 428 } | 435 } |
| 429 | 436 |
| 430 #if !ENABLE(OILPAN) | 437 #if !ENABLE(OILPAN) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 454 } | 461 } |
| 455 | 462 |
| 456 bool ImageEventListener::operator==(const EventListener& listener) const | 463 bool ImageEventListener::operator==(const EventListener& listener) const |
| 457 { | 464 { |
| 458 if (const ImageEventListener* imageEventListener = ImageEventListener::cast(
&listener)) | 465 if (const ImageEventListener* imageEventListener = ImageEventListener::cast(
&listener)) |
| 459 return m_doc == imageEventListener->m_doc; | 466 return m_doc == imageEventListener->m_doc; |
| 460 return false; | 467 return false; |
| 461 } | 468 } |
| 462 | 469 |
| 463 } // namespace blink | 470 } // namespace blink |
| OLD | NEW |