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

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

Issue 11413018: alternate ntp: implement searchbox api for instant overlay to adopt themes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed scott's comments Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/stringprintf.h" 7 #include "base/stringprintf.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/renderer/searchbox/searchbox.h" 9 #include "chrome/renderer/searchbox/searchbox.h"
10 #include "content/public/renderer/render_view.h" 10 #include "content/public/renderer/render_view.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 static const char kDispatchContextChangeEventScript[] = 112 static const char kDispatchContextChangeEventScript[] =
113 "if (window.chrome &&" 113 "if (window.chrome &&"
114 " window.chrome.searchBox &&" 114 " window.chrome.searchBox &&"
115 " window.chrome.searchBox.oncontextchange &&" 115 " window.chrome.searchBox.oncontextchange &&"
116 " typeof window.chrome.searchBox.oncontextchange == 'function') {" 116 " typeof window.chrome.searchBox.oncontextchange == 'function') {"
117 " window.chrome.searchBox.oncontextchange();" 117 " window.chrome.searchBox.oncontextchange();"
118 " true;" 118 " true;"
119 "}"; 119 "}";
120 120
121 static const char kDispatchThemeChangeEventScript[] =
122 "if (window.chrome &&"
123 " window.chrome.searchBox &&"
124 " window.chrome.searchBox.onthemechange &&"
125 " typeof window.chrome.searchBox.onthemechange == 'function') {"
126 " window.chrome.searchBox.onthemechange();"
127 " true;"
128 "}";
129
130 static const char kDispatchThemeAreaHeightChangeEventScript[] =
131 "if (window.chrome &&"
132 " window.chrome.searchBox &&"
133 " window.chrome.searchBox.onthemeareaheightchange &&"
134 " typeof window.chrome.searchBox.onthemeareaheightchange =="
135 " 'function') {"
136 " window.chrome.searchBox.onthemeareaheightchange();"
137 " true;"
138 "}";
139
121 // ---------------------------------------------------------------------------- 140 // ----------------------------------------------------------------------------
122 141
123 class SearchBoxExtensionWrapper : public v8::Extension { 142 class SearchBoxExtensionWrapper : public v8::Extension {
124 public: 143 public:
125 explicit SearchBoxExtensionWrapper(const base::StringPiece& code); 144 explicit SearchBoxExtensionWrapper(const base::StringPiece& code);
126 145
127 // Allows v8's javascript code to call the native functions defined 146 // Allows v8's javascript code to call the native functions defined
128 // in this class for window.chrome. 147 // in this class for window.chrome.
129 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 148 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
130 v8::Handle<v8::String> name); 149 v8::Handle<v8::String> name);
(...skipping 29 matching lines...) Expand all
160 // Gets the height of the region of the search box that overlaps the window. 179 // Gets the height of the region of the search box that overlaps the window.
161 static v8::Handle<v8::Value> GetHeight(const v8::Arguments& args); 180 static v8::Handle<v8::Value> GetHeight(const v8::Arguments& args);
162 181
163 // Gets the autocomplete results from search box. 182 // Gets the autocomplete results from search box.
164 static v8::Handle<v8::Value> GetAutocompleteResults( 183 static v8::Handle<v8::Value> GetAutocompleteResults(
165 const v8::Arguments& args); 184 const v8::Arguments& args);
166 185
167 // Gets the current session context. 186 // Gets the current session context.
168 static v8::Handle<v8::Value> GetContext(const v8::Arguments& args); 187 static v8::Handle<v8::Value> GetContext(const v8::Arguments& args);
169 188
189 // Gets the background info of the theme currently adopted by browser.
190 // Call only when overlay is showing NTP page.
191 static v8::Handle<v8::Value> GetThemeBackgroundInfo(
192 const v8::Arguments& args);
193
194 // Gets the theme area height that the entire theme background image should
195 // fill up.
196 // Call only when overlay is showing NTP page and GetThemeBackgroundInfo
197 // returns a non-empty image_url and an image_vertical_alignment that is not
198 // "top".
199 static v8::Handle<v8::Value> GetThemeAreaHeight(const v8::Arguments& args);
200
170 // Navigates the window to a URL represented by either a URL string or a 201 // Navigates the window to a URL represented by either a URL string or a
171 // restricted ID. 202 // restricted ID.
172 static v8::Handle<v8::Value> NavigateContentWindow(const v8::Arguments& args); 203 static v8::Handle<v8::Value> NavigateContentWindow(const v8::Arguments& args);
173 204
174 // Sets ordered suggestions. Valid for current |value|. 205 // Sets ordered suggestions. Valid for current |value|.
175 static v8::Handle<v8::Value> SetSuggestions(const v8::Arguments& args); 206 static v8::Handle<v8::Value> SetSuggestions(const v8::Arguments& args);
176 207
177 // Sets the text to be autocompleted into the search box. 208 // Sets the text to be autocompleted into the search box.
178 static v8::Handle<v8::Value> SetQuerySuggestion(const v8::Arguments& args); 209 static v8::Handle<v8::Value> SetQuerySuggestion(const v8::Arguments& args);
179 210
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 if (name->Equals(v8::String::New("GetY"))) 246 if (name->Equals(v8::String::New("GetY")))
216 return v8::FunctionTemplate::New(GetY); 247 return v8::FunctionTemplate::New(GetY);
217 if (name->Equals(v8::String::New("GetWidth"))) 248 if (name->Equals(v8::String::New("GetWidth")))
218 return v8::FunctionTemplate::New(GetWidth); 249 return v8::FunctionTemplate::New(GetWidth);
219 if (name->Equals(v8::String::New("GetHeight"))) 250 if (name->Equals(v8::String::New("GetHeight")))
220 return v8::FunctionTemplate::New(GetHeight); 251 return v8::FunctionTemplate::New(GetHeight);
221 if (name->Equals(v8::String::New("GetAutocompleteResults"))) 252 if (name->Equals(v8::String::New("GetAutocompleteResults")))
222 return v8::FunctionTemplate::New(GetAutocompleteResults); 253 return v8::FunctionTemplate::New(GetAutocompleteResults);
223 if (name->Equals(v8::String::New("GetContext"))) 254 if (name->Equals(v8::String::New("GetContext")))
224 return v8::FunctionTemplate::New(GetContext); 255 return v8::FunctionTemplate::New(GetContext);
256 if (name->Equals(v8::String::New("GetThemeBackgroundInfo")))
257 return v8::FunctionTemplate::New(GetThemeBackgroundInfo);
258 if (name->Equals(v8::String::New("GetThemeAreaHeight")))
259 return v8::FunctionTemplate::New(GetThemeAreaHeight);
225 if (name->Equals(v8::String::New("NavigateContentWindow"))) 260 if (name->Equals(v8::String::New("NavigateContentWindow")))
226 return v8::FunctionTemplate::New(NavigateContentWindow); 261 return v8::FunctionTemplate::New(NavigateContentWindow);
227 if (name->Equals(v8::String::New("SetSuggestions"))) 262 if (name->Equals(v8::String::New("SetSuggestions")))
228 return v8::FunctionTemplate::New(SetSuggestions); 263 return v8::FunctionTemplate::New(SetSuggestions);
229 if (name->Equals(v8::String::New("SetQuerySuggestion"))) 264 if (name->Equals(v8::String::New("SetQuerySuggestion")))
230 return v8::FunctionTemplate::New(SetQuerySuggestion); 265 return v8::FunctionTemplate::New(SetQuerySuggestion);
231 if (name->Equals(v8::String::New("SetQuerySuggestionFromAutocompleteResult"))) 266 if (name->Equals(v8::String::New("SetQuerySuggestionFromAutocompleteResult")))
232 return v8::FunctionTemplate::New(SetQuerySuggestionFromAutocompleteResult); 267 return v8::FunctionTemplate::New(SetQuerySuggestionFromAutocompleteResult);
233 if (name->Equals(v8::String::New("SetQuery"))) 268 if (name->Equals(v8::String::New("SetQuery")))
234 return v8::FunctionTemplate::New(SetQuery); 269 return v8::FunctionTemplate::New(SetQuery);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 content::RenderView* render_view = GetRenderView(); 395 content::RenderView* render_view = GetRenderView();
361 if (!render_view) return v8::Undefined(); 396 if (!render_view) return v8::Undefined();
362 397
363 v8::Handle<v8::Object> context = v8::Object::New(); 398 v8::Handle<v8::Object> context = v8::Object::New();
364 context->Set( 399 context->Set(
365 v8::String::New("isNewTabPage"), 400 v8::String::New("isNewTabPage"),
366 v8::Boolean::New(SearchBox::Get(render_view)->active_tab_is_ntp())); 401 v8::Boolean::New(SearchBox::Get(render_view)->active_tab_is_ntp()));
367 return context; 402 return context;
368 } 403 }
369 404
405 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetThemeBackgroundInfo(
406 const v8::Arguments& args) {
407 content::RenderView* render_view = GetRenderView();
408 if (!render_view) return v8::Undefined();
409
410 const ThemeBackgroundInfo& theme_info =
411 SearchBox::Get(render_view)->GetThemeBackgroundInfo();
412 v8::Handle<v8::Object> info = v8::Object::New();
413 info->Set(v8::String::New("colorRgba"),
palmer 2012/11/19 18:26:51 Right, here is where your switch/case statements o
kuan 2012/11/19 22:06:07 Done, except i have the problem that i mentioned e
414 UTF16ToV8String(theme_info.color_rgba));
415 info->Set(v8::String::New("imageUrl"),
416 UTF16ToV8String(theme_info.image_url));
417 info->Set(v8::String::New("imageHorizontalAlignment"),
418 UTF16ToV8String(theme_info.image_horizontal_alignment));
419 info->Set(v8::String::New("imageVerticalAlignment"),
420 UTF16ToV8String(theme_info.image_vertical_alignment));
421 info->Set(v8::String::New("imageTiling"),
422 UTF16ToV8String(theme_info.image_tiling));
423 info->Set(v8::String::New("imageHeight"),
424 v8::Int32::New(theme_info.image_height));
425 return info;
426 }
427
428
429 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetThemeAreaHeight(
430 const v8::Arguments& args) {
431 content::RenderView* render_view = GetRenderView();
432 if (!render_view) return v8::Undefined();
433
434 return v8::Int32::New(SearchBox::Get(render_view)->GetThemeAreaHeight());
435 }
436
370 // static 437 // static
371 v8::Handle<v8::Value> SearchBoxExtensionWrapper::NavigateContentWindow( 438 v8::Handle<v8::Value> SearchBoxExtensionWrapper::NavigateContentWindow(
372 const v8::Arguments& args) { 439 const v8::Arguments& args) {
373 content::RenderView* render_view = GetRenderView(); 440 content::RenderView* render_view = GetRenderView();
374 if (!render_view || !args.Length()) return v8::Undefined(); 441 if (!render_view || !args.Length()) return v8::Undefined();
375 442
376 GURL destination_url; 443 GURL destination_url;
377 if (args[0]->IsNumber()) { 444 if (args[0]->IsNumber()) {
378 const InstantAutocompleteResult* result = SearchBox::Get(render_view)-> 445 const InstantAutocompleteResult* result = SearchBox::Get(render_view)->
379 GetAutocompleteResultWithId(args[0]->Uint32Value()); 446 GetAutocompleteResultWithId(args[0]->Uint32Value());
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 base::StringPrintf(kDispatchUpOrDownKeyPressEventScript, abs(count), 661 base::StringPrintf(kDispatchUpOrDownKeyPressEventScript, abs(count),
595 count < 0 ? ui::VKEY_UP : ui::VKEY_DOWN))); 662 count < 0 ? ui::VKEY_UP : ui::VKEY_DOWN)));
596 } 663 }
597 664
598 // static 665 // static
599 void SearchBoxExtension::DispatchContextChange(WebKit::WebFrame* frame) { 666 void SearchBoxExtension::DispatchContextChange(WebKit::WebFrame* frame) {
600 Dispatch(frame, kDispatchContextChangeEventScript); 667 Dispatch(frame, kDispatchContextChangeEventScript);
601 } 668 }
602 669
603 // static 670 // static
671 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) {
672 Dispatch(frame, kDispatchThemeChangeEventScript);
673 }
674
675 // static
676 void SearchBoxExtension::DispatchThemeAreaHeightChange(
677 WebKit::WebFrame* frame) {
678 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript);
679 }
680
681 // static
604 v8::Extension* SearchBoxExtension::Get() { 682 v8::Extension* SearchBoxExtension::Get() {
605 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). 683 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance().
606 GetRawDataResource(IDR_SEARCHBOX_API)); 684 GetRawDataResource(IDR_SEARCHBOX_API));
607 } 685 }
608 686
609 } // namespace extensions_v8 687 } // namespace extensions_v8
OLDNEW
« chrome/renderer/searchbox/searchbox.cc ('K') | « chrome/renderer/searchbox/searchbox_extension.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698