diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-15 20:21:58 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-15 20:21:58 +0000 |
commit | 4577622518be7c7ddd4f3b45016d4fa68d253802 (patch) | |
tree | e09db89fdb34063d7dcb6ffc013821792ab3f38e /chrome/renderer | |
parent | 631d1ab9de83c531ca43b8134226eb247a4ee3aa (diff) | |
download | chromium_src-4577622518be7c7ddd4f3b45016d4fa68d253802.zip chromium_src-4577622518be7c7ddd4f3b45016d4fa68d253802.tar.gz chromium_src-4577622518be7c7ddd4f3b45016d4fa68d253802.tar.bz2 |
Retrying this patch. This was already reviewed by mpcomplete and the
only change is a fix for the UI test that broke and a small change to
event_bindings.cc (reviewed in-person).
ExtensionFunctionDispatcher now notifies ExtensionProcessManager 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.
TBR=mpcomplete
BUG=13936
TEST=The RSS sample extension should work as before.
Review URL: http://codereview.chromium.org/149683
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20782 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/extensions/event_bindings.cc | 14 | ||||
-rw-r--r-- | chrome/renderer/extensions/extension_process_bindings.cc | 58 | ||||
-rw-r--r-- | chrome/renderer/extensions/extension_process_bindings.h | 5 | ||||
-rw-r--r-- | chrome/renderer/render_thread.cc | 10 | ||||
-rw-r--r-- | chrome/renderer/render_thread.h | 8 | ||||
-rw-r--r-- | chrome/renderer/renderer_resources.grd | 2 | ||||
-rw-r--r-- | chrome/renderer/resources/extension_process_bindings.js | 16 |
7 files changed, 97 insertions, 16 deletions
diff --git a/chrome/renderer/extensions/event_bindings.cc b/chrome/renderer/extensions/event_bindings.cc index eab00fc..bb8df28 100644 --- a/chrome/renderer/extensions/event_bindings.cc +++ b/chrome/renderer/extensions/event_bindings.cc @@ -118,9 +118,13 @@ RenderThreadBase* EventBindings::GetRenderThread() { return render_thread ? render_thread : RenderThread::current(); } -static void HandleContextDestroyed(ContextList::iterator context_iter) { +static void HandleContextDestroyed(ContextList::iterator context_iter, + bool callUnload) { // Notify the bindings that they're going away. - CallFunctionInContext((*context_iter)->context, "dispatchOnUnload", 0, NULL); + if (callUnload) { + CallFunctionInContext((*context_iter)->context, "dispatchOnUnload", 0, + NULL); + } // Remove all pending requests for this context. PendingRequestMap& pending_requests = GetPendingRequestMap(); @@ -139,7 +143,7 @@ static void HandleContextDestroyed(ContextList::iterator context_iter) { it != GetContexts().end(); ) { ContextList::iterator current = it++; if ((*current)->parent_context == (*context_iter)->context) - HandleContextDestroyed(current); + HandleContextDestroyed(current, callUnload); } // Remove it from our registered contexts. @@ -155,7 +159,7 @@ static void ContextWeakReferenceCallback(v8::Persistent<v8::Value> context, for (ContextList::iterator it = GetContexts().begin(); it != GetContexts().end(); ++it) { if ((*it)->context == context) { - HandleContextDestroyed(it); + HandleContextDestroyed(it, false); return; } } @@ -211,7 +215,7 @@ void EventBindings::HandleContextDestroyed(WebFrame* frame) { ContextList::iterator context_iter = bindings_utils::FindContext(context); DCHECK(context_iter != GetContexts().end()); - ::HandleContextDestroyed(context_iter); + ::HandleContextDestroyed(context_iter, true); } // static diff --git a/chrome/renderer/extensions/extension_process_bindings.cc b/chrome/renderer/extensions/extension_process_bindings.cc index e68fb82..fd70dcf 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,32 @@ 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); + + std::vector<std::string> page_actions; + 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); + for (size_t i = 0; i < size; ++i) { + std::string page_action_id = page_actions[i]; + 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 @@ 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 eb128c7..a48534c 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. aa1 --> +without changes to the corresponding grd file. Zorglub2 --> <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() { |