Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(461)

Side by Side Diff: chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.cc

Issue 1361253002: Separate the URL of an infobar link with clicking on it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fit Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/autocomplete/shortcuts_backend_factory.h" 8 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h"
9 #include "chrome/browser/history/history_service_factory.h" 9 #include "chrome/browser/history/history_service_factory.h"
10 #include "chrome/browser/infobars/infobar_service.h" 10 #include "chrome/browser/infobars/infobar_service.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 size_t* link_offset) const { 56 size_t* link_offset) const {
57 const base::string16 label = l10n_util::GetStringFUTF16( 57 const base::string16 label = l10n_util::GetStringFUTF16(
58 IDS_ALTERNATE_NAV_URL_VIEW_LABEL, base::string16(), link_offset); 58 IDS_ALTERNATE_NAV_URL_VIEW_LABEL, base::string16(), link_offset);
59 return label; 59 return label;
60 } 60 }
61 61
62 base::string16 AlternateNavInfoBarDelegate::GetLinkText() const { 62 base::string16 AlternateNavInfoBarDelegate::GetLinkText() const {
63 return base::UTF8ToUTF16(match_.destination_url.spec()); 63 return base::UTF8ToUTF16(match_.destination_url.spec());
64 } 64 }
65 65
66 GURL AlternateNavInfoBarDelegate::GetLinkURL() const {
67 return match_.destination_url;
68 }
69
66 bool AlternateNavInfoBarDelegate::LinkClicked( 70 bool AlternateNavInfoBarDelegate::LinkClicked(
67 WindowOpenDisposition disposition) { 71 WindowOpenDisposition disposition) {
68 // Tell the shortcuts backend to remove the shortcut it added for the original 72 // Tell the shortcuts backend to remove the shortcut it added for the original
69 // search and instead add one reflecting this navigation. 73 // search and instead add one reflecting this navigation.
70 scoped_refptr<ShortcutsBackend> shortcuts_backend( 74 scoped_refptr<ShortcutsBackend> shortcuts_backend(
71 ShortcutsBackendFactory::GetForProfile(profile_)); 75 ShortcutsBackendFactory::GetForProfile(profile_));
72 if (shortcuts_backend.get()) { // May be NULL in incognito. 76 if (shortcuts_backend.get()) { // May be NULL in incognito.
73 shortcuts_backend->DeleteShortcutsWithURL(search_url_); 77 shortcuts_backend->DeleteShortcutsWithURL(search_url_);
74 shortcuts_backend->AddOrUpdateShortcut(text_, match_); 78 shortcuts_backend->AddOrUpdateShortcut(text_, match_);
75 } 79 }
76 80
77 // Tell the history system to remove any saved search term for the search. 81 // Tell the history system to remove any saved search term for the search.
78 history::HistoryService* const history_service = 82 history::HistoryService* const history_service =
79 HistoryServiceFactory::GetForProfile(profile_, 83 HistoryServiceFactory::GetForProfile(profile_,
80 ServiceAccessType::IMPLICIT_ACCESS); 84 ServiceAccessType::IMPLICIT_ACCESS);
81 if (history_service) 85 if (history_service)
82 history_service->DeleteKeywordSearchTermForURL(search_url_); 86 history_service->DeleteKeywordSearchTermForURL(search_url_);
83 87
84 // Pretend the user typed this URL, so that navigating to it will be the 88 // Pretend the user typed this URL, so that navigating to it will be the
85 // default action when it's typed again in the future. 89 // default action when it's typed again in the future.
86 InfoBarService::WebContentsFromInfoBar(infobar())->OpenURL( 90 InfoBarService::WebContentsFromInfoBar(infobar())->OpenURL(
87 content::OpenURLParams(match_.destination_url, content::Referrer(), 91 content::OpenURLParams(GetLinkURL(), content::Referrer(),
88 disposition, ui::PAGE_TRANSITION_TYPED, 92 disposition, ui::PAGE_TRANSITION_TYPED,
89 false)); 93 false));
90 94
91 // We should always close, even if the navigation did not occur within this 95 // We should always close, even if the navigation did not occur within this
92 // WebContents. 96 // WebContents.
93 return true; 97 return true;
94 } 98 }
95 99
96 infobars::InfoBarDelegate::Type 100 infobars::InfoBarDelegate::Type
97 AlternateNavInfoBarDelegate::GetInfoBarType() const { 101 AlternateNavInfoBarDelegate::GetInfoBarType() const {
98 return PAGE_ACTION_TYPE; 102 return PAGE_ACTION_TYPE;
99 } 103 }
100 104
101 int AlternateNavInfoBarDelegate::GetIconId() const { 105 int AlternateNavInfoBarDelegate::GetIconId() const {
102 return IDR_INFOBAR_ALT_NAV_URL; 106 return IDR_INFOBAR_ALT_NAV_URL;
103 } 107 }
104 108
105 gfx::VectorIconId AlternateNavInfoBarDelegate::GetVectorIconId() const { 109 gfx::VectorIconId AlternateNavInfoBarDelegate::GetVectorIconId() const {
106 #if defined(OS_MACOSX) 110 #if defined(OS_MACOSX)
107 return gfx::VectorIconId::VECTOR_ICON_NONE; 111 return gfx::VectorIconId::VECTOR_ICON_NONE;
108 #else 112 #else
109 return gfx::VectorIconId::GLOBE; 113 return gfx::VectorIconId::GLOBE;
110 #endif 114 #endif
111 } 115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698