Home | History | Annotate | Download | only in views
      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 "components/content_settings/core/common/content_settings_types.h"
     13 #include "content/public/browser/web_contents_observer.h"
     14 #include "content/public/common/media_stream_request.h"
     15 #include "ui/views/bubble/bubble_delegate.h"
     16 #include "ui/views/controls/button/button.h"
     17 #include "ui/views/controls/button/menu_button_listener.h"
     18 #include "ui/views/controls/link_listener.h"
     19 
     20 class ContentSettingBubbleModel;
     21 class ContentSettingMediaMenuModel;
     22 class Profile;
     23 
     24 namespace ui {
     25 class SimpleMenuModel;
     26 }
     27 
     28 namespace views {
     29 class LabelButton;
     30 class MenuButton;
     31 class MenuRunner;
     32 class RadioButton;
     33 }
     34 
     35 // ContentSettingBubbleContents is used when the user turns on different kinds
     36 // of content blocking (e.g. "block images").  When viewing a page with blocked
     37 // content, icons appear in the omnibox corresponding to the content types that
     38 // were blocked, and the user can click one to get a bubble hosting a few
     39 // controls.  This class provides the content of that bubble.  In general,
     40 // these bubbles typically have a title, a pair of radio buttons for toggling
     41 // the blocking settings for the current site, a close button, and a link to
     42 // get to a more comprehensive settings management dialog.  A few types have
     43 // more or fewer controls than this.
     44 class ContentSettingBubbleContents : public content::WebContentsObserver,
     45                                      public views::BubbleDelegateView,
     46                                      public views::ButtonListener,
     47                                      public views::LinkListener,
     48                                      public views::MenuButtonListener {
     49  public:
     50   ContentSettingBubbleContents(
     51       ContentSettingBubbleModel* content_setting_bubble_model,
     52       content::WebContents* web_contents,
     53       views::View* anchor_view,
     54       views::BubbleBorder::Arrow arrow);
     55   virtual ~ContentSettingBubbleContents();
     56 
     57   virtual gfx::Size GetPreferredSize() const OVERRIDE;
     58 
     59   // 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::View:
     80   virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE;
     81 
     82   // views::ButtonListener:
     83   virtual void ButtonPressed(views::Button* sender,
     84                              const ui::Event& event) OVERRIDE;
     85 
     86   // views::LinkListener:
     87   virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
     88 
     89   // views::MenuButtonListener:
     90   virtual void OnMenuButtonClicked(views::View* source,
     91                                    const gfx::Point& point) OVERRIDE;
     92 
     93   // Helper to get the preferred width of the media menu.
     94   void UpdateMenuButtonSizes(const ui::NativeTheme* theme);
     95 
     96   // Provides data for this bubble.
     97   scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model_;
     98 
     99   // Some of our controls, so we can tell what's been clicked when we get a
    100   // message.
    101   PopupLinks popup_links_;
    102   typedef std::vector<views::RadioButton*> RadioGroup;
    103   RadioGroup radio_group_;
    104   views::Link* custom_link_;
    105   views::Link* manage_link_;
    106   views::Link* learn_more_link_;
    107   views::LabelButton* close_button_;
    108   scoped_ptr<views::MenuRunner> menu_runner_;
    109   MediaMenuPartsMap media_menus_;
    110 
    111   DISALLOW_IMPLICIT_CONSTRUCTORS(ContentSettingBubbleContents);
    112 };
    113 
    114 #endif  // CHROME_BROWSER_UI_VIEWS_CONTENT_SETTING_BUBBLE_CONTENTS_H_
    115