content_setting_bubble_contents.h revision cedac228d2dd51db4b79ea1e72c7f249408ee061
12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2011 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CHROME_BROWSER_UI_VIEWS_CONTENT_SETTING_BUBBLE_CONTENTS_H_
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CHROME_BROWSER_UI_VIEWS_CONTENT_SETTING_BUBBLE_CONTENTS_H_
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <map>
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/basictypes.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/compiler_specific.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/content_settings_types.h"
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/web_contents_observer.h"
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/common/media_stream_request.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/bubble/bubble_delegate.h"
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/controls/button/button.h"
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/controls/button/menu_button_listener.h"
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/controls/link_listener.h"
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ContentSettingBubbleModel;
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ContentSettingMediaMenuModel;
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class Profile;
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace ui {
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class SimpleMenuModel;
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace views {
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class LabelButton;
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MenuButton;
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MenuRunner;
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class RadioButton;
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// ContentSettingBubbleContents is used when the user turns on different kinds
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// of content blocking (e.g. "block images").  When viewing a page with blocked
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// content, icons appear in the omnibox corresponding to the content types that
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// were blocked, and the user can click one to get a bubble hosting a few
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// controls.  This class provides the content of that bubble.  In general,
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// these bubbles typically have a title, a pair of radio buttons for toggling
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// the blocking settings for the current site, a close button, and a link to
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// get to a more comprehensive settings management dialog.  A few types have
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// more or fewer controls than this.
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ContentSettingBubbleContents : public content::WebContentsObserver,
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                     public views::BubbleDelegateView,
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                     public views::ButtonListener,
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                     public views::LinkListener,
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                     public views::MenuButtonListener {
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ContentSettingBubbleContents(
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      ContentSettingBubbleModel* content_setting_bubble_model,
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      content::WebContents* web_contents,
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      views::View* anchor_view,
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      views::BubbleBorder::Arrow arrow);
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~ContentSettingBubbleContents();
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual gfx::Size GetPreferredSize() const OVERRIDE;
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Callback to allow ContentSettingMediaMenuModel to update the menu label.
60  void UpdateMenuLabel(content::MediaStreamType type,
61                       const std::string& label);
62
63 protected:
64  // views::BubbleDelegateView:
65  virtual void Init() OVERRIDE;
66
67 private:
68  class Favicon;
69  struct MediaMenuParts;
70
71  typedef std::map<views::Link*, int> PopupLinks;
72  typedef std::map<views::MenuButton*, MediaMenuParts*> MediaMenuPartsMap;
73
74  // content::WebContentsObserver:
75  virtual void DidNavigateMainFrame(
76      const content::LoadCommittedDetails& details,
77      const content::FrameNavigateParams& params) OVERRIDE;
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  // Helper to get the preferred width of the media menu.
91  int GetPreferredMediaMenuWidth(views::MenuButton* button,
92                                 ui::SimpleMenuModel* menu_model);
93
94  // Provides data for this bubble.
95  scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model_;
96
97  // Some of our controls, so we can tell what's been clicked when we get a
98  // message.
99  PopupLinks popup_links_;
100  typedef std::vector<views::RadioButton*> RadioGroup;
101  RadioGroup radio_group_;
102  views::Link* custom_link_;
103  views::Link* manage_link_;
104  views::LabelButton* close_button_;
105  scoped_ptr<views::MenuRunner> menu_runner_;
106  MediaMenuPartsMap media_menus_;
107
108  DISALLOW_IMPLICIT_CONSTRUCTORS(ContentSettingBubbleContents);
109};
110
111#endif  // CHROME_BROWSER_UI_VIEWS_CONTENT_SETTING_BUBBLE_CONTENTS_H_
112