diff options
-rw-r--r-- | chrome/app/theme/theme_resources.grd | 5 | ||||
-rw-r--r-- | chrome/browser/cocoa/location_bar_view_mac.h | 3 | ||||
-rw-r--r-- | chrome/browser/cocoa/location_bar_view_mac.mm | 6 | ||||
-rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.cc | 6 | ||||
-rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.h | 3 | ||||
-rw-r--r-- | chrome/browser/location_bar.h | 5 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 5 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.h | 5 | ||||
-rw-r--r-- | chrome/browser/views/content_blocked_bubble_contents.cc | 176 | ||||
-rw-r--r-- | chrome/browser/views/content_blocked_bubble_contents.h | 80 | ||||
-rw-r--r-- | chrome/browser/views/info_bubble.cc | 8 | ||||
-rw-r--r-- | chrome/browser/views/location_bar_view.cc | 143 | ||||
-rw-r--r-- | chrome/browser/views/location_bar_view.h | 57 | ||||
-rwxr-xr-x | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/test/test_location_bar.h | 3 |
15 files changed, 499 insertions, 8 deletions
diff --git a/chrome/app/theme/theme_resources.grd b/chrome/app/theme/theme_resources.grd index 9f02719..14652a7 100644 --- a/chrome/app/theme/theme_resources.grd +++ b/chrome/app/theme/theme_resources.grd @@ -118,6 +118,11 @@ <include name="IDR_FIND_BOX_BACKGROUND_LEFT" file="find_box_bg_left.png" type="BINDATA" /> <include name="IDR_FIND_BOX_BACKGROUND_LEFT_RTL" file="find_box_bg_left_rtl.png" type="BINDATA" /> <include name="IDR_APP_DROPARROW" file="app_droparrow.png" type="BINDATA" /> + <include name="IDR_BLOCKED_COOKIES" file="blocked_cookies.png" type="BINDATA" /> + <include name="IDR_BLOCKED_IMAGES" file="blocked_images.png" type="BINDATA" /> + <include name="IDR_BLOCKED_JAVASCRIPT" file="blocked_javascript.png" type="BINDATA" /> + <include name="IDR_BLOCKED_PLUGINS" file="blocked_plugins.png" type="BINDATA" /> + <include name="IDR_BLOCKED_POPUPS" file="blocked_popups.png" type="BINDATA" /> <include name="IDR_LOCK" file="lock_small.png" type="BINDATA" /> <include name="IDR_WARNING" file="alert_small.png" type="BINDATA" /> <include name="IDR_STOP" file="stop.png" type="BINDATA" /> diff --git a/chrome/browser/cocoa/location_bar_view_mac.h b/chrome/browser/cocoa/location_bar_view_mac.h index 837dc4a..2d82997 100644 --- a/chrome/browser/cocoa/location_bar_view_mac.h +++ b/chrome/browser/cocoa/location_bar_view_mac.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -52,6 +52,7 @@ class LocationBarViewMac : public AutocompleteEditController, virtual void AcceptInputWithDisposition(WindowOpenDisposition disposition); virtual void FocusLocation(); virtual void FocusSearch(); + virtual void UpdateContentBlockedIcons(); virtual void UpdatePageActions(); virtual void InvalidatePageActions(); virtual void SaveStateToContents(TabContents* contents); diff --git a/chrome/browser/cocoa/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar_view_mac.mm index f206bda..52a28b2 100644 --- a/chrome/browser/cocoa/location_bar_view_mac.mm +++ b/chrome/browser/cocoa/location_bar_view_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -147,6 +147,10 @@ void LocationBarViewMac::FocusSearch() { // TODO(pkasting): Focus the edit a la Linux/Win } +void LocationBarViewMac::UpdateContentBlockedIcons() { + // TODO(pkasting): Implement. +} + void LocationBarViewMac::UpdatePageActions() { page_action_views_->RefreshViews(); [field_ resetFieldEditorFrameIfNeeded]; diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc index a52105d..3a9462ca 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/gtk/location_bar_view_gtk.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -510,6 +510,10 @@ void LocationBarViewGtk::FocusSearch() { location_entry_->SetForcedQuery(); } +void LocationBarViewGtk::UpdateContentBlockedIcons() { + // TODO(pkasting): Implement. +} + void LocationBarViewGtk::UpdatePageActions() { std::vector<ExtensionAction*> page_actions; ExtensionsService* service = profile_->GetExtensionsService(); diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h index 5f861b7..112aeba 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.h +++ b/chrome/browser/gtk/location_bar_view_gtk.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -93,6 +93,7 @@ class LocationBarViewGtk : public AutocompleteEditController, virtual void AcceptInputWithDisposition(WindowOpenDisposition); virtual void FocusLocation(); virtual void FocusSearch(); + virtual void UpdateContentBlockedIcons(); virtual void UpdatePageActions(); virtual void InvalidatePageActions(); virtual void SaveStateToContents(TabContents* contents); diff --git a/chrome/browser/location_bar.h b/chrome/browser/location_bar.h index d3f4019..9d0a49c 100644 --- a/chrome/browser/location_bar.h +++ b/chrome/browser/location_bar.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -50,6 +50,9 @@ class LocationBar { // focus to it. virtual void FocusSearch() = 0; + // Updates the state of the images showing what content was blocked. + virtual void UpdateContentBlockedIcons() = 0; + // Updates the state of the page actions. virtual void UpdatePageActions() = 0; diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 310f2e9..a575ae5 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -560,6 +560,11 @@ bool TabContents::ShouldDisplayFavIcon() { return true; } +bool TabContents::IsContentBlocked(ContentSettingsType content_type) const { + // TODO(pkasting): Return meaningful values here. + return false; +} + std::wstring TabContents::GetStatusText() const { if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE) return std::wstring(); diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index d78f150..9586f88 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -33,6 +33,7 @@ #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/page_navigator.h" #include "chrome/browser/tab_contents/render_view_host_manager.h" +#include "chrome/common/content_settings_types.h" #include "chrome/common/extensions/url_pattern.h" #include "chrome/common/navigation_types.h" #include "chrome/common/notification_registrar.h" @@ -230,6 +231,10 @@ class TabContents : public PageNavigator, // space is provided for the favicon, and the favicon is never displayed. virtual bool ShouldDisplayFavIcon(); + // Returns whether a particular kind of content has been blocked for this + // page. + bool IsContentBlocked(ContentSettingsType content_type) const; + // Returns a human-readable description the tab's loading state. virtual std::wstring GetStatusText() const; diff --git a/chrome/browser/views/content_blocked_bubble_contents.cc b/chrome/browser/views/content_blocked_bubble_contents.cc new file mode 100644 index 0000000..8e37497 --- /dev/null +++ b/chrome/browser/views/content_blocked_bubble_contents.cc @@ -0,0 +1,176 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/views/content_blocked_bubble_contents.h" + +#include "app/l10n_util.h" +#include "chrome/browser/views/info_bubble.h" +#include "chrome/browser/views/options/content_settings_window_view.h" +#include "grit/generated_resources.h" +#include "views/controls/button/native_button.h" +#include "views/controls/button/radio_button.h" +#include "views/controls/label.h" +#include "views/controls/separator.h" +#include "views/grid_layout.h" +#include "views/standard_layout.h" + +ContentBlockedBubbleContents::ContentBlockedBubbleContents( + ContentSettingsType content_type, + const std::wstring& host, + Profile* profile) + : content_type_(content_type), + host_(host), + profile_(profile), + info_bubble_(NULL), + allow_radio_(NULL), + block_radio_(NULL), + close_button_(NULL), + manage_link_(NULL) { +} + +ContentBlockedBubbleContents::~ContentBlockedBubbleContents() { +} + +void ContentBlockedBubbleContents::ViewHierarchyChanged(bool is_add, + View* parent, + View* child) { + if (is_add && (child == this)) + InitControlLayout(); +} + +void ContentBlockedBubbleContents::ButtonPressed(views::Button* sender, + const views::Event& event) { + if (sender == close_button_) { + info_bubble_->Close(); // CAREFUL: This deletes us. + return; + } + + // TODO(pkasting): Set block state for this host and content type. +} + +void ContentBlockedBubbleContents::LinkActivated(views::Link* source, + int event_flags) { + if (source == manage_link_) { + ContentSettingsWindowView::Show(content_type_, profile_); + // CAREFUL: Showing the settings window activates it, which deactivates the + // info bubble, which causes it to close, which deletes us. + return; + } + + // TODO(pkasting): A popup link was clicked, show the corresponding popup. +} + +void ContentBlockedBubbleContents::InitControlLayout() { + using views::GridLayout; + + GridLayout* layout = new views::GridLayout(this); + SetLayoutManager(layout); + + const int single_column_set_id = 0; + views::ColumnSet* column_set = layout->AddColumnSet(single_column_set_id); + column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, + GridLayout::USE_PREF, 0, 0); + + static const int kTitleIDs[] = { + IDS_BLOCKED_COOKIES_TITLE, + IDS_BLOCKED_IMAGES_TITLE, + IDS_BLOCKED_JAVASCRIPT_TITLE, + IDS_BLOCKED_PLUGINS_TITLE, + IDS_BLOCKED_POPUPS_TITLE, + }; + DCHECK_EQ(arraysize(kTitleIDs), CONTENT_SETTINGS_NUM_TYPES); + views::Label* title_label = + new views::Label(l10n_util::GetString(kTitleIDs[content_type_])); + + layout->StartRow(0, single_column_set_id); + layout->AddView(title_label); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + + if (content_type_ == CONTENT_SETTINGS_TYPE_POPUPS) { + /* TODO(pkasting): Show list of blocked popups as clickable links. + for (size_t i = 0; i < num_popups; ++i) { + if (i != 0) + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + layout->StartRow(0, single_column_set_id); + layout->AddView(popup_link); + } + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + */ + + views::Separator* separator = new views::Separator; + layout->StartRow(0, single_column_set_id); + layout->AddView(separator); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + } + + if (content_type_ != CONTENT_SETTINGS_TYPE_COOKIES) { + static const int kAllowIDs[] = { + 0, // Not displayed for cookies + IDS_BLOCKED_IMAGES_UNBLOCK, + IDS_BLOCKED_JAVASCRIPT_UNBLOCK, + IDS_BLOCKED_PLUGINS_UNBLOCK, + IDS_BLOCKED_POPUPS_UNBLOCK, + }; + DCHECK_EQ(arraysize(kAllowIDs), CONTENT_SETTINGS_NUM_TYPES); + const int radio_button_group = 0; + allow_radio_ = new views::RadioButton( + l10n_util::GetStringF(kAllowIDs[content_type_], host_), + radio_button_group); + allow_radio_->set_listener(this); + + static const int kBlockIDs[] = { + 0, // Not displayed for cookies + IDS_BLOCKED_IMAGES_NO_ACTION, + IDS_BLOCKED_JAVASCRIPT_NO_ACTION, + IDS_BLOCKED_PLUGINS_NO_ACTION, + IDS_BLOCKED_POPUPS_NO_ACTION, + }; + DCHECK_EQ(arraysize(kAllowIDs), CONTENT_SETTINGS_NUM_TYPES); + block_radio_ = new views::RadioButton( + l10n_util::GetString(kBlockIDs[content_type_]), radio_button_group); + block_radio_->set_listener(this); + + layout->StartRow(0, single_column_set_id); + layout->AddView(allow_radio_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + layout->StartRow(0, single_column_set_id); + layout->AddView(block_radio_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + + // Now that this has been added to the view hierarchy, it's safe to call + // SetChecked() on it. + block_radio_->SetChecked(true); + + views::Separator* separator = new views::Separator; + layout->StartRow(0, single_column_set_id); + layout->AddView(separator, 1, 1, GridLayout::FILL, GridLayout::FILL); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + } + + const int double_column_set_id = 1; + views::ColumnSet* double_column_set = + layout->AddColumnSet(double_column_set_id); + double_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, + GridLayout::USE_PREF, 0, 0); + double_column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, + GridLayout::USE_PREF, 0, 0); + + static const int kLinkIDs[] = { + IDS_BLOCKED_COOKIES_LINK, + IDS_BLOCKED_IMAGES_LINK, + IDS_BLOCKED_JAVASCRIPT_LINK, + IDS_BLOCKED_PLUGINS_LINK, + IDS_BLOCKED_POPUPS_LINK, + }; + DCHECK_EQ(arraysize(kLinkIDs), CONTENT_SETTINGS_NUM_TYPES); + manage_link_ = new views::Link(l10n_util::GetString(kLinkIDs[content_type_])); + manage_link_->SetController(this); + + layout->StartRow(0, double_column_set_id); + layout->AddView(manage_link_); + + close_button_ = + new views::NativeButton(this, l10n_util::GetString(IDS_CLOSE)); + layout->AddView(close_button_); +} diff --git a/chrome/browser/views/content_blocked_bubble_contents.h b/chrome/browser/views/content_blocked_bubble_contents.h new file mode 100644 index 0000000..8d03196 --- /dev/null +++ b/chrome/browser/views/content_blocked_bubble_contents.h @@ -0,0 +1,80 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_VIEWS_CONTENT_BLOCKED_BUBBLE_CONTENTS_H_ +#define CHROME_BROWSER_VIEWS_CONTENT_BLOCKED_BUBBLE_CONTENTS_H_ + +#include <string> + +#include "chrome/common/content_settings_types.h" +#include "views/controls/button/button.h" +#include "views/controls/link.h" + +// ContentBlockedBubbleContents is used when the user turns on different kinds +// of content blocking (e.g. "block images"). When viewing a page with blocked +// content, icons appear in the omnibox corresponding to the content types that +// were blocked, and the user can click one to get a bubble hosting a few +// controls. This class provides the content of that bubble. In general, +// these bubbles typically have a title, a pair of radio buttons for toggling +// the blocking settings for the current site, a close button, and a link to +// get to a more comprehensive settings management dialog. A few types have +// more or fewer controls than this. + +class InfoBubble; +class Profile; + +namespace views { +class NativeButton; +class RadioButton; +} + +class ContentBlockedBubbleContents : public views::View, + public views::ButtonListener, + public views::LinkController { + public: + ContentBlockedBubbleContents(ContentSettingsType content_type, + const std::wstring& host, + Profile* profile); + virtual ~ContentBlockedBubbleContents(); + + // Overridden from views::View: + virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); + + // views::ButtonListener: + virtual void ButtonPressed(views::Button* sender, const views::Event& event); + + // views::LinkController: + virtual void LinkActivated(views::Link* source, int event_flags); + + // Sets |info_bubble_|, so we can close the bubble if needed. The caller owns + // the bubble and must keep it alive. + void set_info_bubble(InfoBubble* info_bubble) { info_bubble_ = info_bubble; } + + private: + // Creates the child views. + void InitControlLayout(); + + // The type of content handled by this view. + ContentSettingsType content_type_; + + // The hostname affected. + std::wstring host_; + + // The active profile. + Profile* profile_; + + // The InfoBubble holding us. + InfoBubble* info_bubble_; + + // Some of our controls, so we can tell what's been clicked when we get a + // message. + views::RadioButton* allow_radio_; + views::RadioButton* block_radio_; + views::NativeButton* close_button_; + views::Link* manage_link_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(ContentBlockedBubbleContents); +}; + +#endif // CHROME_BROWSER_VIEWS_CONTENT_BLOCKED_BUBBLE_CONTENTS_H_ diff --git a/chrome/browser/views/info_bubble.cc b/chrome/browser/views/info_bubble.cc index edbc3b1..9f88fc8 100644 --- a/chrome/browser/views/info_bubble.cc +++ b/chrome/browser/views/info_bubble.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -248,11 +248,15 @@ void InfoBubble::Init(views::Window* parent, // Create a View to hold the contents of the main window. views::View* contents_view = new views::View; + // We add |contents_view| to ourselves before the AddChildView() call below so + // that when |contents| gets added, it will already have a widget, and thus + // any NativeButtons it creates in ViewHierarchyChanged() will be functional + // (e.g. calling SetChecked() on checkboxes is safe). + SetContentsView(contents_view); // Adding |contents| as a child has to be done before we call // contents->GetPreferredSize() below, since some supplied views don't // actually initialize themselves until they're added to a hierarchy. contents_view->AddChildView(contents); - SetContentsView(contents_view); // Calculate and set the bounds for all windows and views. gfx::Rect window_bounds; diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc index 450b8d6..446574c 100644 --- a/chrome/browser/views/location_bar_view.cc +++ b/chrome/browser/views/location_bar_view.cc @@ -26,8 +26,11 @@ #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/view_ids.h" #include "chrome/browser/views/extensions/extension_popup.h" +#include "chrome/browser/views/content_blocked_bubble_contents.h" +#include "chrome/common/pref_names.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" +#include "net/base/net_util.h" #if defined(OS_WIN) #include "chrome/browser/views/first_run_bubble.h" @@ -218,6 +221,16 @@ void LocationBarView::Init() { security_image_view_.SetVisible(false); security_image_view_.set_parent_owned(false); + for (int i = CONTENT_SETTINGS_FIRST_TYPE; i < CONTENT_SETTINGS_NUM_TYPES; + ++i) { + ContentBlockedImageView* content_blocked_view = + new ContentBlockedImageView(static_cast<ContentSettingsType>(i), this, + profile_, bubble_positioner_); + content_blocked_views_.push_back(content_blocked_view); + AddChildView(content_blocked_view); + content_blocked_view->SetVisible(false); + } + AddChildView(&info_label_); info_label_.SetVisible(false); info_label_.set_parent_owned(false); @@ -286,6 +299,7 @@ SkColor LocationBarView::GetColor(bool is_secure, ColorKind kind) { void LocationBarView::Update(const TabContents* tab_for_state_restoring) { SetSecurityIcon(model_->GetIcon()); + RefreshContentBlockedViews(); RefreshPageActionViews(); std::wstring info_text, info_tooltip; ToolbarModel::InfoTextType info_text_type = @@ -296,6 +310,13 @@ void LocationBarView::Update(const TabContents* tab_for_state_restoring) { SchedulePaint(); } +void LocationBarView::UpdateContentBlockedIcons() { + RefreshContentBlockedViews(); + + Layout(); + SchedulePaint(); +} + void LocationBarView::UpdatePageActions() { RefreshPageActionViews(); @@ -319,10 +340,25 @@ void LocationBarView::SetProfile(Profile* profile) { location_entry_->model()->SetProfile(profile); selected_keyword_view_.set_profile(profile); keyword_hint_view_.set_profile(profile); + for (ContentBlockedViews::const_iterator i(content_blocked_views_.begin()); + i != content_blocked_views_.end(); ++i) + (*i)->set_profile(profile); security_image_view_.set_profile(profile); } } +std::wstring LocationBarView::GetHost() const { + const TabContents* tab_contents = delegate_->GetTabContents(); + if (!tab_contents) + return std::wstring(); + + std::wstring host; + net::AppendFormattedHost(tab_contents->GetURL(), + profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), &host, NULL, + NULL); + return host; +} + void LocationBarView::SetPreviewEnabledPageAction(ExtensionAction *page_action, bool preview_enabled) { DCHECK(page_action); @@ -504,6 +540,11 @@ void LocationBarView::DoLayout(const bool force_layout) { if ((*i)->IsVisible()) entry_width -= (*i)->GetPreferredSize().width() + kInnerPadding; } + for (ContentBlockedViews::const_iterator i(content_blocked_views_.begin()); + i != content_blocked_views_.end(); ++i) { + if ((*i)->IsVisible()) + entry_width -= (*i)->GetPreferredSize().width() + kInnerPadding; + } gfx::Size security_image_size; if (security_image_view_.IsVisible()) { security_image_size = security_image_view_.GetPreferredSize(); @@ -565,6 +606,19 @@ void LocationBarView::DoLayout(const bool force_layout) { offset -= kInnerPadding; } } + // We use a reverse_iterator here because we're laying out the views from + // right to left but in the vector they're ordered left to right. + for (ContentBlockedViews::const_reverse_iterator + i(content_blocked_views_.rbegin()); i != content_blocked_views_.rend(); + ++i) { + if ((*i)->IsVisible()) { + int content_blocked_width = (*i)->GetPreferredSize().width(); + offset -= content_blocked_width; + (*i)->SetBounds(offset, location_y, content_blocked_width, + location_height); + offset -= kInnerPadding; + } + } gfx::Rect location_bounds(kEntryPadding, location_y, entry_width, location_height); if (selected_keyword_view_.IsVisible()) { @@ -696,6 +750,15 @@ void LocationBarView::SetSecurityIcon(ToolbarModel::Icon icon) { } } +void LocationBarView::RefreshContentBlockedViews() { + const TabContents* tab_contents = delegate_->GetTabContents(); + for (ContentBlockedViews::const_iterator i(content_blocked_views_.begin()); + i != content_blocked_views_.end(); ++i) { + (*i)->SetVisible((!model_->input_in_progress() && tab_contents) ? + tab_contents->IsContentBlocked((*i)->content_type()) : false); + } +} + void LocationBarView::DeletePageActionViews() { for (PageActionViews::const_iterator i(page_action_views_.begin()); i != page_action_views_.end(); ++i) @@ -1210,6 +1273,8 @@ void LocationBarView::LocationBarImageView::ShowInfoBubbleImpl( // static SkBitmap* LocationBarView::SecurityImageView::lock_icon_ = NULL; SkBitmap* LocationBarView::SecurityImageView::warning_icon_ = NULL; +SkBitmap* LocationBarView:: + ContentBlockedImageView::icons_[CONTENT_SETTINGS_NUM_TYPES] = { NULL }; LocationBarView::SecurityImageView::SecurityImageView( Profile* profile, @@ -1263,6 +1328,84 @@ void LocationBarView::SecurityImageView::ShowInfoBubble() { SECURITY_INFO_BUBBLE_TEXT)); } +// ContentBlockedImageView------------------------------------------------------ + +LocationBarView::ContentBlockedImageView::ContentBlockedImageView( + ContentSettingsType content_type, + const LocationBarView* parent, + Profile* profile, + const BubblePositioner* bubble_positioner) + : content_type_(content_type), + parent_(parent), + profile_(profile), + info_bubble_(NULL), + bubble_positioner_(bubble_positioner) { + if (!icons_[CONTENT_SETTINGS_FIRST_TYPE]) { + static const int kIconIDs[] = { + IDR_BLOCKED_COOKIES, + IDR_BLOCKED_IMAGES, + IDR_BLOCKED_JAVASCRIPT, + IDR_BLOCKED_PLUGINS, + IDR_BLOCKED_POPUPS, + }; + DCHECK_EQ(arraysize(kIconIDs), CONTENT_SETTINGS_NUM_TYPES); + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + for (int i = CONTENT_SETTINGS_FIRST_TYPE; i < CONTENT_SETTINGS_NUM_TYPES; + ++i) + icons_[i] = rb.GetBitmapNamed(kIconIDs[i]); + } + SetImage(icons_[content_type_]); + + static const int kTooltipIDs[] = { + IDS_BLOCKED_COOKIES_TITLE, + IDS_BLOCKED_IMAGES_TITLE, + IDS_BLOCKED_JAVASCRIPT_TITLE, + IDS_BLOCKED_PLUGINS_TITLE, + IDS_BLOCKED_POPUPS_TOOLTIP, + }; + DCHECK_EQ(arraysize(kTooltipIDs), CONTENT_SETTINGS_NUM_TYPES); + SetTooltipText(l10n_util::GetString(kTooltipIDs[content_type_])); +} + +LocationBarView::ContentBlockedImageView::~ContentBlockedImageView() { + if (info_bubble_) + info_bubble_->Close(); +} + +bool LocationBarView::ContentBlockedImageView::OnMousePressed( + const views::MouseEvent& event) { + gfx::Rect bounds(bubble_positioner_->GetLocationStackBounds()); + gfx::Point location; + views::View::ConvertPointToScreen(this, &location); + bounds.set_x(location.x()); + bounds.set_width(width()); + + ContentBlockedBubbleContents* bubble_contents = + new ContentBlockedBubbleContents(content_type_, parent_->GetHost(), + profile_); + DCHECK(info_bubble_ == NULL); + info_bubble_ = InfoBubble::Show(GetWindow(), bounds, bubble_contents, this); + bubble_contents->set_info_bubble(info_bubble_); + return true; +} + +void LocationBarView::ContentBlockedImageView::VisibilityChanged( + View* starting_from, + bool is_visible) { + if (!is_visible && info_bubble_) + info_bubble_->Close(); +} + +void LocationBarView::ContentBlockedImageView::InfoBubbleClosing( + InfoBubble* info_bubble, + bool closed_by_escape) { + info_bubble_ = NULL; +} + +bool LocationBarView::ContentBlockedImageView::CloseOnEscape() { + return true; +} + // PageActionImageView---------------------------------------------------------- LocationBarView::PageActionImageView::PageActionImageView( diff --git a/chrome/browser/views/location_bar_view.h b/chrome/browser/views/location_bar_view.h index ad168f0..fedee9d 100644 --- a/chrome/browser/views/location_bar_view.h +++ b/chrome/browser/views/location_bar_view.h @@ -20,6 +20,7 @@ #include "chrome/browser/views/browser_bubble.h" #include "chrome/browser/views/extensions/extension_action_context_menu.h" #include "chrome/browser/views/info_bubble.h" +#include "chrome/common/content_settings_types.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" #include "views/controls/image_view.h" @@ -101,6 +102,10 @@ class LocationBarView : public LocationBar, void SetProfile(Profile* profile); Profile* profile() { return profile_; } + // Returns the display-formatted hostname for the current page. This should + // only be used by the ContentBlockedImageView. + std::wstring GetHost() const; + // Sets |preview_enabled| for the PageAction View associated with this // |page_action|. If |preview_enabled| is true, the view will display the // PageActions icon even though it has not been activated by the extension. @@ -160,6 +165,7 @@ class LocationBarView : public LocationBar, virtual void AcceptInputWithDisposition(WindowOpenDisposition); virtual void FocusLocation(); virtual void FocusSearch(); + virtual void UpdateContentBlockedIcons(); virtual void UpdatePageActions(); virtual void InvalidatePageActions(); virtual void SaveStateToContents(TabContents* contents); @@ -355,6 +361,50 @@ class LocationBarView : public LocationBar, DISALLOW_COPY_AND_ASSIGN(SecurityImageView); }; + class ContentBlockedImageView : public views::ImageView, + public InfoBubbleDelegate { + public: + ContentBlockedImageView(ContentSettingsType content_type, + const LocationBarView* parent, + Profile* profile, + const BubblePositioner* bubble_positioner); + virtual ~ContentBlockedImageView(); + + ContentSettingsType content_type() const { return content_type_; } + void set_profile(Profile* profile) { profile_ = profile; } + + private: + // views::ImageView overrides: + virtual bool OnMousePressed(const views::MouseEvent& event); + virtual void VisibilityChanged(View* starting_from, bool is_visible); + + // InfoBubbleDelegate overrides: + virtual void InfoBubbleClosing(InfoBubble* info_bubble, + bool closed_by_escape); + virtual bool CloseOnEscape(); + + static SkBitmap* icons_[CONTENT_SETTINGS_NUM_TYPES]; + + // The type of content handled by this view. + ContentSettingsType content_type_; + + // The owning LocationBarView. + const LocationBarView* parent_; + + // The currently active profile. + Profile* profile_; + + // The currently shown info bubble if any. + InfoBubble* info_bubble_; + + // A positioner used to give the info bubble the correct target bounds. The + // caller maintains ownership of this and must ensure it's kept alive. + const BubblePositioner* bubble_positioner_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(ContentBlockedImageView); + }; + typedef std::vector<ContentBlockedImageView*> ContentBlockedViews; + // PageActionImageView is used to display the icon for a given PageAction // and notify the extension when the icon is clicked. class PageActionImageView : public LocationBarImageView, @@ -496,6 +546,10 @@ class LocationBarView : public LocationBar, // Sets the security icon to display. Note that no repaint is done. void SetSecurityIcon(ToolbarModel::Icon icon); + // Update the visibility state of the Content Blocked icons to reflect what is + // actually blocked on the current page. + void RefreshContentBlockedViews(); + // Delete all page action views that we have created. void DeletePageActionViews(); @@ -574,6 +628,9 @@ class LocationBarView : public LocationBar, // The view that shows the lock/warning when in HTTPS mode. SecurityImageView security_image_view_; + // The content blocked views. + ContentBlockedViews content_blocked_views_; + // The page action icon views. PageActionViews page_action_views_; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 10288b1..1cb00e0 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1731,6 +1731,8 @@ 'browser/views/confirm_message_box_dialog.h', 'browser/views/constrained_window_win.cc', 'browser/views/constrained_window_win.h', + 'browser/views/content_blocked_bubble_contents.cc', + 'browser/views/content_blocked_bubble_contents.h', 'browser/views/cookie_info_view.cc', 'browser/views/cookie_info_view.h', 'browser/views/cookie_prompt_view.cc', diff --git a/chrome/test/test_location_bar.h b/chrome/test/test_location_bar.h index cd96629..e501dfb 100644 --- a/chrome/test/test_location_bar.h +++ b/chrome/test/test_location_bar.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -37,6 +37,7 @@ class TestLocationBar : public LocationBar { virtual void AcceptInputWithDisposition(WindowOpenDisposition) {} virtual void FocusLocation() {} virtual void FocusSearch() {} + virtual void UpdateContentBlockedIcons() {} virtual void UpdatePageActions() {} virtual void InvalidatePageActions() {} virtual void SaveStateToContents(TabContents* contents) {} |