OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "sky/shell/ui/engine.h" | 5 #include "sky/shell/ui/engine.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
9 #include "mojo/public/cpp/application/connect.h" | 9 #include "mojo/public/cpp/application/connect.h" |
10 #include "sky/engine/public/platform/WebInputEvent.h" | 10 #include "sky/engine/public/platform/WebInputEvent.h" |
11 #include "sky/engine/public/platform/sky_display_metrics.h" | 11 #include "sky/engine/public/platform/sky_display_metrics.h" |
12 #include "sky/engine/public/platform/sky_display_metrics.h" | 12 #include "sky/engine/public/platform/sky_display_metrics.h" |
13 #include "sky/engine/public/web/Sky.h" | 13 #include "sky/engine/public/web/Sky.h" |
14 #include "sky/engine/public/web/WebLocalFrame.h" | 14 #include "sky/engine/public/web/WebLocalFrame.h" |
15 #include "sky/engine/public/web/WebSettings.h" | 15 #include "sky/engine/public/web/WebSettings.h" |
16 #include "sky/engine/public/web/WebView.h" | 16 #include "sky/engine/public/web/WebView.h" |
17 #include "sky/services/platform/platform_impl.h" | 17 #include "sky/services/platform/platform_impl.h" |
| 18 #include "sky/shell/dart/dart_library_provider_files.h" |
| 19 #include "sky/shell/dart/dart_library_provider_network.h" |
18 #include "sky/shell/service_provider.h" | 20 #include "sky/shell/service_provider.h" |
19 #include "sky/shell/ui/animator.h" | 21 #include "sky/shell/ui/animator.h" |
20 #include "sky/shell/ui/input_event_converter.h" | 22 #include "sky/shell/ui/input_event_converter.h" |
21 #include "sky/shell/ui/internals.h" | 23 #include "sky/shell/ui/internals.h" |
22 #include "third_party/skia/include/core/SkCanvas.h" | 24 #include "third_party/skia/include/core/SkCanvas.h" |
23 #include "third_party/skia/include/core/SkPictureRecorder.h" | 25 #include "third_party/skia/include/core/SkPictureRecorder.h" |
24 | 26 |
25 namespace sky { | 27 namespace sky { |
26 namespace shell { | 28 namespace shell { |
27 | 29 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 scoped_ptr<blink::WebInputEvent> web_event = | 179 scoped_ptr<blink::WebInputEvent> web_event = |
178 ConvertEvent(event, device_pixel_ratio_); | 180 ConvertEvent(event, device_pixel_ratio_); |
179 if (!web_event) | 181 if (!web_event) |
180 return; | 182 return; |
181 if (sky_view_) | 183 if (sky_view_) |
182 sky_view_->HandleInputEvent(*web_event); | 184 sky_view_->HandleInputEvent(*web_event); |
183 if (web_view_) | 185 if (web_view_) |
184 web_view_->handleInputEvent(*web_event); | 186 web_view_->handleInputEvent(*web_event); |
185 } | 187 } |
186 | 188 |
187 void Engine::LoadURL(const mojo::String& mojo_url) { | 189 void Engine::CloseWebViewIfNeeded() { |
188 GURL url(mojo_url); | 190 if (web_view_) { |
189 if (!blink::WebView::shouldUseWebView(url)) { | 191 web_view_->close(); |
190 if (web_view_) { | 192 web_view_ = nullptr; |
191 web_view_->close(); | 193 } |
192 web_view_ = nullptr; | 194 } |
193 } | 195 |
194 sky_view_ = blink::SkyView::Create(this); | 196 void Engine::RunFromLibrary(const mojo::String& name) { |
195 sky_view_->Load(url); | 197 CloseWebViewIfNeeded(); |
196 UpdateSkyViewSize(); | 198 sky_view_ = blink::SkyView::Create(this); |
| 199 sky_view_->RunFromLibrary(blink::WebString::fromUTF8(name), |
| 200 dart_library_provider_.get()); |
| 201 UpdateSkyViewSize(); |
| 202 } |
| 203 |
| 204 void Engine::RunFromNetwork(const mojo::String& url) { |
| 205 if (blink::WebView::shouldUseWebView(GURL(url))) { |
| 206 LoadUsingWebView(url); |
197 return; | 207 return; |
198 } | 208 } |
| 209 dart_library_provider_.reset( |
| 210 new DartLibraryProviderNetwork(g_platform_impl->networkService())); |
| 211 RunFromLibrary(url); |
| 212 } |
| 213 |
| 214 void Engine::RunFromFile(const mojo::String& main, |
| 215 const mojo::String& package_root) { |
| 216 dart_library_provider_.reset( |
| 217 new DartLibraryProviderFiles(base::FilePath(package_root))); |
| 218 RunFromLibrary(main); |
| 219 } |
| 220 |
| 221 void Engine::RunFromSnapshot(mojo::ScopedDataPipeConsumerHandle snapshot) { |
| 222 // TODO(abarth): Implement. |
| 223 } |
| 224 |
| 225 void Engine::LoadUsingWebView(const mojo::String& mojo_url) { |
| 226 GURL url(mojo_url); |
| 227 DCHECK(blink::WebView::shouldUseWebView(url)); |
199 | 228 |
200 if (sky_view_) | 229 if (sky_view_) |
201 sky_view_ = nullptr; | 230 sky_view_ = nullptr; |
202 | 231 |
203 LOG(WARNING) << ".sky support is deprecated, please use .dart for main()"; | 232 LOG(WARNING) << ".sky support is deprecated, please use .dart for main()"; |
204 | 233 |
205 // Something bad happens if you try to call WebView::close and replace | 234 // Something bad happens if you try to call WebView::close and replace |
206 // the webview. So for now we just load into the existing one. :/ | 235 // the webview. So for now we just load into the existing one. :/ |
207 if (!web_view_) | 236 if (!web_view_) |
208 web_view_ = blink::WebView::create(this); | 237 web_view_ = blink::WebView::create(this); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 return this; | 272 return this; |
244 } | 273 } |
245 | 274 |
246 mojo::NavigatorHost* Engine::NavigatorHost() { | 275 mojo::NavigatorHost* Engine::NavigatorHost() { |
247 return this; | 276 return this; |
248 } | 277 } |
249 | 278 |
250 void Engine::RequestNavigate(mojo::Target target, | 279 void Engine::RequestNavigate(mojo::Target target, |
251 mojo::URLRequestPtr request) { | 280 mojo::URLRequestPtr request) { |
252 // Ignoring target for now. | 281 // Ignoring target for now. |
253 base::MessageLoop::current()->PostTask(FROM_HERE, | 282 base::MessageLoop::current()->PostTask( |
254 base::Bind(&Engine::LoadURL, GetWeakPtr(), request->url)); | 283 FROM_HERE, |
| 284 base::Bind(&Engine::RunFromNetwork, GetWeakPtr(), request->url)); |
255 } | 285 } |
256 | 286 |
257 void Engine::DidNavigateLocally(const mojo::String& url) { | 287 void Engine::DidNavigateLocally(const mojo::String& url) { |
258 } | 288 } |
259 | 289 |
260 void Engine::RequestNavigateHistory(int32_t delta) { | 290 void Engine::RequestNavigateHistory(int32_t delta) { |
261 NOTIMPLEMENTED(); | 291 NOTIMPLEMENTED(); |
262 } | 292 } |
263 | 293 |
264 } // namespace shell | 294 } // namespace shell |
265 } // namespace sky | 295 } // namespace sky |
OLD | NEW |