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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_VIEWS_WEBSITE_SETTINGS_WEBSITE_SETTINGS_POPUP_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_WEBSITE_SETTINGS_WEBSITE_SETTINGS_POPUP_VIEW_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/strings/string16.h"
12 #include "chrome/browser/ssl/security_state_model.h"
13 #include "chrome/browser/ui/views/website_settings/permission_selector_view_observer.h"
14 #include "chrome/browser/ui/website_settings/website_settings_ui.h"
15 #include "content/public/browser/web_contents_observer.h"
16 #include "ui/views/bubble/bubble_delegate.h"
17 #include "ui/views/controls/button/button.h"
18 #include "ui/views/controls/link_listener.h"
19 #include "ui/views/controls/tabbed_pane/tabbed_pane_listener.h"
22 class PopupHeaderView
;
30 class WebsiteSettingsPopupViewTestApi
;
40 // The views implementation of the website settings UI.
41 class WebsiteSettingsPopupView
: public content::WebContentsObserver
,
42 public PermissionSelectorViewObserver
,
43 public views::BubbleDelegateView
,
44 public views::ButtonListener
,
45 public views::LinkListener
,
46 public views::TabbedPaneListener
,
47 public WebsiteSettingsUI
{
49 ~WebsiteSettingsPopupView() override
;
51 // If |anchor_view| is null, |anchor_rect| is used to anchor the bubble.
52 static void ShowPopup(views::View
* anchor_view
,
53 const gfx::Rect
& anchor_rect
,
55 content::WebContents
* web_contents
,
57 const SecurityStateModel::SecurityInfo
& security_info
);
59 static bool IsPopupShowing();
62 friend class test::WebsiteSettingsPopupViewTestApi
;
64 WebsiteSettingsPopupView(
65 views::View
* anchor_view
,
66 gfx::NativeView parent_window
,
68 content::WebContents
* web_contents
,
70 const SecurityStateModel::SecurityInfo
& security_info
);
72 // WebContentsObserver implementation.
73 void RenderFrameDeleted(content::RenderFrameHost
* render_frame_host
) override
;
75 // PermissionSelectorViewObserver implementation.
76 void OnPermissionChanged(
77 const WebsiteSettingsUI::PermissionInfo
& permission
) override
;
79 // views::BubbleDelegateView implementation.
80 void OnWidgetDestroying(views::Widget
* widget
) override
;
82 // views::ButtonListener implementation.
83 void ButtonPressed(views::Button
* button
, const ui::Event
& event
) override
;
85 // views::LinkListener implementation.
86 void LinkClicked(views::Link
* source
, int event_flags
) override
;
88 // views::TabbedPaneListener implementations.
89 void TabSelectedAt(int index
) override
;
91 // views::View implementation.
92 gfx::Size
GetPreferredSize() const override
;
94 // WebsiteSettingsUI implementations.
95 void SetCookieInfo(const CookieInfoList
& cookie_info_list
) override
;
96 void SetPermissionInfo(
97 const PermissionInfoList
& permission_info_list
) override
;
98 void SetIdentityInfo(const IdentityInfo
& identity_info
) override
;
99 void SetSelectedTab(TabId tab_id
) override
;
101 // Creates the contents of the "Permissions" tab. The ownership of the
102 // returned view is transferred to the caller.
103 views::View
* CreatePermissionsTab() WARN_UNUSED_RESULT
;
105 // Creates the contents of the "connection" tab. The ownership of the returned
106 // view is transferred to the caller.
107 views::View
* CreateConnectionTab() WARN_UNUSED_RESULT
;
109 // Each tab contains several sections with a |headline| followed by the
110 // section |contents| and an optional |link|. This method creates a section
111 // for the given |headline|, |contents| and |link|. |link| can be NULL if the
112 // section should not contain a link.
113 views::View
* CreateSection(const base::string16
& headline
,
114 views::View
* contents
,
115 views::Link
* link
) WARN_UNUSED_RESULT
;
117 // Resets the content of a section. All children of the |section_container|
118 // are cleared and destroyed first. Then the |icon|, |headline|, |text|,
119 // |link|, and |secondary_link| are laid out properly. If the |headline| is an
120 // empty string then no headline will be displayed. Ownership of |link| and
121 // |secondary_link| is transfered to the ResetConnectionSection method and the
122 // links are added to the views hierarchy. NULL links are not displayed.
123 void ResetConnectionSection(views::View
* section_container
,
124 const gfx::Image
& icon
,
125 const base::string16
& headline
,
126 const base::string16
& text
,
128 views::LabelButton
* reset_decisions_button
);
130 // Used to asynchronously handle clicks since these calls may cause the
131 // destruction of the settings view and the base class window still needs to
132 // be alive to finish handling the mouse or keyboard click.
133 void HandleLinkClickedAsync(views::Link
* source
);
135 // The web contents of the current tab. The popup can't live longer than a
137 content::WebContents
* web_contents_
;
139 // The presenter that controls the Website Settings UI.
140 scoped_ptr
<WebsiteSettings
> presenter_
;
142 PopupHeaderView
* header_
; // Owned by views hierarchy.
144 // The |TabbedPane| that contains the tabs of the Website Settings UI.
145 views::TabbedPane
* tabbed_pane_
;
147 // The view that contains the permissions tab contents.
148 views::View
* permissions_tab_
;
149 // The view that contains the contents of the "Cookies and Site data" section
150 // from the "Permissions" tab.
151 views::View
* site_data_content_
;
152 // The link that opens the "Cookies" dialog.
153 views::Link
* cookie_dialog_link_
;
154 // The view that contains the contents of the "Permissions" section from the
155 // "Permissions" tab.
156 views::View
* permissions_content_
;
158 // The view that contains the connection tab contents.
159 views::View
* connection_tab_
;
160 // The view that contains the UI elements for displaying information about
161 // the site's identity.
162 views::View
* identity_info_content_
;
163 // The link to open the certificate viewer for displaying the certificate
164 // provided by the website. If the site does not provide a certificate then
165 // |certificate_dialog_link_| is NULL.
166 views::Link
* certificate_dialog_link_
;
167 // The button to reset the Allow/Deny certificate errors decision for the
169 views::LabelButton
* reset_decisions_button_
;
170 // The view that contains the contents of the "What Do These Mean?" section
171 // from the "Connection" tab.
172 views::View
* help_center_content_
;
174 // The ID of the certificate provided by the site. If the site does not
175 // provide a certificate then |cert_id_| is 0.
178 // The link to open the help center page that contains more information about
179 // the connection status icons.
180 views::Link
* help_center_link_
;
182 // The link to open the site settings page that provides full control over
183 // the origin's permissions.
184 views::Link
* site_settings_link_
;
186 views::View
* connection_info_content_
;
188 base::WeakPtrFactory
<WebsiteSettingsPopupView
> weak_factory_
;
190 DISALLOW_COPY_AND_ASSIGN(WebsiteSettingsPopupView
);
193 #endif // CHROME_BROWSER_UI_VIEWS_WEBSITE_SETTINGS_WEBSITE_SETTINGS_POPUP_VIEW_H_