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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/searchbox/searchbox_extension.cc
diff --git a/chrome/renderer/searchbox/searchbox_extension.cc b/chrome/renderer/searchbox/searchbox_extension.cc
index c2aa8108a1ff8ac074d22f41b804859c1fcb5c3a..d98efa58f28b500f0ad340c19d04de94e1b42b45 100644
--- a/chrome/renderer/searchbox/searchbox_extension.cc
+++ b/chrome/renderer/searchbox/searchbox_extension.cc
@@ -118,6 +118,25 @@ static const char kDispatchContextChangeEventScript[] =
" true;"
"}";
+static const char kDispatchThemeChangeEventScript[] =
+ "if (window.chrome &&"
+ " window.chrome.searchBox &&"
+ " window.chrome.searchBox.onthemechange &&"
+ " typeof window.chrome.searchBox.onthemechange == 'function') {"
+ " window.chrome.searchBox.onthemechange();"
+ " true;"
+ "}";
+
+static const char kDispatchThemeAreaHeightChangeEventScript[] =
+ "if (window.chrome &&"
+ " window.chrome.searchBox &&"
+ " window.chrome.searchBox.onthemeareaheightchange &&"
+ " typeof window.chrome.searchBox.onthemeareaheightchange =="
+ " 'function') {"
+ " window.chrome.searchBox.onthemeareaheightchange();"
+ " true;"
+ "}";
+
// ----------------------------------------------------------------------------
class SearchBoxExtensionWrapper : public v8::Extension {
@@ -167,6 +186,18 @@ class SearchBoxExtensionWrapper : public v8::Extension {
// Gets the current session context.
static v8::Handle<v8::Value> GetContext(const v8::Arguments& args);
+ // Gets the background info of the theme currently adopted by browser.
+ // Call only when overlay is showing NTP page.
+ static v8::Handle<v8::Value> GetThemeBackgroundInfo(
+ const v8::Arguments& args);
+
+ // Gets the theme area height that the entire theme background image should
+ // fill up.
+ // Call only when overlay is showing NTP page and GetThemeBackgroundInfo
+ // returns a non-empty image_url and an image_vertical_alignment that is not
+ // "top".
+ static v8::Handle<v8::Value> GetThemeAreaHeight(const v8::Arguments& args);
+
// Navigates the window to a URL represented by either a URL string or a
// restricted ID.
static v8::Handle<v8::Value> NavigateContentWindow(const v8::Arguments& args);
@@ -222,6 +253,10 @@ v8::Handle<v8::FunctionTemplate> SearchBoxExtensionWrapper::GetNativeFunction(
return v8::FunctionTemplate::New(GetAutocompleteResults);
if (name->Equals(v8::String::New("GetContext")))
return v8::FunctionTemplate::New(GetContext);
+ if (name->Equals(v8::String::New("GetThemeBackgroundInfo")))
+ return v8::FunctionTemplate::New(GetThemeBackgroundInfo);
+ if (name->Equals(v8::String::New("GetThemeAreaHeight")))
+ return v8::FunctionTemplate::New(GetThemeAreaHeight);
if (name->Equals(v8::String::New("NavigateContentWindow")))
return v8::FunctionTemplate::New(NavigateContentWindow);
if (name->Equals(v8::String::New("SetSuggestions")))
@@ -367,6 +402,38 @@ v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetContext(
return context;
}
+v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetThemeBackgroundInfo(
+ const v8::Arguments& args) {
+ content::RenderView* render_view = GetRenderView();
+ if (!render_view) return v8::Undefined();
+
+ const ThemeBackgroundInfo& theme_info =
+ SearchBox::Get(render_view)->GetThemeBackgroundInfo();
+ v8::Handle<v8::Object> info = v8::Object::New();
+ 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
+ UTF16ToV8String(theme_info.color_rgba));
+ info->Set(v8::String::New("imageUrl"),
+ UTF16ToV8String(theme_info.image_url));
+ info->Set(v8::String::New("imageHorizontalAlignment"),
+ UTF16ToV8String(theme_info.image_horizontal_alignment));
+ info->Set(v8::String::New("imageVerticalAlignment"),
+ UTF16ToV8String(theme_info.image_vertical_alignment));
+ info->Set(v8::String::New("imageTiling"),
+ UTF16ToV8String(theme_info.image_tiling));
+ info->Set(v8::String::New("imageHeight"),
+ v8::Int32::New(theme_info.image_height));
+ return info;
+}
+
+
+v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetThemeAreaHeight(
+ const v8::Arguments& args) {
+ content::RenderView* render_view = GetRenderView();
+ if (!render_view) return v8::Undefined();
+
+ return v8::Int32::New(SearchBox::Get(render_view)->GetThemeAreaHeight());
+}
+
// static
v8::Handle<v8::Value> SearchBoxExtensionWrapper::NavigateContentWindow(
const v8::Arguments& args) {
@@ -601,6 +668,17 @@ void SearchBoxExtension::DispatchContextChange(WebKit::WebFrame* frame) {
}
// static
+void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) {
+ Dispatch(frame, kDispatchThemeChangeEventScript);
+}
+
+// static
+void SearchBoxExtension::DispatchThemeAreaHeightChange(
+ WebKit::WebFrame* frame) {
+ Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript);
+}
+
+// static
v8::Extension* SearchBoxExtension::Get() {
return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance().
GetRawDataResource(IDR_SEARCHBOX_API));
« 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