- Revision
- 122099
- Author
- [email protected]
- Date
- 2012-07-09 01:53:48 -0700 (Mon, 09 Jul 2012)
Log Message
[Chromium] ContextFeaturesClient::isEnabled is slow
https://bugs.webkit.org/show_bug.cgi?id=90367
Reviewed by Kent Tamura.
Source/WebCore:
* dom/ContextFeatures.h:
(WebCore::ContextFeaturesClient::urlDidChange): Added.
(WebCore::ContextFeatures::urlDidChange): Added.
(WebCore):
* dom/Document.cpp:
(WebCore::Document::setURL): Added an urlDidChange() call.
Source/WebKit/chromium:
ContextFeaturesClientImpl::isEnabled touches a heavy part in chrome
where locks are acquired for each invocation.
This change introduces a set of caches to avoid such slow calls.
The cache class ContextFeaturesCache is implemented as a
Supplement of ScriptExecutionContext because the flag bits
depend on the domain of each Document.
* src/ContextFeaturesClientImpl.cpp:
(ContextFeaturesCache): Added.
(Entry): Added.
(WebKit::ContextFeaturesCache::Entry::Entry):
(WebKit::ContextFeaturesCache::Entry::isEnabled):
(WebKit::ContextFeaturesCache::Entry::set):
(WebKit::ContextFeaturesCache::Entry::needsRefresh):
(WebKit::ContextFeaturesCache::entryFor):
(WebKit):
(WebKit::ContextFeaturesCache::supplementName):
(WebKit::ContextFeaturesCache::from):
(WebKit::ContextFeaturesCache::refreshAgainst):
(WebKit::ContextFeaturesClientImpl::isEnabled):
(WebKit::ContextFeaturesClientImpl::urlDidChange): Added to invoke refrshAgainst.
(WebKit::ContextFeaturesClientImpl::askIfIsEnabled):
* src/ContextFeaturesClientImpl.h:
(ContextFeaturesClientImpl):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (122098 => 122099)
--- trunk/Source/WebCore/ChangeLog 2012-07-09 08:36:51 UTC (rev 122098)
+++ trunk/Source/WebCore/ChangeLog 2012-07-09 08:53:48 UTC (rev 122099)
@@ -1,3 +1,17 @@
+2012-07-09 MORITA Hajime <[email protected]>
+
+ [Chromium] ContextFeaturesClient::isEnabled is slow
+ https://bugs.webkit.org/show_bug.cgi?id=90367
+
+ Reviewed by Kent Tamura.
+
+ * dom/ContextFeatures.h:
+ (WebCore::ContextFeaturesClient::urlDidChange): Added.
+ (WebCore::ContextFeatures::urlDidChange): Added.
+ (WebCore):
+ * dom/Document.cpp:
+ (WebCore::Document::setURL): Added an urlDidChange() call.
+
2012-07-09 Andrei Onea <[email protected]>
[CSSRegions] Implement NamedFlow::firstEmptyRegionIndex attribute
Modified: trunk/Source/WebCore/dom/ContextFeatures.h (122098 => 122099)
--- trunk/Source/WebCore/dom/ContextFeatures.h 2012-07-09 08:36:51 UTC (rev 122098)
+++ trunk/Source/WebCore/dom/ContextFeatures.h 2012-07-09 08:53:48 UTC (rev 122099)
@@ -40,9 +40,10 @@
class ContextFeatures : public RefCountedSupplement<Page, ContextFeatures> {
public:
enum FeatureType {
- ShadowDOM,
+ ShadowDOM = 0,
StyleScoped,
- PagePopup
+ PagePopup,
+ FeatureTypeSize // Should be the last enetry.
};
static const AtomicString& supplementName();
@@ -54,6 +55,7 @@
static bool pagePopupEnabled(Document*);
bool isEnabled(Document*, FeatureType, bool) const;
+ void urlDidChange(Document*);
private:
explicit ContextFeatures(ContextFeaturesClient* client)
@@ -77,6 +79,7 @@
virtual ~ContextFeaturesClient() { }
virtual bool isEnabled(Document*, ContextFeatures::FeatureType, bool defaultValue) { return defaultValue; }
+ virtual void urlDidChange(Document*) { }
};
void provideContextFeaturesTo(Page*, ContextFeaturesClient*);
@@ -94,6 +97,13 @@
return m_client->isEnabled(document, type, defaultValue);
}
+inline void ContextFeatures::urlDidChange(Document* document)
+{
+ if (m_client)
+ return;
+ m_client->urlDidChange(document);
+}
+
} // namespace WebCore
#endif // ContextFeatures_h
Modified: trunk/Source/WebCore/dom/Document.cpp (122098 => 122099)
--- trunk/Source/WebCore/dom/Document.cpp 2012-07-09 08:36:51 UTC (rev 122098)
+++ trunk/Source/WebCore/dom/Document.cpp 2012-07-09 08:53:48 UTC (rev 122099)
@@ -2684,6 +2684,7 @@
m_url = newURL;
m_documentURI = m_url.string();
updateBaseURL();
+ contextFeatures()->urlDidChange(this);
}
void Document::updateBaseURL()
Modified: trunk/Source/WebKit/chromium/ChangeLog (122098 => 122099)
--- trunk/Source/WebKit/chromium/ChangeLog 2012-07-09 08:36:51 UTC (rev 122098)
+++ trunk/Source/WebKit/chromium/ChangeLog 2012-07-09 08:53:48 UTC (rev 122099)
@@ -1,3 +1,36 @@
+2012-07-09 MORITA Hajime <[email protected]>
+
+ [Chromium] ContextFeaturesClient::isEnabled is slow
+ https://bugs.webkit.org/show_bug.cgi?id=90367
+
+ Reviewed by Kent Tamura.
+
+ ContextFeaturesClientImpl::isEnabled touches a heavy part in chrome
+ where locks are acquired for each invocation.
+
+ This change introduces a set of caches to avoid such slow calls.
+ The cache class ContextFeaturesCache is implemented as a
+ Supplement of ScriptExecutionContext because the flag bits
+ depend on the domain of each Document.
+
+ * src/ContextFeaturesClientImpl.cpp:
+ (ContextFeaturesCache): Added.
+ (Entry): Added.
+ (WebKit::ContextFeaturesCache::Entry::Entry):
+ (WebKit::ContextFeaturesCache::Entry::isEnabled):
+ (WebKit::ContextFeaturesCache::Entry::set):
+ (WebKit::ContextFeaturesCache::Entry::needsRefresh):
+ (WebKit::ContextFeaturesCache::entryFor):
+ (WebKit):
+ (WebKit::ContextFeaturesCache::supplementName):
+ (WebKit::ContextFeaturesCache::from):
+ (WebKit::ContextFeaturesCache::refreshAgainst):
+ (WebKit::ContextFeaturesClientImpl::isEnabled):
+ (WebKit::ContextFeaturesClientImpl::urlDidChange): Added to invoke refrshAgainst.
+ (WebKit::ContextFeaturesClientImpl::askIfIsEnabled):
+ * src/ContextFeaturesClientImpl.h:
+ (ContextFeaturesClientImpl):
+
2012-07-09 Vsevolod Vlasov <[email protected]>
Unreviewed chromium inspector test fix.
Modified: trunk/Source/WebKit/chromium/src/ContextFeaturesClientImpl.cpp (122098 => 122099)
--- trunk/Source/WebKit/chromium/src/ContextFeaturesClientImpl.cpp 2012-07-09 08:36:51 UTC (rev 122098)
+++ trunk/Source/WebKit/chromium/src/ContextFeaturesClientImpl.cpp 2012-07-09 08:53:48 UTC (rev 122099)
@@ -32,19 +32,116 @@
#include "ContextFeaturesClientImpl.h"
#include "Document.h"
+#include "SecurityOrigin.h"
#include "WebDocument.h"
#include "WebPermissionClient.h"
+using namespace WebCore;
+
namespace WebKit {
-bool ContextFeaturesClientImpl::isEnabled(WebCore::Document* document, WebCore::ContextFeatures::FeatureType type, bool defaultValue)
+class ContextFeaturesCache : public Supplement<ScriptExecutionContext> {
+public:
+ class Entry {
+ public:
+ enum Value {
+ IsEnabled,
+ IsDisabled,
+ NeedsRefresh
+ };
+
+ Entry()
+ : m_value(NeedsRefresh)
+ , m_defaultValue(false)
+ { }
+
+ bool isEnabled() const
+ {
+ ASSERT(m_value != NeedsRefresh);
+ return m_value == IsEnabled;
+ }
+
+ void set(bool value, bool defaultValue)
+ {
+ m_value = value ? IsEnabled : IsDisabled;
+ m_defaultValue = defaultValue;
+ }
+
+ bool needsRefresh(bool defaultValue) const
+ {
+ return m_value == NeedsRefresh || m_defaultValue != defaultValue;
+ }
+
+ private:
+ Value m_value;
+ bool m_defaultValue; // Needs to be traked as a part of the signature since it can be changed dynamically.
+ };
+
+ static const AtomicString& supplementName();
+ static ContextFeaturesCache* from(Document*);
+
+ Entry& entryFor(ContextFeatures::FeatureType type)
+ {
+ size_t index = static_cast<size_t>(type);
+ ASSERT(index < ContextFeatures::FeatureTypeSize);
+ return m_entries[index];
+ }
+
+ void validateAgainst(Document*);
+
+private:
+ String m_domain;
+ Entry m_entries[ContextFeatures::FeatureTypeSize];
+};
+
+const AtomicString& ContextFeaturesCache::supplementName()
{
+ DEFINE_STATIC_LOCAL(AtomicString, name, ("ContextFeaturesCache"));
+ return name;
+}
+
+ContextFeaturesCache* ContextFeaturesCache::from(Document* document)
+{
+ ContextFeaturesCache* cache = static_cast<ContextFeaturesCache*>(Supplement<ScriptExecutionContext>::from(document, supplementName()));
+ if (!cache) {
+ cache = new ContextFeaturesCache();
+ Supplement<ScriptExecutionContext>::provideTo(document, supplementName(), adoptPtr(cache));
+ }
+
+ return cache;
+}
+
+void ContextFeaturesCache::validateAgainst(Document* document)
+{
+ String currentDomain = document->securityOrigin()->domain();
+ if (currentDomain == m_domain)
+ return;
+ m_domain = currentDomain;
+ for (size_t i = 0; i < ContextFeatures::FeatureTypeSize; ++i)
+ m_entries[i] = Entry();
+}
+
+bool ContextFeaturesClientImpl::isEnabled(Document* document, ContextFeatures::FeatureType type, bool defaultValue)
+{
+ ContextFeaturesCache::Entry& cache = ContextFeaturesCache::from(document)->entryFor(type);
+ if (cache.needsRefresh(defaultValue))
+ cache.set(askIfIsEnabled(document, type, defaultValue), defaultValue);
+ return cache.isEnabled();
+}
+
+void ContextFeaturesClientImpl::urlDidChange(Document* document)
+{
+ ContextFeaturesCache::from(document)->validateAgainst(document);
+}
+
+bool ContextFeaturesClientImpl::askIfIsEnabled(Document* document, ContextFeatures::FeatureType type, bool defaultValue)
+{
if (!m_client)
return defaultValue;
switch (type) {
- case WebCore::ContextFeatures::ShadowDOM:
- case WebCore::ContextFeatures::StyleScoped:
+ case ContextFeatures::ShadowDOM:
+ case ContextFeatures::StyleScoped:
return m_client->allowWebComponents(WebDocument(document), defaultValue);
default:
return defaultValue;
Modified: trunk/Source/WebKit/chromium/src/ContextFeaturesClientImpl.h (122098 => 122099)
--- trunk/Source/WebKit/chromium/src/ContextFeaturesClientImpl.h 2012-07-09 08:36:51 UTC (rev 122098)
+++ trunk/Source/WebKit/chromium/src/ContextFeaturesClientImpl.h 2012-07-09 08:53:48 UTC (rev 122099)
@@ -44,9 +44,12 @@
{ }
virtual bool isEnabled(WebCore::Document*, WebCore::ContextFeatures::FeatureType, bool defaultValue) OVERRIDE;
+ virtual void urlDidChange(WebCore::Document*) OVERRIDE;
void setPermissionClient(WebPermissionClient* client) { m_client = client; }
private:
+ bool askIfIsEnabled(WebCore::Document*, WebCore::ContextFeatures::FeatureType, bool defaultValue);
+
WebPermissionClient* m_client;
};