Add security-checked casts for all WebCore::CachedResource subclasses
<http://webkit.org/b/127988>

Reviewed by Darin Adler.

* inspector/InspectorPageAgent.cpp:
(WebCore::InspectorPageAgent::cachedResourceContent):
* inspector/InspectorResourceAgent.cpp:
(WebCore::InspectorResourceAgent::didLoadResourceFromMemoryCache):
- Switch from static_cast<>() to security-checked cast.

* loader/cache/CachedCSSStyleSheet.h:
(WebCore::toCachedCSSStyleSheet): Add.
* loader/cache/CachedFont.h:
(WebCore::toCachedFont): Add.

* loader/cache/CachedImage.h: Make CachedImageManual final.

* loader/cache/CachedRawResource.cpp:
(WebCore::CachedRawResource::CachedRawResource): Add assert that
only MainResource or RawResource types are used to construct a
CachedRawResource.  This may be a security issue depending on
what code exists that uses the type() value to cast to a
CachedResource subclass.
(WebCore::CachedRawResource::switchClientsToRevalidatedResource):
Switch from static_cast<>() to toCachedRawResource().

* loader/cache/CachedRawResource.h:
(WebCore::toCachedRawResource): Add.
* loader/cache/CachedResource.h:
(WebCore::CachedResource::isMainOrRawResource): Add.  A
CachedRawResource could be either a MainResource or a
RawResource.  Currently only used in assertions.

* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::requestFont):
(WebCore::CachedResourceLoader::requestTextTrack):
(WebCore::CachedResourceLoader::requestCSSStyleSheet):
(WebCore::CachedResourceLoader::requestUserCSSStyleSheet):
(WebCore::CachedResourceLoader::requestScript):
(WebCore::CachedResourceLoader::requestXSLStyleSheet):
(WebCore::CachedResourceLoader::requestSVGDocument):
(WebCore::CachedResourceLoader::requestRawResource):
(WebCore::CachedResourceLoader::requestMainResource):
- Switch from static_cast<>() to security-checked cast.

* loader/cache/CachedSVGDocument.h:
(WebCore::toCachedSVGDocument): Add.
* loader/cache/CachedScript.h:
(WebCore::toCachedScript): Add.
* loader/cache/CachedTextTrack.h:
(WebCore::toCachedTextTrack): Add.
* loader/cache/CachedXSLStyleSheet.h:
(WebCore::toCachedXSLStyleSheet): Add.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@163242 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Add webView:didFailNavigation:withError: delegate method
https://bugs.webkit.org/show_bug.cgi?id=128022

Reviewed by Darin Adler.

* UIProcess/API/APILoaderClient.h:
(API::LoaderClient::didFailLoadWithErrorForFrame):
* UIProcess/API/C/WKPage.cpp:
(WKPageSetPageLoaderClient):
* UIProcess/API/Cocoa/WKNavigationDelegate.h:
* UIProcess/Cocoa/NavigationState.h:
* UIProcess/Cocoa/NavigationState.mm:
(WebKit::NavigationState::setNavigationDelegate):
(WebKit::NavigationState::LoaderClient::didFailLoadWithErrorForFrame):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didFailLoadForFrame):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::dispatchDidFailLoad):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@163243 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Update WebCrypto JWK mapping to use key_ops
https://bugs.webkit.org/show_bug.cgi?id=127609

Reviewed by Sam Weinig.

Source/WebCore:

Updated JWK support ot match current editor draft.

* bindings/js/JSCryptoKeySerializationJWK.cpp:
(WebCore::getJSArrayFromJSON): Fixed this previously untested function to actually work.
(WebCore::tryJWKKeyOpsValue):
(WebCore::JSCryptoKeySerializationJWK::reconcileUsages):
(WebCore::JSCryptoKeySerializationJWK::reconcileExtractable): Removed an old comment,
these things are now specced.
(WebCore::addToJSON): Made static functions file static, there is no reason for
them to be class members.
(WebCore::buildJSONForOctetSequence):
(WebCore::buildJSONForRSAComponents):
(WebCore::addBoolToJSON):
(WebCore::addJWKAlgorithmToJSON):
(WebCore::addUsagesToJSON):
(WebCore::JSCryptoKeySerializationJWK::serialize):
* bindings/js/JSCryptoKeySerializationJWK.h:

* crypto/mac/CryptoAlgorithmAES_KWMac.cpp:
(WebCore::CryptoAlgorithmAES_KW::platformEncrypt):
(WebCore::CryptoAlgorithmAES_KW::platformDecrypt):
Check for length, so that we don't fail silently.

LayoutTests:

* crypto/subtle/aes-kw-wrap-unwrap-aes-expected.txt:
* crypto/subtle/aes-kw-wrap-unwrap-aes.html:
Removed a subtest for wrapping JWK. That doesn't really work per the spec, because
JWK is arbitatry length, and AES-KW requires 8*n bytes.

* crypto/subtle/aes-export-key-expected.txt:
* crypto/subtle/aes-export-key.html:
* crypto/subtle/hmac-export-key-expected.txt:
* crypto/subtle/hmac-export-key.html:
* crypto/subtle/jwk-export-use-values-expected.txt:
* crypto/subtle/jwk-export-use-values.html:
* crypto/subtle/jwk-import-use-values-expected.txt:
* crypto/subtle/jwk-import-use-values.html:
* crypto/subtle/rsa-export-key-expected.txt:
* crypto/subtle/rsa-export-key.html:
* crypto/subtle/rsa-export-private-key-expected.txt:
* crypto/subtle/rsa-export-private-key.html:
* crypto/subtle/rsa-oaep-key-manipulation-expected.txt:
* crypto/subtle/rsa-oaep-key-manipulation.html:
* crypto/subtle/rsa-postMessage-expected.txt:
* crypto/subtle/rsa-postMessage.html:
Updated for the fix.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@163244 268f45cc-cd09-0410-ab3c-d52691b4dbfc