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

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

Issue 190063006: Infobar Componentization Proof of Concept (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor fixes Created 6 years, 9 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/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.h"
13 #include "chrome/browser/infobars/infobar_manager.h"
13 #include "chrome/browser/infobars/infobar_service.h" 14 #include "chrome/browser/infobars/infobar_service.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
16 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
17 #include "grit/theme_resources.h" 18 #include "grit/theme_resources.h"
18 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
19 20
20 21
21 AlternateNavInfoBarDelegate::~AlternateNavInfoBarDelegate() { 22 AlternateNavInfoBarDelegate::~AlternateNavInfoBarDelegate() {
22 } 23 }
23 24
24 // static 25 // static
25 void AlternateNavInfoBarDelegate::Create( 26 void AlternateNavInfoBarDelegate::Create(
26 content::WebContents* web_contents, 27 content::WebContents* web_contents,
27 const base::string16& text, 28 const base::string16& text,
28 const AutocompleteMatch& match, 29 const AutocompleteMatch& match,
29 const GURL& search_url) { 30 const GURL& search_url) {
30 InfoBarService* infobar_service = 31 InfoBarService* infobar_service =
31 InfoBarService::FromWebContents(web_contents); 32 InfoBarService::FromWebContents(web_contents);
32 infobar_service->AddInfoBar(AlternateNavInfoBarDelegate::CreateInfoBar( 33 infobar_service->AddInfoBar(AlternateNavInfoBarDelegate::CreateInfoBar(
33 scoped_ptr<AlternateNavInfoBarDelegate>(new AlternateNavInfoBarDelegate( 34 scoped_ptr<AlternateNavInfoBarDelegate>(new AlternateNavInfoBarDelegate(
34 Profile::FromBrowserContext(web_contents->GetBrowserContext()), text, 35 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
35 match, search_url)))); 36 web_contents,
37 text,
38 match,
39 search_url))));
36 } 40 }
37 41
38 AlternateNavInfoBarDelegate::AlternateNavInfoBarDelegate( 42 AlternateNavInfoBarDelegate::AlternateNavInfoBarDelegate(
39 Profile* profile, 43 Profile* profile,
44 content::WebContents* web_contents,
40 const base::string16& text, 45 const base::string16& text,
41 const AutocompleteMatch& match, 46 const AutocompleteMatch& match,
42 const GURL& search_url) 47 const GURL& search_url)
43 : InfoBarDelegate(), 48 : InfoBarDelegate(),
44 profile_(profile), 49 profile_(profile),
50 web_contents_(web_contents),
45 text_(text), 51 text_(text),
46 match_(match), 52 match_(match),
47 search_url_(search_url) { 53 search_url_(search_url) {
48 DCHECK(match_.destination_url.is_valid()); 54 DCHECK(match_.destination_url.is_valid());
49 DCHECK(search_url_.is_valid()); 55 DCHECK(search_url_.is_valid());
50 } 56 }
51 57
52 // AlternateNavInfoBarDelegate::CreateInfoBar() is implemented in 58 // AlternateNavInfoBarDelegate::CreateInfoBar() is implemented in
53 // platform-specific files. 59 // platform-specific files.
54 60
(...skipping 20 matching lines...) Expand all
75 } 81 }
76 82
77 // Tell the history system to remove any saved search term for the search. 83 // Tell the history system to remove any saved search term for the search.
78 HistoryService* const history_service = 84 HistoryService* const history_service =
79 HistoryServiceFactory::GetForProfile(profile_, Profile::IMPLICIT_ACCESS); 85 HistoryServiceFactory::GetForProfile(profile_, Profile::IMPLICIT_ACCESS);
80 if (history_service) 86 if (history_service)
81 history_service->DeleteKeywordSearchTermForURL(search_url_); 87 history_service->DeleteKeywordSearchTermForURL(search_url_);
82 88
83 // Pretend the user typed this URL, so that navigating to it will be the 89 // Pretend the user typed this URL, so that navigating to it will be the
84 // default action when it's typed again in the future. 90 // default action when it's typed again in the future.
85 web_contents()->OpenURL(content::OpenURLParams( 91 web_contents_->OpenURL(content::OpenURLParams(match_.destination_url,
86 match_.destination_url, content::Referrer(), disposition, 92 content::Referrer(),
87 content::PAGE_TRANSITION_TYPED, false)); 93 disposition,
94 content::PAGE_TRANSITION_TYPED,
95 false));
88 96
89 // We should always close, even if the navigation did not occur within this 97 // We should always close, even if the navigation did not occur within this
90 // WebContents. 98 // WebContents.
91 return true; 99 return true;
92 } 100 }
93 101
94 int AlternateNavInfoBarDelegate::GetIconID() const { 102 int AlternateNavInfoBarDelegate::GetIconID() const {
95 return IDR_INFOBAR_ALT_NAV_URL; 103 return IDR_INFOBAR_ALT_NAV_URL;
96 } 104 }
97 105
98 InfoBarDelegate::Type AlternateNavInfoBarDelegate::GetInfoBarType() const { 106 InfoBarDelegate::Type AlternateNavInfoBarDelegate::GetInfoBarType() const {
99 return PAGE_ACTION_TYPE; 107 return PAGE_ACTION_TYPE;
100 } 108 }
109
110 void AlternateNavInfoBarDelegate::CleanUp() { web_contents_ = NULL; }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698