Commit 428eaaad authored by meacer's avatar meacer Committed by Commit bot
parent 12846b3c
......@@ -236,10 +236,6 @@ void TabSpecificContentSettings::FileSystemAccessed(int render_process_id,
settings->OnFileSystemAccessed(url, blocked_by_policy);
}
const base::string16 TabSpecificContentSettings::GetBlockedPluginNames() const {
return JoinString(blocked_plugin_names_, base::ASCIIToUTF16(", "));
}
bool TabSpecificContentSettings::IsContentBlocked(
ContentSettingsType content_type) const {
DCHECK(content_type != CONTENT_SETTINGS_TYPE_GEOLOCATION)
......
......@@ -180,7 +180,9 @@ class TabSpecificContentSettings
bool IsContentAllowed(ContentSettingsType content_type) const;
// Returns the names of plugins that have been blocked for this tab.
const base::string16 GetBlockedPluginNames() const;
const std::vector<base::string16>& blocked_plugin_names() const {
return blocked_plugin_names_;
}
const GURL& media_stream_access_origin() const {
return media_stream_access_origin_;
......
......@@ -210,7 +210,7 @@ class ContentSettingBubbleWebContentsObserverBridge
- (void)initializeBlockedPluginsList;
- (void)initializeTitle;
- (void)initializeRadioGroup;
- (void)initializePopupList;
- (void)initializeItemList;
- (void)initializeGeoLists;
- (void)initializeMediaMenus;
- (void)initializeMIDISysExLists;
......@@ -384,16 +384,20 @@ class ContentSettingBubbleWebContentsObserverBridge
}
- (void)initializeBlockedPluginsList {
NSString* label = base::SysUTF16ToNSString(
contentSettingBubbleModel_->bubble_content().plugin_names);
[blockedResourcesField_ setStringValue:label];
// Hide the empty label at the top of the dialog.
int delta =
NSMinY([titleLabel_ frame]) - NSMinY([blockedResourcesField_ frame]);
[blockedResourcesField_ removeFromSuperview];
NSRect frame = [[self window] frame];
frame.size.height -= delta;
[[self window] setFrame:frame display:NO];
}
- (void)initializePopupList {
- (void)initializeItemList {
// I didn't put the buttons into a NSMatrix because then they are only one
// entity in the key view loop. This way, one can tab through all of them.
const ContentSettingBubbleModel::PopupItems& popupItems =
contentSettingBubbleModel_->bubble_content().popup_items;
const ContentSettingBubbleModel::ListItems& listItems =
contentSettingBubbleModel_->bubble_content().list_items;
// Get the pre-resize frame of the radio group. Its origin is where the
// popup list should go.
......@@ -403,37 +407,36 @@ class ContentSettingBubbleWebContentsObserverBridge
// themselves when the window is enlarged.
// Heading and radio box are already 1 * kLinkOuterPadding apart in the nib,
// so only 1 * kLinkOuterPadding more is needed.
int delta = popupItems.size() * kLinkLineHeight - kLinkPadding +
kLinkOuterPadding;
int delta =
listItems.size() * kLinkLineHeight - kLinkPadding + kLinkOuterPadding;
NSSize deltaSize = NSMakeSize(0, delta);
deltaSize = [[[self window] contentView] convertSize:deltaSize toView:nil];
NSRect windowFrame = [[self window] frame];
windowFrame.size.height += deltaSize.height;
[[self window] setFrame:windowFrame display:NO];
// Create popup list.
// Create item list.
int topLinkY = NSMaxY(radioFrame) + delta - kLinkHeight;
int row = 0;
for (std::vector<ContentSettingBubbleModel::PopupItem>::const_iterator
it(popupItems.begin()); it != popupItems.end(); ++it, ++row) {
NSImage* image = it->image.AsNSImage();
std::string title(it->title);
// The popup may not have committed a load yet, in which case it won't
// have a URL or title.
if (title.empty())
title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE);
NSRect linkFrame =
NSMakeRect(NSMinX(radioFrame), topLinkY - kLinkLineHeight * row,
200, kLinkHeight);
NSButton* button = [self
hyperlinkButtonWithFrame:linkFrame
title:base::SysUTF8ToNSString(title)
for (const ContentSettingBubbleModel::ListItem& listItem : listItems) {
NSImage* image = listItem.image.AsNSImage();
NSRect frame = NSMakeRect(
NSMinX(radioFrame), topLinkY - kLinkLineHeight * row, 200, kLinkHeight);
if (listItem.has_link) {
NSButton* button =
[self hyperlinkButtonWithFrame:frame
title:base::SysUTF8ToNSString(listItem.title)
icon:image
referenceFrame:radioFrame];
[[self bubble] addSubview:button];
popupLinks_[button] = row;
popupLinks_[button] = row++;
} else {
NSTextField* label =
LabelWithFrame(base::SysUTF8ToNSString(listItem.title), frame);
SetControlSize(label, NSSmallControlSize);
[[self bubble] addSubview:label];
row++;
}
}
}
......@@ -531,12 +534,13 @@ class ContentSettingBubbleWebContentsObserverBridge
CGFloat maxMenuWidth = 0;
CGFloat maxMenuHeight = 0;
NSRect radioFrame = [allowBlockRadioGroup_ frame];
for (ContentSettingBubbleModel::MediaMenuMap::const_iterator it(
media_menus.begin()); it != media_menus.end(); ++it) {
for (const std::pair<content::MediaStreamType,
ContentSettingBubbleModel::MediaMenu>& map_entry :
media_menus) {
// |labelFrame| will be resized later on in this function.
NSRect labelFrame = NSMakeRect(NSMinX(radioFrame), 0, 0, 0);
NSTextField* label =
LabelWithFrame(base::SysUTF8ToNSString(it->second.label), labelFrame);
NSTextField* label = LabelWithFrame(
base::SysUTF8ToNSString(map_entry.second.label), labelFrame);
SetControlSize(label, NSSmallControlSize);
NSCell* cell = [label cell];
[cell setAlignment:NSRightTextAlignment];
......@@ -553,15 +557,14 @@ class ContentSettingBubbleWebContentsObserverBridge
// Store the |label| and |button| into MediaMenuParts struct and build
// the popup menu from the menu model.
content_setting_bubble::MediaMenuParts* menuParts =
new content_setting_bubble::MediaMenuParts(it->first, label);
new content_setting_bubble::MediaMenuParts(map_entry.first, label);
menuParts->model.reset(new ContentSettingMediaMenuModel(
it->first, contentSettingBubbleModel_.get(),
map_entry.first, contentSettingBubbleModel_.get(),
ContentSettingMediaMenuModel::MenuLabelChangedCallback()));
mediaMenus_[button] = menuParts;
CGFloat width = BuildPopUpMenuFromModel(button,
menuParts->model.get(),
it->second.selected_device.name,
it->second.disabled);
CGFloat width = BuildPopUpMenuFromModel(
button, menuParts->model.get(), map_entry.second.selected_device.name,
map_entry.second.disabled);
maxMenuWidth = std::max(maxMenuWidth, width);
[[self bubble] addSubview:button
......@@ -593,20 +596,20 @@ class ContentSettingBubbleWebContentsObserverBridge
// Resize and reposition the media menus layout.
CGFloat topMenuY = NSMinY(radioFrame) - kMediaMenuVerticalPadding;
maxMenuWidth = std::max(maxMenuWidth, kMinMediaMenuButtonWidth);
for (content_setting_bubble::MediaMenuPartsMap::const_iterator i =
mediaMenus_.begin(); i != mediaMenus_.end(); ++i) {
NSRect labelFrame = [i->second->label frame];
for (const std::pair<NSPopUpButton*, content_setting_bubble::MediaMenuParts*>&
map_entry : mediaMenus_) {
NSRect labelFrame = [map_entry.second->label frame];
// Align the label text with the button text.
labelFrame.origin.y =
topMenuY + (maxMenuHeight - labelFrame.size.height) / 2 + 1;
labelFrame.size.width = maxLabelWidth;
[i->second->label setFrame:labelFrame];
NSRect menuFrame = [i->first frame];
[map_entry.second->label setFrame:labelFrame];
NSRect menuFrame = [map_entry.first frame];
menuFrame.origin.y = topMenuY;
menuFrame.origin.x = NSMinX(radioFrame) + maxLabelWidth;
menuFrame.size.width = maxMenuWidth;
menuFrame.size.height = maxMenuHeight;
[i->first setFrame:menuFrame];
[map_entry.first setFrame:menuFrame];
topMenuY -= (maxMenuHeight + kMediaMenuElementVerticalPadding);
}
}
......@@ -748,8 +751,9 @@ class ContentSettingBubbleWebContentsObserverBridge
if (allowBlockRadioGroup_) // not bound in cookie bubble xib
[self initializeRadioGroup];
if (type == CONTENT_SETTINGS_TYPE_POPUPS)
[self initializePopupList];
if (type == CONTENT_SETTINGS_TYPE_POPUPS ||
type == CONTENT_SETTINGS_TYPE_PLUGINS)
[self initializeItemList];
if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION)
[self initializeGeoLists];
if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM)
......@@ -769,7 +773,7 @@ class ContentSettingBubbleWebContentsObserverBridge
- (void)popupLinkClicked:(id)sender {
content_setting_bubble::PopupLinks::iterator i(popupLinks_.find(sender));
DCHECK(i != popupLinks_.end());
contentSettingBubbleModel_->OnPopupClicked(i->second);
contentSettingBubbleModel_->OnListItemClicked(i->second);
}
- (void)clearGeolocationForCurrentHost:(id)sender {
......
......@@ -36,6 +36,7 @@
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "grit/components_strings.h"
#include "grit/theme_resources.h"
#include "net/base/net_util.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
......@@ -79,10 +80,9 @@ const content::MediaStreamDevice& GetMediaDeviceById(
const std::string& device_id,
const content::MediaStreamDevices& devices) {
DCHECK(!devices.empty());
for (content::MediaStreamDevices::const_iterator it = devices.begin();
it != devices.end(); ++it) {
if (it->id == device_id)
return *(it);
for (const content::MediaStreamDevice& device : devices) {
if (device.id == device_id)
return device;
}
// A device with the |device_id| was not found. It is likely that the device
......@@ -114,11 +114,6 @@ void ContentSettingTitleAndLinkModel::SetTitle() {
TabSpecificContentSettings::FromWebContents(web_contents());
}
if (content_type() == CONTENT_SETTINGS_TYPE_PLUGINS && content_settings &&
content_settings->IsContentBlocked(content_type())) {
set_plugin_names(content_settings->GetBlockedPluginNames());
}
static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = {
{CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE},
{CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE},
......@@ -425,8 +420,7 @@ class ContentSettingCookiesBubbleModel : public ContentSettingSingleRadioGroup {
public:
ContentSettingCookiesBubbleModel(Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ContentSettingsType content_type);
Profile* profile);
~ContentSettingCookiesBubbleModel() override;
......@@ -437,11 +431,11 @@ class ContentSettingCookiesBubbleModel : public ContentSettingSingleRadioGroup {
ContentSettingCookiesBubbleModel::ContentSettingCookiesBubbleModel(
Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ContentSettingsType content_type)
: ContentSettingSingleRadioGroup(
delegate, web_contents, profile, content_type) {
DCHECK_EQ(CONTENT_SETTINGS_TYPE_COOKIES, content_type);
Profile* profile)
: ContentSettingSingleRadioGroup(delegate,
web_contents,
profile,
CONTENT_SETTINGS_TYPE_COOKIES) {
set_custom_link_enabled(true);
}
......@@ -469,8 +463,7 @@ class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup {
public:
ContentSettingPluginBubbleModel(Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ContentSettingsType content_type);
Profile* profile);
~ContentSettingPluginBubbleModel() override;
......@@ -481,11 +474,11 @@ class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup {
ContentSettingPluginBubbleModel::ContentSettingPluginBubbleModel(
Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ContentSettingsType content_type)
: ContentSettingSingleRadioGroup(
delegate, web_contents, profile, content_type) {
DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS);
Profile* profile)
: ContentSettingSingleRadioGroup(delegate,
web_contents,
profile,
CONTENT_SETTINGS_TYPE_PLUGINS) {
// Disable the "Run all plugins this time" link if the setting is managed and
// can't be controlled by the user or if the user already clicked on the link
// and ran all plugins.
......@@ -493,6 +486,21 @@ ContentSettingPluginBubbleModel::ContentSettingPluginBubbleModel(
web_contents &&
TabSpecificContentSettings::FromWebContents(
web_contents)->load_plugins_link_enabled());
// Build blocked plugin list.
if (web_contents) {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents);
const std::vector<base::string16>& blocked_plugins =
content_settings->blocked_plugin_names();
for (const base::string16& blocked_plugin : blocked_plugins) {
ListItem plugin_item(
ui::ResourceBundle::GetSharedInstance().GetImageNamed(
IDR_BLOCKED_PLUGINS),
base::UTF16ToUTF8(blocked_plugin), false, 0);
add_list_item(plugin_item);
}
}
}
ContentSettingPluginBubbleModel::~ContentSettingPluginBubbleModel() {
......@@ -523,50 +531,47 @@ class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup {
public:
ContentSettingPopupBubbleModel(Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ContentSettingsType content_type);
Profile* profile);
~ContentSettingPopupBubbleModel() override {}
private:
void SetPopups();
void OnPopupClicked(int index) override;
void OnListItemClicked(int index) override;
int32 item_id_from_item_index(int index) const {
return bubble_content().list_items[index].item_id;
}
};
ContentSettingPopupBubbleModel::ContentSettingPopupBubbleModel(
Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ContentSettingsType content_type)
: ContentSettingSingleRadioGroup(
delegate, web_contents, profile, content_type) {
SetPopups();
}
void ContentSettingPopupBubbleModel::SetPopups() {
Profile* profile)
: ContentSettingSingleRadioGroup(delegate,
web_contents,
profile,
CONTENT_SETTINGS_TYPE_POPUPS) {
if (web_contents) {
// Build blocked popup list.
std::map<int32, GURL> blocked_popups =
PopupBlockerTabHelper::FromWebContents(web_contents())
PopupBlockerTabHelper::FromWebContents(web_contents)
->GetBlockedPopupRequests();
for (std::map<int32, GURL>::const_iterator iter = blocked_popups.begin();
iter != blocked_popups.end();
++iter) {
std::string title(iter->second.spec());
for (const std::pair<int32, GURL>& blocked_popup : blocked_popups) {
std::string title(blocked_popup.second.spec());
// The popup may not have a valid URL.
if (title.empty())
title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE);
PopupItem popup_item(
ui::ResourceBundle::GetSharedInstance().GetImageNamed(
ListItem popup_item(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
IDR_DEFAULT_FAVICON),
title,
iter->first);
add_popup(popup_item);
title, true, blocked_popup.first);
add_list_item(popup_item);
}
}
}
void ContentSettingPopupBubbleModel::OnPopupClicked(int index) {
void ContentSettingPopupBubbleModel::OnListItemClicked(int index) {
if (web_contents()) {
PopupBlockerTabHelper::FromWebContents(web_contents())->
ShowBlockedPopup(bubble_content().popup_items[index].popup_id);
PopupBlockerTabHelper::FromWebContents(web_contents())
->ShowBlockedPopup(item_id_from_item_index(index));
}
}
......@@ -640,10 +645,12 @@ ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() {
if (!web_contents())
return;
for (MediaMenuMap::const_iterator it = bubble_content().media_menus.begin();
it != bubble_content().media_menus.end(); ++it) {
if (it->second.selected_device.id != it->second.default_device.id) {
UpdateDefaultDeviceForType(it->first, it->second.selected_device.id);
for (const std::pair<content::MediaStreamType, MediaMenu>& media_menu :
bubble_content().media_menus) {
if (media_menu.second.selected_device.id !=
media_menu.second.default_device.id) {
UpdateDefaultDeviceForType(media_menu.first,
media_menu.second.selected_device.id);
}
}
......@@ -952,13 +959,11 @@ void ContentSettingDomainListBubbleModel::OnCustomLinkClicked() {
HostContentSettingsMap* settings_map =
profile()->GetHostContentSettingsMap();
for (ContentSettingsUsagesState::StateMap::const_iterator it =
state_map.begin(); it != state_map.end(); ++it) {
for (const std::pair<GURL, ContentSetting>& map_entry : state_map) {
settings_map->SetContentSetting(
ContentSettingsPattern::FromURLNoWildcard(it->first),
ContentSettingsPattern::FromURLNoWildcard(map_entry.first),
ContentSettingsPattern::FromURLNoWildcard(embedder_url),
CONTENT_SETTINGS_TYPE_GEOLOCATION,
std::string(),
CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(),
CONTENT_SETTING_DEFAULT);
}
}
......@@ -968,8 +973,7 @@ class ContentSettingMixedScriptBubbleModel
public:
ContentSettingMixedScriptBubbleModel(Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ContentSettingsType content_type);
Profile* profile);
~ContentSettingMixedScriptBubbleModel() override {}
......@@ -980,11 +984,11 @@ class ContentSettingMixedScriptBubbleModel
ContentSettingMixedScriptBubbleModel::ContentSettingMixedScriptBubbleModel(
Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ContentSettingsType content_type)
: ContentSettingTitleLinkAndCustomModel(
delegate, web_contents, profile, content_type) {
DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_MIXEDSCRIPT);
Profile* profile)
: ContentSettingTitleLinkAndCustomModel(delegate,
web_contents,
profile,
CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) {
content_settings::RecordMixedScriptAction(
content_settings::MIXED_SCRIPT_ACTION_DISPLAYED_BUBBLE);
set_custom_link_enabled(true);
......@@ -1004,16 +1008,15 @@ ContentSettingRPHBubbleModel::ContentSettingRPHBubbleModel(
Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ProtocolHandlerRegistry* registry,
ContentSettingsType content_type)
: ContentSettingTitleAndLinkModel(
delegate, web_contents, profile, content_type),
ProtocolHandlerRegistry* registry)
: ContentSettingTitleAndLinkModel(delegate,
web_contents,
profile,
CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS),
selected_item_(0),
registry_(registry),
pending_handler_(ProtocolHandler::EmptyProtocolHandler()),
previous_handler_(ProtocolHandler::EmptyProtocolHandler()) {
DCHECK_EQ(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, content_type);
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents);
pending_handler_ = content_settings->pending_protocol_handler();
......@@ -1136,8 +1139,7 @@ class ContentSettingMidiSysExBubbleModel
public:
ContentSettingMidiSysExBubbleModel(Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ContentSettingsType content_type);
Profile* profile);
~ContentSettingMidiSysExBubbleModel() override {}
private:
......@@ -1149,11 +1151,11 @@ class ContentSettingMidiSysExBubbleModel
ContentSettingMidiSysExBubbleModel::ContentSettingMidiSysExBubbleModel(
Delegate* delegate,
WebContents* web_contents,
Profile* profile,
ContentSettingsType content_type)
: ContentSettingTitleAndLinkModel(
delegate, web_contents, profile, content_type) {
DCHECK_EQ(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, content_type);
Profile* profile)
: ContentSettingTitleAndLinkModel(delegate,
web_contents,
profile,
CONTENT_SETTINGS_TYPE_MIDI_SYSEX) {
SetDomainsAndCustomLink();
}
......@@ -1207,13 +1209,11 @@ void ContentSettingMidiSysExBubbleModel::OnCustomLinkClicked() {
HostContentSettingsMap* settings_map =
profile()->GetHostContentSettingsMap();
for (ContentSettingsUsagesState::StateMap::const_iterator it =
state_map.begin(); it != state_map.end(); ++it) {
for (const std::pair<GURL, ContentSetting>& map_entry : state_map) {
settings_map->SetContentSetting(
ContentSettingsPattern::FromURLNoWildcard(it->first),
ContentSettingsPattern::FromURLNoWildcard(map_entry.first),
ContentSettingsPattern::FromURLNoWildcard(embedder_url),
CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
std::string(),
CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string(),
CONTENT_SETTING_DEFAULT);
}
}
......@@ -1226,12 +1226,11 @@ ContentSettingBubbleModel*
Profile* profile,
ContentSettingsType content_type) {
if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) {
return new ContentSettingCookiesBubbleModel(delegate, web_contents, profile,
content_type);
return new ContentSettingCookiesBubbleModel(delegate, web_contents,
profile);
}
if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) {
return new ContentSettingPopupBubbleModel(delegate, web_contents, profile,
content_type);
return new ContentSettingPopupBubbleModel(delegate, web_contents, profile);
}
if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
return new ContentSettingDomainListBubbleModel(delegate, web_contents,
......@@ -1242,22 +1241,21 @@ ContentSettingBubbleModel*
profile);
}
if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) {
return new ContentSettingPluginBubbleModel(delegate, web_contents, profile,
content_type);
return new ContentSettingPluginBubbleModel(delegate, web_contents, profile);
}
if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) {
return new ContentSettingMixedScriptBubbleModel(delegate, web_contents,
profile, content_type);
profile);
}
if (content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) {
ProtocolHandlerRegistry* registry =
ProtocolHandlerRegistryFactory::GetForBrowserContext(profile);
return new ContentSettingRPHBubbleModel(delegate, web_contents, profile,
registry, content_type);
registry);
}
if (content_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) {
return new ContentSettingMidiSysExBubbleModel(delegate, web_contents,
profile, content_type);
profile);
}
return new ContentSettingSingleRadioGroup(delegate, web_contents, profile,
content_type);
......
......@@ -34,15 +34,19 @@ class ContentSettingBubbleModel : public content::NotificationObserver {
public:
typedef ContentSettingBubbleModelDelegate Delegate;
struct PopupItem {
PopupItem(const gfx::Image& image, const std::string& title, int32 popup_id)
: image(image), title(title), popup_id(popup_id) {}
struct ListItem {
ListItem(const gfx::Image& image,
const std::string& title,
bool has_link,
int32 item_id)
: image(image), title(title), has_link(has_link), item_id(item_id) {}
gfx::Image image;
std::string title;
int32 popup_id;
bool has_link;
int32 item_id;
};
typedef std::vector<PopupItem> PopupItems;
typedef std::vector<ListItem> ListItems;
typedef std::vector<std::string> RadioItems;
struct RadioGroup {
......@@ -79,8 +83,7 @@ class ContentSettingBubbleModel : public content::NotificationObserver {
~BubbleContent();
std::string title;
base::string16 plugin_names;
PopupItems popup_items;
ListItems list_items;
RadioGroup radio_group;
bool radio_group_enabled;
std::vector<DomainList> domain_lists;
......@@ -112,7 +115,7 @@ class ContentSettingBubbleModel : public content::NotificationObserver {
const content::NotificationDetails& details) override;
virtual void OnRadioClicked(int radio_index) {}
virtual void OnPopupClicked(int index) {}
virtual void OnListItemClicked(int index) {}
virtual void OnCustomLinkClicked() {}
virtual void OnManageLinkClicked() {}
virtual void OnLearnMoreLinkClicked() {}
......@@ -133,11 +136,8 @@ class ContentSettingBubbleModel : public content::NotificationObserver {
Profile* profile() const { return profile_; }
void set_title(const std::string& title) { bubble_content_.title = title; }
void set_plugin_names(const base::string16& plugin_names) {
bubble_content_.plugin_names = plugin_names;
}
void add_popup(const PopupItem& popup) {
bubble_content_.popup_items.push_back(popup);
void add_list_item(const ListItem& item) {
bubble_content_.list_items.push_back(item);
}
void set_radio_group(const RadioGroup& radio_group) {
bubble_content_.radio_group = radio_group;
......@@ -213,8 +213,7 @@ class ContentSettingRPHBubbleModel : public ContentSettingTitleAndLinkModel {
ContentSettingRPHBubbleModel(Delegate* delegate,
content::WebContents* web_contents,
Profile* profile,
ProtocolHandlerRegistry* registry,
ContentSettingsType content_type);
ProtocolHandlerRegistry* registry);
void OnRadioClicked(int radio_index) override;
void OnDoneClicked() override;
......
......@@ -47,7 +47,7 @@ class ContentSettingBubbleModelTest : public ChromeRenderViewHostTestHarness {
content_setting_bubble_model->bubble_content();
EXPECT_TRUE(bubble_content.title.empty());
EXPECT_TRUE(bubble_content.radio_group.radio_items.empty());
EXPECT_TRUE(bubble_content.popup_items.empty());
EXPECT_TRUE(bubble_content.list_items.empty());
EXPECT_EQ(expected_domains, bubble_content.domain_lists.size());
EXPECT_NE(expect_clear_link || expect_reload_hint,
bubble_content.custom_link.empty());
......@@ -96,7 +96,6 @@ TEST_F(ContentSettingBubbleModelTest, Cookies) {
content_setting_bubble_model->bubble_content();
std::string title = bubble_content.title;
EXPECT_FALSE(title.empty());
EXPECT_TRUE(bubble_content.plugin_names.empty());
ASSERT_EQ(2U, bubble_content.radio_group.radio_items.size());
std::string radio1 = bubble_content.radio_group.radio_items[0];
std::string radio2 = bubble_content.radio_group.radio_items[1];
......@@ -742,9 +741,9 @@ TEST_F(ContentSettingBubbleModelTest, Plugins) {
const ContentSettingBubbleModel::BubbleContent& bubble_content =
content_setting_bubble_model->bubble_content();
EXPECT_FALSE(bubble_content.title.empty());
EXPECT_FALSE(bubble_content.plugin_names.empty());
EXPECT_NE(base::string16::npos,
bubble_content.plugin_names.find(plugin_name));
ASSERT_EQ(1U, bubble_content.list_items.size());
EXPECT_EQ(plugin_name,
base::ASCIIToUTF16(bubble_content.list_items[0].title));
EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size());
EXPECT_FALSE(bubble_content.custom_link.empty());
EXPECT_TRUE(bubble_content.custom_link_enabled);
......@@ -853,14 +852,13 @@ TEST_F(ContentSettingBubbleModelTest, RegisterProtocolHandler) {
"mailto", GURL("http://www.toplevel.example/")));
ContentSettingRPHBubbleModel content_setting_bubble_model(
NULL, web_contents(), profile(), NULL,
CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS);
NULL, web_contents(), profile(), NULL);
const ContentSettingBubbleModel::BubbleContent& bubble_content =
content_setting_bubble_model.bubble_content();
EXPECT_FALSE(bubble_content.title.empty());
EXPECT_FALSE(bubble_content.radio_group.radio_items.empty());
EXPECT_TRUE(bubble_content.popup_items.empty());
EXPECT_TRUE(bubble_content.list_items.empty());
EXPECT_TRUE(bubble_content.domain_lists.empty());
EXPECT_TRUE(bubble_content.custom_link.empty());
EXPECT_FALSE(bubble_content.custom_link_enabled);
......@@ -907,8 +905,7 @@ TEST_F(ContentSettingBubbleModelTest, RPHAllow) {
content_settings->set_pending_protocol_handler(test_handler);
ContentSettingRPHBubbleModel content_setting_bubble_model(
NULL, web_contents(), profile(), &registry,
CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS);
NULL, web_contents(), profile(), &registry);
{
ProtocolHandler handler = registry.GetHandlerFor("mailto");
......
......@@ -211,52 +211,38 @@ void ContentSettingBubbleContents::Init() {
bubble_content_empty = false;
}
if (!bubble_content.plugin_names.empty()) {
const int kPluginsColumnSetId = 4;
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
views::ColumnSet* plugins_column_set =
layout->AddColumnSet(kPluginsColumnSetId);
plugins_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
// Layout for the item list (blocked plugins and popups).
if (!bubble_content.list_items.empty()) {
const int kItemListColumnSetId = 2;
views::ColumnSet* item_list_column_set =
layout->AddColumnSet(kItemListColumnSetId);
item_list_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0,
GridLayout::USE_PREF, 0, 0);
plugins_column_set->AddPaddingColumn(
item_list_column_set->AddPaddingColumn(
0, views::kRelatedControlHorizontalSpacing);
plugins_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
item_list_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
GridLayout::USE_PREF, 0, 0);
views::Label* plugin_names_label =
new views::Label(bubble_content.plugin_names);
plugin_names_label->SetMultiLine(true);
plugin_names_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
layout->StartRow(0, kPluginsColumnSetId);
layout->AddView(plugin_names_label);
bubble_content_empty = false;
}
if (content_setting_bubble_model_->content_type() ==
CONTENT_SETTINGS_TYPE_POPUPS) {
const int kPopupColumnSetId = 2;
views::ColumnSet* popup_column_set =
layout->AddColumnSet(kPopupColumnSetId);
popup_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0,
GridLayout::USE_PREF, 0, 0);
popup_column_set->AddPaddingColumn(
0, views::kRelatedControlHorizontalSpacing);
popup_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
GridLayout::USE_PREF, 0, 0);
for (std::vector<ContentSettingBubbleModel::PopupItem>::const_iterator
i(bubble_content.popup_items.begin());
i != bubble_content.popup_items.end(); ++i) {
int row = 0;
for (const ContentSettingBubbleModel::ListItem& list_item :
bubble_content.list_items) {
if (!bubble_content_empty)
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
layout->StartRow(0, kPopupColumnSetId);
views::Link* link = new views::Link(base::UTF8ToUTF16(i->title));
layout->StartRow(0, kItemListColumnSetId);
if (list_item.has_link) {
views::Link* link = new views::Link(base::UTF8ToUTF16(list_item.title));
link->set_listener(this);
link->SetElideBehavior(gfx::ELIDE_MIDDLE);
popup_links_[link] = i - bubble_content.popup_items.begin();
layout->AddView(new Favicon(i->image, this, link));
list_item_links_[link] = row;
layout->AddView(new Favicon(list_item.image, this, link));
layout->AddView(link);
} else {
views::Label* label =
new views::Label(base::UTF8ToUTF16(list_item.title));
layout->AddView(new Favicon(list_item.image, this, NULL));
layout->AddView(label);
}
row++;
bubble_content_empty = false;
}
}
......@@ -295,7 +281,7 @@ void ContentSettingBubbleContents::Init() {
// Layout code for the media device menus.
if (content_setting_bubble_model_->content_type() ==
CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
const int kMediaMenuColumnSetId = 2;
const int kMediaMenuColumnSetId = 4;
views::ColumnSet* menu_column_set =
layout->AddColumnSet(kMediaMenuColumnSetId);
menu_column_set->AddPaddingColumn(0, views::kCheckboxIndent);
......@@ -463,9 +449,9 @@ void ContentSettingBubbleContents::LinkClicked(views::Link* source,
return;
}
PopupLinks::const_iterator i(popup_links_.find(source));
DCHECK(i != popup_links_.end());
content_setting_bubble_model_->OnPopupClicked(i->second);
ListItemLinks::const_iterator i(list_item_links_.find(source));
DCHECK(i != list_item_links_.end());
content_setting_bubble_model_->OnListItemClicked(i->second);
}
void ContentSettingBubbleContents::OnMenuButtonClicked(
......
......@@ -68,7 +68,7 @@ class ContentSettingBubbleContents : public content::WebContentsObserver,
class Favicon;
struct MediaMenuParts;
typedef std::map<views::Link*, int> PopupLinks;
typedef std::map<views::Link*, int> ListItemLinks;
typedef std::map<views::MenuButton*, MediaMenuParts*> MediaMenuPartsMap;
// content::WebContentsObserver:
......@@ -97,7 +97,7 @@ class ContentSettingBubbleContents : public content::WebContentsObserver,
// Some of our controls, so we can tell what's been clicked when we get a
// message.
PopupLinks popup_links_;
ListItemLinks list_item_links_;
typedef std::vector<views::RadioButton*> RadioGroup;
RadioGroup radio_group_;
views::Link* custom_link_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment