summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-15 03:24:36 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-15 03:24:36 +0000
commitcf9a246cf386c7af0fb6524ac5d025c0d4e8563a (patch)
tree914b55375eee47f6d21f2fc3f106c4ba506637ec /chrome/renderer
parent0c48c17f7ebcc0c8f79eba1aeae56d32b3c2f03f (diff)
downloadchromium_src-cf9a246cf386c7af0fb6524ac5d025c0d4e8563a.zip
chromium_src-cf9a246cf386c7af0fb6524ac5d025c0d4e8563a.tar.gz
chromium_src-cf9a246cf386c7af0fb6524ac5d025c0d4e8563a.tar.bz2
EFD now notifies EPM of renderviews created, which in turn notifies the renderer of page actions that it knows about.
Remove generic event "page-action-executed" in favor of page action specific event (sent as extension_id/page_action_id). In the bindings, we now setup events for each page action we know about so we can register for specific events, and not receive broadcast events from all page actions. To setup these events I added a GetCurrentPageActions() to extension_process_bindings.cc and a helper function GetCurrentExtensionId(). And, finally, I simplified the page action background page by removing the check to see if we are already subscribed to the feed (since we now support multiple feed readers, it doesn't make sense anymore to always check Google Reader). This check might make a comeback later in a different form. BUG=13936 TEST=The RSS sample extension should work as before. Review URL: http://codereview.chromium.org/155514 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20714 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/extensions/extension_process_bindings.cc56
-rw-r--r--chrome/renderer/extensions/extension_process_bindings.h5
-rw-r--r--chrome/renderer/render_thread.cc10
-rw-r--r--chrome/renderer/render_thread.h8
-rw-r--r--chrome/renderer/renderer_resources.grd2
-rw-r--r--chrome/renderer/resources/extension_process_bindings.js16
6 files changed, 86 insertions, 11 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_
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc
index 16b4d45..3debfac 100644
--- a/chrome/renderer/render_thread.cc
+++ b/chrome/renderer/render_thread.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -214,6 +214,12 @@ void RenderThread::OnSetExtensionFunctionNames(
ExtensionProcessBindings::SetFunctionNames(names);
}
+void RenderThread::OnPageActionsUpdated(
+ const std::string& extension_id,
+ const std::vector<std::string>& page_actions) {
+ ExtensionProcessBindings::SetPageActions(extension_id, page_actions);
+}
+
void RenderThread::OnControlMessageReceived(const IPC::Message& msg) {
// App cache messages are handled by a delegate.
if (app_cache_dispatcher_->OnMessageReceived(msg))
@@ -242,6 +248,8 @@ void RenderThread::OnControlMessageReceived(const IPC::Message& msg) {
OnSetExtensionFunctionNames)
IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache,
OnPurgePluginListCache)
+ IPC_MESSAGE_HANDLER(ViewMsg_Extension_UpdatePageActions,
+ OnPageActionsUpdated)
IPC_END_MESSAGE_MAP()
}
diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h
index 733887e..5ced914 100644
--- a/chrome/renderer/render_thread.h
+++ b/chrome/renderer/render_thread.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -70,7 +70,7 @@ class RenderThread : public RenderThreadBase,
// be accessed when running on the render thread itself
static RenderThread* current();
- // Overridded from RenderThreadBase.
+ // Overridden from RenderThreadBase.
virtual bool Send(IPC::Message* msg) {
return ChildThread::Send(msg);
}
@@ -114,7 +114,7 @@ class RenderThread : public RenderThreadBase,
private:
virtual void OnControlMessageReceived(const IPC::Message& msg);
- // Called by the thread base class
+ // Called by the thread base class.
virtual void Init();
virtual void CleanUp();
@@ -124,6 +124,8 @@ class RenderThread : public RenderThreadBase,
void OnUpdateUserScripts(base::SharedMemoryHandle table);
void OnSetExtensionFunctionNames(const std::vector<std::string>& names);
+ void OnPageActionsUpdated(const std::string& extension_id,
+ const std::vector<std::string>& page_actions);
void OnSetNextPageID(int32 next_page_id);
void OnCreateNewView(gfx::NativeViewId parent_hwnd,
ModalDialogEvent modal_dialog_event,
diff --git a/chrome/renderer/renderer_resources.grd b/chrome/renderer/renderer_resources.grd
index bdba06d..fe9b91e 100644
--- a/chrome/renderer/renderer_resources.grd
+++ b/chrome/renderer/renderer_resources.grd
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- This comment is only here because changes to resources are not picked up
-without changes to the corresponding grd file. mp1 -->
+without changes to the corresponding grd file. Zorglub1 -->
<grit latest_public_release="0" current_release="1">
<outputs>
<output filename="grit/renderer_resources.h" type="rc_header">
diff --git a/chrome/renderer/resources/extension_process_bindings.js b/chrome/renderer/resources/extension_process_bindings.js
index 1c8fc9c4..e0dba27 100644
--- a/chrome/renderer/resources/extension_process_bindings.js
+++ b/chrome/renderer/resources/extension_process_bindings.js
@@ -30,6 +30,7 @@ var chrome = chrome || {};
native function GetTabLanguage();
native function EnablePageAction();
native function DisablePageAction();
+ native function GetCurrentPageActions();
native function GetBookmarks();
native function GetBookmarkChildren();
native function GetBookmarkTree();
@@ -397,9 +398,16 @@ var chrome = chrome || {};
}
];
- // Sends ({pageActionId, tabId, tabUrl}).
- chrome.pageActions.onExecute =
- new chrome.Event("page-action-executed");
+ // Page action events send (pageActionId, {tabId, tabUrl}).
+ function setupPageActionEvents(extensionId) {
+ var pageActions = GetCurrentPageActions();
+ var eventName = "";
+ for (var i = 0; i < pageActions.length; ++i) {
+ eventName = extensionId + "/" + pageActions[i];
+ // Setup events for each extension_id/page_action_id string we find.
+ chrome.pageActions[pageActions[i]] = new chrome.Event(eventName);
+ }
+ }
//----------------------------------------------------------------------------
// Bookmarks
@@ -548,6 +556,8 @@ var chrome = chrome || {};
// TODO(mpcomplete): self.onConnect is deprecated. Remove it at 1.0.
// http://code.google.com/p/chromium/issues/detail?id=16356
chrome.self.onConnect = new chrome.Event("channel-connect:" + extensionId);
+
+ setupPageActionEvents(extensionId);
});
chrome.self.getViews = function() {