content_setting_bubble_contents.h revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
1// Copyright (c) 2011 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#ifndef CHROME_BROWSER_UI_VIEWS_CONTENT_SETTING_BUBBLE_CONTENTS_H_ 6#define CHROME_BROWSER_UI_VIEWS_CONTENT_SETTING_BUBBLE_CONTENTS_H_ 7 8#include <map> 9 10#include "base/basictypes.h" 11#include "base/compiler_specific.h" 12#include "chrome/common/content_settings_types.h" 13#include "content/public/browser/notification_observer.h" 14#include "content/public/browser/notification_registrar.h" 15#include "content/public/common/media_stream_request.h" 16#include "ui/views/bubble/bubble_delegate.h" 17#include "ui/views/controls/button/button.h" 18#include "ui/views/controls/button/menu_button_listener.h" 19#include "ui/views/controls/link_listener.h" 20 21class ContentSettingBubbleModel; 22class ContentSettingMediaMenuModel; 23class Profile; 24 25namespace content { 26class WebContents; 27} 28 29namespace ui { 30class SimpleMenuModel; 31} 32 33namespace views { 34class LabelButton; 35class MenuButton; 36class MenuRunner; 37class RadioButton; 38} 39 40// ContentSettingBubbleContents is used when the user turns on different kinds 41// of content blocking (e.g. "block images"). When viewing a page with blocked 42// content, icons appear in the omnibox corresponding to the content types that 43// were blocked, and the user can click one to get a bubble hosting a few 44// controls. This class provides the content of that bubble. In general, 45// these bubbles typically have a title, a pair of radio buttons for toggling 46// the blocking settings for the current site, a close button, and a link to 47// get to a more comprehensive settings management dialog. A few types have 48// more or fewer controls than this. 49class ContentSettingBubbleContents : public content::NotificationObserver, 50 public views::BubbleDelegateView, 51 public views::ButtonListener, 52 public views::LinkListener, 53 public views::MenuButtonListener { 54 public: 55 ContentSettingBubbleContents( 56 ContentSettingBubbleModel* content_setting_bubble_model, 57 content::WebContents* web_contents, 58 views::View* anchor_view, 59 views::BubbleBorder::Arrow arrow); 60 virtual ~ContentSettingBubbleContents(); 61 62 virtual gfx::Size GetPreferredSize() OVERRIDE; 63 64 // Callback to allow ContentSettingMediaMenuModel to update the menu label. 65 void UpdateMenuLabel(content::MediaStreamType type, 66 const std::string& label); 67 68 protected: 69 // views::BubbleDelegateView: 70 virtual void Init() OVERRIDE; 71 72 private: 73 class Favicon; 74 struct MediaMenuParts; 75 76 typedef std::map<views::Link*, int> PopupLinks; 77 typedef std::map<views::MenuButton*, MediaMenuParts*> MediaMenuPartsMap; 78 79 // views::ButtonListener: 80 virtual void ButtonPressed(views::Button* sender, 81 const ui::Event& event) OVERRIDE; 82 83 // views::LinkListener: 84 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; 85 86 // views::MenuButtonListener: 87 virtual void OnMenuButtonClicked(views::View* source, 88 const gfx::Point& point) OVERRIDE; 89 90 // content::NotificationObserver: 91 virtual void Observe(int type, 92 const content::NotificationSource& source, 93 const content::NotificationDetails& details) OVERRIDE; 94 95 // Helper to get the preferred width of the media menu. 96 int GetPreferredMediaMenuWidth(views::MenuButton* button, 97 ui::SimpleMenuModel* menu_model); 98 99 // Provides data for this bubble. 100 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model_; 101 102 // The active web contents. 103 content::WebContents* web_contents_; 104 105 // A registrar for listening for WEB_CONTENTS_DESTROYED notifications. 106 content::NotificationRegistrar registrar_; 107 108 // Some of our controls, so we can tell what's been clicked when we get a 109 // message. 110 PopupLinks popup_links_; 111 typedef std::vector<views::RadioButton*> RadioGroup; 112 RadioGroup radio_group_; 113 views::LabelButton* cancel_button_; 114 views::LabelButton* save_button_; 115 views::Link* custom_link_; 116 views::Link* manage_link_; 117 views::LabelButton* close_button_; 118 scoped_ptr<views::MenuRunner> menu_runner_; 119 MediaMenuPartsMap media_menus_; 120 121 DISALLOW_IMPLICIT_CONSTRUCTORS(ContentSettingBubbleContents); 122}; 123 124#endif // CHROME_BROWSER_UI_VIEWS_CONTENT_SETTING_BUBBLE_CONTENTS_H_ 125