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

Side by Side Diff: content/browser/web_contents/web_contents_view_aura.cc

Issue 1815593002: Remove windowed NPAPI code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@make_test_plugin_windowless
Patch Set: rebase Created 4 years, 9 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 "content/browser/web_contents/web_contents_view_aura.h" 5 #include "content/browser/web_contents/web_contents_view_aura.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 399
400 } // namespace 400 } // namespace
401 401
402 class WebContentsViewAura::WindowObserver 402 class WebContentsViewAura::WindowObserver
403 : public aura::WindowObserver, public aura::WindowTreeHostObserver { 403 : public aura::WindowObserver, public aura::WindowTreeHostObserver {
404 public: 404 public:
405 explicit WindowObserver(WebContentsViewAura* view) 405 explicit WindowObserver(WebContentsViewAura* view)
406 : view_(view), 406 : view_(view),
407 host_window_(NULL) { 407 host_window_(NULL) {
408 view_->window_->AddObserver(this); 408 view_->window_->AddObserver(this);
409
410 #if defined(OS_WIN)
411 if (view_->window_->GetRootWindow())
412 view_->window_->GetRootWindow()->AddObserver(this);
413 #endif
414 } 409 }
415 410
416 ~WindowObserver() override { 411 ~WindowObserver() override {
417 view_->window_->RemoveObserver(this); 412 view_->window_->RemoveObserver(this);
418 if (view_->window_->GetHost()) 413 if (view_->window_->GetHost())
419 view_->window_->GetHost()->RemoveObserver(this); 414 view_->window_->GetHost()->RemoveObserver(this);
420 if (host_window_) 415 if (host_window_)
421 host_window_->RemoveObserver(this); 416 host_window_->RemoveObserver(this);
422 #if defined(OS_WIN)
423 if (host_window_) {
424 const aura::Window::Windows& children = host_window_->children();
425 for (size_t i = 0; i < children.size(); ++i)
426 children[i]->RemoveObserver(this);
427 }
428
429 aura::Window* root_window = view_->window_->GetRootWindow();
430 if (root_window) {
431 root_window->RemoveObserver(this);
432 const aura::Window::Windows& root_children = root_window->children();
433 for (size_t i = 0; i < root_children.size(); ++i)
434 root_children[i]->RemoveObserver(this);
435 }
436 #endif
437 } 417 }
438 418
439 #if defined(OS_WIN)
440 // Constrained windows are added as children of the parent's parent's view
441 // which may overlap with windowed NPAPI plugins. In that case, tell the RWHV
442 // so that it can update the plugins' cutout rects accordingly.
443 // Note: this is hard coding how Chrome layer adds its dialogs. Since NPAPI is
444 // going to be deprecated in a year, this is ok for now. The test for this is
445 // PrintPreviewTest.WindowedNPAPIPluginHidden.
446 void OnWindowAdded(aura::Window* new_window) override {
447 if (!new_window->Contains(view_->window_.get())) {
448 // Skip the case when the parent moves to the root window.
449 if (new_window != host_window_) {
450 // Observe sibling windows of the WebContents, or children of the root
451 // window.
452 if (new_window->parent() == host_window_ ||
453 new_window->parent() == view_->window_->GetRootWindow()) {
454 new_window->AddObserver(this);
455 }
456 }
457 }
458
459 if (new_window->parent() == host_window_) {
460 UpdateConstrainedWindows(NULL);
461 }
462 }
463
464 void OnWillRemoveWindow(aura::Window* window) override {
465 if (window == view_->window_.get())
466 return;
467
468 window->RemoveObserver(this);
469 UpdateConstrainedWindows(window);
470 }
471
472 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override {
473 if (window == view_->window_.get() || window->parent() == host_window_ ||
474 window->parent() == view_->window_->GetRootWindow()) {
475 UpdateConstrainedWindows(NULL);
476 }
477 }
478 #endif
479
480 void OnWindowParentChanged(aura::Window* window, 419 void OnWindowParentChanged(aura::Window* window,
481 aura::Window* parent) override { 420 aura::Window* parent) override {
482 if (window != view_->window_.get()) 421 if (window != view_->window_.get())
483 return; 422 return;
484 423
485 aura::Window* host_window = 424 aura::Window* host_window =
486 window->GetProperty(aura::client::kHostWindowKey); 425 window->GetProperty(aura::client::kHostWindowKey);
487 if (!host_window) 426 if (!host_window)
488 host_window = parent; 427 host_window = parent;
489 428
490 if (host_window_) 429 if (host_window_)
491 host_window_->RemoveObserver(this); 430 host_window_->RemoveObserver(this);
492 431
493 #if defined(OS_WIN)
494 if (host_window_) {
495 const aura::Window::Windows& children = host_window_->children();
496 for (size_t i = 0; i < children.size(); ++i)
497 children[i]->RemoveObserver(this);
498 RenderWidgetHostViewAura* rwhv = ToRenderWidgetHostViewAura(
499 view_->web_contents_->GetRenderWidgetHostView());
500 if (rwhv)
501 rwhv->UpdateConstrainedWindowRects(std::vector<gfx::Rect>());
502 }
503
504 // When we get parented to the root window, the code below will watch the
505 // host window, aka root window. Since we already watch the root window on
506 // Windows, unregister first so that the debug check doesn't fire.
507 if (host_window && host_window == window->GetRootWindow())
508 host_window->RemoveObserver(this);
509
510 // We need to undo the above if we were parented to the root window and then
511 // got parented to another window. At that point, the code before the ifdef
512 // would have stopped watching the root window.
513 if (window->GetRootWindow() &&
514 host_window != window->GetRootWindow() &&
515 !window->GetRootWindow()->HasObserver(this)) {
516 window->GetRootWindow()->AddObserver(this);
517 }
518 #endif
519
520 host_window_ = host_window; 432 host_window_ = host_window;
521 if (host_window) { 433 if (host_window)
522 host_window->AddObserver(this); 434 host_window->AddObserver(this);
523 #if defined(OS_WIN)
524 if (host_window != window->GetRootWindow()) {
525 const aura::Window::Windows& children = host_window->children();
526 for (size_t i = 0; i < children.size(); ++i) {
527 if (!children[i]->Contains(view_->window_.get()))
528 children[i]->AddObserver(this);
529 }
530 }
531 #endif
532 }
533 } 435 }
534 436
535 void OnWindowBoundsChanged(aura::Window* window, 437 void OnWindowBoundsChanged(aura::Window* window,
536 const gfx::Rect& old_bounds, 438 const gfx::Rect& old_bounds,
537 const gfx::Rect& new_bounds) override { 439 const gfx::Rect& new_bounds) override {
538 if (window == host_window_ || window == view_->window_.get()) { 440 if (window == host_window_ || window == view_->window_.get()) {
539 SendScreenRects(); 441 SendScreenRects();
540 if (old_bounds.origin() != new_bounds.origin()) { 442 if (old_bounds.origin() != new_bounds.origin()) {
541 TouchSelectionControllerClientAura* selection_controller_client = 443 TouchSelectionControllerClientAura* selection_controller_client =
542 view_->GetSelectionControllerClient(); 444 view_->GetSelectionControllerClient();
543 if (selection_controller_client) 445 if (selection_controller_client)
544 selection_controller_client->OnWindowMoved(); 446 selection_controller_client->OnWindowMoved();
545 } 447 }
546 #if defined(OS_WIN)
547 } else {
548 UpdateConstrainedWindows(NULL);
549 #endif
550 } 448 }
551 } 449 }
552 450
553 void OnWindowDestroying(aura::Window* window) override { 451 void OnWindowDestroying(aura::Window* window) override {
554 if (window == host_window_) { 452 if (window == host_window_) {
555 host_window_->RemoveObserver(this); 453 host_window_->RemoveObserver(this);
556 host_window_ = NULL; 454 host_window_ = NULL;
557 } 455 }
558 } 456 }
559 457
560 void OnWindowAddedToRootWindow(aura::Window* window) override { 458 void OnWindowAddedToRootWindow(aura::Window* window) override {
561 if (window == view_->window_.get()) { 459 if (window == view_->window_.get())
562 window->GetHost()->AddObserver(this); 460 window->GetHost()->AddObserver(this);
563 #if defined(OS_WIN)
564 if (!window->GetRootWindow()->HasObserver(this))
565 window->GetRootWindow()->AddObserver(this);
566 #endif
567 }
568 } 461 }
569 462
570 void OnWindowRemovingFromRootWindow(aura::Window* window, 463 void OnWindowRemovingFromRootWindow(aura::Window* window,
571 aura::Window* new_root) override { 464 aura::Window* new_root) override {
572 if (window == view_->window_.get()) { 465 if (window == view_->window_.get())
573 window->GetHost()->RemoveObserver(this); 466 window->GetHost()->RemoveObserver(this);
574 #if defined(OS_WIN)
575 window->GetRootWindow()->RemoveObserver(this);
576
577 const aura::Window::Windows& root_children =
578 window->GetRootWindow()->children();
579 for (size_t i = 0; i < root_children.size(); ++i) {
580 if (root_children[i] != view_->window_.get() &&
581 root_children[i] != host_window_) {
582 root_children[i]->RemoveObserver(this);
583 }
584 }
585 #endif
586 }
587 } 467 }
588 468
589 // Overridden WindowTreeHostObserver: 469 // Overridden WindowTreeHostObserver:
590 void OnHostMoved(const aura::WindowTreeHost* host, 470 void OnHostMoved(const aura::WindowTreeHost* host,
591 const gfx::Point& new_origin) override { 471 const gfx::Point& new_origin) override {
592 TRACE_EVENT1("ui", 472 TRACE_EVENT1("ui",
593 "WebContentsViewAura::WindowObserver::OnHostMoved", 473 "WebContentsViewAura::WindowObserver::OnHostMoved",
594 "new_origin", new_origin.ToString()); 474 "new_origin", new_origin.ToString());
595 475
596 // This is for the desktop case (i.e. Aura desktop). 476 // This is for the desktop case (i.e. Aura desktop).
597 SendScreenRects(); 477 SendScreenRects();
598 } 478 }
599 479
600 private: 480 private:
601 void SendScreenRects() { view_->web_contents_->SendScreenRects(); } 481 void SendScreenRects() { view_->web_contents_->SendScreenRects(); }
602 482
603 #if defined(OS_WIN)
604 void UpdateConstrainedWindows(aura::Window* exclude) {
605 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura(
606 view_->web_contents_->GetRenderWidgetHostView());
607 if (!view)
608 return;
609
610 std::vector<gfx::Rect> constrained_windows;
611 if (host_window_) {
612 const aura::Window::Windows& children = host_window_->children();
613 for (size_t i = 0; i < children.size(); ++i) {
614 if (!children[i]->Contains(view_->window_.get()) &&
615 children[i] != exclude &&
616 children[i]->IsVisible()) {
617 constrained_windows.push_back(children[i]->GetBoundsInRootWindow());
618 }
619 }
620 }
621
622 aura::Window* root_window = view_->window_->GetRootWindow();
623 const aura::Window::Windows& root_children = root_window->children();
624 if (root_window) {
625 for (size_t i = 0; i < root_children.size(); ++i) {
626 if (root_children[i]->IsVisible() &&
627 !root_children[i]->Contains(view_->window_.get())) {
628 constrained_windows.push_back(
629 root_children[i]->GetBoundsInRootWindow());
630 }
631 }
632 }
633
634 view->UpdateConstrainedWindowRects(constrained_windows);
635 }
636 #endif
637
638 WebContentsViewAura* view_; 483 WebContentsViewAura* view_;
639 484
640 // The parent window that hosts the constrained windows. We cache the old host 485 // The parent window that hosts the constrained windows. We cache the old host
641 // view so that we can unregister when it's not the parent anymore. 486 // view so that we can unregister when it's not the parent anymore.
642 aura::Window* host_window_; 487 aura::Window* host_window_;
643 488
644 DISALLOW_COPY_AND_ASSIGN(WindowObserver); 489 DISALLOW_COPY_AND_ASSIGN(WindowObserver);
645 }; 490 };
646 491
647 //////////////////////////////////////////////////////////////////////////////// 492 ////////////////////////////////////////////////////////////////////////////////
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window, 1133 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window,
1289 bool visible) { 1134 bool visible) {
1290 // Ignore any visibility changes in the hierarchy below. 1135 // Ignore any visibility changes in the hierarchy below.
1291 if (window != window_.get() && window_->Contains(window)) 1136 if (window != window_.get() && window_->Contains(window))
1292 return; 1137 return;
1293 1138
1294 web_contents_->UpdateWebContentsVisibility(visible); 1139 web_contents_->UpdateWebContentsVisibility(visible);
1295 } 1140 }
1296 1141
1297 } // namespace content 1142 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mus.cc ('k') | content/child/npapi/plugin_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698