Commit b7893322 authored by jamesr's avatar jamesr Committed by Commit bot

Drop refs to net::EmbeddedTestServer / net::File{Path,URL} utils in mojo

We don't actually use the embedded test server and we don't need most
of what the file path conversion utilities provide. We only need to
support very simple URLs for loading off of file paths and we do not
need to support windows at all for mojo_shell.

Review URL: https://codereview.chromium.org/640403002

Cr-Commit-Position: refs/heads/master@{#300331}
parent 9867e691
...@@ -150,16 +150,18 @@ ...@@ -150,16 +150,18 @@
'shell/dynamic_application_loader.cc', 'shell/dynamic_application_loader.cc',
'shell/dynamic_application_loader.h', 'shell/dynamic_application_loader.h',
'shell/dynamic_service_runner.h', 'shell/dynamic_service_runner.h',
'shell/external_application_listener.h',
'shell/external_application_listener_posix.cc', 'shell/external_application_listener_posix.cc',
'shell/external_application_listener_win.cc', 'shell/external_application_listener_win.cc',
'shell/external_application_listener.h',
'shell/external_application_registrar.mojom', 'shell/external_application_registrar.mojom',
'shell/filename_util.cc',
'shell/filename_util.h',
'shell/in_process_dynamic_service_runner.cc',
'shell/in_process_dynamic_service_runner.h',
'shell/incoming_connection_listener_posix.cc', 'shell/incoming_connection_listener_posix.cc',
'shell/incoming_connection_listener_posix.h', 'shell/incoming_connection_listener_posix.h',
'shell/init.cc', 'shell/init.cc',
'shell/init.h', 'shell/init.h',
'shell/in_process_dynamic_service_runner.cc',
'shell/in_process_dynamic_service_runner.h',
'shell/mojo_url_resolver.cc', 'shell/mojo_url_resolver.cc',
'shell/mojo_url_resolver.h', 'shell/mojo_url_resolver.h',
'shell/out_of_process_dynamic_service_runner.cc', 'shell/out_of_process_dynamic_service_runner.cc',
......
...@@ -55,15 +55,17 @@ source_set("lib") { ...@@ -55,15 +55,17 @@ source_set("lib") {
"dynamic_application_loader.cc", "dynamic_application_loader.cc",
"dynamic_application_loader.h", "dynamic_application_loader.h",
"dynamic_service_runner.h", "dynamic_service_runner.h",
"external_application_listener.h",
"external_application_listener_posix.cc", "external_application_listener_posix.cc",
"external_application_listener_win.cc", "external_application_listener_win.cc",
"external_application_listener.h", "filename_util.cc",
"filename_util.h",
"in_process_dynamic_service_runner.cc",
"in_process_dynamic_service_runner.h",
"incoming_connection_listener_posix.cc", "incoming_connection_listener_posix.cc",
"incoming_connection_listener_posix.h", "incoming_connection_listener_posix.h",
"init.cc", "init.cc",
"init.h", "init.h",
"in_process_dynamic_service_runner.cc",
"in_process_dynamic_service_runner.h",
"mojo_url_resolver.cc", "mojo_url_resolver.cc",
"mojo_url_resolver.h", "mojo_url_resolver.h",
"out_of_process_dynamic_service_runner.cc", "out_of_process_dynamic_service_runner.cc",
......
...@@ -11,12 +11,14 @@ ...@@ -11,12 +11,14 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "mojo/common/common_type_converters.h" #include "mojo/common/common_type_converters.h"
#include "mojo/common/data_pipe_utils.h" #include "mojo/common/data_pipe_utils.h"
#include "mojo/services/public/interfaces/network/url_loader.mojom.h" #include "mojo/services/public/interfaces/network/url_loader.mojom.h"
#include "mojo/shell/context.h" #include "mojo/shell/context.h"
#include "mojo/shell/filename_util.h"
#include "mojo/shell/switches.h" #include "mojo/shell/switches.h"
#include "net/base/filename_util.h" #include "url/url_util.h"
namespace mojo { namespace mojo {
namespace shell { namespace shell {
...@@ -92,8 +94,17 @@ class DynamicApplicationLoader::LocalLoader : public Loader { ...@@ -92,8 +94,17 @@ class DynamicApplicationLoader::LocalLoader : public Loader {
load_callbacks, load_callbacks,
loader_complete_callback), loader_complete_callback),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
base::FilePath path; DCHECK(url.SchemeIsFile());
net::FileURLToFilePath(url, &path); url::RawCanonOutputW<1024> output;
url::DecodeURLEscapeSequences(
url.path().data(), static_cast<int>(url.path().length()), &output);
base::string16 decoded_path =
base::string16(output.data(), output.length());
#if defined(OS_WIN)
base::FilePath path(decoded_path);
#else
base::FilePath path(base::UTF16ToUTF8(decoded_path));
#endif
// Async for consistency with network case. // Async for consistency with network case.
base::MessageLoop::current()->PostTask( base::MessageLoop::current()->PostTask(
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "mojo/shell/context.h" #include "mojo/shell/context.h"
#include "mojo/shell/dynamic_application_loader.h" #include "mojo/shell/dynamic_application_loader.h"
#include "mojo/shell/dynamic_service_runner.h" #include "mojo/shell/dynamic_service_runner.h"
#include "net/base/filename_util.h" #include "mojo/shell/filename_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace mojo { namespace mojo {
...@@ -81,7 +81,7 @@ TEST_F(DynamicApplicationLoaderTest, DoesNotExist) { ...@@ -81,7 +81,7 @@ TEST_F(DynamicApplicationLoaderTest, DoesNotExist) {
base::ScopedTempDir temp_dir; base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
base::FilePath nonexistent_file(FILE_PATH_LITERAL("nonexistent.txt")); base::FilePath nonexistent_file(FILE_PATH_LITERAL("nonexistent.txt"));
GURL url(net::FilePathToFileURL(temp_dir.path().Append(nonexistent_file))); GURL url(FilePathToFileURL(temp_dir.path().Append(nonexistent_file)));
MessagePipe pipe; MessagePipe pipe;
scoped_refptr<ApplicationLoader::SimpleLoadCallbacks> callbacks( scoped_refptr<ApplicationLoader::SimpleLoadCallbacks> callbacks(
new ApplicationLoader::SimpleLoadCallbacks(pipe.handle0.Pass())); new ApplicationLoader::SimpleLoadCallbacks(pipe.handle0.Pass()));
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mojo/shell/filename_util.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "url/gurl.h"
#include "url/url_canon_internal.h"
#include "url/url_util.h"
namespace mojo {
// Prefix to prepend to get a file URL.
static const base::FilePath::CharType kFileURLPrefix[] =
FILE_PATH_LITERAL("file://");
GURL FilePathToFileURL(const base::FilePath& path) {
// Produce a URL like "file:///C:/foo" for a regular file, or
// "file://///server/path" for UNC. The URL canonicalizer will fix up the
// latter case to be the canonical UNC form: "file://server/path"
base::FilePath::StringType url_string(kFileURLPrefix);
if (!path.IsAbsolute()) {
base::FilePath current_dir;
PathService::Get(base::DIR_CURRENT, &current_dir);
url_string.append(current_dir.value());
url_string.push_back(base::FilePath::kSeparators[0]);
}
url_string.append(path.value());
// Now do replacement of some characters. Since we assume the input is a
// literal filename, anything the URL parser might consider special should
// be escaped here.
// This must be the first substitution since others will introduce percents as
// the escape character
ReplaceSubstringsAfterOffset(
&url_string, 0, FILE_PATH_LITERAL("%"), FILE_PATH_LITERAL("%25"));
// A semicolon is supposed to be some kind of separator according to RFC 2396.
ReplaceSubstringsAfterOffset(
&url_string, 0, FILE_PATH_LITERAL(";"), FILE_PATH_LITERAL("%3B"));
ReplaceSubstringsAfterOffset(
&url_string, 0, FILE_PATH_LITERAL("#"), FILE_PATH_LITERAL("%23"));
ReplaceSubstringsAfterOffset(
&url_string, 0, FILE_PATH_LITERAL("?"), FILE_PATH_LITERAL("%3F"));
#if defined(OS_POSIX)
ReplaceSubstringsAfterOffset(
&url_string, 0, FILE_PATH_LITERAL("\\"), FILE_PATH_LITERAL("%5C"));
#endif
return GURL(url_string);
}
} // namespace mojo
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MOJO_SHELL_FILENAME_UTIL_H_
#define MOJO_SHELL_FILENAME_UTIL_H_
class GURL;
namespace base {
class FilePath;
}
namespace mojo {
// Given the full path to a file name, creates a file: URL. The returned URL
// may not be valid if the input is malformed.
GURL FilePathToFileURL(const base::FilePath& path);
} // namespace mojo
#endif // MOJO_SHELL_FILENAME_UTIL_H_
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "net/base/filename_util.h" #include "mojo/shell/filename_util.h"
#include "url/url_util.h" #include "url/url_util.h"
namespace mojo { namespace mojo {
...@@ -55,7 +55,7 @@ MojoURLResolver::MojoURLResolver() { ...@@ -55,7 +55,7 @@ MojoURLResolver::MojoURLResolver() {
// By default, resolve mojo URLs to files living alongside the shell. // By default, resolve mojo URLs to files living alongside the shell.
base::FilePath path; base::FilePath path;
PathService::Get(base::DIR_MODULE, &path); PathService::Get(base::DIR_MODULE, &path);
default_base_url_ = AddTrailingSlashIfNeeded(net::FilePathToFileURL(path)); default_base_url_ = AddTrailingSlashIfNeeded(FilePathToFileURL(path));
} }
MojoURLResolver::~MojoURLResolver() { MojoURLResolver::~MojoURLResolver() {
......
...@@ -10,8 +10,7 @@ ...@@ -10,8 +10,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "net/base/filename_util.h" #include "mojo/shell/filename_util.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace mojo { namespace mojo {
...@@ -26,11 +25,8 @@ ShellTestBase::~ShellTestBase() { ...@@ -26,11 +25,8 @@ ShellTestBase::~ShellTestBase() {
void ShellTestBase::SetUp() { void ShellTestBase::SetUp() {
shell_context_.Init(); shell_context_.Init();
test_server_.reset(new net::test_server::EmbeddedTestServer());
ASSERT_TRUE(test_server_->InitializeAndWaitUntilReady());
base::FilePath service_dir; base::FilePath service_dir;
CHECK(PathService::Get(base::DIR_MODULE, &service_dir)); CHECK(PathService::Get(base::DIR_MODULE, &service_dir));
test_server_->ServeFilesFromDirectory(service_dir);
} }
ScopedMessagePipeHandle ShellTestBase::ConnectToService( ScopedMessagePipeHandle ShellTestBase::ConnectToService(
...@@ -43,7 +39,7 @@ ScopedMessagePipeHandle ShellTestBase::ConnectToService( ...@@ -43,7 +39,7 @@ ScopedMessagePipeHandle ShellTestBase::ConnectToService(
base::FilePath service_dir; base::FilePath service_dir;
CHECK(PathService::Get(base::DIR_MODULE, &service_dir)); CHECK(PathService::Get(base::DIR_MODULE, &service_dir));
shell_context_.mojo_url_resolver()->SetBaseURL( shell_context_.mojo_url_resolver()->SetBaseURL(
net::FilePathToFileURL(service_dir)); FilePathToFileURL(service_dir));
return shell_context_.ConnectToServiceByName( return shell_context_.ConnectToServiceByName(
application_url, service_name).Pass(); application_url, service_name).Pass();
...@@ -52,9 +48,6 @@ ScopedMessagePipeHandle ShellTestBase::ConnectToService( ...@@ -52,9 +48,6 @@ ScopedMessagePipeHandle ShellTestBase::ConnectToService(
ScopedMessagePipeHandle ShellTestBase::ConnectToServiceViaNetwork( ScopedMessagePipeHandle ShellTestBase::ConnectToServiceViaNetwork(
const GURL& application_url, const GURL& application_url,
const std::string& service_name) { const std::string& service_name) {
shell_context_.mojo_url_resolver()->SetBaseURL(
test_server_->base_url());
return shell_context_.ConnectToServiceByName( return shell_context_.ConnectToServiceByName(
application_url, service_name).Pass(); application_url, service_name).Pass();
} }
......
...@@ -15,12 +15,6 @@ ...@@ -15,12 +15,6 @@
class GURL; class GURL;
namespace net {
namespace test_server {
class EmbeddedTestServer;
}
} // namespace net
namespace mojo { namespace mojo {
namespace shell { namespace shell {
namespace test { namespace test {
...@@ -60,7 +54,6 @@ class ShellTestBase : public testing::Test { ...@@ -60,7 +54,6 @@ class ShellTestBase : public testing::Test {
Context* shell_context() { return &shell_context_; } Context* shell_context() { return &shell_context_; }
private: private:
scoped_ptr<net::test_server::EmbeddedTestServer> test_server_;
Context shell_context_; Context shell_context_;
base::MessageLoop message_loop_; base::MessageLoop message_loop_;
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "mojo/shell/filename_util.h"
#include "mojo/shell/init.h" #include "mojo/shell/init.h"
#include "net/base/filename_util.h"
namespace mojo { namespace mojo {
namespace shell { namespace shell {
...@@ -29,8 +29,7 @@ void ShellTestHelper::Init() { ...@@ -29,8 +29,7 @@ void ShellTestHelper::Init() {
new ApplicationManager::TestAPI(context_.application_manager())); new ApplicationManager::TestAPI(context_.application_manager()));
base::FilePath service_dir; base::FilePath service_dir;
CHECK(PathService::Get(base::DIR_MODULE, &service_dir)); CHECK(PathService::Get(base::DIR_MODULE, &service_dir));
context_.mojo_url_resolver()->SetBaseURL( context_.mojo_url_resolver()->SetBaseURL(FilePathToFileURL(service_dir));
net::FilePathToFileURL(service_dir));
} }
void ShellTestHelper::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, void ShellTestHelper::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader,
......
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