diff options
author | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-18 13:48:02 +0000 |
---|---|---|
committer | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-18 13:48:02 +0000 |
commit | ff667b93c29a81d1446ed9a220f8f762fbf6b7d4 (patch) | |
tree | 81c02afbf3c22890da5aa4256ad63441fe0c8eb1 | |
parent | 19d81be80dec350f85e6beb21845203179eb34f2 (diff) | |
download | chromium_src-ff667b93c29a81d1446ed9a220f8f762fbf6b7d4.zip chromium_src-ff667b93c29a81d1446ed9a220f8f762fbf6b7d4.tar.gz chromium_src-ff667b93c29a81d1446ed9a220f8f762fbf6b7d4.tar.bz2 |
Finish implementing the geolocation infobar; adds a Learn more link pointing to the (placeholder) help center page.
This extends ConfirmInfoBar to support to have optional link support (simple support, i.e. not the inserted mid-label link that LinkInfoBar sports)
Note 1: this does not exactly match the mock; the allow/deny buttons and link are swapped. I think this looks nicer, is more consistent with other confirm infobars, and happens to be easier to code
Note 2: linux & mac will need follow-up CLs, but will simply ignore the link in the meantime
BUG=11246
TEST=browser_tests.exe --gtest_filter=Geol*
Review URL: http://codereview.chromium.org/1037006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41951 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/resources/locale_settings.grd | 5 | ||||
-rw-r--r-- | chrome/browser/geolocation/geolocation_permission_context.cc | 28 | ||||
-rw-r--r-- | chrome/browser/tab_contents/infobar_delegate.h | 16 | ||||
-rw-r--r-- | chrome/browser/views/infobars/infobars.cc | 56 | ||||
-rw-r--r-- | chrome/browser/views/infobars/infobars.h | 7 |
5 files changed, 97 insertions, 15 deletions
diff --git a/chrome/app/resources/locale_settings.grd b/chrome/app/resources/locale_settings.grd index 847756a..ee62230 100644 --- a/chrome/app/resources/locale_settings.grd +++ b/chrome/app/resources/locale_settings.grd @@ -484,6 +484,11 @@ http://www.google.com/support/chrome/bin/answer.py?answer=96817&hl=[GRITLANGCODE] </message> + <!-- The URL for the "Learn more" privacy page for the Geolocation permission infobar. --> + <message name="IDS_LEARN_MORE_GEOLOCATION_URL" translateable="false"> + http://www.google.com/support/chrome/bin/answer.py?answer=142065&hl=[GRITLANGCODE] + </message> + <!-- The width and height of the bookmark manager in characters and lines --> <!-- (See above). --> <message name="IDS_BOOKMARK_MANAGER_DIALOG_WIDTH_CHARS" use_name_for_id="true"> diff --git a/chrome/browser/geolocation/geolocation_permission_context.cc b/chrome/browser/geolocation/geolocation_permission_context.cc index f9fa9e2..2ff2f12 100644 --- a/chrome/browser/geolocation/geolocation_permission_context.cc +++ b/chrome/browser/geolocation/geolocation_permission_context.cc @@ -21,6 +21,7 @@ #include "chrome/common/json_value_serializer.h" #include "chrome/common/render_messages.h" #include "grit/generated_resources.h" +#include "grit/locale_settings.h" #include "grit/theme_resources.h" namespace { @@ -37,17 +38,21 @@ class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { TabContents* tab_contents, GeolocationPermissionContext* context, int render_process_id, int render_view_id, int bridge_id, const std::string& host) - : ConfirmInfoBarDelegate(tab_contents), context_(context), - render_process_id_(render_process_id), render_view_id_(render_view_id), - bridge_id_(bridge_id), host_(host) { + : ConfirmInfoBarDelegate(tab_contents), + tab_contents_(tab_contents), + context_(context), + render_process_id_(render_process_id), + render_view_id_(render_view_id), + bridge_id_(bridge_id), + host_(host) { } // ConfirmInfoBarDelegate + virtual void InfoBarClosed() { delete this; } virtual Type GetInfoBarType() { return INFO_TYPE; } virtual bool Accept() { return SetPermission(true); } virtual bool Cancel() { return SetPermission(false); } virtual int GetButtons() const { return BUTTON_OK | BUTTON_CANCEL; } - virtual std::wstring GetButtonLabel(InfoBarButton button) const { switch (button) { case BUTTON_OK: @@ -60,16 +65,24 @@ class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { return L""; } } - virtual std::wstring GetMessageText() const { return l10n_util::GetStringF( IDS_GEOLOCATION_INFOBAR_QUESTION, UTF8ToWide(host_)); } - virtual SkBitmap* GetIcon() const { return ResourceBundle::GetSharedInstance().GetBitmapNamed( IDR_GEOLOCATION_INFOBAR_ICON); } + virtual std::wstring GetLinkText() { + return l10n_util::GetString(IDS_LEARN_MORE); + } + virtual bool LinkClicked(WindowOpenDisposition disposition) { + // Ignore the click dispostion and always open in a new top level tab. + tab_contents_->OpenURL( + GURL(l10n_util::GetStringUTF8(IDS_LEARN_MORE_GEOLOCATION_URL)), GURL(), + NEW_FOREGROUND_TAB, PageTransition::LINK); + return false; // Do not dismiss the info bar. + } private: bool SetPermission(bool confirm) { @@ -78,11 +91,14 @@ class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { return true; } + TabContents* tab_contents_; scoped_refptr<GeolocationPermissionContext> context_; int render_process_id_; int render_view_id_; int bridge_id_; std::string host_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(GeolocationConfirmInfoBarDelegate); }; // TODO(bulach): use HostContentSettingsMap instead! diff --git a/chrome/browser/tab_contents/infobar_delegate.h b/chrome/browser/tab_contents/infobar_delegate.h index 41e09ce..4c72cca 100644 --- a/chrome/browser/tab_contents/infobar_delegate.h +++ b/chrome/browser/tab_contents/infobar_delegate.h @@ -241,6 +241,22 @@ class ConfirmInfoBarDelegate : public AlertInfoBarDelegate { // the InfoBarDelegate should be removed from the associated TabContents. virtual bool Cancel() { return true; } + // Returns the text of the link to be displayed, if any. Otherwise returns + // and empty string. + virtual std::wstring GetLinkText() { + return std::wstring(); + } + + // Called when the Link is clicked. The |disposition| specifies how the + // resulting document should be loaded (based on the event flags present when + // the link was clicked). This function returns true if the InfoBar should be + // closed now or false if it should remain until the user explicitly closes + // it. + // Will only be called if GetLinkText() returns non-empty string. + virtual bool LinkClicked(WindowOpenDisposition disposition) { + return true; + } + // Overridden from InfoBarDelegate: virtual InfoBar* CreateInfoBar(); virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate() { diff --git a/chrome/browser/views/infobars/infobars.cc b/chrome/browser/views/infobars/infobars.cc index 6ddffc3..49cc4bb 100644 --- a/chrome/browser/views/infobars/infobars.cc +++ b/chrome/browser/views/infobars/infobars.cc @@ -310,8 +310,9 @@ void AlertInfoBar::Layout() { icon_ps.height()); gfx::Size text_ps = label_->GetPreferredSize(); - int text_width = - GetAvailableWidth() - icon_->bounds().right() - kIconLabelSpacing; + int text_width = std::min( + text_ps.width(), + GetAvailableWidth() - icon_->bounds().right() - kIconLabelSpacing); label_->SetBounds(icon_->bounds().right() + kIconLabelSpacing, OffsetY(this, text_ps), text_width, text_ps.height()); } @@ -431,6 +432,7 @@ ConfirmInfoBar::ConfirmInfoBar(ConfirmInfoBarDelegate* delegate) : AlertInfoBar(delegate), ok_button_(NULL), cancel_button_(NULL), + link_(NULL), initialized_(false) { ok_button_ = new views::NativeButton( this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK)); @@ -438,16 +440,48 @@ ConfirmInfoBar::ConfirmInfoBar(ConfirmInfoBarDelegate* delegate) ok_button_->SetAppearsAsDefault(true); cancel_button_ = new views::NativeButton( this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL)); + + // Set up the link. + link_ = new views::Link; + link_->SetText(delegate->GetLinkText()); + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + link_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); + link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + link_->SetController(this); + link_->MakeReadableOverBackgroundColor(background()->get_color()); } ConfirmInfoBar::~ConfirmInfoBar() { + if (!initialized_) { + delete ok_button_; + delete cancel_button_; + delete link_; + } +} + +// ConfirmInfoBar, views::LinkController implementation: ----------------------- + +void ConfirmInfoBar::LinkActivated(views::Link* source, int event_flags) { + DCHECK(source == link_); + DCHECK(link_->IsVisible()); + DCHECK(!link_->GetText().empty()); + if (GetDelegate()->LinkClicked( + event_utils::DispositionFromEventFlags(event_flags))) { + RemoveInfoBar(); + } } // ConfirmInfoBar, views::View overrides: -------------------------------------- void ConfirmInfoBar::Layout() { + // First layout right aligned items (from right to left) in order to determine + // the space avalable, then layout the left aligned items. + + // Layout the close button. InfoBar::Layout(); - int available_width = InfoBar::GetAvailableWidth(); + + // Layout the cancel and OK buttons. + int available_width = AlertInfoBar::GetAvailableWidth(); int ok_button_width = 0; int cancel_button_width = 0; gfx::Size ok_ps = ok_button_->GetPreferredSize(); @@ -470,7 +504,16 @@ void ConfirmInfoBar::Layout() { int spacing = cancel_button_width > 0 ? kButtonButtonSpacing : 0; ok_button_->SetBounds(cancel_button_->x() - spacing - ok_button_width, OffsetY(this, ok_ps), ok_ps.width(), ok_ps.height()); + + // Layout the icon and label. AlertInfoBar::Layout(); + + // Now append the link to the label's right edge. + link_->SetVisible(!link_->GetText().empty()); + gfx::Size link_ps = link_->GetPreferredSize(); + int link_x = label()->bounds().right() + kEndOfLabelSpacing; + int link_w = std::min(GetAvailableWidth() - link_x, link_ps.width()); + link_->SetBounds(link_x, OffsetY(this, link_ps), link_w, link_ps.height()); } void ConfirmInfoBar::ViewHierarchyChanged(bool is_add, @@ -500,11 +543,7 @@ void ConfirmInfoBar::ButtonPressed( // ConfirmInfoBar, InfoBar overrides: ------------------------------------------ int ConfirmInfoBar::GetAvailableWidth() const { - if (ok_button_) - return ok_button_->x() - kEndOfLabelSpacing; - if (cancel_button_) - return cancel_button_->x() - kEndOfLabelSpacing; - return InfoBar::GetAvailableWidth(); + return ok_button_->x() - kEndOfLabelSpacing; } // ConfirmInfoBar, private: ---------------------------------------------------- @@ -516,6 +555,7 @@ ConfirmInfoBarDelegate* ConfirmInfoBar::GetDelegate() { void ConfirmInfoBar::Init() { AddChildView(ok_button_); AddChildView(cancel_button_); + AddChildView(link_); } // AlertInfoBarDelegate, InfoBarDelegate overrides: ---------------------------- diff --git a/chrome/browser/views/infobars/infobars.h b/chrome/browser/views/infobars/infobars.h index 7d04904..60067ba 100644 --- a/chrome/browser/views/infobars/infobars.h +++ b/chrome/browser/views/infobars/infobars.h @@ -186,11 +186,15 @@ class LinkInfoBar : public InfoBar, DISALLOW_COPY_AND_ASSIGN(LinkInfoBar); }; -class ConfirmInfoBar : public AlertInfoBar { +class ConfirmInfoBar : public AlertInfoBar, + public views::LinkController { public: explicit ConfirmInfoBar(ConfirmInfoBarDelegate* delegate); virtual ~ConfirmInfoBar(); + // Overridden from views::LinkController: + virtual void LinkActivated(views::Link* source, int event_flags); + // Overridden from views::View: virtual void Layout(); @@ -213,6 +217,7 @@ class ConfirmInfoBar : public AlertInfoBar { views::NativeButton* ok_button_; views::NativeButton* cancel_button_; + views::Link* link_; bool initialized_; |