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/extension_devtools_events.h" | 13 #include "chrome/browser/extensions/extension_devtools_events.h" |
13 #include "chrome/browser/extensions/extension_devtools_manager.h" | 14 #include "chrome/browser/extensions/extension_devtools_manager.h" |
14 #include "chrome/browser/extensions/extension_event_router.h" | 15 #include "chrome/browser/extensions/extension_event_router.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 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, profile_, GURL()); |
111 | 113 |
112 // This may result in this object being destroyed. | 114 // This may result in this object being destroyed. |
113 extension_devtools_manager_->BridgeClosingForTab(tab_id_); | 115 extension_devtools_manager_->BridgeClosingForTab(tab_id_); |
114 } | 116 } |
115 | 117 |
116 void ExtensionDevToolsBridge::DispatchOnInspectorFrontend( | 118 void ExtensionDevToolsBridge::DispatchOnInspectorFrontend( |
117 const std::string& data) { | 119 const std::string& data) { |
118 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); | 120 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); |
119 | 121 |
120 std::string json = base::StringPrintf("[%s]", data.c_str()); | 122 base::ListValue* arguments = new base::ListValue(); |
| 123 arguments->Append(base::JSONReader::Read(data)); |
| 124 |
121 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 125 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
122 on_page_event_name_, json, profile_, GURL()); | 126 on_page_event_name_, arguments, profile_, GURL()); |
123 } | 127 } |
124 | 128 |
125 void ExtensionDevToolsBridge::ContentsReplaced(WebContents* new_contents) { | 129 void ExtensionDevToolsBridge::ContentsReplaced(WebContents* new_contents) { |
126 // We don't update the tab id as it needs to remain the same so that we can | 130 // We don't update the tab id as it needs to remain the same so that we can |
127 // properly unregister. | 131 // properly unregister. |
128 } | 132 } |
OLD | NEW |