Skip to content

Commit

Permalink
Reland 55888: Allow per-plugin content settings.
Browse files Browse the repository at this point in the history
Now with Fixed Unit Tests!

Run with --enable-resource-content-settings and --enable-click-to-play to enable.

TabSpecificContentSettings now keeps track of which resources were blocked. The content setting bubble displays those resource, and selecting the "allow radio buttons adds exceptions for these resources.

The infobar for non-sandboxed plug-ins now also shows a button to always allow the blocked plug-in on that site.

Screenshot of the plugin bubble: http://imgur.com/6npqv.png

Because we need to change the title and radio button labels depending on whether we track specific plug-ins, we copy them from the ContentSettingBubbleModel.

XIB changes: Add a text field for the blocked plug-ins to ContentBlockedPlugins.xib, hooked up to the |blockedResourcesField_| outlet.

BUG=39252,38432
TEST=HostContentSettingsMapTest.*,manual

Review URL: http://codereview.chromium.org/2873104

Review URL: http://codereview.chromium.org/3124018

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56687 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
bauerb@chromium.org committed Aug 19, 2010
1 parent 904f191 commit 5512613
Show file tree
Hide file tree
Showing 35 changed files with 1,273 additions and 160 deletions.
13 changes: 11 additions & 2 deletions chrome/app/generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -2376,12 +2376,18 @@ each locale. -->
<message name="IDS_BLOCKED_JAVASCRIPT_LINK" desc="Link to JavaScript section of content blocking management dialog, displayed in bubble when a page tries to run JavaScript.">
Manage JavaScript blocking...
</message>
<message name="IDS_BLOCKED_PLUGINS_TITLE" desc="Tooltip and bubble info header text when a page is not allowed to display plug-ins.">
<message name="IDS_BLOCKED_PLUGINS_TITLE" desc="Bubble info header text when a page is not allowed to display plug-ins.">
The following plug-ins were blocked on this page:
</message>
<message name="IDS_BLOCKED_PLUGINS_MESSAGE" desc="Tooltip and message when a page is not allowed to display plug-ins.">
Plug-ins were blocked on this page.
</message>
<message name="IDS_BLOCKED_PLUGINS_UNBLOCK" desc="Radio button choice to unblock a site from using plug-ins, displayed in bubble when a page tries to use plug-ins.">
<message name="IDS_BLOCKED_PLUGINS_UNBLOCK_ALL" desc="Radio button choice to unblock a site from using plug-ins, displayed in bubble when a page tries to use plug-ins.">
Always allow plug-ins on <ph name="HOST">$1<ex>mail.google.com</ex></ph>
</message>
<message name="IDS_BLOCKED_PLUGINS_UNBLOCK" desc="Radio button choice to unblock a site from using *a specific set* of plug-ins, displayed in bubble when a page tries to use plug-ins.">
Always allow these plug-ins on <ph name="HOST">$1<ex>mail.google.com</ex></ph>
</message>
<message name="IDS_BLOCKED_PLUGINS_NO_ACTION" desc="Radio button choice to continue blocking a site from using plug-ins, displayed in bubble when a page tries to use plug-ins.">
Continue blocking plug-ins
</message>
Expand All @@ -2391,6 +2397,9 @@ each locale. -->
<message name="IDS_BLOCKED_PLUGINS_LOAD_ALL" desc="Button to load all blocked plugins on a page, displayed in bubble when a page tries to display plug-ins.">
Run all plug-ins this time
</message>
<message name="IDS_BLOCKED_PLUGINS_UNBLOCK_SHORT" desc="Button to unblock nonsandboxed plug-ins on a site">
Always allow
</message>

<!-- SSL error strings -->
<message name="IDS_SEVERAL_SSL_ERRORS" desc="Bubble info header text when there is more than 1 error">
Expand Down
891 changes: 821 additions & 70 deletions chrome/app/nibs/ContentBlockedPlugins.xib

Large diffs are not rendered by default.

27 changes: 25 additions & 2 deletions chrome/browser/blocked_plugin_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@

#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "base/command_line.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/host_content_settings_map.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/chrome_switches.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"

BlockedPluginManager::BlockedPluginManager(TabContents* tab_contents)
: ConfirmInfoBarDelegate(tab_contents),
tab_contents_(tab_contents) { }

void BlockedPluginManager::OnNonSandboxedPluginBlocked(const string16& name) {
void BlockedPluginManager::OnNonSandboxedPluginBlocked(
const std::string& plugin,
const string16& name) {
plugin_ = plugin;
name_ = name;
tab_contents_->AddInfoBar(this);
}
Expand All @@ -26,12 +33,18 @@ void BlockedPluginManager::OnBlockedPluginLoaded() {
}

int BlockedPluginManager::GetButtons() const {
return BUTTON_OK;
int buttons = BUTTON_OK;
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableResourceContentSettings))
buttons |= BUTTON_CANCEL;
return buttons;
}

string16 BlockedPluginManager::GetButtonLabel(InfoBarButton button) const {
if (button == BUTTON_OK)
return l10n_util::GetStringUTF16(IDS_PLUGIN_LOAD_SHORT);
if (button == BUTTON_CANCEL)
return l10n_util::GetStringUTF16(IDS_BLOCKED_PLUGINS_UNBLOCK_SHORT);
return ConfirmInfoBarDelegate::GetButtonLabel(button);
}

Expand All @@ -53,6 +66,16 @@ bool BlockedPluginManager::Accept() {
return true;
}

bool BlockedPluginManager::Cancel() {
DCHECK(CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableResourceContentSettings));
tab_contents_->profile()->GetHostContentSettingsMap()->AddExceptionForURL(
tab_contents_->GetURL(), CONTENT_SETTINGS_TYPE_PLUGINS, plugin_,
CONTENT_SETTING_ALLOW);
tab_contents_->render_view_host()->LoadBlockedPlugins();
return true;
}

bool BlockedPluginManager::LinkClicked(WindowOpenDisposition disposition) {
// TODO(bauerb): Navigate to a help page explaining why we blocked the plugin,
// once we have one.
Expand Down
5 changes: 4 additions & 1 deletion chrome/browser/blocked_plugin_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class BlockedPluginManager : public RenderViewHostDelegate::BlockedPlugin,
public:
explicit BlockedPluginManager(TabContents* tab_contents);

virtual void OnNonSandboxedPluginBlocked(const string16& name);
virtual void OnNonSandboxedPluginBlocked(const std::string& plugin,
const string16& name);
virtual void OnBlockedPluginLoaded();

// ConfirmInfoBarDelegate methods
Expand All @@ -25,12 +26,14 @@ class BlockedPluginManager : public RenderViewHostDelegate::BlockedPlugin,
virtual string16 GetLinkText();
virtual SkBitmap* GetIcon() const;
virtual bool Accept();
virtual bool Cancel();
virtual bool LinkClicked(WindowOpenDisposition disposition);

private:
// Owns us.
TabContents* tab_contents_;
string16 name_;
std::string plugin_;
};

#endif // CHROME_BROWSER_BLOCKED_PLUGIN_MANAGER_H_
2 changes: 2 additions & 0 deletions chrome/browser/cocoa/content_setting_bubble_cocoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ typedef std::map<NSButton*, int> PopupLinks;
// The info button of the cookies bubble.
IBOutlet NSButton* infoButton_;

IBOutlet NSTextField* blockedResourcesField_;

scoped_ptr<ContentSettingBubbleModel> contentSettingBubbleModel_;
content_setting_bubble::PopupLinks popupLinks_;
}
Expand Down
59 changes: 50 additions & 9 deletions chrome/browser/cocoa/content_setting_bubble_cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "grit/generated_resources.h"
#include "skia/ext/skia_utils_mac.h"
#import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
#include "webkit/glue/plugins/plugin_list.h"

namespace {

Expand Down Expand Up @@ -88,6 +89,7 @@ - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame
title:(NSString*)title
icon:(NSImage*)icon
referenceFrame:(NSRect)referenceFrame;
- (void)initializeBlockedPluginsList;
- (void)initializeTitle;
- (void)initializeRadioGroup;
- (void)initializePopupList;
Expand Down Expand Up @@ -147,6 +149,10 @@ - (void)initializeTitle {
if (!titleLabel_)
return;

NSString* label = base::SysUTF8ToNSString(
contentSettingBubbleModel_->bubble_content().title);
[titleLabel_ setStringValue:label];

// Layout title post-localization.
CGFloat deltaY = [GTMUILocalizerAndLayoutTweaker
sizeToFitFixedWidthTextField:titleLabel_];
Expand All @@ -161,20 +167,22 @@ - (void)initializeTitle {
- (void)initializeRadioGroup {
// Configure the radio group. For now, only deal with the
// strictly needed case of group containing 2 radio buttons.
// TODO(joth): Implement the generic case, getting localized strings from the
// bubble model instead of the xib, or remove it if it's never needed.
// http://crbug.com/38432
const ContentSettingBubbleModel::RadioGroup& radioGroup =
const ContentSettingBubbleModel::RadioGroup& radio_group =
contentSettingBubbleModel_->bubble_content().radio_group;

// Select appropriate radio button.
[allowBlockRadioGroup_ selectCellWithTag:
radioGroup.default_item == 0 ? kAllowTag : kBlockTag];
radio_group.default_item == 0 ? kAllowTag : kBlockTag];

// Copy |host_| into radio group label.
const ContentSettingBubbleModel::RadioItems& radio_items =
radio_group.radio_items;
DCHECK_EQ(2u, radio_items.size()) << "Only 2 radio items per group supported";
// Set radio group labels from model.
NSCell* radioCell = [allowBlockRadioGroup_ cellWithTag:kAllowTag];
[radioCell setTitle:cocoa_l10n_util::ReplaceNSStringPlaceholders(
[radioCell title], UTF8ToUTF16(radioGroup.url.host()), NULL)];
[radioCell setTitle:base::SysUTF8ToNSString(radio_items[0])];

radioCell = [allowBlockRadioGroup_ cellWithTag:kBlockTag];
[radioCell setTitle:base::SysUTF8ToNSString(radio_items[1])];

// Layout radio group labels post-localization.
[GTMUILocalizerAndLayoutTweaker
Expand Down Expand Up @@ -219,6 +227,37 @@ - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame
return button;
}

- (void)initializeBlockedPluginsList {
NSMutableArray* pluginArray = [NSMutableArray array];
const std::set<std::string>& plugins =
contentSettingBubbleModel_->bubble_content().resource_identifiers;
if (plugins.empty()) {
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];
} else {
for (std::set<std::string>::iterator it = plugins.begin();
it != plugins.end(); ++it) {
WebPluginInfo plugin;
NSString* name;
if (NPAPI::PluginList::Singleton()->
GetPluginInfoByPath(FilePath(*it), &plugin)) {
name = base::SysUTF16ToNSString(plugin.name);
} else {
name = base::SysUTF8ToNSString(*it);
}
[pluginArray addObject:name];
}
[blockedResourcesField_
setStringValue:[pluginArray componentsJoinedByString:@"\n"]];
[GTMUILocalizerAndLayoutTweaker
sizeToFitFixedWidthTextField:blockedResourcesField_];
}
}

- (void)initializePopupList {
// 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.
Expand Down Expand Up @@ -419,8 +458,10 @@ - (void)awakeFromNib {
[self initializeTitle];

ContentSettingsType type = contentSettingBubbleModel_->content_type();
if (type == CONTENT_SETTINGS_TYPE_PLUGINS)
if (type == CONTENT_SETTINGS_TYPE_PLUGINS) {
[self sizeToFitLoadPluginsButton];
[self initializeBlockedPluginsList];
}
if (type == CONTENT_SETTINGS_TYPE_COOKIES)
[self removeInfoButton];
if (allowBlockRadioGroup_) // not bound in cookie bubble xib
Expand Down
Loading

0 comments on commit 5512613

Please sign in to comment.