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