1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/tab_dialogs_views.h"
6
7 #include <memory>
8 #include <utility>
9
10 #include "build/build_config.h"
11 #include "chrome/browser/ui/views/collected_cookies_views.h"
12 #include "chrome/browser/ui/views/hung_renderer_view.h"
13 #include "chrome/browser/ui/views/passwords/password_bubble_view_base.h"
14 #include "content/public/browser/web_contents.h"
15
16 #if !defined(OS_CHROMEOS)
17 #include "chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.h"
18 #endif
19
20 // static
CreateForWebContents(content::WebContents * contents)21 void TabDialogs::CreateForWebContents(content::WebContents* contents) {
22 DCHECK(contents);
23 if (!FromWebContents(contents)) {
24 contents->SetUserData(UserDataKey(),
25 std::make_unique<TabDialogsViews>(contents));
26 }
27 }
28
TabDialogsViews(content::WebContents * contents)29 TabDialogsViews::TabDialogsViews(content::WebContents* contents)
30 : web_contents_(contents) {
31 DCHECK(contents);
32 }
33
34 TabDialogsViews::~TabDialogsViews() = default;
35
GetDialogParentView() const36 gfx::NativeView TabDialogsViews::GetDialogParentView() const {
37 return web_contents_->GetNativeView();
38 }
39
ShowCollectedCookies()40 void TabDialogsViews::ShowCollectedCookies() {
41 CollectedCookiesViews::CreateAndShowForWebContents(web_contents_);
42 }
43
ShowHungRendererDialog(content::RenderWidgetHost * render_widget_host,base::RepeatingClosure hang_monitor_restarter)44 void TabDialogsViews::ShowHungRendererDialog(
45 content::RenderWidgetHost* render_widget_host,
46 base::RepeatingClosure hang_monitor_restarter) {
47 HungRendererDialogView::Show(web_contents_, render_widget_host,
48 std::move(hang_monitor_restarter));
49 }
50
HideHungRendererDialog(content::RenderWidgetHost * render_widget_host)51 void TabDialogsViews::HideHungRendererDialog(
52 content::RenderWidgetHost* render_widget_host) {
53 HungRendererDialogView::Hide(web_contents_, render_widget_host);
54 }
55
IsShowingHungRendererDialog()56 bool TabDialogsViews::IsShowingHungRendererDialog() {
57 return HungRendererDialogView::GetInstance();
58 }
59
ShowProfileSigninConfirmation(Browser * browser,Profile * profile,const std::string & username,std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate)60 void TabDialogsViews::ShowProfileSigninConfirmation(
61 Browser* browser,
62 Profile* profile,
63 const std::string& username,
64 std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate) {
65 #if !defined(OS_CHROMEOS)
66 ProfileSigninConfirmationDialogViews::ShowDialog(browser, profile, username,
67 std::move(delegate));
68 #else
69 NOTREACHED();
70 #endif
71 }
72
ShowManagePasswordsBubble(bool user_action)73 void TabDialogsViews::ShowManagePasswordsBubble(bool user_action) {
74 if (PasswordBubbleViewBase::manage_password_bubble()) {
75 // The bubble is currently shown for some other tab. We should close it now
76 // and open for |web_contents_|.
77 PasswordBubbleViewBase::CloseCurrentBubble();
78 }
79 PasswordBubbleViewBase::ShowBubble(
80 web_contents_, user_action ? LocationBarBubbleDelegateView::USER_GESTURE
81 : LocationBarBubbleDelegateView::AUTOMATIC);
82 }
83
HideManagePasswordsBubble()84 void TabDialogsViews::HideManagePasswordsBubble() {
85 PasswordBubbleViewBase* bubble =
86 PasswordBubbleViewBase::manage_password_bubble();
87 if (!bubble)
88 return;
89 if (bubble->GetWebContents() == web_contents_)
90 PasswordBubbleViewBase::CloseCurrentBubble();
91 }
92