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

Side by Side Diff: ui/views/controls/webview/webview.cc

Issue 880063002: Ensure WebView notifies desktop automation on creation, destruction, and change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Wait for start. Created 5 years, 10 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
OLDNEW
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
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
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_ = nullptr; 274 observing_render_process_host_ = nullptr;
275 } 275 }
276 276
277 //////////////////////////////////////////////////////////////////////////////// 277 ////////////////////////////////////////////////////////////////////////////////
278 // WebView, content::WebContentsDelegate implementation: 278 // WebView, content::WebContentsDelegate implementation:
279 279
280 void WebView::WebContentsFocused(content::WebContents* web_contents) { 280 void WebView::WebContentsFocused(content::WebContents* web_contents) {
281 DCHECK(wc_owner_.get()); 281 DCHECK(wc_owner_.get());
282 // The WebView is only the delegate of WebContentses it creates itself. 282 // The WebView is only the delegate of WebContentses it creates itself.
283 OnWebContentsFocused(wc_owner_.get()); 283 OnWebContentsFocused(wc_owner_.get());
284 } 284 }
285 285
286 bool WebView::EmbedsFullscreenWidget() const { 286 bool WebView::EmbedsFullscreenWidget() const {
287 DCHECK(wc_owner_.get()); 287 DCHECK(wc_owner_.get());
288 return embed_fullscreen_widget_mode_enabled_; 288 return embed_fullscreen_widget_mode_enabled_;
289 } 289 }
290 290
291 //////////////////////////////////////////////////////////////////////////////// 291 ////////////////////////////////////////////////////////////////////////////////
292 // WebView, content::WebContentsObserver implementation: 292 // WebView, content::WebContentsObserver implementation:
293 293
294 void WebView::RenderViewReady() { 294 void WebView::RenderViewReady() {
295 NotifyMaybeTextInputClientChanged(); 295 NotifyMaybeTextInputClientAndAccessibilityChanged();
296 } 296 }
297 297
298 void WebView::RenderViewDeleted(content::RenderViewHost* render_view_host) { 298 void WebView::RenderViewDeleted(content::RenderViewHost* render_view_host) {
299 NotifyMaybeTextInputClientChanged(); 299 NotifyMaybeTextInputClientAndAccessibilityChanged();
300 } 300 }
301 301
302 void WebView::RenderViewHostChanged(content::RenderViewHost* old_host, 302 void WebView::RenderViewHostChanged(content::RenderViewHost* old_host,
303 content::RenderViewHost* new_host) { 303 content::RenderViewHost* new_host) {
304 FocusManager* const focus_manager = GetFocusManager(); 304 FocusManager* const focus_manager = GetFocusManager();
305 if (focus_manager && focus_manager->GetFocusedView() == this) 305 if (focus_manager && focus_manager->GetFocusedView() == this)
306 OnFocus(); 306 OnFocus();
307 NotifyMaybeTextInputClientChanged(); 307 NotifyMaybeTextInputClientAndAccessibilityChanged();
308 } 308 }
309 309
310 void WebView::WebContentsDestroyed() { 310 void WebView::WebContentsDestroyed() {
311 if (observing_render_process_host_) { 311 if (observing_render_process_host_) {
312 observing_render_process_host_->RemoveObserver(this); 312 observing_render_process_host_->RemoveObserver(this);
313 observing_render_process_host_ = nullptr; 313 observing_render_process_host_ = nullptr;
314 } 314 }
315 NotifyMaybeTextInputClientChanged(); 315 NotifyMaybeTextInputClientAndAccessibilityChanged();
316 } 316 }
317 317
318 void WebView::DidShowFullscreenWidget(int routing_id) { 318 void WebView::DidShowFullscreenWidget(int routing_id) {
319 if (embed_fullscreen_widget_mode_enabled_) 319 if (embed_fullscreen_widget_mode_enabled_)
320 ReattachForFullscreenChange(true); 320 ReattachForFullscreenChange(true);
321 } 321 }
322 322
323 void WebView::DidDestroyFullscreenWidget(int routing_id) { 323 void WebView::DidDestroyFullscreenWidget(int routing_id) {
324 if (embed_fullscreen_widget_mode_enabled_) 324 if (embed_fullscreen_widget_mode_enabled_)
325 ReattachForFullscreenChange(false); 325 ReattachForFullscreenChange(false);
326 } 326 }
327 327
328 void WebView::DidToggleFullscreenModeForTab(bool entered_fullscreen) { 328 void WebView::DidToggleFullscreenModeForTab(bool entered_fullscreen) {
329 if (embed_fullscreen_widget_mode_enabled_) 329 if (embed_fullscreen_widget_mode_enabled_)
330 ReattachForFullscreenChange(entered_fullscreen); 330 ReattachForFullscreenChange(entered_fullscreen);
331 } 331 }
332 332
333 void WebView::DidAttachInterstitialPage() { 333 void WebView::DidAttachInterstitialPage() {
334 NotifyMaybeTextInputClientChanged(); 334 NotifyMaybeTextInputClientAndAccessibilityChanged();
335 } 335 }
336 336
337 void WebView::DidDetachInterstitialPage() { 337 void WebView::DidDetachInterstitialPage() {
338 NotifyMaybeTextInputClientChanged(); 338 NotifyMaybeTextInputClientAndAccessibilityChanged();
339 } 339 }
340 340
341 //////////////////////////////////////////////////////////////////////////////// 341 ////////////////////////////////////////////////////////////////////////////////
342 // WebView, private: 342 // WebView, private:
343 343
344 void WebView::AttachWebContents() { 344 void WebView::AttachWebContents() {
345 // Prevents attachment if the WebView isn't already in a Widget, or it's 345 // Prevents attachment if the WebView isn't already in a Widget, or it's
346 // already attached. 346 // already attached.
347 if (!GetWidget() || !web_contents()) 347 if (!GetWidget() || !web_contents())
348 return; 348 return;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 // widget. Need to detach and re-attach to a different native view. 390 // widget. Need to detach and re-attach to a different native view.
391 DetachWebContents(); 391 DetachWebContents();
392 is_embedding_fullscreen_widget_ = 392 is_embedding_fullscreen_widget_ =
393 enter_fullscreen && web_contents_has_separate_fs_widget; 393 enter_fullscreen && web_contents_has_separate_fs_widget;
394 AttachWebContents(); 394 AttachWebContents();
395 } else { 395 } else {
396 // Entering or exiting "non-Flash" fullscreen mode, where the native view is 396 // Entering or exiting "non-Flash" fullscreen mode, where the native view is
397 // the same. So, do not change attachment. 397 // the same. So, do not change attachment.
398 OnBoundsChanged(bounds()); 398 OnBoundsChanged(bounds());
399 } 399 }
400 NotifyMaybeTextInputClientChanged(); 400 NotifyMaybeTextInputClientAndAccessibilityChanged();
401 } 401 }
402 402
403 void WebView::NotifyMaybeTextInputClientChanged() { 403 void WebView::NotifyMaybeTextInputClientAndAccessibilityChanged() {
404 // Update the TextInputClient as needed; see GetTextInputClient(). 404 // Update the TextInputClient as needed; see GetTextInputClient().
405 FocusManager* const focus_manager = GetFocusManager(); 405 FocusManager* const focus_manager = GetFocusManager();
406 if (focus_manager) 406 if (focus_manager)
407 focus_manager->OnTextInputClientChanged(this); 407 focus_manager->OnTextInputClientChanged(this);
408
409 #if defined(OS_CHROMEOS)
dmazzoni 2015/01/28 23:05:21 I think we should fire this event on all platforms
David Tseng 2015/01/29 00:33:51 Was getting various test failures specific to Wind
410 NotifyAccessibilityEvent(ui::AX_EVENT_CHILDREN_CHANGED, true);
411 #endif // defined OS_CHROMEOS
408 } 412 }
409 413
410 content::WebContents* WebView::CreateWebContents( 414 content::WebContents* WebView::CreateWebContents(
411 content::BrowserContext* browser_context) { 415 content::BrowserContext* browser_context) {
412 content::WebContents* contents = NULL; 416 content::WebContents* contents = NULL;
413 if (ViewsDelegate::views_delegate) { 417 if (ViewsDelegate::views_delegate) {
414 contents = ViewsDelegate::views_delegate->CreateWebContents( 418 contents = ViewsDelegate::views_delegate->CreateWebContents(
415 browser_context, NULL); 419 browser_context, NULL);
416 } 420 }
417 421
418 if (!contents) { 422 if (!contents) {
419 content::WebContents::CreateParams create_params( 423 content::WebContents::CreateParams create_params(
420 browser_context, NULL); 424 browser_context, NULL);
421 return content::WebContents::Create(create_params); 425 return content::WebContents::Create(create_params);
422 } 426 }
423 427
424 return contents; 428 return contents;
425 } 429 }
426 430
427 } // namespace views 431 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698