Fix a crash in downloads.acceptDanger()
On mac, when the ConstrainedWindow (DownloadDangerPrompt) stole key-ness from
the extension popup, the popup was automatically closing, which would
automatically close the DownloadDangerPrompt before the user could interact with
it.
Now when ExtensionPopupController receives a windowDidResignKey notification, it
drops the notification if there are any modal dialogs showing for its WebContents.
There's also an extra windowDidResignKey notification right after the modal
dialog closes, so ExtensionPopupController::windowDidResignKey() sets a flag to
ignore it.
TabModalConfirmDialogMac::OnConstrainedWindowClosed() could be called twice
causing double-deletes. Passing the delegate_ to a stack variable allows the
second call to return before double-deleting.
Add DownloadsAcceptDangerFunction::OnPromptCreatedForTesting(callback) so that
the browser test can fake the user clicking in the DownloadDangerPrompt.
Override ChromeWebModalDialogManagerDelegate::GetWebContentsModalDialogHost() in
ExtensionHost to return a valid WebContentsModalDialogHost (ExtensionDialogHost)
instead of NULL. This object is necessary in
CreateWebContentsModalDialogViews(). ExtensionHost outlives ExtensionDialogHost
which outlives the dialog.
BUG=273114
Review URL: https://chromiumcodereview.appspot.com/23064010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@219455 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc
index 7388727..d7cd528 100644
--- a/chrome/browser/extensions/extension_host.cc
+++ b/chrome/browser/extensions/extension_host.cc
@@ -44,6 +44,7 @@
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
@@ -287,6 +288,34 @@
content::Details<ExtensionHost>(this));
}
+#if !defined(OS_ANDROID)
+web_modal::WebContentsModalDialogHost*
+ExtensionHost::GetWebContentsModalDialogHost() {
+ return this;
+}
+
+gfx::NativeView ExtensionHost::GetHostView() const {
+ return view_ ? view_->native_view() : NULL;
+}
+
+gfx::Point ExtensionHost::GetDialogPosition(const gfx::Size& size) {
+ if (!GetVisibleWebContents())
+ return gfx::Point();
+ gfx::Rect bounds = GetVisibleWebContents()->GetView()->GetViewBounds();
+ return gfx::Point(
+ std::max(0, (bounds.width() - size.width()) / 2),
+ std::max(0, (bounds.height() - size.height()) / 2));
+}
+
+void ExtensionHost::AddObserver(
+ web_modal::WebContentsModalDialogHostObserver* observer) {
+}
+
+void ExtensionHost::RemoveObserver(
+ web_modal::WebContentsModalDialogHostObserver* observer) {
+}
+#endif
+
void ExtensionHost::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {