Changeset 162384 in webkit
- Timestamp:
- Jan 20, 2014 4:08:55 PM (10 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r162380 r162384 1 2014-01-20 Anders Carlsson <andersca@apple.com> 2 3 UserContentController should keep track of user scripts 4 https://bugs.webkit.org/show_bug.cgi?id=127317 5 <rdar://problem/15861296> 6 7 Reviewed by Andreas Kling. 8 9 Move handling of user scripts from PageGroup to UserContentController. 10 11 * page/Frame.cpp: 12 (WebCore::Frame::injectUserScripts): 13 * page/PageGroup.cpp: 14 (WebCore::PageGroup::addUserScriptToWorld): 15 (WebCore::PageGroup::removeUserScriptFromWorld): 16 (WebCore::PageGroup::removeUserScriptsFromWorld): 17 (WebCore::PageGroup::removeAllUserContent): 18 * page/PageGroup.h: 19 * page/UserContentController.cpp: 20 (WebCore::UserContentController::addUserScript): 21 (WebCore::UserContentController::removeUserScript): 22 (WebCore::UserContentController::removeUserScripts): 23 (WebCore::UserContentController::removeAllUserContent): 24 * page/UserContentController.h: 25 (WebCore::UserContentController::userScripts): 26 1 27 2014-01-20 Anders Carlsson <andersca@apple.com> 2 28 3 29 Give each page a UserContentController 4 30 https://bugs.webkit.org/show_bug.cgi?id=127315 31 <rdar://problem/15861296> 5 32 6 33 Reviewed by Andreas Kling. -
trunk/Source/WebCore/page/Frame.cpp
r161703 r162384 93 93 #include "TextNodeTraversal.h" 94 94 #include "TextResourceDecoder.h" 95 #include "UserContentController.h" 95 96 #include "UserContentURLPattern.h" 96 97 #include "UserTypingGestureIndicator.h" … … 704 705 return; 705 706 707 UserContentController* userContentController = m_page->userContentController(); 708 if (!userContentController) 709 return; 710 706 711 // Walk the hashtable. Inject by world. 707 const UserScriptMap* userScripts = m_page->group().userScripts();712 const UserScriptMap* userScripts = userContentController->userScripts(); 708 713 if (!userScripts) 709 714 return; 710 715 711 for ( auto it = userScripts->begin(), end = userScripts->end(); it != end; ++it)712 injectUserScriptsForWorld(* it->key.get(), *it->value, injectionTime);716 for (const auto& worldAndUserScript : *userScripts) 717 injectUserScriptsForWorld(*worldAndUserScript.key, *worldAndUserScript.value, injectionTime); 713 718 } 714 719 -
trunk/Source/WebCore/page/PageGroup.cpp
r162380 r162384 74 74 : m_visitedLinksPopulated(false) 75 75 , m_identifier(getUniqueIdentifier()) 76 , m_userContentController(UserContentController::create()) 76 77 , m_groupSettings(std::make_unique<GroupSettings>()) 77 78 { … … 280 281 { 281 282 auto userScript = std::make_unique<UserScript>(source, url, whitelist, blacklist, injectionTime, injectedFrames); 282 if (!m_userScripts) 283 m_userScripts = std::make_unique<UserScriptMap>(); 284 std::unique_ptr<UserScriptVector>& scriptsInWorld = m_userScripts->add(&world, nullptr).iterator->value; 285 if (!scriptsInWorld) 286 scriptsInWorld = std::make_unique<UserScriptVector>(); 287 scriptsInWorld->append(std::move(userScript)); 283 m_userContentController->addUserScript(world, std::move(userScript)); 288 284 } 289 285 … … 304 300 void PageGroup::removeUserScriptFromWorld(DOMWrapperWorld& world, const URL& url) 305 301 { 306 if (!m_userScripts) 307 return; 308 309 auto it = m_userScripts->find(&world); 310 if (it == m_userScripts->end()) 311 return; 312 313 auto scripts = it->value.get(); 314 for (int i = scripts->size() - 1; i >= 0; --i) { 315 if (scripts->at(i)->url() == url) 316 scripts->remove(i); 317 } 318 319 if (scripts->isEmpty()) 320 m_userScripts->remove(it); 302 m_userContentController->removeUserScript(world, url); 321 303 } 322 304 … … 350 332 void PageGroup::removeUserScriptsFromWorld(DOMWrapperWorld& world) 351 333 { 352 if (!m_userScripts) 353 return; 354 355 m_userScripts->remove(&world); 334 m_userContentController->removeUserScripts(world); 356 335 } 357 336 … … 369 348 void PageGroup::removeAllUserContent() 370 349 { 371 m_user Scripts = nullptr;350 m_userContentController->removeAllUserContent(); 372 351 373 352 if (m_userStyleSheets) { -
trunk/Source/WebCore/page/PageGroup.h
r162380 r162384 95 95 void addUserScriptToWorld(DOMWrapperWorld&, const String& source, const URL&, const Vector<String>& whitelist, const Vector<String>& blacklist, UserScriptInjectionTime, UserContentInjectedFrames); 96 96 void addUserStyleSheetToWorld(DOMWrapperWorld&, const String& source, const URL&, const Vector<String>& whitelist, const Vector<String>& blacklist, UserContentInjectedFrames, UserStyleLevel = UserStyleUserLevel, UserStyleInjectionTime = InjectInExistingDocuments); 97 void removeUserStyleSheetFromWorld(DOMWrapperWorld&, const URL&); 97 98 void removeUserScriptFromWorld(DOMWrapperWorld&, const URL&); 98 void removeUserStyleSheetFromWorld(DOMWrapperWorld&, const URL&);99 99 void removeUserScriptsFromWorld(DOMWrapperWorld&); 100 100 void removeUserStyleSheetsFromWorld(DOMWrapperWorld&); 101 101 void removeAllUserContent(); 102 102 103 const UserScriptMap* userScripts() const { return m_userScripts.get(); }104 103 const UserStyleSheetMap* userStyleSheets() const { return m_userStyleSheets.get(); } 105 104 … … 126 125 127 126 RefPtr<UserContentController> m_userContentController; 128 std::unique_ptr<UserScriptMap> m_userScripts;129 127 std::unique_ptr<UserStyleSheetMap> m_userStyleSheets; 130 128 -
trunk/Source/WebCore/page/UserContentController.cpp
r162380 r162384 57 57 } 58 58 59 void UserContentController::addUserScript(DOMWrapperWorld& world, std::unique_ptr<UserScript> userScript) 60 { 61 if (!m_userScripts) 62 m_userScripts = std::make_unique<UserScriptMap>(); 63 64 auto& scriptsInWorld = m_userScripts->add(&world, nullptr).iterator->value; 65 if (!scriptsInWorld) 66 scriptsInWorld = std::make_unique<UserScriptVector>(); 67 scriptsInWorld->append(std::move(userScript)); 68 } 69 70 void UserContentController::removeUserScript(DOMWrapperWorld& world, const URL& url) 71 { 72 if (!m_userScripts) 73 return; 74 75 auto it = m_userScripts->find(&world); 76 if (it == m_userScripts->end()) 77 return; 78 79 auto scripts = it->value.get(); 80 for (int i = scripts->size() - 1; i >= 0; --i) { 81 if (scripts->at(i)->url() == url) 82 scripts->remove(i); 83 } 84 85 if (scripts->isEmpty()) 86 m_userScripts->remove(it); 87 } 88 89 void UserContentController::removeUserScripts(DOMWrapperWorld& world) 90 { 91 if (!m_userScripts) 92 return; 93 94 m_userScripts->remove(&world); 95 } 96 97 void UserContentController::removeAllUserContent() 98 { 99 m_userScripts = nullptr; 100 } 101 59 102 } // namespace WebCore -
trunk/Source/WebCore/page/UserContentController.h
r162380 r162384 27 27 #define UserContentController_h 28 28 29 #include <wtf/HashMap.h>29 #include "UserScriptTypes.h" 30 30 #include <wtf/HashSet.h> 31 31 #include <wtf/RefCounted.h> 32 32 #include <wtf/RefPtr.h> 33 #include <wtf/Vector.h>34 33 35 34 namespace WebCore { … … 48 47 void removePage(Page&); 49 48 49 const UserScriptMap* userScripts() const { return m_userScripts.get(); } 50 51 void addUserScript(DOMWrapperWorld&, std::unique_ptr<UserScript>); 52 void removeUserScript(DOMWrapperWorld&, const URL&); 53 void removeUserScripts(DOMWrapperWorld&); 54 55 void removeAllUserContent(); 56 50 57 private: 51 58 UserContentController(); 52 59 53 60 HashSet<Page*> m_pages; 61 62 std::unique_ptr<UserScriptMap> m_userScripts; 54 63 }; 55 64
Note: See TracChangeset
for help on using the changeset viewer.