| 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/history/history_service.h" | 8 #include "chrome/browser/history/history_service.h" |
| 9 #include "chrome/browser/history/history_service_factory.h" | 9 #include "chrome/browser/history/history_service_factory.h" |
| 10 #include "chrome/browser/history/shortcuts_backend.h" | 10 #include "chrome/browser/history/shortcuts_backend.h" |
| 11 #include "chrome/browser/history/shortcuts_backend_factory.h" | 11 #include "chrome/browser/history/shortcuts_backend_factory.h" |
| 12 #include "chrome/browser/infobars/infobar.h" |
| 12 #include "chrome/browser/infobars/infobar_service.h" | 13 #include "chrome/browser/infobars/infobar_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 15 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 16 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 18 | 19 |
| 19 | 20 |
| 21 AlternateNavInfoBarDelegate::~AlternateNavInfoBarDelegate() { |
| 22 } |
| 23 |
| 20 // static | 24 // static |
| 21 void AlternateNavInfoBarDelegate::Create( | 25 void AlternateNavInfoBarDelegate::Create( |
| 22 content::WebContents* web_contents, | 26 content::WebContents* web_contents, |
| 23 const string16& text, | 27 const string16& text, |
| 24 const AutocompleteMatch& match, | 28 const AutocompleteMatch& match, |
| 25 const GURL& search_url) { | 29 const GURL& search_url) { |
| 26 InfoBarService* infobar_service = | 30 InfoBarService* infobar_service = |
| 27 InfoBarService::FromWebContents(web_contents); | 31 InfoBarService::FromWebContents(web_contents); |
| 28 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( | 32 infobar_service->AddInfoBar(AlternateNavInfoBarDelegate::CreateInfoBar( |
| 29 new AlternateNavInfoBarDelegate( | 33 scoped_ptr<AlternateNavInfoBarDelegate>(new AlternateNavInfoBarDelegate( |
| 30 infobar_service, | |
| 31 Profile::FromBrowserContext(web_contents->GetBrowserContext()), text, | 34 Profile::FromBrowserContext(web_contents->GetBrowserContext()), text, |
| 32 match, search_url))); | 35 match, search_url)))); |
| 33 } | 36 } |
| 34 | 37 |
| 35 AlternateNavInfoBarDelegate::AlternateNavInfoBarDelegate( | 38 AlternateNavInfoBarDelegate::AlternateNavInfoBarDelegate( |
| 36 InfoBarService* owner, | |
| 37 Profile* profile, | 39 Profile* profile, |
| 38 const string16& text, | 40 const string16& text, |
| 39 const AutocompleteMatch& match, | 41 const AutocompleteMatch& match, |
| 40 const GURL& search_url) | 42 const GURL& search_url) |
| 41 : InfoBarDelegate(owner), | 43 : InfoBarDelegate(), |
| 42 profile_(profile), | 44 profile_(profile), |
| 43 text_(text), | 45 text_(text), |
| 44 match_(match), | 46 match_(match), |
| 45 search_url_(search_url) { | 47 search_url_(search_url) { |
| 46 DCHECK(match_.destination_url.is_valid()); | 48 DCHECK(match_.destination_url.is_valid()); |
| 47 DCHECK(search_url_.is_valid()); | 49 DCHECK(search_url_.is_valid()); |
| 48 } | 50 } |
| 49 | 51 |
| 50 AlternateNavInfoBarDelegate::~AlternateNavInfoBarDelegate() { | 52 // AlternateNavInfoBarDelegate::CreateInfoBar() is implemented in |
| 51 } | 53 // platform-specific files. |
| 52 | 54 |
| 53 string16 AlternateNavInfoBarDelegate::GetMessageTextWithOffset( | 55 string16 AlternateNavInfoBarDelegate::GetMessageTextWithOffset( |
| 54 size_t* link_offset) const { | 56 size_t* link_offset) const { |
| 55 const string16 label = l10n_util::GetStringFUTF16( | 57 const string16 label = l10n_util::GetStringFUTF16( |
| 56 IDS_ALTERNATE_NAV_URL_VIEW_LABEL, string16(), link_offset); | 58 IDS_ALTERNATE_NAV_URL_VIEW_LABEL, string16(), link_offset); |
| 57 return label; | 59 return label; |
| 58 } | 60 } |
| 59 | 61 |
| 60 string16 AlternateNavInfoBarDelegate::GetLinkText() const { | 62 string16 AlternateNavInfoBarDelegate::GetLinkText() const { |
| 61 return UTF8ToUTF16(match_.destination_url.spec()); | 63 return UTF8ToUTF16(match_.destination_url.spec()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 89 return true; | 91 return true; |
| 90 } | 92 } |
| 91 | 93 |
| 92 int AlternateNavInfoBarDelegate::GetIconID() const { | 94 int AlternateNavInfoBarDelegate::GetIconID() const { |
| 93 return IDR_INFOBAR_ALT_NAV_URL; | 95 return IDR_INFOBAR_ALT_NAV_URL; |
| 94 } | 96 } |
| 95 | 97 |
| 96 InfoBarDelegate::Type AlternateNavInfoBarDelegate::GetInfoBarType() const { | 98 InfoBarDelegate::Type AlternateNavInfoBarDelegate::GetInfoBarType() const { |
| 97 return PAGE_ACTION_TYPE; | 99 return PAGE_ACTION_TYPE; |
| 98 } | 100 } |
| OLD | NEW |