Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "modules/crypto/Algorithm.h" | 32 #include "core/page/FormatConsoleMessage.h" |
| 33 | 33 |
| 34 #include "modules/crypto/AesCbcParams.h" | 34 #include "core/inspector/ScriptCallFrame.h" |
| 35 #include "modules/crypto/AesKeyGenParams.h" | 35 #include "core/inspector/ScriptCallStack.h" |
| 36 #include "modules/crypto/HmacParams.h" | 36 #include "wtf/NotFound.h" |
| 37 #include "modules/crypto/RsaKeyGenParams.h" | |
| 38 #include "modules/crypto/RsaSsaParams.h" | |
| 39 #include "wtf/text/WTFString.h" | 37 #include "wtf/text/WTFString.h" |
| 40 | 38 |
| 41 namespace WebCore { | 39 namespace WebCore { |
| 42 | 40 |
| 43 PassRefPtr<Algorithm> Algorithm::create(const WebKit::WebCryptoAlgorithm& algori thm) | 41 // If there is already a callstack in the message (which can happen when we exec ute internal code with try-catch and error reporting), we don't want to include another. |
| 42 static bool containsStackTrace(const String& message) | |
| 44 { | 43 { |
| 45 switch (algorithm.paramsType()) { | 44 return message.find("\n at ") != WTF::notFound; |
|
pfeldman
2013/08/14 09:53:00
This looks like a very fragile heuristic.
Devlin
2013/08/14 17:00:40
It is fragile, but there's not really a solution (
| |
| 46 case WebKit::WebCryptoAlgorithmParamsTypeNone: | |
| 47 return adoptRef(new Algorithm(algorithm)); | |
| 48 case WebKit::WebCryptoAlgorithmParamsTypeAesCbcParams: | |
| 49 return AesCbcParams::create(algorithm); | |
| 50 case WebKit::WebCryptoAlgorithmParamsTypeAesKeyGenParams: | |
| 51 return AesKeyGenParams::create(algorithm); | |
| 52 case WebKit::WebCryptoAlgorithmParamsTypeHmacParams: | |
| 53 return HmacParams::create(algorithm); | |
| 54 case WebKit::WebCryptoAlgorithmParamsTypeRsaSsaParams: | |
| 55 return RsaSsaParams::create(algorithm); | |
| 56 case WebKit::WebCryptoAlgorithmParamsTypeRsaKeyGenParams: | |
| 57 return RsaKeyGenParams::create(algorithm); | |
| 58 } | |
| 59 ASSERT_NOT_REACHED(); | |
| 60 return 0; | |
| 61 } | 45 } |
| 62 | 46 |
| 63 Algorithm::Algorithm(const WebKit::WebCryptoAlgorithm& algorithm) | 47 String formatConsoleMessage(const String& originalMessage, PassRefPtr<ScriptCall Stack> callStack) |
| 64 : m_algorithm(algorithm) | |
| 65 { | 48 { |
| 66 ScriptWrappable::init(this); | 49 String formattedMessage = originalMessage; |
| 50 if (containsStackTrace(formattedMessage)) | |
| 51 return formattedMessage; | |
| 52 | |
| 53 for (size_t i = 0; i < callStack->size(); ++i) { | |
| 54 const ScriptCallFrame& frame = callStack->at(i); | |
| 55 formattedMessage.append("\n at " + (frame.functionName().length() ? f rame.functionName() : String("(anonymous function)")) + " (" + frame.sourceURL() + ":" + String::number(frame.lineNumber()) + ":" + String::number(frame.columnN umber()) + ")"); | |
| 56 } | |
| 57 | |
| 58 return formattedMessage; | |
| 67 } | 59 } |
| 68 | 60 |
| 69 String Algorithm::name() | 61 String formatConsoleMessage(const WTF::String& originalMessage, const WTF::Strin g& url, unsigned lineNumber, unsigned columnNumber) |
|
pfeldman
2013/08/14 09:53:00
Console message already has url, line number and c
Devlin
2013/08/14 17:00:40
Mostly it was for completeness purposes - this way
| |
| 70 { | 62 { |
| 71 return m_algorithm.name(); | 63 String formattedMessage = originalMessage; |
| 64 if (containsStackTrace(formattedMessage)) | |
| 65 return formattedMessage; | |
| 66 | |
| 67 formattedMessage.append("\n at (anonymous function) (" + url + ":" + Stri ng::number(lineNumber) + ":" + String::number(columnNumber) + ")"); | |
| 68 | |
| 69 return formattedMessage; | |
| 72 } | 70 } |
| 73 | 71 |
| 74 } // namespace WebCore | 72 } // namespace WebCore |
| OLD | NEW |