| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 void didSerializeDataForFrame(const WebCString& data, | 56 void didSerializeDataForFrame(const WebCString& data, |
| 57 FrameSerializationStatus) final { | 57 FrameSerializationStatus) final { |
| 58 m_builder.append(data.data(), data.length()); | 58 m_builder.append(data.data(), data.length()); |
| 59 } | 59 } |
| 60 | 60 |
| 61 StringBuilder m_builder; | 61 StringBuilder m_builder; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 class SimpleMHTMLPartsGenerationDelegate | 64 class SimpleMHTMLPartsGenerationDelegate |
| 65 : public WebFrameSerializer::MHTMLPartsGenerationDelegate { | 65 : public WebFrameSerializer::MHTMLPartsGenerationDelegate { |
| 66 public: |
| 67 SimpleMHTMLPartsGenerationDelegate() : m_removePopupOverlay(false) {} |
| 68 |
| 69 void setRemovePopupOverlay(bool removePopupOverlay) { |
| 70 m_removePopupOverlay = removePopupOverlay; |
| 71 } |
| 72 |
| 66 private: | 73 private: |
| 67 bool shouldSkipResource(const WebURL&) final { return false; } | 74 bool shouldSkipResource(const WebURL&) final { return false; } |
| 68 | 75 |
| 69 WebString getContentID(WebFrame*) final { return WebString("<cid>"); } | 76 WebString getContentID(WebFrame*) final { return WebString("<cid>"); } |
| 70 | 77 |
| 71 WebFrameSerializerCacheControlPolicy cacheControlPolicy() final { | 78 WebFrameSerializerCacheControlPolicy cacheControlPolicy() final { |
| 72 return WebFrameSerializerCacheControlPolicy::None; | 79 return WebFrameSerializerCacheControlPolicy::None; |
| 73 } | 80 } |
| 74 | 81 |
| 75 bool useBinaryEncoding() final { return false; } | 82 bool useBinaryEncoding() final { return false; } |
| 83 bool removePopupOverlay() final { return m_removePopupOverlay; } |
| 84 |
| 85 bool m_removePopupOverlay; |
| 76 }; | 86 }; |
| 77 | 87 |
| 78 // Returns the count of match for substring |pattern| in string |str|. | 88 // Returns the count of match for substring |pattern| in string |str|. |
| 79 int matchSubstring(const String& str, const char* pattern, size_t size) { | 89 int matchSubstring(const String& str, const char* pattern, size_t size) { |
| 80 int matches = 0; | 90 int matches = 0; |
| 81 size_t start = 0; | 91 size_t start = 0; |
| 82 while (true) { | 92 while (true) { |
| 83 size_t pos = str.find(pattern, start); | 93 size_t pos = str.find(pattern, start); |
| 84 if (pos == WTF::kNotFound) | 94 if (pos == WTF::kNotFound) |
| 85 break; | 95 break; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 const String& mimeType = "text/html") { | 215 const String& mimeType = "text/html") { |
| 206 KURL parsedURL(ParsedURLString, url); | 216 KURL parsedURL(ParsedURLString, url); |
| 207 URLTestHelpers::registerMockedURLLoad(parsedURL, fileName, | 217 URLTestHelpers::registerMockedURLLoad(parsedURL, fileName, |
| 208 "frameserialization/", mimeType); | 218 "frameserialization/", mimeType); |
| 209 FrameTestHelpers::loadFrame(mainFrameImpl(), url.utf8().data()); | 219 FrameTestHelpers::loadFrame(mainFrameImpl(), url.utf8().data()); |
| 210 WebThreadSafeData result = WebFrameSerializer::generateMHTMLParts( | 220 WebThreadSafeData result = WebFrameSerializer::generateMHTMLParts( |
| 211 WebString("boundary"), mainFrameImpl(), &m_mhtmlDelegate); | 221 WebString("boundary"), mainFrameImpl(), &m_mhtmlDelegate); |
| 212 return String(result.data(), result.size()); | 222 return String(result.data(), result.size()); |
| 213 } | 223 } |
| 214 | 224 |
| 225 void setRemovePopupOverlay(bool removePopupOverlay) { |
| 226 m_mhtmlDelegate.setRemovePopupOverlay(removePopupOverlay); |
| 227 } |
| 228 |
| 215 private: | 229 private: |
| 216 SimpleMHTMLPartsGenerationDelegate m_mhtmlDelegate; | 230 SimpleMHTMLPartsGenerationDelegate m_mhtmlDelegate; |
| 217 }; | 231 }; |
| 218 | 232 |
| 219 TEST_F(WebFrameSerializerSanitizationTest, RemoveInlineScriptInAttributes) { | 233 TEST_F(WebFrameSerializerSanitizationTest, RemoveInlineScriptInAttributes) { |
| 220 String mhtml = | 234 String mhtml = |
| 221 generateMHTMLParts("http://www.test.com", "script_in_attributes.html"); | 235 generateMHTMLParts("http://www.test.com", "script_in_attributes.html"); |
| 222 | 236 |
| 223 // These scripting attributes should be removed. | 237 // These scripting attributes should be removed. |
| 224 EXPECT_EQ(WTF::kNotFound, mhtml.find("onload=")); | 238 EXPECT_EQ(WTF::kNotFound, mhtml.find("onload=")); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 String mhtml = generateMHTMLParts("http://www.test.com", "img_srcset.html"); | 338 String mhtml = generateMHTMLParts("http://www.test.com", "img_srcset.html"); |
| 325 | 339 |
| 326 // srcset attribute should be skipped. | 340 // srcset attribute should be skipped. |
| 327 EXPECT_EQ(WTF::kNotFound, mhtml.find("srcset=")); | 341 EXPECT_EQ(WTF::kNotFound, mhtml.find("srcset=")); |
| 328 | 342 |
| 329 // New width and height attributes should not be set. | 343 // New width and height attributes should not be set. |
| 330 EXPECT_NE(WTF::kNotFound, mhtml.find("id=3D\"i1\">")); | 344 EXPECT_NE(WTF::kNotFound, mhtml.find("id=3D\"i1\">")); |
| 331 EXPECT_NE(WTF::kNotFound, mhtml.find("id=3D\"i2\" width=3D\"8\">")); | 345 EXPECT_NE(WTF::kNotFound, mhtml.find("id=3D\"i2\" width=3D\"8\">")); |
| 332 } | 346 } |
| 333 | 347 |
| 348 TEST_F(WebFrameSerializerSanitizationTest, RemovePopupOverlayIfRequested) { |
| 349 webView()->resize(WebSize(500, 500)); |
| 350 setRemovePopupOverlay(true); |
| 351 String mhtml = generateMHTMLParts("http://www.test.com", "popup.html"); |
| 352 EXPECT_EQ(WTF::kNotFound, mhtml.find("class=3D\"overlay")); |
| 353 EXPECT_EQ(WTF::kNotFound, mhtml.find("class=3D\"modal")); |
| 354 } |
| 355 |
| 356 TEST_F(WebFrameSerializerSanitizationTest, KeepPopupOverlayIfNotRequested) { |
| 357 webView()->resize(WebSize(500, 500)); |
| 358 setRemovePopupOverlay(false); |
| 359 String mhtml = generateMHTMLParts("http://www.test.com", "popup.html"); |
| 360 EXPECT_NE(WTF::kNotFound, mhtml.find("class=3D\"overlay")); |
| 361 EXPECT_NE(WTF::kNotFound, mhtml.find("class=3D\"modal")); |
| 362 } |
| 363 |
| 334 } // namespace blink | 364 } // namespace blink |
| OLD | NEW |