Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_CONTENT_SETTING_BUBBLE_CONTENTS_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_CONTENT_SETTING_BUBBLE_CONTENTS_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_CONTENT_SETTING_BUBBLE_CONTENTS_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_CONTENT_SETTING_BUBBLE_CONTENTS_H_ |
| 7 | 7 |
| 8 #include <list> | |
| 8 #include <map> | 9 #include <map> |
| 9 | 10 |
| 10 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "components/content_settings/core/common/content_settings_types.h" | 13 #include "components/content_settings/core/common/content_settings_types.h" |
| 13 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
| 14 #include "content/public/common/media_stream_request.h" | 15 #include "content/public/common/media_stream_request.h" |
| 16 #include "ui/base/models/combobox_model.h" | |
| 15 #include "ui/views/bubble/bubble_dialog_delegate.h" | 17 #include "ui/views/bubble/bubble_dialog_delegate.h" |
| 16 #include "ui/views/controls/button/button.h" | 18 #include "ui/views/controls/button/button.h" |
| 17 #include "ui/views/controls/button/menu_button_listener.h" | 19 #include "ui/views/controls/combobox/combobox_listener.h" |
| 18 #include "ui/views/controls/link_listener.h" | 20 #include "ui/views/controls/link_listener.h" |
| 19 | 21 |
| 20 class ContentSettingBubbleModel; | 22 class ContentSettingBubbleModel; |
| 21 class ContentSettingMediaMenuModel; | |
| 22 class Profile; | 23 class Profile; |
| 23 | 24 |
| 24 namespace chrome { | 25 namespace chrome { |
| 25 class ContentSettingBubbleViewsBridge; | 26 class ContentSettingBubbleViewsBridge; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace ui { | |
| 29 class SimpleMenuModel; | |
| 30 } | |
| 31 | |
| 32 namespace views { | 29 namespace views { |
| 33 class LabelButton; | 30 class LabelButton; |
| 34 class MenuButton; | |
| 35 class MenuRunner; | |
| 36 class RadioButton; | 31 class RadioButton; |
| 37 } | 32 } |
| 38 | 33 |
| 39 // ContentSettingBubbleContents is used when the user turns on different kinds | 34 // ContentSettingBubbleContents is used when the user turns on different kinds |
| 40 // of content blocking (e.g. "block images"). When viewing a page with blocked | 35 // of content blocking (e.g. "block images"). When viewing a page with blocked |
| 41 // content, icons appear in the omnibox corresponding to the content types that | 36 // content, icons appear in the omnibox corresponding to the content types that |
| 42 // were blocked, and the user can click one to get a bubble hosting a few | 37 // were blocked, and the user can click one to get a bubble hosting a few |
| 43 // controls. This class provides the content of that bubble. In general, | 38 // controls. This class provides the content of that bubble. In general, |
| 44 // these bubbles typically have a title, a pair of radio buttons for toggling | 39 // these bubbles typically have a title, a pair of radio buttons for toggling |
| 45 // the blocking settings for the current site, a close button, and a link to | 40 // the blocking settings for the current site, a close button, and a link to |
| 46 // get to a more comprehensive settings management dialog. A few types have | 41 // get to a more comprehensive settings management dialog. A few types have |
| 47 // more or fewer controls than this. | 42 // more or fewer controls than this. |
| 48 class ContentSettingBubbleContents : public content::WebContentsObserver, | 43 class ContentSettingBubbleContents : public content::WebContentsObserver, |
| 49 public views::BubbleDialogDelegateView, | 44 public views::BubbleDialogDelegateView, |
| 50 public views::ButtonListener, | 45 public views::ButtonListener, |
| 51 public views::LinkListener, | 46 public views::LinkListener, |
| 52 public views::MenuButtonListener { | 47 public views::ComboboxListener { |
| 53 public: | 48 public: |
| 54 ContentSettingBubbleContents( | 49 ContentSettingBubbleContents( |
| 55 ContentSettingBubbleModel* content_setting_bubble_model, | 50 ContentSettingBubbleModel* content_setting_bubble_model, |
| 56 content::WebContents* web_contents, | 51 content::WebContents* web_contents, |
| 57 views::View* anchor_view, | 52 views::View* anchor_view, |
| 58 views::BubbleBorder::Arrow arrow); | 53 views::BubbleBorder::Arrow arrow); |
| 59 ~ContentSettingBubbleContents() override; | 54 ~ContentSettingBubbleContents() override; |
| 60 | 55 |
| 61 gfx::Size GetPreferredSize() const override; | 56 gfx::Size GetPreferredSize() const override; |
| 62 | 57 |
| 63 // Callback to allow ContentSettingMediaMenuModel to update the menu label. | |
| 64 void UpdateMenuLabel(content::MediaStreamType type, | |
| 65 const std::string& label); | |
| 66 | |
| 67 protected: | 58 protected: |
| 68 // views::BubbleDialogDelegateView: | 59 // views::BubbleDialogDelegateView: |
| 69 void Init() override; | 60 void Init() override; |
| 70 View* CreateExtraView() override; | 61 View* CreateExtraView() override; |
| 71 int GetDialogButtons() const override; | 62 int GetDialogButtons() const override; |
| 72 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; | 63 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; |
| 73 | 64 |
| 74 private: | 65 private: |
| 66 // A combobox model that builds the contents of the media capture devices menu | |
| 67 // in the content setting bubble. | |
| 68 class MediaComboboxModel : public ui::ComboboxModel { | |
| 69 public: | |
| 70 explicit MediaComboboxModel(content::MediaStreamType type); | |
| 71 ~MediaComboboxModel() override; | |
| 72 | |
| 73 content::MediaStreamType type() const { return type_; } | |
| 74 const content::MediaStreamDevices& GetDevices() const; | |
| 75 int GetDeviceIndex(const content::MediaStreamDevice& device) const; | |
| 76 | |
| 77 // ui::ComboboxModel | |
|
msw
2016/05/13 18:18:13
nit: add a trailing colon
Evan Stade
2016/05/13 18:46:12
Done.
| |
| 78 int GetItemCount() const override; | |
| 79 base::string16 GetItemAt(int index) override; | |
| 80 | |
| 81 private: | |
| 82 content::MediaStreamType type_; | |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(MediaComboboxModel); | |
| 85 }; | |
| 86 | |
| 75 class Favicon; | 87 class Favicon; |
| 76 struct MediaMenuParts; | |
| 77 | 88 |
| 78 // This allows ContentSettingBubbleViewsBridge to call SetAnchorRect(). | 89 // This allows ContentSettingBubbleViewsBridge to call SetAnchorRect(). |
| 79 friend class chrome::ContentSettingBubbleViewsBridge; | 90 friend class chrome::ContentSettingBubbleViewsBridge; |
| 80 | 91 |
| 81 typedef std::map<views::Link*, int> ListItemLinks; | 92 typedef std::map<views::Link*, int> ListItemLinks; |
| 82 typedef std::map<views::MenuButton*, MediaMenuParts*> MediaMenuPartsMap; | |
| 83 | 93 |
| 84 // content::WebContentsObserver: | 94 // content::WebContentsObserver: |
| 85 void DidNavigateMainFrame( | 95 void DidNavigateMainFrame( |
| 86 const content::LoadCommittedDetails& details, | 96 const content::LoadCommittedDetails& details, |
| 87 const content::FrameNavigateParams& params) override; | 97 const content::FrameNavigateParams& params) override; |
| 88 | 98 |
| 89 // views::ButtonListener: | 99 // views::ButtonListener: |
| 90 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 100 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 91 | 101 |
| 92 // views::LinkListener: | 102 // views::LinkListener: |
| 93 void LinkClicked(views::Link* source, int event_flags) override; | 103 void LinkClicked(views::Link* source, int event_flags) override; |
| 94 | 104 |
| 95 // views::MenuButtonListener: | 105 // views::ComboboxListener: |
| 96 void OnMenuButtonClicked(views::MenuButton* source, | 106 void OnPerformAction(views::Combobox* combobox) override; |
| 97 const gfx::Point& point, | |
| 98 const ui::Event* event) override; | |
| 99 | |
| 100 // Helper to get the preferred width of the media menu. | |
| 101 void UpdateMenuButtonSizes(); | |
| 102 | 107 |
| 103 // Provides data for this bubble. | 108 // Provides data for this bubble. |
| 104 std::unique_ptr<ContentSettingBubbleModel> content_setting_bubble_model_; | 109 std::unique_ptr<ContentSettingBubbleModel> content_setting_bubble_model_; |
| 105 | 110 |
| 106 // Some of our controls, so we can tell what's been clicked when we get a | 111 // Some of our controls, so we can tell what's been clicked when we get a |
| 107 // message. | 112 // message. |
| 108 ListItemLinks list_item_links_; | 113 ListItemLinks list_item_links_; |
| 109 typedef std::vector<views::RadioButton*> RadioGroup; | 114 typedef std::vector<views::RadioButton*> RadioGroup; |
| 110 RadioGroup radio_group_; | 115 RadioGroup radio_group_; |
| 111 views::Link* custom_link_; | 116 views::Link* custom_link_; |
| 112 views::Link* manage_link_; | 117 views::Link* manage_link_; |
| 113 views::Link* learn_more_link_; | 118 views::Link* learn_more_link_; |
| 114 views::LabelButton* close_button_; | 119 views::LabelButton* close_button_; |
| 115 std::unique_ptr<views::MenuRunner> menu_runner_; | 120 |
| 116 MediaMenuPartsMap media_menus_; | 121 // Combobox models the bubble owns. |
| 122 std::list<MediaComboboxModel> combobox_models_; | |
| 117 | 123 |
| 118 DISALLOW_IMPLICIT_CONSTRUCTORS(ContentSettingBubbleContents); | 124 DISALLOW_IMPLICIT_CONSTRUCTORS(ContentSettingBubbleContents); |
| 119 }; | 125 }; |
| 120 | 126 |
| 121 #endif // CHROME_BROWSER_UI_VIEWS_CONTENT_SETTING_BUBBLE_CONTENTS_H_ | 127 #endif // CHROME_BROWSER_UI_VIEWS_CONTENT_SETTING_BUBBLE_CONTENTS_H_ |
| OLD | NEW |