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

Side by Side Diff: Source/core/dom/ScriptElement.h

Issue 18676002: Refactoring: Decouple ScriptElement from HTMLScriptElement and SVGScriptElement. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Addressed points Created 7 years, 5 months 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
« no previous file with comments | « no previous file | Source/core/dom/ScriptElement.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 16 matching lines...) Expand all
27 #include <wtf/text/WTFString.h> 27 #include <wtf/text/WTFString.h>
28 28
29 namespace WebCore { 29 namespace WebCore {
30 30
31 class CachedScript; 31 class CachedScript;
32 class ContainerNode; 32 class ContainerNode;
33 class Element; 33 class Element;
34 class ScriptElement; 34 class ScriptElement;
35 class ScriptSourceCode; 35 class ScriptSourceCode;
36 36
37 class ScriptElementClient {
38 public:
39 virtual ~ScriptElementClient() { }
40
41 virtual void dispatchLoadEvent() = 0;
42
43 virtual String sourceAttributeValue() const = 0;
44 virtual String charsetAttributeValue() const = 0;
45 virtual String typeAttributeValue() const = 0;
46 virtual String languageAttributeValue() const = 0;
47 virtual String forAttributeValue() const = 0;
48 virtual String eventAttributeValue() const = 0;
49 virtual bool asyncAttributeValue() const = 0;
50 virtual bool deferAttributeValue() const = 0;
51 virtual bool hasSourceAttribute() const = 0;
52 };
53
37 class ScriptElement : private CachedResourceClient { 54 class ScriptElement : private CachedResourceClient {
38 public: 55 public:
39 ScriptElement(Element*, bool createdByParser, bool isEvaluated); 56 static PassOwnPtr<ScriptElement> create(Element*, bool createdByParser, bool isEvaluated);
40 virtual ~ScriptElement(); 57 virtual ~ScriptElement();
41 58
42 Element* element() const { return m_element; } 59 Element* element() const { return m_element; }
43 60
44 enum LegacyTypeSupport { DisallowLegacyTypeInTypeAttribute, AllowLegacyTypeI nTypeAttribute }; 61 enum LegacyTypeSupport { DisallowLegacyTypeInTypeAttribute, AllowLegacyTypeI nTypeAttribute };
45 bool prepareScript(const TextPosition& scriptStartPosition = TextPosition::m inimumPosition(), LegacyTypeSupport = DisallowLegacyTypeInTypeAttribute); 62 bool prepareScript(const TextPosition& scriptStartPosition = TextPosition::m inimumPosition(), LegacyTypeSupport = DisallowLegacyTypeInTypeAttribute);
46 63
47 String scriptCharset() const { return m_characterEncoding; } 64 String scriptCharset() const { return m_characterEncoding; }
48 String scriptContent() const; 65 String scriptContent() const;
49 void executeScript(const ScriptSourceCode&); 66 void executeScript(const ScriptSourceCode&);
50 void execute(CachedScript*); 67 void execute(CachedScript*);
51 68
52 // XML parser calls these 69 // XML parser calls these
53 virtual void dispatchLoadEvent() = 0; 70 void dispatchLoadEvent();
54 void dispatchErrorEvent(); 71 void dispatchErrorEvent();
55 bool isScriptTypeSupported(LegacyTypeSupport) const; 72 bool isScriptTypeSupported(LegacyTypeSupport) const;
56 73
57 bool haveFiredLoadEvent() const { return m_haveFiredLoad; } 74 bool haveFiredLoadEvent() const { return m_haveFiredLoad; }
58 bool willBeParserExecuted() const { return m_willBeParserExecuted; } 75 bool willBeParserExecuted() const { return m_willBeParserExecuted; }
59 bool readyToBeParserExecuted() const { return m_readyToBeParserExecuted; } 76 bool readyToBeParserExecuted() const { return m_readyToBeParserExecuted; }
60 bool willExecuteWhenDocumentFinishedParsing() const { return m_willExecuteWh enDocumentFinishedParsing; } 77 bool willExecuteWhenDocumentFinishedParsing() const { return m_willExecuteWh enDocumentFinishedParsing; }
61 CachedResourceHandle<CachedScript> cachedScript() { return m_cachedScript; } 78 CachedResourceHandle<CachedScript> cachedScript() { return m_cachedScript; }
62 79
63 protected:
64 void setHaveFiredLoadEvent(bool haveFiredLoad) { m_haveFiredLoad = haveFired Load; } 80 void setHaveFiredLoadEvent(bool haveFiredLoad) { m_haveFiredLoad = haveFired Load; }
65 bool isParserInserted() const { return m_parserInserted; } 81 bool isParserInserted() const { return m_parserInserted; }
66 bool alreadyStarted() const { return m_alreadyStarted; } 82 bool alreadyStarted() const { return m_alreadyStarted; }
67 bool forceAsync() const { return m_forceAsync; } 83 bool forceAsync() const { return m_forceAsync; }
68 84
69 // Helper functions used by our parent classes. 85 // Helper functions used by our parent classes.
70 void insertedInto(ContainerNode*); 86 void insertedInto(ContainerNode*);
71 void childrenChanged(); 87 void childrenChanged();
72 void handleSourceAttribute(const String& sourceUrl); 88 void handleSourceAttribute(const String& sourceUrl);
73 void handleAsyncAttribute(); 89 void handleAsyncAttribute();
74 90
75 private: 91 private:
92 ScriptElement(Element*, bool createdByParser, bool isEvaluated);
93
76 bool ignoresLoadRequest() const; 94 bool ignoresLoadRequest() const;
77 bool isScriptForEventSupported() const; 95 bool isScriptForEventSupported() const;
78 96
79 bool requestScript(const String& sourceUrl); 97 bool requestScript(const String& sourceUrl);
80 void stopLoadRequest(); 98 void stopLoadRequest();
81 99
82 virtual void notifyFinished(CachedResource*); 100 ScriptElementClient* client() const;
83 101
84 virtual String sourceAttributeValue() const = 0; 102 // CachedResourceClient
85 virtual String charsetAttributeValue() const = 0; 103 virtual void notifyFinished(CachedResource*) OVERRIDE;
86 virtual String typeAttributeValue() const = 0;
87 virtual String languageAttributeValue() const = 0;
88 virtual String forAttributeValue() const = 0;
89 virtual String eventAttributeValue() const = 0;
90 virtual bool asyncAttributeValue() const = 0;
91 virtual bool deferAttributeValue() const = 0;
92 virtual bool hasSourceAttribute() const = 0;
93 104
94 Element* m_element; 105 Element* m_element;
95 CachedResourceHandle<CachedScript> m_cachedScript; 106 CachedResourceHandle<CachedScript> m_cachedScript;
96 WTF::OrdinalNumber m_startLineNumber; 107 WTF::OrdinalNumber m_startLineNumber;
97 bool m_parserInserted : 1; 108 bool m_parserInserted : 1;
98 bool m_isExternalScript : 1; 109 bool m_isExternalScript : 1;
99 bool m_alreadyStarted : 1; 110 bool m_alreadyStarted : 1;
100 bool m_haveFiredLoad : 1; 111 bool m_haveFiredLoad : 1;
101 bool m_willBeParserExecuted : 1; // Same as "The parser will handle executin g the script." 112 bool m_willBeParserExecuted : 1; // Same as "The parser will handle executin g the script."
102 bool m_readyToBeParserExecuted : 1; 113 bool m_readyToBeParserExecuted : 1;
103 bool m_willExecuteWhenDocumentFinishedParsing : 1; 114 bool m_willExecuteWhenDocumentFinishedParsing : 1;
104 bool m_forceAsync : 1; 115 bool m_forceAsync : 1;
105 bool m_willExecuteInOrder : 1; 116 bool m_willExecuteInOrder : 1;
106 String m_characterEncoding; 117 String m_characterEncoding;
107 String m_fallbackCharacterEncoding; 118 String m_fallbackCharacterEncoding;
108 }; 119 };
109 120
110 ScriptElement* toScriptElementIfPossible(Element*); 121 ScriptElement* toScriptElementIfPossible(Element*);
111 122
123 inline PassOwnPtr<ScriptElement> ScriptElement::create(Element* element, bool cr eatedByParser, bool isEvaluated)
124 {
125 return adoptPtr(new ScriptElement(element, createdByParser, isEvaluated));
112 } 126 }
113 127
128 }
129
130
114 #endif 131 #endif
OLDNEW
« no previous file with comments | « no previous file | Source/core/dom/ScriptElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698