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_GTK_CONTENT_SETTING_BUBBLE_GTK_H_ 6 #define CHROME_BROWSER_UI_GTK_CONTENT_SETTING_BUBBLE_GTK_H_ 7 8 #include <map> 9 10 #include "base/compiler_specific.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" 13 #include "chrome/browser/ui/gtk/menu_gtk.h" 14 #include "chrome/common/content_settings_types.h" 15 #include "content/public/browser/notification_observer.h" 16 #include "content/public/browser/notification_registrar.h" 17 #include "content/public/common/media_stream_request.h" 18 #include "ui/base/gtk/gtk_signal.h" 19 #include "ui/base/gtk/owned_widget_gtk.h" 20 21 class ContentSettingBubbleModel; 22 class ContentSettingMediaMenuModel; 23 class Profile; 24 25 namespace content { 26 class WebContents; 27 } 28 29 namespace ui { 30 class SimpleMenuModel; 31 } 32 33 // ContentSettingBubbleGtk is used when the user turns on different kinds of 34 // content blocking (e.g. "block images"). An icon appears in the location bar, 35 // and when clicked, an instance of this class is created specialized for the 36 // type of content being blocked. 37 class ContentSettingBubbleGtk : public BubbleDelegateGtk, 38 public content::NotificationObserver { 39 public: 40 ContentSettingBubbleGtk( 41 GtkWidget* anchor, 42 BubbleDelegateGtk* delegate, 43 ContentSettingBubbleModel* content_setting_bubble_model, 44 Profile* profile, content::WebContents* web_contents); 45 virtual ~ContentSettingBubbleGtk(); 46 47 // Callback to allow ContentSettingMediaMenuModel to update the menu label. 48 void UpdateMenuLabel(content::MediaStreamType type, 49 const std::string& label); 50 51 // Dismisses the bubble. 52 void Close(); 53 54 private: 55 // A map from a GtkWidget* to a MediaMenuGtk*. MediaMenuGtk struct is used 56 // to store the UI members that a media menu owns. 57 struct MediaMenuGtk { 58 explicit MediaMenuGtk(content::MediaStreamType type); 59 ~MediaMenuGtk(); 60 61 content::MediaStreamType type; 62 scoped_ptr<ui::SimpleMenuModel> menu_model; 63 scoped_ptr<MenuGtk> menu; 64 ui::OwnedWidgetGtk label; 65 66 private: 67 DISALLOW_COPY_AND_ASSIGN(MediaMenuGtk); 68 }; 69 typedef std::map<GtkWidget*, MediaMenuGtk*> GtkMediaMenuMap; 70 71 typedef std::map<GtkWidget*, int> PopupMap; 72 73 // BubbleDelegateGtk: 74 virtual void BubbleClosing(BubbleGtk* bubble, bool closed_by_escape) OVERRIDE; 75 76 // content::NotificationObserver: 77 virtual void Observe(int type, 78 const content::NotificationSource& source, 79 const content::NotificationDetails& details) OVERRIDE; 80 81 // Builds the bubble and all the widgets that it displays. 82 void BuildBubble(); 83 84 // Widget callback methods. 85 CHROMEGTK_CALLBACK_1(ContentSettingBubbleGtk, void, OnPopupIconButtonPress, 86 GdkEventButton*); 87 CHROMEGTK_CALLBACK_0(ContentSettingBubbleGtk, void, OnPopupLinkClicked); 88 CHROMEGTK_CALLBACK_0(ContentSettingBubbleGtk, void, OnRadioToggled); 89 CHROMEGTK_CALLBACK_0(ContentSettingBubbleGtk, void, OnCustomLinkClicked); 90 CHROMEGTK_CALLBACK_0(ContentSettingBubbleGtk, void, OnManageLinkClicked); 91 CHROMEGTK_CALLBACK_0(ContentSettingBubbleGtk, void, OnCloseButtonClicked); 92 CHROMEGTK_CALLBACK_0(ContentSettingBubbleGtk, void, OnMenuButtonClicked); 93 94 // We position the bubble near this widget. 95 GtkWidget* anchor_; 96 97 // The active profile. 98 Profile* profile_; 99 100 // The active web contents. 101 content::WebContents* web_contents_; 102 103 // A registrar for listening for WEB_CONTENTS_DESTROYED notifications. 104 content::NotificationRegistrar registrar_; 105 106 // Pass on delegate messages to this. 107 BubbleDelegateGtk* delegate_; 108 109 // Provides data for this bubble. 110 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model_; 111 112 // The bubble. 113 BubbleGtk* bubble_; 114 115 // Stored controls so we can figure out what was clicked. 116 PopupMap popup_links_; 117 PopupMap popup_icons_; 118 119 typedef std::vector<GtkWidget*> RadioGroupGtk; 120 RadioGroupGtk radio_group_gtk_; 121 122 GtkMediaMenuMap media_menus_; 123 }; 124 125 #endif // CHROME_BROWSER_UI_GTK_CONTENT_SETTING_BUBBLE_GTK_H_ 126