| OLD | NEW |
| (Empty) |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/infobars/alternate_nav_infobar_delegate.h" | |
| 6 | |
| 7 #include "base/utf_string_conversions.h" | |
| 8 #include "chrome/browser/api/infobars/infobar_service.h" | |
| 9 #include "content/public/browser/web_contents.h" | |
| 10 #include "grit/generated_resources.h" | |
| 11 #include "grit/theme_resources.h" | |
| 12 #include "ui/base/l10n/l10n_util.h" | |
| 13 #include "ui/base/resource/resource_bundle.h" | |
| 14 | |
| 15 // static | |
| 16 void AlternateNavInfoBarDelegate::Create(InfoBarService* infobar_service, | |
| 17 const GURL& alternate_nav_url) { | |
| 18 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( | |
| 19 new AlternateNavInfoBarDelegate(infobar_service, alternate_nav_url))); | |
| 20 } | |
| 21 | |
| 22 AlternateNavInfoBarDelegate::AlternateNavInfoBarDelegate( | |
| 23 InfoBarService* owner, | |
| 24 const GURL& alternate_nav_url) | |
| 25 : InfoBarDelegate(owner), | |
| 26 alternate_nav_url_(alternate_nav_url) { | |
| 27 } | |
| 28 | |
| 29 AlternateNavInfoBarDelegate::~AlternateNavInfoBarDelegate() { | |
| 30 } | |
| 31 | |
| 32 string16 AlternateNavInfoBarDelegate::GetMessageTextWithOffset( | |
| 33 size_t* link_offset) const { | |
| 34 const string16 label = l10n_util::GetStringFUTF16( | |
| 35 IDS_ALTERNATE_NAV_URL_VIEW_LABEL, string16(), link_offset); | |
| 36 return label; | |
| 37 } | |
| 38 | |
| 39 string16 AlternateNavInfoBarDelegate::GetLinkText() const { | |
| 40 return UTF8ToUTF16(alternate_nav_url_.spec()); | |
| 41 } | |
| 42 | |
| 43 bool AlternateNavInfoBarDelegate::LinkClicked( | |
| 44 WindowOpenDisposition disposition) { | |
| 45 content::OpenURLParams params( | |
| 46 alternate_nav_url_, content::Referrer(), disposition, | |
| 47 // Pretend the user typed this URL, so that navigating to | |
| 48 // it will be the default action when it's typed again in | |
| 49 // the future. | |
| 50 content::PAGE_TRANSITION_TYPED, | |
| 51 false); | |
| 52 owner()->GetWebContents()->OpenURL(params); | |
| 53 | |
| 54 // We should always close, even if the navigation did not occur within this | |
| 55 // WebContents. | |
| 56 return true; | |
| 57 } | |
| 58 | |
| 59 AlternateNavInfoBarDelegate* | |
| 60 AlternateNavInfoBarDelegate::AsAlternateNavInfoBarDelegate() { | |
| 61 return this; | |
| 62 } | |
| 63 | |
| 64 gfx::Image* AlternateNavInfoBarDelegate::GetIcon() const { | |
| 65 return &ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( | |
| 66 IDR_INFOBAR_ALT_NAV_URL); | |
| 67 } | |
| 68 | |
| 69 InfoBarDelegate::Type AlternateNavInfoBarDelegate::GetInfoBarType() const { | |
| 70 return PAGE_ACTION_TYPE; | |
| 71 } | |
| OLD | NEW |