diff options
57 files changed, 681 insertions, 708 deletions
diff --git a/chrome/browser/automation/extension_port_container.cc b/chrome/browser/automation/extension_port_container.cc index 52dc34a..bdcbb7e 100644 --- a/chrome/browser/automation/extension_port_container.cc +++ b/chrome/browser/automation/extension_port_container.cc @@ -13,7 +13,7 @@ #include "chrome/browser/extensions/extension_message_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/automation_messages.h" -#include "chrome/common/render_messages.h" +#include "chrome/common/extensions/extension_messages.h" #include "content/browser/renderer_host/render_process_host.h" #include "content/browser/renderer_host/render_view_host.h" @@ -95,8 +95,7 @@ bool ExtensionPortContainer::Send(IPC::Message *message) { DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); IPC_BEGIN_MESSAGE_MAP(ExtensionPortContainer, *message) - IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke, - OnExtensionMessageInvoke) + IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnExtensionMessageInvoke) IPC_MESSAGE_UNHANDLED_ERROR() IPC_END_MESSAGE_MAP() diff --git a/chrome/browser/chromeos/notifications/balloon_view_host.cc b/chrome/browser/chromeos/notifications/balloon_view_host.cc index ff4c50e..1e9be4f 100644 --- a/chrome/browser/chromeos/notifications/balloon_view_host.cc +++ b/chrome/browser/chromeos/notifications/balloon_view_host.cc @@ -6,8 +6,7 @@ #include "base/stl_util-inl.h" #include "base/values.h" -#include "chrome/common/render_messages.h" -#include "chrome/common/render_messages_params.h" +#include "chrome/common/extensions/extension_messages.h" namespace chromeos { @@ -27,7 +26,7 @@ bool BalloonViewHost::AddWebUIMessageCallback( } void BalloonViewHost::ProcessWebUIMessage( - const ViewHostMsg_DomMessage_Params& params) { + const ExtensionHostMsg_DomMessage_Params& params) { ::BalloonViewHost::ProcessWebUIMessage(params); // Look up the callback for this message. diff --git a/chrome/browser/chromeos/notifications/balloon_view_host.h b/chrome/browser/chromeos/notifications/balloon_view_host.h index db532b7..5b6a3ca5 100644 --- a/chrome/browser/chromeos/notifications/balloon_view_host.h +++ b/chrome/browser/chromeos/notifications/balloon_view_host.h @@ -34,7 +34,8 @@ class BalloonViewHost : public ::BalloonViewHost { MessageCallback* callback); // Process WebUI message. - virtual void ProcessWebUIMessage(const ViewHostMsg_DomMessage_Params& params); + virtual void ProcessWebUIMessage( + const ExtensionHostMsg_DomMessage_Params& params); private: // A map of message name -> message handling callback. diff --git a/chrome/browser/debugger/extension_ports_remote_service.cc b/chrome/browser/debugger/extension_ports_remote_service.cc index 711e3f8..a340ca6e 100644 --- a/chrome/browser/debugger/extension_ports_remote_service.cc +++ b/chrome/browser/debugger/extension_ports_remote_service.cc @@ -21,7 +21,7 @@ #include "chrome/browser/debugger/inspectable_tab_proxy.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/devtools_messages.h" -#include "chrome/common/render_messages.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/render_messages_params.h" #include "content/browser/tab_contents/tab_contents.h" @@ -226,8 +226,7 @@ bool ExtensionPortsRemoteService::Send(IPC::Message *message) { DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); IPC_BEGIN_MESSAGE_MAP(ExtensionPortsRemoteService, *message) - IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke, - OnExtensionMessageInvoke) + IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnExtensionMessageInvoke) IPC_MESSAGE_UNHANDLED_ERROR() IPC_END_MESSAGE_MAP() diff --git a/chrome/browser/extensions/extension_event_router.cc b/chrome/browser/extensions/extension_event_router.cc index fc8bd87..257a7f2 100644 --- a/chrome/browser/extensions/extension_event_router.cc +++ b/chrome/browser/extensions/extension_event_router.cc @@ -13,7 +13,7 @@ #include "chrome/browser/extensions/extension_webrequest_api.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/render_messages.h" +#include "chrome/common/extensions/extension_messages.h" #include "content/browser/child_process_security_policy.h" #include "content/browser/renderer_host/render_process_host.h" #include "content/common/notification_service.h" @@ -30,7 +30,7 @@ static void DispatchEvent(RenderProcessHost* renderer, ListValue args; args.Set(0, Value::CreateStringValue(event_name)); args.Set(1, Value::CreateStringValue(event_args)); - renderer->Send(new ViewMsg_ExtensionMessageInvoke(MSG_ROUTING_CONTROL, + renderer->Send(new ExtensionMsg_MessageInvoke(MSG_ROUTING_CONTROL, extension_id, kDispatchEvent, args, event_url)); } diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc index 40384a70..924a530 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.cc +++ b/chrome/browser/extensions/extension_function_dispatcher.cc @@ -53,8 +53,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/webui/chrome_url_data_manager.h" #include "chrome/browser/ui/webui/favicon_source.h" -#include "chrome/common/render_messages.h" -#include "chrome/common/render_messages_params.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/url_constants.h" #include "content/browser/renderer_host/render_process_host.h" #include "content/browser/renderer_host/render_view_host.h" @@ -421,9 +420,9 @@ ExtensionFunctionDispatcher::ExtensionFunctionDispatcher( // Update the extension permissions. Doing this each time we create an EFD // ensures that new processes are informed of permissions for newly installed // extensions. - render_view_host->Send(new ViewMsg_Extension_SetAPIPermissions( + render_view_host->Send(new ExtensionMsg_SetAPIPermissions( extension->id(), extension->api_permissions())); - render_view_host->Send(new ViewMsg_Extension_SetHostPermissions( + render_view_host->Send(new ExtensionMsg_SetHostPermissions( extension->url(), extension->host_permissions())); NotificationService::current()->Notify( @@ -468,7 +467,7 @@ Browser* ExtensionFunctionDispatcher::GetCurrentBrowser( } void ExtensionFunctionDispatcher::HandleRequest( - const ViewHostMsg_DomMessage_Params& params) { + const ExtensionHostMsg_DomMessage_Params& params) { scoped_refptr<ExtensionFunction> function( FactoryRegistry::GetInstance()->NewFunction(params.name)); function->set_dispatcher_peer(peer_); diff --git a/chrome/browser/extensions/extension_function_dispatcher.h b/chrome/browser/extensions/extension_function_dispatcher.h index 8ec22ac..6674bb4 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.h +++ b/chrome/browser/extensions/extension_function_dispatcher.h @@ -20,7 +20,7 @@ class ListValue; class Profile; class RenderViewHost; class TabContents; -struct ViewHostMsg_DomMessage_Params; +struct ExtensionHostMsg_DomMessage_Params; // A factory function for creating new ExtensionFunction instances. typedef ExtensionFunction* (*ExtensionFunctionFactory)(); @@ -86,7 +86,7 @@ class ExtensionFunctionDispatcher { Delegate* delegate() { return delegate_; } // Handle a request to execute an extension function. - void HandleRequest(const ViewHostMsg_DomMessage_Params& params); + void HandleRequest(const ExtensionHostMsg_DomMessage_Params& params); // Send a response to a function. void SendResponse(ExtensionFunction* api, bool success); diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index e249a33..8d95d1b 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -554,7 +554,7 @@ WebPreferences ExtensionHost::GetWebkitPrefs() { } void ExtensionHost::ProcessWebUIMessage( - const ViewHostMsg_DomMessage_Params& params) { + const ExtensionHostMsg_DomMessage_Params& params) { if (extension_function_dispatcher_.get()) { extension_function_dispatcher_->HandleRequest(params); } diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h index 50e050c..d0cd5ec 100644 --- a/chrome/browser/extensions/extension_host.h +++ b/chrome/browser/extensions/extension_host.h @@ -129,7 +129,8 @@ class ExtensionHost : public RenderViewHostDelegate, // RenderViewHostDelegate implementation. virtual RenderViewHostDelegate::View* GetViewDelegate(); virtual WebPreferences GetWebkitPrefs(); - virtual void ProcessWebUIMessage(const ViewHostMsg_DomMessage_Params& params); + virtual void ProcessWebUIMessage( + const ExtensionHostMsg_DomMessage_Params& params); virtual void RunJavaScriptMessage(const std::wstring& message, const std::wstring& default_prompt, const GURL& frame_url, diff --git a/chrome/browser/extensions/extension_message_service.cc b/chrome/browser/extensions/extension_message_service.cc index 4d38160..4f4035b 100644 --- a/chrome/browser/extensions/extension_message_service.cc +++ b/chrome/browser/extensions/extension_message_service.cc @@ -14,7 +14,7 @@ #include "chrome/browser/tab_contents/tab_util.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/render_messages.h" +#include "chrome/common/extensions/extension_messages.h" #include "content/browser/child_process_security_policy.h" #include "content/browser/renderer_host/render_process_host.h" #include "content/browser/renderer_host/render_view_host.h" @@ -70,7 +70,7 @@ static void DispatchOnConnect(const ExtensionMessageService::MessagePort& port, args.Set(3, Value::CreateStringValue(source_extension_id)); args.Set(4, Value::CreateStringValue(target_extension_id)); CHECK(port.sender); - port.sender->Send(new ViewMsg_ExtensionMessageInvoke(port.routing_id, + port.sender->Send(new ExtensionMsg_MessageInvoke(port.routing_id, "", ExtensionMessageService::kDispatchOnConnect, args, GURL())); } @@ -80,7 +80,7 @@ static void DispatchOnDisconnect( ListValue args; args.Set(0, Value::CreateIntegerValue(source_port_id)); args.Set(1, Value::CreateBooleanValue(connection_error)); - port.sender->Send(new ViewMsg_ExtensionMessageInvoke(port.routing_id, + port.sender->Send(new ExtensionMsg_MessageInvoke(port.routing_id, "", ExtensionMessageService::kDispatchOnDisconnect, args, GURL())); } @@ -89,7 +89,7 @@ static void DispatchOnMessage(const ExtensionMessageService::MessagePort& port, ListValue args; args.Set(0, Value::CreateStringValue(message)); args.Set(1, Value::CreateIntegerValue(source_port_id)); - port.sender->Send(new ViewMsg_ExtensionMessageInvoke(port.routing_id, + port.sender->Send(new ExtensionMsg_MessageInvoke(port.routing_id, "", ExtensionMessageService::kDispatchOnMessage, args, GURL())); } diff --git a/chrome/browser/extensions/extension_messages_browsertest.cc b/chrome/browser/extensions/extension_messages_browsertest.cc index 30cfbd8..c7a9b76 100644 --- a/chrome/browser/extensions/extension_messages_browsertest.cc +++ b/chrome/browser/extensions/extension_messages_browsertest.cc @@ -4,6 +4,7 @@ #include "base/values.h" #include "chrome/browser/extensions/extension_message_service.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/render_messages.h" #include "chrome/renderer/extensions/event_bindings.h" #include "chrome/renderer/extensions/renderer_extension_bindings.h" @@ -57,19 +58,19 @@ TEST_F(RenderViewTest, ExtensionMessagesOpenChannel) { // Verify that we opened a channel and sent a message through it. const IPC::Message* open_channel_msg = render_thread_.sink().GetUniqueMessageMatching( - ViewHostMsg_OpenChannelToExtension::ID); + ExtensionHostMsg_OpenChannelToExtension::ID); ASSERT_TRUE(open_channel_msg); void* iter = IPC::SyncMessage::GetDataIterator(open_channel_msg); - ViewHostMsg_OpenChannelToExtension::SendParam open_params; + ExtensionHostMsg_OpenChannelToExtension::SendParam open_params; ASSERT_TRUE(IPC::ReadParam(open_channel_msg, &iter, &open_params)); EXPECT_EQ("testName", open_params.d); const IPC::Message* post_msg = render_thread_.sink().GetUniqueMessageMatching( - ViewHostMsg_ExtensionPostMessage::ID); + ExtensionHostMsg_PostMessage::ID); ASSERT_TRUE(post_msg); - ViewHostMsg_ExtensionPostMessage::Param post_params; - ViewHostMsg_ExtensionPostMessage::Read(post_msg, &post_params); + ExtensionHostMsg_PostMessage::Param post_params; + ExtensionHostMsg_PostMessage::Read(post_msg, &post_params); EXPECT_EQ("{\"message\":\"content ready\"}", post_params.b); // Now simulate getting a message back from the other side. @@ -117,10 +118,10 @@ TEST_F(RenderViewTest, ExtensionMessagesOnConnect) { // Verify that we handled the new connection by posting a message. const IPC::Message* post_msg = render_thread_.sink().GetUniqueMessageMatching( - ViewHostMsg_ExtensionPostMessage::ID); + ExtensionHostMsg_PostMessage::ID); ASSERT_TRUE(post_msg); - ViewHostMsg_ExtensionPostMessage::Param post_params; - ViewHostMsg_ExtensionPostMessage::Read(post_msg, &post_params); + ExtensionHostMsg_PostMessage::Param post_params; + ExtensionHostMsg_PostMessage::Read(post_msg, &post_params); std::string expected_msg = "{\"message\":\"onconnect from foo://bar name " + kPortName + "\"}"; EXPECT_EQ(expected_msg, post_params.b); diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc index 14ce191..8ff58e6f 100644 --- a/chrome/browser/extensions/extension_process_manager.cc +++ b/chrome/browser/extensions/extension_process_manager.cc @@ -15,7 +15,7 @@ #include "chrome/browser/ui/browser.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_action.h" -#include "chrome/common/render_messages.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/url_constants.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/site_instance.h" @@ -236,8 +236,7 @@ void ExtensionProcessManager::RegisterExtensionProcess( page_action_ids.push_back(extension->page_action()->id()); RenderProcessHost* rph = RenderProcessHost::FromID(process_id); - rph->Send(new ViewMsg_Extension_UpdatePageActions(extension_id, - page_action_ids)); + rph->Send(new ExtensionMsg_UpdatePageActions(extension_id, page_action_ids)); } void ExtensionProcessManager::UnregisterExtensionProcess(int process_id) { diff --git a/chrome/browser/extensions/extension_web_ui.cc b/chrome/browser/extensions/extension_web_ui.cc index d20e30e..e1f34fb 100644 --- a/chrome/browser/extensions/extension_web_ui.cc +++ b/chrome/browser/extensions/extension_web_ui.cc @@ -183,7 +183,7 @@ void ExtensionWebUI::RenderViewReused(RenderViewHost* render_view_host) { } void ExtensionWebUI::ProcessWebUIMessage( - const ViewHostMsg_DomMessage_Params& params) { + const ExtensionHostMsg_DomMessage_Params& params) { extension_function_dispatcher_->HandleRequest(params); } diff --git a/chrome/browser/extensions/extension_web_ui.h b/chrome/browser/extensions/extension_web_ui.h index e4821a8..34f0899 100644 --- a/chrome/browser/extensions/extension_web_ui.h +++ b/chrome/browser/extensions/extension_web_ui.h @@ -21,7 +21,7 @@ class PrefService; class Profile; class RenderViewHost; class TabContents; -struct ViewHostMsg_DomMessage_Params; +struct ExtensionHostMsg_DomMessage_Params; // This class implements WebUI for extensions and allows extensions to put UI in // the main tab contents area. For example, each extension can specify an @@ -44,7 +44,8 @@ class ExtensionWebUI // WebUI virtual void RenderViewCreated(RenderViewHost* render_view_host); virtual void RenderViewReused(RenderViewHost* render_view_host); - virtual void ProcessWebUIMessage(const ViewHostMsg_DomMessage_Params& params); + virtual void ProcessWebUIMessage( + const ExtensionHostMsg_DomMessage_Params& params); // ExtensionFunctionDispatcher::Delegate virtual Browser* GetBrowser(); diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc index 9bf98df..7943b68 100644 --- a/chrome/browser/extensions/user_script_master.cc +++ b/chrome/browser/extensions/user_script_master.cc @@ -238,7 +238,7 @@ static base::SharedMemory* Serialize(const UserScriptList& scripts) { for (size_t i = 0; i < scripts.size(); i++) { const UserScript& script = scripts[i]; // TODO(aa): This can be replaced by sending content script metadata to - // renderers along with other extension data in ViewMsg_ExtensionLoaded. + // renderers along with other extension data in ExtensionMsg_Loaded. // See crbug.com/70516. script.Pickle(&pickle); // Write scripts as 'data' so that we can read it out in the slave without diff --git a/chrome/browser/notifications/balloon_host.cc b/chrome/browser/notifications/balloon_host.cc index c608150..f5a824e 100644 --- a/chrome/browser/notifications/balloon_host.cc +++ b/chrome/browser/notifications/balloon_host.cc @@ -132,7 +132,7 @@ RenderViewHostDelegate::View* BalloonHost::GetViewDelegate() { } void BalloonHost::ProcessWebUIMessage( - const ViewHostMsg_DomMessage_Params& params) { + const ExtensionHostMsg_DomMessage_Params& params) { if (extension_function_dispatcher_.get()) { extension_function_dispatcher_->HandleRequest(params); } diff --git a/chrome/browser/notifications/balloon_host.h b/chrome/browser/notifications/balloon_host.h index 2f39301..d00fbf9 100644 --- a/chrome/browser/notifications/balloon_host.h +++ b/chrome/browser/notifications/balloon_host.h @@ -60,7 +60,8 @@ class BalloonHost : public RenderViewHostDelegate, virtual int GetBrowserWindowID() const; virtual ViewType::Type GetRenderViewType() const; virtual RenderViewHostDelegate::View* GetViewDelegate(); - virtual void ProcessWebUIMessage(const ViewHostMsg_DomMessage_Params& params); + virtual void ProcessWebUIMessage( + const ExtensionHostMsg_DomMessage_Params& params); // NotificationObserver override. virtual void Observe(NotificationType type, diff --git a/chrome/browser/prerender/prerender_contents.cc b/chrome/browser/prerender/prerender_contents.cc index 172ae37..1d4164b 100644 --- a/chrome/browser/prerender/prerender_contents.cc +++ b/chrome/browser/prerender/prerender_contents.cc @@ -16,7 +16,7 @@ #include "chrome/browser/ui/login/login_prompt.h" #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/render_messages.h" -#include "chrome/common/render_messages_params.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/url_constants.h" #include "chrome/common/view_types.h" #include "content/browser/browsing_instance.h" @@ -360,7 +360,7 @@ WebPreferences PrerenderContents::GetWebkitPrefs() { } void PrerenderContents::ProcessWebUIMessage( - const ViewHostMsg_DomMessage_Params& params) { + const ExtensionHostMsg_DomMessage_Params& params) { render_view_host_->BlockExtensionRequest(params.request_id); } diff --git a/chrome/browser/prerender/prerender_contents.h b/chrome/browser/prerender/prerender_contents.h index 6c20b56..7ec68e1 100644 --- a/chrome/browser/prerender/prerender_contents.h +++ b/chrome/browser/prerender/prerender_contents.h @@ -115,7 +115,8 @@ class PrerenderContents : public RenderViewHostDelegate, int32 page_id, const std::wstring& title); virtual WebPreferences GetWebkitPrefs(); - virtual void ProcessWebUIMessage(const ViewHostMsg_DomMessage_Params& params); + virtual void ProcessWebUIMessage( + const ExtensionHostMsg_DomMessage_Params& params); virtual void RunJavaScriptMessage(const std::wstring& message, const std::wstring& default_prompt, const GURL& frame_url, diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc index 187d840..14fedea 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.cc +++ b/chrome/browser/renderer_host/browser_render_process_host.cc @@ -52,6 +52,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_icon_set.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/logging_chrome.h" #include "chrome/common/net/url_request_context_getter.h" #include "chrome/common/pref_names.h" @@ -830,19 +831,19 @@ void BrowserRenderProcessHost::InitExtensions() { // Valid extension function names, used to setup bindings in renderer. std::vector<std::string> function_names; ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names); - Send(new ViewMsg_Extension_SetFunctionNames(function_names)); + Send(new ExtensionMsg_SetFunctionNames(function_names)); // Scripting whitelist. This is modified by tests and must be communicated to // renderers. - Send(new ViewMsg_Extension_SetScriptingWhitelist( + Send(new ExtensionMsg_SetScriptingWhitelist( *Extension::GetScriptingWhitelist())); // Loaded extensions. ExtensionService* service = profile()->GetExtensionService(); if (service) { for (size_t i = 0; i < service->extensions()->size(); ++i) { - Send(new ViewMsg_ExtensionLoaded( - ViewMsg_ExtensionLoaded_Params(service->extensions()->at(i)))); + Send(new ExtensionMsg_Loaded( + ExtensionMsg_Loaded_Params(service->extensions()->at(i)))); } } } @@ -1002,11 +1003,10 @@ bool BrowserRenderProcessHost::OnMessageReceived(const IPC::Message& msg) { OnUpdatedCacheStats) IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged, SuddenTerminationChanged); - IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionAddListener, - OnExtensionAddListener) - IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionRemoveListener, + IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddListener, OnExtensionAddListener) + IPC_MESSAGE_HANDLER(ExtensionHostMsg_RemoveListener, OnExtensionRemoveListener) - IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionCloseChannel, + IPC_MESSAGE_HANDLER(ExtensionHostMsg_CloseChannel, OnExtensionCloseChannel) IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction, OnUserMetricsRecordAction) @@ -1144,13 +1144,12 @@ void BrowserRenderProcessHost::Observe(NotificationType type, break; } case NotificationType::EXTENSION_LOADED: { - Send(new ViewMsg_ExtensionLoaded( - ViewMsg_ExtensionLoaded_Params( - Details<const Extension>(details).ptr()))); + Send(new ExtensionMsg_Loaded( + ExtensionMsg_Loaded_Params(Details<const Extension>(details).ptr()))); break; } case NotificationType::EXTENSION_UNLOADED: { - Send(new ViewMsg_ExtensionUnloaded( + Send(new ExtensionMsg_Unloaded( Details<UnloadedExtensionInfo>(details).ptr()->extension->id())); break; } diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.cc b/chrome/browser/renderer_host/chrome_render_message_filter.cc index 39b4bc0..fd1c802 100644 --- a/chrome/browser/renderer_host/chrome_render_message_filter.cc +++ b/chrome/browser/renderer_host/chrome_render_message_filter.cc @@ -16,6 +16,7 @@ #include "chrome/browser/task_manager/task_manager.h" #include "chrome/common/extensions/extension_file_util.h" #include "chrome/common/extensions/extension_message_bundle.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/render_messages.h" #include "content/browser/renderer_host/resource_dispatcher_host.h" @@ -49,10 +50,10 @@ bool ChromeRenderMessageFilter::OnMessageReceived(const IPC::Message& message, IPC_MESSAGE_HANDLER(ViewHostMsg_RendererHistograms, OnRendererHistograms) IPC_MESSAGE_HANDLER(ViewHostMsg_ResourceTypeStats, OnResourceTypeStats) IPC_MESSAGE_HANDLER(ViewHostMsg_V8HeapStats, OnV8HeapStats) - IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToExtension, + IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToExtension, OnOpenChannelToExtension) - IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToTab, OnOpenChannelToTab) - IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetExtensionMessageBundle, + IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToTab, OnOpenChannelToTab) + IPC_MESSAGE_HANDLER_DELAY_REPLY(ExtensionHostMsg_GetMessageBundle, OnGetExtensionMessageBundle) #if defined(USE_TCMALLOC) IPC_MESSAGE_HANDLER(ViewHostMsg_RendererTcmalloc, OnRendererTcmalloc) @@ -216,7 +217,7 @@ void ChromeRenderMessageFilter::OnGetExtensionMessageBundleOnFileThread( dictionary_map.insert( std::make_pair(ExtensionMessageBundle::kExtensionIdKey, extension_id)); - ViewHostMsg_GetExtensionMessageBundle::WriteReplyParams( + ExtensionHostMsg_GetMessageBundle::WriteReplyParams( reply_msg, dictionary_map); Send(reply_msg); } diff --git a/chrome/browser/tab_contents/background_contents.cc b/chrome/browser/tab_contents/background_contents.cc index 8c92a0e..945a88b 100644 --- a/chrome/browser/tab_contents/background_contents.cc +++ b/chrome/browser/tab_contents/background_contents.cc @@ -9,7 +9,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/renderer_preferences_util.h" #include "chrome/common/extensions/extension_constants.h" -#include "chrome/common/render_messages_params.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/url_constants.h" #include "chrome/common/view_types.h" #include "content/browser/browsing_instance.h" @@ -211,7 +211,7 @@ WebPreferences BackgroundContents::GetWebkitPrefs() { } void BackgroundContents::ProcessWebUIMessage( - const ViewHostMsg_DomMessage_Params& params) { + const ExtensionHostMsg_DomMessage_Params& params) { // TODO(rafaelw): It may make sense for extensions to be able to open // BackgroundContents to chrome-extension://<id> pages. Consider implementing. render_view_host_->BlockExtensionRequest(params.request_id); diff --git a/chrome/browser/tab_contents/background_contents.h b/chrome/browser/tab_contents/background_contents.h index 70659c7..670abd4 100644 --- a/chrome/browser/tab_contents/background_contents.h +++ b/chrome/browser/tab_contents/background_contents.h @@ -67,7 +67,8 @@ class BackgroundContents : public RenderViewHostDelegate, virtual void DidNavigate(RenderViewHost* render_view_host, const ViewHostMsg_FrameNavigate_Params& params); virtual WebPreferences GetWebkitPrefs(); - virtual void ProcessWebUIMessage(const ViewHostMsg_DomMessage_Params& params); + virtual void ProcessWebUIMessage( + const ExtensionHostMsg_DomMessage_Params& params); virtual void RunJavaScriptMessage(const std::wstring& message, const std::wstring& default_prompt, const GURL& frame_url, diff --git a/chrome/browser/ui/webui/sync_internals_ui.cc b/chrome/browser/ui/webui/sync_internals_ui.cc index f44e51a..8ab946e1 100644 --- a/chrome/browser/ui/webui/sync_internals_ui.cc +++ b/chrome/browser/ui/webui/sync_internals_ui.cc @@ -19,7 +19,7 @@ #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/webui/chrome_url_data_manager.h" #include "chrome/browser/ui/webui/sync_internals_html_source.h" -#include "chrome/common/render_messages_params.h" +#include "chrome/common/extensions/extension_messages.h" #include "content/browser/browser_thread.h" SyncInternalsUI::SyncInternalsUI(TabContents* contents) @@ -43,7 +43,7 @@ SyncInternalsUI::~SyncInternalsUI() { } void SyncInternalsUI::ProcessWebUIMessage( - const ViewHostMsg_DomMessage_Params& params) { + const ExtensionHostMsg_DomMessage_Params& params) { const std::string& name = params.name; browser_sync::JsArgList args(params.arguments); VLOG(1) << "Received message: " << name << " with args " diff --git a/chrome/browser/ui/webui/sync_internals_ui.h b/chrome/browser/ui/webui/sync_internals_ui.h index 0afdca4..589b712 100644 --- a/chrome/browser/ui/webui/sync_internals_ui.h +++ b/chrome/browser/ui/webui/sync_internals_ui.h @@ -36,7 +36,7 @@ class SyncInternalsUI : public WebUI, public browser_sync::JsEventHandler { // TODO(akalin): Add a simple isSyncEnabled() message and make // getAboutInfo() be handled by the sync service. virtual void ProcessWebUIMessage( - const ViewHostMsg_DomMessage_Params& params); + const ExtensionHostMsg_DomMessage_Params& params); // browser_sync::JsEventHandler implementation. virtual void HandleJsEvent(const std::string& name, diff --git a/chrome/browser/ui/webui/sync_internals_ui_unittest.cc b/chrome/browser/ui/webui/sync_internals_ui_unittest.cc index d103363..1407f10 100644 --- a/chrome/browser/ui/webui/sync_internals_ui_unittest.cc +++ b/chrome/browser/ui/webui/sync_internals_ui_unittest.cc @@ -12,7 +12,7 @@ #include "chrome/browser/sync/js_arg_list.h" #include "chrome/browser/sync/js_test_util.h" #include "chrome/browser/sync/profile_sync_service_mock.h" -#include "chrome/common/render_messages_params.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/test/profile_mock.h" #include "content/browser/browser_thread.h" #include "content/browser/renderer_host/test_render_view_host.h" @@ -164,7 +164,7 @@ TEST_F(SyncInternalsUITest, HandleJsEventNullService) { TEST_F(SyncInternalsUITest, ProcessWebUIMessageBasic) { ExpectSetupTeardownCalls(); - ViewHostMsg_DomMessage_Params params; + ExtensionHostMsg_DomMessage_Params params; params.name = "testName"; params.arguments.Append(Value::CreateIntegerValue(10)); @@ -182,7 +182,7 @@ TEST_F(SyncInternalsUITest, ProcessWebUIMessageBasicNullService) { ConstructTestSyncInternalsUI(); - ViewHostMsg_DomMessage_Params params; + ExtensionHostMsg_DomMessage_Params params; params.name = "testName"; params.arguments.Append(Value::CreateIntegerValue(5)); @@ -198,7 +198,7 @@ const char kAboutInfoCall[] = TEST_F(SyncInternalsUITest, ProcessWebUIMessageGetAboutInfo) { ExpectSetupTeardownCalls(); - ViewHostMsg_DomMessage_Params params; + ExtensionHostMsg_DomMessage_Params params; params.name = "getAboutInfo"; ConstructTestSyncInternalsUI(); @@ -212,7 +212,7 @@ TEST_F(SyncInternalsUITest, ProcessWebUIMessageGetAboutInfo) { TEST_F(SyncInternalsUITest, ProcessWebUIMessageGetAboutInfoNullService) { ExpectSetupTeardownCallsNullService(); - ViewHostMsg_DomMessage_Params params; + ExtensionHostMsg_DomMessage_Params params; params.name = "getAboutInfo"; ConstructTestSyncInternalsUI(); diff --git a/chrome/browser/web_applications/web_app_unittest.cc b/chrome/browser/web_applications/web_app_unittest.cc index 931add1..7e75a76 100644 --- a/chrome/browser/web_applications/web_app_unittest.cc +++ b/chrome/browser/web_applications/web_app_unittest.cc @@ -9,7 +9,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" #include "chrome/browser/ui/web_applications/web_app_ui.h" -#include "chrome/common/render_messages.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/test/testing_profile.h" #include "content/browser/browser_thread.h" #include "testing/gtest/include/gtest/gtest.h" @@ -49,7 +49,7 @@ TEST_F(WebApplicationTest, GetShortcutInfoForTab) { web_app_info.app_url = url; rvh()->TestOnMessageReceived( - ViewHostMsg_DidGetApplicationInfo(0, 0, web_app_info)); + ExtensionHostMsg_DidGetApplicationInfo(0, 0, web_app_info)); ShellIntegration::ShortcutInfo info; web_app::GetShortcutInfoForTab(contents_wrapper(), &info); diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index 3fcb4f4..47bff48 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -171,6 +171,8 @@ 'common/extensions/extension_localization_peer.h', 'common/extensions/extension_message_bundle.cc', 'common/extensions/extension_message_bundle.h', + 'common/extensions/extension_messages.cc', + 'common/extensions/extension_messages.h', 'common/extensions/extension_resource.cc', 'common/extensions/extension_resource.h', 'common/extensions/extension_set.cc', diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi index 1b7163e..ac81281 100644 --- a/chrome/chrome_renderer.gypi +++ b/chrome/chrome_renderer.gypi @@ -59,6 +59,8 @@ 'renderer/extensions/chrome_app_bindings.h', 'renderer/extensions/event_bindings.cc', 'renderer/extensions/event_bindings.h', + 'renderer/extensions/extension_helper.cc', + 'renderer/extensions/extension_helper.h', 'renderer/extensions/extension_process_bindings.cc', 'renderer/extensions/extension_process_bindings.h', 'renderer/extensions/extension_resource_request_policy.cc', diff --git a/chrome/common/common_message_generator.h b/chrome/common/common_message_generator.h index 6d6dfb5..0d1f4eb 100644 --- a/chrome/common/common_message_generator.h +++ b/chrome/common/common_message_generator.h @@ -6,6 +6,7 @@ #include "chrome/common/autofill_messages.h" #include "chrome/common/devtools_messages.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/print_messages.h" #include "chrome/common/render_messages.h" #include "chrome/common/safebrowsing_messages.h" diff --git a/chrome/common/extensions/extension_localization_peer.cc b/chrome/common/extensions/extension_localization_peer.cc index 9399c15..8323d9f 100644 --- a/chrome/common/extensions/extension_localization_peer.cc +++ b/chrome/common/extensions/extension_localization_peer.cc @@ -7,7 +7,7 @@ #include "base/memory/scoped_ptr.h" #include "base/string_util.h" #include "chrome/common/extensions/extension_message_bundle.h" -#include "chrome/common/render_messages.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/url_constants.h" #include "grit/generated_resources.h" #include "net/base/net_errors.h" @@ -100,7 +100,7 @@ void ExtensionLocalizationPeer::ReplaceMessages() { L10nMessagesMap* l10n_messages = GetL10nMessagesMap(extension_id); if (!l10n_messages) { L10nMessagesMap messages; - message_sender_->Send(new ViewHostMsg_GetExtensionMessageBundle( + message_sender_->Send(new ExtensionHostMsg_GetMessageBundle( extension_id, &messages)); // Save messages we got, so we don't have to ask again. diff --git a/chrome/common/extensions/extension_localization_peer.h b/chrome/common/extensions/extension_localization_peer.h index c633933..f370e3a 100644 --- a/chrome/common/extensions/extension_localization_peer.h +++ b/chrome/common/extensions/extension_localization_peer.h @@ -63,7 +63,7 @@ class ExtensionLocalizationPeer // We just pass though the response info. This holds the copy of the original. webkit_glue::ResourceResponseInfo response_info_; - // Sends ViewHostMsg_GetExtensionMessageBundle message to the browser to fetch + // Sends ExtensionHostMsg_GetMessageBundle message to the browser to fetch // message catalog. IPC::Message::Sender* message_sender_; diff --git a/chrome/common/extensions/extension_messages.cc b/chrome/common/extensions/extension_messages.cc new file mode 100644 index 0000000..b9ba244 --- /dev/null +++ b/chrome/common/extensions/extension_messages.cc @@ -0,0 +1,155 @@ +// Copyright (c) 2011 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. + +#include "chrome/common/extensions/extension_messages.h" + +#include "chrome/common/extensions/extension_constants.h" +#include "content/common/common_param_traits.h" + +ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params() + : location(Extension::INVALID) { +} + +ExtensionMsg_Loaded_Params::~ExtensionMsg_Loaded_Params() { +} + +ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params( + const ExtensionMsg_Loaded_Params& other) + : manifest(other.manifest->DeepCopy()), + location(other.location), + path(other.path), + id(other.id) { +} + +ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params( + const Extension* extension) + : manifest(new DictionaryValue()), + location(extension->location()), + path(extension->path()), + id(extension->id()) { + // As we need more bits of extension data in the renderer, add more keys to + // this list. + const char* kRendererExtensionKeys[] = { + extension_manifest_keys::kPublicKey, + extension_manifest_keys::kName, + extension_manifest_keys::kVersion, + extension_manifest_keys::kIcons, + extension_manifest_keys::kPermissions, + extension_manifest_keys::kApp + }; + + // Copy only the data we need. + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRendererExtensionKeys); ++i) { + Value* temp = NULL; + if (extension->manifest_value()->Get(kRendererExtensionKeys[i], &temp)) + manifest->Set(kRendererExtensionKeys[i], temp->DeepCopy()); + } +} + +scoped_refptr<Extension> + ExtensionMsg_Loaded_Params::ConvertToExtension() const { + // Extensions that are loaded unpacked won't have a key. + const bool kRequireKey = false; + + // The extension may have been loaded in a way that does not require + // strict error checks to pass. Do not do strict checks here. + const bool kStrictErrorChecks = false; + std::string error; + + scoped_refptr<Extension> extension( + Extension::Create(path, location, *manifest, kRequireKey, + kStrictErrorChecks, &error)); + if (!extension.get()) + LOG(ERROR) << "Error deserializing extension: " << error; + + return extension; +} + +namespace IPC { + +template <> +struct ParamTraits<Extension::Location> { + typedef Extension::Location param_type; + static void Write(Message* m, const param_type& p) { + int val = static_cast<int>(p); + WriteParam(m, val); + } + static bool Read(const Message* m, void** iter, param_type* p) { + int val = 0; + if (!ReadParam(m, iter, &val) || + val < Extension::INVALID || + val >= Extension::NUM_LOCATIONS) + return false; + *p = static_cast<param_type>(val); + return true; + } + static void Log(const param_type& p, std::string* l) { + ParamTraits<int>::Log(static_cast<int>(p), l); + } +}; + +void ParamTraits<URLPattern>::Write(Message* m, const param_type& p) { + WriteParam(m, p.valid_schemes()); + WriteParam(m, p.GetAsString()); +} + +bool ParamTraits<URLPattern>::Read(const Message* m, void** iter, + param_type* p) { + int valid_schemes; + std::string spec; + if (!ReadParam(m, iter, &valid_schemes) || + !ReadParam(m, iter, &spec)) + return false; + + p->set_valid_schemes(valid_schemes); + return URLPattern::PARSE_SUCCESS == p->Parse(spec, URLPattern::PARSE_LENIENT); +} + +void ParamTraits<URLPattern>::Log(const param_type& p, std::string* l) { + LogParam(p.GetAsString(), l); +} + +void ParamTraits<ExtensionExtent>::Write(Message* m, const param_type& p) { + WriteParam(m, p.patterns()); +} + +bool ParamTraits<ExtensionExtent>::Read(const Message* m, void** iter, + param_type* p) { + std::vector<URLPattern> patterns; + bool success = + ReadParam(m, iter, &patterns); + if (!success) + return false; + + for (size_t i = 0; i < patterns.size(); ++i) + p->AddPattern(patterns[i]); + return true; +} + +void ParamTraits<ExtensionExtent>::Log(const param_type& p, std::string* l) { + LogParam(p.patterns(), l); +} + +void ParamTraits<ExtensionMsg_Loaded_Params>::Write(Message* m, + const param_type& p) { + WriteParam(m, p.location); + WriteParam(m, p.path); + WriteParam(m, *(p.manifest)); +} + +bool ParamTraits<ExtensionMsg_Loaded_Params>::Read(const Message* m, + void** iter, + param_type* p) { + p->manifest.reset(new DictionaryValue()); + return ReadParam(m, iter, &p->location) && + ReadParam(m, iter, &p->path) && + ReadParam(m, iter, p->manifest.get()); +} + +void ParamTraits<ExtensionMsg_Loaded_Params>::Log(const param_type& p, + std::string* l) { + l->append(p.id); +} + +} // namespace IPC diff --git a/chrome/common/extensions/extension_messages.h b/chrome/common/extensions/extension_messages.h new file mode 100644 index 0000000..2a6bcdb --- /dev/null +++ b/chrome/common/extensions/extension_messages.h @@ -0,0 +1,274 @@ +// Copyright (c) 2011 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. + +// IPC messages for extensions. +// Multiply-included message file, hence no include guard. + +#include "base/values.h" +#include "chrome/common/extensions/extension.h" +#include "chrome/common/extensions/extension_extent.h" +#include "chrome/common/extensions/url_pattern.h" +#include "chrome/common/web_apps.h" +#include "ipc/ipc_message_macros.h" + +#define IPC_MESSAGE_START ExtensionMsgStart + +// Parameters structure for ExtensionHostMsg_Request. +IPC_STRUCT_BEGIN(ExtensionHostMsg_DomMessage_Params) + // Message name. + IPC_STRUCT_MEMBER(std::string, name) + + // List of message arguments. + IPC_STRUCT_MEMBER(ListValue, arguments) + + // URL of the frame request was sent from. + IPC_STRUCT_MEMBER(GURL, source_url) + + // Unique request id to match requests and responses. + IPC_STRUCT_MEMBER(int, request_id) + + // True if request has a callback specified. + IPC_STRUCT_MEMBER(bool, has_callback) + + // True if request is executed in response to an explicit user gesture. + IPC_STRUCT_MEMBER(bool, user_gesture) +IPC_STRUCT_END() + +// Allows an extension to execute code in a tab. +IPC_STRUCT_BEGIN(ExtensionMsg_ExecuteCode_Params) + // The extension API request id, for responding. + IPC_STRUCT_MEMBER(int, request_id) + + // The ID of the requesting extension. To know which isolated world to + // execute the code inside of. + IPC_STRUCT_MEMBER(std::string, extension_id) + + // Whether the code is JavaScript or CSS. + IPC_STRUCT_MEMBER(bool, is_javascript) + + // String of code to execute. + IPC_STRUCT_MEMBER(std::string, code) + + // Whether to inject into all frames, or only the root frame. + IPC_STRUCT_MEMBER(bool, all_frames) +IPC_STRUCT_END() + +IPC_STRUCT_TRAITS_BEGIN(WebApplicationInfo::IconInfo) + IPC_STRUCT_TRAITS_MEMBER(url) + IPC_STRUCT_TRAITS_MEMBER(width) + IPC_STRUCT_TRAITS_MEMBER(height) + IPC_STRUCT_TRAITS_MEMBER(data) +IPC_STRUCT_TRAITS_END() + +IPC_STRUCT_TRAITS_BEGIN(WebApplicationInfo) + IPC_STRUCT_TRAITS_MEMBER(title) + IPC_STRUCT_TRAITS_MEMBER(description) + IPC_STRUCT_TRAITS_MEMBER(app_url) + IPC_STRUCT_TRAITS_MEMBER(icons) + IPC_STRUCT_TRAITS_MEMBER(permissions) + IPC_STRUCT_TRAITS_MEMBER(launch_container) +IPC_STRUCT_TRAITS_END() + +// Singly-included section for custom IPC traits. +#ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGES_H_ +#define CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGES_H_ + +// IPC_MESSAGE macros choke on extra , in the std::map, when expanding. We need +// to typedef it to avoid that. +// Substitution map for l10n messages. +typedef std::map<std::string, std::string> SubstitutionMap; + +struct ExtensionMsg_Loaded_Params { + ExtensionMsg_Loaded_Params(); + ~ExtensionMsg_Loaded_Params(); + explicit ExtensionMsg_Loaded_Params(const Extension* extension); + + // A copy constructor is needed because this structure can end up getting + // copied inside the IPC machinery on gcc <= 4.2. + ExtensionMsg_Loaded_Params(const ExtensionMsg_Loaded_Params& other); + + // Creates a new extension from the data in this object. + scoped_refptr<Extension> ConvertToExtension() const; + + // The subset of the extension manifest data we send to renderers. + scoped_ptr<DictionaryValue> manifest; + + // The location the extension was installed from. + Extension::Location location; + + // The path the extension was loaded from. This is used in the renderer only + // to generate the extension ID for extensions that are loaded unpacked. + FilePath path; + + // We keep this separate so that it can be used in logging. + std::string id; +}; + +namespace IPC { + +template <> +struct ParamTraits<URLPattern> { + typedef URLPattern param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, void** iter, param_type* p); + static void Log(const param_type& p, std::string* l); +}; + +template <> +struct ParamTraits<ExtensionExtent> { + typedef ExtensionExtent param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, void** iter, param_type* p); + static void Log(const param_type& p, std::string* l); +}; + +template <> +struct ParamTraits<ExtensionMsg_Loaded_Params> { + typedef ExtensionMsg_Loaded_Params param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, void** iter, param_type* p); + static void Log(const param_type& p, std::string* l); +}; + +} // namespace IPC + +#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGES_H_ + +// Messages sent from the browser to the renderer. + +// The browser sends this message in response to all extension api calls. +IPC_MESSAGE_ROUTED4(ExtensionMsg_Response, + int /* request_id */, + bool /* success */, + std::string /* response */, + std::string /* error */) + +// This message is optionally routed. If used as a control message, it +// will call a javascript function in every registered context in the +// target process. If routed, it will be restricted to the contexts that +// are part of the target RenderView. +// If |extension_id| is non-empty, the function will be invoked only in +// contexts owned by the extension. |args| is a list of primitive Value types +// that are passed to the function. +IPC_MESSAGE_ROUTED4(ExtensionMsg_MessageInvoke, + std::string /* extension_id */, + std::string /* function_name */, + ListValue /* args */, + GURL /* event URL */) + +// Tell the renderer process all known extension function names. +IPC_MESSAGE_CONTROL1(ExtensionMsg_SetFunctionNames, + std::vector<std::string>) + +// TODO(aa): SetAPIPermissions, SetHostPermissions, and possibly +// UpdatePageActions should be replaced with just sending additional data in +// ExtensionLoaded. See: crbug.com/70516. + +// Tell the renderer process which permissions the given extension has. See +// Extension::Permissions for which elements correspond to which permissions. +IPC_MESSAGE_CONTROL2(ExtensionMsg_SetAPIPermissions, + std::string /* extension_id */, + std::set<std::string> /* permissions */) + +// Tell the renderer process which host permissions the given extension has. +IPC_MESSAGE_CONTROL2(ExtensionMsg_SetHostPermissions, + GURL /* source extension's origin */, + /* URLPatterns the extension can access */ + std::vector<URLPattern>) + +// Tell the renderer process all known page action ids for a particular +// extension. +IPC_MESSAGE_CONTROL2(ExtensionMsg_UpdatePageActions, + std::string /* extension_id */, + std::vector<std::string> /* page_action_ids */) + +// Notifies the renderer that an extension was loaded in the browser. +IPC_MESSAGE_CONTROL1(ExtensionMsg_Loaded, + ExtensionMsg_Loaded_Params) + +// Notifies the renderer that an extension was unloaded in the browser. +IPC_MESSAGE_CONTROL1(ExtensionMsg_Unloaded, + std::string) + +// Updates the scripting whitelist for extensions in the render process. This is +// only used for testing. +IPC_MESSAGE_CONTROL1(ExtensionMsg_SetScriptingWhitelist, + Extension::ScriptingWhitelist /* extenison ids */) + +// Notification that renderer should run some JavaScript code. +IPC_MESSAGE_ROUTED1(ExtensionMsg_ExecuteCode, + ExtensionMsg_ExecuteCode_Params) + +// Requests application info for the page. The renderer responds back with +// ExtensionHostMsg_DidGetApplicationInfo. +IPC_MESSAGE_ROUTED1(ExtensionMsg_GetApplicationInfo, + int32 /*page_id*/) + +// Messages sent from the renderer to the browser. + +// A renderer sends this message when an extension process starts an API +// request. The browser will always respond with a ExtensionMsg_Response. +IPC_MESSAGE_ROUTED1(ExtensionHostMsg_Request, + ExtensionHostMsg_DomMessage_Params) + +// Notify the browser that the given extension added a listener to an event. +IPC_MESSAGE_CONTROL2(ExtensionHostMsg_AddListener, + std::string /* extension_id */, + std::string /* name */) + +// Notify the browser that the given extension removed a listener from an +// event. +IPC_MESSAGE_CONTROL2(ExtensionHostMsg_RemoveListener, + std::string /* extension_id */, + std::string /* name */) + +// Open a channel to all listening contexts owned by the extension with +// the given ID. This always returns a valid port ID which can be used for +// sending messages. If an error occurred, the opener will be notified +// asynchronously. +IPC_SYNC_MESSAGE_CONTROL4_1(ExtensionHostMsg_OpenChannelToExtension, + int /* routing_id */, + std::string /* source_extension_id */, + std::string /* target_extension_id */, + std::string /* channel_name */, + int /* port_id */) + +// Get a port handle to the given tab. The handle can be used for sending +// messages to the extension. +IPC_SYNC_MESSAGE_CONTROL4_1(ExtensionHostMsg_OpenChannelToTab, + int /* routing_id */, + int /* tab_id */, + std::string /* extension_id */, + std::string /* channel_name */, + int /* port_id */) + +// Send a message to an extension process. The handle is the value returned +// by ViewHostMsg_OpenChannelTo*. +IPC_MESSAGE_ROUTED2(ExtensionHostMsg_PostMessage, + int /* port_id */, + std::string /* message */) + +// Send a message to an extension process. The handle is the value returned +// by ViewHostMsg_OpenChannelTo*. +IPC_MESSAGE_CONTROL1(ExtensionHostMsg_CloseChannel, + int /* port_id */) + +// Used to get the extension message bundle. +IPC_SYNC_MESSAGE_CONTROL1_1(ExtensionHostMsg_GetMessageBundle, + std::string /* extension id */, + SubstitutionMap /* message bundle */) + +// Send from the renderer to the browser to return the script running result. +IPC_MESSAGE_ROUTED2(ViewHostMsg_ExecuteCodeFinished, + int, /* request id */ + bool /* whether the script ran successfully */) + + +IPC_MESSAGE_ROUTED2(ExtensionHostMsg_DidGetApplicationInfo, + int32 /* page_id */, + WebApplicationInfo) + +// Sent by the renderer to implement chrome.app.installApplication(). +IPC_MESSAGE_ROUTED1(ExtensionHostMsg_InstallApplication, + WebApplicationInfo) diff --git a/chrome/common/render_messages.cc b/chrome/common/render_messages.cc index 051e63f..7fd44d4 100644 --- a/chrome/common/render_messages.cc +++ b/chrome/common/render_messages.cc @@ -26,46 +26,4 @@ void ParamTraits<ContentSettings>::Log( l->append("<ContentSettings>"); } -void ParamTraits<URLPattern>::Write(Message* m, const param_type& p) { - WriteParam(m, p.valid_schemes()); - WriteParam(m, p.GetAsString()); -} - -bool ParamTraits<URLPattern>::Read(const Message* m, void** iter, - param_type* p) { - int valid_schemes; - std::string spec; - if (!ReadParam(m, iter, &valid_schemes) || - !ReadParam(m, iter, &spec)) - return false; - - p->set_valid_schemes(valid_schemes); - return URLPattern::PARSE_SUCCESS == p->Parse(spec, URLPattern::PARSE_LENIENT); -} - -void ParamTraits<URLPattern>::Log(const param_type& p, std::string* l) { - LogParam(p.GetAsString(), l); -} - -void ParamTraits<ExtensionExtent>::Write(Message* m, const param_type& p) { - WriteParam(m, p.patterns()); -} - -bool ParamTraits<ExtensionExtent>::Read(const Message* m, void** iter, - param_type* p) { - std::vector<URLPattern> patterns; - bool success = - ReadParam(m, iter, &patterns); - if (!success) - return false; - - for (size_t i = 0; i < patterns.size(); ++i) - p->AddPattern(patterns[i]); - return true; -} - -void ParamTraits<ExtensionExtent>::Log(const param_type& p, std::string* l) { - LogParam(p.patterns(), l); -} - } // namespace IPC diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index ba5207f..5bc6626 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -18,36 +18,23 @@ #include "base/values.h" #include "build/build_config.h" #include "chrome/common/content_settings.h" -#include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_extent.h" -#include "chrome/common/extensions/url_pattern.h" #include "chrome/common/instant_types.h" #include "chrome/common/nacl_types.h" #include "chrome/common/render_messages_params.h" #include "chrome/common/thumbnail_score.h" #include "chrome/common/translate_errors.h" #include "chrome/common/view_types.h" -#include "chrome/common/web_apps.h" #include "content/common/common_param_traits.h" -#include "chrome/common/web_apps.h" #include "ipc/ipc_message_macros.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/rect.h" -// TODO(mpcomplete): rename ViewMsg and ViewHostMsg to something that makes -// more sense with our current design. - -// Singly-included section, not yet converted. +// Singly-included section for enums and custom IPC traits. #ifndef CHROME_COMMON_RENDER_MESSAGES_H_ #define CHROME_COMMON_RENDER_MESSAGES_H_ -// IPC_MESSAGE macros choke on extra , in the std::map, when expanding. We need -// to typedef it to avoid that. -// Substitution map for l10n messages. -typedef std::map<std::string, std::string> SubstitutionMap; - // Values that may be OR'd together to form the 'flags' parameter of the // ViewMsg_EnablePreferredSizeChangedMode message. enum ViewHostMsg_EnablePreferredSizeChangedMode_Flags { @@ -104,22 +91,6 @@ struct ParamTraits<ContentSettings> { static void Log(const param_type& p, std::string* l); }; -template <> -struct ParamTraits<URLPattern> { - typedef URLPattern param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, void** iter, param_type* p); - static void Log(const param_type& p, std::string* l); -}; - -template <> -struct ParamTraits<ExtensionExtent> { - typedef ExtensionExtent param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, void** iter, param_type* p); - static void Log(const param_type& p, std::string* l); -}; - } // namespace IPC #endif // CHROME_COMMON_RENDER_MESSAGES_H_ @@ -140,22 +111,6 @@ IPC_STRUCT_TRAITS_BEGIN(ThumbnailScore) IPC_STRUCT_TRAITS_MEMBER(time_at_snapshot) IPC_STRUCT_TRAITS_END() -IPC_STRUCT_TRAITS_BEGIN(WebApplicationInfo::IconInfo) - IPC_STRUCT_TRAITS_MEMBER(url) - IPC_STRUCT_TRAITS_MEMBER(width) - IPC_STRUCT_TRAITS_MEMBER(height) - IPC_STRUCT_TRAITS_MEMBER(data) -IPC_STRUCT_TRAITS_END() - -IPC_STRUCT_TRAITS_BEGIN(WebApplicationInfo) - IPC_STRUCT_TRAITS_MEMBER(title) - IPC_STRUCT_TRAITS_MEMBER(description) - IPC_STRUCT_TRAITS_MEMBER(app_url) - IPC_STRUCT_TRAITS_MEMBER(icons) - IPC_STRUCT_TRAITS_MEMBER(permissions) - IPC_STRUCT_TRAITS_MEMBER(launch_container) -IPC_STRUCT_TRAITS_END() - IPC_STRUCT_TRAITS_BEGIN(WebKit::WebCache::ResourceTypeStat) IPC_STRUCT_TRAITS_MEMBER(count) IPC_STRUCT_TRAITS_MEMBER(size) @@ -269,10 +224,6 @@ IPC_MESSAGE_ROUTED3(ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, std::vector<FilePath> /* paths of local copy */, FilePath /* local directory path */) -// Requests application info for the page. The renderer responds back with -// ViewHostMsg_DidGetApplicationInfo. -IPC_MESSAGE_ROUTED1(ViewMsg_GetApplicationInfo, int32 /*page_id*/) - // Requests the renderer to download the specified favicon image encode it as // PNG and send the PNG data back ala ViewHostMsg_DidDownloadFavicon. IPC_MESSAGE_ROUTED3(ViewMsg_DownloadFavicon, @@ -316,63 +267,6 @@ IPC_MESSAGE_ROUTED0(ViewMsg_DisassociateFromPopupCount) IPC_MESSAGE_ROUTED1(ViewMsg_AllowScriptToClose, bool /* script_can_close */) -// The browser sends this message in response to all extension api calls. -IPC_MESSAGE_ROUTED4(ViewMsg_ExtensionResponse, - int /* request_id */, - bool /* success */, - std::string /* response */, - std::string /* error */) - -// This message is optionally routed. If used as a control message, it -// will call a javascript function in every registered context in the -// target process. If routed, it will be restricted to the contexts that -// are part of the target RenderView. -// If |extension_id| is non-empty, the function will be invoked only in -// contexts owned by the extension. |args| is a list of primitive Value types -// that are passed to the function. -IPC_MESSAGE_ROUTED4(ViewMsg_ExtensionMessageInvoke, - std::string /* extension_id */, - std::string /* function_name */, - ListValue /* args */, - GURL /* event URL */) - -// Tell the renderer process all known extension function names. -IPC_MESSAGE_CONTROL1(ViewMsg_Extension_SetFunctionNames, - std::vector<std::string>) - -// TODO(aa): SetAPIPermissions, SetHostPermissions, and possibly -// UpdatePageActions should be replaced with just sending additional data in -// ExtensionLoaded. See: crbug.com/70516. - -// Tell the renderer process which permissions the given extension has. See -// Extension::Permissions for which elements correspond to which permissions. -IPC_MESSAGE_CONTROL2(ViewMsg_Extension_SetAPIPermissions, - std::string /* extension_id */, - std::set<std::string> /* permissions */) - -// Tell the renderer process which host permissions the given extension has. -IPC_MESSAGE_CONTROL2( - ViewMsg_Extension_SetHostPermissions, - GURL /* source extension's origin */, - std::vector<URLPattern> /* URLPatterns the extension can access */) - -// Tell the renderer process all known page action ids for a particular -// extension. -IPC_MESSAGE_CONTROL2(ViewMsg_Extension_UpdatePageActions, - std::string /* extension_id */, - std::vector<std::string> /* page_action_ids */) - -// Notifies the renderer that an extension was loaded in the browser. -IPC_MESSAGE_CONTROL1(ViewMsg_ExtensionLoaded, ViewMsg_ExtensionLoaded_Params) - -// Notifies the renderer that an extension was unloaded in the browser. -IPC_MESSAGE_CONTROL1(ViewMsg_ExtensionUnloaded, std::string) - -// Updates the scripting whitelist for extensions in the render process. This is -// only used for testing. -IPC_MESSAGE_CONTROL1(ViewMsg_Extension_SetScriptingWhitelist, - Extension::ScriptingWhitelist /* extenison ids */) - IPC_MESSAGE_ROUTED4(ViewMsg_SearchBoxChange, string16 /* value */, bool /* verbatim */, @@ -398,10 +292,6 @@ IPC_MESSAGE_ROUTED1(ViewMsg_UpdateBrowserWindowId, IPC_MESSAGE_ROUTED1(ViewMsg_NotifyRenderViewType, ViewType::Type /* view_type */) -// Notification that renderer should run some JavaScript code. -IPC_MESSAGE_ROUTED1(ViewMsg_ExecuteCode, - ViewMsg_ExecuteCode_Params) - // Tells the renderer to translate the page contents from one language to // another. IPC_MESSAGE_ROUTED4(ViewMsg_TranslatePage, @@ -435,11 +325,6 @@ IPC_MESSAGE_ROUTED2(ViewHostMsg_ContentBlocked, ContentSettingsType, /* type of blocked content */ std::string /* resource identifier */) -// Used to get the extension message bundle. -IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_GetExtensionMessageBundle, - std::string /* extension id */, - SubstitutionMap /* message bundle */) - // Specifies the URL as the first parameter (a wstring) and thumbnail as // binary data as the second parameter. IPC_MESSAGE_ROUTED3(ViewHostMsg_Thumbnail, @@ -550,14 +435,6 @@ IPC_MESSAGE_ROUTED3(ViewHostMsg_SendSerializedHtmlData, std::string /* data buffer */, int32 /* complete status */) -IPC_MESSAGE_ROUTED2(ViewHostMsg_DidGetApplicationInfo, - int32 /* page_id */, - WebApplicationInfo) - -// Sent by the renderer to implement chrome.app.installApplication(). -IPC_MESSAGE_ROUTED1(ViewHostMsg_InstallApplication, - WebApplicationInfo) - IPC_MESSAGE_ROUTED4(ViewHostMsg_DidDownloadFavicon, int /* Identifier of the request */, GURL /* URL of the image */, @@ -569,22 +446,6 @@ IPC_MESSAGE_ROUTED4(ViewHostMsg_DidDownloadFavicon, IPC_MESSAGE_CONTROL1(ViewHostMsg_ResourceTypeStats, WebKit::WebCache::ResourceTypeStats) -// A renderer sends this message when an extension process starts an API -// request. The browser will always respond with a ViewMsg_ExtensionResponse. -IPC_MESSAGE_ROUTED1(ViewHostMsg_ExtensionRequest, - ViewHostMsg_DomMessage_Params) - -// Notify the browser that the given extension added a listener to an event. -IPC_MESSAGE_CONTROL2(ViewHostMsg_ExtensionAddListener, - std::string /* extension_id */, - std::string /* name */) - -// Notify the browser that the given extension removed a listener from an -// event. -IPC_MESSAGE_CONTROL2(ViewHostMsg_ExtensionRemoveListener, - std::string /* extension_id */, - std::string /* name */) - // Message sent from renderer to the browser to update the state of a command. // The |command| parameter is a RenderViewCommand. The |checked_state| parameter // is a CommandCheckedState. @@ -593,40 +454,6 @@ IPC_MESSAGE_ROUTED3(ViewHostMsg_CommandStateChanged, bool /* is_enabled */, int /* checked_state */) -// Open a channel to all listening contexts owned by the extension with -// the given ID. This always returns a valid port ID which can be used for -// sending messages. If an error occurred, the opener will be notified -// asynchronously. -IPC_SYNC_MESSAGE_CONTROL4_1(ViewHostMsg_OpenChannelToExtension, - int /* routing_id */, - std::string /* source_extension_id */, - std::string /* target_extension_id */, - std::string /* channel_name */, - int /* port_id */) - -// Get a port handle to the given tab. The handle can be used for sending -// messages to the extension. -IPC_SYNC_MESSAGE_CONTROL4_1(ViewHostMsg_OpenChannelToTab, - int /* routing_id */, - int /* tab_id */, - std::string /* extension_id */, - std::string /* channel_name */, - int /* port_id */) - -// Send a message to an extension process. The handle is the value returned -// by ViewHostMsg_OpenChannelTo*. -IPC_MESSAGE_ROUTED2(ViewHostMsg_ExtensionPostMessage, - int /* port_id */, - std::string /* message */) - -// Send a message to an extension process. The handle is the value returned -// by ViewHostMsg_OpenChannelTo*. -IPC_MESSAGE_CONTROL1(ViewHostMsg_ExtensionCloseChannel, - int /* port_id */) - -// Sent by the renderer process to acknowledge receipt of a -// ViewMsg_CSSInsertRequest message and css has been inserted into the frame. -IPC_MESSAGE_ROUTED0(ViewHostMsg_OnCSSInserted) // Notifies the browser of the language (ISO 639_1 code language, such as fr, // en, zh...) of the current page. @@ -671,8 +498,3 @@ IPC_MESSAGE_ROUTED3(ViewHostMsg_RegisterProtocolHandler, std::string /* scheme */, GURL /* url */, string16 /* title */) - -// Send from the renderer to the browser to return the script running result. -IPC_MESSAGE_ROUTED2(ViewHostMsg_ExecuteCodeFinished, - int, /* request id */ - bool /* whether the script ran successfully */) diff --git a/chrome/common/render_messages_params.cc b/chrome/common/render_messages_params.cc index 9dce8f1..71824db 100644 --- a/chrome/common/render_messages_params.cc +++ b/chrome/common/render_messages_params.cc @@ -4,117 +4,10 @@ #include "chrome/common/render_messages_params.h" -#include "chrome/common/extensions/extension_constants.h" #include "chrome/common/render_messages.h" -ViewMsg_ExecuteCode_Params::ViewMsg_ExecuteCode_Params() { -} - -ViewMsg_ExecuteCode_Params::ViewMsg_ExecuteCode_Params( - int request_id, - const std::string& extension_id, - bool is_javascript, - const std::string& code, - bool all_frames) - : request_id(request_id), extension_id(extension_id), - is_javascript(is_javascript), - code(code), all_frames(all_frames) { -} - -ViewMsg_ExecuteCode_Params::~ViewMsg_ExecuteCode_Params() { -} - -ViewHostMsg_DomMessage_Params::ViewHostMsg_DomMessage_Params() - : request_id(0), - has_callback(false), - user_gesture(false) { -} - -ViewHostMsg_DomMessage_Params::~ViewHostMsg_DomMessage_Params() { -} - -ViewMsg_ExtensionLoaded_Params::ViewMsg_ExtensionLoaded_Params() - : location(Extension::INVALID) { -} - -ViewMsg_ExtensionLoaded_Params::~ViewMsg_ExtensionLoaded_Params() { -} - -ViewMsg_ExtensionLoaded_Params::ViewMsg_ExtensionLoaded_Params( - const ViewMsg_ExtensionLoaded_Params& other) - : manifest(other.manifest->DeepCopy()), - location(other.location), - path(other.path), - id(other.id) { -} - -ViewMsg_ExtensionLoaded_Params::ViewMsg_ExtensionLoaded_Params( - const Extension* extension) - : manifest(new DictionaryValue()), - location(extension->location()), - path(extension->path()), - id(extension->id()) { - // As we need more bits of extension data in the renderer, add more keys to - // this list. - const char* kRendererExtensionKeys[] = { - extension_manifest_keys::kPublicKey, - extension_manifest_keys::kName, - extension_manifest_keys::kVersion, - extension_manifest_keys::kIcons, - extension_manifest_keys::kPermissions, - extension_manifest_keys::kApp - }; - - // Copy only the data we need. - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRendererExtensionKeys); ++i) { - Value* temp = NULL; - if (extension->manifest_value()->Get(kRendererExtensionKeys[i], &temp)) - manifest->Set(kRendererExtensionKeys[i], temp->DeepCopy()); - } -} - -scoped_refptr<Extension> - ViewMsg_ExtensionLoaded_Params::ConvertToExtension() const { - // Extensions that are loaded unpacked won't have a key. - const bool kRequireKey = false; - - // The extension may have been loaded in a way that does not require - // strict error checks to pass. Do not do strict checks here. - const bool kStrictErrorChecks = false; - std::string error; - - scoped_refptr<Extension> extension( - Extension::Create(path, location, *manifest, kRequireKey, - kStrictErrorChecks, &error)); - if (!extension.get()) - LOG(ERROR) << "Error deserializing extension: " << error; - - return extension; -} - namespace IPC { -template <> -struct ParamTraits<Extension::Location> { - typedef Extension::Location param_type; - static void Write(Message* m, const param_type& p) { - int val = static_cast<int>(p); - WriteParam(m, val); - } - static bool Read(const Message* m, void** iter, param_type* p) { - int val = 0; - if (!ReadParam(m, iter, &val) || - val < Extension::INVALID || - val >= Extension::NUM_LOCATIONS) - return false; - *p = static_cast<param_type>(val); - return true; - } - static void Log(const param_type& p, std::string* l) { - ParamTraits<int>::Log(static_cast<int>(p), l); - } -}; - void ParamTraits<ViewHostMsg_PageHasOSDD_Type>::Write(Message* m, const param_type& p) { m->WriteInt(p.type); @@ -192,89 +85,4 @@ void ParamTraits<ViewHostMsg_GetSearchProviderInstallState_Params>::Log( LogParam(state, l); } -void ParamTraits<ViewMsg_ExecuteCode_Params>::Write(Message* m, - const param_type& p) { - WriteParam(m, p.request_id); - WriteParam(m, p.extension_id); - WriteParam(m, p.is_javascript); - WriteParam(m, p.code); - WriteParam(m, p.all_frames); -} - -bool ParamTraits<ViewMsg_ExecuteCode_Params>::Read(const Message* m, - void** iter, - param_type* p) { - return - ReadParam(m, iter, &p->request_id) && - ReadParam(m, iter, &p->extension_id) && - ReadParam(m, iter, &p->is_javascript) && - ReadParam(m, iter, &p->code) && - ReadParam(m, iter, &p->all_frames); -} - -void ParamTraits<ViewMsg_ExecuteCode_Params>::Log(const param_type& p, - std::string* l) { - l->append("<ViewMsg_ExecuteCode_Params>"); -} - -void ParamTraits<ViewMsg_ExtensionLoaded_Params>::Write(Message* m, - const param_type& p) { - WriteParam(m, p.location); - WriteParam(m, p.path); - WriteParam(m, *(p.manifest)); -} - -bool ParamTraits<ViewMsg_ExtensionLoaded_Params>::Read(const Message* m, - void** iter, - param_type* p) { - p->manifest.reset(new DictionaryValue()); - return ReadParam(m, iter, &p->location) && - ReadParam(m, iter, &p->path) && - ReadParam(m, iter, p->manifest.get()); -} - -void ParamTraits<ViewMsg_ExtensionLoaded_Params>::Log(const param_type& p, - std::string* l) { - l->append(p.id); -} - -void ParamTraits<ViewHostMsg_DomMessage_Params>::Write(Message* m, - const param_type& p) { - WriteParam(m, p.name); - WriteParam(m, p.arguments); - WriteParam(m, p.source_url); - WriteParam(m, p.request_id); - WriteParam(m, p.has_callback); - WriteParam(m, p.user_gesture); -} - -bool ParamTraits<ViewHostMsg_DomMessage_Params>::Read(const Message* m, - void** iter, - param_type* p) { - return - ReadParam(m, iter, &p->name) && - ReadParam(m, iter, &p->arguments) && - ReadParam(m, iter, &p->source_url) && - ReadParam(m, iter, &p->request_id) && - ReadParam(m, iter, &p->has_callback) && - ReadParam(m, iter, &p->user_gesture); -} - -void ParamTraits<ViewHostMsg_DomMessage_Params>::Log(const param_type& p, - std::string* l) { - l->append("("); - LogParam(p.name, l); - l->append(", "); - LogParam(p.arguments, l); - l->append(", "); - LogParam(p.source_url, l); - l->append(", "); - LogParam(p.request_id, l); - l->append(", "); - LogParam(p.has_callback, l); - l->append(", "); - LogParam(p.user_gesture, l); - l->append(")"); -} - } // namespace IPC diff --git a/chrome/common/render_messages_params.h b/chrome/common/render_messages_params.h index f7bf677..ae2330f 100644 --- a/chrome/common/render_messages_params.h +++ b/chrome/common/render_messages_params.h @@ -8,17 +8,8 @@ #include <string> -#include "base/values.h" -#include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_extent.h" -#include "chrome/common/extensions/url_pattern.h" -#include "googleurl/src/gurl.h" #include "ipc/ipc_param_traits.h" -namespace net { -class UploadData; -} - // The type of OSDD that the renderer is giving to the browser. struct ViewHostMsg_PageHasOSDD_Type { enum Type { @@ -104,82 +95,6 @@ struct ViewHostMsg_GetSearchProviderInstallState_Params { } }; -// Allows an extension to execute code in a tab. -struct ViewMsg_ExecuteCode_Params { - ViewMsg_ExecuteCode_Params(); - ViewMsg_ExecuteCode_Params(int request_id, const std::string& extension_id, - bool is_javascript, const std::string& code, - bool all_frames); - ~ViewMsg_ExecuteCode_Params(); - - // The extension API request id, for responding. - int request_id; - - // The ID of the requesting extension. To know which isolated world to - // execute the code inside of. - std::string extension_id; - - // Whether the code is JavaScript or CSS. - bool is_javascript; - - // String of code to execute. - std::string code; - - // Whether to inject into all frames, or only the root frame. - bool all_frames; -}; - -struct ViewMsg_ExtensionLoaded_Params { - ViewMsg_ExtensionLoaded_Params(); - ~ViewMsg_ExtensionLoaded_Params(); - explicit ViewMsg_ExtensionLoaded_Params(const Extension* extension); - - // A copy constructor is needed because this structure can end up getting - // copied inside the IPC machinery on gcc <= 4.2. - ViewMsg_ExtensionLoaded_Params( - const ViewMsg_ExtensionLoaded_Params& other); - - // Creates a new extension from the data in this object. - scoped_refptr<Extension> ConvertToExtension() const; - - // The subset of the extension manifest data we send to renderers. - scoped_ptr<DictionaryValue> manifest; - - // The location the extension was installed from. - Extension::Location location; - - // The path the extension was loaded from. This is used in the renderer only - // to generate the extension ID for extensions that are loaded unpacked. - FilePath path; - - // We keep this separate so that it can be used in logging. - std::string id; -}; - -// Parameters structure for ViewHostMsg_ExtensionRequest. -struct ViewHostMsg_DomMessage_Params { - ViewHostMsg_DomMessage_Params(); - ~ViewHostMsg_DomMessage_Params(); - - // Message name. - std::string name; - - // List of message arguments. - ListValue arguments; - - // URL of the frame request was sent from. - GURL source_url; - - // Unique request id to match requests and responses. - int request_id; - - // True if request has a callback specified. - bool has_callback; - - // True if request is executed in response to an explicit user gesture. - bool user_gesture; -}; - namespace IPC { class Message; @@ -200,30 +115,6 @@ struct ParamTraits<ViewHostMsg_GetSearchProviderInstallState_Params> { static void Log(const param_type& p, std::string* l); }; -template <> -struct ParamTraits<ViewMsg_ExecuteCode_Params> { - typedef ViewMsg_ExecuteCode_Params param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, void** iter, param_type* p); - static void Log(const param_type& p, std::string* l); -}; - -template <> -struct ParamTraits<ViewMsg_ExtensionLoaded_Params> { - typedef ViewMsg_ExtensionLoaded_Params param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, void** iter, param_type* p); - static void Log(const param_type& p, std::string* l); -}; - -template <> -struct ParamTraits<ViewHostMsg_DomMessage_Params> { - typedef ViewHostMsg_DomMessage_Params param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, void** iter, param_type* p); - static void Log(const param_type& p, std::string* l); -}; - } // namespace IPC #endif // CHROME_COMMON_RENDER_MESSAGES_PARAMS_H_ diff --git a/chrome/renderer/extensions/event_bindings.cc b/chrome/renderer/extensions/event_bindings.cc index 62787b1..7dd83ca 100644 --- a/chrome/renderer/extensions/event_bindings.cc +++ b/chrome/renderer/extensions/event_bindings.cc @@ -6,8 +6,8 @@ #include "base/basictypes.h" #include "base/lazy_instance.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/extensions/extension_set.h" -#include "chrome/common/render_messages.h" #include "chrome/common/url_constants.h" #include "chrome/renderer/extensions/bindings_utils.h" #include "chrome/renderer/extensions/event_bindings.h" @@ -108,8 +108,8 @@ class ExtensionImpl : public ExtensionBase { if (++listener_counts[event_name] == 1) { EventBindings::GetRenderThread()->Send( - new ViewHostMsg_ExtensionAddListener(context_info->extension_id, - event_name)); + new ExtensionHostMsg_AddListener(context_info->extension_id, + event_name)); } if (++context_info->num_connected_events == 1) @@ -135,8 +135,8 @@ class ExtensionImpl : public ExtensionBase { std::string event_name(*v8::String::AsciiValue(args[0])); if (--listener_counts[event_name] == 0) { EventBindings::GetRenderThread()->Send( - new ViewHostMsg_ExtensionRemoveListener(context_info->extension_id, - event_name)); + new ExtensionHostMsg_RemoveListener(context_info->extension_id, + event_name)); } if (--context_info->num_connected_events == 0) { diff --git a/chrome/renderer/extensions/extension_helper.cc b/chrome/renderer/extensions/extension_helper.cc new file mode 100644 index 0000000..d089955 --- /dev/null +++ b/chrome/renderer/extensions/extension_helper.cc @@ -0,0 +1,42 @@ +// Copyright (c) 2011 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. + +#include "chrome/renderer/extensions/extension_helper.h" + +#include "chrome/common/extensions/extension_messages.h" +#include "chrome/renderer/extensions/extension_process_bindings.h" +#include "chrome/renderer/extensions/renderer_extension_bindings.h" + +ExtensionHelper::ExtensionHelper(RenderView* render_view) + : RenderViewObserver(render_view) { +} + +ExtensionHelper::~ExtensionHelper() { +} + +bool ExtensionHelper::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(ExtensionHelper, message) + IPC_MESSAGE_HANDLER(ExtensionMsg_Response, OnExtensionResponse) + IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnExtensionMessageInvoke) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void ExtensionHelper::OnExtensionResponse(int request_id, + bool success, + const std::string& response, + const std::string& error) { + ExtensionProcessBindings::HandleResponse( + request_id, success, response, error); +} + +void ExtensionHelper::OnExtensionMessageInvoke(const std::string& extension_id, + const std::string& function_name, + const ListValue& args, + const GURL& event_url) { + RendererExtensionBindings::Invoke( + extension_id, function_name, args, render_view(), event_url); +} diff --git a/chrome/renderer/extensions/extension_helper.h b/chrome/renderer/extensions/extension_helper.h new file mode 100644 index 0000000..d18ad48 --- /dev/null +++ b/chrome/renderer/extensions/extension_helper.h @@ -0,0 +1,36 @@ +// Copyright (c) 2011 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. + +#ifndef CHROME_RENDERER_EXTENSIONS_EXTENSION_HELPER_H_ +#define CHROME_RENDERER_EXTENSIONS_EXTENSION_HELPER_H_ +#pragma once + +#include "content/renderer/render_view_observer.h" + +class GURL; +class ListValue; + +// Filters extension related messages sent to RenderViews. +class ExtensionHelper : public RenderViewObserver { + public: + explicit ExtensionHelper(RenderView* render_view); + virtual ~ExtensionHelper(); + + private: + // RenderViewObserver implementation. + virtual bool OnMessageReceived(const IPC::Message& message); + + void OnExtensionResponse(int request_id, bool success, + const std::string& response, + const std::string& error); + void OnExtensionMessageInvoke(const std::string& extension_id, + const std::string& function_name, + const ListValue& args, + const GURL& event_url); + + + DISALLOW_COPY_AND_ASSIGN(ExtensionHelper); +}; + +#endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_HELPER_H_ diff --git a/chrome/renderer/extensions/extension_process_bindings.cc b/chrome/renderer/extensions/extension_process_bindings.cc index 4ae044e..510da83 100644 --- a/chrome/renderer/extensions/extension_process_bindings.cc +++ b/chrome/renderer/extensions/extension_process_bindings.cc @@ -17,6 +17,7 @@ #include "base/string_util.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_constants.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/extensions/extension_set.h" #include "chrome/common/extensions/url_pattern.h" #include "chrome/common/render_messages.h" @@ -332,7 +333,7 @@ class ExtensionImpl : public ExtensionBase { std::string extension_id = *v8::String::Utf8Value(args[1]->ToString()); std::string channel_name = *v8::String::Utf8Value(args[2]->ToString()); int port_id = -1; - renderview->Send(new ViewHostMsg_OpenChannelToTab( + renderview->Send(new ExtensionHostMsg_OpenChannelToTab( renderview->routing_id(), tab_id, extension_id, channel_name, &port_id)); return v8::Integer::New(port_id); @@ -398,14 +399,15 @@ class ExtensionImpl : public ExtensionBase { GetPendingRequestMap()[request_id].reset(new PendingRequest( current_context, name)); - ViewHostMsg_DomMessage_Params params; + ExtensionHostMsg_DomMessage_Params params; params.name = name; params.arguments.Swap(value_args); params.source_url = source_url; params.request_id = request_id; params.has_callback = has_callback; params.user_gesture = webframe->isProcessingUserGesture(); - renderview->SendExtensionRequest(params); + renderview->Send(new ExtensionHostMsg_Request( + renderview->routing_id(), params)); return v8::Undefined(); } diff --git a/chrome/renderer/extensions/renderer_extension_bindings.cc b/chrome/renderer/extensions/renderer_extension_bindings.cc index f8cfe14..1a5cc2e 100644 --- a/chrome/renderer/extensions/renderer_extension_bindings.cc +++ b/chrome/renderer/extensions/renderer_extension_bindings.cc @@ -11,7 +11,7 @@ #include "base/lazy_instance.h" #include "base/values.h" #include "chrome/common/extensions/extension_message_bundle.h" -#include "chrome/common/render_messages.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/url_constants.h" #include "chrome/renderer/extensions/bindings_utils.h" #include "chrome/renderer/extensions/event_bindings.h" @@ -104,7 +104,7 @@ class ExtensionImpl : public ExtensionBase { std::string target_id = *v8::String::Utf8Value(args[1]->ToString()); std::string channel_name = *v8::String::Utf8Value(args[2]->ToString()); int port_id = -1; - renderview->Send(new ViewHostMsg_OpenChannelToExtension( + renderview->Send(new ExtensionHostMsg_OpenChannelToExtension( renderview->routing_id(), source_id, target_id, channel_name, &port_id)); return v8::Integer::New(port_id); @@ -125,7 +125,7 @@ class ExtensionImpl : public ExtensionBase { v8::String::New(kPortClosedError))); } std::string message = *v8::String::Utf8Value(args[1]->ToString()); - renderview->Send(new ViewHostMsg_ExtensionPostMessage( + renderview->Send(new ExtensionHostMsg_PostMessage( renderview->routing_id(), port_id, message)); } return v8::Undefined(); @@ -142,7 +142,7 @@ class ExtensionImpl : public ExtensionBase { bool notify_browser = args[1]->BooleanValue(); if (notify_browser) EventBindings::GetRenderThread()->Send( - new ViewHostMsg_ExtensionCloseChannel(port_id)); + new ExtensionHostMsg_CloseChannel(port_id)); ClearPortData(port_id); } return v8::Undefined(); @@ -167,7 +167,7 @@ class ExtensionImpl : public ExtensionBase { if (HasPortData(port_id) && --GetPortData(port_id).ref_count == 0) { // Send via the RenderThread because the RenderView might be closing. EventBindings::GetRenderThread()->Send( - new ViewHostMsg_ExtensionCloseChannel(port_id)); + new ExtensionHostMsg_CloseChannel(port_id)); ClearPortData(port_id); } } @@ -199,7 +199,7 @@ class ExtensionImpl : public ExtensionBase { L10nMessagesMap messages; // A sync call to load message catalogs for current extension. - renderview->Send(new ViewHostMsg_GetExtensionMessageBundle( + renderview->Send(new ExtensionHostMsg_GetMessageBundle( extension_id, &messages)); // Save messages we got. diff --git a/chrome/renderer/mock_render_thread.cc b/chrome/renderer/mock_render_thread.cc index aa45dba..0ae683d 100644 --- a/chrome/renderer/mock_render_thread.cc +++ b/chrome/renderer/mock_render_thread.cc @@ -8,6 +8,7 @@ #include "base/file_util.h" #include "base/process_util.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/print_messages.h" #include "chrome/common/render_messages.h" #include "chrome/common/url_constants.h" @@ -104,7 +105,7 @@ bool MockRenderThread::OnMessageReceived(const IPC::Message& msg) { bool msg_is_ok = true; IPC_BEGIN_MESSAGE_MAP_EX(MockRenderThread, msg, msg_is_ok) IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWidget, OnMsgCreateWidget) - IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToExtension, + IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToExtension, OnMsgOpenChannelToExtension) IPC_MESSAGE_HANDLER(PrintHostMsg_GetDefaultPrintSettings, OnGetDefaultPrintSettings) diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index 001415f..2366deb 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -26,6 +26,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_localization_peer.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/extensions/extension_set.h" #include "chrome/common/render_messages.h" #include "chrome/common/spellcheck_messages.h" @@ -578,8 +579,7 @@ void RenderThread::OnSetExtensionFunctionNames( ExtensionProcessBindings::SetFunctionNames(names); } -void RenderThread::OnExtensionLoaded( - const ViewMsg_ExtensionLoaded_Params& params) { +void RenderThread::OnExtensionLoaded(const ExtensionMsg_Loaded_Params& params) { scoped_refptr<const Extension> extension(params.ConvertToExtension()); if (!extension) { // This can happen if extension parsing fails for any reason. One reason @@ -666,21 +666,19 @@ bool RenderThread::OnControlMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewMsg_UserScripts_UpdatedScripts, OnUpdateUserScripts) // TODO(rafaelw): create an ExtensionDispatcher that handles extension // messages seperates their handling from the RenderThread. - IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke, - OnExtensionMessageInvoke) - IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetFunctionNames, + IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnExtensionMessageInvoke) + IPC_MESSAGE_HANDLER(ExtensionMsg_SetFunctionNames, OnSetExtensionFunctionNames) - IPC_MESSAGE_HANDLER(ViewMsg_ExtensionLoaded, OnExtensionLoaded) - IPC_MESSAGE_HANDLER(ViewMsg_ExtensionUnloaded, OnExtensionUnloaded) - IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetScriptingWhitelist, + IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnExtensionLoaded) + IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnExtensionUnloaded) + IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist, OnSetExtensionScriptingWhitelist) IPC_MESSAGE_HANDLER(ViewMsg_PurgeMemory, OnPurgeMemory) IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache) - IPC_MESSAGE_HANDLER(ViewMsg_Extension_UpdatePageActions, - OnPageActionsUpdated) - IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetAPIPermissions, + IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePageActions, OnPageActionsUpdated) + IPC_MESSAGE_HANDLER(ExtensionMsg_SetAPIPermissions, OnExtensionSetAPIPermissions) - IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetHostPermissions, + IPC_MESSAGE_HANDLER(ExtensionMsg_SetHostPermissions, OnExtensionSetHostPermissions) IPC_MESSAGE_HANDLER(DOMStorageMsg_Event, OnDOMStorageEvent) IPC_MESSAGE_HANDLER(SpellCheckMsg_Init, OnInitSpellChecker) diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h index fd4fa84..9b77b10a 100644 --- a/chrome/renderer/render_thread.h +++ b/chrome/renderer/render_thread.h @@ -46,7 +46,7 @@ struct ContentSettings; struct RendererPreferences; struct DOMStorageMsg_Event_Params; struct GPUInfo; -struct ViewMsg_ExtensionLoaded_Params; +struct ExtensionMsg_Loaded_Params; struct ViewMsg_New_Params; struct WebPreferences; @@ -272,7 +272,7 @@ class RenderThread : public RenderThreadBase, const GURL& url, const ContentSettings& content_settings); void OnUpdateUserScripts(base::SharedMemoryHandle table); void OnSetExtensionFunctionNames(const std::vector<std::string>& names); - void OnExtensionLoaded(const ViewMsg_ExtensionLoaded_Params& params); + void OnExtensionLoaded(const ExtensionMsg_Loaded_Params& params); void OnExtensionUnloaded(const std::string& id); void OnSetExtensionScriptingWhitelist( const Extension::ScriptingWhitelist& extension_ids); diff --git a/content/browser/renderer_host/render_view_host.cc b/content/browser/renderer_host/render_view_host.cc index 13e9963..bf91d391 100644 --- a/content/browser/renderer_host/render_view_host.cc +++ b/content/browser/renderer_host/render_view_host.cc @@ -23,6 +23,7 @@ #include "chrome/common/bindings_policy.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/net/url_request_context_getter.h" #include "chrome/common/render_messages.h" #include "chrome/common/print_messages.h" @@ -565,7 +566,7 @@ int RenderViewHost::DownloadFavicon(const GURL& url, int image_size) { } void RenderViewHost::GetApplicationInfo(int32 page_id) { - Send(new ViewMsg_GetApplicationInfo(routing_id(), page_id)); + Send(new ExtensionMsg_GetApplicationInfo(routing_id(), page_id)); } void RenderViewHost::CaptureSnapshot() { @@ -772,10 +773,9 @@ bool RenderViewHost::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) IPC_MESSAGE_HANDLER(ViewHostMsg_AddMessageToConsole, OnAddMessageToConsole) IPC_MESSAGE_HANDLER(ViewHostMsg_ShouldClose_ACK, OnMsgShouldCloseACK) - IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionRequest, OnExtensionRequest) + IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnExtensionRequest) IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionChanged, OnMsgSelectionChanged) - IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionPostMessage, - OnExtensionPostMessage) + IPC_MESSAGE_HANDLER(ExtensionHostMsg_PostMessage, OnExtensionPostMessage) IPC_MESSAGE_HANDLER(ViewHostMsg_AccessibilityNotifications, OnAccessibilityNotifications) IPC_MESSAGE_HANDLER(ViewHostMsg_OnCSSInserted, OnCSSInserted) @@ -1115,7 +1115,7 @@ void RenderViewHost::OnMsgWebUISend( } } - ViewHostMsg_DomMessage_Params params; + ExtensionHostMsg_DomMessage_Params params; params.name = message; if (value.get()) params.arguments.Swap(static_cast<ListValue*>(value.get())); @@ -1399,7 +1399,7 @@ void RenderViewHost::ForwardMessageFromExternalHost(const std::string& message, } void RenderViewHost::OnExtensionRequest( - const ViewHostMsg_DomMessage_Params& params) { + const ExtensionHostMsg_DomMessage_Params& params) { if (!ChildProcessSecurityPolicy::GetInstance()-> HasExtensionBindings(process()->id())) { // This can happen if someone uses window.open() to open an extension URL @@ -1414,8 +1414,8 @@ void RenderViewHost::OnExtensionRequest( void RenderViewHost::SendExtensionResponse(int request_id, bool success, const std::string& response, const std::string& error) { - Send(new ViewMsg_ExtensionResponse(routing_id(), request_id, success, - response, error)); + Send(new ExtensionMsg_Response( + routing_id(), request_id, success, response, error)); } void RenderViewHost::BlockExtensionRequest(int request_id) { diff --git a/content/browser/renderer_host/render_view_host.h b/content/browser/renderer_host/render_view_host.h index d45c749..d40b8c7 100644 --- a/content/browser/renderer_host/render_view_host.h +++ b/content/browser/renderer_host/render_view_host.h @@ -39,10 +39,10 @@ class SkBitmap; class ViewMsg_Navigate; struct ContentSettings; struct ContextMenuParams; +struct ExtensionHostMsg_DomMessage_Params; struct MediaPlayerAction; struct ViewHostMsg_AccessibilityNotification_Params; struct ViewHostMsg_CreateWindow_Params; -struct ViewHostMsg_DomMessage_Params; struct ViewHostMsg_ShowPopup_Params; struct ViewMsg_Navigate_Params; struct WebApplicationInfo; @@ -602,7 +602,7 @@ class RenderViewHost : public RenderWidgetHost { const std::string& value); void OnMsgShouldCloseACK(bool proceed); - void OnExtensionRequest(const ViewHostMsg_DomMessage_Params& params); + void OnExtensionRequest(const ExtensionHostMsg_DomMessage_Params& params); void OnExtensionPostMessage(int port_id, const std::string& message); void OnAccessibilityNotifications( const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params); diff --git a/content/browser/renderer_host/render_view_host_delegate.h b/content/browser/renderer_host/render_view_host_delegate.h index be8d04e..3fcc384 100644 --- a/content/browser/renderer_host/render_view_host_delegate.h +++ b/content/browser/renderer_host/render_view_host_delegate.h @@ -45,8 +45,8 @@ class SkBitmap; class SSLClientAuthHandler; class SSLAddCertHandler; class TabContents; +struct ExtensionHostMsg_DomMessage_Params; struct ViewHostMsg_CreateWindow_Params; -struct ViewHostMsg_DomMessage_Params; struct ViewHostMsg_FrameNavigate_Params; struct WebApplicationInfo; struct WebDropData; @@ -492,7 +492,7 @@ class RenderViewHostDelegate : public IPC::Channel::Listener { // A message was sent from HTML-based UI. // By default we ignore such messages. virtual void ProcessWebUIMessage( - const ViewHostMsg_DomMessage_Params& params) {} + const ExtensionHostMsg_DomMessage_Params& params) {} // A message for external host. By default we ignore such messages. // |receiver| can be a receiving script and |message| is any diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index ba82541..7ac1749 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -58,12 +58,12 @@ #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_icon_set.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/extensions/extension_resource.h" #include "chrome/common/extensions/url_pattern.h" #include "chrome/common/net/url_request_context_getter.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" -#include "chrome/common/render_messages_params.h" #include "chrome/common/url_constants.h" #include "content/browser/child_process_security_policy.h" #include "content/browser/host_zoom_map.h" @@ -417,9 +417,9 @@ bool TabContents::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewHostMsg_PDFHasUnsupportedFeature, OnPDFHasUnsupportedFeature) IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset) - IPC_MESSAGE_HANDLER(ViewHostMsg_DidGetApplicationInfo, + IPC_MESSAGE_HANDLER(ExtensionHostMsg_DidGetApplicationInfo, OnDidGetApplicationInfo) - IPC_MESSAGE_HANDLER(ViewHostMsg_InstallApplication, + IPC_MESSAGE_HANDLER(ExtensionHostMsg_InstallApplication, OnInstallApplication) IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents) IPC_MESSAGE_HANDLER(ViewHostMsg_PageTranslated, OnPageTranslated) @@ -892,9 +892,13 @@ bool TabContents::ExecuteCode(int request_id, const std::string& extension_id, if (!host) return false; - return host->Send(new ViewMsg_ExecuteCode(host->routing_id(), - ViewMsg_ExecuteCode_Params(request_id, extension_id, - is_js_code, code_string, all_frames))); + ExtensionMsg_ExecuteCode_Params params; + params.request_id = request_id; + params.extension_id = extension_id; + params.is_javascript = is_js_code; + params.code = code_string; + params.all_frames = all_frames; + return host->Send(new ExtensionMsg_ExecuteCode(host->routing_id(), params)); } void TabContents::PopupNotificationVisibilityChanged(bool visible) { @@ -2314,7 +2318,7 @@ void TabContents::DomOperationResponse(const std::string& json_string, } void TabContents::ProcessWebUIMessage( - const ViewHostMsg_DomMessage_Params& params) { + const ExtensionHostMsg_DomMessage_Params& params) { if (!render_manager_.web_ui()) { // This can happen if someone uses window.open() to open an extension URL // from a non-extension context. diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h index 75a54c6..daa7813 100644 --- a/content/browser/tab_contents/tab_contents.h +++ b/content/browser/tab_contents/tab_contents.h @@ -79,9 +79,9 @@ class TabContentsObserver; class TabContentsSSLHelper; class TabContentsView; class URLPattern; +struct ExtensionHostMsg_DomMessage_Params; struct RendererPreferences; struct ThumbnailScore; -struct ViewHostMsg_DomMessage_Params; struct ViewHostMsg_FrameNavigate_Params; struct WebPreferences; @@ -911,7 +911,8 @@ class TabContents : public PageNavigator, WindowOpenDisposition disposition); virtual void DomOperationResponse(const std::string& json_string, int automation_id); - virtual void ProcessWebUIMessage(const ViewHostMsg_DomMessage_Params& params); + virtual void ProcessWebUIMessage( + const ExtensionHostMsg_DomMessage_Params& params); virtual void ProcessExternalHostMessage(const std::string& message, const std::string& origin, const std::string& target); diff --git a/content/browser/webui/web_ui.cc b/content/browser/webui/web_ui.cc index 6a8e8c4..9202958 100644 --- a/content/browser/webui/web_ui.cc +++ b/content/browser/webui/web_ui.cc @@ -13,8 +13,8 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/webui/generic_handler.h" #include "chrome/common/bindings_policy.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/render_messages.h" -#include "chrome/common/render_messages_params.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_view.h" @@ -59,7 +59,8 @@ WebUI::~WebUI() { // WebUI, public: ------------------------------------------------------------- -void WebUI::ProcessWebUIMessage(const ViewHostMsg_DomMessage_Params& params) { +void WebUI::ProcessWebUIMessage( + const ExtensionHostMsg_DomMessage_Params& params) { // Look up the callback for this message. MessageCallbackMap::const_iterator callback = message_callbacks_.find(params.name); diff --git a/content/browser/webui/web_ui.h b/content/browser/webui/web_ui.h index 4bcda5d..98adcb1 100644 --- a/content/browser/webui/web_ui.h +++ b/content/browser/webui/web_ui.h @@ -22,7 +22,7 @@ class Profile; class RenderViewHost; class TabContents; class Value; -struct ViewHostMsg_DomMessage_Params; +struct ExtensionHostMsg_DomMessage_Params; // A WebUI sets up the datasources and message handlers for a given HTML-based // UI. It is contained by a WebUIManager. @@ -53,7 +53,8 @@ class WebUI { virtual void DidBecomeActiveForReusedRenderView() {} // Called from TabContents. - virtual void ProcessWebUIMessage(const ViewHostMsg_DomMessage_Params& params); + virtual void ProcessWebUIMessage( + const ExtensionHostMsg_DomMessage_Params& params); // Used by WebUIMessageHandlers. typedef Callback1<const ListValue*>::Type MessageCallback; diff --git a/content/common/view_messages.h b/content/common/view_messages.h index b2626e6..fa0ef4a 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -1235,6 +1235,10 @@ IPC_MESSAGE_ROUTED2(ViewHostMsg_ScriptEvalResponse, int /* id */, ListValue /* result */) +// Sent by the renderer process to acknowledge receipt of a +// ViewMsg_CSSInsertRequest message and css has been inserted into the frame. +IPC_MESSAGE_ROUTED0(ViewHostMsg_OnCSSInserted) + // Result of string search in the page. // Response to ViewMsg_Find with the results of the requested find-in-page // search, the number of matches found and the selection rect (in screen diff --git a/content/renderer/render_view.cc b/content/renderer/render_view.cc index 4d22f54..07acef3 100644 --- a/content/renderer/render_view.cc +++ b/content/renderer/render_view.cc @@ -30,11 +30,11 @@ #include "chrome/common/devtools_messages.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_constants.h" +#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/extensions/extension_set.h" #include "chrome/common/json_value_serializer.h" #include "chrome/common/pepper_plugin_registry.h" #include "chrome/common/render_messages.h" -#include "chrome/common/render_messages_params.h" #include "chrome/common/render_view_commands.h" #include "chrome/common/spellcheck_messages.h" #include "chrome/common/thumbnail_score.h" @@ -50,6 +50,7 @@ #include "chrome/renderer/extension_groups.h" #include "chrome/renderer/extensions/bindings_utils.h" #include "chrome/renderer/extensions/event_bindings.h" +#include "chrome/renderer/extensions/extension_helper.h" #include "chrome/renderer/extensions/extension_process_bindings.h" #include "chrome/renderer/extensions/extension_resource_request_policy.h" #include "chrome/renderer/extensions/renderer_extension_bindings.h" @@ -647,6 +648,8 @@ RenderView::RenderView(RenderThreadBase* render_thread, // Observer for Malware DOM details messages. new safe_browsing::MalwareDOMDetails(this); + + new ExtensionHelper(this); } RenderView::~RenderView() { @@ -856,7 +859,7 @@ void RenderView::DidDownloadApplicationDefinition( NewCallback(this, &RenderView::DidDownloadApplicationIcon)))); } } else { - Send(new ViewHostMsg_InstallApplication(routing_id_, *app_info)); + Send(new ExtensionHostMsg_InstallApplication(routing_id_, *app_info)); } } @@ -905,7 +908,8 @@ void RenderView::DidDownloadApplicationIcon(ImageResourceFetcher* fetcher, actual_icon_size += current_size; } - Send(new ViewHostMsg_InstallApplication(routing_id_, *pending_app_info_)); + Send(new ExtensionHostMsg_InstallApplication( + routing_id_, *pending_app_info_)); pending_app_info_.reset(NULL); } @@ -1028,7 +1032,7 @@ bool RenderView::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER( ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) - IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo) + IPC_MESSAGE_HANDLER(ExtensionMsg_GetApplicationInfo, OnGetApplicationInfo) IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) @@ -1039,9 +1043,6 @@ bool RenderView::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose, OnAllowScriptToClose) IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) - IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse) - IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke, - OnExtensionMessageInvoke) IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, @@ -1063,8 +1064,7 @@ bool RenderView::OnMessageReceived(const IPC::Message& message) { #endif IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent, OnSetEditCommandsForNextKeyEvent) - IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode, - OnExecuteCode) + IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteCode, OnExecuteCode) IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction, OnCustomContextMenuAction) IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility) @@ -3370,7 +3370,7 @@ void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) { WebFrame* main_frame = webview()->mainFrame(); if (frame == main_frame) { while (!pending_code_execution_queue_.empty()) { - linked_ptr<ViewMsg_ExecuteCode_Params>& params = + linked_ptr<ExtensionMsg_ExecuteCode_Params>& params = pending_code_execution_queue_.front(); ExecuteCodeImpl(main_frame, *params); pending_code_execution_queue_.pop(); @@ -3905,7 +3905,8 @@ void RenderView::OnGetApplicationInfo(int page_id) { } } - Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info)); + Send(new ExtensionHostMsg_DidGetApplicationInfo( + routing_id_, page_id, app_info)); } GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url, @@ -4893,27 +4894,6 @@ void RenderView::OnPluginImeCompositionCompleted(const string16& text, } #endif // OS_MACOSX -void RenderView::SendExtensionRequest( - const ViewHostMsg_DomMessage_Params& params) { - Send(new ViewHostMsg_ExtensionRequest(routing_id_, params)); -} - -void RenderView::OnExtensionResponse(int request_id, - bool success, - const std::string& response, - const std::string& error) { - ExtensionProcessBindings::HandleResponse( - request_id, success, response, error); -} - -void RenderView::OnExtensionMessageInvoke(const std::string& extension_id, - const std::string& function_name, - const ListValue& args, - const GURL& event_url) { - RendererExtensionBindings::Invoke( - extension_id, function_name, args, this, event_url); -} - void RenderView::postAccessibilityNotification( const WebAccessibilityObject& obj, WebAccessibilityNotification notification) { @@ -4982,7 +4962,7 @@ void RenderView::OnSetEditCommandsForNextKeyEvent( edit_commands_ = edit_commands; } -void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) { +void RenderView::OnExecuteCode(const ExtensionMsg_ExecuteCode_Params& params) { WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; if (!main_frame) { Send(new ViewHostMsg_ExecuteCodeFinished(routing_id_, params.request_id, @@ -4994,16 +4974,16 @@ void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) { NavigationState* navigation_state = NavigationState::FromDataSource(ds); if (!navigation_state->user_script_idle_scheduler()->has_run()) { pending_code_execution_queue_.push( - linked_ptr<ViewMsg_ExecuteCode_Params>( - new ViewMsg_ExecuteCode_Params(params))); + linked_ptr<ExtensionMsg_ExecuteCode_Params>( + new ExtensionMsg_ExecuteCode_Params(params))); return; } ExecuteCodeImpl(main_frame, params); } -void RenderView::ExecuteCodeImpl(WebFrame* frame, - const ViewMsg_ExecuteCode_Params& params) { +void RenderView::ExecuteCodeImpl( + WebFrame* frame, const ExtensionMsg_ExecuteCode_Params& params) { std::vector<WebFrame*> frame_vector; frame_vector.push_back(frame); if (params.all_frames) diff --git a/content/renderer/render_view.h b/content/renderer/render_view.h index a4af2fb..05c64c2 100644 --- a/content/renderer/render_view.h +++ b/content/renderer/render_view.h @@ -63,7 +63,6 @@ class ExternalPopupMenu; class FilePath; class GeolocationDispatcher; class GURL; -class ListValue; class LoadProgressTracker; class NavigationState; class NotificationProvider; @@ -80,14 +79,13 @@ class WebPluginDelegatePepper; class WebPluginDelegateProxy; class WebUIBindings; struct ContextMenuMediaParams; +struct ExtensionMsg_ExecuteCode_Params; struct PP_Flash_NetAddress; struct ThumbnailScore; -struct ViewHostMsg_DomMessage_Params; struct ViewHostMsg_GetSearchProviderInstallState_Params; struct ViewHostMsg_PageHasOSDD_Type; struct ViewHostMsg_RunFileChooser_Params; struct ViewMsg_ClosePage_Params; -struct ViewMsg_ExecuteCode_Params; struct ViewMsg_Navigate_Params; struct ViewMsg_StopFinding_Params; struct WebApplicationInfo; @@ -311,16 +309,9 @@ class RenderView : public RenderWidget, // Extensions ---------------------------------------------------------------- - void SendExtensionRequest(const ViewHostMsg_DomMessage_Params& params); - - void OnExtensionResponse(int request_id, bool success, - const std::string& response, - const std::string& error); - - void OnSetExtensionViewMode(const std::string& mode); - // Called when the "idle" user script state has been reached. See // UserScript::DOCUMENT_IDLE. + // TODO(jam): remove me void OnUserScriptIdleTriggered(WebKit::WebFrame* frame); // Plugin-related functions -------------------------------------------------- @@ -847,12 +838,8 @@ class RenderView : public RenderWidget, WebKit::WebDragOperationsMask operations_allowed); void OnEnablePreferredSizeChangedMode(int flags); void OnEnableViewSourceMode(); - void OnExecuteCode(const ViewMsg_ExecuteCode_Params& params); + void OnExecuteCode(const ExtensionMsg_ExecuteCode_Params& params); void OnExecuteEditCommand(const std::string& name, const std::string& value); - void OnExtensionMessageInvoke(const std::string& extension_id, - const std::string& function_name, - const ListValue& args, - const GURL& event_url); void OnFileChooserResponse(const std::vector<FilePath>& paths); void OnFind(int request_id, const string16&, const WebKit::WebFindOptions&); void OnFindReplyAck(); @@ -1002,7 +989,7 @@ class RenderView : public RenderWidget, // Backend for the IPC Message ExecuteCode in addition to being used // internally by other RenderView functions. void ExecuteCodeImpl(WebKit::WebFrame* frame, - const ViewMsg_ExecuteCode_Params& params); + const ExtensionMsg_ExecuteCode_Params& params); // Get all child frames of parent_frame, returned by frames_vector. bool GetAllChildFrames(WebKit::WebFrame* parent_frame, @@ -1352,7 +1339,7 @@ class RenderView : public RenderWidget, struct PendingFileChooser; std::deque< linked_ptr<PendingFileChooser> > file_chooser_completions_; - std::queue<linked_ptr<ViewMsg_ExecuteCode_Params> > + std::queue<linked_ptr<ExtensionMsg_ExecuteCode_Params> > pending_code_execution_queue_; // ImageResourceFetchers schedule via DownloadImage. diff --git a/ipc/ipc_message_utils.h b/ipc/ipc_message_utils.h index 3d63875..c7086d2 100644 --- a/ipc/ipc_message_utils.h +++ b/ipc/ipc_message_utils.h @@ -85,6 +85,7 @@ enum IPCMessageStart { DragMsgStart, PrintMsgStart, SpellCheckMsgStart, + ExtensionMsgStart, LastIPCMsgStart // Must come last. }; |