Chromium Code Reviews| Index: chrome/renderer/extensions/extension_process_bindings.cc |
| =================================================================== |
| --- chrome/renderer/extensions/extension_process_bindings.cc (revision 20629) |
| +++ chrome/renderer/extensions/extension_process_bindings.cc (working copy) |
| @@ -25,6 +25,9 @@ |
| 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 @@ |
| 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 @@ |
| 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,12 +80,16 @@ |
| } |
| 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); |
| DCHECK(contexts.size() > 0); |
| @@ -97,7 +111,32 @@ |
| 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(); |
|
Matt Perry
2009/07/14 21:17:48
nit: no need to wrap this
|
| + PageActionIdMap::const_iterator it = |
| + page_action_map->find(extension_id); |
| + |
| + std::vector<std::string> page_actions; |
|
Matt Perry
2009/07/14 21:17:48
This creates a copy of the vector. Use a pointer
|
| + size_t size = 0; |
| + if (it != page_action_map->end()) { |
| + page_actions = it->second; |
| + size = page_actions.size(); |
| + } |
| + |
| + v8::Local<v8::Array> page_action_vector = v8::Array::New(size); |
|
Matt Perry
2009/07/14 21:17:48
nit: "vector" is lying - it's an array
|
| + for (size_t i = 0; i < size; ++i) { |
| + std::string page_action_id = page_actions[i]; |
|
Matt Perry
2009/07/14 21:17:48
nit: wasteful copy. use const ref
|
| + page_action_vector->Set(v8::Integer::New(i), |
| + v8::String::New(page_action_id.c_str())); |
| + } |
| + |
| + return page_action_vector; |
| + } |
| + |
| // 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 +198,16 @@ |
| 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); |
| + } |
| +} |
| Property changes on: chrome\renderer\extensions\extension_process_bindings.cc |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |