diff options
author | dcblack@chromium.org <dcblack@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-18 02:05:29 +0000 |
---|---|---|
committer | dcblack@chromium.org <dcblack@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-18 02:05:29 +0000 |
commit | 120e3de4a1124d2694cb68daf538b05db171cb64 (patch) | |
tree | 6f04011117be5f17aad01ca712bf05d49e972119 /chrome/renderer/searchbox_extension.cc | |
parent | 2bf23365000aba59e63c8f8b757a5388b1f9caa6 (diff) | |
download | chromium_src-120e3de4a1124d2694cb68daf538b05db171cb64.zip chromium_src-120e3de4a1124d2694cb68daf538b05db171cb64.tar.gz chromium_src-120e3de4a1124d2694cb68daf538b05db171cb64.tar.bz2 |
Move Chrome-Instant JS into a new file.
Move the code that defines the API for Chrome-Instant into a separate file in preparation for extending it.
BUG=134865
TEST=No benavior change - covered by existing tests.
R=sky@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10785046
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147162 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/searchbox_extension.cc')
-rw-r--r-- | chrome/renderer/searchbox_extension.cc | 48 |
1 files changed, 11 insertions, 37 deletions
diff --git a/chrome/renderer/searchbox_extension.cc b/chrome/renderer/searchbox_extension.cc index 1135265..29bddcf 100644 --- a/chrome/renderer/searchbox_extension.cc +++ b/chrome/renderer/searchbox_extension.cc @@ -7,14 +7,17 @@ #include <string> #include <vector> +#include "base/basictypes.h" #include "base/command_line.h" #include "base/string_split.h" #include "base/stringprintf.h" #include "chrome/renderer/searchbox.h" #include "content/public/renderer/render_view.h" +#include "grit/renderer_resources.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" +#include "ui/base/resource/resource_bundle.h" #include "v8/include/v8.h" using WebKit::WebFrame; @@ -26,39 +29,6 @@ namespace extensions_v8 { static const char kSearchBoxExtensionName[] = "v8/SearchBox"; -static const char kSearchBoxExtensionScript[] = - "var chrome;" - "if (!chrome)" - " chrome = {};" - "if (!chrome.searchBox) {" - " chrome.searchBox = new function() {" - " native function GetValue();" - " native function GetVerbatim();" - " native function GetSelectionStart();" - " native function GetSelectionEnd();" - " native function GetX();" - " native function GetY();" - " native function GetWidth();" - " native function GetHeight();" - " native function SetSuggestions();" - " this.__defineGetter__('value', GetValue);" - " this.__defineGetter__('verbatim', GetVerbatim);" - " this.__defineGetter__('selectionStart', GetSelectionStart);" - " this.__defineGetter__('selectionEnd', GetSelectionEnd);" - " this.__defineGetter__('x', GetX);" - " this.__defineGetter__('y', GetY);" - " this.__defineGetter__('width', GetWidth);" - " this.__defineGetter__('height', GetHeight);" - " this.setSuggestions = function(text) {" - " SetSuggestions(text);" - " };" - " this.onchange = null;" - " this.onsubmit = null;" - " this.oncancel = null;" - " this.onresize = null;" - " };" - "}"; - static const char kDispatchChangeEventScript[] = "if (window.chrome &&" " window.chrome.searchBox &&" @@ -152,7 +122,7 @@ static const char kInitScript[] = class SearchBoxExtensionWrapper : public v8::Extension { public: - SearchBoxExtensionWrapper(); + explicit SearchBoxExtensionWrapper(const base::StringPiece& code); // Allows v8's javascript code to call the native functions defined // in this class for window.chrome. @@ -197,8 +167,9 @@ class SearchBoxExtensionWrapper : public v8::Extension { DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper); }; -SearchBoxExtensionWrapper::SearchBoxExtensionWrapper() - : v8::Extension(kSearchBoxExtensionName, kSearchBoxExtensionScript) {} +SearchBoxExtensionWrapper::SearchBoxExtensionWrapper( + const base::StringPiece& code) + : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) {} v8::Handle<v8::FunctionTemplate> SearchBoxExtensionWrapper::GetNativeFunction( v8::Handle<v8::String> name) { @@ -437,7 +408,10 @@ bool SearchBoxExtension::PageSupportsInstant(WebFrame* frame) { // static v8::Extension* SearchBoxExtension::Get() { - return new SearchBoxExtensionWrapper(); + const base::StringPiece code = + ResourceBundle::GetSharedInstance().GetRawDataResource( + IDR_SEARCHBOX_API, ui::SCALE_FACTOR_NONE); + return new SearchBoxExtensionWrapper(code); } } // namespace extensions_v8 |