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