Changeset 162395 in webkit
- Timestamp:
- Jan 20, 2014 5:51:03 PM (10 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r162394 r162395 1 2014-01-20 Anders Carlsson <andersca@apple.com> 2 3 Move user style sheet handling to UserContentController 4 https://bugs.webkit.org/show_bug.cgi?id=127322 5 <rdar://problem/15861296> 6 7 Reviewed by Andreas Kling. 8 9 * dom/DocumentStyleSheetCollection.cpp: 10 (WebCore::DocumentStyleSheetCollection::updateInjectedStyleSheetCache): 11 * page/PageGroup.cpp: 12 (WebCore::PageGroup::addUserStyleSheetToWorld): 13 (WebCore::PageGroup::removeUserStyleSheetFromWorld): 14 (WebCore::PageGroup::removeUserStyleSheetsFromWorld): 15 (WebCore::PageGroup::removeAllUserContent): 16 * page/PageGroup.h: 17 * page/UserContentController.cpp: 18 (WebCore::UserContentController::addUserStyleSheet): 19 (WebCore::UserContentController::removeUserStyleSheet): 20 (WebCore::UserContentController::removeUserStyleSheets): 21 (WebCore::UserContentController::removeAllUserContent): 22 (WebCore::UserContentController::invalidateInjectedStyleSheetCacheInAllFrames): 23 * page/UserContentController.h: 24 (WebCore::UserContentController::userStyleSheets): 25 1 26 2014-01-20 Benjamin Poulain <benjamin@webkit.org> 2 27 -
trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp
r161127 r162395 44 44 #include "StyleSheetContents.h" 45 45 #include "StyleSheetList.h" 46 #include "UserContentController.h" 46 47 #include "UserContentURLPattern.h" 47 48 … … 141 142 if (!owningPage) 142 143 return; 143 144 const PageGroup& pageGroup = owningPage->group();145 const UserStyleSheetMap* sheetsMap = pageGroup.userStyleSheets();146 if (!sheetsMap)147 return; 148 149 UserStyleSheetMap::const_iterator end = sheetsMap->end();150 for (UserStyleSheetMap::const_iterator it = sheetsMap->begin(); it != end; ++it) {151 const UserStyleSheetVector* sheets = it->value.get(); 152 for (unsigned i = 0; i < sheets->size(); ++i) {153 const UserStyleSheet* sheet = sheets->at(i).get();144 145 const auto* userContentController = owningPage->userContentController(); 146 if (!userContentController) 147 return; 148 149 const UserStyleSheetMap* userStyleSheets = userContentController->userStyleSheets(); 150 if (!userStyleSheets) 151 return; 152 153 for (auto& styleSheets : userStyleSheets->values()) { 154 for (const auto& sheet : *styleSheets) { 154 155 if (sheet->injectedFrames() == InjectInTopFrameOnly && m_document.ownerElement()) 155 156 continue; 157 156 158 if (!UserContentURLPattern::matchesPatterns(m_document.url(), sheet->whitelist(), sheet->blacklist())) 157 159 continue; 160 158 161 RefPtr<CSSStyleSheet> groupSheet = CSSStyleSheet::createInline(const_cast<Document&>(m_document), sheet->url()); 159 162 bool isUserStyleSheet = sheet->level() == UserStyleUserLevel; … … 162 165 else 163 166 m_injectedAuthorStyleSheets.append(groupSheet); 167 164 168 groupSheet->contents().setIsUserStyleSheet(isUserStyleSheet); 165 169 groupSheet->contents().parseString(sheet->source()); -
trunk/Source/WebCore/page/Frame.cpp
r162384 r162395 705 705 return; 706 706 707 UserContentController* userContentController = m_page->userContentController();707 const auto* userContentController = m_page->userContentController(); 708 708 if (!userContentController) 709 709 return; -
trunk/Source/WebCore/page/PageGroup.cpp
r162384 r162395 287 287 { 288 288 auto userStyleSheet = std::make_unique<UserStyleSheet>(source, url, whitelist, blacklist, injectedFrames, level); 289 if (!m_userStyleSheets) 290 m_userStyleSheets = std::make_unique<UserStyleSheetMap>(); 291 std::unique_ptr<UserStyleSheetVector>& styleSheetsInWorld = m_userStyleSheets->add(&world, nullptr).iterator->value; 292 if (!styleSheetsInWorld) 293 styleSheetsInWorld = std::make_unique<UserStyleSheetVector>(); 294 styleSheetsInWorld->append(std::move(userStyleSheet)); 295 296 if (injectionTime == InjectInExistingDocuments) 297 invalidateInjectedStyleSheetCacheInAllFrames(); 289 m_userContentController->addUserStyleSheet(world, std::move(userStyleSheet), injectionTime); 290 298 291 } 299 292 … … 305 298 void PageGroup::removeUserStyleSheetFromWorld(DOMWrapperWorld& world, const URL& url) 306 299 { 307 if (!m_userStyleSheets) 308 return; 309 310 auto it = m_userStyleSheets->find(&world); 311 bool sheetsChanged = false; 312 if (it == m_userStyleSheets->end()) 313 return; 314 315 auto stylesheets = it->value.get(); 316 for (int i = stylesheets->size() - 1; i >= 0; --i) { 317 if (stylesheets->at(i)->url() == url) { 318 stylesheets->remove(i); 319 sheetsChanged = true; 320 } 321 } 322 323 if (!sheetsChanged) 324 return; 325 326 if (stylesheets->isEmpty()) 327 m_userStyleSheets->remove(it); 328 329 invalidateInjectedStyleSheetCacheInAllFrames(); 300 m_userContentController->removeUserStyleSheet(world, url); 330 301 } 331 302 … … 337 308 void PageGroup::removeUserStyleSheetsFromWorld(DOMWrapperWorld& world) 338 309 { 339 if (!m_userStyleSheets) 340 return; 341 342 if (!m_userStyleSheets->remove(&world)) 343 return; 344 345 invalidateInjectedStyleSheetCacheInAllFrames(); 310 m_userContentController->removeUserStyleSheets(world); 346 311 } 347 312 … … 349 314 { 350 315 m_userContentController->removeAllUserContent(); 351 352 if (m_userStyleSheets) {353 m_userStyleSheets = nullptr;354 invalidateInjectedStyleSheetCacheInAllFrames();355 }356 }357 358 void PageGroup::invalidateInjectedStyleSheetCacheInAllFrames()359 {360 // Clear our cached sheets and have them just reparse.361 for (auto it = m_pages.begin(), end = m_pages.end(); it != end; ++it) {362 for (Frame* frame = &(*it)->mainFrame(); frame; frame = frame->tree().traverseNext()) {363 frame->document()->styleSheetCollection().invalidateInjectedStyleSheetCache();364 frame->document()->styleResolverChanged(DeferRecalcStyle);365 }366 }367 316 } 368 317 -
trunk/Source/WebCore/page/PageGroup.h
r162384 r162395 101 101 void removeAllUserContent(); 102 102 103 const UserStyleSheetMap* userStyleSheets() const { return m_userStyleSheets.get(); }104 105 103 GroupSettings& groupSettings() const { return *m_groupSettings; } 106 104 … … 112 110 private: 113 111 void addVisitedLink(LinkHash); 114 void invalidateInjectedStyleSheetCacheInAllFrames();115 112 116 113 String m_name; … … 125 122 126 123 RefPtr<UserContentController> m_userContentController; 127 std::unique_ptr<UserStyleSheetMap> m_userStyleSheets;128 124 129 125 const std::unique_ptr<GroupSettings> m_groupSettings; -
trunk/Source/WebCore/page/UserContentController.cpp
r162384 r162395 28 28 29 29 #include "DOMWrapperWorld.h" 30 #include "Document.h" 31 #include "MainFrame.h" 32 #include "Page.h" 30 33 #include "UserScript.h" 34 #include "UserStyleSheet.h" 31 35 32 36 namespace WebCore { … … 95 99 } 96 100 101 void UserContentController::addUserStyleSheet(DOMWrapperWorld& world, std::unique_ptr<UserStyleSheet> userStyleSheet, UserStyleInjectionTime injectionTime) 102 { 103 if (!m_userStyleSheets) 104 m_userStyleSheets = std::make_unique<UserStyleSheetMap>(); 105 106 auto& styleSheetsInWorld = m_userStyleSheets->add(&world, nullptr).iterator->value; 107 if (!styleSheetsInWorld) 108 styleSheetsInWorld = std::make_unique<UserStyleSheetVector>(); 109 styleSheetsInWorld->append(std::move(userStyleSheet)); 110 111 if (injectionTime == InjectInExistingDocuments) 112 invalidateInjectedStyleSheetCacheInAllFrames(); 113 } 114 115 void UserContentController::removeUserStyleSheet(DOMWrapperWorld& world, const URL& url) 116 { 117 if (!m_userStyleSheets) 118 return; 119 120 auto it = m_userStyleSheets->find(&world); 121 if (it == m_userStyleSheets->end()) 122 return; 123 124 auto& stylesheets = *it->value; 125 126 bool sheetsChanged = false; 127 for (int i = stylesheets.size() - 1; i >= 0; --i) { 128 if (stylesheets[i]->url() == url) { 129 stylesheets.remove(i); 130 sheetsChanged = true; 131 } 132 } 133 134 if (!sheetsChanged) 135 return; 136 137 if (stylesheets.isEmpty()) 138 m_userStyleSheets->remove(it); 139 140 invalidateInjectedStyleSheetCacheInAllFrames(); 141 } 142 143 void UserContentController::removeUserStyleSheets(DOMWrapperWorld& world) 144 { 145 if (!m_userStyleSheets) 146 return; 147 148 if (!m_userStyleSheets->remove(&world)) 149 return; 150 151 invalidateInjectedStyleSheetCacheInAllFrames(); 152 } 153 97 154 void UserContentController::removeAllUserContent() 98 155 { 99 156 m_userScripts = nullptr; 157 158 if (m_userStyleSheets) { 159 m_userStyleSheets = nullptr; 160 invalidateInjectedStyleSheetCacheInAllFrames(); 161 } 162 } 163 164 void UserContentController::invalidateInjectedStyleSheetCacheInAllFrames() 165 { 166 for (auto& page : m_pages) { 167 for (Frame* frame = &page->mainFrame(); frame; frame = frame->tree().traverseNext()) { 168 frame->document()->styleSheetCollection().invalidateInjectedStyleSheetCache(); 169 frame->document()->styleResolverChanged(DeferRecalcStyle); 170 } 171 } 100 172 } 101 173 -
trunk/Source/WebCore/page/UserContentController.h
r162384 r162395 28 28 29 29 #include "UserScriptTypes.h" 30 #include "UserStyleSheetTypes.h" 30 31 #include <wtf/HashSet.h> 31 32 #include <wtf/RefCounted.h> … … 38 39 class URL; 39 40 class UserScript; 41 class UserStyleSheet; 40 42 41 43 class UserContentController : public RefCounted<UserContentController> { … … 53 55 void removeUserScripts(DOMWrapperWorld&); 54 56 57 const UserStyleSheetMap* userStyleSheets() const { return m_userStyleSheets.get(); } 58 59 void addUserStyleSheet(DOMWrapperWorld&, std::unique_ptr<UserStyleSheet>, UserStyleInjectionTime); 60 void removeUserStyleSheet(DOMWrapperWorld&, const URL&); 61 void removeUserStyleSheets(DOMWrapperWorld&); 62 55 63 void removeAllUserContent(); 56 64 … … 58 66 UserContentController(); 59 67 68 void invalidateInjectedStyleSheetCacheInAllFrames(); 69 60 70 HashSet<Page*> m_pages; 61 71 62 72 std::unique_ptr<UserScriptMap> m_userScripts; 73 std::unique_ptr<UserStyleSheetMap> m_userStyleSheets; 63 74 }; 64 75
Note: See TracChangeset
for help on using the changeset viewer.