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_view.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" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
14 #include "mojo/public/cpp/application/connect.h" | 14 #include "mojo/public/cpp/application/connect.h" |
15 #include "mojo/public/cpp/system/data_pipe.h" | 15 #include "mojo/public/cpp/system/data_pipe.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 if (request.extraData()) | 78 if (request.extraData()) |
79 return true; | 79 return true; |
80 | 80 |
81 // Otherwise we don't know if we're the right app to handle this request. Ask | 81 // Otherwise we don't know if we're the right app to handle this request. Ask |
82 // host to do the navigation for us. | 82 // host to do the navigation for us. |
83 return false; | 83 return false; |
84 } | 84 } |
85 | 85 |
86 } // namespace | 86 } // namespace |
87 | 87 |
88 HTMLDocumentView::HTMLDocumentView( | 88 HTMLDocument::HTMLDocument( |
89 mojo::ServiceProviderPtr provider, | |
89 URLResponsePtr response, | 90 URLResponsePtr response, |
90 ShellPtr shell, | 91 Shell* shell, |
91 scoped_refptr<base::MessageLoopProxy> compositor_thread, | 92 scoped_refptr<base::MessageLoopProxy> compositor_thread, |
92 WebMediaPlayerFactory* web_media_player_factory) | 93 WebMediaPlayerFactory* web_media_player_factory) |
93 : response_(response.Pass()), | 94 : response_(response.Pass()), |
94 shell_(shell.Pass()), | 95 shell_(shell), |
95 web_view_(NULL), | 96 web_view_(NULL), |
96 root_(NULL), | 97 root_(NULL), |
97 view_manager_client_factory_(shell_.get(), this), | 98 view_manager_client_factory_(shell_, this), |
98 compositor_thread_(compositor_thread), | 99 compositor_thread_(compositor_thread), |
99 web_media_player_factory_(web_media_player_factory) { | 100 web_media_player_factory_(web_media_player_factory) { |
100 shell_.set_client(this); | 101 exported_services_.AddService(this); |
102 exported_services_.AddService(&view_manager_client_factory_); | |
103 WeakBindToPipe(&exported_services_, provider.PassMessagePipe()); | |
101 } | 104 } |
102 | 105 |
103 HTMLDocumentView::~HTMLDocumentView() { | 106 HTMLDocument::~HTMLDocument() { |
104 STLDeleteElements(&ax_provider_impls_); | 107 STLDeleteElements(&ax_provider_impls_); |
105 | 108 |
106 if (web_view_) | 109 if (web_view_) |
107 web_view_->close(); | 110 web_view_->close(); |
108 if (root_) | 111 if (root_) |
109 root_->RemoveObserver(this); | 112 root_->RemoveObserver(this); |
110 } | 113 } |
111 | 114 |
112 void HTMLDocumentView::AcceptConnection(const String& requestor_url, | 115 void HTMLDocument::OnEmbed( |
113 ServiceProviderPtr provider) { | |
114 exported_services_.AddService(this); | |
115 exported_services_.AddService(&view_manager_client_factory_); | |
116 WeakBindToPipe(&exported_services_, provider.PassMessagePipe()); | |
117 Load(response_.Pass()); | |
118 } | |
119 | |
120 void HTMLDocumentView::Initialize(Array<String> args) { | |
121 } | |
122 | |
123 void HTMLDocumentView::OnEmbed( | |
124 ViewManager* view_manager, | 116 ViewManager* view_manager, |
125 View* root, | 117 View* root, |
126 ServiceProviderImpl* embedee_service_provider_impl, | 118 ServiceProviderImpl* embedee_service_provider_impl, |
127 scoped_ptr<ServiceProvider> embedder_service_provider) { | 119 scoped_ptr<ServiceProvider> embedder_service_provider) { |
128 root_ = root; | 120 root_ = root; |
129 embedder_service_provider_ = embedder_service_provider.Pass(); | 121 embedder_service_provider_ = embedder_service_provider.Pass(); |
130 navigator_host_.set_service_provider(embedder_service_provider_.get()); | 122 navigator_host_.set_service_provider(embedder_service_provider_.get()); |
131 | 123 |
124 Load(response_.Pass()); | |
xhwang
2014/12/12 01:50:14
This is breaking my local test. In my chromium che
| |
125 | |
132 blink::WebSize root_size(root_->bounds().width, root_->bounds().height); | 126 blink::WebSize root_size(root_->bounds().width, root_->bounds().height); |
133 web_view_->resize(root_size); | 127 web_view_->resize(root_size); |
134 web_layer_tree_view_impl_->setViewportSize(root_size); | 128 web_layer_tree_view_impl_->setViewportSize(root_size); |
135 web_layer_tree_view_impl_->set_view(root_); | 129 web_layer_tree_view_impl_->set_view(root_); |
136 root_->AddObserver(this); | 130 root_->AddObserver(this); |
137 } | 131 } |
138 | 132 |
139 void HTMLDocumentView::Create(ApplicationConnection* connection, | 133 void HTMLDocument::Create(ApplicationConnection* connection, |
140 InterfaceRequest<AxProvider> request) { | 134 InterfaceRequest<AxProvider> request) { |
141 if (!web_view_) | 135 if (!web_view_) |
142 return; | 136 return; |
143 ax_provider_impls_.insert( | 137 ax_provider_impls_.insert( |
144 WeakBindToRequest(new AxProviderImpl(web_view_), &request)); | 138 WeakBindToRequest(new AxProviderImpl(web_view_), &request)); |
145 } | 139 } |
146 | 140 |
147 void HTMLDocumentView::OnViewManagerDisconnected(ViewManager* view_manager) { | 141 void HTMLDocument::OnViewManagerDisconnected(ViewManager* view_manager) { |
148 // TODO(aa): Need to figure out how shutdown works. | 142 // TODO(aa): Need to figure out how shutdown works. |
149 } | 143 } |
150 | 144 |
151 void HTMLDocumentView::Load(URLResponsePtr response) { | 145 void HTMLDocument::Load(URLResponsePtr response) { |
152 web_view_ = blink::WebView::create(this); | 146 web_view_ = blink::WebView::create(this); |
153 web_layer_tree_view_impl_->set_widget(web_view_); | 147 web_layer_tree_view_impl_->set_widget(web_view_); |
154 ConfigureSettings(web_view_->settings()); | 148 ConfigureSettings(web_view_->settings()); |
155 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); | 149 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); |
156 | 150 |
157 GURL url(response->url); | 151 GURL url(response->url); |
158 | 152 |
159 WebURLRequestExtraData* extra_data = new WebURLRequestExtraData; | 153 WebURLRequestExtraData* extra_data = new WebURLRequestExtraData; |
160 extra_data->synthetic_response = response.Pass(); | 154 extra_data->synthetic_response = response.Pass(); |
161 | 155 |
162 blink::WebURLRequest web_request; | 156 blink::WebURLRequest web_request; |
163 web_request.initialize(); | 157 web_request.initialize(); |
164 web_request.setURL(url); | 158 web_request.setURL(url); |
165 web_request.setExtraData(extra_data); | 159 web_request.setExtraData(extra_data); |
166 | 160 |
167 web_view_->mainFrame()->loadRequest(web_request); | 161 web_view_->mainFrame()->loadRequest(web_request); |
168 } | 162 } |
169 | 163 |
170 blink::WebStorageNamespace* HTMLDocumentView::createSessionStorageNamespace() { | 164 blink::WebStorageNamespace* HTMLDocument::createSessionStorageNamespace() { |
171 return new WebStorageNamespaceImpl(); | 165 return new WebStorageNamespaceImpl(); |
172 } | 166 } |
173 | 167 |
174 void HTMLDocumentView::initializeLayerTreeView() { | 168 void HTMLDocument::initializeLayerTreeView() { |
175 ServiceProviderPtr surfaces_service_provider; | 169 ServiceProviderPtr surfaces_service_provider; |
176 shell_->ConnectToApplication("mojo:surfaces_service", | 170 shell_->ConnectToApplication("mojo:surfaces_service", |
177 GetProxy(&surfaces_service_provider)); | 171 GetProxy(&surfaces_service_provider)); |
178 SurfacesServicePtr surfaces_service; | 172 SurfacesServicePtr surfaces_service; |
179 ConnectToService(surfaces_service_provider.get(), &surfaces_service); | 173 ConnectToService(surfaces_service_provider.get(), &surfaces_service); |
180 | 174 |
181 ServiceProviderPtr gpu_service_provider; | 175 ServiceProviderPtr gpu_service_provider; |
182 // TODO(jamesr): Should be mojo:gpu_service | 176 // TODO(jamesr): Should be mojo:gpu_service |
183 shell_->ConnectToApplication("mojo:native_viewport_service", | 177 shell_->ConnectToApplication("mojo:native_viewport_service", |
184 GetProxy(&gpu_service_provider)); | 178 GetProxy(&gpu_service_provider)); |
185 GpuPtr gpu_service; | 179 GpuPtr gpu_service; |
186 ConnectToService(gpu_service_provider.get(), &gpu_service); | 180 ConnectToService(gpu_service_provider.get(), &gpu_service); |
187 web_layer_tree_view_impl_.reset(new WebLayerTreeViewImpl( | 181 web_layer_tree_view_impl_.reset(new WebLayerTreeViewImpl( |
188 compositor_thread_, surfaces_service.Pass(), gpu_service.Pass())); | 182 compositor_thread_, surfaces_service.Pass(), gpu_service.Pass())); |
189 } | 183 } |
190 | 184 |
191 blink::WebLayerTreeView* HTMLDocumentView::layerTreeView() { | 185 blink::WebLayerTreeView* HTMLDocument::layerTreeView() { |
192 return web_layer_tree_view_impl_.get(); | 186 return web_layer_tree_view_impl_.get(); |
193 } | 187 } |
194 | 188 |
195 blink::WebMediaPlayer* HTMLDocumentView::createMediaPlayer( | 189 blink::WebMediaPlayer* HTMLDocument::createMediaPlayer( |
196 blink::WebLocalFrame* frame, | 190 blink::WebLocalFrame* frame, |
197 const blink::WebURL& url, | 191 const blink::WebURL& url, |
198 blink::WebMediaPlayerClient* client) { | 192 blink::WebMediaPlayerClient* client) { |
199 return web_media_player_factory_->CreateMediaPlayer( | 193 return web_media_player_factory_->CreateMediaPlayer(frame, url, client, |
200 frame, url, client, shell_.get()); | 194 shell_); |
201 } | 195 } |
202 | 196 |
203 blink::WebMediaPlayer* HTMLDocumentView::createMediaPlayer( | 197 blink::WebMediaPlayer* HTMLDocument::createMediaPlayer( |
204 blink::WebLocalFrame* frame, | 198 blink::WebLocalFrame* frame, |
205 const blink::WebURL& url, | 199 const blink::WebURL& url, |
206 blink::WebMediaPlayerClient* client, | 200 blink::WebMediaPlayerClient* client, |
207 blink::WebContentDecryptionModule* initial_cdm) { | 201 blink::WebContentDecryptionModule* initial_cdm) { |
208 return createMediaPlayer(frame, url, client); | 202 return createMediaPlayer(frame, url, client); |
209 } | 203 } |
210 | 204 |
211 blink::WebFrame* HTMLDocumentView::createChildFrame( | 205 blink::WebFrame* HTMLDocument::createChildFrame( |
212 blink::WebLocalFrame* parent, | 206 blink::WebLocalFrame* parent, |
213 const blink::WebString& frameName) { | 207 const blink::WebString& frameName) { |
214 blink::WebLocalFrame* web_frame = blink::WebLocalFrame::create(this); | 208 blink::WebLocalFrame* web_frame = blink::WebLocalFrame::create(this); |
215 parent->appendChild(web_frame); | 209 parent->appendChild(web_frame); |
216 return web_frame; | 210 return web_frame; |
217 } | 211 } |
218 | 212 |
219 void HTMLDocumentView::frameDetached(blink::WebFrame* frame) { | 213 void HTMLDocument::frameDetached(blink::WebFrame* frame) { |
220 if (frame->parent()) | 214 if (frame->parent()) |
221 frame->parent()->removeChild(frame); | 215 frame->parent()->removeChild(frame); |
222 | 216 |
223 // |frame| is invalid after here. | 217 // |frame| is invalid after here. |
224 frame->close(); | 218 frame->close(); |
225 } | 219 } |
226 | 220 |
227 blink::WebCookieJar* HTMLDocumentView::cookieJar(blink::WebLocalFrame* frame) { | 221 blink::WebCookieJar* HTMLDocument::cookieJar(blink::WebLocalFrame* frame) { |
228 // TODO(darin): Blink does not fallback to the Platform provided WebCookieJar. | 222 // TODO(darin): Blink does not fallback to the Platform provided WebCookieJar. |
229 // Either it should, as it once did, or we should find another solution here. | 223 // Either it should, as it once did, or we should find another solution here. |
230 return blink::Platform::current()->cookieJar(); | 224 return blink::Platform::current()->cookieJar(); |
231 } | 225 } |
232 | 226 |
233 blink::WebNavigationPolicy HTMLDocumentView::decidePolicyForNavigation( | 227 blink::WebNavigationPolicy HTMLDocument::decidePolicyForNavigation( |
234 blink::WebLocalFrame* frame, blink::WebDataSource::ExtraData* data, | 228 blink::WebLocalFrame* frame, |
235 const blink::WebURLRequest& request, blink::WebNavigationType nav_type, | 229 blink::WebDataSource::ExtraData* data, |
236 blink::WebNavigationPolicy default_policy, bool is_redirect) { | 230 const blink::WebURLRequest& request, |
231 blink::WebNavigationType nav_type, | |
232 blink::WebNavigationPolicy default_policy, | |
233 bool is_redirect) { | |
237 if (CanNavigateLocally(frame, request)) | 234 if (CanNavigateLocally(frame, request)) |
238 return default_policy; | 235 return default_policy; |
239 | 236 |
240 navigator_host_->RequestNavigate( | 237 navigator_host_->RequestNavigate( |
241 WebNavigationPolicyToNavigationTarget(default_policy), | 238 WebNavigationPolicyToNavigationTarget(default_policy), |
242 URLRequest::From(request).Pass()); | 239 URLRequest::From(request).Pass()); |
243 | 240 |
244 return blink::WebNavigationPolicyIgnore; | 241 return blink::WebNavigationPolicyIgnore; |
245 } | 242 } |
246 | 243 |
247 void HTMLDocumentView::didAddMessageToConsole( | 244 void HTMLDocument::didAddMessageToConsole( |
248 const blink::WebConsoleMessage& message, | 245 const blink::WebConsoleMessage& message, |
249 const blink::WebString& source_name, | 246 const blink::WebString& source_name, |
250 unsigned source_line, | 247 unsigned source_line, |
251 const blink::WebString& stack_trace) { | 248 const blink::WebString& stack_trace) { |
252 } | 249 } |
253 | 250 |
254 void HTMLDocumentView::didNavigateWithinPage( | 251 void HTMLDocument::didNavigateWithinPage( |
255 blink::WebLocalFrame* frame, const blink::WebHistoryItem& history_item, | 252 blink::WebLocalFrame* frame, |
253 const blink::WebHistoryItem& history_item, | |
256 blink::WebHistoryCommitType commit_type) { | 254 blink::WebHistoryCommitType commit_type) { |
257 navigator_host_->DidNavigateLocally(history_item.urlString().utf8()); | 255 navigator_host_->DidNavigateLocally(history_item.urlString().utf8()); |
258 } | 256 } |
259 | 257 |
260 void HTMLDocumentView::OnViewBoundsChanged(View* view, | 258 void HTMLDocument::OnViewBoundsChanged(View* view, |
261 const Rect& old_bounds, | 259 const Rect& old_bounds, |
262 const Rect& new_bounds) { | 260 const Rect& new_bounds) { |
263 DCHECK_EQ(view, root_); | 261 DCHECK_EQ(view, root_); |
264 web_view_->resize( | 262 web_view_->resize( |
265 blink::WebSize(view->bounds().width, view->bounds().height)); | 263 blink::WebSize(view->bounds().width, view->bounds().height)); |
266 } | 264 } |
267 | 265 |
268 void HTMLDocumentView::OnViewDestroyed(View* view) { | 266 void HTMLDocument::OnViewDestroyed(View* view) { |
269 DCHECK_EQ(view, root_); | 267 DCHECK_EQ(view, root_); |
270 view->RemoveObserver(this); | 268 root_ = nullptr; |
271 root_ = NULL; | |
272 } | 269 } |
273 | 270 |
274 void HTMLDocumentView::OnViewInputEvent(View* view, const EventPtr& event) { | 271 void HTMLDocument::OnViewInputEvent(View* view, const EventPtr& event) { |
275 scoped_ptr<blink::WebInputEvent> web_event = | 272 scoped_ptr<blink::WebInputEvent> web_event = |
276 event.To<scoped_ptr<blink::WebInputEvent> >(); | 273 event.To<scoped_ptr<blink::WebInputEvent>>(); |
277 if (web_event) | 274 if (web_event) |
278 web_view_->handleInputEvent(*web_event); | 275 web_view_->handleInputEvent(*web_event); |
279 } | 276 } |
280 | 277 |
281 } // namespace mojo | 278 } // namespace mojo |
OLD | NEW |