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

Side by Side Diff: chrome/browser/extensions/api/debugger/debugger_api.cc

Issue 11232066: Remove GetExtensionEventRouter from Profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rerebase Created 8 years, 1 month 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Implements the Chrome Extensions Debugger API. 5 // Implements the Chrome Extensions Debugger API.
6 6
7 #include "chrome/browser/extensions/api/debugger/debugger_api.h" 7 #include "chrome/browser/extensions/api/debugger/debugger_api.h"
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 11
12 #include "base/json/json_reader.h" 12 #include "base/json/json_reader.h"
13 #include "base/json/json_writer.h" 13 #include "base/json/json_writer.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/singleton.h" 15 #include "base/memory/singleton.h"
16 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" 19 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
20 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h" 20 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h"
21 #include "chrome/browser/extensions/event_router.h" 21 #include "chrome/browser/extensions/event_router.h"
22 #include "chrome/browser/extensions/extension_system.h"
22 #include "chrome/browser/extensions/extension_tab_util.h" 23 #include "chrome/browser/extensions/extension_tab_util.h"
23 #include "chrome/browser/infobars/infobar.h" 24 #include "chrome/browser/infobars/infobar.h"
24 #include "chrome/browser/infobars/infobar_tab_helper.h" 25 #include "chrome/browser/infobars/infobar_tab_helper.h"
25 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/ui/tab_contents/tab_contents.h" 27 #include "chrome/browser/ui/tab_contents/tab_contents.h"
27 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" 28 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
28 #include "chrome/common/chrome_notification_types.h" 29 #include "chrome/common/chrome_notification_types.h"
29 #include "chrome/common/extensions/api/debugger.h" 30 #include "chrome/common/extensions/api/debugger.h"
30 #include "chrome/common/extensions/extension.h" 31 #include "chrome/common/extensions/extension.h"
31 #include "chrome/common/extensions/extension_error_utils.h" 32 #include "chrome/common/extensions/extension_error_utils.h"
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 detach_reason_ = OnDetach::REASON_REPLACED_WITH_DEVTOOLS; 280 detach_reason_ = OnDetach::REASON_REPLACED_WITH_DEVTOOLS;
280 } 281 }
281 282
282 void ExtensionDevToolsClientHost::MarkAsDismissed() { 283 void ExtensionDevToolsClientHost::MarkAsDismissed() {
283 detach_reason_ = OnDetach::REASON_CANCELED_BY_USER; 284 detach_reason_ = OnDetach::REASON_CANCELED_BY_USER;
284 } 285 }
285 286
286 void ExtensionDevToolsClientHost::SendDetachedEvent() { 287 void ExtensionDevToolsClientHost::SendDetachedEvent() {
287 Profile* profile = 288 Profile* profile =
288 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 289 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
289 if (profile != NULL && profile->GetExtensionEventRouter()) { 290 if (profile != NULL &&
291 extensions::ExtensionSystem::Get(profile)->event_router()) {
290 Debuggee debuggee; 292 Debuggee debuggee;
291 debuggee.tab_id = tab_id_; 293 debuggee.tab_id = tab_id_;
292 scoped_ptr<base::ListValue> args(OnDetach::Create(debuggee, 294 scoped_ptr<base::ListValue> args(OnDetach::Create(debuggee,
293 detach_reason_)); 295 detach_reason_));
294 profile->GetExtensionEventRouter()->DispatchEventToExtension( 296 extensions::ExtensionSystem::Get(profile)->event_router()->
295 extension_id_, keys::kOnDetach, args.Pass(), profile, GURL()); 297 DispatchEventToExtension(extension_id_, keys::kOnDetach, args.Pass(),
298 profile, GURL());
296 } 299 }
297 } 300 }
298 301
299 void ExtensionDevToolsClientHost::Observe( 302 void ExtensionDevToolsClientHost::Observe(
300 int type, 303 int type,
301 const content::NotificationSource& source, 304 const content::NotificationSource& source,
302 const content::NotificationDetails& details) { 305 const content::NotificationDetails& details) {
303 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { 306 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
304 std::string id = 307 std::string id =
305 content::Details<extensions::UnloadedExtensionInfo>(details)-> 308 content::Details<extensions::UnloadedExtensionInfo>(details)->
306 extension->id(); 309 extension->id();
307 if (id == extension_id_) 310 if (id == extension_id_)
308 Close(); 311 Close();
309 } else { 312 } else {
310 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); 313 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type);
311 if (content::Details<InfoBarRemovedDetails>(details)->first == 314 if (content::Details<InfoBarRemovedDetails>(details)->first ==
312 infobar_delegate_) { 315 infobar_delegate_) {
313 infobar_delegate_ = NULL; 316 infobar_delegate_ = NULL;
314 SendDetachedEvent(); 317 SendDetachedEvent();
315 Close(); 318 Close();
316 } 319 }
317 } 320 }
318 } 321 }
319 322
320 void ExtensionDevToolsClientHost::DispatchOnInspectorFrontend( 323 void ExtensionDevToolsClientHost::DispatchOnInspectorFrontend(
321 const std::string& message) { 324 const std::string& message) {
322 Profile* profile = 325 Profile* profile =
323 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 326 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
324 if (profile == NULL || !profile->GetExtensionEventRouter()) 327 if (profile == NULL ||
328 !extensions::ExtensionSystem::Get(profile)->event_router())
325 return; 329 return;
326 330
327 scoped_ptr<Value> result(base::JSONReader::Read(message)); 331 scoped_ptr<Value> result(base::JSONReader::Read(message));
328 if (!result->IsType(Value::TYPE_DICTIONARY)) 332 if (!result->IsType(Value::TYPE_DICTIONARY))
329 return; 333 return;
330 DictionaryValue* dictionary = static_cast<DictionaryValue*>(result.get()); 334 DictionaryValue* dictionary = static_cast<DictionaryValue*>(result.get());
331 335
332 int id; 336 int id;
333 if (!dictionary->GetInteger("id", &id)) { 337 if (!dictionary->GetInteger("id", &id)) {
334 std::string method_name; 338 std::string method_name;
335 if (!dictionary->GetString("method", &method_name)) 339 if (!dictionary->GetString("method", &method_name))
336 return; 340 return;
337 341
338 Debuggee debuggee; 342 Debuggee debuggee;
339 debuggee.tab_id = tab_id_; 343 debuggee.tab_id = tab_id_;
340 344
341 OnEvent::Params params; 345 OnEvent::Params params;
342 DictionaryValue* params_value; 346 DictionaryValue* params_value;
343 if (dictionary->GetDictionary("params", &params_value)) 347 if (dictionary->GetDictionary("params", &params_value))
344 params.additional_properties.Swap(params_value); 348 params.additional_properties.Swap(params_value);
345 349
346 scoped_ptr<ListValue> args(OnEvent::Create(debuggee, method_name, params)); 350 scoped_ptr<ListValue> args(OnEvent::Create(debuggee, method_name, params));
347 profile->GetExtensionEventRouter()->DispatchEventToExtension( 351 extensions::ExtensionSystem::Get(profile)->event_router()->
348 extension_id_, keys::kOnEvent, args.Pass(), profile, GURL()); 352 DispatchEventToExtension(extension_id_, keys::kOnEvent, args.Pass(),
353 profile, GURL());
349 } else { 354 } else {
350 SendCommandDebuggerFunction* function = pending_requests_[id]; 355 SendCommandDebuggerFunction* function = pending_requests_[id];
351 if (!function) 356 if (!function)
352 return; 357 return;
353 358
354 function->SendResponseBody(dictionary); 359 function->SendResponseBody(dictionary);
355 pending_requests_.erase(id); 360 pending_requests_.erase(id);
356 } 361 }
357 } 362 }
358 363
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 } 548 }
544 549
545 // static 550 // static
546 void DebuggerApi::MarkDevToolsClientHostAsReplaced( 551 void DebuggerApi::MarkDevToolsClientHostAsReplaced(
547 DevToolsClientHost* client_host) { 552 DevToolsClientHost* client_host) {
548 ExtensionDevToolsClientHost* host = AttachedClientHosts::GetInstance()-> 553 ExtensionDevToolsClientHost* host = AttachedClientHosts::GetInstance()->
549 AsExtensionDevToolsClientHost(client_host); 554 AsExtensionDevToolsClientHost(client_host);
550 if (host) 555 if (host)
551 host->MarkAsReplaced(); 556 host->MarkAsReplaced();
552 } 557 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/cookies/cookies_api.cc ('k') | chrome/browser/extensions/api/downloads/downloads_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698