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 | |
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
-rw-r--r-- | webkit/support/webkit_support.cc | 24 | ||||
-rw-r--r-- | webkit/support/webkit_support.h | 3 | ||||
-rw-r--r-- | webkit/tools/test_shell/layout_test_controller.cc | 23 |
3 files changed, 45 insertions, 5 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() { diff --git a/webkit/support/webkit_support.h b/webkit/support/webkit_support.h index c8b7978..745b979 100644 --- a/webkit/support/webkit_support.h +++ b/webkit/support/webkit_support.h @@ -120,6 +120,9 @@ WebKit::WebURL RewriteLayoutTestsURL(const std::string& utf8_url); // Set the directory of specified file: URL as the current working directory. bool SetCurrentDirectoryForFileURL(const WebKit::WebURL& fileUrl); +// Convert a file:/// URL to a base64 encoded data: URL. +WebKit::WebURL LocalFileToDataURL(const WebKit::WebURL& fileUrl); + // -------- Time int64 GetCurrentTimeInMillisecond(); diff --git a/webkit/tools/test_shell/layout_test_controller.cc b/webkit/tools/test_shell/layout_test_controller.cc index 79dbc04..8d7088f 100644 --- a/webkit/tools/test_shell/layout_test_controller.cc +++ b/webkit/tools/test_shell/layout_test_controller.cc @@ -8,13 +8,16 @@ #include "webkit/tools/test_shell/layout_test_controller.h" +#include "base/base64.h" #include "base/basictypes.h" #include "base/file_path.h" +#include "base/file_util.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/path_service.h" #include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" +#include "net/base/net_util.h" #include "third_party/WebKit/WebKit/chromium/public/WebAnimationController.h" #include "third_party/WebKit/WebKit/chromium/public/WebBindings.h" #include "third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h" @@ -664,12 +667,28 @@ void LayoutTestController::setUserStyleSheetEnabled( void LayoutTestController::setUserStyleSheetLocation( const CppArgumentList& args, CppVariant* result) { + result->SetNull(); + if (args.size() > 0 && args[0].isString()) { GURL location(TestShell::RewriteLocalUrl(args[0].ToString())); + + FilePath local_path; + if (!net::FileURLToFilePath(location, &local_path)) + return; + + std::string contents; + if (!file_util::ReadFileToString(local_path, &contents)) + return; + + std::string contents_base64; + if (!base::Base64Encode(contents, &contents_base64)) + return; + + const char kDataUrlPrefix[] = "data:text/css;charset=utf-8;base64,"; + location = GURL(kDataUrlPrefix + contents_base64); + shell_->delegate()->SetUserStyleSheetLocation(location); } - - result->SetNull(); } void LayoutTestController::setAuthorAndUserStylesEnabled( |