OLD | NEW |
---|---|
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 void ScheduleDestroy() { | 70 void ScheduleDestroy() { |
70 if (destroy_scheduled_) | 71 if (destroy_scheduled_) |
71 return; | 72 return; |
72 destroy_scheduled_ = true; | 73 destroy_scheduled_ = true; |
73 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 74 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
74 } | 75 } |
75 | 76 |
76 LauncherApp* app_; | 77 LauncherApp* app_; |
77 bool destroy_scheduled_; | 78 bool destroy_scheduled_; |
78 LauncherClient* client_; | 79 LauncherClient* client_; |
80 String url_; | |
79 URLLoaderPtr url_loader_; | 81 URLLoaderPtr url_loader_; |
80 ScopedDataPipeConsumerHandle response_body_stream_; | 82 ScopedDataPipeConsumerHandle response_body_stream_; |
81 | 83 |
82 DISALLOW_COPY_AND_ASSIGN(LaunchInstance); | 84 DISALLOW_COPY_AND_ASSIGN(LaunchInstance); |
83 }; | 85 }; |
84 | 86 |
85 class LauncherApp : public Application { | 87 class LauncherApp : public Application { |
86 public: | 88 public: |
87 LauncherApp() { | 89 LauncherApp() { |
88 handler_map_["text/html"] = "mojo:mojo_html_viewer"; | 90 handler_map_["text/html"] = "mojo:mojo_html_viewer"; |
(...skipping 21 matching lines...) Expand all Loading... | |
110 ConnectTo("mojo:mojo_network_service", &network_service_); | 112 ConnectTo("mojo:mojo_network_service", &network_service_); |
111 } | 113 } |
112 | 114 |
113 HandlerMap handler_map_; | 115 HandlerMap handler_map_; |
114 | 116 |
115 NetworkServicePtr network_service_; | 117 NetworkServicePtr network_service_; |
116 | 118 |
117 DISALLOW_COPY_AND_ASSIGN(LauncherApp); | 119 DISALLOW_COPY_AND_ASSIGN(LauncherApp); |
118 }; | 120 }; |
119 | 121 |
120 void LauncherConnection::Launch(const String& url) { | 122 void LauncherConnection::Launch(const String& url_string) { |
121 new LaunchInstance(app_, client(), url); | 123 GURL url(url_string.To<std::string>()); |
124 | |
125 // For Mojo URLs, the handler can always be found at the origin. | |
126 // TODO(aa): Return error for invalid URL? | |
127 if (url.is_valid() && url.SchemeIs("mojo")) { | |
Ben Goodger (Google)
2014/06/19 21:09:47
I think this is fine for now, but note that when a
Aaron Boodman
2014/06/19 21:25:12
Hm, ok.
I didn't realize/remember we wanted mojo
| |
128 client()->OnLaunch(url_string, | |
129 url.GetOrigin().spec(), | |
130 navigation::ResponseDetailsPtr()); | |
131 return; | |
132 } | |
133 | |
134 new LaunchInstance(app_, client(), url_string); | |
122 } | 135 } |
123 | 136 |
124 LaunchInstance::LaunchInstance(LauncherApp* app, | 137 LaunchInstance::LaunchInstance(LauncherApp* app, |
125 LauncherClient* client, | 138 LauncherClient* client, |
126 const String& url) | 139 const String& url) |
127 : app_(app), | 140 : app_(app), |
128 destroy_scheduled_(false), | 141 destroy_scheduled_(false), |
129 client_(client) { | 142 client_(client), |
143 url_(url) { | |
130 url_loader_ = app_->CreateURLLoader(); | 144 url_loader_ = app_->CreateURLLoader(); |
131 url_loader_.set_client(this); | 145 url_loader_.set_client(this); |
132 | 146 |
133 URLRequestPtr request(URLRequest::New()); | 147 URLRequestPtr request(URLRequest::New()); |
134 request->url = url; | 148 request->url = url; |
135 request->method = "GET"; | 149 request->method = "GET"; |
136 request->auto_follow_redirects = true; | 150 request->auto_follow_redirects = true; |
137 | 151 |
138 DataPipe data_pipe; | 152 DataPipe data_pipe; |
139 response_body_stream_ = data_pipe.consumer_handle.Pass(); | 153 response_body_stream_ = data_pipe.consumer_handle.Pass(); |
140 | 154 |
141 url_loader_->Start(request.Pass(), data_pipe.producer_handle.Pass()); | 155 url_loader_->Start(request.Pass(), data_pipe.producer_handle.Pass()); |
142 } | 156 } |
143 | 157 |
144 void LaunchInstance::OnReceivedResponse(URLResponsePtr response) { | 158 void LaunchInstance::OnReceivedResponse(URLResponsePtr response) { |
145 std::string content_type = GetContentType(response->headers); | 159 std::string content_type = GetContentType(response->headers); |
146 std::string handler_url = app_->GetHandlerForContentType(content_type); | 160 std::string handler_url = app_->GetHandlerForContentType(content_type); |
147 if (!handler_url.empty()) { | 161 if (!handler_url.empty()) { |
148 client_->OnLaunch(handler_url, response.Pass(), | 162 navigation::ResponseDetailsPtr nav_response( |
149 response_body_stream_.Pass()); | 163 navigation::ResponseDetails::New()); |
164 nav_response->response = response.Pass(); | |
165 nav_response->response_body_stream = response_body_stream_.Pass(); | |
166 client_->OnLaunch(url_, handler_url, nav_response.Pass()); | |
150 } | 167 } |
151 } | 168 } |
152 | 169 |
153 } // namespace launcher | 170 } // namespace launcher |
154 | 171 |
155 // static | 172 // static |
156 Application* Application::Create() { | 173 Application* Application::Create() { |
157 return new launcher::LauncherApp; | 174 return new launcher::LauncherApp; |
158 } | 175 } |
159 | 176 |
160 } // namespace mojo | 177 } // namespace mojo |
OLD | NEW |