Commit be36a37d authored by samarth@chromium.org's avatar samarth@chromium.org

InstantExtended: add back focus() API call.

BUG=none
TESTED=Open NTP, run chrome.embeddedSearch.searchBox.focus() in the DOM inspector.

Review URL: https://chromiumcodereview.appspot.com/23462014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220531 0039d316-1c4b-4281-b951-d872f2087c98
parent 219b882d
......@@ -13,6 +13,7 @@ if (!chrome.embeddedSearch) {
// =======================================================================
// Private functions
// =======================================================================
native function Focus();
native function GetDisplayInstantResults();
native function GetFont();
native function GetFontSize();
......@@ -41,6 +42,10 @@ if (!chrome.embeddedSearch) {
this.__defineGetter__('suggestion', GetSuggestionToPrefetch);
this.__defineGetter__('value', GetQuery);
this.focus = function() {
Focus();
};
// This method is restricted to chrome-search://most-visited pages by
// checking the invoking context's origin in searchbox_extension.cc.
this.getMostVisitedItemData = function(restrictedId) {
......
......@@ -223,6 +223,12 @@ const ThemeBackgroundInfo& SearchBox::GetThemeBackgroundInfo() {
return theme_info_;
}
void SearchBox::Focus() {
render_view()->Send(new ChromeViewHostMsg_FocusOmnibox(
render_view()->GetRoutingID(), render_view()->GetPageId(),
OMNIBOX_FOCUS_VISIBLE));
}
void SearchBox::NavigateToURL(const GURL& url,
content::PageTransition transition,
WindowOpenDisposition disposition,
......
......@@ -66,6 +66,9 @@ class SearchBox : public content::RenderViewObserver,
bool GetMostVisitedItemWithID(InstantRestrictedID most_visited_item_id,
InstantMostVisitedItem* item) const;
// Sends ChromeViewHostMsg_FocusOmnibox to the browser.
void Focus();
// Sends ChromeViewHostMsg_SearchBoxNavigate to the browser.
void NavigateToURL(const GURL& url,
content::PageTransition transition,
......
......@@ -321,6 +321,9 @@ class SearchBoxExtensionWrapper : public v8::Extension {
static void DeleteMostVisitedItem(
const v8::FunctionCallbackInfo<v8::Value>& args);
// Focuses the omnibox.
static void Focus(const v8::FunctionCallbackInfo<v8::Value>& args);
// Gets whether or not the app launcher is enabled.
static void GetAppLauncherEnabled(
const v8::FunctionCallbackInfo<v8::Value>& args);
......@@ -485,6 +488,8 @@ v8::Handle<v8::FunctionTemplate> SearchBoxExtensionWrapper::GetNativeFunction(
v8::Handle<v8::String> name) {
if (name->Equals(v8::String::New("DeleteMostVisitedItem")))
return v8::FunctionTemplate::New(DeleteMostVisitedItem);
if (name->Equals(v8::String::New("Focus")))
return v8::FunctionTemplate::New(Focus);
if (name->Equals(v8::String::New("GetAppLauncherEnabled")))
return v8::FunctionTemplate::New(GetAppLauncherEnabled);
if (name->Equals(v8::String::New("GetFont")))
......@@ -553,6 +558,16 @@ void SearchBoxExtensionWrapper::DeleteMostVisitedItem(
SearchBox::Get(render_view)->DeleteMostVisitedItem(args[0]->IntegerValue());
}
// static
void SearchBoxExtensionWrapper::Focus(
const v8::FunctionCallbackInfo<v8::Value>& args) {
content::RenderView* render_view = GetRenderView();
if (!render_view) return;
DVLOG(1) << render_view << " Focus";
SearchBox::Get(render_view)->Focus();
}
// static
void SearchBoxExtensionWrapper::GetAppLauncherEnabled(
const v8::FunctionCallbackInfo<v8::Value>& args) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment