| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 { | 72 { |
| 73 return m_value == NeedsRefresh || m_defaultValue != defaultValue; | 73 return m_value == NeedsRefresh || m_defaultValue != defaultValue; |
| 74 } | 74 } |
| 75 | 75 |
| 76 private: | 76 private: |
| 77 Value m_value; | 77 Value m_value; |
| 78 bool m_defaultValue; // Needs to be traked as a part of the signature si
nce it can be changed dynamically. | 78 bool m_defaultValue; // Needs to be traked as a part of the signature si
nce it can be changed dynamically. |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 static const char* supplementName(); | 81 static const char* supplementName(); |
| 82 static ContextFeaturesCache* from(Document*); | 82 static ContextFeaturesCache& from(Document&); |
| 83 | 83 |
| 84 Entry& entryFor(ContextFeatures::FeatureType type) | 84 Entry& entryFor(ContextFeatures::FeatureType type) |
| 85 { | 85 { |
| 86 size_t index = static_cast<size_t>(type); | 86 size_t index = static_cast<size_t>(type); |
| 87 ASSERT_WITH_SECURITY_IMPLICATION(index < ContextFeatures::FeatureTypeSiz
e); | 87 ASSERT_WITH_SECURITY_IMPLICATION(index < ContextFeatures::FeatureTypeSiz
e); |
| 88 return m_entries[index]; | 88 return m_entries[index]; |
| 89 } | 89 } |
| 90 | 90 |
| 91 void validateAgainst(Document*); | 91 void validateAgainst(Document*); |
| 92 | 92 |
| 93 private: | 93 private: |
| 94 String m_domain; | 94 String m_domain; |
| 95 Entry m_entries[ContextFeatures::FeatureTypeSize]; | 95 Entry m_entries[ContextFeatures::FeatureTypeSize]; |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 const char* ContextFeaturesCache::supplementName() | 98 const char* ContextFeaturesCache::supplementName() |
| 99 { | 99 { |
| 100 return "ContextFeaturesCache"; | 100 return "ContextFeaturesCache"; |
| 101 } | 101 } |
| 102 | 102 |
| 103 ContextFeaturesCache* ContextFeaturesCache::from(Document* document) | 103 ContextFeaturesCache& ContextFeaturesCache::from(Document& document) |
| 104 { | 104 { |
| 105 ContextFeaturesCache* cache = static_cast<ContextFeaturesCache*>(DocumentSup
plement::from(document, supplementName())); | 105 ContextFeaturesCache* cache = static_cast<ContextFeaturesCache*>(DocumentSup
plement::from(document, supplementName())); |
| 106 if (!cache) { | 106 if (!cache) { |
| 107 cache = new ContextFeaturesCache(); | 107 cache = new ContextFeaturesCache(); |
| 108 DocumentSupplement::provideTo(document, supplementName(), adoptPtr(cache
)); | 108 DocumentSupplement::provideTo(document, supplementName(), adoptPtr(cache
)); |
| 109 } | 109 } |
| 110 | 110 |
| 111 return cache; | 111 return *cache; |
| 112 } | 112 } |
| 113 | 113 |
| 114 void ContextFeaturesCache::validateAgainst(Document* document) | 114 void ContextFeaturesCache::validateAgainst(Document* document) |
| 115 { | 115 { |
| 116 String currentDomain = document->securityOrigin()->domain(); | 116 String currentDomain = document->securityOrigin()->domain(); |
| 117 if (currentDomain == m_domain) | 117 if (currentDomain == m_domain) |
| 118 return; | 118 return; |
| 119 m_domain = currentDomain; | 119 m_domain = currentDomain; |
| 120 for (size_t i = 0; i < ContextFeatures::FeatureTypeSize; ++i) | 120 for (size_t i = 0; i < ContextFeatures::FeatureTypeSize; ++i) |
| 121 m_entries[i] = Entry(); | 121 m_entries[i] = Entry(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 bool ContextFeaturesClientImpl::isEnabled(Document* document, ContextFeatures::F
eatureType type, bool defaultValue) | 124 bool ContextFeaturesClientImpl::isEnabled(Document* document, ContextFeatures::F
eatureType type, bool defaultValue) |
| 125 { | 125 { |
| 126 ContextFeaturesCache::Entry& cache = ContextFeaturesCache::from(document)->e
ntryFor(type); | 126 ASSERT(document); |
| 127 ContextFeaturesCache::Entry& cache = ContextFeaturesCache::from(*document).e
ntryFor(type); |
| 127 if (cache.needsRefresh(defaultValue)) | 128 if (cache.needsRefresh(defaultValue)) |
| 128 cache.set(askIfIsEnabled(document, type, defaultValue), defaultValue); | 129 cache.set(askIfIsEnabled(document, type, defaultValue), defaultValue); |
| 129 return cache.isEnabled(); | 130 return cache.isEnabled(); |
| 130 } | 131 } |
| 131 | 132 |
| 132 void ContextFeaturesClientImpl::urlDidChange(Document* document) | 133 void ContextFeaturesClientImpl::urlDidChange(Document* document) |
| 133 { | 134 { |
| 134 ContextFeaturesCache::from(document)->validateAgainst(document); | 135 ASSERT(document); |
| 136 ContextFeaturesCache::from(*document).validateAgainst(document); |
| 135 } | 137 } |
| 136 | 138 |
| 137 bool ContextFeaturesClientImpl::askIfIsEnabled(Document* document, ContextFeatur
es::FeatureType type, bool defaultValue) | 139 bool ContextFeaturesClientImpl::askIfIsEnabled(Document* document, ContextFeatur
es::FeatureType type, bool defaultValue) |
| 138 { | 140 { |
| 139 WebFrameImpl* frame = WebFrameImpl::fromFrame(document->frame()); | 141 WebFrameImpl* frame = WebFrameImpl::fromFrame(document->frame()); |
| 140 if (!frame || !frame->permissionClient()) | 142 if (!frame || !frame->permissionClient()) |
| 141 return defaultValue; | 143 return defaultValue; |
| 142 | 144 |
| 143 switch (type) { | 145 switch (type) { |
| 144 case ContextFeatures::StyleScoped: | 146 case ContextFeatures::StyleScoped: |
| 145 return frame->permissionClient()->allowWebComponents(frame, defaultValue
); | 147 return frame->permissionClient()->allowWebComponents(frame, defaultValue
); |
| 146 case ContextFeatures::MutationEvents: | 148 case ContextFeatures::MutationEvents: |
| 147 return frame->permissionClient()->allowMutationEvents(frame, defaultValu
e); | 149 return frame->permissionClient()->allowMutationEvents(frame, defaultValu
e); |
| 148 case ContextFeatures::PushState: | 150 case ContextFeatures::PushState: |
| 149 return frame->permissionClient()->allowPushState(frame); | 151 return frame->permissionClient()->allowPushState(frame); |
| 150 default: | 152 default: |
| 151 return defaultValue; | 153 return defaultValue; |
| 152 } | 154 } |
| 153 } | 155 } |
| 154 | 156 |
| 155 } // namespace blink | 157 } // namespace blink |
| OLD | NEW |