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 {
......
......@@ -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