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() | 202 void ImageDocument::createDocumentStructure() |
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 | 212 |
213 RefPtrWillBeRawPtr<HTMLHeadElement> head = HTMLHeadElement::create(*this); | 213 RefPtrWillBeRawPtr<HTMLHeadElement> head = HTMLHeadElement::create(*this); |
214 RefPtrWillBeRawPtr<HTMLMetaElement> meta = HTMLMetaElement::create(*this); | 214 RefPtrWillBeRawPtr<HTMLMetaElement> meta = HTMLMetaElement::create(*this); |
215 meta->setAttribute(nameAttr, "viewport"); | 215 meta->setAttribute(nameAttr, "viewport"); |
216 meta->setAttribute(contentAttr, "width=device-width, minimum-scale=0.1"); | 216 meta->setAttribute(contentAttr, "width=device-width, minimum-scale=0.1"); |
217 head->appendChild(meta); | 217 head->appendChild(meta); |
218 | 218 |
219 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*this); | 219 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*this); |
220 body->setAttribute(styleAttr, "margin: 0px;"); | 220 body->setAttribute(styleAttr, "margin: 0px;"); |
221 | 221 |
222 if (frame()) | 222 frame()->loader().client()->dispatchWillInsertBody(); |
223 frame()->loader().client()->dispatchWillInsertBody(); | |
224 | 223 |
225 m_imageElement = HTMLImageElement::create(*this); | 224 m_imageElement = HTMLImageElement::create(*this); |
226 m_imageElement->setAttribute(styleAttr, "-webkit-user-select: none"); | 225 m_imageElement->setAttribute(styleAttr, "-webkit-user-select: none"); |
227 m_imageElement->setLoadingImageDocument(); | 226 m_imageElement->setLoadingImageDocument(); |
228 m_imageElement->setSrc(url().getString()); | 227 m_imageElement->setSrc(url().getString()); |
229 body->appendChild(m_imageElement.get()); | 228 body->appendChild(m_imageElement.get()); |
230 if (loader()) | 229 if (loader()) |
231 m_imageElement->cachedImage()->responseReceived(loader()->response(), nu
llptr); | 230 m_imageElement->cachedImage()->responseReceived(loader()->response(), nu
llptr); |
232 | 231 |
233 if (shouldShrinkToFit()) { | 232 if (shouldShrinkToFit()) { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 // If the image isn't resized but needs to be, then resize it. | 397 // If the image isn't resized but needs to be, then resize it. |
399 if (!fitsInWindow) { | 398 if (!fitsInWindow) { |
400 resizeImageToFit(type); | 399 resizeImageToFit(type); |
401 m_didShrinkImage = true; | 400 m_didShrinkImage = true; |
402 } | 401 } |
403 } | 402 } |
404 } | 403 } |
405 | 404 |
406 ImageResource* ImageDocument::cachedImage() | 405 ImageResource* ImageDocument::cachedImage() |
407 { | 406 { |
408 if (!m_imageElement) | 407 if (!m_imageElement) { |
409 createDocumentStructure(); | 408 createDocumentStructure(); |
| 409 if (isStopped()) { |
| 410 m_imageElement = nullptr; |
| 411 return nullptr; |
| 412 } |
| 413 } |
410 | 414 |
411 return m_imageElement->cachedImage(); | 415 return m_imageElement->cachedImage(); |
412 } | 416 } |
413 | 417 |
414 bool ImageDocument::shouldShrinkToFit() const | 418 bool ImageDocument::shouldShrinkToFit() const |
415 { | 419 { |
416 return frame()->isMainFrame(); | 420 return frame()->isMainFrame(); |
417 } | 421 } |
418 | 422 |
419 #if !ENABLE(OILPAN) | 423 #if !ENABLE(OILPAN) |
(...skipping 23 matching lines...) Expand all Loading... |
443 } | 447 } |
444 | 448 |
445 bool ImageEventListener::operator==(const EventListener& listener) const | 449 bool ImageEventListener::operator==(const EventListener& listener) const |
446 { | 450 { |
447 if (const ImageEventListener* imageEventListener = ImageEventListener::cast(
&listener)) | 451 if (const ImageEventListener* imageEventListener = ImageEventListener::cast(
&listener)) |
448 return m_doc == imageEventListener->m_doc; | 452 return m_doc == imageEventListener->m_doc; |
449 return false; | 453 return false; |
450 } | 454 } |
451 | 455 |
452 } // namespace blink | 456 } // namespace blink |
OLD | NEW |