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