Changeset 122099 in webkit
- Timestamp:
- Jul 9, 2012 1:53:48 AM (12 years ago)
- Location:
- trunk/Source
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r122096 r122099 1 2012-07-09 MORITA Hajime <morrita@google.com> 2 3 [Chromium] ContextFeaturesClient::isEnabled is slow 4 https://bugs.webkit.org/show_bug.cgi?id=90367 5 6 Reviewed by Kent Tamura. 7 8 * dom/ContextFeatures.h: 9 (WebCore::ContextFeaturesClient::urlDidChange): Added. 10 (WebCore::ContextFeatures::urlDidChange): Added. 11 (WebCore): 12 * dom/Document.cpp: 13 (WebCore::Document::setURL): Added an urlDidChange() call. 14 1 15 2012-07-09 Andrei Onea <onea@adobe.com> 2 16 -
trunk/Source/WebCore/dom/ContextFeatures.h
r120168 r122099 41 41 public: 42 42 enum FeatureType { 43 ShadowDOM ,43 ShadowDOM = 0, 44 44 StyleScoped, 45 PagePopup 45 PagePopup, 46 FeatureTypeSize // Should be the last enetry. 46 47 }; 47 48 … … 55 56 56 57 bool isEnabled(Document*, FeatureType, bool) const; 58 void urlDidChange(Document*); 57 59 58 60 private: … … 78 80 virtual ~ContextFeaturesClient() { } 79 81 virtual bool isEnabled(Document*, ContextFeatures::FeatureType, bool defaultValue) { return defaultValue; } 82 virtual void urlDidChange(Document*) { } 80 83 }; 81 84 … … 95 98 } 96 99 100 inline void ContextFeatures::urlDidChange(Document* document) 101 { 102 if (m_client) 103 return; 104 m_client->urlDidChange(document); 105 } 106 97 107 } // namespace WebCore 98 108 -
trunk/Source/WebCore/dom/Document.cpp
r121952 r122099 2685 2685 m_documentURI = m_url.string(); 2686 2686 updateBaseURL(); 2687 contextFeatures()->urlDidChange(this); 2687 2688 } 2688 2689 -
trunk/Source/WebKit/chromium/ChangeLog
r122098 r122099 1 2012-07-09 MORITA Hajime <morrita@google.com> 2 3 [Chromium] ContextFeaturesClient::isEnabled is slow 4 https://bugs.webkit.org/show_bug.cgi?id=90367 5 6 Reviewed by Kent Tamura. 7 8 ContextFeaturesClientImpl::isEnabled touches a heavy part in chrome 9 where locks are acquired for each invocation. 10 11 This change introduces a set of caches to avoid such slow calls. 12 The cache class ContextFeaturesCache is implemented as a 13 Supplement of ScriptExecutionContext because the flag bits 14 depend on the domain of each Document. 15 16 * src/ContextFeaturesClientImpl.cpp: 17 (ContextFeaturesCache): Added. 18 (Entry): Added. 19 (WebKit::ContextFeaturesCache::Entry::Entry): 20 (WebKit::ContextFeaturesCache::Entry::isEnabled): 21 (WebKit::ContextFeaturesCache::Entry::set): 22 (WebKit::ContextFeaturesCache::Entry::needsRefresh): 23 (WebKit::ContextFeaturesCache::entryFor): 24 (WebKit): 25 (WebKit::ContextFeaturesCache::supplementName): 26 (WebKit::ContextFeaturesCache::from): 27 (WebKit::ContextFeaturesCache::refreshAgainst): 28 (WebKit::ContextFeaturesClientImpl::isEnabled): 29 (WebKit::ContextFeaturesClientImpl::urlDidChange): Added to invoke refrshAgainst. 30 (WebKit::ContextFeaturesClientImpl::askIfIsEnabled): 31 * src/ContextFeaturesClientImpl.h: 32 (ContextFeaturesClientImpl): 33 1 34 2012-07-09 Vsevolod Vlasov <vsevik@chromium.org> 2 35 -
trunk/Source/WebKit/chromium/src/ContextFeaturesClientImpl.cpp
r120168 r122099 33 33 34 34 #include "Document.h" 35 #include "SecurityOrigin.h" 35 36 #include "WebDocument.h" 36 37 #include "WebPermissionClient.h" 37 38 39 using namespace WebCore; 40 38 41 namespace WebKit { 39 42 40 bool ContextFeaturesClientImpl::isEnabled(WebCore::Document* document, WebCore::ContextFeatures::FeatureType type, bool defaultValue) 43 class ContextFeaturesCache : public Supplement<ScriptExecutionContext> { 44 public: 45 class Entry { 46 public: 47 enum Value { 48 IsEnabled, 49 IsDisabled, 50 NeedsRefresh 51 }; 52 53 Entry() 54 : m_value(NeedsRefresh) 55 , m_defaultValue(false) 56 { } 57 58 bool isEnabled() const 59 { 60 ASSERT(m_value != NeedsRefresh); 61 return m_value == IsEnabled; 62 } 63 64 void set(bool value, bool defaultValue) 65 { 66 m_value = value ? IsEnabled : IsDisabled; 67 m_defaultValue = defaultValue; 68 } 69 70 bool needsRefresh(bool defaultValue) const 71 { 72 return m_value == NeedsRefresh || m_defaultValue != defaultValue; 73 } 74 75 private: 76 Value m_value; 77 bool m_defaultValue; // Needs to be traked as a part of the signature since it can be changed dynamically. 78 }; 79 80 static const AtomicString& supplementName(); 81 static ContextFeaturesCache* from(Document*); 82 83 Entry& entryFor(ContextFeatures::FeatureType type) 84 { 85 size_t index = static_cast<size_t>(type); 86 ASSERT(index < ContextFeatures::FeatureTypeSize); 87 return m_entries[index]; 88 } 89 90 void validateAgainst(Document*); 91 92 private: 93 String m_domain; 94 Entry m_entries[ContextFeatures::FeatureTypeSize]; 95 }; 96 97 const AtomicString& ContextFeaturesCache::supplementName() 98 { 99 DEFINE_STATIC_LOCAL(AtomicString, name, ("ContextFeaturesCache")); 100 return name; 101 } 102 103 ContextFeaturesCache* ContextFeaturesCache::from(Document* document) 104 { 105 ContextFeaturesCache* cache = static_cast<ContextFeaturesCache*>(Supplement<ScriptExecutionContext>::from(document, supplementName())); 106 if (!cache) { 107 cache = new ContextFeaturesCache(); 108 Supplement<ScriptExecutionContext>::provideTo(document, supplementName(), adoptPtr(cache)); 109 } 110 111 return cache; 112 } 113 114 void ContextFeaturesCache::validateAgainst(Document* document) 115 { 116 String currentDomain = document->securityOrigin()->domain(); 117 if (currentDomain == m_domain) 118 return; 119 m_domain = currentDomain; 120 for (size_t i = 0; i < ContextFeatures::FeatureTypeSize; ++i) 121 m_entries[i] = Entry(); 122 } 123 124 bool ContextFeaturesClientImpl::isEnabled(Document* document, ContextFeatures::FeatureType type, bool defaultValue) 125 { 126 ContextFeaturesCache::Entry& cache = ContextFeaturesCache::from(document)->entryFor(type); 127 if (cache.needsRefresh(defaultValue)) 128 cache.set(askIfIsEnabled(document, type, defaultValue), defaultValue); 129 return cache.isEnabled(); 130 } 131 132 void ContextFeaturesClientImpl::urlDidChange(Document* document) 133 { 134 ContextFeaturesCache::from(document)->validateAgainst(document); 135 } 136 137 bool ContextFeaturesClientImpl::askIfIsEnabled(Document* document, ContextFeatures::FeatureType type, bool defaultValue) 41 138 { 42 139 if (!m_client) … … 44 141 45 142 switch (type) { 46 case WebCore::ContextFeatures::ShadowDOM:47 case WebCore::ContextFeatures::StyleScoped:143 case ContextFeatures::ShadowDOM: 144 case ContextFeatures::StyleScoped: 48 145 return m_client->allowWebComponents(WebDocument(document), defaultValue); 49 146 default: -
trunk/Source/WebKit/chromium/src/ContextFeaturesClientImpl.h
r120168 r122099 45 45 46 46 virtual bool isEnabled(WebCore::Document*, WebCore::ContextFeatures::FeatureType, bool defaultValue) OVERRIDE; 47 virtual void urlDidChange(WebCore::Document*) OVERRIDE; 47 48 void setPermissionClient(WebPermissionClient* client) { m_client = client; } 48 49 49 50 private: 51 bool askIfIsEnabled(WebCore::Document*, WebCore::ContextFeatures::FeatureType, bool defaultValue); 52 50 53 WebPermissionClient* m_client; 51 54 };
Note: See TracChangeset
for help on using the changeset viewer.