Changeset 195650 in webkit
- Timestamp:
- Jan 26, 2016 7:05:49 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r195644 r195650 1 2016-01-26 I-Ting Liu <iting_liu@apple.com> 2 3 Implement wildcard matching for plug-in policy host. 4 https://bugs.webkit.org/show_bug.cgi?id=153090 5 6 Reviewed by Darin Adler. 7 8 * wtf/text/AtomicString.h: 9 (WTF::AtomicString::AtomicString): 10 Add __bridge to allow compilation. 11 1 12 2016-01-26 Joseph Pecoraro <pecoraro@apple.com> 2 13 -
trunk/Source/WTF/wtf/text/AtomicString.h
r195501 r195650 298 298 #ifdef __OBJC__ 299 299 inline AtomicString::AtomicString(NSString* s) 300 : m_string(AtomicStringImpl::add(( CFStringRef)s))300 : m_string(AtomicStringImpl::add((__bridge CFStringRef)s)) 301 301 { 302 302 } -
trunk/Source/WebKit2/ChangeLog
r195647 r195650 1 2016-01-26 I-Ting Liu <iting_liu@apple.com> 2 3 Implement wildcard matching for plug-in policy host. 4 https://bugs.webkit.org/show_bug.cgi?id=153090 5 6 Reviewed by Darin Adler. 7 8 WebPlatformStrategies decides the plug-in load policy for a host by looking 9 for a matched hostname in the list of plug-in policies sent by Safari. This 10 patch adds support for wildcard matching -- if there's a policy with hostname 11 "*.example.com," the policy for "foo.example.com" would be replaced with that 12 of "*.example.com" if there's no policy for this hostname. If there is more 13 than one wildcard hostname, the host with the longest wildcard hostname will 14 be used. 15 16 This patch adds a helper function in StringUtilites that matches a string to 17 another string, which may contain wildcard ('*') characters. 18 19 * Platform/mac/StringUtilities.h: 20 - Add WebKit::stringMatchesWildcardString. 21 - Remove #if ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC) flag so that 22 the compiler allows exposing StringUtilities.h. 23 - Add #if __OBJC__ to allow the file to be included in WebPltformStrategies.cpp 24 25 * Platform/mac/StringUtilities.mm: 26 (WebKit::stringMatchesWildcardString): 27 Return true if the entire first given String matches the second. The second string 28 may contain wildcard characters. 29 (WebKit::wildcardRegexPatternString): 30 Return the regex expression from a wildcard string by replacing the wildcard 31 character ('*') with (".*") and escaping regular expression metacharacters. 32 (WebKit::formattedPhoneNumberString): 33 To expose StringUtilities.h for tests, we removed #if ENABLE(TELEPHONE_NUMBER_DETECTION) 34 && PLATFORM(MAC) flag in the header. Add a function that returns nil for 35 #if !(ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)) to fix the removal 36 of the flag in the header file. 37 38 * WebKit2.xcodeproj/project.pbxproj: 39 Change the file attribute of StringUtilities.h from Project to Private for 40 testing in TestWebKitAPI. 41 42 * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp: 43 (WebKit::WebPlatformStrategies::longestMatchedWildcardHostForHost): 44 Return the wildcard hostname whose matched substring with the host is the longest. 45 (WebKit::WebPlatformStrategies::replaceHostWithMatchedWildcardHost): 46 Replace the look-up host with a matched wildcard host if there is a match and that 47 the matched wildcard host's plug-in identifier is the same as that of the host. 48 (WebKit::WebPlatformStrategies::pluginLoadClientPolicyForHost): 49 Try to replace the look-up host with the wildcard host if there's no policy for 50 the host. Restructure the function to reduce hashmap lookup. 51 52 * WebProcess/WebCoreSupport/WebPlatformStrategies.h: 53 Declare the methods. 54 1 55 2016-01-26 Anders Carlsson <andersca@apple.com> 2 56 -
trunk/Source/WebKit2/Platform/mac/StringUtilities.h
r194318 r195650 27 27 #define StringUtilities_h 28 28 29 #import <WebKit/WKDeclarationSpecifiers.h> 29 30 #import <wtf/Forward.h> 30 31 31 32 namespace WebKit { 32 33 34 #ifdef __OBJC__ 35 33 36 // NOTE: This does not use String::operator NSString*() since that function 34 37 // expects to be called on the thread running WebCore. 35 38 NSString *nsStringFromWebCoreString(const String&); 39 NSString *formattedPhoneNumberString(NSString *originalPhoneNumber); 36 40 37 # if ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)38 NSString *formattedPhoneNumberString(NSString *originalPhoneNumber); 39 #endif 41 #endif // defined(__OBJC__) 42 43 WK_EXPORT bool stringMatchesWildcardString(const String& stringToBeMatched, const String& wildcardString); 40 44 41 45 } -
trunk/Source/WebKit2/Platform/mac/StringUtilities.mm
r194318 r195650 31 31 #import <WebCore/SoftLinking.h> 32 32 #import <wtf/ObjcRuntimeExtras.h> 33 #import <wtf/text/WTFString.h> 33 #import <wtf/text/StringBuilder.h> 34 #import <yarr/RegularExpression.h> 34 35 35 36 namespace WebKit { … … 38 39 { 39 40 return string.isEmpty() ? @"" : CFBridgingRelease(WKStringCopyCFString(0, toAPI(string.impl()))); 41 } 42 43 static String wildcardRegexPatternString(const String& string) 44 { 45 String metaCharacters = ".|+?()[]{}^$"; 46 UChar escapeCharacter = '\\'; 47 UChar wildcardCharacter = '*'; 48 49 StringBuilder stringBuilder; 50 51 stringBuilder.append('^'); 52 for (unsigned i = 0; i < string.length(); i++) { 53 auto character = string[i]; 54 if (metaCharacters.contains(character) || character == escapeCharacter) 55 stringBuilder.append(escapeCharacter); 56 else if (character == wildcardCharacter) 57 stringBuilder.append('.'); 58 59 stringBuilder.append(character); 60 } 61 stringBuilder.append('$'); 62 63 return stringBuilder.toString(); 64 } 65 66 bool stringMatchesWildcardString(const String& string, const String& wildcardString) 67 { 68 return JSC::Yarr::RegularExpression(wildcardRegexPatternString(wildcardString), TextCaseInsensitive).match(string) != -1; 40 69 } 41 70 … … 73 102 } 74 103 104 #else 105 106 NSString *formattedPhoneNumberString(NSString *) 107 { 108 return nil; 109 } 110 75 111 #endif // ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC) 76 112 -
trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
r195647 r195650 580 580 293EBEAC1627D9C9005F89F1 /* WKDOMText.mm in Sources */ = {isa = PBXBuildFile; fileRef = 293EBEAA1627D9C9005F89F1 /* WKDOMText.mm */; }; 581 581 29501724162A4504004A9D71 /* WKWebProcessPlugInBrowserContextControllerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 29501723162A4504004A9D71 /* WKWebProcessPlugInBrowserContextControllerPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; }; 582 296BD85D15019BC30071F424 /* StringUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 296BD85B15019BC30071F424 /* StringUtilities.h */; };582 296BD85D15019BC30071F424 /* StringUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 296BD85B15019BC30071F424 /* StringUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; }; 583 583 296BD85E15019BC30071F424 /* StringUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = 296BD85C15019BC30071F424 /* StringUtilities.mm */; }; 584 584 2984F57C164B915F004BC0C6 /* CustomProtocolManagerProxyMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2984F57A164B915F004BC0C6 /* CustomProtocolManagerProxyMessageReceiver.cpp */; }; -
trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp
r194367 r195650 68 68 #include <wtf/Atomics.h> 69 69 70 #if PLATFORM(MAC) 71 #include "StringUtilities.h" 72 #endif 73 70 74 using namespace WebCore; 71 75 … … 240 244 #if ENABLE(NETSCAPE_PLUGIN_API) 241 245 #if PLATFORM(MAC) 246 247 String WebPlatformStrategies::longestMatchedWildcardHostForHost(const String& host) const 248 { 249 String longestMatchedHost; 250 251 for (auto& key : m_hostsToPluginIdentifierData.keys()) { 252 if (key.contains('*') && key != "*" && stringMatchesWildcardString(host, key)) { 253 if (key.length() > longestMatchedHost.length()) 254 longestMatchedHost = key; 255 else if (key.length() == longestMatchedHost.length() && codePointCompareLessThan(key, longestMatchedHost)) 256 longestMatchedHost = key; 257 } 258 } 259 260 return longestMatchedHost; 261 } 262 263 bool WebPlatformStrategies::replaceHostWithMatchedWildcardHost(String& host, const String& identifier) const 264 { 265 String matchedWildcardHost = longestMatchedWildcardHostForHost(host); 266 267 if (matchedWildcardHost.isNull()) 268 return false; 269 270 auto plugInIdentifierData = m_hostsToPluginIdentifierData.find(matchedWildcardHost); 271 if (plugInIdentifierData == m_hostsToPluginIdentifierData.end() || !plugInIdentifierData->value.contains(identifier)) 272 return false; 273 274 host = matchedWildcardHost; 275 return true; 276 } 277 242 278 bool WebPlatformStrategies::pluginLoadClientPolicyForHost(const String& host, const PluginInfo& info, PluginLoadClientPolicy& policy) const 243 279 { 244 280 String hostToLookUp = host; 245 if (!m_hostsToPluginIdentifierData.contains(hostToLookUp))246 hostToLookUp = "*";247 if (!m_hostsToPluginIdentifierData.contains(hostToLookUp))248 return false;249 250 PluginPolicyMapsByIdentifier policiesByIdentifier = m_hostsToPluginIdentifierData.get(hostToLookUp);251 281 String identifier = info.bundleIdentifier; 252 if (!identifier || !policiesByIdentifier.contains(identifier)) 282 283 auto policiesByIdentifierIterator = m_hostsToPluginIdentifierData.find(hostToLookUp); 284 285 if (!identifier.isNull() && policiesByIdentifierIterator == m_hostsToPluginIdentifierData.end()) { 286 if (!replaceHostWithMatchedWildcardHost(hostToLookUp, identifier)) 287 hostToLookUp = "*"; 288 policiesByIdentifierIterator = m_hostsToPluginIdentifierData.find(hostToLookUp); 289 if (hostToLookUp != "*" && policiesByIdentifierIterator == m_hostsToPluginIdentifierData.end()) { 290 hostToLookUp = "*"; 291 policiesByIdentifierIterator = m_hostsToPluginIdentifierData.find(hostToLookUp); 292 } 293 } 294 if (policiesByIdentifierIterator == m_hostsToPluginIdentifierData.end()) 295 return false; 296 297 auto& policiesByIdentifier = policiesByIdentifierIterator->value; 298 299 if (!identifier) 253 300 identifier = "*"; 254 if (!policiesByIdentifier.contains(identifier)) 255 return false; 256 257 PluginLoadClientPoliciesByBundleVersion versionsToPolicies = policiesByIdentifier.get(identifier); 301 302 auto identifierPolicyIterator = policiesByIdentifier.find(identifier); 303 if (identifier != "*" && identifierPolicyIterator == policiesByIdentifier.end()) { 304 identifier = "*"; 305 identifierPolicyIterator = policiesByIdentifier.find(identifier); 306 } 307 if (identifierPolicyIterator == policiesByIdentifier.end()) 308 return false; 309 310 auto& versionsToPolicies = identifierPolicyIterator->value; 311 258 312 String version = info.versionString; 259 if (!version || !versionsToPolicies.contains(version))313 if (!version) 260 314 version = "*"; 261 if (!versionsToPolicies.contains(version)) 262 return false; 263 264 policy = versionsToPolicies.get(version); 315 auto policyIterator = versionsToPolicies.find(version); 316 if (version != "*" && policyIterator == versionsToPolicies.end()) { 317 version = "*"; 318 policyIterator = versionsToPolicies.find(version); 319 } 320 321 if (policyIterator == versionsToPolicies.end()) 322 return false; 323 324 policy = policyIterator->value; 265 325 return true; 266 326 } -
trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h
r192995 r195650 113 113 HashMap<String, PluginPolicyMapsByIdentifier> m_hostsToPluginIdentifierData; 114 114 bool pluginLoadClientPolicyForHost(const String&, const WebCore::PluginInfo&, WebCore::PluginLoadClientPolicy&) const; 115 String longestMatchedWildcardHostForHost(const String& host) const; 116 bool replaceHostWithMatchedWildcardHost(String& host, const String& identifier) const; 115 117 #endif // PLATFORM(MAC) 116 118 #endif // ENABLE(NETSCAPE_PLUGIN_API) -
trunk/Tools/ChangeLog
r195617 r195650 1 2016-01-26 I-Ting Liu <iting_liu@apple.com> 2 3 Add a test for WebKit::stringMatchesWildcardString. 4 https://bugs.webkit.org/show_bug.cgi?id=153090 5 6 Reviewed by Darin Adler. 7 8 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 9 Add the file to the project. 10 11 * TestWebKitAPI/Tests/WebKit2/mac/StringUtilities.mm: Added. 12 (TestWebKitAPI::TEST): 13 Test that a string matches another string that may contain wildcard characters. 14 1 15 2016-01-26 Konstantin Tokarev <annulen@yandex.ru> 2 16 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r194950 r195650 261 261 7CEFA9661AC0B9E200B910FD /* _WKUserContentExtensionStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7CEFA9641AC0B9E200B910FD /* _WKUserContentExtensionStore.mm */; }; 262 262 7CFBCAE51743238F00B2BFCF /* WillLoad_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */; }; 263 83CF1C301C4F1B8B00688447 /* StringUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = 83CF1C2C1C4F19AE00688447 /* StringUtilities.mm */; }; 263 264 930AD402150698D00067970F /* lots-of-text.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 930AD401150698B30067970F /* lots-of-text.html */; }; 264 265 9361002914DC95A70061379D /* lots-of-iframes.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9361002814DC957B0061379D /* lots-of-iframes.html */; }; … … 629 630 7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad_Bundle.cpp; sourceTree = "<group>"; }; 630 631 81B50192140F232300D9EB58 /* StringBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringBuilder.cpp; sourceTree = "<group>"; }; 632 83CF1C2C1C4F19AE00688447 /* StringUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StringUtilities.mm; sourceTree = "<group>"; }; 631 633 86BD19971A2DB05B006DCF0A /* RefCounter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefCounter.cpp; sourceTree = "<group>"; }; 632 634 8A2C750D16CED9550024F352 /* ResizeWindowAfterCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResizeWindowAfterCrash.cpp; sourceTree = "<group>"; }; … … 1450 1452 C0C5D3BD14598B6F00A802A6 /* GetBackingScaleFactor_Bundle.mm */, 1451 1453 1AEF994817A09F5300998EF0 /* GetPIDAfterAbortedProcessLaunch.cpp */, 1454 83CF1C2C1C4F19AE00688447 /* StringUtilities.mm */, 1452 1455 ); 1453 1456 path = mac; … … 1741 1744 7CCE7F0D1A411AE600447C4C /* ReloadPageAfterCrash.cpp in Sources */, 1742 1745 7CCE7EC91A411A7E00447C4C /* RenderedImageFromDOMNode.mm in Sources */, 1746 83CF1C301C4F1B8B00688447 /* StringUtilities.mm in Sources */, 1743 1747 7CCE7ECA1A411A7E00447C4C /* RenderedImageFromDOMRange.mm in Sources */, 1744 1748 51CD1C6C1B38CE4300142CA5 /* ModalAlerts.mm in Sources */,
Note: See TracChangeset
for help on using the changeset viewer.