OLD | NEW |
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 #include "chrome/browser/extensions/extension_devtools_bridge.h" | 5 #include "chrome/browser/extensions/extension_devtools_bridge.h" |
6 | 6 |
| 7 #include "base/json/json_reader.h" |
7 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
8 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stringprintf.h" |
9 #include "base/string_util.h" | 11 #include "base/string_util.h" |
10 #include "base/stringprintf.h" | |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "chrome/browser/extensions/event_router.h" | 13 #include "chrome/browser/extensions/event_router.h" |
13 #include "chrome/browser/extensions/extension_devtools_events.h" | 14 #include "chrome/browser/extensions/extension_devtools_events.h" |
14 #include "chrome/browser/extensions/extension_devtools_manager.h" | 15 #include "chrome/browser/extensions/extension_devtools_manager.h" |
15 #include "chrome/browser/extensions/extension_system.h" | 16 #include "chrome/browser/extensions/extension_system.h" |
16 #include "chrome/browser/extensions/extension_tab_util.h" | 17 #include "chrome/browser/extensions/extension_tab_util.h" |
17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
19 #include "content/public/browser/devtools_agent_host_registry.h" | 20 #include "content/public/browser/devtools_agent_host_registry.h" |
20 #include "content/public/browser/devtools_manager.h" | 21 #include "content/public/browser/devtools_manager.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 DevToolsManager::GetInstance()->ClientHostClosing(this); | 99 DevToolsManager::GetInstance()->ClientHostClosing(this); |
99 } | 100 } |
100 | 101 |
101 // If the tab we are looking at is going away then we fire a closing event at | 102 // If the tab we are looking at is going away then we fire a closing event at |
102 // the extension. | 103 // the extension. |
103 void ExtensionDevToolsBridge::InspectedContentsClosing() { | 104 void ExtensionDevToolsBridge::InspectedContentsClosing() { |
104 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); | 105 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); |
105 | 106 |
106 // TODO(knorton): Remove this event in favor of the standard tabs.onRemoved | 107 // TODO(knorton): Remove this event in favor of the standard tabs.onRemoved |
107 // event in extensions. | 108 // event in extensions. |
108 std::string json("[{}]"); | 109 scoped_ptr<base::ListValue> arguments(new base::ListValue()); |
| 110 arguments->Set(0, new base::DictionaryValue()); |
109 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 111 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
110 on_tab_close_event_name_, json, profile_, GURL(), | 112 on_tab_close_event_name_, arguments.Pass(), profile_, GURL(), |
111 extensions::EventFilteringInfo()); | 113 extensions::EventFilteringInfo()); |
112 | 114 |
113 // This may result in this object being destroyed. | 115 // This may result in this object being destroyed. |
114 extension_devtools_manager_->BridgeClosingForTab(tab_id_); | 116 extension_devtools_manager_->BridgeClosingForTab(tab_id_); |
115 } | 117 } |
116 | 118 |
117 void ExtensionDevToolsBridge::DispatchOnInspectorFrontend( | 119 void ExtensionDevToolsBridge::DispatchOnInspectorFrontend( |
118 const std::string& data) { | 120 const std::string& data) { |
119 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); | 121 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); |
120 | 122 |
121 std::string json = base::StringPrintf("[%s]", data.c_str()); | 123 scoped_ptr<base::ListValue> arguments(new base::ListValue()); |
| 124 if (!data.empty()) { |
| 125 arguments->Append(base::JSONReader::Read(data)); |
| 126 } |
| 127 |
122 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 128 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
123 on_page_event_name_, json, profile_, GURL(), | 129 on_page_event_name_, arguments.Pass(), profile_, GURL(), |
124 extensions::EventFilteringInfo()); | 130 extensions::EventFilteringInfo()); |
125 } | 131 } |
126 | 132 |
127 void ExtensionDevToolsBridge::ContentsReplaced(WebContents* new_contents) { | 133 void ExtensionDevToolsBridge::ContentsReplaced(WebContents* new_contents) { |
128 // We don't update the tab id as it needs to remain the same so that we can | 134 // We don't update the tab id as it needs to remain the same so that we can |
129 // properly unregister. | 135 // properly unregister. |
130 } | 136 } |
OLD | NEW |