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

Side by Side Diff: mojo/services/launcher/launcher.cc

Issue 345773003: Mojo: teach launcher about mojo:// URLs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, add comments Created 6 years, 6 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 | Annotate | Revision Log
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 "base/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/strings/string_tokenizer.h" 7 #include "base/strings/string_tokenizer.h"
8 #include "mojo/public/cpp/application/application.h" 8 #include "mojo/public/cpp/application/application.h"
9 #include "mojo/services/public/cpp/view_manager/types.h" 9 #include "mojo/services/public/cpp/view_manager/types.h"
10 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h" 10 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h"
11 #include "mojo/services/public/interfaces/network/network_service.mojom.h" 11 #include "mojo/services/public/interfaces/network/network_service.mojom.h"
12 #include "mojo/services/public/interfaces/network/url_loader.mojom.h" 12 #include "mojo/services/public/interfaces/network/url_loader.mojom.h"
13 #include "url/gurl.h"
13 14
14 namespace mojo { 15 namespace mojo {
15 namespace launcher { 16 namespace launcher {
16 17
17 class LauncherApp; 18 class LauncherApp;
18 19
19 class LauncherConnection : public InterfaceImpl<Launcher> { 20 class LauncherConnection : public InterfaceImpl<Launcher> {
20 public: 21 public:
21 explicit LauncherConnection(LauncherApp* app) : app_(app) {} 22 explicit LauncherConnection(LauncherApp* app) : app_(app) {}
22 virtual ~LauncherConnection() {} 23 virtual ~LauncherConnection() {}
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 ConnectTo("mojo:mojo_network_service", &network_service_); 111 ConnectTo("mojo:mojo_network_service", &network_service_);
111 } 112 }
112 113
113 HandlerMap handler_map_; 114 HandlerMap handler_map_;
114 115
115 NetworkServicePtr network_service_; 116 NetworkServicePtr network_service_;
116 117
117 DISALLOW_COPY_AND_ASSIGN(LauncherApp); 118 DISALLOW_COPY_AND_ASSIGN(LauncherApp);
118 }; 119 };
119 120
120 void LauncherConnection::Launch(const String& url) { 121 void LauncherConnection::Launch(const String& url_string) {
121 new LaunchInstance(app_, client(), url); 122 GURL url(url_string.To<std::string>());
123
124 // For Mojo URLs, the handler can always be found at the origin.
125 // TODO(aa): Return error for invalid URL?
126 if (url.is_valid() && url.SchemeIs("mojo")) {
127 client()->OnLaunch(url_string,
128 url.GetOrigin().spec(),
129 navigation::ResponseDetailsPtr());
130 return;
131 }
132
133 new LaunchInstance(app_, client(), url_string);
122 } 134 }
123 135
124 LaunchInstance::LaunchInstance(LauncherApp* app, 136 LaunchInstance::LaunchInstance(LauncherApp* app,
125 LauncherClient* client, 137 LauncherClient* client,
126 const String& url) 138 const String& url)
127 : app_(app), 139 : app_(app),
128 destroy_scheduled_(false), 140 destroy_scheduled_(false),
129 client_(client) { 141 client_(client) {
130 url_loader_ = app_->CreateURLLoader(); 142 url_loader_ = app_->CreateURLLoader();
131 url_loader_.set_client(this); 143 url_loader_.set_client(this);
132 144
133 URLRequestPtr request(URLRequest::New()); 145 URLRequestPtr request(URLRequest::New());
134 request->url = url; 146 request->url = url;
135 request->method = "GET"; 147 request->method = "GET";
136 request->auto_follow_redirects = true; 148 request->auto_follow_redirects = true;
137 149
138 DataPipe data_pipe; 150 DataPipe data_pipe;
139 response_body_stream_ = data_pipe.consumer_handle.Pass(); 151 response_body_stream_ = data_pipe.consumer_handle.Pass();
140 152
141 url_loader_->Start(request.Pass(), data_pipe.producer_handle.Pass()); 153 url_loader_->Start(request.Pass(), data_pipe.producer_handle.Pass());
142 } 154 }
143 155
144 void LaunchInstance::OnReceivedResponse(URLResponsePtr response) { 156 void LaunchInstance::OnReceivedResponse(URLResponsePtr response) {
145 std::string content_type = GetContentType(response->headers); 157 std::string content_type = GetContentType(response->headers);
146 std::string handler_url = app_->GetHandlerForContentType(content_type); 158 std::string handler_url = app_->GetHandlerForContentType(content_type);
147 if (!handler_url.empty()) { 159 if (!handler_url.empty()) {
148 client_->OnLaunch(handler_url, response.Pass(), 160 navigation::ResponseDetailsPtr nav_response(
149 response_body_stream_.Pass()); 161 navigation::ResponseDetails::New());
162 nav_response->response = response.Pass();
163 nav_response->response_body_stream = response_body_stream_.Pass();
164 client_->OnLaunch(nav_response->response->url, handler_url,
165 nav_response.Pass());
150 } 166 }
151 } 167 }
152 168
153 } // namespace launcher 169 } // namespace launcher
154 170
155 // static 171 // static
156 Application* Application::Create() { 172 Application* Application::Create() {
157 return new launcher::LauncherApp; 173 return new launcher::LauncherApp;
158 } 174 }
159 175
160 } // namespace mojo 176 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698