• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4  * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #include "config.h"
23 #include "HTMLImageLoader.h"
24 
25 #include "CachedImage.h"
26 #include "Element.h"
27 #include "Event.h"
28 #include "EventNames.h"
29 #include "HTMLNames.h"
30 #include "HTMLObjectElement.h"
31 #include "HTMLParserIdioms.h"
32 #include "Settings.h"
33 
34 #if USE(JSC)
35 #include "JSDOMWindowBase.h"
36 #include <runtime/JSLock.h>
37 #endif
38 
39 namespace WebCore {
40 
HTMLImageLoader(Element * node)41 HTMLImageLoader::HTMLImageLoader(Element* node)
42     : ImageLoader(node)
43 {
44 }
45 
~HTMLImageLoader()46 HTMLImageLoader::~HTMLImageLoader()
47 {
48 }
49 
dispatchLoadEvent()50 void HTMLImageLoader::dispatchLoadEvent()
51 {
52     // HTMLVideoElement uses this class to load the poster image, but it should not fire events for loading or failure.
53     if (element()->hasTagName(HTMLNames::videoTag))
54         return;
55 
56     bool errorOccurred = image()->errorOccurred();
57     if (!errorOccurred && image()->response().httpStatusCode() >= 400)
58         errorOccurred = element()->hasTagName(HTMLNames::objectTag); // An <object> considers a 404 to be an error and should fire onerror.
59     element()->dispatchEvent(Event::create(errorOccurred ? eventNames().errorEvent : eventNames().loadEvent, false, false));
60 }
61 
sourceURI(const AtomicString & attr) const62 String HTMLImageLoader::sourceURI(const AtomicString& attr) const
63 {
64 #if ENABLE(DASHBOARD_SUPPORT)
65     Settings* settings = element()->document()->settings();
66     if (settings && settings->usesDashboardBackwardCompatibilityMode() && attr.length() > 7 && attr.startsWith("url(\"") && attr.endsWith("\")"))
67         return attr.string().substring(5, attr.length() - 7);
68 #endif
69 
70     return stripLeadingAndTrailingHTMLSpaces(attr);
71 }
72 
notifyFinished(CachedResource *)73 void HTMLImageLoader::notifyFinished(CachedResource*)
74 {
75     CachedImage* cachedImage = image();
76 
77     Element* elem = element();
78     ImageLoader::notifyFinished(cachedImage);
79 
80     bool loadError = cachedImage->errorOccurred() || cachedImage->response().httpStatusCode() >= 400;
81 #if USE(JSC)
82     if (!loadError) {
83         if (!elem->inDocument()) {
84             JSC::JSLock lock(JSC::SilenceAssertionsOnly);
85             JSC::JSGlobalData* globalData = JSDOMWindowBase::commonJSGlobalData();
86             globalData->heap.reportExtraMemoryCost(cachedImage->encodedSize());
87         }
88     }
89 #endif
90 
91     if (loadError && elem->hasTagName(HTMLNames::objectTag))
92         static_cast<HTMLObjectElement*>(elem)->renderFallbackContent();
93 }
94 
95 }
96