content_setting_bubble_model.h revision c407dc5cd9bdc5668497f21b26b09d988ab439de
1// Copyright (c) 2010 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_CONTENT_SETTING_BUBBLE_MODEL_H_ 6#define CHROME_BROWSER_CONTENT_SETTING_BUBBLE_MODEL_H_ 7 8#include <set> 9#include <string> 10#include <vector> 11 12#include "chrome/common/content_settings.h" 13#include "chrome/common/notification_observer.h" 14#include "chrome/common/notification_registrar.h" 15#include "googleurl/src/gurl.h" 16#include "third_party/skia/include/core/SkBitmap.h" 17 18class Profile; 19class SkBitmap; 20class TabContents; 21 22// This model provides data for ContentSettingBubble, and also controls 23// the action triggered when the allow / block radio buttons are triggered. 24class ContentSettingBubbleModel : public NotificationObserver { 25 public: 26 virtual ~ContentSettingBubbleModel(); 27 28 static ContentSettingBubbleModel* CreateContentSettingBubbleModel( 29 TabContents* tab_contents, 30 Profile* profile, 31 ContentSettingsType content_type); 32 33 ContentSettingsType content_type() const { return content_type_; } 34 35 struct PopupItem { 36 SkBitmap bitmap; 37 std::string title; 38 TabContents* tab_contents; 39 }; 40 typedef std::vector<PopupItem> PopupItems; 41 42 typedef std::vector<std::string> RadioItems; 43 struct RadioGroup { 44 GURL url; 45 std::string title; 46 RadioItems radio_items; 47 int default_item; 48 }; 49 50 struct DomainList { 51 std::string title; 52 std::set<std::string> hosts; 53 }; 54 55 struct BubbleContent { 56 std::string title; 57 PopupItems popup_items; 58 RadioGroup radio_group; 59 std::vector<DomainList> domain_lists; 60 std::string manage_link; 61 std::string clear_link; 62 std::string info_link; 63 }; 64 65 const BubbleContent& bubble_content() const { return bubble_content_; } 66 67 // NotificationObserver: 68 virtual void Observe(NotificationType type, 69 const NotificationSource& source, 70 const NotificationDetails& details); 71 72 virtual void OnRadioClicked(int radio_index) {} 73 virtual void OnPopupClicked(int index) {} 74 virtual void OnManageLinkClicked() {} 75 virtual void OnClearLinkClicked() {} 76 virtual void OnInfoLinkClicked() {} 77 78 protected: 79 ContentSettingBubbleModel(TabContents* tab_contents, Profile* profile, 80 ContentSettingsType content_type); 81 82 TabContents* tab_contents() const { return tab_contents_; } 83 Profile* profile() const { return profile_; } 84 85 void set_title(const std::string& title) { bubble_content_.title = title; } 86 void add_popup(const PopupItem& popup) { 87 bubble_content_.popup_items.push_back(popup); 88 } 89 void set_radio_group(const RadioGroup& radio_group) { 90 bubble_content_.radio_group = radio_group; 91 } 92 void add_domain_list(const DomainList& domain_list) { 93 bubble_content_.domain_lists.push_back(domain_list); 94 } 95 void set_manage_link(const std::string& link) { 96 bubble_content_.manage_link = link; 97 } 98 void set_clear_link(const std::string& link) { 99 bubble_content_.clear_link = link; 100 } 101 void set_info_link(const std::string& link) { 102 bubble_content_.info_link = link; 103 } 104 105 private: 106 TabContents* tab_contents_; 107 Profile* profile_; 108 ContentSettingsType content_type_; 109 BubbleContent bubble_content_; 110 // A registrar for listening for TAB_CONTENTS_DESTROYED notifications. 111 NotificationRegistrar registrar_; 112}; 113 114#endif // CHROME_BROWSER_CONTENT_SETTING_BUBBLE_MODEL_H_ 115