diff options
author | loislo@chromium.org <loislo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-11 05:38:51 +0000 |
---|---|---|
committer | loislo@chromium.org <loislo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-11 05:38:51 +0000 |
commit | a2569bdab803a5ff5906ba2e47e2ace28679094e (patch) | |
tree | b5299322f47178b516d1bcdc6144bd307f0665c9 /chrome | |
parent | 1af9a7d924a2360a2a42dd5d1e5942911665b113 (diff) | |
download | chromium_src-a2569bdab803a5ff5906ba2e47e2ace28679094e.zip chromium_src-a2569bdab803a5ff5906ba2e47e2ace28679094e.tar.gz chromium_src-a2569bdab803a5ff5906ba2e47e2ace28679094e.tar.bz2 |
Push DevTools extensions data to the client when the DevTools client page is loaded.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3090022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55673 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-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) { |