12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/renderer/searchbox/searchbox_extension.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/i18n/rtl.h"
80f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "base/json/string_escape.h"
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/strings/string_number_conversions.h"
107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/strings/string_util.h"
117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/strings/stringprintf.h"
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
13b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "chrome/common/instant_types.h"
143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/common/ntp_logging_events.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/url_constants.h"
166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chrome/grit/renderer_resources.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/renderer/searchbox/searchbox.h"
1803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "components/crx_file/id_util.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/renderer/render_view.h"
20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "third_party/WebKit/public/platform/WebURLRequest.h"
217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "third_party/WebKit/public/web/WebDocument.h"
22a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "third_party/WebKit/public/web/WebLocalFrame.h"
237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "third_party/WebKit/public/web/WebScriptSource.h"
247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "third_party/WebKit/public/web/WebView.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/resource/resource_bundle.h"
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/window_open_disposition.h"
27d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/keycodes/keyboard_codes.h"
287dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/gurl.h"
29cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "url/url_constants.h"
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "v8/include/v8.h"
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kCSSBackgroundImageFormat[] = "-webkit-image-set("
3558e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch    "url(chrome-search://theme/IDR_THEME_NTP_BACKGROUND?%s) 1x, "
3658e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch    "url(chrome-search://theme/IDR_THEME_NTP_BACKGROUND@2x?%s) 2x)";
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kCSSBackgroundColorFormat[] = "rgba(%d,%d,%d,%s)";
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kCSSBackgroundPositionCenter[] = "center";
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kCSSBackgroundPositionLeft[] = "left";
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kCSSBackgroundPositionTop[] = "top";
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kCSSBackgroundPositionRight[] = "right";
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kCSSBackgroundPositionBottom[] = "bottom";
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kCSSBackgroundRepeatNo[] = "no-repeat";
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kCSSBackgroundRepeatX[] = "repeat-x";
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kCSSBackgroundRepeatY[] = "repeat-y";
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kCSSBackgroundRepeat[] = "repeat";
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5158e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdochconst char kThemeAttributionFormat[] = "-webkit-image-set("
5258e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch    "url(chrome-search://theme/IDR_THEME_NTP_ATTRIBUTION?%s) 1x, "
5358e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch    "url(chrome-search://theme/IDR_THEME_NTP_ATTRIBUTION@2x?%s) 2x)";
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kLTRHtmlTextDirection[] = "ltr";
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kRTLHtmlTextDirection[] = "rtl";
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Converts a V8 value to a string16.
59a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)base::string16 V8ValueToUTF16(v8::Handle<v8::Value> v) {
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  v8::String::Value s(v);
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return base::string16(reinterpret_cast<const base::char16*>(*s), s.length());
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Converts string16 to V8 String.
65a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)v8::Handle<v8::String> UTF16ToV8String(v8::Isolate* isolate,
66a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                       const base::string16& s) {
67a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return v8::String::NewFromTwoByte(isolate,
68a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                    reinterpret_cast<const uint16_t*>(s.data()),
69a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                    v8::String::kNormalString,
70a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                    s.size());
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Converts std::string to V8 String.
74a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)v8::Handle<v8::String> UTF8ToV8String(v8::Isolate* isolate,
75a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                      const std::string& s) {
76a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return v8::String::NewFromUtf8(
77a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      isolate, s.data(), v8::String::kNormalString, s.size());
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
80f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void Dispatch(blink::WebFrame* frame, const blink::WebString& script) {
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!frame) return;
82f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  frame->executeScript(blink::WebScriptSource(script));
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)v8::Handle<v8::String> GenerateThumbnailURL(
86a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    v8::Isolate* isolate,
87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    int render_view_id,
88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    InstantRestrictedID most_visited_item_id) {
89a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return UTF8ToV8String(
90a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      isolate,
91a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      base::StringPrintf(
92a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          "chrome-search://thumb/%d/%d", render_view_id, most_visited_item_id));
932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
95c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Populates a Javascript MostVisitedItem object from |mv_item|.
96c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// NOTE: Includes "url", "title" and "domain" which are private data, so should
97c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// not be returned to the Instant page. These should be erased before returning
98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// the object. See GetMostVisitedItemsWrapper() in searchbox_api.js.
99c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)v8::Handle<v8::Object> GenerateMostVisitedItem(
100a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    v8::Isolate* isolate,
101868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    int render_view_id,
102c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    InstantRestrictedID restricted_id,
103a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const InstantMostVisitedItem& mv_item) {
104c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // We set the "dir" attribute of the title, so that in RTL locales, a LTR
105c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // title is rendered left-to-right and truncated from the right. For
106c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // example, the title of http://msdn.microsoft.com/en-us/default.aspx is
107c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // "MSDN: Microsoft developer network". In RTL locales, in the New Tab
108c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // page, if the "dir" of this title is not specified, it takes Chrome UI's
109c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // directionality. So the title will be truncated as "soft developer
110c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // network". Setting the "dir" attribute as "ltr" renders the truncated
111c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // title as "MSDN: Microsoft D...". As another example, the title of
112c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // http://yahoo.com is "Yahoo!". In RTL locales, in the New Tab page, the
113c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // title will be rendered as "!Yahoo" if its "dir" attribute is not set to
114c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // "ltr".
115c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::string direction;
116c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (base::i18n::StringContainsStrongRTLChars(mv_item.title))
117c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    direction = kRTLHtmlTextDirection;
118c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  else
119c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    direction = kLTRHtmlTextDirection;
120c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
121a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::string16 title = mv_item.title;
122c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (title.empty())
1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    title = base::UTF8ToUTF16(mv_item.url.spec());
124c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  v8::Handle<v8::Object> obj = v8::Object::New(isolate);
126a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  obj->Set(v8::String::NewFromUtf8(isolate, "renderViewId"),
127a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)           v8::Int32::New(isolate, render_view_id));
128a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  obj->Set(v8::String::NewFromUtf8(isolate, "rid"),
129a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)           v8::Int32::New(isolate, restricted_id));
130a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  obj->Set(v8::String::NewFromUtf8(isolate, "thumbnailUrl"),
131a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)           GenerateThumbnailURL(isolate, render_view_id, restricted_id));
132a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  obj->Set(v8::String::NewFromUtf8(isolate, "title"),
133a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)           UTF16ToV8String(isolate, title));
134a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  obj->Set(v8::String::NewFromUtf8(isolate, "domain"),
135a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)           UTF8ToV8String(isolate, mv_item.url.host()));
136a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  obj->Set(v8::String::NewFromUtf8(isolate, "direction"),
137a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)           UTF8ToV8String(isolate, direction));
138a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  obj->Set(v8::String::NewFromUtf8(isolate, "url"),
139a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)           UTF8ToV8String(isolate, mv_item.url.spec()));
140c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return obj;
141c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
142c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
143c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Returns the render view for the current JS context if it matches |origin|,
144c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// otherwise returns NULL. Used to restrict methods that access suggestions and
145c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// most visited data to pages with origin chrome-search://most-visited and
146c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// chrome-search://suggestions.
147c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)content::RenderView* GetRenderViewWithCheckedOrigin(const GURL& origin) {
148a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  blink::WebLocalFrame* webframe =
149a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      blink::WebLocalFrame::frameForCurrentContext();
150c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (!webframe)
151c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return NULL;
152f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  blink::WebView* webview = webframe->view();
153c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (!webview)
154c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return NULL;  // Can happen during closing.
155c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  content::RenderView* render_view = content::RenderView::FromWebView(webview);
156c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (!render_view)
157c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return NULL;
158c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
159c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  GURL url(webframe->document().url());
160c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (url.GetOrigin() != origin.GetOrigin())
161c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return NULL;
162c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
163c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return render_view;
164c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
165c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
166b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Returns the current URL.
167b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)GURL GetCurrentURL(content::RenderView* render_view) {
168f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  blink::WebView* webview = render_view->GetWebView();
169b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  return webview ? GURL(webview->mainFrame()->document().url()) : GURL();
170b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
171b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
174c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)namespace internal {  // for testing.
175c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1767dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Returns an array with the RGBA color components.
177a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)v8::Handle<v8::Value> RGBAColorToArray(v8::Isolate* isolate,
178a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                       const RGBAColor& color) {
179a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  v8::Handle<v8::Array> color_array = v8::Array::New(isolate, 4);
180a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  color_array->Set(0, v8::Int32::New(isolate, color.r));
181a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  color_array->Set(1, v8::Int32::New(isolate, color.g));
182a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  color_array->Set(2, v8::Int32::New(isolate, color.b));
183a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  color_array->Set(3, v8::Int32::New(isolate, color.a));
1847dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  return color_array;
185c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
186c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
187b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Resolves a possibly relative URL using the current URL.
188b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)GURL ResolveURL(const GURL& current_url,
189a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                const base::string16& possibly_relative_url) {
190b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  if (current_url.is_valid() && !possibly_relative_url.empty())
191b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    return current_url.Resolve(possibly_relative_url);
192b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  return GURL(possibly_relative_url);
193b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
194b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
195c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}  // namespace internal
196c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace extensions_v8 {
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)static const char kSearchBoxExtensionName[] = "v8/EmbeddedSearch";
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// We first send this script down to determine if the page supports instant.
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static const char kSupportsInstantScript[] =
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "if (window.chrome &&"
2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    window.chrome.embeddedSearch &&"
2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    window.chrome.embeddedSearch.searchBox &&"
2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    window.chrome.embeddedSearch.searchBox.onsubmit &&"
2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    typeof window.chrome.embeddedSearch.searchBox.onsubmit =="
2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "        'function') {"
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "  true;"
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "} else {"
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "  false;"
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "}";
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)static const char kDispatchChromeIdentityCheckResult[] =
2150f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    "if (window.chrome &&"
2160f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    "    window.chrome.embeddedSearch &&"
2170f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    "    window.chrome.embeddedSearch.newTabPage &&"
2180f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    "    window.chrome.embeddedSearch.newTabPage.onsignedincheckdone &&"
2190f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    "    typeof window.chrome.embeddedSearch.newTabPage"
2200f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    "        .onsignedincheckdone === 'function') {"
2210f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    "  window.chrome.embeddedSearch.newTabPage.onsignedincheckdone(%s, %s);"
2220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    "  true;"
2230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    "}";
2240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
2250f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
2267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochstatic const char kDispatchFocusChangedScript[] =
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "if (window.chrome &&"
2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    window.chrome.embeddedSearch &&"
2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    window.chrome.embeddedSearch.searchBox &&"
2307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "    window.chrome.embeddedSearch.searchBox.onfocuschange &&"
2317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "    typeof window.chrome.embeddedSearch.searchBox.onfocuschange =="
2327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "         'function') {"
2337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "  window.chrome.embeddedSearch.searchBox.onfocuschange();"
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "  true;"
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "}";
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochstatic const char kDispatchInputCancelScript[] =
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "if (window.chrome &&"
2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    window.chrome.embeddedSearch &&"
2407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "    window.chrome.embeddedSearch.newTabPage &&"
2417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "    window.chrome.embeddedSearch.newTabPage.oninputcancel &&"
2427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "    typeof window.chrome.embeddedSearch.newTabPage.oninputcancel =="
2437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "         'function') {"
2447dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "  window.chrome.embeddedSearch.newTabPage.oninputcancel();"
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "  true;"
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "}";
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2487dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochstatic const char kDispatchInputStartScript[] =
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "if (window.chrome &&"
2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    window.chrome.embeddedSearch &&"
2517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "    window.chrome.embeddedSearch.newTabPage &&"
2527dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "    window.chrome.embeddedSearch.newTabPage.oninputstart &&"
2537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "    typeof window.chrome.embeddedSearch.newTabPage.oninputstart =="
2547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "         'function') {"
2557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "  window.chrome.embeddedSearch.newTabPage.oninputstart();"
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "  true;"
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "}";
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)static const char kDispatchKeyCaptureChangeScript[] =
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "if (window.chrome &&"
2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    window.chrome.embeddedSearch &&"
2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    window.chrome.embeddedSearch.searchBox &&"
2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    window.chrome.embeddedSearch.searchBox.onkeycapturechange &&"
2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    typeof window.chrome.embeddedSearch.searchBox.onkeycapturechange =="
2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "        'function') {"
2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "  window.chrome.embeddedSearch.searchBox.onkeycapturechange();"
2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "  true;"
2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "}";
2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)static const char kDispatchMarginChangeEventScript[] =
2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "if (window.chrome &&"
2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    window.chrome.embeddedSearch &&"
2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    window.chrome.embeddedSearch.searchBox &&"
2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    window.chrome.embeddedSearch.searchBox.onmarginchange &&"
2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    typeof window.chrome.embeddedSearch.searchBox.onmarginchange =="
2762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "        'function') {"
2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "  window.chrome.embeddedSearch.searchBox.onmarginchange();"
2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "  true;"
2792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "}";
2802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)static const char kDispatchMostVisitedChangedScript[] =
2822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "if (window.chrome &&"
2832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    window.chrome.embeddedSearch &&"
2842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    window.chrome.embeddedSearch.newTabPage &&"
2852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    window.chrome.embeddedSearch.newTabPage.onmostvisitedchange &&"
2862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "    typeof window.chrome.embeddedSearch.newTabPage.onmostvisitedchange =="
2872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "         'function') {"
2882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "  window.chrome.embeddedSearch.newTabPage.onmostvisitedchange();"
2892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "  true;"
2902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "}";
2912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2927dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochstatic const char kDispatchSubmitEventScript[] =
293868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "if (window.chrome &&"
294868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "    window.chrome.embeddedSearch &&"
295868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "    window.chrome.embeddedSearch.searchBox &&"
2967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "    window.chrome.embeddedSearch.searchBox.onsubmit &&"
2977dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "    typeof window.chrome.embeddedSearch.searchBox.onsubmit =="
2987dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "        'function') {"
2997dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "  window.chrome.embeddedSearch.searchBox.onsubmit();"
3007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    "  true;"
3017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    "}";
3027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
303424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)static const char kDispatchSuggestionChangeEventScript[] =
304424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    "if (window.chrome &&"
305424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    "    window.chrome.embeddedSearch &&"
306424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    "    window.chrome.embeddedSearch.searchBox &&"
307424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    "    window.chrome.embeddedSearch.searchBox.onsuggestionchange &&"
308424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    "    typeof window.chrome.embeddedSearch.searchBox.onsuggestionchange =="
309424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    "        'function') {"
310424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    "  window.chrome.embeddedSearch.searchBox.onsuggestionchange();"
311424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    "  true;"
312424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    "}";
313424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
3147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochstatic const char kDispatchThemeChangeEventScript[] =
3157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    "if (window.chrome &&"
3167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    "    window.chrome.embeddedSearch &&"
3177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    "    window.chrome.embeddedSearch.newTabPage &&"
3187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "    window.chrome.embeddedSearch.newTabPage.onthemechange &&"
3197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "    typeof window.chrome.embeddedSearch.newTabPage.onthemechange =="
3207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "        'function') {"
3217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    "  window.chrome.embeddedSearch.newTabPage.onthemechange();"
3227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    "  true;"
3237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    "}";
3247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
325868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)static const char kDispatchToggleVoiceSearchScript[] =
326868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "if (window.chrome &&"
327868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "    window.chrome.embeddedSearch &&"
328868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "    window.chrome.embeddedSearch.searchBox &&"
329868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "    window.chrome.embeddedSearch.searchBox.ontogglevoicesearch &&"
330868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "    typeof window.chrome.embeddedSearch.searchBox.ontogglevoicesearch =="
331868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "         'function') {"
332868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "  window.chrome.embeddedSearch.searchBox.ontogglevoicesearch();"
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "  true;"
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "}";
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ----------------------------------------------------------------------------
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SearchBoxExtensionWrapper : public v8::Extension {
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit SearchBoxExtensionWrapper(const base::StringPiece& code);
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Allows v8's javascript code to call the native functions defined
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // in this class for window.chrome.
344a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate(
345a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      v8::Isolate*,
3462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      v8::Handle<v8::String> name) OVERRIDE;
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Helper function to find the RenderView. May return NULL.
3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static content::RenderView* GetRenderView();
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3510f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Sends a Chrome identity check to the browser.
3520f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  static void CheckIsUserSignedInToChromeAs(
3530f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      const v8::FunctionCallbackInfo<v8::Value>& args);
3540f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
3552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Deletes a Most Visited item.
3567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  static void DeleteMostVisitedItem(
3577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      const v8::FunctionCallbackInfo<v8::Value>& args);
3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
359424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Focuses the omnibox.
360424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  static void Focus(const v8::FunctionCallbackInfo<v8::Value>& args);
361424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
3627dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Gets whether or not the app launcher is enabled.
3637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static void GetAppLauncherEnabled(
3647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      const v8::FunctionCallbackInfo<v8::Value>& args);
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
366a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Gets the desired navigation behavior from a click event.
367a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static void GetDispositionFromClick(
368a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      const v8::FunctionCallbackInfo<v8::Value>& args);
369a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
3702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Gets Most Visited Items.
3717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  static void GetMostVisitedItems(
3727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      const v8::FunctionCallbackInfo<v8::Value>& args);
3732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3747dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Gets the raw data for a most visited item including its raw URL.
3757dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // GetRenderViewWithCheckedOrigin() enforces that only code in the origin
3767dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // chrome-search://most-visited can call this function.
3777dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static void GetMostVisitedItemData(
3787dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    const v8::FunctionCallbackInfo<v8::Value>& args);
3797dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
3807dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Gets the submitted value of the user's search query.
3817dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static void GetQuery(const v8::FunctionCallbackInfo<v8::Value>& args);
3822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns true if the Searchbox itself is oriented right-to-left.
3847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  static void GetRightToLeft(const v8::FunctionCallbackInfo<v8::Value>& args);
3852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3867dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Gets the start-edge margin to use with extended Instant.
3877dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static void GetStartMargin(const v8::FunctionCallbackInfo<v8::Value>& args);
3882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
389424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Gets the current top suggestion to prefetch search results.
390424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  static void GetSuggestionToPrefetch(
391424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      const v8::FunctionCallbackInfo<v8::Value>& args);
392424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
3932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Gets the background info of the theme currently adopted by browser.
3942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Call only when overlay is showing NTP page.
3957d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  static void GetThemeBackgroundInfo(
3967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      const v8::FunctionCallbackInfo<v8::Value>& args);
3972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3987dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Gets whether the omnibox has focus or not.
3997dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static void IsFocused(const v8::FunctionCallbackInfo<v8::Value>& args);
4007dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
4017dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Gets whether user input is in progress.
4027dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static void IsInputInProgress(
4037dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      const v8::FunctionCallbackInfo<v8::Value>& args);
4047dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
4052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Gets whether the browser is capturing key strokes.
4067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  static void IsKeyCaptureEnabled(
4077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      const v8::FunctionCallbackInfo<v8::Value>& args);
4082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4097dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Logs information from the iframes/titles on the NTP.
4107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static void LogEvent(const v8::FunctionCallbackInfo<v8::Value>& args);
411eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
4125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Logs an impression on one of the Most Visited tile on the NTP.
413a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static void LogMostVisitedImpression(
414a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      const v8::FunctionCallbackInfo<v8::Value>& args);
415a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
416a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Logs a navigation on one of the Most Visited tile on the NTP.
417a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static void LogMostVisitedNavigation(
418a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      const v8::FunctionCallbackInfo<v8::Value>& args);
4195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Navigates the window to a URL represented by either a URL string or a
4217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // restricted ID.
4227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  static void NavigateContentWindow(
4237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      const v8::FunctionCallbackInfo<v8::Value>& args);
4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
425ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // Pastes provided value or clipboard's content into the omnibox.
426ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  static void Paste(const v8::FunctionCallbackInfo<v8::Value>& args);
427ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
428eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Indicates whether the page supports voice search.
429eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  static void SetVoiceSearchSupported(
430eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      const v8::FunctionCallbackInfo<v8::Value>& args);
431eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
4322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Start capturing user key strokes.
4337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  static void StartCapturingKeyStrokes(
4347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      const v8::FunctionCallbackInfo<v8::Value>& args);
4352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Stop capturing user key strokes.
4377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  static void StopCapturingKeyStrokes(
4387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      const v8::FunctionCallbackInfo<v8::Value>& args);
4392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Undoes the deletion of all Most Visited itens.
4417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  static void UndoAllMostVisitedDeletions(
4427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      const v8::FunctionCallbackInfo<v8::Value>& args);
4432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Undoes the deletion of a Most Visited item.
4457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  static void UndoMostVisitedDeletion(
4467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      const v8::FunctionCallbackInfo<v8::Value>& args);
4472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
448424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Indicates whether the page supports Instant.
449424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  static void GetDisplayInstantResults(
450424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      const v8::FunctionCallbackInfo<v8::Value>& args);
451424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
4527dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch private:
4537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper);
4547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch};
4552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// static
4577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochv8::Extension* SearchBoxExtension::Get() {
4587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance().
4597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      GetRawDataResource(IDR_SEARCHBOX_API));
4607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4627dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// static
463f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)bool SearchBoxExtension::PageSupportsInstant(blink::WebFrame* frame) {
4647dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  if (!frame) return false;
46558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
4667dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  v8::Handle<v8::Value> v = frame->executeScriptAndReturnValue(
467f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      blink::WebScriptSource(kSupportsInstantScript));
4687dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  return !v.IsEmpty() && v->BooleanValue();
4697dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
470c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
4717dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// static
4720f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)void SearchBoxExtension::DispatchChromeIdentityCheckResult(
473a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    blink::WebFrame* frame,
474a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const base::string16& identity,
475a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    bool identity_match) {
4765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string escaped_identity = base::GetQuotedJSONString(identity);
4775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  blink::WebString script(base::UTF8ToUTF16(base::StringPrintf(
4780f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      kDispatchChromeIdentityCheckResult,
4790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      escaped_identity.c_str(),
4800f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      identity_match ? "true" : "false")));
4810f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Dispatch(frame, script);
4820f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)}
4830f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
4840f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// static
485f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void SearchBoxExtension::DispatchFocusChange(blink::WebFrame* frame) {
4867dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  Dispatch(frame, kDispatchFocusChangedScript);
4877dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
488c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
4897dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// static
490f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void SearchBoxExtension::DispatchInputCancel(blink::WebFrame* frame) {
4917dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  Dispatch(frame, kDispatchInputCancelScript);
4927dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
4937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
4947dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// static
495f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void SearchBoxExtension::DispatchInputStart(blink::WebFrame* frame) {
4967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  Dispatch(frame, kDispatchInputStartScript);
4977dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
498868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
4997dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// static
500f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void SearchBoxExtension::DispatchKeyCaptureChange(blink::WebFrame* frame) {
5017dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  Dispatch(frame, kDispatchKeyCaptureChangeScript);
5027dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
5037dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
5047dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// static
505f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void SearchBoxExtension::DispatchMarginChange(blink::WebFrame* frame) {
5067dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  Dispatch(frame, kDispatchMarginChangeEventScript);
5077dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
5087dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
5097dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// static
5107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid SearchBoxExtension::DispatchMostVisitedChanged(
511f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    blink::WebFrame* frame) {
5127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  Dispatch(frame, kDispatchMostVisitedChangedScript);
5137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
5147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
5157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// static
516f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void SearchBoxExtension::DispatchSubmit(blink::WebFrame* frame) {
5177dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  Dispatch(frame, kDispatchSubmitEventScript);
5187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
5197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
5207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// static
521f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void SearchBoxExtension::DispatchSuggestionChange(blink::WebFrame* frame) {
522424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  Dispatch(frame, kDispatchSuggestionChangeEventScript);
523424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)}
524424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
525424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// static
526f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void SearchBoxExtension::DispatchThemeChange(blink::WebFrame* frame) {
5277dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  Dispatch(frame, kDispatchThemeChangeEventScript);
5287dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
5297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
5307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// static
5317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid SearchBoxExtension::DispatchToggleVoiceSearch(
532f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    blink::WebFrame* frame) {
5337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  Dispatch(frame, kDispatchToggleVoiceSearchScript);
5347dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)SearchBoxExtensionWrapper::SearchBoxExtensionWrapper(
5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const base::StringPiece& code)
5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) {
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
541a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)v8::Handle<v8::FunctionTemplate>
542a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)SearchBoxExtensionWrapper::GetNativeFunctionTemplate(
543a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    v8::Isolate* isolate,
5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    v8::Handle<v8::String> name) {
545a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(
546a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          v8::String::NewFromUtf8(isolate, "CheckIsUserSignedInToChromeAs")))
547a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, CheckIsUserSignedInToChromeAs);
548a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "DeleteMostVisitedItem")))
549a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, DeleteMostVisitedItem);
550a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "Focus")))
551a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, Focus);
552a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "GetAppLauncherEnabled")))
553a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, GetAppLauncherEnabled);
554a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "GetDispositionFromClick")))
555a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, GetDispositionFromClick);
556a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItems")))
557a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, GetMostVisitedItems);
558a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItemData")))
559a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, GetMostVisitedItemData);
560a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "GetQuery")))
561a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, GetQuery);
562a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "GetRightToLeft")))
563a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, GetRightToLeft);
564a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "GetStartMargin")))
565a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, GetStartMargin);
566a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "GetSuggestionToPrefetch")))
567a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, GetSuggestionToPrefetch);
568a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "GetThemeBackgroundInfo")))
569a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, GetThemeBackgroundInfo);
570a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "IsFocused")))
571a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, IsFocused);
572a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "IsInputInProgress")))
573a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, IsInputInProgress);
574a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "IsKeyCaptureEnabled")))
575a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, IsKeyCaptureEnabled);
576a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "LogEvent")))
577a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, LogEvent);
578a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (name->Equals(
579a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)          v8::String::NewFromUtf8(isolate, "LogMostVisitedImpression"))) {
580a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, LogMostVisitedImpression);
581a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
582a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (name->Equals(
583a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)          v8::String::NewFromUtf8(isolate, "LogMostVisitedNavigation"))) {
584a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, LogMostVisitedNavigation);
585a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
586a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "NavigateContentWindow")))
587a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, NavigateContentWindow);
588a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "Paste")))
589a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, Paste);
590a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "SetVoiceSearchSupported")))
591a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, SetVoiceSearchSupported);
592a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(
593a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          v8::String::NewFromUtf8(isolate, "StartCapturingKeyStrokes")))
594a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, StartCapturingKeyStrokes);
595a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "StopCapturingKeyStrokes")))
596a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, StopCapturingKeyStrokes);
597a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(
598a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          v8::String::NewFromUtf8(isolate, "UndoAllMostVisitedDeletions")))
599a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, UndoAllMostVisitedDeletions);
600a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(v8::String::NewFromUtf8(isolate, "UndoMostVisitedDeletion")))
601a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, UndoMostVisitedDeletion);
602a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (name->Equals(
603a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          v8::String::NewFromUtf8(isolate, "GetDisplayInstantResults")))
604a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return v8::FunctionTemplate::New(isolate, GetDisplayInstantResults);
6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return v8::Handle<v8::FunctionTemplate>();
6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)content::RenderView* SearchBoxExtensionWrapper::GetRenderView() {
610a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  blink::WebLocalFrame* webframe =
611a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      blink::WebLocalFrame::frameForCurrentContext();
6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!webframe) return NULL;
6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
614f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  blink::WebView* webview = webframe->view();
6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!webview) return NULL;  // can happen during closing
6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return content::RenderView::FromWebView(webview);
6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
6210f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)void SearchBoxExtensionWrapper::CheckIsUserSignedInToChromeAs(
6220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
6230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  content::RenderView* render_view = GetRenderView();
6240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  if (!render_view || args.Length() == 0 || args[0]->IsUndefined()) return;
6250f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
6260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  DVLOG(1) << render_view << " CheckIsUserSignedInToChromeAs";
6270f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
6280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  SearchBox::Get(render_view)->CheckIsUserSignedInToChromeAs(
6290f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      V8ValueToUTF16(args[0]));
6300f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)}
6310f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
6320f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// static
6337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid SearchBoxExtensionWrapper::DeleteMostVisitedItem(
6347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::RenderView* render_view = GetRenderView();
6367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  if (!render_view || !args.Length()) return;
637c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
6387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  DVLOG(1) << render_view << " DeleteMostVisitedItem";
6397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  SearchBox::Get(render_view)->DeleteMostVisitedItem(args[0]->IntegerValue());
6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
643424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void SearchBoxExtensionWrapper::Focus(
644424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
645424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  content::RenderView* render_view = GetRenderView();
646424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  if (!render_view) return;
647424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
648424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  DVLOG(1) << render_view << " Focus";
649424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  SearchBox::Get(render_view)->Focus();
650424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)}
651424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
652424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// static
6537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid SearchBoxExtensionWrapper::GetAppLauncherEnabled(
6547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::RenderView* render_view = GetRenderView();
6567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!render_view) return;
6572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  args.GetReturnValue().Set(
6597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      SearchBox::Get(render_view)->app_launcher_enabled());
6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
663a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SearchBoxExtensionWrapper::GetDispositionFromClick(
664a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
665a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  content::RenderView* render_view = GetRenderView();
666a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!render_view || args.Length() != 5) return;
667a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
668a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool middle_button = args[0]->BooleanValue();
669a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool alt_key = args[1]->BooleanValue();
670a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool ctrl_key = args[2]->BooleanValue();
671a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool meta_key = args[3]->BooleanValue();
672a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool shift_key = args[4]->BooleanValue();
673a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
674a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  WindowOpenDisposition disposition = ui::DispositionFromClick(middle_button,
675a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                                                               alt_key,
676a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                                                               ctrl_key,
677a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                                                               meta_key,
678a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                                                               shift_key);
679a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  v8::Isolate* isolate = args.GetIsolate();
680a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  args.GetReturnValue().Set(v8::Int32::New(isolate, disposition));
681a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
682a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
683a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// static
6847dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid SearchBoxExtensionWrapper::GetMostVisitedItems(
6857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::RenderView* render_view = GetRenderView();
6877dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  if (!render_view)
6887dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    return;
6897dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  DVLOG(1) << render_view << " GetMostVisitedItems";
6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6917dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  const SearchBox* search_box = SearchBox::Get(render_view);
6922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6937dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  std::vector<InstantMostVisitedItemIDPair> instant_mv_items;
6947dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  search_box->GetMostVisitedItems(&instant_mv_items);
695a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  v8::Isolate* isolate = args.GetIsolate();
696a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  v8::Handle<v8::Array> v8_mv_items =
697a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      v8::Array::New(isolate, instant_mv_items.size());
6987dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  for (size_t i = 0; i < instant_mv_items.size(); ++i) {
699a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    v8_mv_items->Set(i,
700a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                     GenerateMostVisitedItem(isolate,
701a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                             render_view->GetRoutingID(),
702a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                             instant_mv_items[i].first,
703a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                             instant_mv_items[i].second));
7047dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
7057dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  args.GetReturnValue().Set(v8_mv_items);
7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
7097dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid SearchBoxExtensionWrapper::GetMostVisitedItemData(
7107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
7117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  content::RenderView* render_view = GetRenderViewWithCheckedOrigin(
7127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      GURL(chrome::kChromeSearchMostVisitedUrl));
7137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!render_view) return;
7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Need an rid argument.
7167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  if (args.Length() < 1 || !args[0]->IsNumber())
7177dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    return;
7182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  DVLOG(1) << render_view << " GetMostVisitedItem";
7207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  InstantRestrictedID restricted_id = args[0]->IntegerValue();
7217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  InstantMostVisitedItem mv_item;
7227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  if (!SearchBox::Get(render_view)->GetMostVisitedItemWithID(
7237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch          restricted_id, &mv_item)) {
7247dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    return;
7257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
726a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  v8::Isolate* isolate = args.GetIsolate();
727a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  args.GetReturnValue().Set(GenerateMostVisitedItem(
728a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      isolate, render_view->GetRoutingID(), restricted_id, mv_item));
7292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// static
7327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid SearchBoxExtensionWrapper::GetQuery(
7337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
7342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::RenderView* render_view = GetRenderView();
7357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!render_view) return;
736a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  const base::string16& query = SearchBox::Get(render_view)->query();
7377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  DVLOG(1) << render_view << " GetQuery: '" << query << "'";
738a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  v8::Isolate* isolate = args.GetIsolate();
739a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  args.GetReturnValue().Set(UTF16ToV8String(isolate, query));
7402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// static
7437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void SearchBoxExtensionWrapper::GetRightToLeft(
7447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
7457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  args.GetReturnValue().Set(base::i18n::IsRTL());
7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
7497dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid SearchBoxExtensionWrapper::GetStartMargin(
7507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::RenderView* render_view = GetRenderView();
7527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!render_view) return;
7537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  args.GetReturnValue().Set(static_cast<int32_t>(
754ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      SearchBox::Get(render_view)->start_margin()));
7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
758424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void SearchBoxExtensionWrapper::GetSuggestionToPrefetch(
759424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
760424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  content::RenderView* render_view = GetRenderView();
761424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  if (!render_view) return;
762424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
763424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  const InstantSuggestion& suggestion =
764424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      SearchBox::Get(render_view)->suggestion();
765a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  v8::Isolate* isolate = args.GetIsolate();
7665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  v8::Handle<v8::Object> data = v8::Object::New(isolate);
767a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  data->Set(v8::String::NewFromUtf8(isolate, "text"),
768a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)            UTF16ToV8String(isolate, suggestion.text));
769a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  data->Set(v8::String::NewFromUtf8(isolate, "metadata"),
770a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)            UTF8ToV8String(isolate, suggestion.metadata));
771424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  args.GetReturnValue().Set(data);
772424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)}
773424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
774424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// static
7757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void SearchBoxExtensionWrapper::GetThemeBackgroundInfo(
7767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
7772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::RenderView* render_view = GetRenderView();
7787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!render_view) return;
7792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DVLOG(1) << render_view << " GetThemeBackgroundInfo";
7812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const ThemeBackgroundInfo& theme_info =
7822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      SearchBox::Get(render_view)->GetThemeBackgroundInfo();
783a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  v8::Isolate* isolate = args.GetIsolate();
7845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  v8::Handle<v8::Object> info = v8::Object::New(isolate);
7852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
786a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  info->Set(v8::String::NewFromUtf8(isolate, "usingDefaultTheme"),
787a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)            v8::Boolean::New(isolate, theme_info.using_default_theme));
7887dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
7892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The theme background color is in RGBA format "rgba(R,G,B,A)" where R, G and
7902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // B are between 0 and 255 inclusive, and A is a double between 0 and 1
7912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // inclusive.
7922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This is the CSS "background-color" format.
7932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Value is always valid.
7947dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // TODO(jfweitz): Remove this field after GWS is modified to use the new
7957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // backgroundColorRgba field.
796a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  info->Set(
797a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      v8::String::NewFromUtf8(isolate, "colorRgba"),
798a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      UTF8ToV8String(
799a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          isolate,
800a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          // Convert the alpha using DoubleToString because StringPrintf will
801a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          // use
802a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          // locale specific formatters (e.g., use , instead of . in German).
803a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          base::StringPrintf(
804a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)              kCSSBackgroundColorFormat,
805a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)              theme_info.background_color.r,
806a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)              theme_info.background_color.g,
807a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)              theme_info.background_color.b,
808a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)              base::DoubleToString(theme_info.background_color.a / 255.0)
809a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                  .c_str())));
8107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
8117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Theme color for background as an array with the RGBA components in order.
8127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Value is always valid.
813a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  info->Set(v8::String::NewFromUtf8(isolate, "backgroundColorRgba"),
814a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)            internal::RGBAColorToArray(isolate, theme_info.background_color));
8157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
8167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Theme color for text as an array with the RGBA components in order.
8177dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Value is always valid.
818a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  info->Set(v8::String::NewFromUtf8(isolate, "textColorRgba"),
819a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)            internal::RGBAColorToArray(isolate, theme_info.text_color));
8207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
8217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Theme color for links as an array with the RGBA components in order.
8227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Value is always valid.
823a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  info->Set(v8::String::NewFromUtf8(isolate, "linkColorRgba"),
824a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)            internal::RGBAColorToArray(isolate, theme_info.link_color));
8257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
8267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Theme color for light text as an array with the RGBA components in order.
8277dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Value is always valid.
828a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  info->Set(v8::String::NewFromUtf8(isolate, "textColorLightRgba"),
829a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)            internal::RGBAColorToArray(isolate, theme_info.text_color_light));
8307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
8317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Theme color for header as an array with the RGBA components in order.
8327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Value is always valid.
833a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  info->Set(v8::String::NewFromUtf8(isolate, "headerColorRgba"),
834a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)            internal::RGBAColorToArray(isolate, theme_info.header_color));
8357dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
8367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Theme color for section border as an array with the RGBA components in
8377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // order. Value is always valid.
838a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  info->Set(
839a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      v8::String::NewFromUtf8(isolate, "sectionBorderColorRgba"),
840a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      internal::RGBAColorToArray(isolate, theme_info.section_border_color));
8417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
8427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // The theme alternate logo value indicates a white logo when TRUE and a
8437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // colorful one when FALSE.
844a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  info->Set(v8::String::NewFromUtf8(isolate, "alternateLogo"),
845a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)            v8::Boolean::New(isolate, theme_info.logo_alternate));
8462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
84758e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  // The theme background image url is of format kCSSBackgroundImageFormat
84858e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  // where both instances of "%s" are replaced with the id that identifies the
84958e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  // theme.
8502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This is the CSS "background-image" format.
8512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Value is only valid if there's a custom theme background image.
85203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  if (crx_file::id_util::IdIsValid(theme_info.theme_id)) {
853a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    info->Set(v8::String::NewFromUtf8(isolate, "imageUrl"),
854a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)              UTF8ToV8String(isolate,
855a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                             base::StringPrintf(kCSSBackgroundImageFormat,
856a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                                theme_info.theme_id.c_str(),
857a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                                theme_info.theme_id.c_str())));
8582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // The theme background image horizontal alignment is one of "left",
8602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // "right", "center".
8612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // This is the horizontal component of the CSS "background-position" format.
8622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Value is only valid if |imageUrl| is not empty.
8632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    std::string alignment = kCSSBackgroundPositionCenter;
8642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (theme_info.image_horizontal_alignment ==
8652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            THEME_BKGRND_IMAGE_ALIGN_LEFT) {
8662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      alignment = kCSSBackgroundPositionLeft;
8672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    } else if (theme_info.image_horizontal_alignment ==
8682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                   THEME_BKGRND_IMAGE_ALIGN_RIGHT) {
8692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      alignment = kCSSBackgroundPositionRight;
8702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
871a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    info->Set(v8::String::NewFromUtf8(isolate, "imageHorizontalAlignment"),
872a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)              UTF8ToV8String(isolate, alignment));
8732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // The theme background image vertical alignment is one of "top", "bottom",
8752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // "center".
8762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // This is the vertical component of the CSS "background-position" format.
8772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Value is only valid if |image_url| is not empty.
8782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (theme_info.image_vertical_alignment == THEME_BKGRND_IMAGE_ALIGN_TOP) {
8792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      alignment = kCSSBackgroundPositionTop;
8802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    } else if (theme_info.image_vertical_alignment ==
8812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                   THEME_BKGRND_IMAGE_ALIGN_BOTTOM) {
8822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      alignment = kCSSBackgroundPositionBottom;
8832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    } else {
8842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      alignment = kCSSBackgroundPositionCenter;
8852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
886a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    info->Set(v8::String::NewFromUtf8(isolate, "imageVerticalAlignment"),
887a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)              UTF8ToV8String(isolate, alignment));
8882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // The tiling of the theme background image is one of "no-repeat",
8902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // "repeat-x", "repeat-y", "repeat".
8912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // This is the CSS "background-repeat" format.
8922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Value is only valid if |image_url| is not empty.
8932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    std::string tiling = kCSSBackgroundRepeatNo;
8942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    switch (theme_info.image_tiling) {
8952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      case THEME_BKGRND_IMAGE_NO_REPEAT:
8962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        tiling = kCSSBackgroundRepeatNo;
8972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        break;
8982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      case THEME_BKGRND_IMAGE_REPEAT_X:
8992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        tiling = kCSSBackgroundRepeatX;
9002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        break;
9012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      case THEME_BKGRND_IMAGE_REPEAT_Y:
9022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        tiling = kCSSBackgroundRepeatY;
9032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        break;
9042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      case THEME_BKGRND_IMAGE_REPEAT:
9052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        tiling = kCSSBackgroundRepeat;
9062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        break;
9072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
908a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    info->Set(v8::String::NewFromUtf8(isolate, "imageTiling"),
909a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)              UTF8ToV8String(isolate, tiling));
9102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // The theme background image height is only valid if |imageUrl| is valid.
912a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    info->Set(v8::String::NewFromUtf8(isolate, "imageHeight"),
913a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)              v8::Int32::New(isolate, theme_info.image_height));
9142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // The attribution URL is only valid if the theme has attribution logo.
9162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (theme_info.has_attribution) {
917a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      info->Set(
918a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          v8::String::NewFromUtf8(isolate, "attributionUrl"),
919a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          UTF8ToV8String(isolate,
920a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                         base::StringPrintf(kThemeAttributionFormat,
921a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                            theme_info.theme_id.c_str(),
922a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                            theme_info.theme_id.c_str())));
9232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
9242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
9252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  args.GetReturnValue().Set(info);
9272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
9282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// static
9307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid SearchBoxExtensionWrapper::IsFocused(
9317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
9322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::RenderView* render_view = GetRenderView();
9337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!render_view) return;
9342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9357dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  bool is_focused = SearchBox::Get(render_view)->is_focused();
9367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  DVLOG(1) << render_view << " IsFocused: " << is_focused;
9377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  args.GetReturnValue().Set(is_focused);
9382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
9392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// static
9417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid SearchBoxExtensionWrapper::IsInputInProgress(
9427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
9432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::RenderView* render_view = GetRenderView();
9447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!render_view) return;
9452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  bool is_input_in_progress =
9477dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      SearchBox::Get(render_view)->is_input_in_progress();
9487dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  DVLOG(1) << render_view << " IsInputInProgress: " << is_input_in_progress;
9497dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  args.GetReturnValue().Set(is_input_in_progress);
9502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
9512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// static
9537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid SearchBoxExtensionWrapper::IsKeyCaptureEnabled(
954eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    const v8::FunctionCallbackInfo<v8::Value>& args) {
955eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  content::RenderView* render_view = GetRenderView();
956eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (!render_view) return;
957eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
9587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  args.GetReturnValue().Set(SearchBox::Get(render_view)->
9597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                            is_key_capture_enabled());
960eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
961eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
962eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// static
9637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid SearchBoxExtensionWrapper::LogEvent(
9647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
9657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  content::RenderView* render_view = GetRenderViewWithCheckedOrigin(
9667dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      GURL(chrome::kChromeSearchMostVisitedUrl));
9677dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  if (!render_view) return;
9685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  if (args.Length() < 1 || !args[0]->IsNumber())
9707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    return;
9712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9727dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  DVLOG(1) << render_view << " LogEvent";
9732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  if (args[0]->Uint32Value() < NTP_NUM_EVENT_TYPES) {
9753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    NTPLoggingEventType event =
9763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)        static_cast<NTPLoggingEventType>(args[0]->Uint32Value());
9773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    SearchBox::Get(render_view)->LogEvent(event);
9783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  }
9795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
982a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SearchBoxExtensionWrapper::LogMostVisitedImpression(
983a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
984a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  content::RenderView* render_view = GetRenderViewWithCheckedOrigin(
985a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      GURL(chrome::kChromeSearchMostVisitedUrl));
986a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!render_view) return;
987a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
988a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (args.Length() < 2 || !args[0]->IsNumber() || args[1]->IsUndefined())
989a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
990a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
991a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  DVLOG(1) << render_view << " LogMostVisitedImpression";
992a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
993a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  SearchBox::Get(render_view)->LogMostVisitedImpression(
994a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      args[0]->IntegerValue(), V8ValueToUTF16(args[1]));
995a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
996a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
997a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// static
998a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SearchBoxExtensionWrapper::LogMostVisitedNavigation(
9995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
10005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RenderView* render_view = GetRenderViewWithCheckedOrigin(
10015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      GURL(chrome::kChromeSearchMostVisitedUrl));
10025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!render_view) return;
10035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
10045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (args.Length() < 2 || !args[0]->IsNumber() || args[1]->IsUndefined())
10055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
10065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1007a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  DVLOG(1) << render_view << " LogMostVisitedNavigation";
10085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1009a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  SearchBox::Get(render_view)->LogMostVisitedNavigation(
1010a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      args[0]->IntegerValue(), V8ValueToUTF16(args[1]));
10115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
10125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
10135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// static
10147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid SearchBoxExtensionWrapper::NavigateContentWindow(
10157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
10162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::RenderView* render_view = GetRenderView();
10177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!render_view || !args.Length()) return;
10182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  GURL destination_url;
10201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  bool is_most_visited_item_url = false;
10219ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch  // Check if the url is a rid
10229ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch  if (args[0]->IsNumber()) {
10239ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch    InstantMostVisitedItem item;
10249ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch    if (SearchBox::Get(render_view)->GetMostVisitedItemWithID(
10251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)            args[0]->IntegerValue(), &item)) {
10269ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch      destination_url = item.url;
10271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      is_most_visited_item_url = true;
10289ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch    }
10299ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch  } else {
10309ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch    // Resolve the URL
1031a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const base::string16& possibly_relative_url = V8ValueToUTF16(args[0]);
1032a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GURL current_url = GetCurrentURL(render_view);
10339ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch    destination_url = internal::ResolveURL(current_url, possibly_relative_url);
10349ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch  }
10359ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch
10367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  DVLOG(1) << render_view << " NavigateContentWindow: " << destination_url;
10372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Navigate the main frame.
1039a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (destination_url.is_valid() &&
1040cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      !destination_url.SchemeIs(url::kJavaScriptScheme)) {
10412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    WindowOpenDisposition disposition = CURRENT_TAB;
1042a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    if (args[1]->IsNumber()) {
1043a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      disposition = (WindowOpenDisposition) args[1]->Uint32Value();
1044a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    }
10451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    SearchBox::Get(render_view)->NavigateToURL(destination_url, disposition,
10461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                               is_most_visited_item_url);
10472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
10482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
10492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// static
1051ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochvoid SearchBoxExtensionWrapper::Paste(
1052ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    const v8::FunctionCallbackInfo<v8::Value>& args) {
1053ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  content::RenderView* render_view = GetRenderView();
1054ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  if (!render_view) return;
1055ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
1056a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::string16 text;
1057ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  if (!args[0]->IsUndefined())
1058ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    text = V8ValueToUTF16(args[0]);
1059ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
1060ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  DVLOG(1) << render_view << " Paste: " << text;
1061ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  SearchBox::Get(render_view)->Paste(text);
1062ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch}
1063ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
1064ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// static
10657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void SearchBoxExtensionWrapper::StartCapturingKeyStrokes(
10667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
10672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::RenderView* render_view = GetRenderView();
10687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!render_view) return;
10692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DVLOG(1) << render_view << " StartCapturingKeyStrokes";
10712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SearchBox::Get(render_view)->StartCapturingKeyStrokes();
10722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
10732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// static
10757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void SearchBoxExtensionWrapper::StopCapturingKeyStrokes(
10767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
10772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::RenderView* render_view = GetRenderView();
10787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!render_view) return;
10792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DVLOG(1) << render_view << " StopCapturingKeyStrokes";
10812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SearchBox::Get(render_view)->StopCapturingKeyStrokes();
10822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
10832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// static
10857dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid SearchBoxExtensionWrapper::SetVoiceSearchSupported(
10867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
10872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::RenderView* render_view = GetRenderView();
10887dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  if (!render_view || args.Length() < 1) return;
1089c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
10907dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  DVLOG(1) << render_view << " SetVoiceSearchSupported";
10917dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  SearchBox::Get(render_view)->SetVoiceSearchSupported(args[0]->BooleanValue());
1092868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
1093868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1094868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// static
10957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid SearchBoxExtensionWrapper::UndoAllMostVisitedDeletions(
10967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
1097868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  content::RenderView* render_view = GetRenderView();
10987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!render_view) return;
1099868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
11007dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  DVLOG(1) << render_view << " UndoAllMostVisitedDeletions";
11017dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  SearchBox::Get(render_view)->UndoAllMostVisitedDeletions();
11027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
11037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
11047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// static
11057dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid SearchBoxExtensionWrapper::UndoMostVisitedDeletion(
11067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
11077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  content::RenderView* render_view = GetRenderView();
11087dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  if (!render_view || !args.Length()) return;
11097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
11107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  DVLOG(1) << render_view << " UndoMostVisitedDeletion";
11117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  SearchBox::Get(render_view)->UndoMostVisitedDeletion(args[0]->IntegerValue());
1112868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
1113868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1114424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// static
1115424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void SearchBoxExtensionWrapper::GetDisplayInstantResults(
1116424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    const v8::FunctionCallbackInfo<v8::Value>& args) {
1117424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  content::RenderView* render_view = GetRenderView();
1118424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  if (!render_view) return;
1119424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
1120424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  bool display_instant_results =
1121424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      SearchBox::Get(render_view)->display_instant_results();
1122424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  DVLOG(1) << render_view << " GetDisplayInstantResults" <<
1123424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      display_instant_results;
1124424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  args.GetReturnValue().Set(display_instant_results);
1125424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)}
1126424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
11275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace extensions_v8
1128