Commit 77ce66b3 authored by weiran's avatar weiran Committed by Commit bot

Allow loading MHTML archive from content scheme

BUG=630753

Review-Url: https://codereview.chromium.org/2247063002
Cr-Commit-Position: refs/heads/master@{#415775}
parent 9816b437
...@@ -69,9 +69,9 @@ MHTMLArchive::MHTMLArchive() ...@@ -69,9 +69,9 @@ MHTMLArchive::MHTMLArchive()
MHTMLArchive* MHTMLArchive::create(const KURL& url, PassRefPtr<SharedBuffer> data) MHTMLArchive* MHTMLArchive::create(const KURL& url, PassRefPtr<SharedBuffer> data)
{ {
// MHTML pages can only be loaded from local URLs and http/https URLs. // MHTML pages can only be loaded from local URLs, http/https URLs, and content URLs(Android specific).
// The latter is now allowed due to full sandboxing enforcement on MHTML pages. // The latter is now allowed due to full sandboxing enforcement on MHTML pages.
if (!SchemeRegistry::shouldTreatURLSchemeAsLocal(url.protocol()) && !url.protocolIsInHTTPFamily()) if (!canLoadArchive(url))
return nullptr; return nullptr;
MHTMLParser parser(data); MHTMLParser parser(data);
...@@ -91,6 +91,21 @@ MHTMLArchive* MHTMLArchive::create(const KURL& url, PassRefPtr<SharedBuffer> dat ...@@ -91,6 +91,21 @@ MHTMLArchive* MHTMLArchive::create(const KURL& url, PassRefPtr<SharedBuffer> dat
return archive; return archive;
} }
bool MHTMLArchive::canLoadArchive(const KURL& url)
{
// MHTML pages can only be loaded from local URLs, http/https URLs, and content URLs(Android specific).
// The latter is now allowed due to full sandboxing enforcement on MHTML pages.
if (SchemeRegistry::shouldTreatURLSchemeAsLocal(url.protocol()))
return true;
if (url.protocolIsInHTTPFamily())
return true;
#if OS(ANDROID)
if (url.protocolIs("content"))
return true;
#endif
return false;
}
void MHTMLArchive::generateMHTMLHeader( void MHTMLArchive::generateMHTMLHeader(
const String& boundary, const String& title, const String& mimeType, const String& boundary, const String& title, const String& mimeType,
SharedBuffer& outputBuffer) SharedBuffer& outputBuffer)
......
...@@ -98,6 +98,7 @@ private: ...@@ -98,6 +98,7 @@ private:
void setMainResource(ArchiveResource*); void setMainResource(ArchiveResource*);
void addSubresource(ArchiveResource*); void addSubresource(ArchiveResource*);
static bool canLoadArchive(const KURL&);
Member<ArchiveResource> m_mainResource; Member<ArchiveResource> m_mainResource;
SubArchiveResources m_subresources; SubArchiveResources m_subresources;
......
...@@ -241,11 +241,17 @@ TEST_F(MHTMLTest, MHTMLFromScheme) ...@@ -241,11 +241,17 @@ TEST_F(MHTMLTest, MHTMLFromScheme)
addTestResources(); addTestResources();
RefPtr<SharedBuffer> data = serialize("Test Serialization", "text/html", MHTMLArchive::UseDefaultEncoding); RefPtr<SharedBuffer> data = serialize("Test Serialization", "text/html", MHTMLArchive::UseDefaultEncoding);
KURL httpURL = toKURL("http://www.example.com"); KURL httpURL = toKURL("http://www.example.com");
KURL contentURL = toKURL("content://foo");
KURL fileURL = toKURL("file://foo"); KURL fileURL = toKURL("file://foo");
KURL specialSchemeURL = toKURL("fooscheme://bar"); KURL specialSchemeURL = toKURL("fooscheme://bar");
// MHTMLArchives can only be initialized from local schemes and http/https schemes. // MHTMLArchives can only be initialized from local schemes, http/https schemes, and content scheme(Android specific).
EXPECT_NE(nullptr, MHTMLArchive::create(httpURL, data.get())); EXPECT_NE(nullptr, MHTMLArchive::create(httpURL, data.get()));
#if OS(ANDROID)
EXPECT_NE(nullptr, MHTMLArchive::create(contentURL, data.get()));
#else
EXPECT_EQ(nullptr, MHTMLArchive::create(contentURL, data.get()));
#endif
EXPECT_NE(nullptr, MHTMLArchive::create(fileURL, data.get())); EXPECT_NE(nullptr, MHTMLArchive::create(fileURL, data.get()));
EXPECT_EQ(nullptr, MHTMLArchive::create(specialSchemeURL, data.get())); EXPECT_EQ(nullptr, MHTMLArchive::create(specialSchemeURL, data.get()));
SchemeRegistry::registerURLSchemeAsLocal("fooscheme"); SchemeRegistry::registerURLSchemeAsLocal("fooscheme");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment