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

Side by Side Diff: sky/viewer/document_view.cc

Issue 1203143004: Make it possible to run Sky apps offline (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: gn check Created 5 years, 5 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 | « sky/viewer/document_view.h ('k') | no next file » | 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 "sky/viewer/document_view.h" 5 #include "sky/viewer/document_view.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 18 matching lines...) Expand all
29 #include "sky/engine/public/web/Sky.h" 29 #include "sky/engine/public/web/Sky.h"
30 #include "sky/engine/public/web/WebConsoleMessage.h" 30 #include "sky/engine/public/web/WebConsoleMessage.h"
31 #include "sky/engine/public/web/WebDocument.h" 31 #include "sky/engine/public/web/WebDocument.h"
32 #include "sky/engine/public/web/WebElement.h" 32 #include "sky/engine/public/web/WebElement.h"
33 #include "sky/engine/public/web/WebLocalFrame.h" 33 #include "sky/engine/public/web/WebLocalFrame.h"
34 #include "sky/engine/public/web/WebScriptSource.h" 34 #include "sky/engine/public/web/WebScriptSource.h"
35 #include "sky/engine/public/web/WebSettings.h" 35 #include "sky/engine/public/web/WebSettings.h"
36 #include "sky/engine/public/web/WebView.h" 36 #include "sky/engine/public/web/WebView.h"
37 #include "sky/services/platform/url_request_types.h" 37 #include "sky/services/platform/url_request_types.h"
38 #include "sky/viewer/converters/input_event_types.h" 38 #include "sky/viewer/converters/input_event_types.h"
39 #include "sky/viewer/dart_library_provider_impl.h"
39 #include "sky/viewer/internals.h" 40 #include "sky/viewer/internals.h"
40 #include "sky/viewer/runtime_flags.h" 41 #include "sky/viewer/runtime_flags.h"
41 #include "third_party/skia/include/core/SkCanvas.h" 42 #include "third_party/skia/include/core/SkCanvas.h"
42 #include "third_party/skia/include/core/SkColor.h" 43 #include "third_party/skia/include/core/SkColor.h"
43 #include "third_party/skia/include/core/SkDevice.h" 44 #include "third_party/skia/include/core/SkDevice.h"
44 #include "ui/events/gestures/gesture_recognizer.h" 45 #include "ui/events/gestures/gesture_recognizer.h"
45 #include "v8/include/v8.h"
46 46
47 namespace sky { 47 namespace sky {
48 namespace { 48 namespace {
49 49
50 void ConfigureSettings(blink::WebSettings* settings) { 50 void ConfigureSettings(blink::WebSettings* settings) {
51 settings->setDefaultFixedFontSize(13); 51 settings->setDefaultFixedFontSize(13);
52 settings->setDefaultFontSize(16); 52 settings->setDefaultFontSize(16);
53 settings->setLoadsImagesAutomatically(true); 53 settings->setLoadsImagesAutomatically(true);
54 } 54 }
55 55
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 const blink::WebPointerEvent& pointer_event = 87 const blink::WebPointerEvent& pointer_event =
88 static_cast<const blink::WebPointerEvent&>(event); 88 static_cast<const blink::WebPointerEvent&>(event);
89 return make_scoped_ptr(new ui::TouchEvent( 89 return make_scoped_ptr(new ui::TouchEvent(
90 ConvertEventTypeToUIEventType(event.type), 90 ConvertEventTypeToUIEventType(event.type),
91 gfx::PointF(pointer_event.x * device_pixel_ratio, 91 gfx::PointF(pointer_event.x * device_pixel_ratio,
92 pointer_event.y * device_pixel_ratio), 92 pointer_event.y * device_pixel_ratio),
93 pointer_event.pointer, 93 pointer_event.pointer,
94 base::TimeDelta::FromMillisecondsD(pointer_event.timeStampMS))); 94 base::TimeDelta::FromMillisecondsD(pointer_event.timeStampMS)));
95 } 95 }
96 96
97 scoped_ptr<DartLibraryProviderImpl::PrefetchedLibrary>
98 CreatePrefetchedLibraryIfNeeded(const String& name,
99 mojo::URLResponsePtr response) {
100 scoped_ptr<DartLibraryProviderImpl::PrefetchedLibrary> prefetched;
101 if (response->status_code == 200) {
102 prefetched.reset(new DartLibraryProviderImpl::PrefetchedLibrary());
103 prefetched->name = name;
104 prefetched->pipe = response->body.Pass();
105 }
106 return prefetched.Pass();
107 }
108
97 } // namespace 109 } // namespace
98 110
99 DocumentView::DocumentView( 111 DocumentView::DocumentView(
100 mojo::InterfaceRequest<mojo::ServiceProvider> services, 112 mojo::InterfaceRequest<mojo::ServiceProvider> services,
101 mojo::ServiceProviderPtr exported_services, 113 mojo::ServiceProviderPtr exported_services,
102 mojo::URLResponsePtr response, 114 mojo::URLResponsePtr response,
103 mojo::Shell* shell) 115 mojo::Shell* shell)
104 : response_(response.Pass()), 116 : response_(response.Pass()),
105 exported_services_(services.Pass()), 117 exported_services_(services.Pass()),
106 imported_services_(exported_services.Pass()), 118 imported_services_(exported_services.Pass()),
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 root_->AddObserver(this); 166 root_->AddObserver(this);
155 } 167 }
156 168
157 void DocumentView::OnViewManagerDisconnected(mojo::ViewManager* view_manager) { 169 void DocumentView::OnViewManagerDisconnected(mojo::ViewManager* view_manager) {
158 // TODO(aa): Need to figure out how shutdown works. 170 // TODO(aa): Need to figure out how shutdown works.
159 } 171 }
160 void DocumentView::Load(mojo::URLResponsePtr response) { 172 void DocumentView::Load(mojo::URLResponsePtr response) {
161 GURL responseURL(response->url); 173 GURL responseURL(response->url);
162 174
163 if (!blink::WebView::shouldUseWebView(responseURL)) { 175 if (!blink::WebView::shouldUseWebView(responseURL)) {
176 String name = String::fromUTF8(responseURL.spec());
177 library_provider_.reset(new DartLibraryProviderImpl(
178 blink::Platform::current()->networkService(),
179 CreatePrefetchedLibraryIfNeeded(name, response.Pass())));
164 sky_view_ = blink::SkyView::Create(this); 180 sky_view_ = blink::SkyView::Create(this);
165 initializeLayerTreeView(); 181 initializeLayerTreeView();
166 sky_view_->Load(responseURL, response.Pass()); 182 sky_view_->RunFromLibrary(name, library_provider_.get());
167 return; 183 return;
168 } 184 }
169 185
170 if (!RuntimeFlags::Get().testing()) 186 if (!RuntimeFlags::Get().testing())
171 LOG(WARNING) << ".sky support is deprecated, please use .dart for main()"; 187 LOG(WARNING) << ".sky support is deprecated, please use .dart for main()";
172 188
173 web_view_ = blink::WebView::create(this); 189 web_view_ = blink::WebView::create(this);
174 ConfigureSettings(web_view_->settings()); 190 ConfigureSettings(web_view_->settings());
175 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); 191 web_view_->setMainFrame(blink::WebLocalFrame::create(this));
176 web_view_->mainFrame()->loadFromDataPipeWithURL( 192 web_view_->mainFrame()->loadFromDataPipeWithURL(
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 new mojo::StrongBinding<mojo::ServiceProvider>(sp_impl, &sp)); 456 new mojo::StrongBinding<mojo::ServiceProvider>(sp_impl, &sp));
441 service_registry_->AddServices(interface_names.Pass(), sp.Pass()); 457 service_registry_->AddServices(interface_names.Pass(), sp.Pass());
442 } 458 }
443 459
444 void DocumentView::ScheduleFrame() { 460 void DocumentView::ScheduleFrame() {
445 DCHECK(sky_view_); 461 DCHECK(sky_view_);
446 layer_host_->SetNeedsAnimate(); 462 layer_host_->SetNeedsAnimate();
447 } 463 }
448 464
449 } // namespace sky 465 } // namespace sky
OLDNEW
« no previous file with comments | « sky/viewer/document_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698