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 "mojo/services/html_viewer/html_document.h" | 5 #include "mojo/services/html_viewer/html_document.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/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "third_party/WebKit/public/web/WebElement.h" | 31 #include "third_party/WebKit/public/web/WebElement.h" |
32 #include "third_party/WebKit/public/web/WebInputEvent.h" | 32 #include "third_party/WebKit/public/web/WebInputEvent.h" |
33 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 33 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
34 #include "third_party/WebKit/public/web/WebScriptSource.h" | 34 #include "third_party/WebKit/public/web/WebScriptSource.h" |
35 #include "third_party/WebKit/public/web/WebSettings.h" | 35 #include "third_party/WebKit/public/web/WebSettings.h" |
36 #include "third_party/WebKit/public/web/WebView.h" | 36 #include "third_party/WebKit/public/web/WebView.h" |
37 #include "third_party/skia/include/core/SkCanvas.h" | 37 #include "third_party/skia/include/core/SkCanvas.h" |
38 #include "third_party/skia/include/core/SkColor.h" | 38 #include "third_party/skia/include/core/SkColor.h" |
39 #include "third_party/skia/include/core/SkDevice.h" | 39 #include "third_party/skia/include/core/SkDevice.h" |
40 | 40 |
41 namespace mojo { | 41 using mojo::AxProvider; |
| 42 using mojo::Rect; |
| 43 using mojo::ServiceProviderPtr; |
| 44 using mojo::URLResponsePtr; |
| 45 using mojo::View; |
| 46 using mojo::ViewManager; |
| 47 |
| 48 namespace html_viewer { |
42 namespace { | 49 namespace { |
43 | 50 |
44 void ConfigureSettings(blink::WebSettings* settings) { | 51 void ConfigureSettings(blink::WebSettings* settings) { |
45 settings->setCookieEnabled(true); | 52 settings->setCookieEnabled(true); |
46 settings->setDefaultFixedFontSize(13); | 53 settings->setDefaultFixedFontSize(13); |
47 settings->setDefaultFontSize(16); | 54 settings->setDefaultFontSize(16); |
48 settings->setLoadsImagesAutomatically(true); | 55 settings->setLoadsImagesAutomatically(true); |
49 settings->setJavaScriptEnabled(true); | 56 settings->setJavaScriptEnabled(true); |
50 } | 57 } |
51 | 58 |
52 Target WebNavigationPolicyToNavigationTarget( | 59 mojo::Target WebNavigationPolicyToNavigationTarget( |
53 blink::WebNavigationPolicy policy) { | 60 blink::WebNavigationPolicy policy) { |
54 switch (policy) { | 61 switch (policy) { |
55 case blink::WebNavigationPolicyCurrentTab: | 62 case blink::WebNavigationPolicyCurrentTab: |
56 return TARGET_SOURCE_NODE; | 63 return mojo::TARGET_SOURCE_NODE; |
57 case blink::WebNavigationPolicyNewBackgroundTab: | 64 case blink::WebNavigationPolicyNewBackgroundTab: |
58 case blink::WebNavigationPolicyNewForegroundTab: | 65 case blink::WebNavigationPolicyNewForegroundTab: |
59 case blink::WebNavigationPolicyNewWindow: | 66 case blink::WebNavigationPolicyNewWindow: |
60 case blink::WebNavigationPolicyNewPopup: | 67 case blink::WebNavigationPolicyNewPopup: |
61 return TARGET_NEW_NODE; | 68 return mojo::TARGET_NEW_NODE; |
62 default: | 69 default: |
63 return TARGET_DEFAULT; | 70 return mojo::TARGET_DEFAULT; |
64 } | 71 } |
65 } | 72 } |
66 | 73 |
67 bool CanNavigateLocally(blink::WebFrame* frame, | 74 bool CanNavigateLocally(blink::WebFrame* frame, |
68 const blink::WebURLRequest& request) { | 75 const blink::WebURLRequest& request) { |
69 // For now, we just load child frames locally. | 76 // For now, we just load child frames locally. |
70 // TODO(aa): In the future, this should use embedding to connect to a | 77 // TODO(aa): In the future, this should use embedding to connect to a |
71 // different instance of Blink if the frame is cross-origin. | 78 // different instance of Blink if the frame is cross-origin. |
72 if (frame->parent()) | 79 if (frame->parent()) |
73 return true; | 80 return true; |
74 | 81 |
75 // If we have extraData() it means we already have the url response | 82 // If we have extraData() it means we already have the url response |
76 // (presumably because we are being called via Navigate()). In that case we | 83 // (presumably because we are being called via Navigate()). In that case we |
77 // can go ahead and navigate locally. | 84 // can go ahead and navigate locally. |
78 if (request.extraData()) | 85 if (request.extraData()) |
79 return true; | 86 return true; |
80 | 87 |
81 // Otherwise we don't know if we're the right app to handle this request. Ask | 88 // Otherwise we don't know if we're the right app to handle this request. Ask |
82 // host to do the navigation for us. | 89 // host to do the navigation for us. |
83 return false; | 90 return false; |
84 } | 91 } |
85 | 92 |
86 } // namespace | 93 } // namespace |
87 | 94 |
88 HTMLDocument::HTMLDocument( | 95 HTMLDocument::HTMLDocument( |
89 mojo::ServiceProviderPtr provider, | 96 mojo::ServiceProviderPtr provider, |
90 URLResponsePtr response, | 97 URLResponsePtr response, |
91 Shell* shell, | 98 mojo::Shell* shell, |
92 scoped_refptr<base::MessageLoopProxy> compositor_thread, | 99 scoped_refptr<base::MessageLoopProxy> compositor_thread, |
93 WebMediaPlayerFactory* web_media_player_factory) | 100 WebMediaPlayerFactory* web_media_player_factory) |
94 : response_(response.Pass()), | 101 : response_(response.Pass()), |
95 shell_(shell), | 102 shell_(shell), |
96 web_view_(NULL), | 103 web_view_(NULL), |
97 root_(NULL), | 104 root_(NULL), |
98 view_manager_client_factory_(shell_, this), | 105 view_manager_client_factory_(shell_, this), |
99 compositor_thread_(compositor_thread), | 106 compositor_thread_(compositor_thread), |
100 web_media_player_factory_(web_media_player_factory) { | 107 web_media_player_factory_(web_media_player_factory) { |
101 exported_services_.AddService(this); | 108 exported_services_.AddService(this); |
102 exported_services_.AddService(&view_manager_client_factory_); | 109 exported_services_.AddService(&view_manager_client_factory_); |
103 WeakBindToPipe(&exported_services_, provider.PassMessagePipe()); | 110 WeakBindToPipe(&exported_services_, provider.PassMessagePipe()); |
104 Load(response_.Pass()); | 111 Load(response_.Pass()); |
105 } | 112 } |
106 | 113 |
107 HTMLDocument::~HTMLDocument() { | 114 HTMLDocument::~HTMLDocument() { |
108 STLDeleteElements(&ax_provider_impls_); | 115 STLDeleteElements(&ax_provider_impls_); |
109 | 116 |
110 if (web_view_) | 117 if (web_view_) |
111 web_view_->close(); | 118 web_view_->close(); |
112 if (root_) | 119 if (root_) |
113 root_->RemoveObserver(this); | 120 root_->RemoveObserver(this); |
114 } | 121 } |
115 | 122 |
116 void HTMLDocument::OnEmbed( | 123 void HTMLDocument::OnEmbed( |
117 ViewManager* view_manager, | 124 ViewManager* view_manager, |
118 View* root, | 125 View* root, |
119 ServiceProviderImpl* embedee_service_provider_impl, | 126 mojo::ServiceProviderImpl* embedee_service_provider_impl, |
120 scoped_ptr<ServiceProvider> embedder_service_provider) { | 127 scoped_ptr<mojo::ServiceProvider> embedder_service_provider) { |
121 root_ = root; | 128 root_ = root; |
122 embedder_service_provider_ = embedder_service_provider.Pass(); | 129 embedder_service_provider_ = embedder_service_provider.Pass(); |
123 navigator_host_.set_service_provider(embedder_service_provider_.get()); | 130 navigator_host_.set_service_provider(embedder_service_provider_.get()); |
124 | 131 |
125 blink::WebSize root_size(root_->bounds().width, root_->bounds().height); | 132 blink::WebSize root_size(root_->bounds().width, root_->bounds().height); |
126 web_view_->resize(root_size); | 133 web_view_->resize(root_size); |
127 web_layer_tree_view_impl_->setViewportSize(root_size); | 134 web_layer_tree_view_impl_->setViewportSize(root_size); |
128 web_layer_tree_view_impl_->set_view(root_); | 135 web_layer_tree_view_impl_->set_view(root_); |
129 root_->AddObserver(this); | 136 root_->AddObserver(this); |
130 } | 137 } |
131 | 138 |
132 void HTMLDocument::Create(ApplicationConnection* connection, | 139 void HTMLDocument::Create(mojo::ApplicationConnection* connection, |
133 InterfaceRequest<AxProvider> request) { | 140 mojo::InterfaceRequest<AxProvider> request) { |
134 if (!web_view_) | 141 if (!web_view_) |
135 return; | 142 return; |
136 ax_provider_impls_.insert( | 143 ax_provider_impls_.insert( |
137 WeakBindToRequest(new AxProviderImpl(web_view_), &request)); | 144 WeakBindToRequest(new AxProviderImpl(web_view_), &request)); |
138 } | 145 } |
139 | 146 |
140 void HTMLDocument::OnViewManagerDisconnected(ViewManager* view_manager) { | 147 void HTMLDocument::OnViewManagerDisconnected(ViewManager* view_manager) { |
141 // TODO(aa): Need to figure out how shutdown works. | 148 // TODO(aa): Need to figure out how shutdown works. |
142 } | 149 } |
143 | 150 |
(...skipping 17 matching lines...) Expand all Loading... |
161 } | 168 } |
162 | 169 |
163 blink::WebStorageNamespace* HTMLDocument::createSessionStorageNamespace() { | 170 blink::WebStorageNamespace* HTMLDocument::createSessionStorageNamespace() { |
164 return new WebStorageNamespaceImpl(); | 171 return new WebStorageNamespaceImpl(); |
165 } | 172 } |
166 | 173 |
167 void HTMLDocument::initializeLayerTreeView() { | 174 void HTMLDocument::initializeLayerTreeView() { |
168 ServiceProviderPtr surfaces_service_provider; | 175 ServiceProviderPtr surfaces_service_provider; |
169 shell_->ConnectToApplication("mojo:surfaces_service", | 176 shell_->ConnectToApplication("mojo:surfaces_service", |
170 GetProxy(&surfaces_service_provider)); | 177 GetProxy(&surfaces_service_provider)); |
171 SurfacesServicePtr surfaces_service; | 178 mojo::SurfacesServicePtr surfaces_service; |
172 ConnectToService(surfaces_service_provider.get(), &surfaces_service); | 179 ConnectToService(surfaces_service_provider.get(), &surfaces_service); |
173 | 180 |
174 ServiceProviderPtr gpu_service_provider; | 181 ServiceProviderPtr gpu_service_provider; |
175 // TODO(jamesr): Should be mojo:gpu_service | 182 // TODO(jamesr): Should be mojo:gpu_service |
176 shell_->ConnectToApplication("mojo:native_viewport_service", | 183 shell_->ConnectToApplication("mojo:native_viewport_service", |
177 GetProxy(&gpu_service_provider)); | 184 GetProxy(&gpu_service_provider)); |
178 GpuPtr gpu_service; | 185 mojo::GpuPtr gpu_service; |
179 ConnectToService(gpu_service_provider.get(), &gpu_service); | 186 ConnectToService(gpu_service_provider.get(), &gpu_service); |
180 web_layer_tree_view_impl_.reset(new WebLayerTreeViewImpl( | 187 web_layer_tree_view_impl_.reset(new WebLayerTreeViewImpl( |
181 compositor_thread_, surfaces_service.Pass(), gpu_service.Pass())); | 188 compositor_thread_, surfaces_service.Pass(), gpu_service.Pass())); |
182 } | 189 } |
183 | 190 |
184 blink::WebLayerTreeView* HTMLDocument::layerTreeView() { | 191 blink::WebLayerTreeView* HTMLDocument::layerTreeView() { |
185 return web_layer_tree_view_impl_.get(); | 192 return web_layer_tree_view_impl_.get(); |
186 } | 193 } |
187 | 194 |
188 blink::WebMediaPlayer* HTMLDocument::createMediaPlayer( | 195 blink::WebMediaPlayer* HTMLDocument::createMediaPlayer( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 blink::WebDataSource::ExtraData* data, | 235 blink::WebDataSource::ExtraData* data, |
229 const blink::WebURLRequest& request, | 236 const blink::WebURLRequest& request, |
230 blink::WebNavigationType nav_type, | 237 blink::WebNavigationType nav_type, |
231 blink::WebNavigationPolicy default_policy, | 238 blink::WebNavigationPolicy default_policy, |
232 bool is_redirect) { | 239 bool is_redirect) { |
233 if (CanNavigateLocally(frame, request)) | 240 if (CanNavigateLocally(frame, request)) |
234 return default_policy; | 241 return default_policy; |
235 | 242 |
236 navigator_host_->RequestNavigate( | 243 navigator_host_->RequestNavigate( |
237 WebNavigationPolicyToNavigationTarget(default_policy), | 244 WebNavigationPolicyToNavigationTarget(default_policy), |
238 URLRequest::From(request).Pass()); | 245 mojo::URLRequest::From(request).Pass()); |
239 | 246 |
240 return blink::WebNavigationPolicyIgnore; | 247 return blink::WebNavigationPolicyIgnore; |
241 } | 248 } |
242 | 249 |
243 void HTMLDocument::didAddMessageToConsole( | 250 void HTMLDocument::didAddMessageToConsole( |
244 const blink::WebConsoleMessage& message, | 251 const blink::WebConsoleMessage& message, |
245 const blink::WebString& source_name, | 252 const blink::WebString& source_name, |
246 unsigned source_line, | 253 unsigned source_line, |
247 const blink::WebString& stack_trace) { | 254 const blink::WebString& stack_trace) { |
248 } | 255 } |
(...skipping 11 matching lines...) Expand all Loading... |
260 DCHECK_EQ(view, root_); | 267 DCHECK_EQ(view, root_); |
261 web_view_->resize( | 268 web_view_->resize( |
262 blink::WebSize(view->bounds().width, view->bounds().height)); | 269 blink::WebSize(view->bounds().width, view->bounds().height)); |
263 } | 270 } |
264 | 271 |
265 void HTMLDocument::OnViewDestroyed(View* view) { | 272 void HTMLDocument::OnViewDestroyed(View* view) { |
266 DCHECK_EQ(view, root_); | 273 DCHECK_EQ(view, root_); |
267 root_ = nullptr; | 274 root_ = nullptr; |
268 } | 275 } |
269 | 276 |
270 void HTMLDocument::OnViewInputEvent(View* view, const EventPtr& event) { | 277 void HTMLDocument::OnViewInputEvent(View* view, const mojo::EventPtr& event) { |
271 scoped_ptr<blink::WebInputEvent> web_event = | 278 scoped_ptr<blink::WebInputEvent> web_event = |
272 event.To<scoped_ptr<blink::WebInputEvent>>(); | 279 event.To<scoped_ptr<blink::WebInputEvent>>(); |
273 if (web_event) | 280 if (web_event) |
274 web_view_->handleInputEvent(*web_event); | 281 web_view_->handleInputEvent(*web_event); |
275 } | 282 } |
276 | 283 |
277 } // namespace mojo | 284 } // namespace html_viewer |
OLD | NEW |