1 /* 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef PendingScript_h 27 #define PendingScript_h 28 29 #include "CachedResourceClient.h" 30 #include "CachedResourceHandle.h" 31 #include <wtf/text/TextPosition.h> 32 #include <wtf/PassRefPtr.h> 33 34 namespace WebCore { 35 36 class CachedScript; 37 class Element; 38 39 // A container for an external script which may be loaded and executed. 40 // 41 // A CachedResourceHandle alone does not prevent the underlying CachedResource 42 // from purging its data buffer. This class holds a dummy client open for its 43 // lifetime in order to guarantee that the data buffer will not be purged. 44 class PendingScript : public CachedResourceClient { 45 public: PendingScript()46 PendingScript() 47 : m_watchingForLoad(false) 48 , m_startingPosition(TextPosition1::belowRangePosition()) 49 { 50 } 51 PendingScript(Element * element,CachedScript * cachedScript)52 PendingScript(Element* element, CachedScript* cachedScript) 53 : m_watchingForLoad(false) 54 , m_element(element) 55 { 56 setCachedScript(cachedScript); 57 } 58 PendingScript(const PendingScript & other)59 PendingScript(const PendingScript& other) 60 : CachedResourceClient(other) 61 , m_watchingForLoad(other.m_watchingForLoad) 62 , m_element(other.m_element) 63 , m_startingPosition(other.m_startingPosition) 64 { 65 setCachedScript(other.cachedScript()); 66 } 67 68 ~PendingScript(); 69 70 PendingScript& operator=(const PendingScript& other) 71 { 72 if (this == &other) 73 return *this; 74 75 m_watchingForLoad = other.m_watchingForLoad; 76 m_element = other.m_element; 77 m_startingPosition = other.m_startingPosition; 78 setCachedScript(other.cachedScript()); 79 80 return *this; 81 } 82 startingPosition()83 TextPosition1 startingPosition() const { return m_startingPosition; } setStartingPosition(const TextPosition1 & position)84 void setStartingPosition(const TextPosition1& position) { m_startingPosition = position; } 85 watchingForLoad()86 bool watchingForLoad() const { return m_watchingForLoad; } setWatchingForLoad(bool b)87 void setWatchingForLoad(bool b) { m_watchingForLoad = b; } 88 element()89 Element* element() const { return m_element.get(); } setElement(Element * element)90 void setElement(Element* element) { m_element = element; } 91 PassRefPtr<Element> releaseElementAndClear(); 92 93 CachedScript* cachedScript() const; 94 void setCachedScript(CachedScript*); 95 96 virtual void notifyFinished(CachedResource*); 97 98 private: 99 bool m_watchingForLoad; 100 RefPtr<Element> m_element; 101 TextPosition1 m_startingPosition; // Only used for inline script tags. 102 CachedResourceHandle<CachedScript> m_cachedScript; 103 }; 104 105 } 106 107 #endif 108