| 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())
|
| + 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()
|
| }
|
|
|