Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(921)

Side by Side Diff: shell/dynamic_application_loader.cc

Issue 821403003: Changes magic sequence to '!#mojo ' and strips 'mojo ' when building url (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: two more Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/js/test/pingpong_target.js ('k') | sky/examples/home.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "shell/dynamic_application_loader.h" 5 #include "shell/dynamic_application_loader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 13 matching lines...) Expand all
24 #include "shell/data_pipe_peek.h" 24 #include "shell/data_pipe_peek.h"
25 #include "shell/filename_util.h" 25 #include "shell/filename_util.h"
26 #include "shell/switches.h" 26 #include "shell/switches.h"
27 #include "url/url_util.h" 27 #include "url/url_util.h"
28 28
29 namespace mojo { 29 namespace mojo {
30 namespace shell { 30 namespace shell {
31 31
32 namespace { 32 namespace {
33 33
34 static const char kMojoMagic[] = "#!mojo:"; 34 static const char kMojoMagic[] = "#!mojo ";
35 static const size_t kMaxShebangLength = 2048; 35 static const size_t kMaxShebangLength = 2048;
36 36
37 void IgnoreResult(bool result) { 37 void IgnoreResult(bool result) {
38 } 38 }
39 39
40 } // namespace 40 } // namespace
41 41
42 // Encapsulates loading and running one individual application. 42 // Encapsulates loading and running one individual application.
43 // 43 //
44 // Loaders are owned by DynamicApplicationLoader. DynamicApplicationLoader must 44 // Loaders are owned by DynamicApplicationLoader. DynamicApplicationLoader must
(...skipping 29 matching lines...) Expand all
74 base::TaskRunner* task_runner, 74 base::TaskRunner* task_runner,
75 base::Callback<void(const base::FilePath&, bool)> callback) = 0; 75 base::Callback<void(const base::FilePath&, bool)> callback) = 0;
76 76
77 virtual std::string MimeType() = 0; 77 virtual std::string MimeType() = 0;
78 78
79 virtual bool HasMojoMagic() = 0; 79 virtual bool HasMojoMagic() = 0;
80 80
81 virtual bool PeekFirstLine(std::string* line) = 0; 81 virtual bool PeekFirstLine(std::string* line) = 0;
82 82
83 void Load() { 83 void Load() {
84 // If the response begins with a #!mojo:<content-handler-url>, use it. 84 // If the response begins with a #!mojo <content-handler-url>, use it.
85 GURL url; 85 GURL url;
86 std::string shebang; 86 std::string shebang;
87 if (PeekContentHandler(&shebang, &url)) { 87 if (PeekContentHandler(&shebang, &url)) {
88 load_callback_.Run( 88 load_callback_.Run(
89 url, shell_handle_.Pass(), 89 url, shell_handle_.Pass(),
90 AsURLResponse(context_->task_runners()->blocking_pool(), 90 AsURLResponse(context_->task_runners()->blocking_pool(),
91 static_cast<int>(shebang.size()))); 91 static_cast<int>(shebang.size())));
92 return; 92 return;
93 } 93 }
94 94
(...skipping 14 matching lines...) Expand all
109 base::Bind(&Loader::RunLibrary, weak_ptr_factory_.GetWeakPtr())); 109 base::Bind(&Loader::RunLibrary, weak_ptr_factory_.GetWeakPtr()));
110 } 110 }
111 111
112 void ReportComplete() { loader_complete_callback_.Run(this); } 112 void ReportComplete() { loader_complete_callback_.Run(this); }
113 113
114 private: 114 private:
115 bool PeekContentHandler(std::string* mojo_shebang, 115 bool PeekContentHandler(std::string* mojo_shebang,
116 GURL* mojo_content_handler_url) { 116 GURL* mojo_content_handler_url) {
117 std::string shebang; 117 std::string shebang;
118 if (HasMojoMagic() && PeekFirstLine(&shebang)) { 118 if (HasMojoMagic() && PeekFirstLine(&shebang)) {
119 GURL url(shebang.substr(2, std::string::npos)); 119 GURL url(shebang.substr(arraysize(kMojoMagic) - 1, std::string::npos));
120 if (url.is_valid()) { 120 if (url.is_valid()) {
121 *mojo_shebang = shebang; 121 *mojo_shebang = shebang;
122 *mojo_content_handler_url = url; 122 *mojo_content_handler_url = url;
123 return true; 123 return true;
124 } 124 }
125 } 125 }
126 return false; 126 return false;
127 } 127 }
128 128
129 void RunLibrary(const base::FilePath& path, bool path_exists) { 129 void RunLibrary(const base::FilePath& path, bool path_exists) {
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 // TODO(darin): What should we do about service errors? This implies that 401 // TODO(darin): What should we do about service errors? This implies that
402 // the app closed its handle to the service manager. Maybe we don't care? 402 // the app closed its handle to the service manager. Maybe we don't care?
403 } 403 }
404 404
405 void DynamicApplicationLoader::LoaderComplete(Loader* loader) { 405 void DynamicApplicationLoader::LoaderComplete(Loader* loader) {
406 loaders_.erase(std::find(loaders_.begin(), loaders_.end(), loader)); 406 loaders_.erase(std::find(loaders_.begin(), loaders_.end(), loader));
407 } 407 }
408 408
409 } // namespace shell 409 } // namespace shell
410 } // namespace mojo 410 } // namespace mojo
OLDNEW
« no previous file with comments | « services/js/test/pingpong_target.js ('k') | sky/examples/home.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698