Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Side by Side Diff: third_party/WebKit/Source/platform/mhtml/MHTMLArchive.cpp

Issue 2247063002: Allow loading MHTML archive from content scheme (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Helper function and test Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 return stringBuilder.toString(); 63 return stringBuilder.toString();
64 } 64 }
65 65
66 MHTMLArchive::MHTMLArchive() 66 MHTMLArchive::MHTMLArchive()
67 { 67 {
68 } 68 }
69 69
70 MHTMLArchive* MHTMLArchive::create(const KURL& url, PassRefPtr<SharedBuffer> dat a) 70 MHTMLArchive* MHTMLArchive::create(const KURL& url, PassRefPtr<SharedBuffer> dat a)
71 { 71 {
72 // MHTML pages can only be loaded from local URLs and http/https URLs. 72 // MHTML pages can only be loaded from local URLs, http/https URLs, and cont ent URLs(Android specific).
73 // The latter is now allowed due to full sandboxing enforcement on MHTML pag es. 73 // The latter is now allowed due to full sandboxing enforcement on MHTML pag es.
74 if (!SchemeRegistry::shouldTreatURLSchemeAsLocal(url.protocol()) && !url.pro tocolIsInHTTPFamily()) 74 if (!SchemeRegistry::shouldTreatURLSchemeAsLocal(url.protocol()) && !url.pro tocolIsInHTTPFamily() && !canLoadContent(url))
jianli 2016/08/17 20:27:21 I think it would be better to move all these check
Vivian 2016/08/17 20:38:17 Done.
75 return nullptr; 75 return nullptr;
76 76
77 MHTMLParser parser(data); 77 MHTMLParser parser(data);
78 HeapVector<Member<ArchiveResource>> resources = parser.parseArchive(); 78 HeapVector<Member<ArchiveResource>> resources = parser.parseArchive();
79 if (resources.isEmpty()) 79 if (resources.isEmpty())
80 return nullptr; // Invalid MHTML file. 80 return nullptr; // Invalid MHTML file.
81 81
82 MHTMLArchive* archive = new MHTMLArchive; 82 MHTMLArchive* archive = new MHTMLArchive;
83 // The first document suitable resource is the main resource of the top fram e. 83 // The first document suitable resource is the main resource of the top fram e.
84 for (size_t i = 0; i < resources.size(); ++i) { 84 for (size_t i = 0; i < resources.size(); ++i) {
85 const AtomicString& mimeType = resources[i]->mimeType(); 85 const AtomicString& mimeType = resources[i]->mimeType();
86 if (archive->mainResource() || !MIMETypeRegistry::isSupportedNonImageMIM EType(mimeType) || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) || mimeType == "text/css") 86 if (archive->mainResource() || !MIMETypeRegistry::isSupportedNonImageMIM EType(mimeType) || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) || mimeType == "text/css")
87 archive->addSubresource(resources[i].get()); 87 archive->addSubresource(resources[i].get());
88 else 88 else
89 archive->setMainResource(resources[i].get()); 89 archive->setMainResource(resources[i].get());
90 } 90 }
91 return archive; 91 return archive;
92 } 92 }
93 93
94 bool MHTMLArchive::canLoadContent(const KURL& url)
95 {
96 #if OS(ANDROID)
97 return url.protocolIs("content");
98 #endif
99 return false;
100 }
101
94 void MHTMLArchive::generateMHTMLHeader( 102 void MHTMLArchive::generateMHTMLHeader(
95 const String& boundary, const String& title, const String& mimeType, 103 const String& boundary, const String& title, const String& mimeType,
96 SharedBuffer& outputBuffer) 104 SharedBuffer& outputBuffer)
97 { 105 {
98 ASSERT(!boundary.isEmpty()); 106 ASSERT(!boundary.isEmpty());
99 ASSERT(!mimeType.isEmpty()); 107 ASSERT(!mimeType.isEmpty());
100 108
101 DateComponents now; 109 DateComponents now;
102 now.setMillisecondsSinceEpochForDateTime(currentTimeMS()); 110 now.setMillisecondsSinceEpochForDateTime(currentTimeMS());
103 // TODO(lukasza): Passing individual date/time components seems fragile. 111 // TODO(lukasza): Passing individual date/time components seems fragile.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 return m_subresources.get(url.getString()); 246 return m_subresources.get(url.getString());
239 } 247 }
240 248
241 DEFINE_TRACE(MHTMLArchive) 249 DEFINE_TRACE(MHTMLArchive)
242 { 250 {
243 visitor->trace(m_mainResource); 251 visitor->trace(m_mainResource);
244 visitor->trace(m_subresources); 252 visitor->trace(m_subresources);
245 } 253 }
246 254
247 } // namespace blink 255 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/mhtml/MHTMLArchive.h ('k') | third_party/WebKit/Source/web/tests/MHTMLTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698