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

Unified Diff: chrome/browser/ui/web_contents_modal_dialog_manager.cc

Issue 14969012: components: Create web_modal component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge-before-land Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/web_contents_modal_dialog_manager.cc
diff --git a/chrome/browser/ui/web_contents_modal_dialog_manager.cc b/chrome/browser/ui/web_contents_modal_dialog_manager.cc
deleted file mode 100644
index dfcbd5cedd61d48d25b85c4fc37f2b93f5db5fac..0000000000000000000000000000000000000000
--- a/chrome/browser/ui/web_contents_modal_dialog_manager.cc
+++ /dev/null
@@ -1,154 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ui/web_contents_modal_dialog_manager.h"
-
-#include "chrome/browser/platform_util.h"
-#include "chrome/browser/ui/web_contents_modal_dialog_manager_delegate.h"
-#include "chrome/common/render_messages.h"
-#include "content/public/browser/navigation_details.h"
-#include "content/public/browser/navigation_entry.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_source.h"
-#include "content/public/browser/notification_types.h"
-#include "content/public/browser/render_view_host.h"
-#include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_view.h"
-#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
-
-using content::WebContents;
-
-DEFINE_WEB_CONTENTS_USER_DATA_KEY(WebContentsModalDialogManager);
-
-WebContentsModalDialogManager::~WebContentsModalDialogManager() {
- DCHECK(child_dialogs_.empty());
-}
-
-void WebContentsModalDialogManager::ShowDialog(
- NativeWebContentsModalDialog dialog) {
- child_dialogs_.push_back(dialog);
-
- native_manager_->ManageDialog(dialog);
-
- if (child_dialogs_.size() == 1) {
- if (IsWebContentsVisible())
- native_manager_->ShowDialog(dialog);
- BlockWebContentsInteraction(true);
- }
-}
-
-bool WebContentsModalDialogManager::IsShowingDialog() const {
- return !child_dialogs_.empty();
-}
-
-void WebContentsModalDialogManager::FocusTopmostDialog() {
- DCHECK(!child_dialogs_.empty());
- native_manager_->FocusDialog(child_dialogs_.front());
-}
-
-content::WebContents* WebContentsModalDialogManager::GetWebContents() const {
- return web_contents();
-}
-
-void WebContentsModalDialogManager::WillClose(
- NativeWebContentsModalDialog dialog) {
- WebContentsModalDialogList::iterator i(
- std::find(child_dialogs_.begin(), child_dialogs_.end(), dialog));
-
- // The Views tab contents modal dialog calls WillClose twice. Ignore the
- // second invocation.
- if (i == child_dialogs_.end())
- return;
-
- bool removed_topmost_dialog = i == child_dialogs_.begin();
- child_dialogs_.erase(i);
- if (!child_dialogs_.empty() && removed_topmost_dialog &&
- !closing_all_dialogs_)
- native_manager_->ShowDialog(child_dialogs_.front());
-
- BlockWebContentsInteraction(!child_dialogs_.empty());
-}
-
-void WebContentsModalDialogManager::Observe(
- int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- DCHECK(type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED);
-
- if (child_dialogs_.empty())
- return;
-
- bool visible = *content::Details<bool>(details).ptr();
- if (visible)
- native_manager_->ShowDialog(child_dialogs_.front());
- else
- native_manager_->HideDialog(child_dialogs_.front());
-}
-
-WebContentsModalDialogManager::WebContentsModalDialogManager(
- content::WebContents* web_contents)
- : content::WebContentsObserver(web_contents),
- delegate_(NULL),
- native_manager_(CreateNativeManager(this)),
- closing_all_dialogs_(false) {
- DCHECK(native_manager_);
- registrar_.Add(this,
- content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
- content::Source<content::WebContents>(web_contents));
-}
-
-void WebContentsModalDialogManager::BlockWebContentsInteraction(bool blocked) {
- WebContents* contents = web_contents();
- if (!contents) {
- // The WebContents has already disconnected.
- return;
- }
-
- // RenderViewHost may be NULL during shutdown.
- content::RenderViewHost* host = contents->GetRenderViewHost();
- if (host) {
- host->SetIgnoreInputEvents(blocked);
- host->Send(new ChromeViewMsg_SetVisuallyDeemphasized(
- host->GetRoutingID(), blocked));
- }
- if (delegate_)
- delegate_->SetWebContentsBlocked(contents, blocked);
-}
-
-bool WebContentsModalDialogManager::IsWebContentsVisible() const {
- return platform_util::IsVisible(web_contents()->GetView()->GetNativeView());
-}
-
-void WebContentsModalDialogManager::CloseAllDialogs() {
- closing_all_dialogs_ = true;
-
- // Clear out any dialogs since we are leaving this page entirely.
- while (!child_dialogs_.empty())
- native_manager_->CloseDialog(child_dialogs_.front());
-
- closing_all_dialogs_ = false;
-}
-
-void WebContentsModalDialogManager::DidNavigateMainFrame(
- const content::LoadCommittedDetails& details,
- const content::FrameNavigateParams& params) {
- // Close constrained windows if necessary.
- if (!net::registry_controlled_domains::SameDomainOrHost(
- details.previous_url, details.entry->GetURL(),
- net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES))
- CloseAllDialogs();
-}
-
-void WebContentsModalDialogManager::DidGetIgnoredUIEvent() {
- if (!child_dialogs_.empty())
- native_manager_->FocusDialog(child_dialogs_.front());
-}
-
-void WebContentsModalDialogManager::WebContentsDestroyed(WebContents* tab) {
- // First cleanly close all child dialogs.
- // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
- // some of these to close. CloseAllDialogs is async, so it might get called
- // twice before it runs.
- CloseAllDialogs();
-}
« no previous file with comments | « chrome/browser/ui/web_contents_modal_dialog_manager.h ('k') | chrome/browser/ui/web_contents_modal_dialog_manager_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698