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

Side by Side Diff: chrome/renderer/searchbox/searchbox_extension.cc

Issue 1103273009: Use v8::Local inplace of v8::Handle in src/chrome/* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/searchbox/searchbox_extension.h" 5 #include "chrome/renderer/searchbox/searchbox_extension.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/json/string_escape.h" 9 #include "base/json/string_escape.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 const char kCSSBackgroundRepeat[] = "repeat"; 52 const char kCSSBackgroundRepeat[] = "repeat";
53 53
54 const char kThemeAttributionFormat[] = "-webkit-image-set(" 54 const char kThemeAttributionFormat[] = "-webkit-image-set("
55 "url(chrome-search://theme/IDR_THEME_NTP_ATTRIBUTION?%s) 1x, " 55 "url(chrome-search://theme/IDR_THEME_NTP_ATTRIBUTION?%s) 1x, "
56 "url(chrome-search://theme/IDR_THEME_NTP_ATTRIBUTION@2x?%s) 2x)"; 56 "url(chrome-search://theme/IDR_THEME_NTP_ATTRIBUTION@2x?%s) 2x)";
57 57
58 const char kLTRHtmlTextDirection[] = "ltr"; 58 const char kLTRHtmlTextDirection[] = "ltr";
59 const char kRTLHtmlTextDirection[] = "rtl"; 59 const char kRTLHtmlTextDirection[] = "rtl";
60 60
61 // Converts a V8 value to a string16. 61 // Converts a V8 value to a string16.
62 base::string16 V8ValueToUTF16(v8::Handle<v8::Value> v) { 62 base::string16 V8ValueToUTF16(v8::Local<v8::Value> v) {
63 v8::String::Value s(v); 63 v8::String::Value s(v);
64 return base::string16(reinterpret_cast<const base::char16*>(*s), s.length()); 64 return base::string16(reinterpret_cast<const base::char16*>(*s), s.length());
65 } 65 }
66 66
67 // Returns whether icon NTP is enabled by experiment. 67 // Returns whether icon NTP is enabled by experiment.
68 // TODO(huangs): Remove all 3 copies of this routine once Icon NTP launches. 68 // TODO(huangs): Remove all 3 copies of this routine once Icon NTP launches.
69 bool IsIconNTPEnabled() { 69 bool IsIconNTPEnabled() {
70 // Note: It's important to query the field trial state first, to ensure that 70 // Note: It's important to query the field trial state first, to ensure that
71 // UMA reports the correct group. 71 // UMA reports the correct group.
72 const std::string group_name = base::FieldTrialList::FindFullName("IconNTP"); 72 const std::string group_name = base::FieldTrialList::FindFullName("IconNTP");
73 using base::CommandLine; 73 using base::CommandLine;
74 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableIconNtp)) 74 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableIconNtp))
75 return false; 75 return false;
76 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableIconNtp)) 76 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableIconNtp))
77 return true; 77 return true;
78 78
79 return StartsWithASCII(group_name, "Enabled", true); 79 return StartsWithASCII(group_name, "Enabled", true);
80 } 80 }
81 81
82 // Converts string16 to V8 String. 82 // Converts string16 to V8 String.
83 v8::Handle<v8::String> UTF16ToV8String(v8::Isolate* isolate, 83 v8::Local<v8::String> UTF16ToV8String(v8::Isolate* isolate,
84 const base::string16& s) { 84 const base::string16& s) {
85 return v8::String::NewFromTwoByte(isolate, 85 return v8::String::NewFromTwoByte(isolate,
86 reinterpret_cast<const uint16_t*>(s.data()), 86 reinterpret_cast<const uint16_t*>(s.data()),
87 v8::String::kNormalString, 87 v8::String::kNormalString,
88 s.size()); 88 s.size());
89 } 89 }
90 90
91 // Converts std::string to V8 String. 91 // Converts std::string to V8 String.
92 v8::Handle<v8::String> UTF8ToV8String(v8::Isolate* isolate, 92 v8::Local<v8::String> UTF8ToV8String(v8::Isolate* isolate,
93 const std::string& s) { 93 const std::string& s) {
94 return v8::String::NewFromUtf8( 94 return v8::String::NewFromUtf8(
95 isolate, s.data(), v8::String::kNormalString, s.size()); 95 isolate, s.data(), v8::String::kNormalString, s.size());
96 } 96 }
97 97
98 // Throws a TypeError on the current V8 context if the args are invalid. 98 // Throws a TypeError on the current V8 context if the args are invalid.
99 void ThrowInvalidParameters(const v8::FunctionCallbackInfo<v8::Value>& args) { 99 void ThrowInvalidParameters(const v8::FunctionCallbackInfo<v8::Value>& args) {
100 v8::Isolate* isolate = args.GetIsolate(); 100 v8::Isolate* isolate = args.GetIsolate();
101 isolate->ThrowException(v8::Exception::TypeError( 101 isolate->ThrowException(v8::Exception::TypeError(
102 v8::String::NewFromUtf8(isolate, "Invalid parameters"))); 102 v8::String::NewFromUtf8(isolate, "Invalid parameters")));
103 } 103 }
104 104
105 void Dispatch(blink::WebFrame* frame, const blink::WebString& script) { 105 void Dispatch(blink::WebFrame* frame, const blink::WebString& script) {
106 if (!frame) return; 106 if (!frame) return;
107 frame->executeScript(blink::WebScriptSource(script)); 107 frame->executeScript(blink::WebScriptSource(script));
108 } 108 }
109 109
110 v8::Handle<v8::String> GenerateThumbnailURL( 110 v8::Local<v8::String> GenerateThumbnailURL(
111 v8::Isolate* isolate, 111 v8::Isolate* isolate,
112 int render_view_id, 112 int render_view_id,
113 InstantRestrictedID most_visited_item_id) { 113 InstantRestrictedID most_visited_item_id) {
114 return UTF8ToV8String( 114 return UTF8ToV8String(
115 isolate, 115 isolate,
116 base::StringPrintf( 116 base::StringPrintf(
117 "chrome-search://thumb/%d/%d", render_view_id, most_visited_item_id)); 117 "chrome-search://thumb/%d/%d", render_view_id, most_visited_item_id));
118 } 118 }
119 119
120 // Populates a Javascript MostVisitedItem object from |mv_item|. 120 // Populates a Javascript MostVisitedItem object from |mv_item|.
121 // NOTE: Includes "url", "title" and "domain" which are private data, so should 121 // NOTE: Includes "url", "title" and "domain" which are private data, so should
122 // not be returned to the Instant page. These should be erased before returning 122 // not be returned to the Instant page. These should be erased before returning
123 // the object. See GetMostVisitedItemsWrapper() in searchbox_api.js. 123 // the object. See GetMostVisitedItemsWrapper() in searchbox_api.js.
124 v8::Handle<v8::Object> GenerateMostVisitedItem( 124 v8::Local<v8::Object> GenerateMostVisitedItem(
125 v8::Isolate* isolate, 125 v8::Isolate* isolate,
126 int render_view_id, 126 int render_view_id,
127 InstantRestrictedID restricted_id, 127 InstantRestrictedID restricted_id,
128 const InstantMostVisitedItem& mv_item) { 128 const InstantMostVisitedItem& mv_item) {
129 // We set the "dir" attribute of the title, so that in RTL locales, a LTR 129 // We set the "dir" attribute of the title, so that in RTL locales, a LTR
130 // title is rendered left-to-right and truncated from the right. For 130 // title is rendered left-to-right and truncated from the right. For
131 // example, the title of http://msdn.microsoft.com/en-us/default.aspx is 131 // example, the title of http://msdn.microsoft.com/en-us/default.aspx is
132 // "MSDN: Microsoft developer network". In RTL locales, in the New Tab 132 // "MSDN: Microsoft developer network". In RTL locales, in the New Tab
133 // page, if the "dir" of this title is not specified, it takes Chrome UI's 133 // page, if the "dir" of this title is not specified, it takes Chrome UI's
134 // directionality. So the title will be truncated as "soft developer 134 // directionality. So the title will be truncated as "soft developer
135 // network". Setting the "dir" attribute as "ltr" renders the truncated 135 // network". Setting the "dir" attribute as "ltr" renders the truncated
136 // title as "MSDN: Microsoft D...". As another example, the title of 136 // title as "MSDN: Microsoft D...". As another example, the title of
137 // http://yahoo.com is "Yahoo!". In RTL locales, in the New Tab page, the 137 // http://yahoo.com is "Yahoo!". In RTL locales, in the New Tab page, the
138 // title will be rendered as "!Yahoo" if its "dir" attribute is not set to 138 // title will be rendered as "!Yahoo" if its "dir" attribute is not set to
139 // "ltr". 139 // "ltr".
140 std::string direction; 140 std::string direction;
141 if (base::i18n::StringContainsStrongRTLChars(mv_item.title)) 141 if (base::i18n::StringContainsStrongRTLChars(mv_item.title))
142 direction = kRTLHtmlTextDirection; 142 direction = kRTLHtmlTextDirection;
143 else 143 else
144 direction = kLTRHtmlTextDirection; 144 direction = kLTRHtmlTextDirection;
145 145
146 base::string16 title = mv_item.title; 146 base::string16 title = mv_item.title;
147 if (title.empty()) 147 if (title.empty())
148 title = base::UTF8ToUTF16(mv_item.url.spec()); 148 title = base::UTF8ToUTF16(mv_item.url.spec());
149 149
150 v8::Handle<v8::Object> obj = v8::Object::New(isolate); 150 v8::Local<v8::Object> obj = v8::Object::New(isolate);
151 obj->Set(v8::String::NewFromUtf8(isolate, "renderViewId"), 151 obj->Set(v8::String::NewFromUtf8(isolate, "renderViewId"),
152 v8::Int32::New(isolate, render_view_id)); 152 v8::Int32::New(isolate, render_view_id));
153 obj->Set(v8::String::NewFromUtf8(isolate, "rid"), 153 obj->Set(v8::String::NewFromUtf8(isolate, "rid"),
154 v8::Int32::New(isolate, restricted_id)); 154 v8::Int32::New(isolate, restricted_id));
155 obj->Set(v8::String::NewFromUtf8(isolate, "thumbnailUrl"), 155 obj->Set(v8::String::NewFromUtf8(isolate, "thumbnailUrl"),
156 GenerateThumbnailURL(isolate, render_view_id, restricted_id)); 156 GenerateThumbnailURL(isolate, render_view_id, restricted_id));
157 if (IsIconNTPEnabled()) { 157 if (IsIconNTPEnabled()) {
158 // Update website http://www.chromium.org/embeddedsearch when we make this 158 // Update website http://www.chromium.org/embeddedsearch when we make this
159 // permanent. 159 // permanent.
160 // Large icon size is 48px * window.devicePixelRatio. This is easier to set 160 // Large icon size is 48px * window.devicePixelRatio. This is easier to set
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 GURL GetCurrentURL(content::RenderView* render_view) { 203 GURL GetCurrentURL(content::RenderView* render_view) {
204 blink::WebView* webview = render_view->GetWebView(); 204 blink::WebView* webview = render_view->GetWebView();
205 return webview ? GURL(webview->mainFrame()->document().url()) : GURL(); 205 return webview ? GURL(webview->mainFrame()->document().url()) : GURL();
206 } 206 }
207 207
208 } // namespace 208 } // namespace
209 209
210 namespace internal { // for testing. 210 namespace internal { // for testing.
211 211
212 // Returns an array with the RGBA color components. 212 // Returns an array with the RGBA color components.
213 v8::Handle<v8::Value> RGBAColorToArray(v8::Isolate* isolate, 213 v8::Local<v8::Value> RGBAColorToArray(v8::Isolate* isolate,
214 const RGBAColor& color) { 214 const RGBAColor& color) {
215 v8::Handle<v8::Array> color_array = v8::Array::New(isolate, 4); 215 v8::Local<v8::Array> color_array = v8::Array::New(isolate, 4);
216 color_array->Set(0, v8::Int32::New(isolate, color.r)); 216 color_array->Set(0, v8::Int32::New(isolate, color.r));
217 color_array->Set(1, v8::Int32::New(isolate, color.g)); 217 color_array->Set(1, v8::Int32::New(isolate, color.g));
218 color_array->Set(2, v8::Int32::New(isolate, color.b)); 218 color_array->Set(2, v8::Int32::New(isolate, color.b));
219 color_array->Set(3, v8::Int32::New(isolate, color.a)); 219 color_array->Set(3, v8::Int32::New(isolate, color.a));
220 return color_array; 220 return color_array;
221 } 221 }
222 222
223 // Resolves a possibly relative URL using the current URL. 223 // Resolves a possibly relative URL using the current URL.
224 GURL ResolveURL(const GURL& current_url, 224 GURL ResolveURL(const GURL& current_url,
225 const base::string16& possibly_relative_url) { 225 const base::string16& possibly_relative_url) {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 "}"; 380 "}";
381 381
382 // ---------------------------------------------------------------------------- 382 // ----------------------------------------------------------------------------
383 383
384 class SearchBoxExtensionWrapper : public v8::Extension { 384 class SearchBoxExtensionWrapper : public v8::Extension {
385 public: 385 public:
386 explicit SearchBoxExtensionWrapper(const base::StringPiece& code); 386 explicit SearchBoxExtensionWrapper(const base::StringPiece& code);
387 387
388 // Allows v8's javascript code to call the native functions defined 388 // Allows v8's javascript code to call the native functions defined
389 // in this class for window.chrome. 389 // in this class for window.chrome.
390 v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate( 390 v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
391 v8::Isolate*, 391 v8::Isolate*,
392 v8::Handle<v8::String> name) override; 392 v8::Local<v8::String> name) override;
393 393
394 // Helper function to find the RenderView. May return NULL. 394 // Helper function to find the RenderView. May return NULL.
395 static content::RenderView* GetRenderView(); 395 static content::RenderView* GetRenderView();
396 396
397 // Sends a Chrome identity check to the browser. 397 // Sends a Chrome identity check to the browser.
398 static void CheckIsUserSignedInToChromeAs( 398 static void CheckIsUserSignedInToChromeAs(
399 const v8::FunctionCallbackInfo<v8::Value>& args); 399 const v8::FunctionCallbackInfo<v8::Value>& args);
400 400
401 // Checks whether the user sync his history. 401 // Checks whether the user sync his history.
402 static void CheckIsUserSyncingHistory( 402 static void CheckIsUserSyncingHistory(
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 // static 510 // static
511 v8::Extension* SearchBoxExtension::Get() { 511 v8::Extension* SearchBoxExtension::Get() {
512 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). 512 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance().
513 GetRawDataResource(IDR_SEARCHBOX_API)); 513 GetRawDataResource(IDR_SEARCHBOX_API));
514 } 514 }
515 515
516 // static 516 // static
517 bool SearchBoxExtension::PageSupportsInstant(blink::WebFrame* frame) { 517 bool SearchBoxExtension::PageSupportsInstant(blink::WebFrame* frame) {
518 if (!frame) return false; 518 if (!frame) return false;
519 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 519 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
520 v8::Handle<v8::Value> v = frame->executeScriptAndReturnValue( 520 v8::Local<v8::Value> v = frame->executeScriptAndReturnValue(
521 blink::WebScriptSource(kSupportsInstantScript)); 521 blink::WebScriptSource(kSupportsInstantScript));
522 return !v.IsEmpty() && v->BooleanValue(); 522 return !v.IsEmpty() && v->BooleanValue();
523 } 523 }
524 524
525 // static 525 // static
526 void SearchBoxExtension::DispatchChromeIdentityCheckResult( 526 void SearchBoxExtension::DispatchChromeIdentityCheckResult(
527 blink::WebFrame* frame, 527 blink::WebFrame* frame,
528 const base::string16& identity, 528 const base::string16& identity,
529 bool identity_match) { 529 bool identity_match) {
530 std::string escaped_identity = base::GetQuotedJSONString(identity); 530 std::string escaped_identity = base::GetQuotedJSONString(identity);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 void SearchBoxExtension::DispatchToggleVoiceSearch( 595 void SearchBoxExtension::DispatchToggleVoiceSearch(
596 blink::WebFrame* frame) { 596 blink::WebFrame* frame) {
597 Dispatch(frame, kDispatchToggleVoiceSearchScript); 597 Dispatch(frame, kDispatchToggleVoiceSearchScript);
598 } 598 }
599 599
600 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper( 600 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper(
601 const base::StringPiece& code) 601 const base::StringPiece& code)
602 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) { 602 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) {
603 } 603 }
604 604
605 v8::Handle<v8::FunctionTemplate> 605 v8::Local<v8::FunctionTemplate>
606 SearchBoxExtensionWrapper::GetNativeFunctionTemplate( 606 SearchBoxExtensionWrapper::GetNativeFunctionTemplate(
607 v8::Isolate* isolate, 607 v8::Isolate* isolate,
608 v8::Handle<v8::String> name) { 608 v8::Local<v8::String> name) {
609 if (name->Equals( 609 if (name->Equals(
610 v8::String::NewFromUtf8(isolate, "CheckIsUserSignedInToChromeAs"))) 610 v8::String::NewFromUtf8(isolate, "CheckIsUserSignedInToChromeAs")))
611 return v8::FunctionTemplate::New(isolate, CheckIsUserSignedInToChromeAs); 611 return v8::FunctionTemplate::New(isolate, CheckIsUserSignedInToChromeAs);
612 if (name->Equals( 612 if (name->Equals(
613 v8::String::NewFromUtf8(isolate, "CheckIsUserSyncingHistory"))) 613 v8::String::NewFromUtf8(isolate, "CheckIsUserSyncingHistory")))
614 return v8::FunctionTemplate::New(isolate, CheckIsUserSyncingHistory); 614 return v8::FunctionTemplate::New(isolate, CheckIsUserSyncingHistory);
615 if (name->Equals(v8::String::NewFromUtf8(isolate, "DeleteMostVisitedItem"))) 615 if (name->Equals(v8::String::NewFromUtf8(isolate, "DeleteMostVisitedItem")))
616 return v8::FunctionTemplate::New(isolate, DeleteMostVisitedItem); 616 return v8::FunctionTemplate::New(isolate, DeleteMostVisitedItem);
617 if (name->Equals(v8::String::NewFromUtf8(isolate, "Focus"))) 617 if (name->Equals(v8::String::NewFromUtf8(isolate, "Focus")))
618 return v8::FunctionTemplate::New(isolate, Focus); 618 return v8::FunctionTemplate::New(isolate, Focus);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 if (name->Equals(v8::String::NewFromUtf8(isolate, "StopCapturingKeyStrokes"))) 664 if (name->Equals(v8::String::NewFromUtf8(isolate, "StopCapturingKeyStrokes")))
665 return v8::FunctionTemplate::New(isolate, StopCapturingKeyStrokes); 665 return v8::FunctionTemplate::New(isolate, StopCapturingKeyStrokes);
666 if (name->Equals( 666 if (name->Equals(
667 v8::String::NewFromUtf8(isolate, "UndoAllMostVisitedDeletions"))) 667 v8::String::NewFromUtf8(isolate, "UndoAllMostVisitedDeletions")))
668 return v8::FunctionTemplate::New(isolate, UndoAllMostVisitedDeletions); 668 return v8::FunctionTemplate::New(isolate, UndoAllMostVisitedDeletions);
669 if (name->Equals(v8::String::NewFromUtf8(isolate, "UndoMostVisitedDeletion"))) 669 if (name->Equals(v8::String::NewFromUtf8(isolate, "UndoMostVisitedDeletion")))
670 return v8::FunctionTemplate::New(isolate, UndoMostVisitedDeletion); 670 return v8::FunctionTemplate::New(isolate, UndoMostVisitedDeletion);
671 if (name->Equals( 671 if (name->Equals(
672 v8::String::NewFromUtf8(isolate, "GetDisplayInstantResults"))) 672 v8::String::NewFromUtf8(isolate, "GetDisplayInstantResults")))
673 return v8::FunctionTemplate::New(isolate, GetDisplayInstantResults); 673 return v8::FunctionTemplate::New(isolate, GetDisplayInstantResults);
674 return v8::Handle<v8::FunctionTemplate>(); 674 return v8::Local<v8::FunctionTemplate>();
675 } 675 }
676 676
677 // static 677 // static
678 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() { 678 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() {
679 blink::WebLocalFrame* webframe = 679 blink::WebLocalFrame* webframe =
680 blink::WebLocalFrame::frameForCurrentContext(); 680 blink::WebLocalFrame::frameForCurrentContext();
681 if (!webframe) return NULL; 681 if (!webframe) return NULL;
682 682
683 blink::WebView* webview = webframe->view(); 683 blink::WebView* webview = webframe->view();
684 if (!webview) return NULL; // can happen during closing 684 if (!webview) return NULL; // can happen during closing
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 content::RenderView* render_view = GetRenderView(); 782 content::RenderView* render_view = GetRenderView();
783 if (!render_view) 783 if (!render_view)
784 return; 784 return;
785 DVLOG(1) << render_view << " GetMostVisitedItems"; 785 DVLOG(1) << render_view << " GetMostVisitedItems";
786 786
787 const SearchBox* search_box = SearchBox::Get(render_view); 787 const SearchBox* search_box = SearchBox::Get(render_view);
788 788
789 std::vector<InstantMostVisitedItemIDPair> instant_mv_items; 789 std::vector<InstantMostVisitedItemIDPair> instant_mv_items;
790 search_box->GetMostVisitedItems(&instant_mv_items); 790 search_box->GetMostVisitedItems(&instant_mv_items);
791 v8::Isolate* isolate = args.GetIsolate(); 791 v8::Isolate* isolate = args.GetIsolate();
792 v8::Handle<v8::Array> v8_mv_items = 792 v8::Local<v8::Array> v8_mv_items =
793 v8::Array::New(isolate, instant_mv_items.size()); 793 v8::Array::New(isolate, instant_mv_items.size());
794 for (size_t i = 0; i < instant_mv_items.size(); ++i) { 794 for (size_t i = 0; i < instant_mv_items.size(); ++i) {
795 v8_mv_items->Set(i, 795 v8_mv_items->Set(i,
796 GenerateMostVisitedItem(isolate, 796 GenerateMostVisitedItem(isolate,
797 render_view->GetRoutingID(), 797 render_view->GetRoutingID(),
798 instant_mv_items[i].first, 798 instant_mv_items[i].first,
799 instant_mv_items[i].second)); 799 instant_mv_items[i].second));
800 } 800 }
801 args.GetReturnValue().Set(v8_mv_items); 801 args.GetReturnValue().Set(v8_mv_items);
802 } 802 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 845
846 // static 846 // static
847 void SearchBoxExtensionWrapper::GetSearchRequestParams( 847 void SearchBoxExtensionWrapper::GetSearchRequestParams(
848 const v8::FunctionCallbackInfo<v8::Value>& args) { 848 const v8::FunctionCallbackInfo<v8::Value>& args) {
849 content::RenderView* render_view = GetRenderView(); 849 content::RenderView* render_view = GetRenderView();
850 if (!render_view) return; 850 if (!render_view) return;
851 851
852 const EmbeddedSearchRequestParams& params = 852 const EmbeddedSearchRequestParams& params =
853 SearchBox::Get(render_view)->GetEmbeddedSearchRequestParams(); 853 SearchBox::Get(render_view)->GetEmbeddedSearchRequestParams();
854 v8::Isolate* isolate = args.GetIsolate(); 854 v8::Isolate* isolate = args.GetIsolate();
855 v8::Handle<v8::Object> data = v8::Object::New(isolate); 855 v8::Local<v8::Object> data = v8::Object::New(isolate);
856 if (!params.search_query.empty()) { 856 if (!params.search_query.empty()) {
857 data->Set(v8::String::NewFromUtf8(isolate, kSearchQueryKey), 857 data->Set(v8::String::NewFromUtf8(isolate, kSearchQueryKey),
858 UTF16ToV8String(isolate, params.search_query)); 858 UTF16ToV8String(isolate, params.search_query));
859 } 859 }
860 if (!params.original_query.empty()) { 860 if (!params.original_query.empty()) {
861 data->Set(v8::String::NewFromUtf8(isolate, kOriginalQueryKey), 861 data->Set(v8::String::NewFromUtf8(isolate, kOriginalQueryKey),
862 UTF16ToV8String(isolate, params.original_query)); 862 UTF16ToV8String(isolate, params.original_query));
863 } 863 }
864 if (!params.rlz_parameter_value.empty()) { 864 if (!params.rlz_parameter_value.empty()) {
865 data->Set(v8::String::NewFromUtf8(isolate, kRLZParameterKey), 865 data->Set(v8::String::NewFromUtf8(isolate, kRLZParameterKey),
(...skipping 21 matching lines...) Expand all
887 887
888 // static 888 // static
889 void SearchBoxExtensionWrapper::GetSuggestionToPrefetch( 889 void SearchBoxExtensionWrapper::GetSuggestionToPrefetch(
890 const v8::FunctionCallbackInfo<v8::Value>& args) { 890 const v8::FunctionCallbackInfo<v8::Value>& args) {
891 content::RenderView* render_view = GetRenderView(); 891 content::RenderView* render_view = GetRenderView();
892 if (!render_view) return; 892 if (!render_view) return;
893 893
894 const InstantSuggestion& suggestion = 894 const InstantSuggestion& suggestion =
895 SearchBox::Get(render_view)->suggestion(); 895 SearchBox::Get(render_view)->suggestion();
896 v8::Isolate* isolate = args.GetIsolate(); 896 v8::Isolate* isolate = args.GetIsolate();
897 v8::Handle<v8::Object> data = v8::Object::New(isolate); 897 v8::Local<v8::Object> data = v8::Object::New(isolate);
898 data->Set(v8::String::NewFromUtf8(isolate, "text"), 898 data->Set(v8::String::NewFromUtf8(isolate, "text"),
899 UTF16ToV8String(isolate, suggestion.text)); 899 UTF16ToV8String(isolate, suggestion.text));
900 data->Set(v8::String::NewFromUtf8(isolate, "metadata"), 900 data->Set(v8::String::NewFromUtf8(isolate, "metadata"),
901 UTF8ToV8String(isolate, suggestion.metadata)); 901 UTF8ToV8String(isolate, suggestion.metadata));
902 args.GetReturnValue().Set(data); 902 args.GetReturnValue().Set(data);
903 } 903 }
904 904
905 // static 905 // static
906 void SearchBoxExtensionWrapper::GetThemeBackgroundInfo( 906 void SearchBoxExtensionWrapper::GetThemeBackgroundInfo(
907 const v8::FunctionCallbackInfo<v8::Value>& args) { 907 const v8::FunctionCallbackInfo<v8::Value>& args) {
908 content::RenderView* render_view = GetRenderView(); 908 content::RenderView* render_view = GetRenderView();
909 if (!render_view) return; 909 if (!render_view) return;
910 910
911 DVLOG(1) << render_view << " GetThemeBackgroundInfo"; 911 DVLOG(1) << render_view << " GetThemeBackgroundInfo";
912 const ThemeBackgroundInfo& theme_info = 912 const ThemeBackgroundInfo& theme_info =
913 SearchBox::Get(render_view)->GetThemeBackgroundInfo(); 913 SearchBox::Get(render_view)->GetThemeBackgroundInfo();
914 v8::Isolate* isolate = args.GetIsolate(); 914 v8::Isolate* isolate = args.GetIsolate();
915 v8::Handle<v8::Object> info = v8::Object::New(isolate); 915 v8::Local<v8::Object> info = v8::Object::New(isolate);
916 916
917 info->Set(v8::String::NewFromUtf8(isolate, "usingDefaultTheme"), 917 info->Set(v8::String::NewFromUtf8(isolate, "usingDefaultTheme"),
918 v8::Boolean::New(isolate, theme_info.using_default_theme)); 918 v8::Boolean::New(isolate, theme_info.using_default_theme));
919 919
920 // The theme background color is in RGBA format "rgba(R,G,B,A)" where R, G and 920 // The theme background color is in RGBA format "rgba(R,G,B,A)" where R, G and
921 // B are between 0 and 255 inclusive, and A is a double between 0 and 1 921 // B are between 0 and 255 inclusive, and A is a double between 0 and 1
922 // inclusive. 922 // inclusive.
923 // This is the CSS "background-color" format. 923 // This is the CSS "background-color" format.
924 // Value is always valid. 924 // Value is always valid.
925 // TODO(jfweitz): Remove this field after GWS is modified to use the new 925 // TODO(jfweitz): Remove this field after GWS is modified to use the new
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 if (!render_view) return; 1273 if (!render_view) return;
1274 1274
1275 bool display_instant_results = 1275 bool display_instant_results =
1276 SearchBox::Get(render_view)->display_instant_results(); 1276 SearchBox::Get(render_view)->display_instant_results();
1277 DVLOG(1) << render_view << " GetDisplayInstantResults" << 1277 DVLOG(1) << render_view << " GetDisplayInstantResults" <<
1278 display_instant_results; 1278 display_instant_results;
1279 args.GetReturnValue().Set(display_instant_results); 1279 args.GetReturnValue().Set(display_instant_results);
1280 } 1280 }
1281 1281
1282 } // namespace extensions_v8 1282 } // namespace extensions_v8
OLDNEW
« no previous file with comments | « chrome/renderer/plugins/chrome_plugin_placeholder.cc ('k') | chrome/renderer/translate/translate_script_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698