Chromium Code Reviews| Index: chrome/browser/ui/webui/inspect_ui.cc |
| diff --git a/chrome/browser/ui/webui/inspect_ui.cc b/chrome/browser/ui/webui/inspect_ui.cc |
| index 0aa1ab127788e313e2055a4d28bb7b2d1f7c0a7d..bc08012d2b4df2268dee86349cd927aac9aec3ff 100644 |
| --- a/chrome/browser/ui/webui/inspect_ui.cc |
| +++ b/chrome/browser/ui/webui/inspect_ui.cc |
| @@ -58,7 +58,11 @@ using content::WebUIMessageHandler; |
| using content::WorkerService; |
| using content::WorkerServiceObserver; |
| +namespace { |
| + |
| static const char kDataFile[] = "targets-data.json"; |
| +static const char kAdbQuery[] = "adb-query/"; |
| +static const char kLocalXhr[] = "local-xhr/"; |
| static const char kExtensionTargetType[] = "extension"; |
| static const char kPageTargetType[] = "page"; |
| @@ -76,8 +80,6 @@ static const char kNameField[] = "name"; |
| static const char kFaviconUrlField[] = "favicon_url"; |
| static const char kPidField[] = "pid"; |
| -namespace { |
| - |
| DictionaryValue* BuildTargetDescriptor( |
| const std::string& target_type, |
| bool attached, |
| @@ -169,12 +171,9 @@ void SendDescriptors( |
| callback.Run(base::RefCountedString::TakeString(&json_string)); |
| } |
| -bool HandleRequestCallback( |
| +bool HandleDataRequestCallback( |
| const std::string& path, |
| const content::WebUIDataSource::GotDataCallback& callback) { |
| - if (path != kDataFile) |
| - return false; |
| - |
| std::set<RenderViewHost*> tab_rvhs; |
| for (TabContentsIterator it; !it.done(); it.Next()) |
| tab_rvhs.insert(it->GetRenderViewHost()); |
| @@ -213,16 +212,6 @@ bool HandleRequestCallback( |
| return true; |
| } |
| -content::WebUIDataSource* CreateInspectUIHTMLSource() { |
| - content::WebUIDataSource* source = |
| - content::WebUIDataSource::Create(chrome::kChromeUIInspectHost); |
| - source->AddResourcePath("inspect.css", IDR_INSPECT_CSS); |
| - source->AddResourcePath("inspect.js", IDR_INSPECT_JS); |
| - source->SetDefaultResource(IDR_INSPECT_HTML); |
| - source->SetRequestFilter(base::Bind(&HandleRequestCallback)); |
| - return source; |
| -} |
| - |
| class InspectMessageHandler : public WebUIMessageHandler { |
| public: |
| InspectMessageHandler() {} |
| @@ -362,6 +351,7 @@ InspectUI::InspectUI(content::WebUI* web_ui) |
| web_ui->AddMessageHandler(new InspectMessageHandler()); |
| Profile* profile = Profile::FromWebUI(web_ui); |
| + adb_bridge_ = DevToolsAdbBridge::Start(profile); |
| content::WebUIDataSource::Add(profile, CreateInspectUIHTMLSource()); |
| registrar_.Add(this, |
| @@ -394,9 +384,64 @@ void InspectUI::Observe(int type, |
| void InspectUI::StopListeningNotifications() |
| { |
| + adb_bridge_->Stop(); |
|
yurys
2013/03/11 07:21:21
Should it be destroyed like observer_ ?
|
| + |
| if (!observer_) |
| return; |
| observer_->InspectUIDestroyed(); |
| observer_ = NULL; |
| registrar_.RemoveAll(); |
| } |
| + |
| +content::WebUIDataSource* InspectUI::CreateInspectUIHTMLSource() { |
| + content::WebUIDataSource* source = |
| + content::WebUIDataSource::Create(chrome::kChromeUIInspectHost); |
| + source->AddResourcePath("inspect.css", IDR_INSPECT_CSS); |
| + source->AddResourcePath("inspect.js", IDR_INSPECT_JS); |
| + source->SetDefaultResource(IDR_INSPECT_HTML); |
| + source->SetRequestFilter(base::Bind(&InspectUI::HandleRequestCallback, |
| + base::Unretained(this))); |
| + return source; |
| +} |
| + |
| +bool InspectUI::HandleRequestCallback( |
| + const std::string& path, |
| + const content::WebUIDataSource::GotDataCallback& callback) { |
| + if (path == kDataFile) |
| + return HandleDataRequestCallback(path, callback); |
| + if (path.find(kAdbQuery) == 0) |
| + return HandleAdbQueryCallback(path, callback); |
| + if (path.find(kLocalXhr) == 0) |
| + return HandleLocalXhrCallback(path, callback); |
| + return false; |
| +} |
| + |
| +bool InspectUI::HandleAdbQueryCallback( |
| + const std::string& path, |
| + const content::WebUIDataSource::GotDataCallback& callback) { |
| + std::string query = path.substr(strlen(kAdbQuery)); |
| + adb_bridge_->Query(query, base::Bind(&InspectUI::OnAdbResponse, |
| + base::Unretained(this), callback)); |
| + return true; |
| +} |
| + |
| +bool InspectUI::HandleLocalXhrCallback( |
| + const std::string& path, |
| + const content::WebUIDataSource::GotDataCallback& callback) { |
| + std::string url = "http://localhost:" + path.substr(strlen(kLocalXhr)); |
| + adb_bridge_->Fetch(url, base::Bind(&InspectUI::OnAdbResponse, |
| + base::Unretained(this), callback)); |
| + return true; |
| +} |
| + |
| +void InspectUI::OnAdbResponse( |
| + const content::WebUIDataSource::GotDataCallback& callback, |
| + const std::string& error, |
| + const std::string& data) { |
| + ListValue result; |
| + result.AppendString(error); |
| + result.AppendString(data); |
| + std::string json_string; |
| + base::JSONWriter::Write(&result, &json_string); |
| + callback.Run(base::RefCountedString::TakeString(&json_string)); |
| +} |