diff options
Diffstat (limited to 'chrome/renderer/extensions')
-rw-r--r-- | chrome/renderer/extensions/extension_process_bindings.cc | 56 | ||||
-rw-r--r-- | chrome/renderer/extensions/extension_process_bindings.h | 5 |
2 files changed, 58 insertions, 3 deletions
diff --git a/chrome/renderer/extensions/extension_process_bindings.cc b/chrome/renderer/extensions/extension_process_bindings.cc index e68fb82..49b12b9 100644 --- a/chrome/renderer/extensions/extension_process_bindings.cc +++ b/chrome/renderer/extensions/extension_process_bindings.cc @@ -25,6 +25,9 @@ using bindings_utils::ExtensionBase; namespace { +// A map of extension ID to vector of page action ids. +typedef std::map< std::string, std::vector<std::string> > PageActionIdMap; + const char kExtensionName[] = "chrome/ExtensionProcessBindings"; const char* kExtensionDeps[] = { BaseJsV8Extension::kName, @@ -35,12 +38,17 @@ const char* kExtensionDeps[] = { struct SingletonData { std::set<std::string> function_names_; + PageActionIdMap page_action_ids_; }; static std::set<std::string>* GetFunctionNameSet() { return &Singleton<SingletonData>()->function_names_; } +static PageActionIdMap* GetPageActionMap() { + return &Singleton<SingletonData>()->page_action_ids_; +} + class ExtensionImpl : public ExtensionBase { public: ExtensionImpl() : ExtensionBase( @@ -62,6 +70,8 @@ class ExtensionImpl : public ExtensionBase { return v8::FunctionTemplate::New(GetViews); } else if (name->Equals(v8::String::New("GetNextRequestId"))) { return v8::FunctionTemplate::New(GetNextRequestId); + } else if (name->Equals(v8::String::New("GetCurrentPageActions"))) { + return v8::FunctionTemplate::New(GetCurrentPageActions); } else if (names->find(*v8::String::AsciiValue(name)) != names->end()) { return v8::FunctionTemplate::New(StartRequest, name); } @@ -70,11 +80,15 @@ class ExtensionImpl : public ExtensionBase { } private: - static v8::Handle<v8::Value> GetViews(const v8::Arguments& args) { + static std::string ExtensionIdFromCurrentContext() { RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext(); DCHECK(renderview); GURL url = renderview->webview()->GetMainFrame()->GetURL(); - std::string extension_id = url.host(); + return url.host(); + } + + static v8::Handle<v8::Value> GetViews(const v8::Arguments& args) { + std::string extension_id = ExtensionIdFromCurrentContext(); ContextList contexts = bindings_utils::GetContextsForExtension(extension_id); @@ -97,7 +111,30 @@ class ExtensionImpl : public ExtensionBase { static int next_request_id = 0; return v8::Integer::New(next_request_id++); } - + + static v8::Handle<v8::Value> GetCurrentPageActions( + const v8::Arguments& args) { + std::string extension_id = ExtensionIdFromCurrentContext(); + PageActionIdMap* page_action_map = GetPageActionMap(); + PageActionIdMap::const_iterator it = page_action_map->find(extension_id); + + const std::vector<std::string>* page_actions = NULL; + size_t size = 0; + if (it != page_action_map->end()) { + page_actions = &it->second; + size = page_actions->size(); + } + + v8::Local<v8::Array> page_action_array = v8::Array::New(size); + for (size_t i = 0; i < size; ++i) { + const std::string& page_action_id = (*page_actions)[i]; + page_action_array->Set(v8::Integer::New(i), + v8::String::New(page_action_id.c_str())); + } + + return page_action_array; + } + // Starts an API request to the browser, with an optional callback. The // callback will be dispatched to EventBindings::HandleResponse. static v8::Handle<v8::Value> StartRequest(const v8::Arguments& args) { @@ -159,3 +196,16 @@ void ExtensionProcessBindings::HandleResponse(int request_id, bool success, GetPendingRequestMap().erase(request_id); } + +// static +void ExtensionProcessBindings::SetPageActions( + const std::string& extension_id, + const std::vector<std::string>& page_actions) { + PageActionIdMap& page_action_map = *GetPageActionMap(); + if (!page_actions.empty()) { + page_action_map[extension_id] = page_actions; + } else { + if (page_action_map.find(extension_id) != page_action_map.end()) + page_action_map.erase(extension_id); + } +} diff --git a/chrome/renderer/extensions/extension_process_bindings.h b/chrome/renderer/extensions/extension_process_bindings.h index 9e2c814..1ce6b47 100644 --- a/chrome/renderer/extensions/extension_process_bindings.h +++ b/chrome/renderer/extensions/extension_process_bindings.h @@ -7,6 +7,7 @@ #ifndef CHROME_RENDERER_EXTENSIONS_EXTENSION_PROCESS_BINDINGS_H_ #define CHROME_RENDERER_EXTENSIONS_EXTENSION_PROCESS_BINDINGS_H_ +#include <map> #include <string> #include <vector> @@ -21,6 +22,10 @@ class ExtensionProcessBindings { static void HandleResponse(int request_id, bool success, const std::string& response, const std::string& error); + + // Sets the page action ids for a particular extension. + static void SetPageActions(const std::string& extension_id, + const std::vector<std::string>& page_actions); }; #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_PROCESS_BINDINGS_H_ |