| Index: chrome/renderer/searchbox/searchbox_extension.cc
|
| diff --git a/chrome/renderer/searchbox/searchbox_extension.cc b/chrome/renderer/searchbox/searchbox_extension.cc
|
| index 54e5e911b75450e21b162d1bd4c96edff2df8d7f..dfffd57aebe0d3488b83f4156ffa730eec2b52bf 100644
|
| --- a/chrome/renderer/searchbox/searchbox_extension.cc
|
| +++ b/chrome/renderer/searchbox/searchbox_extension.cc
|
| @@ -136,6 +136,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 {
|
| @@ -188,6 +207,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);
|
| @@ -245,6 +276,10 @@ v8::Handle<v8::FunctionTemplate> SearchBoxExtensionWrapper::GetNativeFunction(
|
| return v8::FunctionTemplate::New(GetIsFocused);
|
| 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")))
|
| @@ -399,6 +434,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"),
|
| + 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) {
|
| @@ -643,6 +710,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));
|
|
|