diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-14 23:58:51 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-14 23:58:51 +0000 |
commit | e1681f221ed06218232a4252721ffc9f5cc24fa0 (patch) | |
tree | 3241a7135c37a7a9e1f5e7168a9ea35e08695cd6 /webkit/support/webkit_support.cc | |
parent | 6ae762e1b393c8b459cc997f107deb5f38ce6255 (diff) | |
download | chromium_src-e1681f221ed06218232a4252721ffc9f5cc24fa0.zip chromium_src-e1681f221ed06218232a4252721ffc9f5cc24fa0.tar.gz chromium_src-e1681f221ed06218232a4252721ffc9f5cc24fa0.tar.bz2 |
Add LocalFileToDataURL to webkit_support.
I'm going to use this to get
http/tests/security/local-user-CSS-from-remote.html
passing. Instead of trying to load a file:/// URL for the
user style sheet, use a data: URL. This matches what happens
in Chromium.
Review URL: http://codereview.chromium.org/3425004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59459 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/support/webkit_support.cc')
-rw-r--r-- | webkit/support/webkit_support.cc | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/webkit/support/webkit_support.cc b/webkit/support/webkit_support.cc index 66d2c66..0d4d72a 100644 --- a/webkit/support/webkit_support.cc +++ b/webkit/support/webkit_support.cc @@ -5,6 +5,7 @@ #include "webkit/support/webkit_support.h" #include "base/at_exit.h" +#include "base/base64.h" #include "base/command_line.h" #include "base/debug_util.h" #include "base/file_path.h" @@ -407,9 +408,26 @@ WebURL RewriteLayoutTestsURL(const std::string& utf8_url) { } bool SetCurrentDirectoryForFileURL(const WebKit::WebURL& fileUrl) { - FilePath localPath; - return net::FileURLToFilePath(fileUrl, &localPath) - && file_util::SetCurrentDirectory(localPath.DirName()); + FilePath local_path; + return net::FileURLToFilePath(fileUrl, &local_path) + && file_util::SetCurrentDirectory(local_path.DirName()); +} + +WebURL LocalFileToDataURL(const WebURL& fileUrl) { + FilePath local_path; + if (!net::FileURLToFilePath(fileUrl, &local_path)) + return WebURL(); + + std::string contents; + if (!file_util::ReadFileToString(local_path, &contents)) + return WebURL(); + + std::string contents_base64; + if (!base::Base64Encode(contents, &contents_base64)) + return WebURL(); + + const char kDataUrlPrefix[] = "data:text/css;charset=utf-8;base64,"; + return WebURL(GURL(kDataUrlPrefix + contents_base64)); } int64 GetCurrentTimeInMillisecond() { |