diff options
-rw-r--r-- | chrome/browser/debugger/devtools_window.cc | 35 | ||||
-rw-r--r-- | chrome/browser/debugger/devtools_window.h | 5 | ||||
-rw-r--r-- | chrome/browser/dom_ui/devtools_ui.cc | 42 |
3 files changed, 38 insertions, 44 deletions
diff --git a/chrome/browser/debugger/devtools_window.cc b/chrome/browser/debugger/devtools_window.cc index bf027c0..400951f 100644 --- a/chrome/browser/debugger/devtools_window.cc +++ b/chrome/browser/debugger/devtools_window.cc @@ -3,7 +3,9 @@ // found in the LICENSE file. #include "base/command_line.h" +#include "base/json/json_writer.h" #include "base/string_number_conversions.h" +#include "base/values.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" @@ -11,6 +13,8 @@ #include "chrome/browser/browser_window.h" #include "chrome/browser/debugger/devtools_manager.h" #include "chrome/browser/debugger/devtools_window.h" +#include "chrome/browser/extensions/extensions_service.h" +#include "chrome/browser/load_notification_details.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_view_host.h" @@ -243,14 +247,43 @@ void DevToolsWindow::SetAttachedWindow() { L"WebInspector.setAttachedWindow(false);"); } + +void DevToolsWindow::AddDevToolsExtensionsToClient() { + ListValue results; + const ExtensionsService* extension_service = tab_contents_->profile()-> + GetOriginalProfile()->GetExtensionsService(); + const ExtensionList* extensions = extension_service->extensions(); + + for (ExtensionList::const_iterator extension = extensions->begin(); + extension != extensions->end(); ++extension) { + if ((*extension)->devtools_url().is_empty()) + continue; + DictionaryValue* extension_info = new DictionaryValue(); + extension_info->Set(L"startPage", + new StringValue((*extension)->devtools_url().spec())); + results.Append(extension_info); + } + CallClientFunction(L"WebInspector.addExtensions", results); +} + +void DevToolsWindow::CallClientFunction(const std::wstring& function_name, + const Value& arg) { + std::string json; + base::JSONWriter::Write(&arg, false, &json); + std::wstring javascript = function_name + L"(" + UTF8ToWide(json) + L");"; + tab_contents_->render_view_host()-> + ExecuteJavascriptInWebFrame(L"", javascript); +} + void DevToolsWindow::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { - if (type == NotificationType::LOAD_STOP) { + if (type == NotificationType::LOAD_STOP && !is_loaded_) { SetAttachedWindow(); is_loaded_ = true; UpdateTheme(); DoAction(); + AddDevToolsExtensionsToClient(); } else if (type == NotificationType::TAB_CLOSING) { if (Source<NavigationController>(source).ptr() == &tab_contents_->controller()) { diff --git a/chrome/browser/debugger/devtools_window.h b/chrome/browser/debugger/devtools_window.h index d69e7d5..e5a868e 100644 --- a/chrome/browser/debugger/devtools_window.h +++ b/chrome/browser/debugger/devtools_window.h @@ -25,6 +25,7 @@ class BrowserWindow; class Profile; class RenderViewHost; class TabContents; +class Value; class DevToolsWindow : public DevToolsClientHost, @@ -65,7 +66,9 @@ class DevToolsWindow void DoAction(); GURL GetDevToolsUrl(); void UpdateTheme(); - + void AddDevToolsExtensionsToClient(); + void CallClientFunction(const std::wstring& function_name, + const Value& arg); // Overridden from TabContentsDelegate. virtual void OpenURLFromTab(TabContents* source, const GURL& url, diff --git a/chrome/browser/dom_ui/devtools_ui.cc b/chrome/browser/dom_ui/devtools_ui.cc index 17946ce..ddb55c8 100644 --- a/chrome/browser/dom_ui/devtools_ui.cc +++ b/chrome/browser/dom_ui/devtools_ui.cc @@ -4,52 +4,10 @@ #include "chrome/browser/dom_ui/devtools_ui.h" -#include "chrome/browser/extensions/extension_process_manager.h" -#include "chrome/browser/extensions/extensions_service.h" -#include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_view_host.h" -#include "chrome/common/extensions/extension.h" #include "chrome/common/render_messages.h" -#include "chrome/common/url_constants.h" - -class DevToolsMessageHandler: public DOMMessageHandler { - public: - explicit DevToolsMessageHandler(ExtensionsService *extensions_service): - extensions_service_(extensions_service) {} - - protected: - void HandleRequestDevToolsExtensionsData(const Value* value) { - DCHECK(!value); - - ListValue results; - const ExtensionList* extensions = extensions_service_->extensions(); - - for (ExtensionList::const_iterator extension = extensions->begin(); - extension != extensions->end(); ++extension) { - if ((*extension)->devtools_url().is_empty()) - continue; - DictionaryValue* extension_info = new DictionaryValue(); - extension_info->Set("startPage", - new StringValue((*extension)->devtools_url().spec())); - results.Append(extension_info); - } - dom_ui_->CallJavascriptFunction(L"WebInspector.addExtensions", results); - } - - virtual void RegisterMessages() { - dom_ui_->RegisterMessageCallback("requestDevToolsExtensionsData", - NewCallback(this, - &DevToolsMessageHandler::HandleRequestDevToolsExtensionsData)); - } - - private: - scoped_refptr<ExtensionsService> extensions_service_; -}; DevToolsUI::DevToolsUI(TabContents* contents) : DOMUI(contents) { - DevToolsMessageHandler* handler = new DevToolsMessageHandler( - GetProfile()->GetOriginalProfile()->GetExtensionsService()); - AddMessageHandler(handler->Attach(this)); } void DevToolsUI::RenderViewCreated(RenderViewHost* render_view_host) { |