| Index: chrome/browser/ui/webui/devtools_ui.cc
|
| diff --git a/chrome/browser/ui/webui/devtools_ui.cc b/chrome/browser/ui/webui/devtools_ui.cc
|
| index 5ed37d9e8a3eabd9f3cd9612d1745debd154a03b..51daec8f0fec3a1e7016cb4d9ad19e2be984a689 100644
|
| --- a/chrome/browser/ui/webui/devtools_ui.cc
|
| +++ b/chrome/browser/ui/webui/devtools_ui.cc
|
| @@ -4,10 +4,87 @@
|
|
|
| #include "chrome/browser/ui/webui/devtools_ui.h"
|
|
|
| +#include "base/string_util.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
|
| #include "chrome/common/render_messages.h"
|
| +#include "chrome/common/url_constants.h"
|
| #include "content/browser/renderer_host/render_view_host.h"
|
| +#include "content/browser/tab_contents/tab_contents.h"
|
| +#include "grit/devtools_resources_map.h"
|
| +#include "ui/base/resource/resource_bundle.h"
|
| +
|
| +namespace {
|
| +
|
| +std::string PathWithoutParams(const std::string& path) {
|
| + return GURL(std::string("chrome-devtools://devtools/") + path)
|
| + .path().substr(1);
|
| +}
|
| +
|
| +}
|
| +
|
| +class DevToolsDataSource : public ChromeURLDataManager::DataSource {
|
| + public:
|
| + DevToolsDataSource();
|
| +
|
| + virtual void StartDataRequest(const std::string& path,
|
| + bool is_off_the_record,
|
| + int request_id);
|
| + virtual std::string GetMimeType(const std::string& path) const;
|
| +
|
| + private:
|
| + ~DevToolsDataSource() {}
|
| + DISALLOW_COPY_AND_ASSIGN(DevToolsDataSource);
|
| +};
|
| +
|
| +
|
| +DevToolsDataSource::DevToolsDataSource()
|
| + : DataSource(chrome::kChromeUIDevToolsHost, MessageLoop::current()) {
|
| +}
|
| +
|
| +void DevToolsDataSource::StartDataRequest(const std::string& path,
|
| + bool is_off_the_record,
|
| + int request_id) {
|
| + std::string filename = PathWithoutParams(path);
|
| +
|
| + int resource_id = -1;
|
| + for (size_t i = 0; i < kDevtoolsResourcesSize; ++i) {
|
| + if (filename == kDevtoolsResources[i].name) {
|
| + resource_id = kDevtoolsResources[i].value;
|
| + break;
|
| + }
|
| + }
|
| +
|
| + DLOG_IF(WARNING, -1 == resource_id) << "Unable to find dev tool resource: "
|
| + << filename << ". If you compiled with debug_devtools=1, try running"
|
| + " with --debug-devtools.";
|
| + const ResourceBundle& rb = ResourceBundle::GetSharedInstance();
|
| + scoped_refptr<RefCountedStaticMemory> bytes(rb.LoadDataResourceBytes(
|
| + resource_id));
|
| + SendResponse(request_id, bytes);
|
| +}
|
| +
|
| +std::string DevToolsDataSource::GetMimeType(const std::string& path) const {
|
| + std::string filename = PathWithoutParams(path);
|
| + if (EndsWith(filename, ".html", false)) {
|
| + return "text/html";
|
| + } else if (EndsWith(filename, ".css", false)) {
|
| + return "text/css";
|
| + } else if (EndsWith(filename, ".js", false)) {
|
| + return "application/javascript";
|
| + } else if (EndsWith(filename, ".png", false)) {
|
| + return "image/png";
|
| + } else if (EndsWith(filename, ".gif", false)) {
|
| + return "image/gif";
|
| + }
|
| + NOTREACHED();
|
| + return "text/plain";
|
| +}
|
| +
|
|
|
| DevToolsUI::DevToolsUI(TabContents* contents) : WebUI(contents) {
|
| + DevToolsDataSource* data_source = new DevToolsDataSource();
|
| + contents->profile()->GetChromeURLDataManager()->AddDataSource(data_source);
|
| }
|
|
|
| void DevToolsUI::RenderViewCreated(RenderViewHost* render_view_host) {
|
|
|