Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1181)

Unified Diff: chrome/browser/extensions/execute_code_in_tab_function.cc

Issue 6794035: Move dispatching and sending of the last extension specific messages out of TabContents and Rende... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/execute_code_in_tab_function.cc
===================================================================
--- chrome/browser/extensions/execute_code_in_tab_function.cc (revision 80315)
+++ chrome/browser/extensions/execute_code_in_tab_function.cc (working copy)
@@ -17,13 +17,16 @@
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/extension_error_utils.h"
+#include "chrome/common/extensions/extension_messages.h"
+#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/common/notification_service.h"
namespace keys = extension_tabs_module_constants;
ExecuteCodeInTabFunction::ExecuteCodeInTabFunction()
- : execute_tab_id_(-1),
+ : ALLOW_THIS_IN_INITIALIZER_LIST(registrar_(this)),
+ execute_tab_id_(-1),
all_frames_(false) {
}
@@ -165,24 +168,46 @@
} else if (function_name != TabsExecuteScriptFunction::function_name()) {
DCHECK(false);
}
- if (!contents->tab_contents()->ExecuteCode(request_id(), extension->id(),
- is_js_code, code_string, all_frames_)) {
- SendResponse(false);
+
+ 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_;
+ contents->render_view_host()->Send(new ExtensionMsg_ExecuteCode(
+ contents->render_view_host()->routing_id(), params));
+
+ registrar_.Observe(contents->tab_contents());
+ AddRef(); // balanced in OnExecuteCodeFinished()
+ return true;
+}
+
+bool ExecuteCodeInTabFunction::OnMessageReceived(const IPC::Message& message) {
+ if (message.type() != ExtensionHostMsg_ExecuteCodeFinished::ID)
return false;
+
+ int message_request_id;
+ void* iter = NULL;
+ if (!message.ReadInt(&iter, &message_request_id)) {
+ NOTREACHED() << "malformed extension message";
+ return true;
}
- registrar_.Add(this, NotificationType::TAB_CODE_EXECUTED,
- NotificationService::AllSources());
- AddRef(); // balanced in Observe()
+
+ if (message_request_id != request_id())
Matt Perry 2011/04/05 19:18:33 why do this manually? can't you do this check in O
jam 2011/04/05 19:25:38 that way I can reply false and let other message E
+ return false;
+
+ IPC_BEGIN_MESSAGE_MAP(ExecuteCodeInTabFunction, message)
+ IPC_MESSAGE_HANDLER(ExtensionHostMsg_ExecuteCodeFinished,
+ OnExecuteCodeFinished)
+ IPC_END_MESSAGE_MAP()
return true;
}
-void ExecuteCodeInTabFunction::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- std::pair<int, bool>* result_details =
- Details<std::pair<int, bool> >(details).ptr();
- if (result_details->first == request_id()) {
- SendResponse(result_details->second);
- Release(); // balanced in Execute()
- }
+void ExecuteCodeInTabFunction::OnExecuteCodeFinished(int request_id,
+ bool success) {
+ SendResponse(success);
+
+ registrar_.Observe(NULL);
+ Release(); // balanced in Execute()
}

Powered by Google App Engine
This is Rietveld 408576698