Skip to content

Commit

Permalink
[OriginChip] Show the default search provider in the Omnibox hint text.
Browse files Browse the repository at this point in the history
BUG=338563
TBR=cpu

Review URL: https://codereview.chromium.org/144643007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@249229 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jdonnelly@chromium.org committed Feb 6, 2014
1 parent 6ae6e34 commit cb39d67
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
12 changes: 10 additions & 2 deletions chrome/app/generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -7376,9 +7376,17 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_OMNIBOX_KEYWORD_TEXT" desc="Text shown in the search button at the front of the omnibox when the user has selected a keyword">
Search <ph name="SITE_NAME">$1<ex>google.com</ex></ph>:
</message>
<message name="IDS_OMNIBOX_EMPTY_HINT" desc="The text displayed in the omnibox when it is empty.">
Search or type URL
<message name="IDS_OMNIBOX_EMPTY_HINT_WITH_DEFAULT_SEARCH_PROVIDER" desc="The text displayed in the omnibox when it is empty, which includes the name of the default search provider.">
Search <ph name="ENGINE">$1<ex>Google</ex></ph> or type URL
</message>
<message name="IDS_OMNIBOX_EMPTY_HINT_NO_DEFAULT_SEARCH_PROVIDER" desc="The text displayed in the omnibox when it is empty, if the default search provider cannot be determined.">
Type URL
</message>
<if expr="is_ios">
<message name="IDS_OMNIBOX_EMPTY_HINT" desc="The text displayed in the omnibox when it is empty.">
Search or type URL
</message>
</if>

<!-- Native Frame menu -->
<message name="IDS_ALWAYS_ON_TOP" desc="The optional menu in native frame windows for setting the window to be always on top">
Expand Down
24 changes: 24 additions & 0 deletions chrome/browser/ui/omnibox/omnibox_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/omnibox/omnibox_edit_controller.h"
#include "chrome/browser/ui/toolbar/toolbar_model.h"
#include "grit/generated_resources.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/l10n/l10n_util.h"

// static
base::string16 OmniboxView::StripJavascriptSchemas(const base::string16& text) {
Expand Down Expand Up @@ -102,6 +107,25 @@ int OmniboxView::GetIcon() const {
model_->CurrentTextType() : AutocompleteMatchType::URL_WHAT_YOU_TYPED);
}

base::string16 OmniboxView::GetHintText() const {
// Attempt to determine the default search provider and use that in the hint
// text.
TemplateURLService* template_url_service =
TemplateURLServiceFactory::GetForProfile(model_->profile());
if (template_url_service) {
TemplateURL* template_url =
template_url_service->GetDefaultSearchProvider();
if (template_url)
return l10n_util::GetStringFUTF16(
IDS_OMNIBOX_EMPTY_HINT_WITH_DEFAULT_SEARCH_PROVIDER,
template_url->AdjustedShortNameForLocaleDirection());
}

// Otherwise return a hint based on there being no default search provider.
return l10n_util::GetStringUTF16(
IDS_OMNIBOX_EMPTY_HINT_NO_DEFAULT_SEARCH_PROVIDER);
}

void OmniboxView::SetUserText(const base::string16& text) {
SetUserText(text, text, true);
}
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/ui/omnibox/omnibox_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ class OmniboxView {
// Returns the resource ID of the icon to show for the current text.
int GetIcon() const;

// Returns the hint text that can be displayed when there is no text in the
// omnibox.
base::string16 GetHintText() const;

// The user text is the text the user has manually keyed in. When present,
// this is shown in preference to the permanent text; hitting escape will
// revert to the permanent text.
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/ui/views/omnibox/omnibox_view_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,6 @@ void OmniboxViewViews::Init() {
if (popup_window_mode_)
SetReadOnly(true);

if (chrome::ShouldDisplayOriginChip())
set_placeholder_text(l10n_util::GetStringUTF16(IDS_OMNIBOX_EMPTY_HINT));

// Initialize the popup view using the same font.
popup_view_.reset(OmniboxPopupContentsView::Create(
GetFontList(), this, model(), location_bar_view_));
Expand Down Expand Up @@ -448,6 +445,9 @@ void OmniboxViewViews::OnTabChanged(const content::WebContents* web_contents) {
}

void OmniboxViewViews::Update() {
if (chrome::ShouldDisplayOriginChip())
set_placeholder_text(GetHintText());

const ToolbarModel::SecurityLevel old_security_level = security_level_;
security_level_ = controller()->GetToolbarModel()->GetSecurityLevel(false);
if (model()->UpdatePermanentText()) {
Expand Down

0 comments on commit cb39d67

Please sign in to comment.