summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-28 19:56:51 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-28 19:56:51 +0000
commit703e807a70e50e32b3c4821c84c23bde69f73272 (patch)
tree615d9f7d150e5ec51821a892eecc8ebdb269b447 /chrome/renderer
parenta137bdac37451b1b218cf4c43a798aa3abd4c875 (diff)
downloadchromium_src-703e807a70e50e32b3c4821c84c23bde69f73272.zip
chromium_src-703e807a70e50e32b3c4821c84c23bde69f73272.tar.gz
chromium_src-703e807a70e50e32b3c4821c84c23bde69f73272.tar.bz2
Add more of the server-side plumbing for extension APIs. Also
added getTabsForWindow() to drive it. Review URL: http://codereview.chromium.org/42680 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12744 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/extensions/extension_process_bindings.cc20
-rw-r--r--chrome/renderer/extensions/extension_process_bindings.h2
-rw-r--r--chrome/renderer/render_thread.cc7
-rw-r--r--chrome/renderer/render_thread.h1
-rw-r--r--chrome/renderer/resources/extension_process_bindings.js5
5 files changed, 33 insertions, 2 deletions
diff --git a/chrome/renderer/extensions/extension_process_bindings.cc b/chrome/renderer/extensions/extension_process_bindings.cc
index 63c0562..1802a66 100644
--- a/chrome/renderer/extensions/extension_process_bindings.cc
+++ b/chrome/renderer/extensions/extension_process_bindings.cc
@@ -19,11 +19,19 @@ class ExtensionProcessBindingsWrapper : public v8::Extension {
ExtensionProcessBindingsWrapper()
: v8::Extension(kExtensionProcessExtensionName, GetSource()) {}
+ static void SetFunctionNames(const std::vector<std::string>& names) {
+ function_names_ = new std::set<std::string>();
+ for (size_t i = 0; i < names.size(); ++i) {
+ function_names_->insert(names[i]);
+ }
+ }
+
virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
v8::Handle<v8::String> name) {
if (name->Equals(v8::String::New("GetNextCallbackId")))
return v8::FunctionTemplate::New(GetNextCallbackId);
- else if (name->Equals(v8::String::New("CreateTab")))
+ else if (function_names_->find(*v8::String::AsciiValue(name)) !=
+ function_names_->end())
return v8::FunctionTemplate::New(StartRequest, name);
return v8::Handle<v8::FunctionTemplate>();
@@ -53,7 +61,7 @@ class ExtensionProcessBindingsWrapper : public v8::Extension {
static v8::Handle<v8::Value> StartRequest(const v8::Arguments& args) {
WebFrame* webframe = WebFrame::RetrieveActiveFrame();
DCHECK(webframe) << "There should be an active frame since we just got "
- "an API called.";
+ "a native function called.";
if (!webframe) return v8::Undefined();
WebView* webview = webframe->GetView();
@@ -76,9 +84,11 @@ class ExtensionProcessBindingsWrapper : public v8::Extension {
}
static std::string* source_;
+ static std::set<std::string>* function_names_;
};
std::string* ExtensionProcessBindingsWrapper::source_;
+std::set<std::string>* ExtensionProcessBindingsWrapper::function_names_;
// static
@@ -87,6 +97,12 @@ v8::Extension* ExtensionProcessBindings::Get() {
}
// static
+void ExtensionProcessBindings::SetFunctionNames(
+ const std::vector<std::string>& names) {
+ ExtensionProcessBindingsWrapper::SetFunctionNames(names);
+}
+
+// static
void ExtensionProcessBindings::ExecuteCallbackInFrame(
WebFrame* frame, int callback_id, const std::string& response) {
std::string code = "chromium._dispatchCallback(";
diff --git a/chrome/renderer/extensions/extension_process_bindings.h b/chrome/renderer/extensions/extension_process_bindings.h
index cbdd0bd..53fe17d 100644
--- a/chrome/renderer/extensions/extension_process_bindings.h
+++ b/chrome/renderer/extensions/extension_process_bindings.h
@@ -8,6 +8,7 @@
#define CHROME_RENDERER_EXTENSIONS_EXTENSION_PROCESS_BINDINGS_H_
#include <string>
+#include <vector>
#include "v8/include/v8.h"
@@ -17,6 +18,7 @@ namespace extensions_v8 {
class ExtensionProcessBindings {
public:
+ static void SetFunctionNames(const std::vector<std::string>& names);
static v8::Extension* Get();
static void ExecuteCallbackInFrame(WebFrame* frame, int callback_id,
const std::string& response);
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc
index 165af40..01259db 100644
--- a/chrome/renderer/render_thread.cc
+++ b/chrome/renderer/render_thread.cc
@@ -147,6 +147,11 @@ void RenderThread::OnUpdateUserScripts(
user_script_slave_->UpdateScripts(scripts);
}
+void RenderThread::OnSetExtensionFunctionNames(
+ const std::vector<std::string>& names) {
+ extensions_v8::ExtensionProcessBindings::SetFunctionNames(names);
+}
+
void RenderThread::OnControlMessageReceived(const IPC::Message& msg) {
IPC_BEGIN_MESSAGE_MAP(RenderThread, msg)
IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_NewTable, OnUpdateVisitedLinks)
@@ -161,6 +166,8 @@ void RenderThread::OnControlMessageReceived(const IPC::Message& msg) {
OnGetCacheResourceStats)
IPC_MESSAGE_HANDLER(ViewMsg_UserScripts_NewScripts,
OnUpdateUserScripts)
+ IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetFunctionNames,
+ OnSetExtensionFunctionNames)
IPC_END_MESSAGE_MAP()
}
diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h
index 1f215dd..0c1290c 100644
--- a/chrome/renderer/render_thread.h
+++ b/chrome/renderer/render_thread.h
@@ -107,6 +107,7 @@ class RenderThread : public RenderThreadBase,
void OnUpdateVisitedLinks(base::SharedMemoryHandle table);
void OnUpdateUserScripts(base::SharedMemoryHandle table);
+ void OnSetExtensionFunctionNames(const std::vector<std::string>& names);
void OnSetNextPageID(int32 next_page_id);
void OnCreateNewView(gfx::NativeViewId parent_hwnd,
ModalDialogEvent modal_dialog_event,
diff --git a/chrome/renderer/resources/extension_process_bindings.js b/chrome/renderer/resources/extension_process_bindings.js
index 3031d85..b109a76 100644
--- a/chrome/renderer/resources/extension_process_bindings.js
+++ b/chrome/renderer/resources/extension_process_bindings.js
@@ -64,6 +64,11 @@ var chromium;
// Tabs
chromium.tabs = {};
+ // TODO(aa): This should eventually take an optional windowId param.
+ chromium.tabs.getTabsForWindow = function(callback) {
+ native function GetTabsForWindow();
+ sendRequest(GetTabsForWindow, null, callback);
+ };
chromium.tabs.createTab = function(tab, callback) {
native function CreateTab();
sendRequest(CreateTab, tab, callback);