blob: d9a4e60574b8f83c428f2c0f026b0c3019fb55ac [file] [log] [blame]
John Abd-El-Malek537a67042015-04-02 17:29:351// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
benee052932015-04-27 21:52:575#include "mojo/shell/fetcher.h"
John Abd-El-Malek537a67042015-04-02 17:29:356
7#include "url/gurl.h"
8
9namespace mojo {
10namespace shell {
11
12const char Fetcher::kMojoMagic[] = "#!mojo ";
13const size_t Fetcher::kMaxShebangLength = 2048;
14
15Fetcher::Fetcher(const FetchCallback& loader_callback)
16 : loader_callback_(loader_callback) {
17}
18
19Fetcher::~Fetcher() {
20}
21
22bool Fetcher::PeekContentHandler(std::string* mojo_shebang,
23 GURL* mojo_content_handler_url) {
24 // TODO(aa): I guess this should just go in ApplicationManager now.
25 std::string shebang;
26 if (HasMojoMagic() && PeekFirstLine(&shebang)) {
27 GURL url(shebang.substr(arraysize(kMojoMagic) - 1, std::string::npos));
28 if (url.is_valid()) {
29 *mojo_shebang = shebang;
30 *mojo_content_handler_url = url;
31 return true;
32 }
33 }
34 return false;
35}
36
37} // namespace shell
38} // namespace mojo