Changeset 194386 in webkit
- Timestamp:
- Dec 23, 2015 2:04:44 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r194366 r194386 1 2015-12-23 Chris Aljoudi <chris@chrismatic.io> and Alex Christensen <achristensen@webkit.org> 2 3 Content blockers should be able to promote http to https 4 https://bugs.webkit.org/show_bug.cgi?id=148966 5 6 Reviewed by Benjamin Poulain. 7 8 * http/tests/contentextensions/make-https-expected.txt: Added. 9 * http/tests/contentextensions/make-https.html: Added. 10 * http/tests/contentextensions/make-https.html.json: Added. 11 1 12 2015-12-22 Xabier Rodriguez Calvar <calvaris@igalia.com> 2 13 -
trunk/Source/WebCore/ChangeLog
r194380 r194386 1 2015-12-23 Chris Aljoudi <chris@chrismatic.io> and Alex Christensen <achristensen@webkit.org> 2 3 Content blockers should be able to promote http to https 4 https://bugs.webkit.org/show_bug.cgi?id=148966 5 6 Reviewed by Benjamin Poulain. 7 8 Test: http/tests/contentextensions/make-https.html 9 10 * contentextensions/ContentExtensionActions.h: 11 * contentextensions/ContentExtensionCompiler.cpp: 12 (WebCore::ContentExtensions::serializeActions): 13 * contentextensions/ContentExtensionParser.cpp: 14 (WebCore::ContentExtensions::loadAction): 15 * contentextensions/ContentExtensionRule.cpp: 16 (WebCore::ContentExtensions::Action::deserialize): 17 (WebCore::ContentExtensions::Action::deserializeType): 18 (WebCore::ContentExtensions::Action::serializedLength): 19 * contentextensions/ContentExtensionsBackend.cpp: 20 (WebCore::ContentExtensions::ContentExtensionsBackend::processContentExtensionRulesForLoad): 21 * loader/cache/CachedResourceLoader.cpp: 22 (WebCore::CachedResourceLoader::requestResource): 23 * platform/URL.cpp: 24 (WebCore::URL::isBlankURL): 25 (WebCore::defaultPortsMap): 26 (WebCore::defaultPortForProtocol): 27 (WebCore::isDefaultPortForProtocol): 28 (WebCore::portAllowed): 29 * platform/URL.h: 30 1 31 2015-12-22 Andy Estes <aestes@apple.com> 2 32 -
trunk/Source/WebCore/contentextensions/ContentExtensionActions.h
r190611 r194386 41 41 CSSDisplayNoneStyleSheet, 42 42 IgnorePreviousRules, 43 MakeHTTPS, 43 44 InvalidAction, 44 45 }; -
trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.cpp
r187049 r194386 103 103 Vector<unsigned> actionLocations; 104 104 105 // Block and BlockCookies do not need to be distinguishable. The order in which they are executed it irrelevant 106 // since Block is a strict superset of BlockCookies. 107 // Similarily, Block is a superset of CSSDisplayNone, and BlockCookies is independent from CSSDisplayNone. 108 // 109 // The only distinguisher is "IgnorePreviousRules". 110 // 111 // The trigger's Flags do not need to be distinguishable either. The way we use them is filtering the actions 112 // based on the flag *after* matching. 113 // 114 // To reduce the number of unique actions, we keep track of the various action, indexed by their flag. 115 // We only need to create new ones when encountering a IgnorePreviousRules. 116 HashMap<uint32_t, uint32_t, DefaultHash<uint32_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<uint32_t>> blockActionsMap; 117 HashMap<uint32_t, uint32_t, DefaultHash<uint32_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<uint32_t>> blockCookiesActionsMap; 105 // Order only matters because of IgnorePreviousRules. All other identical actions can be combined between each IgnorePreviousRules 106 // and CSSDisplayNone strings can be combined if their triggers are identical. 107 typedef HashMap<uint32_t, uint32_t, DefaultHash<uint32_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<uint32_t>> ActionMap; 108 ActionMap blockLoadActionsMap; 109 ActionMap blockCookiesActionsMap; 118 110 PendingDisplayNoneActionsMap cssDisplayNoneActionsMap; 119 HashMap<uint32_t, uint32_t, DefaultHash<uint32_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<uint32_t>> ignorePreviousRuleActionsMap; 111 ActionMap ignorePreviousRuleActionsMap; 112 ActionMap makeHTTPSActionsMap; 120 113 121 114 for (unsigned ruleIndex = 0; ruleIndex < ruleList.size(); ++ruleIndex) { … … 123 116 ActionType actionType = rule.action().type(); 124 117 125 RELEASE_ASSERT(actionType == ActionType::CSSDisplayNoneSelector126 || actionType == ActionType::BlockLoad127 || actionType == ActionType::BlockCookies128 || actionType == ActionType::IgnorePreviousRules);129 130 118 if (actionType == ActionType::IgnorePreviousRules) { 131 119 resolvePendingDisplayNoneActions(actions, actionLocations, cssDisplayNoneActionsMap); 132 120 133 block ActionsMap.clear();121 blockLoadActionsMap.clear(); 134 122 blockCookiesActionsMap.clear(); 135 123 cssDisplayNoneActionsMap.clear(); 124 makeHTTPSActionsMap.clear(); 136 125 } else 137 126 ignorePreviousRuleActionsMap.clear(); … … 151 140 ResourceFlags flags = rule.trigger().flags; 152 141 unsigned actionLocation = std::numeric_limits<unsigned>::max(); 142 143 auto findOrMakeActionLocation = [&] (ActionMap& map) 144 { 145 const auto existingAction = map.find(flags); 146 if (existingAction == map.end()) { 147 actionLocation = actions.size(); 148 actions.append(static_cast<SerializedActionByte>(actionType)); 149 map.set(flags, actionLocation); 150 } else 151 actionLocation = existingAction->value; 152 }; 153 153 154 154 switch (actionType) { … … 157 157 RELEASE_ASSERT_NOT_REACHED(); 158 158 159 case ActionType::IgnorePreviousRules: {160 const auto existingAction = ignorePreviousRuleActionsMap.find(flags);161 if (existingAction == ignorePreviousRuleActionsMap.end()) {162 actionLocation = actions.size();163 actions.append(static_cast<SerializedActionByte>(rule.action().type()));164 ignorePreviousRuleActionsMap.set(flags, actionLocation);165 } else166 actionLocation = existingAction->value;167 break;168 }169 159 case ActionType::CSSDisplayNoneSelector: { 170 160 const auto addResult = cssDisplayNoneActionsMap.add(rule.trigger(), PendingDisplayNoneActions()); … … 176 166 break; 177 167 } 178 case ActionType::BlockLoad: { 179 const auto existingAction = blockActionsMap.find(flags); 180 if (existingAction == blockActionsMap.end()) { 181 actionLocation = actions.size(); 182 actions.append(static_cast<SerializedActionByte>(rule.action().type())); 183 blockActionsMap.set(flags, actionLocation); 184 } else 185 actionLocation = existingAction->value; 168 case ActionType::IgnorePreviousRules: 169 findOrMakeActionLocation(ignorePreviousRuleActionsMap); 186 170 break; 187 } 188 case ActionType::BlockCookies: { 189 const auto existingAction = blockCookiesActionsMap.find(flags); 190 if (existingAction == blockCookiesActionsMap.end()) { 191 actionLocation = actions.size(); 192 actions.append(static_cast<SerializedActionByte>(rule.action().type())); 193 blockCookiesActionsMap.set(flags, actionLocation); 194 } else 195 actionLocation = existingAction->value; 171 case ActionType::BlockLoad: 172 findOrMakeActionLocation(blockLoadActionsMap); 196 173 break; 197 } 174 case ActionType::BlockCookies: 175 findOrMakeActionLocation(blockCookiesActionsMap); 176 break; 177 case ActionType::MakeHTTPS: 178 findOrMakeActionLocation(makeHTTPSActionsMap); 179 break; 198 180 } 199 181 -
trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp
r190602 r194386 217 217 } 218 218 action = Action(ActionType::CSSDisplayNoneSelector, s); 219 } else if (actionType == "make-https") { 220 action = ActionType::MakeHTTPS; 219 221 } else 220 222 return ContentExtensionError::JSONInvalidActionType; -
trunk/Source/WebCore/contentextensions/ContentExtensionRule.cpp
r187049 r194386 50 50 case ActionType::IgnorePreviousRules: 51 51 return Action(ActionType::IgnorePreviousRules, location); 52 case ActionType::MakeHTTPS: 53 return Action(ActionType::MakeHTTPS, location); 52 54 case ActionType::CSSDisplayNoneSelector: { 53 55 uint32_t headerLength = sizeof(ActionType) + sizeof(uint32_t) + sizeof(bool); … … 80 82 case ActionType::IgnorePreviousRules: 81 83 case ActionType::CSSDisplayNoneSelector: 84 case ActionType::MakeHTTPS: 82 85 return type; 83 86 case ActionType::CSSDisplayNoneStyleSheet: … … 95 98 case ActionType::BlockLoad: 96 99 case ActionType::IgnorePreviousRules: 100 case ActionType::MakeHTTPS: 97 101 return sizeof(ActionType); 98 102 case ActionType::CSSDisplayNoneSelector: { -
trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp
r190611 r194386 37 37 #include "ExtensionStyleSheets.h" 38 38 #include "Frame.h" 39 #include "FrameLoaderClient.h" 39 40 #include "MainFrame.h" 40 41 #include "ResourceLoadInfo.h" … … 190 191 break; 191 192 } 193 case ContentExtensions::ActionType::MakeHTTPS: { 194 const URL originalURL = request.url(); 195 if (originalURL.protocolIs("http") && (!originalURL.hasPort() || isDefaultPortForProtocol(originalURL.port(), originalURL.protocol()))) { 196 URL newURL = originalURL; 197 newURL.setProtocol("https"); 198 if (originalURL.hasPort()) 199 newURL.setPort(defaultPortForProtocol("https")); 200 request.setURL(newURL); 201 202 if (resourceType == ResourceType::Document && initiatingDocumentLoader.isLoadingMainResource()) { 203 // This is to make sure the correct 'new' URL shows in the location bar. 204 initiatingDocumentLoader.request().setURL(newURL); 205 initiatingDocumentLoader.frameLoader()->client().dispatchDidChangeProvisionalURL(); 206 } 207 if (currentDocument) 208 currentDocument->addConsoleMessage(MessageSource::ContentBlocker, MessageLevel::Info, makeString("Content blocker promoted URL from ", originalURL.string(), " to ", newURL.string())); 209 } 210 break; 211 } 192 212 case ContentExtensions::ActionType::IgnorePreviousRules: 193 213 case ContentExtensions::ActionType::InvalidAction: -
trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp
r194209 r194386 550 550 return nullptr; 551 551 } 552 url = request.resourceRequest().url(); // The content extension could have changed it from http to https. 553 url = MemoryCache::removeFragmentIdentifierIfNeeded(url); // Might need to remove fragment identifier again. 552 554 } 553 555 #endif -
trunk/Source/WebCore/platform/URL.cpp
r192100 r194386 36 36 #include <wtf/HashMap.h> 37 37 #include <wtf/HexNumber.h> 38 #include <wtf/NeverDestroyed.h> 38 39 #include <wtf/StdLibExtras.h> 39 40 #include <wtf/text/CString.h> … … 1990 1991 } 1991 1992 1993 typedef HashMap<String, unsigned short, CaseFoldingHash> DefaultPortsMap; 1994 static const DefaultPortsMap& defaultPortsMap() 1995 { 1996 static NeverDestroyed<const DefaultPortsMap> defaultPortsMap(DefaultPortsMap({ 1997 { "http", 80 }, 1998 { "https", 443 }, 1999 { "ftp", 21 }, 2000 { "ftps", 990 } 2001 })); 2002 return defaultPortsMap.get(); 2003 } 2004 unsigned short defaultPortForProtocol(const String& protocol) 2005 { 2006 return defaultPortsMap().get(protocol); 2007 } 2008 1992 2009 bool isDefaultPortForProtocol(unsigned short port, const String& protocol) 1993 2010 { … … 1995 2012 return false; 1996 2013 1997 typedef HashMap<String, unsigned, CaseFoldingHash> DefaultPortsMap; 1998 DEPRECATED_DEFINE_STATIC_LOCAL(DefaultPortsMap, defaultPorts, ()); 1999 if (defaultPorts.isEmpty()) { 2000 defaultPorts.set("http", 80); 2001 defaultPorts.set("https", 443); 2002 defaultPorts.set("ftp", 21); 2003 defaultPorts.set("ftps", 990); 2004 } 2005 return defaultPorts.get(protocol) == port; 2014 return defaultPortForProtocol(protocol) == port; 2006 2015 } 2007 2016 -
trunk/Source/WebCore/platform/URL.h
r191487 r194386 247 247 WEBCORE_EXPORT bool protocolIsInHTTPFamily(const String& url); 248 248 249 unsigned short defaultPortForProtocol(const String& protocol); 249 250 bool isDefaultPortForProtocol(unsigned short port, const String& protocol); 250 251 bool portAllowed(const URL&); // Blacklist ports that should never be used for Web resources. -
trunk/Tools/ChangeLog
r194381 r194386 1 2015-12-23 Chris Aljoudi <chris@chrismatic.io> and Alex Christensen <achristensen@webkit.org> 2 3 Content blockers should be able to promote http to https 4 https://bugs.webkit.org/show_bug.cgi?id=148966 5 6 Reviewed by Benjamin Poulain. 7 8 * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp: 9 (WebCore::ContentExtensions::operator<<): 10 (TestWebKitAPI::TEST_F): 11 1 12 2015-12-22 Hunseop Jeong <hs85.jeong@samsung.com> 2 13 -
trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp
r186965 r194386 51 51 switch (action) { 52 52 case ActionType::BlockLoad: 53 return os << " ContentFilterAction::BlockLoad";53 return os << "ActionType::BlockLoad"; 54 54 case ActionType::BlockCookies: 55 return os << " ContentFilterAction::BlockCookies";55 return os << "ActionType::BlockCookies"; 56 56 case ActionType::CSSDisplayNoneSelector: 57 return os << " ContentFilterAction::CSSDisplayNone";57 return os << "ActionType::CSSDisplayNone"; 58 58 case ActionType::CSSDisplayNoneStyleSheet: 59 return os << " ContentFilterAction::CSSDisplayNoneStyleSheet";59 return os << "ActionType::CSSDisplayNoneStyleSheet"; 60 60 case ActionType::IgnorePreviousRules: 61 return os << "ContentFilterAction::IgnorePreviousRules"; 61 return os << "ActionType::IgnorePreviousRules"; 62 case ActionType::MakeHTTPS: 63 return os << "ActionType::MakeHTTPS"; 62 64 case ActionType::InvalidAction: 63 return os << " ContentFilterAction::InvalidAction";65 return os << "ActionType::InvalidAction"; 64 66 } 65 67 } … … 1439 1441 auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"A*D\"}}," 1440 1442 "{\"action\":{\"type\":\"ignore-previous-rules\"},\"trigger\":{\"url-filter\":\"A*BA+\"}}," 1441 "{\"action\":{\"type\":\" block-cookies\"},\"trigger\":{\"url-filter\":\"A*BC\"}}]");1443 "{\"action\":{\"type\":\"make-https\"},\"trigger\":{\"url-filter\":\"A*BC\"}}]"); 1442 1444 1443 1445 testRequest(backend, mainDocumentRequest("http://webkit.org/D"), { ContentExtensions::ActionType::BlockLoad }); … … 1446 1448 testRequest(backend, mainDocumentRequest("http://webkit.org/ABA"), { }, true); 1447 1449 testRequest(backend, mainDocumentRequest("http://webkit.org/ABAD"), { }, true); 1448 testRequest(backend, mainDocumentRequest("http://webkit.org/BC"), { ContentExtensions::ActionType:: BlockCookies});1449 testRequest(backend, mainDocumentRequest("http://webkit.org/ABC"), { ContentExtensions::ActionType:: BlockCookies});1450 testRequest(backend, mainDocumentRequest("http://webkit.org/ABABC"), { ContentExtensions::ActionType:: BlockCookies}, true);1451 testRequest(backend, mainDocumentRequest("http://webkit.org/ABABCAD"), { ContentExtensions::ActionType:: BlockCookies}, true);1452 testRequest(backend, mainDocumentRequest("http://webkit.org/ABCAD"), { ContentExtensions::ActionType:: BlockCookies, ContentExtensions::ActionType::BlockLoad });1450 testRequest(backend, mainDocumentRequest("http://webkit.org/BC"), { ContentExtensions::ActionType::MakeHTTPS }); 1451 testRequest(backend, mainDocumentRequest("http://webkit.org/ABC"), { ContentExtensions::ActionType::MakeHTTPS }); 1452 testRequest(backend, mainDocumentRequest("http://webkit.org/ABABC"), { ContentExtensions::ActionType::MakeHTTPS }, true); 1453 testRequest(backend, mainDocumentRequest("http://webkit.org/ABABCAD"), { ContentExtensions::ActionType::MakeHTTPS }, true); 1454 testRequest(backend, mainDocumentRequest("http://webkit.org/ABCAD"), { ContentExtensions::ActionType::MakeHTTPS, ContentExtensions::ActionType::BlockLoad }); 1453 1455 } 1454 1456
Note: See TracChangeset
for help on using the changeset viewer.