1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/renderer/searchbox/searchbox_extension.h"
7 #include "base/i18n/rtl.h"
8 #include "base/json/string_escape.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/common/instant_types.h"
14 #include "chrome/common/ntp_logging_events.h"
15 #include "chrome/common/url_constants.h"
16 #include "chrome/grit/renderer_resources.h"
17 #include "chrome/renderer/searchbox/searchbox.h"
18 #include "components/crx_file/id_util.h"
19 #include "content/public/renderer/render_view.h"
20 #include "third_party/WebKit/public/platform/WebURLRequest.h"
21 #include "third_party/WebKit/public/web/WebDocument.h"
22 #include "third_party/WebKit/public/web/WebLocalFrame.h"
23 #include "third_party/WebKit/public/web/WebScriptSource.h"
24 #include "third_party/WebKit/public/web/WebView.h"
25 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/base/window_open_disposition.h"
27 #include "ui/events/keycodes/keyboard_codes.h"
29 #include "url/url_constants.h"
30 #include "v8/include/v8.h"
34 const char kCSSBackgroundImageFormat
[] = "-webkit-image-set("
35 "url(chrome-search://theme/IDR_THEME_NTP_BACKGROUND?%s) 1x, "
36 "url(chrome-search://theme/IDR_THEME_NTP_BACKGROUND@2x?%s) 2x)";
38 const char kCSSBackgroundColorFormat
[] = "rgba(%d,%d,%d,%s)";
40 const char kCSSBackgroundPositionCenter
[] = "center";
41 const char kCSSBackgroundPositionLeft
[] = "left";
42 const char kCSSBackgroundPositionTop
[] = "top";
43 const char kCSSBackgroundPositionRight
[] = "right";
44 const char kCSSBackgroundPositionBottom
[] = "bottom";
46 const char kCSSBackgroundRepeatNo
[] = "no-repeat";
47 const char kCSSBackgroundRepeatX
[] = "repeat-x";
48 const char kCSSBackgroundRepeatY
[] = "repeat-y";
49 const char kCSSBackgroundRepeat
[] = "repeat";
51 const char kThemeAttributionFormat
[] = "-webkit-image-set("
52 "url(chrome-search://theme/IDR_THEME_NTP_ATTRIBUTION?%s) 1x, "
53 "url(chrome-search://theme/IDR_THEME_NTP_ATTRIBUTION@2x?%s) 2x)";
55 const char kLTRHtmlTextDirection
[] = "ltr";
56 const char kRTLHtmlTextDirection
[] = "rtl";
58 // Converts a V8 value to a string16.
59 base::string16
V8ValueToUTF16(v8::Handle
<v8::Value
> v
) {
60 v8::String::Value
s(v
);
61 return base::string16(reinterpret_cast<const base::char16
*>(*s
), s
.length());
64 // Converts string16 to V8 String.
65 v8::Handle
<v8::String
> UTF16ToV8String(v8::Isolate
* isolate
,
66 const base::string16
& s
) {
67 return v8::String::NewFromTwoByte(isolate
,
68 reinterpret_cast<const uint16_t*>(s
.data()),
69 v8::String::kNormalString
,
73 // Converts std::string to V8 String.
74 v8::Handle
<v8::String
> UTF8ToV8String(v8::Isolate
* isolate
,
75 const std::string
& s
) {
76 return v8::String::NewFromUtf8(
77 isolate
, s
.data(), v8::String::kNormalString
, s
.size());
80 void Dispatch(blink::WebFrame
* frame
, const blink::WebString
& script
) {
82 frame
->executeScript(blink::WebScriptSource(script
));
85 v8::Handle
<v8::String
> GenerateThumbnailURL(
88 InstantRestrictedID most_visited_item_id
) {
89 return UTF8ToV8String(
92 "chrome-search://thumb/%d/%d", render_view_id
, most_visited_item_id
));
95 // Populates a Javascript MostVisitedItem object from |mv_item|.
96 // NOTE: Includes "url", "title" and "domain" which are private data, so should
97 // not be returned to the Instant page. These should be erased before returning
98 // the object. See GetMostVisitedItemsWrapper() in searchbox_api.js.
99 v8::Handle
<v8::Object
> GenerateMostVisitedItem(
100 v8::Isolate
* isolate
,
102 InstantRestrictedID restricted_id
,
103 const InstantMostVisitedItem
& mv_item
) {
104 // We set the "dir" attribute of the title, so that in RTL locales, a LTR
105 // title is rendered left-to-right and truncated from the right. For
106 // example, the title of http://msdn.microsoft.com/en-us/default.aspx is
107 // "MSDN: Microsoft developer network". In RTL locales, in the New Tab
108 // page, if the "dir" of this title is not specified, it takes Chrome UI's
109 // directionality. So the title will be truncated as "soft developer
110 // network". Setting the "dir" attribute as "ltr" renders the truncated
111 // title as "MSDN: Microsoft D...". As another example, the title of
112 // http://yahoo.com is "Yahoo!". In RTL locales, in the New Tab page, the
113 // title will be rendered as "!Yahoo" if its "dir" attribute is not set to
115 std::string direction
;
116 if (base::i18n::StringContainsStrongRTLChars(mv_item
.title
))
117 direction
= kRTLHtmlTextDirection
;
119 direction
= kLTRHtmlTextDirection
;
121 base::string16 title
= mv_item
.title
;
123 title
= base::UTF8ToUTF16(mv_item
.url
.spec());
125 v8::Handle
<v8::Object
> obj
= v8::Object::New(isolate
);
126 obj
->Set(v8::String::NewFromUtf8(isolate
, "renderViewId"),
127 v8::Int32::New(isolate
, render_view_id
));
128 obj
->Set(v8::String::NewFromUtf8(isolate
, "rid"),
129 v8::Int32::New(isolate
, restricted_id
));
130 obj
->Set(v8::String::NewFromUtf8(isolate
, "thumbnailUrl"),
131 GenerateThumbnailURL(isolate
, render_view_id
, restricted_id
));
132 obj
->Set(v8::String::NewFromUtf8(isolate
, "title"),
133 UTF16ToV8String(isolate
, title
));
134 obj
->Set(v8::String::NewFromUtf8(isolate
, "domain"),
135 UTF8ToV8String(isolate
, mv_item
.url
.host()));
136 obj
->Set(v8::String::NewFromUtf8(isolate
, "direction"),
137 UTF8ToV8String(isolate
, direction
));
138 obj
->Set(v8::String::NewFromUtf8(isolate
, "url"),
139 UTF8ToV8String(isolate
, mv_item
.url
.spec()));
143 // Returns the render view for the current JS context if it matches |origin|,
144 // otherwise returns NULL. Used to restrict methods that access suggestions and
145 // most visited data to pages with origin chrome-search://most-visited and
146 // chrome-search://suggestions.
147 content::RenderView
* GetRenderViewWithCheckedOrigin(const GURL
& origin
) {
148 blink::WebLocalFrame
* webframe
=
149 blink::WebLocalFrame::frameForCurrentContext();
152 blink::WebView
* webview
= webframe
->view();
154 return NULL
; // Can happen during closing.
155 content::RenderView
* render_view
= content::RenderView::FromWebView(webview
);
159 GURL
url(webframe
->document().url());
160 if (url
.GetOrigin() != origin
.GetOrigin())
166 // Returns the current URL.
167 GURL
GetCurrentURL(content::RenderView
* render_view
) {
168 blink::WebView
* webview
= render_view
->GetWebView();
169 return webview
? GURL(webview
->mainFrame()->document().url()) : GURL();
174 namespace internal
{ // for testing.
176 // Returns an array with the RGBA color components.
177 v8::Handle
<v8::Value
> RGBAColorToArray(v8::Isolate
* isolate
,
178 const RGBAColor
& color
) {
179 v8::Handle
<v8::Array
> color_array
= v8::Array::New(isolate
, 4);
180 color_array
->Set(0, v8::Int32::New(isolate
, color
.r
));
181 color_array
->Set(1, v8::Int32::New(isolate
, color
.g
));
182 color_array
->Set(2, v8::Int32::New(isolate
, color
.b
));
183 color_array
->Set(3, v8::Int32::New(isolate
, color
.a
));
187 // Resolves a possibly relative URL using the current URL.
188 GURL
ResolveURL(const GURL
& current_url
,
189 const base::string16
& possibly_relative_url
) {
190 if (current_url
.is_valid() && !possibly_relative_url
.empty())
191 return current_url
.Resolve(possibly_relative_url
);
192 return GURL(possibly_relative_url
);
195 } // namespace internal
197 namespace extensions_v8
{
199 static const char kSearchBoxExtensionName
[] = "v8/EmbeddedSearch";
201 // We first send this script down to determine if the page supports instant.
202 static const char kSupportsInstantScript
[] =
203 "if (window.chrome &&"
204 " window.chrome.embeddedSearch &&"
205 " window.chrome.embeddedSearch.searchBox &&"
206 " window.chrome.embeddedSearch.searchBox.onsubmit &&"
207 " typeof window.chrome.embeddedSearch.searchBox.onsubmit =="
214 static const char kDispatchChromeIdentityCheckResult
[] =
215 "if (window.chrome &&"
216 " window.chrome.embeddedSearch &&"
217 " window.chrome.embeddedSearch.newTabPage &&"
218 " window.chrome.embeddedSearch.newTabPage.onsignedincheckdone &&"
219 " typeof window.chrome.embeddedSearch.newTabPage"
220 " .onsignedincheckdone === 'function') {"
221 " window.chrome.embeddedSearch.newTabPage.onsignedincheckdone(%s, %s);"
225 static const char kDispatchFocusChangedScript
[] =
226 "if (window.chrome &&"
227 " window.chrome.embeddedSearch &&"
228 " window.chrome.embeddedSearch.searchBox &&"
229 " window.chrome.embeddedSearch.searchBox.onfocuschange &&"
230 " typeof window.chrome.embeddedSearch.searchBox.onfocuschange =="
232 " window.chrome.embeddedSearch.searchBox.onfocuschange();"
236 static const char kDispatchHistorySyncCheckResult
[] =
237 "if (window.chrome &&"
238 " window.chrome.embeddedSearch &&"
239 " window.chrome.embeddedSearch.newTabPage &&"
240 " window.chrome.embeddedSearch.newTabPage.onhistorysynccheckdone &&"
241 " typeof window.chrome.embeddedSearch.newTabPage"
242 " .onhistorysynccheckdone === 'function') {"
243 " window.chrome.embeddedSearch.newTabPage.onhistorysynccheckdone(%s);"
247 static const char kDispatchInputCancelScript
[] =
248 "if (window.chrome &&"
249 " window.chrome.embeddedSearch &&"
250 " window.chrome.embeddedSearch.newTabPage &&"
251 " window.chrome.embeddedSearch.newTabPage.oninputcancel &&"
252 " typeof window.chrome.embeddedSearch.newTabPage.oninputcancel =="
254 " window.chrome.embeddedSearch.newTabPage.oninputcancel();"
258 static const char kDispatchInputStartScript
[] =
259 "if (window.chrome &&"
260 " window.chrome.embeddedSearch &&"
261 " window.chrome.embeddedSearch.newTabPage &&"
262 " window.chrome.embeddedSearch.newTabPage.oninputstart &&"
263 " typeof window.chrome.embeddedSearch.newTabPage.oninputstart =="
265 " window.chrome.embeddedSearch.newTabPage.oninputstart();"
269 static const char kDispatchKeyCaptureChangeScript
[] =
270 "if (window.chrome &&"
271 " window.chrome.embeddedSearch &&"
272 " window.chrome.embeddedSearch.searchBox &&"
273 " window.chrome.embeddedSearch.searchBox.onkeycapturechange &&"
274 " typeof window.chrome.embeddedSearch.searchBox.onkeycapturechange =="
276 " window.chrome.embeddedSearch.searchBox.onkeycapturechange();"
280 static const char kDispatchMarginChangeEventScript
[] =
281 "if (window.chrome &&"
282 " window.chrome.embeddedSearch &&"
283 " window.chrome.embeddedSearch.searchBox &&"
284 " window.chrome.embeddedSearch.searchBox.onmarginchange &&"
285 " typeof window.chrome.embeddedSearch.searchBox.onmarginchange =="
287 " window.chrome.embeddedSearch.searchBox.onmarginchange();"
291 static const char kDispatchMostVisitedChangedScript
[] =
292 "if (window.chrome &&"
293 " window.chrome.embeddedSearch &&"
294 " window.chrome.embeddedSearch.newTabPage &&"
295 " window.chrome.embeddedSearch.newTabPage.onmostvisitedchange &&"
296 " typeof window.chrome.embeddedSearch.newTabPage.onmostvisitedchange =="
298 " window.chrome.embeddedSearch.newTabPage.onmostvisitedchange();"
302 static const char kDispatchSubmitEventScript
[] =
303 "if (window.chrome &&"
304 " window.chrome.embeddedSearch &&"
305 " window.chrome.embeddedSearch.searchBox &&"
306 " window.chrome.embeddedSearch.searchBox.onsubmit &&"
307 " typeof window.chrome.embeddedSearch.searchBox.onsubmit =="
309 " window.chrome.embeddedSearch.searchBox.onsubmit();"
313 static const char kDispatchSuggestionChangeEventScript
[] =
314 "if (window.chrome &&"
315 " window.chrome.embeddedSearch &&"
316 " window.chrome.embeddedSearch.searchBox &&"
317 " window.chrome.embeddedSearch.searchBox.onsuggestionchange &&"
318 " typeof window.chrome.embeddedSearch.searchBox.onsuggestionchange =="
320 " window.chrome.embeddedSearch.searchBox.onsuggestionchange();"
324 static const char kDispatchThemeChangeEventScript
[] =
325 "if (window.chrome &&"
326 " window.chrome.embeddedSearch &&"
327 " window.chrome.embeddedSearch.newTabPage &&"
328 " window.chrome.embeddedSearch.newTabPage.onthemechange &&"
329 " typeof window.chrome.embeddedSearch.newTabPage.onthemechange =="
331 " window.chrome.embeddedSearch.newTabPage.onthemechange();"
335 static const char kDispatchToggleVoiceSearchScript
[] =
336 "if (window.chrome &&"
337 " window.chrome.embeddedSearch &&"
338 " window.chrome.embeddedSearch.searchBox &&"
339 " window.chrome.embeddedSearch.searchBox.ontogglevoicesearch &&"
340 " typeof window.chrome.embeddedSearch.searchBox.ontogglevoicesearch =="
342 " window.chrome.embeddedSearch.searchBox.ontogglevoicesearch();"
346 // ----------------------------------------------------------------------------
348 class SearchBoxExtensionWrapper
: public v8::Extension
{
350 explicit SearchBoxExtensionWrapper(const base::StringPiece
& code
);
352 // Allows v8's javascript code to call the native functions defined
353 // in this class for window.chrome.
354 v8::Handle
<v8::FunctionTemplate
> GetNativeFunctionTemplate(
356 v8::Handle
<v8::String
> name
) override
;
358 // Helper function to find the RenderView. May return NULL.
359 static content::RenderView
* GetRenderView();
361 // Sends a Chrome identity check to the browser.
362 static void CheckIsUserSignedInToChromeAs(
363 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
365 // Checks whether the user sync his history.
366 static void CheckIsUserSyncingHistory(
367 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
369 // Deletes a Most Visited item.
370 static void DeleteMostVisitedItem(
371 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
373 // Focuses the omnibox.
374 static void Focus(const v8::FunctionCallbackInfo
<v8::Value
>& args
);
376 // Gets whether or not the app launcher is enabled.
377 static void GetAppLauncherEnabled(
378 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
380 // Gets the desired navigation behavior from a click event.
381 static void GetDispositionFromClick(
382 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
384 // Gets Most Visited Items.
385 static void GetMostVisitedItems(
386 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
388 // Gets the raw data for a most visited item including its raw URL.
389 // GetRenderViewWithCheckedOrigin() enforces that only code in the origin
390 // chrome-search://most-visited can call this function.
391 static void GetMostVisitedItemData(
392 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
394 // Gets the submitted value of the user's search query.
395 static void GetQuery(const v8::FunctionCallbackInfo
<v8::Value
>& args
);
397 // Returns true if the Searchbox itself is oriented right-to-left.
398 static void GetRightToLeft(const v8::FunctionCallbackInfo
<v8::Value
>& args
);
400 // Gets the Embedded Search request params. Used for logging purposes.
401 static void GetSearchRequestParams(
402 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
404 // Gets the start-edge margin to use with extended Instant.
405 static void GetStartMargin(const v8::FunctionCallbackInfo
<v8::Value
>& args
);
407 // Gets the current top suggestion to prefetch search results.
408 static void GetSuggestionToPrefetch(
409 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
411 // Gets the background info of the theme currently adopted by browser.
412 // Call only when overlay is showing NTP page.
413 static void GetThemeBackgroundInfo(
414 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
416 // Gets whether the omnibox has focus or not.
417 static void IsFocused(const v8::FunctionCallbackInfo
<v8::Value
>& args
);
419 // Gets whether user input is in progress.
420 static void IsInputInProgress(
421 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
423 // Gets whether the browser is capturing key strokes.
424 static void IsKeyCaptureEnabled(
425 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
427 // Logs information from the iframes/titles on the NTP.
428 static void LogEvent(const v8::FunctionCallbackInfo
<v8::Value
>& args
);
430 // Logs an impression on one of the Most Visited tile on the NTP.
431 static void LogMostVisitedImpression(
432 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
434 // Logs a navigation on one of the Most Visited tile on the NTP.
435 static void LogMostVisitedNavigation(
436 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
438 // Navigates the window to a URL represented by either a URL string or a
440 static void NavigateContentWindow(
441 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
443 // Pastes provided value or clipboard's content into the omnibox.
444 static void Paste(const v8::FunctionCallbackInfo
<v8::Value
>& args
);
446 // Indicates whether the page supports voice search.
447 static void SetVoiceSearchSupported(
448 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
450 // Start capturing user key strokes.
451 static void StartCapturingKeyStrokes(
452 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
454 // Stop capturing user key strokes.
455 static void StopCapturingKeyStrokes(
456 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
458 // Undoes the deletion of all Most Visited itens.
459 static void UndoAllMostVisitedDeletions(
460 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
462 // Undoes the deletion of a Most Visited item.
463 static void UndoMostVisitedDeletion(
464 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
466 // Indicates whether the page supports Instant.
467 static void GetDisplayInstantResults(
468 const v8::FunctionCallbackInfo
<v8::Value
>& args
);
471 DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper
);
475 v8::Extension
* SearchBoxExtension::Get() {
476 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance().
477 GetRawDataResource(IDR_SEARCHBOX_API
));
481 bool SearchBoxExtension::PageSupportsInstant(blink::WebFrame
* frame
) {
482 if (!frame
) return false;
483 v8::HandleScope
handle_scope(v8::Isolate::GetCurrent());
484 v8::Handle
<v8::Value
> v
= frame
->executeScriptAndReturnValue(
485 blink::WebScriptSource(kSupportsInstantScript
));
486 return !v
.IsEmpty() && v
->BooleanValue();
490 void SearchBoxExtension::DispatchChromeIdentityCheckResult(
491 blink::WebFrame
* frame
,
492 const base::string16
& identity
,
493 bool identity_match
) {
494 std::string escaped_identity
= base::GetQuotedJSONString(identity
);
495 blink::WebString
script(base::UTF8ToUTF16(base::StringPrintf(
496 kDispatchChromeIdentityCheckResult
,
497 escaped_identity
.c_str(),
498 identity_match
? "true" : "false")));
499 Dispatch(frame
, script
);
503 void SearchBoxExtension::DispatchFocusChange(blink::WebFrame
* frame
) {
504 Dispatch(frame
, kDispatchFocusChangedScript
);
508 void SearchBoxExtension::DispatchHistorySyncCheckResult(
509 blink::WebFrame
* frame
,
511 blink::WebString
script(base::UTF8ToUTF16(base::StringPrintf(
512 kDispatchHistorySyncCheckResult
,
513 sync_history
? "true" : "false")));
514 Dispatch(frame
, script
);
518 void SearchBoxExtension::DispatchInputCancel(blink::WebFrame
* frame
) {
519 Dispatch(frame
, kDispatchInputCancelScript
);
523 void SearchBoxExtension::DispatchInputStart(blink::WebFrame
* frame
) {
524 Dispatch(frame
, kDispatchInputStartScript
);
528 void SearchBoxExtension::DispatchKeyCaptureChange(blink::WebFrame
* frame
) {
529 Dispatch(frame
, kDispatchKeyCaptureChangeScript
);
533 void SearchBoxExtension::DispatchMarginChange(blink::WebFrame
* frame
) {
534 Dispatch(frame
, kDispatchMarginChangeEventScript
);
538 void SearchBoxExtension::DispatchMostVisitedChanged(
539 blink::WebFrame
* frame
) {
540 Dispatch(frame
, kDispatchMostVisitedChangedScript
);
544 void SearchBoxExtension::DispatchSubmit(blink::WebFrame
* frame
) {
545 Dispatch(frame
, kDispatchSubmitEventScript
);
549 void SearchBoxExtension::DispatchSuggestionChange(blink::WebFrame
* frame
) {
550 Dispatch(frame
, kDispatchSuggestionChangeEventScript
);
554 void SearchBoxExtension::DispatchThemeChange(blink::WebFrame
* frame
) {
555 Dispatch(frame
, kDispatchThemeChangeEventScript
);
559 void SearchBoxExtension::DispatchToggleVoiceSearch(
560 blink::WebFrame
* frame
) {
561 Dispatch(frame
, kDispatchToggleVoiceSearchScript
);
564 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper(
565 const base::StringPiece
& code
)
566 : v8::Extension(kSearchBoxExtensionName
, code
.data(), 0, 0, code
.size()) {
569 v8::Handle
<v8::FunctionTemplate
>
570 SearchBoxExtensionWrapper::GetNativeFunctionTemplate(
571 v8::Isolate
* isolate
,
572 v8::Handle
<v8::String
> name
) {
574 v8::String::NewFromUtf8(isolate
, "CheckIsUserSignedInToChromeAs")))
575 return v8::FunctionTemplate::New(isolate
, CheckIsUserSignedInToChromeAs
);
577 v8::String::NewFromUtf8(isolate
, "CheckIsUserSyncingHistory")))
578 return v8::FunctionTemplate::New(isolate
, CheckIsUserSyncingHistory
);
579 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "DeleteMostVisitedItem")))
580 return v8::FunctionTemplate::New(isolate
, DeleteMostVisitedItem
);
581 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "Focus")))
582 return v8::FunctionTemplate::New(isolate
, Focus
);
583 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "GetAppLauncherEnabled")))
584 return v8::FunctionTemplate::New(isolate
, GetAppLauncherEnabled
);
585 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "GetDispositionFromClick")))
586 return v8::FunctionTemplate::New(isolate
, GetDispositionFromClick
);
587 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "GetMostVisitedItems")))
588 return v8::FunctionTemplate::New(isolate
, GetMostVisitedItems
);
589 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "GetMostVisitedItemData")))
590 return v8::FunctionTemplate::New(isolate
, GetMostVisitedItemData
);
591 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "GetQuery")))
592 return v8::FunctionTemplate::New(isolate
, GetQuery
);
593 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "GetRightToLeft")))
594 return v8::FunctionTemplate::New(isolate
, GetRightToLeft
);
595 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "GetSearchRequestParams")))
596 return v8::FunctionTemplate::New(isolate
, GetSearchRequestParams
);
597 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "GetStartMargin")))
598 return v8::FunctionTemplate::New(isolate
, GetStartMargin
);
599 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "GetSuggestionToPrefetch")))
600 return v8::FunctionTemplate::New(isolate
, GetSuggestionToPrefetch
);
601 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "GetThemeBackgroundInfo")))
602 return v8::FunctionTemplate::New(isolate
, GetThemeBackgroundInfo
);
603 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "IsFocused")))
604 return v8::FunctionTemplate::New(isolate
, IsFocused
);
605 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "IsInputInProgress")))
606 return v8::FunctionTemplate::New(isolate
, IsInputInProgress
);
607 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "IsKeyCaptureEnabled")))
608 return v8::FunctionTemplate::New(isolate
, IsKeyCaptureEnabled
);
609 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "LogEvent")))
610 return v8::FunctionTemplate::New(isolate
, LogEvent
);
612 v8::String::NewFromUtf8(isolate
, "LogMostVisitedImpression"))) {
613 return v8::FunctionTemplate::New(isolate
, LogMostVisitedImpression
);
616 v8::String::NewFromUtf8(isolate
, "LogMostVisitedNavigation"))) {
617 return v8::FunctionTemplate::New(isolate
, LogMostVisitedNavigation
);
619 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "NavigateContentWindow")))
620 return v8::FunctionTemplate::New(isolate
, NavigateContentWindow
);
621 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "Paste")))
622 return v8::FunctionTemplate::New(isolate
, Paste
);
623 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "SetVoiceSearchSupported")))
624 return v8::FunctionTemplate::New(isolate
, SetVoiceSearchSupported
);
626 v8::String::NewFromUtf8(isolate
, "StartCapturingKeyStrokes")))
627 return v8::FunctionTemplate::New(isolate
, StartCapturingKeyStrokes
);
628 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "StopCapturingKeyStrokes")))
629 return v8::FunctionTemplate::New(isolate
, StopCapturingKeyStrokes
);
631 v8::String::NewFromUtf8(isolate
, "UndoAllMostVisitedDeletions")))
632 return v8::FunctionTemplate::New(isolate
, UndoAllMostVisitedDeletions
);
633 if (name
->Equals(v8::String::NewFromUtf8(isolate
, "UndoMostVisitedDeletion")))
634 return v8::FunctionTemplate::New(isolate
, UndoMostVisitedDeletion
);
636 v8::String::NewFromUtf8(isolate
, "GetDisplayInstantResults")))
637 return v8::FunctionTemplate::New(isolate
, GetDisplayInstantResults
);
638 return v8::Handle
<v8::FunctionTemplate
>();
642 content::RenderView
* SearchBoxExtensionWrapper::GetRenderView() {
643 blink::WebLocalFrame
* webframe
=
644 blink::WebLocalFrame::frameForCurrentContext();
645 if (!webframe
) return NULL
;
647 blink::WebView
* webview
= webframe
->view();
648 if (!webview
) return NULL
; // can happen during closing
650 return content::RenderView::FromWebView(webview
);
654 void SearchBoxExtensionWrapper::CheckIsUserSignedInToChromeAs(
655 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
656 content::RenderView
* render_view
= GetRenderView();
657 if (!render_view
|| args
.Length() == 0 || args
[0]->IsUndefined()) return;
659 DVLOG(1) << render_view
<< " CheckIsUserSignedInToChromeAs";
661 SearchBox::Get(render_view
)->CheckIsUserSignedInToChromeAs(
662 V8ValueToUTF16(args
[0]));
666 void SearchBoxExtensionWrapper::CheckIsUserSyncingHistory(
667 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
668 content::RenderView
* render_view
= GetRenderView();
669 if (!render_view
) return;
671 DVLOG(1) << render_view
<< " CheckIsUserSyncingHistory";
672 SearchBox::Get(render_view
)->CheckIsUserSyncingHistory();
676 void SearchBoxExtensionWrapper::DeleteMostVisitedItem(
677 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
678 content::RenderView
* render_view
= GetRenderView();
679 if (!render_view
|| !args
.Length()) return;
681 DVLOG(1) << render_view
<< " DeleteMostVisitedItem";
682 SearchBox::Get(render_view
)->DeleteMostVisitedItem(args
[0]->IntegerValue());
686 void SearchBoxExtensionWrapper::Focus(
687 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
688 content::RenderView
* render_view
= GetRenderView();
689 if (!render_view
) return;
691 DVLOG(1) << render_view
<< " Focus";
692 SearchBox::Get(render_view
)->Focus();
696 void SearchBoxExtensionWrapper::GetAppLauncherEnabled(
697 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
698 content::RenderView
* render_view
= GetRenderView();
699 if (!render_view
) return;
701 args
.GetReturnValue().Set(
702 SearchBox::Get(render_view
)->app_launcher_enabled());
706 void SearchBoxExtensionWrapper::GetDispositionFromClick(
707 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
708 content::RenderView
* render_view
= GetRenderView();
709 if (!render_view
|| args
.Length() != 5) return;
711 bool middle_button
= args
[0]->BooleanValue();
712 bool alt_key
= args
[1]->BooleanValue();
713 bool ctrl_key
= args
[2]->BooleanValue();
714 bool meta_key
= args
[3]->BooleanValue();
715 bool shift_key
= args
[4]->BooleanValue();
717 WindowOpenDisposition disposition
= ui::DispositionFromClick(middle_button
,
722 v8::Isolate
* isolate
= args
.GetIsolate();
723 args
.GetReturnValue().Set(v8::Int32::New(isolate
, disposition
));
727 void SearchBoxExtensionWrapper::GetMostVisitedItems(
728 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
729 content::RenderView
* render_view
= GetRenderView();
732 DVLOG(1) << render_view
<< " GetMostVisitedItems";
734 const SearchBox
* search_box
= SearchBox::Get(render_view
);
736 std::vector
<InstantMostVisitedItemIDPair
> instant_mv_items
;
737 search_box
->GetMostVisitedItems(&instant_mv_items
);
738 v8::Isolate
* isolate
= args
.GetIsolate();
739 v8::Handle
<v8::Array
> v8_mv_items
=
740 v8::Array::New(isolate
, instant_mv_items
.size());
741 for (size_t i
= 0; i
< instant_mv_items
.size(); ++i
) {
743 GenerateMostVisitedItem(isolate
,
744 render_view
->GetRoutingID(),
745 instant_mv_items
[i
].first
,
746 instant_mv_items
[i
].second
));
748 args
.GetReturnValue().Set(v8_mv_items
);
752 void SearchBoxExtensionWrapper::GetMostVisitedItemData(
753 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
754 content::RenderView
* render_view
= GetRenderViewWithCheckedOrigin(
755 GURL(chrome::kChromeSearchMostVisitedUrl
));
756 if (!render_view
) return;
758 // Need an rid argument.
759 if (args
.Length() < 1 || !args
[0]->IsNumber())
762 DVLOG(1) << render_view
<< " GetMostVisitedItem";
763 InstantRestrictedID restricted_id
= args
[0]->IntegerValue();
764 InstantMostVisitedItem mv_item
;
765 if (!SearchBox::Get(render_view
)->GetMostVisitedItemWithID(
766 restricted_id
, &mv_item
)) {
769 v8::Isolate
* isolate
= args
.GetIsolate();
770 args
.GetReturnValue().Set(GenerateMostVisitedItem(
771 isolate
, render_view
->GetRoutingID(), restricted_id
, mv_item
));
775 void SearchBoxExtensionWrapper::GetQuery(
776 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
777 content::RenderView
* render_view
= GetRenderView();
778 if (!render_view
) return;
779 const base::string16
& query
= SearchBox::Get(render_view
)->query();
780 DVLOG(1) << render_view
<< " GetQuery: '" << query
<< "'";
781 v8::Isolate
* isolate
= args
.GetIsolate();
782 args
.GetReturnValue().Set(UTF16ToV8String(isolate
, query
));
786 void SearchBoxExtensionWrapper::GetRightToLeft(
787 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
788 args
.GetReturnValue().Set(base::i18n::IsRTL());
792 void SearchBoxExtensionWrapper::GetSearchRequestParams(
793 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
794 content::RenderView
* render_view
= GetRenderView();
795 if (!render_view
) return;
797 const EmbeddedSearchRequestParams
& params
=
798 SearchBox::Get(render_view
)->GetEmbeddedSearchRequestParams();
799 v8::Isolate
* isolate
= args
.GetIsolate();
800 v8::Handle
<v8::Object
> data
= v8::Object::New(isolate
);
801 if (!params
.search_query
.empty()) {
802 data
->Set(v8::String::NewFromUtf8(isolate
, kSearchQueryKey
),
803 UTF16ToV8String(isolate
, params
.search_query
));
805 if (!params
.original_query
.empty()) {
806 data
->Set(v8::String::NewFromUtf8(isolate
, kOriginalQueryKey
),
807 UTF16ToV8String(isolate
, params
.original_query
));
809 if (!params
.rlz_parameter_value
.empty()) {
810 data
->Set(v8::String::NewFromUtf8(isolate
, kRLZParameterKey
),
811 UTF16ToV8String(isolate
, params
.rlz_parameter_value
));
813 if (!params
.input_encoding
.empty()) {
814 data
->Set(v8::String::NewFromUtf8(isolate
, kInputEncodingKey
),
815 UTF16ToV8String(isolate
, params
.input_encoding
));
817 if (!params
.assisted_query_stats
.empty()) {
818 data
->Set(v8::String::NewFromUtf8(isolate
, kAssistedQueryStatsKey
),
819 UTF16ToV8String(isolate
, params
.assisted_query_stats
));
821 args
.GetReturnValue().Set(data
);
825 void SearchBoxExtensionWrapper::GetStartMargin(
826 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
827 content::RenderView
* render_view
= GetRenderView();
828 if (!render_view
) return;
829 args
.GetReturnValue().Set(static_cast<int32_t>(
830 SearchBox::Get(render_view
)->start_margin()));
834 void SearchBoxExtensionWrapper::GetSuggestionToPrefetch(
835 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
836 content::RenderView
* render_view
= GetRenderView();
837 if (!render_view
) return;
839 const InstantSuggestion
& suggestion
=
840 SearchBox::Get(render_view
)->suggestion();
841 v8::Isolate
* isolate
= args
.GetIsolate();
842 v8::Handle
<v8::Object
> data
= v8::Object::New(isolate
);
843 data
->Set(v8::String::NewFromUtf8(isolate
, "text"),
844 UTF16ToV8String(isolate
, suggestion
.text
));
845 data
->Set(v8::String::NewFromUtf8(isolate
, "metadata"),
846 UTF8ToV8String(isolate
, suggestion
.metadata
));
847 args
.GetReturnValue().Set(data
);
851 void SearchBoxExtensionWrapper::GetThemeBackgroundInfo(
852 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
853 content::RenderView
* render_view
= GetRenderView();
854 if (!render_view
) return;
856 DVLOG(1) << render_view
<< " GetThemeBackgroundInfo";
857 const ThemeBackgroundInfo
& theme_info
=
858 SearchBox::Get(render_view
)->GetThemeBackgroundInfo();
859 v8::Isolate
* isolate
= args
.GetIsolate();
860 v8::Handle
<v8::Object
> info
= v8::Object::New(isolate
);
862 info
->Set(v8::String::NewFromUtf8(isolate
, "usingDefaultTheme"),
863 v8::Boolean::New(isolate
, theme_info
.using_default_theme
));
865 // The theme background color is in RGBA format "rgba(R,G,B,A)" where R, G and
866 // B are between 0 and 255 inclusive, and A is a double between 0 and 1
868 // This is the CSS "background-color" format.
869 // Value is always valid.
870 // TODO(jfweitz): Remove this field after GWS is modified to use the new
871 // backgroundColorRgba field.
873 v8::String::NewFromUtf8(isolate
, "colorRgba"),
876 // Convert the alpha using DoubleToString because StringPrintf will
878 // locale specific formatters (e.g., use , instead of . in German).
880 kCSSBackgroundColorFormat
,
881 theme_info
.background_color
.r
,
882 theme_info
.background_color
.g
,
883 theme_info
.background_color
.b
,
884 base::DoubleToString(theme_info
.background_color
.a
/ 255.0)
887 // Theme color for background as an array with the RGBA components in order.
888 // Value is always valid.
889 info
->Set(v8::String::NewFromUtf8(isolate
, "backgroundColorRgba"),
890 internal::RGBAColorToArray(isolate
, theme_info
.background_color
));
892 // Theme color for text as an array with the RGBA components in order.
893 // Value is always valid.
894 info
->Set(v8::String::NewFromUtf8(isolate
, "textColorRgba"),
895 internal::RGBAColorToArray(isolate
, theme_info
.text_color
));
897 // Theme color for links as an array with the RGBA components in order.
898 // Value is always valid.
899 info
->Set(v8::String::NewFromUtf8(isolate
, "linkColorRgba"),
900 internal::RGBAColorToArray(isolate
, theme_info
.link_color
));
902 // Theme color for light text as an array with the RGBA components in order.
903 // Value is always valid.
904 info
->Set(v8::String::NewFromUtf8(isolate
, "textColorLightRgba"),
905 internal::RGBAColorToArray(isolate
, theme_info
.text_color_light
));
907 // Theme color for header as an array with the RGBA components in order.
908 // Value is always valid.
909 info
->Set(v8::String::NewFromUtf8(isolate
, "headerColorRgba"),
910 internal::RGBAColorToArray(isolate
, theme_info
.header_color
));
912 // Theme color for section border as an array with the RGBA components in
913 // order. Value is always valid.
915 v8::String::NewFromUtf8(isolate
, "sectionBorderColorRgba"),
916 internal::RGBAColorToArray(isolate
, theme_info
.section_border_color
));
918 // The theme alternate logo value indicates a white logo when TRUE and a
919 // colorful one when FALSE.
920 info
->Set(v8::String::NewFromUtf8(isolate
, "alternateLogo"),
921 v8::Boolean::New(isolate
, theme_info
.logo_alternate
));
923 // The theme background image url is of format kCSSBackgroundImageFormat
924 // where both instances of "%s" are replaced with the id that identifies the
926 // This is the CSS "background-image" format.
927 // Value is only valid if there's a custom theme background image.
928 if (crx_file::id_util::IdIsValid(theme_info
.theme_id
)) {
929 info
->Set(v8::String::NewFromUtf8(isolate
, "imageUrl"),
930 UTF8ToV8String(isolate
,
931 base::StringPrintf(kCSSBackgroundImageFormat
,
932 theme_info
.theme_id
.c_str(),
933 theme_info
.theme_id
.c_str())));
935 // The theme background image horizontal alignment is one of "left",
936 // "right", "center".
937 // This is the horizontal component of the CSS "background-position" format.
938 // Value is only valid if |imageUrl| is not empty.
939 std::string alignment
= kCSSBackgroundPositionCenter
;
940 if (theme_info
.image_horizontal_alignment
==
941 THEME_BKGRND_IMAGE_ALIGN_LEFT
) {
942 alignment
= kCSSBackgroundPositionLeft
;
943 } else if (theme_info
.image_horizontal_alignment
==
944 THEME_BKGRND_IMAGE_ALIGN_RIGHT
) {
945 alignment
= kCSSBackgroundPositionRight
;
947 info
->Set(v8::String::NewFromUtf8(isolate
, "imageHorizontalAlignment"),
948 UTF8ToV8String(isolate
, alignment
));
950 // The theme background image vertical alignment is one of "top", "bottom",
952 // This is the vertical component of the CSS "background-position" format.
953 // Value is only valid if |image_url| is not empty.
954 if (theme_info
.image_vertical_alignment
== THEME_BKGRND_IMAGE_ALIGN_TOP
) {
955 alignment
= kCSSBackgroundPositionTop
;
956 } else if (theme_info
.image_vertical_alignment
==
957 THEME_BKGRND_IMAGE_ALIGN_BOTTOM
) {
958 alignment
= kCSSBackgroundPositionBottom
;
960 alignment
= kCSSBackgroundPositionCenter
;
962 info
->Set(v8::String::NewFromUtf8(isolate
, "imageVerticalAlignment"),
963 UTF8ToV8String(isolate
, alignment
));
965 // The tiling of the theme background image is one of "no-repeat",
966 // "repeat-x", "repeat-y", "repeat".
967 // This is the CSS "background-repeat" format.
968 // Value is only valid if |image_url| is not empty.
969 std::string tiling
= kCSSBackgroundRepeatNo
;
970 switch (theme_info
.image_tiling
) {
971 case THEME_BKGRND_IMAGE_NO_REPEAT
:
972 tiling
= kCSSBackgroundRepeatNo
;
974 case THEME_BKGRND_IMAGE_REPEAT_X
:
975 tiling
= kCSSBackgroundRepeatX
;
977 case THEME_BKGRND_IMAGE_REPEAT_Y
:
978 tiling
= kCSSBackgroundRepeatY
;
980 case THEME_BKGRND_IMAGE_REPEAT
:
981 tiling
= kCSSBackgroundRepeat
;
984 info
->Set(v8::String::NewFromUtf8(isolate
, "imageTiling"),
985 UTF8ToV8String(isolate
, tiling
));
987 // The theme background image height is only valid if |imageUrl| is valid.
988 info
->Set(v8::String::NewFromUtf8(isolate
, "imageHeight"),
989 v8::Int32::New(isolate
, theme_info
.image_height
));
991 // The attribution URL is only valid if the theme has attribution logo.
992 if (theme_info
.has_attribution
) {
994 v8::String::NewFromUtf8(isolate
, "attributionUrl"),
995 UTF8ToV8String(isolate
,
996 base::StringPrintf(kThemeAttributionFormat
,
997 theme_info
.theme_id
.c_str(),
998 theme_info
.theme_id
.c_str())));
1002 args
.GetReturnValue().Set(info
);
1006 void SearchBoxExtensionWrapper::IsFocused(
1007 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
1008 content::RenderView
* render_view
= GetRenderView();
1009 if (!render_view
) return;
1011 bool is_focused
= SearchBox::Get(render_view
)->is_focused();
1012 DVLOG(1) << render_view
<< " IsFocused: " << is_focused
;
1013 args
.GetReturnValue().Set(is_focused
);
1017 void SearchBoxExtensionWrapper::IsInputInProgress(
1018 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
1019 content::RenderView
* render_view
= GetRenderView();
1020 if (!render_view
) return;
1022 bool is_input_in_progress
=
1023 SearchBox::Get(render_view
)->is_input_in_progress();
1024 DVLOG(1) << render_view
<< " IsInputInProgress: " << is_input_in_progress
;
1025 args
.GetReturnValue().Set(is_input_in_progress
);
1029 void SearchBoxExtensionWrapper::IsKeyCaptureEnabled(
1030 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
1031 content::RenderView
* render_view
= GetRenderView();
1032 if (!render_view
) return;
1034 args
.GetReturnValue().Set(SearchBox::Get(render_view
)->
1035 is_key_capture_enabled());
1039 void SearchBoxExtensionWrapper::LogEvent(
1040 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
1041 content::RenderView
* render_view
= GetRenderViewWithCheckedOrigin(
1042 GURL(chrome::kChromeSearchMostVisitedUrl
));
1043 if (!render_view
) return;
1045 if (args
.Length() < 1 || !args
[0]->IsNumber())
1048 DVLOG(1) << render_view
<< " LogEvent";
1050 if (args
[0]->Uint32Value() <= NTP_EVENT_TYPE_LAST
) {
1051 NTPLoggingEventType event
=
1052 static_cast<NTPLoggingEventType
>(args
[0]->Uint32Value());
1053 SearchBox::Get(render_view
)->LogEvent(event
);
1058 void SearchBoxExtensionWrapper::LogMostVisitedImpression(
1059 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
1060 content::RenderView
* render_view
= GetRenderViewWithCheckedOrigin(
1061 GURL(chrome::kChromeSearchMostVisitedUrl
));
1062 if (!render_view
) return;
1064 if (args
.Length() < 2 || !args
[0]->IsNumber() || args
[1]->IsUndefined())
1067 DVLOG(1) << render_view
<< " LogMostVisitedImpression";
1069 SearchBox::Get(render_view
)->LogMostVisitedImpression(
1070 args
[0]->IntegerValue(), V8ValueToUTF16(args
[1]));
1074 void SearchBoxExtensionWrapper::LogMostVisitedNavigation(
1075 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
1076 content::RenderView
* render_view
= GetRenderViewWithCheckedOrigin(
1077 GURL(chrome::kChromeSearchMostVisitedUrl
));
1078 if (!render_view
) return;
1080 if (args
.Length() < 2 || !args
[0]->IsNumber() || args
[1]->IsUndefined())
1083 DVLOG(1) << render_view
<< " LogMostVisitedNavigation";
1085 SearchBox::Get(render_view
)->LogMostVisitedNavigation(
1086 args
[0]->IntegerValue(), V8ValueToUTF16(args
[1]));
1090 void SearchBoxExtensionWrapper::NavigateContentWindow(
1091 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
1092 content::RenderView
* render_view
= GetRenderView();
1093 if (!render_view
|| !args
.Length()) return;
1095 GURL destination_url
;
1096 bool is_most_visited_item_url
= false;
1097 // Check if the url is a rid
1098 if (args
[0]->IsNumber()) {
1099 InstantMostVisitedItem item
;
1100 if (SearchBox::Get(render_view
)->GetMostVisitedItemWithID(
1101 args
[0]->IntegerValue(), &item
)) {
1102 destination_url
= item
.url
;
1103 is_most_visited_item_url
= true;
1107 const base::string16
& possibly_relative_url
= V8ValueToUTF16(args
[0]);
1108 GURL current_url
= GetCurrentURL(render_view
);
1109 destination_url
= internal::ResolveURL(current_url
, possibly_relative_url
);
1112 DVLOG(1) << render_view
<< " NavigateContentWindow: " << destination_url
;
1114 // Navigate the main frame.
1115 if (destination_url
.is_valid() &&
1116 !destination_url
.SchemeIs(url::kJavaScriptScheme
)) {
1117 WindowOpenDisposition disposition
= CURRENT_TAB
;
1118 if (args
[1]->IsNumber()) {
1119 disposition
= (WindowOpenDisposition
) args
[1]->Uint32Value();
1121 SearchBox::Get(render_view
)->NavigateToURL(destination_url
, disposition
,
1122 is_most_visited_item_url
);
1127 void SearchBoxExtensionWrapper::Paste(
1128 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
1129 content::RenderView
* render_view
= GetRenderView();
1130 if (!render_view
) return;
1132 base::string16 text
;
1133 if (!args
[0]->IsUndefined())
1134 text
= V8ValueToUTF16(args
[0]);
1136 DVLOG(1) << render_view
<< " Paste: " << text
;
1137 SearchBox::Get(render_view
)->Paste(text
);
1141 void SearchBoxExtensionWrapper::StartCapturingKeyStrokes(
1142 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
1143 content::RenderView
* render_view
= GetRenderView();
1144 if (!render_view
) return;
1146 DVLOG(1) << render_view
<< " StartCapturingKeyStrokes";
1147 SearchBox::Get(render_view
)->StartCapturingKeyStrokes();
1151 void SearchBoxExtensionWrapper::StopCapturingKeyStrokes(
1152 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
1153 content::RenderView
* render_view
= GetRenderView();
1154 if (!render_view
) return;
1156 DVLOG(1) << render_view
<< " StopCapturingKeyStrokes";
1157 SearchBox::Get(render_view
)->StopCapturingKeyStrokes();
1161 void SearchBoxExtensionWrapper::SetVoiceSearchSupported(
1162 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
1163 content::RenderView
* render_view
= GetRenderView();
1164 if (!render_view
|| args
.Length() < 1) return;
1166 DVLOG(1) << render_view
<< " SetVoiceSearchSupported";
1167 SearchBox::Get(render_view
)->SetVoiceSearchSupported(args
[0]->BooleanValue());
1171 void SearchBoxExtensionWrapper::UndoAllMostVisitedDeletions(
1172 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
1173 content::RenderView
* render_view
= GetRenderView();
1174 if (!render_view
) return;
1176 DVLOG(1) << render_view
<< " UndoAllMostVisitedDeletions";
1177 SearchBox::Get(render_view
)->UndoAllMostVisitedDeletions();
1181 void SearchBoxExtensionWrapper::UndoMostVisitedDeletion(
1182 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
1183 content::RenderView
* render_view
= GetRenderView();
1184 if (!render_view
|| !args
.Length()) return;
1186 DVLOG(1) << render_view
<< " UndoMostVisitedDeletion";
1187 SearchBox::Get(render_view
)->UndoMostVisitedDeletion(args
[0]->IntegerValue());
1191 void SearchBoxExtensionWrapper::GetDisplayInstantResults(
1192 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
1193 content::RenderView
* render_view
= GetRenderView();
1194 if (!render_view
) return;
1196 bool display_instant_results
=
1197 SearchBox::Get(render_view
)->display_instant_results();
1198 DVLOG(1) << render_view
<< " GetDisplayInstantResults" <<
1199 display_instant_results
;
1200 args
.GetReturnValue().Set(display_instant_results
);
1203 } // namespace extensions_v8