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

Side by Side Diff: Source/core/loader/ImageLoader.h

Issue 481753002: Use Shadow DOM to display fallback content for images (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Updated Created 6 years 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2004, 2009 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2009 Apple Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 template<typename T> class EventSender; 57 template<typename T> class EventSender;
58 typedef EventSender<ImageLoader> ImageEventSender; 58 typedef EventSender<ImageLoader> ImageEventSender;
59 59
60 class ImageLoader : public NoBaseWillBeGarbageCollectedFinalized<ImageLoader>, p ublic ImageResourceClient { 60 class ImageLoader : public NoBaseWillBeGarbageCollectedFinalized<ImageLoader>, p ublic ImageResourceClient {
61 public: 61 public:
62 explicit ImageLoader(Element*); 62 explicit ImageLoader(Element*);
63 virtual ~ImageLoader(); 63 virtual ~ImageLoader();
64 void trace(Visitor*); 64 void trace(Visitor*);
65 65
66 enum LoadType {
67 LoadNormally,
68 ForceLoadImmediately
69 };
70
71 enum UpdateFromElementBehavior { 66 enum UpdateFromElementBehavior {
72 // This should be the update behavior when the element is attached to a document, or when DOM mutations trigger a new load. 67 // This should be the update behavior when the element is attached to a document, or when DOM mutations trigger a new load.
73 // Starts loading if a load hasn't already been started. 68 // Starts loading if a load hasn't already been started.
74 UpdateNormal, 69 UpdateNormal,
75 // This should be the update behavior when the resource was changed (via 'src', 'srcset' or 'sizes'). 70 // This should be the update behavior when the resource was changed (via 'src', 'srcset' or 'sizes').
76 // Starts a new load even if a previous load of the same resource have f ailed, to match Firefox's behavior. 71 // Starts a new load even if a previous load of the same resource have f ailed, to match Firefox's behavior.
77 // FIXME - Verify that this is the right behavior according to the spec. 72 // FIXME - Verify that this is the right behavior according to the spec.
78 UpdateIgnorePreviousError, 73 UpdateIgnorePreviousError,
79 // This forces the image to update its intrinsic size, even if the image source has not changed. 74 // This forces the image to update its intrinsic size, even if the image source has not changed.
80 UpdateSizeChanged 75 UpdateSizeChanged
81 }; 76 };
82 77
83 enum BypassMainWorldBehavior { 78 enum BypassMainWorldBehavior {
84 BypassMainWorldCSP, 79 BypassMainWorldCSP,
85 DoNotBypassMainWorldCSP 80 DoNotBypassMainWorldCSP
86 }; 81 };
87 82
88 void updateFromElement(UpdateFromElementBehavior = UpdateNormal, LoadType = LoadNormally); 83 void updateFromElement(UpdateFromElementBehavior = UpdateNormal);
89 84
90 void elementDidMoveToNewDocument(); 85 void elementDidMoveToNewDocument();
91 86
92 Element* element() const { return m_element; } 87 Element* element() const { return m_element; }
93 bool imageComplete() const 88 bool imageComplete() const
94 { 89 {
95 return m_imageComplete && !m_pendingTask; 90 return m_imageComplete && !m_pendingTask;
96 } 91 }
97 92
98 ImageResource* image() const { return m_image.get(); } 93 ImageResource* image() const { return m_image.get(); }
99 void setImage(ImageResource*); // Cancels pending load events, and doesn't d ispatch new ones. 94 void setImage(ImageResource*); // Cancels pending load events, and doesn't d ispatch new ones.
100 95
101 void setLoadingImageDocument() { m_loadingImageDocument = true; } 96 void setLoadingImageDocument() { m_loadingImageDocument = true; }
102 97
103 bool hasPendingActivity() const 98 bool hasPendingActivity() const
104 { 99 {
105 return m_hasPendingLoadEvent || m_hasPendingErrorEvent || m_pendingTask; 100 return m_hasPendingLoadEvent || m_hasPendingErrorEvent || m_pendingTask;
106 } 101 }
107 102
108 void dispatchPendingEvent(ImageEventSender*); 103 void dispatchPendingEvent(ImageEventSender*);
109 104
110 static void dispatchPendingLoadEvents(); 105 static void dispatchPendingLoadEvents();
111 static void dispatchPendingErrorEvents(); 106 static void dispatchPendingErrorEvents();
112 107
113 void addClient(ImageLoaderClient*); 108 void addClient(ImageLoaderClient*);
114 void removeClient(ImageLoaderClient*); 109 void removeClient(ImageLoaderClient*);
115
116 protected: 110 protected:
117 virtual void notifyFinished(Resource*) override; 111 virtual void notifyFinished(Resource*) override;
118 112
119 private: 113 private:
120 class Task; 114 class Task;
121 115
122 // Called from the task or from updateFromElement to initiate the load. 116 // Called from the task or from updateFromElement to initiate the load.
123 void doUpdateFromElement(BypassMainWorldBehavior, UpdateFromElementBehavior) ; 117 void doUpdateFromElement(BypassMainWorldBehavior, UpdateFromElementBehavior) ;
124 118
125 virtual void dispatchLoadEvent() = 0; 119 virtual void dispatchLoadEvent() = 0;
126 virtual String sourceURI(const AtomicString&) const = 0; 120 virtual String sourceURI(const AtomicString&) const = 0;
121 virtual void noImageResourceToLoad() { };
127 122
128 void updatedHasPendingEvent(); 123 void updatedHasPendingEvent();
129 124
130 void dispatchPendingLoadEvent(); 125 void dispatchPendingLoadEvent();
131 void dispatchPendingErrorEvent(); 126 void dispatchPendingErrorEvent();
132 127
133 RenderImageResource* renderImageResource(); 128 RenderImageResource* renderImageResource();
134 void updateRenderer(); 129 void updateRenderer();
135 130
136 void setImageWithoutConsideringPendingLoadEvent(ImageResource*); 131 void setImageWithoutConsideringPendingLoadEvent(ImageResource*);
137 void sourceImageChanged(); 132 void sourceImageChanged();
138 void clearFailedLoadURL(); 133 void clearFailedLoadURL();
139 void dispatchErrorEvent(); 134 void dispatchErrorEvent();
140 void crossSiteOrCSPViolationOccurred(AtomicString); 135 void crossSiteOrCSPViolationOccurred(AtomicString);
141 void enqueueImageLoadingMicroTask(UpdateFromElementBehavior); 136 void enqueueImageLoadingMicroTask(UpdateFromElementBehavior);
142 static ResourcePtr<ImageResource> createImageResourceForImageDocument(Docume nt&, FetchRequest&); 137 static ResourcePtr<ImageResource> createImageResourceForImageDocument(Docume nt&, FetchRequest&);
143 138
144 void timerFired(Timer<ImageLoader>*); 139 void timerFired(Timer<ImageLoader>*);
145 140
146 KURL imageSourceToKURL(AtomicString) const; 141 KURL imageSourceToKURL(AtomicString) const;
147 142
148 // Used to determine whether to immediately initiate the load 143 // Used to determine whether to immediately initiate the load
149 // or to schedule a microtask. 144 // or to schedule a microtask.
150 bool shouldLoadImmediately(const KURL&, LoadType) const; 145 bool shouldLoadImmediately(const KURL&) const;
151 146
152 void willRemoveClient(ImageLoaderClient&); 147 void willRemoveClient(ImageLoaderClient&);
153 148
154 RawPtrWillBeMember<Element> m_element; 149 RawPtrWillBeMember<Element> m_element;
155 ResourcePtr<ImageResource> m_image; 150 ResourcePtr<ImageResource> m_image;
156 // FIXME: Oilpan: We might be able to remove this Persistent hack when 151 // FIXME: Oilpan: We might be able to remove this Persistent hack when
157 // ImageResourceClient is traceable. 152 // ImageResourceClient is traceable.
158 GC_PLUGIN_IGNORE("http://crbug.com/383741") 153 GC_PLUGIN_IGNORE("http://crbug.com/383741")
159 RefPtrWillBePersistent<Element> m_keepAlive; 154 RefPtrWillBePersistent<Element> m_keepAlive;
160 #if ENABLE(OILPAN) 155 #if ENABLE(OILPAN)
(...skipping 26 matching lines...) Expand all
187 bool m_imageComplete : 1; 182 bool m_imageComplete : 1;
188 bool m_loadingImageDocument : 1; 183 bool m_loadingImageDocument : 1;
189 bool m_elementIsProtected : 1; 184 bool m_elementIsProtected : 1;
190 bool m_suppressErrorEvents : 1; 185 bool m_suppressErrorEvents : 1;
191 unsigned m_highPriorityClientCount; 186 unsigned m_highPriorityClientCount;
192 }; 187 };
193 188
194 } 189 }
195 190
196 #endif 191 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698