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

Side by Side 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, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/execute_code_in_tab_function.h" 5 #include "chrome/browser/extensions/execute_code_in_tab_function.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/extension_tabs_module.h" 11 #include "chrome/browser/extensions/extension_tabs_module.h"
12 #include "chrome/browser/extensions/extension_tabs_module_constants.h" 12 #include "chrome/browser/extensions/extension_tabs_module_constants.h"
13 #include "chrome/browser/extensions/file_reader.h" 13 #include "chrome/browser/extensions/file_reader.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
17 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
18 #include "chrome/common/extensions/extension_constants.h" 18 #include "chrome/common/extensions/extension_constants.h"
19 #include "chrome/common/extensions/extension_error_utils.h" 19 #include "chrome/common/extensions/extension_error_utils.h"
20 #include "chrome/common/extensions/extension_messages.h"
21 #include "content/browser/renderer_host/render_view_host.h"
20 #include "content/browser/tab_contents/tab_contents.h" 22 #include "content/browser/tab_contents/tab_contents.h"
21 #include "content/common/notification_service.h" 23 #include "content/common/notification_service.h"
22 24
23 namespace keys = extension_tabs_module_constants; 25 namespace keys = extension_tabs_module_constants;
24 26
25 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction() 27 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction()
26 : execute_tab_id_(-1), 28 : ALLOW_THIS_IN_INITIALIZER_LIST(registrar_(this)),
29 execute_tab_id_(-1),
27 all_frames_(false) { 30 all_frames_(false) {
28 } 31 }
29 32
30 ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() { 33 ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() {
31 } 34 }
32 35
33 bool ExecuteCodeInTabFunction::RunImpl() { 36 bool ExecuteCodeInTabFunction::RunImpl() {
34 DictionaryValue* script_info; 37 DictionaryValue* script_info;
35 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &script_info)); 38 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &script_info));
36 size_t number_of_value = script_info->size(); 39 size_t number_of_value = script_info->size();
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 return false; 161 return false;
159 } 162 }
160 163
161 bool is_js_code = true; 164 bool is_js_code = true;
162 std::string function_name = name(); 165 std::string function_name = name();
163 if (function_name == TabsInsertCSSFunction::function_name()) { 166 if (function_name == TabsInsertCSSFunction::function_name()) {
164 is_js_code = false; 167 is_js_code = false;
165 } else if (function_name != TabsExecuteScriptFunction::function_name()) { 168 } else if (function_name != TabsExecuteScriptFunction::function_name()) {
166 DCHECK(false); 169 DCHECK(false);
167 } 170 }
168 if (!contents->tab_contents()->ExecuteCode(request_id(), extension->id(), 171
169 is_js_code, code_string, all_frames_)) { 172 ExtensionMsg_ExecuteCode_Params params;
170 SendResponse(false); 173 params.request_id = request_id();
171 return false; 174 params.extension_id = extension->id();
172 } 175 params.is_javascript = is_js_code;
173 registrar_.Add(this, NotificationType::TAB_CODE_EXECUTED, 176 params.code = code_string;
174 NotificationService::AllSources()); 177 params.all_frames = all_frames_;
175 AddRef(); // balanced in Observe() 178 contents->render_view_host()->Send(new ExtensionMsg_ExecuteCode(
179 contents->render_view_host()->routing_id(), params));
180
181 registrar_.Observe(contents->tab_contents());
182 AddRef(); // balanced in OnExecuteCodeFinished()
176 return true; 183 return true;
177 } 184 }
178 185
179 void ExecuteCodeInTabFunction::Observe(NotificationType type, 186 bool ExecuteCodeInTabFunction::OnMessageReceived(const IPC::Message& message) {
180 const NotificationSource& source, 187 if (message.type() != ExtensionHostMsg_ExecuteCodeFinished::ID)
181 const NotificationDetails& details) { 188 return false;
182 std::pair<int, bool>* result_details = 189
183 Details<std::pair<int, bool> >(details).ptr(); 190 int message_request_id;
184 if (result_details->first == request_id()) { 191 void* iter = NULL;
185 SendResponse(result_details->second); 192 if (!message.ReadInt(&iter, &message_request_id)) {
186 Release(); // balanced in Execute() 193 NOTREACHED() << "malformed extension message";
194 return true;
187 } 195 }
196
197 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
198 return false;
199
200 IPC_BEGIN_MESSAGE_MAP(ExecuteCodeInTabFunction, message)
201 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ExecuteCodeFinished,
202 OnExecuteCodeFinished)
203 IPC_END_MESSAGE_MAP()
204 return true;
188 } 205 }
206
207 void ExecuteCodeInTabFunction::OnExecuteCodeFinished(int request_id,
208 bool success) {
209 SendResponse(success);
210
211 registrar_.Observe(NULL);
212 Release(); // balanced in Execute()
213 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698