OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/controls/webview/webview.h" | 5 #include "ui/views/controls/webview/webview.h" |
6 | 6 |
7 #include "content/public/browser/browser_accessibility_state.h" | 7 #include "content/public/browser/browser_accessibility_state.h" |
8 #include "content/public/browser/browser_context.h" | 8 #include "content/public/browser/browser_context.h" |
9 #include "content/public/browser/navigation_controller.h" | 9 #include "content/public/browser/navigation_controller.h" |
10 #include "content/public/browser/render_process_host.h" | 10 #include "content/public/browser/render_process_host.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 SetFocusable(!!web_contents()); | 71 SetFocusable(!!web_contents()); |
72 if (wc_owner_ != replacement) | 72 if (wc_owner_ != replacement) |
73 wc_owner_.reset(); | 73 wc_owner_.reset(); |
74 if (embed_fullscreen_widget_mode_enabled_) { | 74 if (embed_fullscreen_widget_mode_enabled_) { |
75 is_embedding_fullscreen_widget_ = | 75 is_embedding_fullscreen_widget_ = |
76 web_contents() && web_contents()->GetFullscreenRenderWidgetHostView(); | 76 web_contents() && web_contents()->GetFullscreenRenderWidgetHostView(); |
77 } else { | 77 } else { |
78 DCHECK(!is_embedding_fullscreen_widget_); | 78 DCHECK(!is_embedding_fullscreen_widget_); |
79 } | 79 } |
80 AttachWebContents(); | 80 AttachWebContents(); |
81 NotifyMaybeTextInputClientChanged(); | 81 NotifyMaybeTextInputClientAndAccessibilityChanged(); |
82 } | 82 } |
83 | 83 |
84 void WebView::SetEmbedFullscreenWidgetMode(bool enable) { | 84 void WebView::SetEmbedFullscreenWidgetMode(bool enable) { |
85 DCHECK(!web_contents()) | 85 DCHECK(!web_contents()) |
86 << "Cannot change mode while a WebContents is attached."; | 86 << "Cannot change mode while a WebContents is attached."; |
87 embed_fullscreen_widget_mode_enabled_ = enable; | 87 embed_fullscreen_widget_mode_enabled_ = enable; |
88 } | 88 } |
89 | 89 |
90 void WebView::LoadInitialURL(const GURL& url) { | 90 void WebView::LoadInitialURL(const GURL& url) { |
91 GetWebContents()->GetController().LoadURL( | 91 GetWebContents()->GetController().LoadURL( |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 else | 259 else |
260 return preferred_size_; | 260 return preferred_size_; |
261 } | 261 } |
262 | 262 |
263 //////////////////////////////////////////////////////////////////////////////// | 263 //////////////////////////////////////////////////////////////////////////////// |
264 // WebView, content::RenderProcessHostObserver implementation: | 264 // WebView, content::RenderProcessHostObserver implementation: |
265 | 265 |
266 void WebView::RenderProcessExited(content::RenderProcessHost* host, | 266 void WebView::RenderProcessExited(content::RenderProcessHost* host, |
267 base::TerminationStatus status, | 267 base::TerminationStatus status, |
268 int exit_code) { | 268 int exit_code) { |
269 NotifyMaybeTextInputClientChanged(); | 269 NotifyMaybeTextInputClientAndAccessibilityChanged(); |
270 } | 270 } |
271 | 271 |
272 void WebView::RenderProcessHostDestroyed(content::RenderProcessHost* host) { | 272 void WebView::RenderProcessHostDestroyed(content::RenderProcessHost* host) { |
273 DCHECK_EQ(host, observing_render_process_host_); | 273 DCHECK_EQ(host, observing_render_process_host_); |
274 observing_render_process_host_->RemoveObserver(this); | 274 observing_render_process_host_->RemoveObserver(this); |
275 observing_render_process_host_ = nullptr; | 275 observing_render_process_host_ = nullptr; |
276 } | 276 } |
277 | 277 |
278 //////////////////////////////////////////////////////////////////////////////// | 278 //////////////////////////////////////////////////////////////////////////////// |
279 // WebView, content::WebContentsDelegate implementation: | 279 // WebView, content::WebContentsDelegate implementation: |
280 | 280 |
281 void WebView::WebContentsFocused(content::WebContents* web_contents) { | 281 void WebView::WebContentsFocused(content::WebContents* web_contents) { |
282 DCHECK(wc_owner_.get()); | 282 DCHECK(wc_owner_.get()); |
283 // The WebView is only the delegate of WebContentses it creates itself. | 283 // The WebView is only the delegate of WebContentses it creates itself. |
284 OnWebContentsFocused(wc_owner_.get()); | 284 OnWebContentsFocused(wc_owner_.get()); |
285 } | 285 } |
286 | 286 |
287 bool WebView::EmbedsFullscreenWidget() const { | 287 bool WebView::EmbedsFullscreenWidget() const { |
288 DCHECK(wc_owner_.get()); | 288 DCHECK(wc_owner_.get()); |
289 return embed_fullscreen_widget_mode_enabled_; | 289 return embed_fullscreen_widget_mode_enabled_; |
290 } | 290 } |
291 | 291 |
292 //////////////////////////////////////////////////////////////////////////////// | 292 //////////////////////////////////////////////////////////////////////////////// |
293 // WebView, content::WebContentsObserver implementation: | 293 // WebView, content::WebContentsObserver implementation: |
294 | 294 |
295 void WebView::RenderViewReady() { | 295 void WebView::RenderViewReady() { |
296 NotifyMaybeTextInputClientChanged(); | 296 NotifyMaybeTextInputClientAndAccessibilityChanged(); |
297 } | 297 } |
298 | 298 |
299 void WebView::RenderViewDeleted(content::RenderViewHost* render_view_host) { | 299 void WebView::RenderViewDeleted(content::RenderViewHost* render_view_host) { |
300 NotifyMaybeTextInputClientChanged(); | 300 NotifyMaybeTextInputClientAndAccessibilityChanged(); |
301 } | 301 } |
302 | 302 |
303 void WebView::RenderViewHostChanged(content::RenderViewHost* old_host, | 303 void WebView::RenderViewHostChanged(content::RenderViewHost* old_host, |
304 content::RenderViewHost* new_host) { | 304 content::RenderViewHost* new_host) { |
305 FocusManager* const focus_manager = GetFocusManager(); | 305 FocusManager* const focus_manager = GetFocusManager(); |
306 if (focus_manager && focus_manager->GetFocusedView() == this) | 306 if (focus_manager && focus_manager->GetFocusedView() == this) |
307 OnFocus(); | 307 OnFocus(); |
308 NotifyMaybeTextInputClientChanged(); | 308 NotifyMaybeTextInputClientAndAccessibilityChanged(); |
309 } | 309 } |
310 | 310 |
311 void WebView::WebContentsDestroyed() { | 311 void WebView::WebContentsDestroyed() { |
312 if (observing_render_process_host_) { | 312 if (observing_render_process_host_) { |
313 observing_render_process_host_->RemoveObserver(this); | 313 observing_render_process_host_->RemoveObserver(this); |
314 observing_render_process_host_ = nullptr; | 314 observing_render_process_host_ = nullptr; |
315 } | 315 } |
316 NotifyMaybeTextInputClientChanged(); | 316 NotifyMaybeTextInputClientAndAccessibilityChanged(); |
317 } | 317 } |
318 | 318 |
319 void WebView::DidShowFullscreenWidget(int routing_id) { | 319 void WebView::DidShowFullscreenWidget(int routing_id) { |
320 if (embed_fullscreen_widget_mode_enabled_) | 320 if (embed_fullscreen_widget_mode_enabled_) |
321 ReattachForFullscreenChange(true); | 321 ReattachForFullscreenChange(true); |
322 } | 322 } |
323 | 323 |
324 void WebView::DidDestroyFullscreenWidget(int routing_id) { | 324 void WebView::DidDestroyFullscreenWidget(int routing_id) { |
325 if (embed_fullscreen_widget_mode_enabled_) | 325 if (embed_fullscreen_widget_mode_enabled_) |
326 ReattachForFullscreenChange(false); | 326 ReattachForFullscreenChange(false); |
327 } | 327 } |
328 | 328 |
329 void WebView::DidToggleFullscreenModeForTab(bool entered_fullscreen) { | 329 void WebView::DidToggleFullscreenModeForTab(bool entered_fullscreen) { |
330 if (embed_fullscreen_widget_mode_enabled_) | 330 if (embed_fullscreen_widget_mode_enabled_) |
331 ReattachForFullscreenChange(entered_fullscreen); | 331 ReattachForFullscreenChange(entered_fullscreen); |
332 } | 332 } |
333 | 333 |
334 void WebView::DidAttachInterstitialPage() { | 334 void WebView::DidAttachInterstitialPage() { |
335 NotifyMaybeTextInputClientChanged(); | 335 NotifyMaybeTextInputClientAndAccessibilityChanged(); |
336 } | 336 } |
337 | 337 |
338 void WebView::DidDetachInterstitialPage() { | 338 void WebView::DidDetachInterstitialPage() { |
339 NotifyMaybeTextInputClientChanged(); | 339 NotifyMaybeTextInputClientAndAccessibilityChanged(); |
340 } | 340 } |
341 | 341 |
342 //////////////////////////////////////////////////////////////////////////////// | 342 //////////////////////////////////////////////////////////////////////////////// |
343 // WebView, private: | 343 // WebView, private: |
344 | 344 |
345 void WebView::AttachWebContents() { | 345 void WebView::AttachWebContents() { |
346 // Prevents attachment if the WebView isn't already in a Widget, or it's | 346 // Prevents attachment if the WebView isn't already in a Widget, or it's |
347 // already attached. | 347 // already attached. |
348 if (!GetWidget() || !web_contents()) | 348 if (!GetWidget() || !web_contents()) |
349 return; | 349 return; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 // widget. Need to detach and re-attach to a different native view. | 391 // widget. Need to detach and re-attach to a different native view. |
392 DetachWebContents(); | 392 DetachWebContents(); |
393 is_embedding_fullscreen_widget_ = | 393 is_embedding_fullscreen_widget_ = |
394 enter_fullscreen && web_contents_has_separate_fs_widget; | 394 enter_fullscreen && web_contents_has_separate_fs_widget; |
395 AttachWebContents(); | 395 AttachWebContents(); |
396 } else { | 396 } else { |
397 // Entering or exiting "non-Flash" fullscreen mode, where the native view is | 397 // Entering or exiting "non-Flash" fullscreen mode, where the native view is |
398 // the same. So, do not change attachment. | 398 // the same. So, do not change attachment. |
399 OnBoundsChanged(bounds()); | 399 OnBoundsChanged(bounds()); |
400 } | 400 } |
401 NotifyMaybeTextInputClientChanged(); | 401 NotifyMaybeTextInputClientAndAccessibilityChanged(); |
402 } | 402 } |
403 | 403 |
404 void WebView::NotifyMaybeTextInputClientChanged() { | 404 void WebView::NotifyMaybeTextInputClientAndAccessibilityChanged() { |
405 // Update the TextInputClient as needed; see GetTextInputClient(). | 405 // Update the TextInputClient as needed; see GetTextInputClient(). |
406 FocusManager* const focus_manager = GetFocusManager(); | 406 FocusManager* const focus_manager = GetFocusManager(); |
407 if (focus_manager) | 407 if (focus_manager) |
408 focus_manager->OnTextInputClientChanged(this); | 408 focus_manager->OnTextInputClientChanged(this); |
| 409 |
| 410 #if defined(OS_CHROMEOS) |
| 411 if (!web_contents()) |
| 412 parent()->NotifyAccessibilityEvent(ui::AX_EVENT_CHILDREN_CHANGED, true); |
| 413 else |
| 414 NotifyAccessibilityEvent(ui::AX_EVENT_CHILDREN_CHANGED, true); |
| 415 #endif // defined OS_CHROMEOS |
409 } | 416 } |
410 | 417 |
411 content::WebContents* WebView::CreateWebContents( | 418 content::WebContents* WebView::CreateWebContents( |
412 content::BrowserContext* browser_context) { | 419 content::BrowserContext* browser_context) { |
413 content::WebContents* contents = NULL; | 420 content::WebContents* contents = NULL; |
414 if (ViewsDelegate::views_delegate) { | 421 if (ViewsDelegate::views_delegate) { |
415 contents = ViewsDelegate::views_delegate->CreateWebContents( | 422 contents = ViewsDelegate::views_delegate->CreateWebContents( |
416 browser_context, NULL); | 423 browser_context, NULL); |
417 } | 424 } |
418 | 425 |
419 if (!contents) { | 426 if (!contents) { |
420 content::WebContents::CreateParams create_params( | 427 content::WebContents::CreateParams create_params( |
421 browser_context, NULL); | 428 browser_context, NULL); |
422 return content::WebContents::Create(create_params); | 429 return content::WebContents::Create(create_params); |
423 } | 430 } |
424 | 431 |
425 return contents; | 432 return contents; |
426 } | 433 } |
427 | 434 |
428 } // namespace views | 435 } // namespace views |
OLD | NEW |