summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-25 20:41:44 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-25 20:41:44 +0000
commitdc11fe336bc652d04746767ce1cb5ba1882d57f0 (patch)
tree621520a6e37879002313f660866fee07695fbcc0
parent1d1478990720cba5bec10936850af7f6a8204ca1 (diff)
downloadchromium_src-dc11fe336bc652d04746767ce1cb5ba1882d57f0.zip
chromium_src-dc11fe336bc652d04746767ce1cb5ba1882d57f0.tar.gz
chromium_src-dc11fe336bc652d04746767ce1cb5ba1882d57f0.tar.bz2
Mojo: Set a default value for the --origin command line switch.
(Also fixes a regression in the wget app.) Review URL: https://codereview.chromium.org/414633003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285668 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--mojo/examples/wget/wget.cc2
-rw-r--r--mojo/shell/mojo_url_resolver.cc31
-rw-r--r--mojo/shell/mojo_url_resolver.h3
3 files changed, 22 insertions, 14 deletions
diff --git a/mojo/examples/wget/wget.cc b/mojo/examples/wget/wget.cc
index 55a8cb8..507b3cb 100644
--- a/mojo/examples/wget/wget.cc
+++ b/mojo/examples/wget/wget.cc
@@ -51,7 +51,7 @@ class ResponsePrinter {
MOJO_HANDLE_SIGNAL_READABLE,
MOJO_DEADLINE_INDEFINITE);
} else if (result == MOJO_RESULT_OK) {
- if (fwrite(buf, num_bytes, 1, stdout) != num_bytes) {
+ if (fwrite(buf, num_bytes, 1, stdout) != 1) {
printf("\nUnexpected error writing to file\n");
break;
}
diff --git a/mojo/shell/mojo_url_resolver.cc b/mojo/shell/mojo_url_resolver.cc
index debb3d7..c3998549 100644
--- a/mojo/shell/mojo_url_resolver.cc
+++ b/mojo/shell/mojo_url_resolver.cc
@@ -28,11 +28,26 @@ std::string MakeSharedLibraryName(const std::string& host_name) {
#endif
}
+GURL AddTrailingSlashIfNeeded(const GURL& url) {
+ if (!url.has_path() || *url.path().rbegin() == '/')
+ return url;
+
+ std::string path(url.path() + '/');
+ GURL::Replacements replacements;
+ replacements.SetPathStr(path);
+ return url.ReplaceComponents(replacements);
+}
+
} // namespace
MojoURLResolver::MojoURLResolver() {
// Needed to treat first component of mojo URLs as host, not path.
url::AddStandardScheme("mojo");
+
+ // By default, resolve mojo URLs to files living alongside the shell.
+ base::FilePath path;
+ PathService::Get(base::DIR_MODULE, &path);
+ default_base_url_ = AddTrailingSlashIfNeeded(net::FilePathToFileURL(path));
}
MojoURLResolver::~MojoURLResolver() {
@@ -40,15 +55,9 @@ MojoURLResolver::~MojoURLResolver() {
void MojoURLResolver::SetBaseURL(const GURL& base_url) {
DCHECK(base_url.is_valid());
- base_url_ = base_url;
// Force a trailing slash on the base_url to simplify resolving
// relative files and URLs below.
- if (base_url.has_path() && *base_url.path().rbegin() != '/') {
- std::string path(base_url.path() + '/');
- GURL::Replacements replacements;
- replacements.SetPathStr(path);
- base_url_ = base_url_.ReplaceComponents(replacements);
- }
+ base_url_ = AddTrailingSlashIfNeeded(base_url);
}
void MojoURLResolver::AddCustomMapping(const GURL& mojo_url,
@@ -67,12 +76,10 @@ GURL MojoURLResolver::Resolve(const GURL& mojo_url) const {
std::string lib = MakeSharedLibraryName(mojo_url.host());
- if (local_file_set_.find(mojo_url) != local_file_set_.end()) {
+ if (!base_url_.is_valid() ||
+ local_file_set_.find(mojo_url) != local_file_set_.end()) {
// Resolve to a local file URL.
- base::FilePath path;
- PathService::Get(base::DIR_MODULE, &path);
- path = path.Append(base::FilePath::FromUTF8Unsafe(lib));
- return net::FilePathToFileURL(path);
+ return default_base_url_.Resolve(lib);
}
// Otherwise, resolve to an URL relative to base_url_.
diff --git a/mojo/shell/mojo_url_resolver.h b/mojo/shell/mojo_url_resolver.h
index c82845c..ccd9bf4 100644
--- a/mojo/shell/mojo_url_resolver.h
+++ b/mojo/shell/mojo_url_resolver.h
@@ -31,7 +31,7 @@ class MojoURLResolver {
void AddCustomMapping(const GURL& mojo_url, const GURL& resolved_url);
// Add a local file mapping for a particular "mojo:" URL. This causes the
- // "mojo:" URL to be resolved to an base::DIR_EXE-relative shared library.
+ // "mojo:" URL to be resolved to a base::DIR_MODULE-relative shared library.
void AddLocalFileMapping(const GURL& mojo_url);
// Resolve the given "mojo:" URL to the URL that should be used to fetch the
@@ -41,6 +41,7 @@ class MojoURLResolver {
private:
std::map<GURL, GURL> url_map_;
std::set<GURL> local_file_set_;
+ GURL default_base_url_;
GURL base_url_;
};