Use the new devtools URL

This commit is contained in:
Cheng Zhao 2015-09-02 18:25:59 +08:00
parent f077a51459
commit dca5c763e9
2 changed files with 39 additions and 14 deletions

View file

@ -20,7 +20,8 @@ namespace brightray {
namespace { namespace {
const char kChromeUIDevToolsBundledHost[] = "devtools"; const char kChromeUIDevToolsHost[] = "devtools";
const char kChromeUIDevToolsBundledPath[] = "bundled";
std::string PathWithoutParams(const std::string& path) { std::string PathWithoutParams(const std::string& path) {
return GURL(std::string("chrome-devtools://devtools/") + path) return GURL(std::string("chrome-devtools://devtools/") + path)
@ -53,19 +54,23 @@ class BundledDataSource : public content::URLDataSource {
// content::URLDataSource implementation. // content::URLDataSource implementation.
std::string GetSource() const override { std::string GetSource() const override {
return kChromeUIDevToolsBundledHost; return kChromeUIDevToolsHost;
} }
void StartDataRequest(const std::string& path, void StartDataRequest(const std::string& path,
int render_process_id, int render_process_id,
int render_view_id, int render_frame_id,
const GotDataCallback& callback) override { const GotDataCallback& callback) override {
std::string filename = PathWithoutParams(path); // Serve request from local bundle.
base::StringPiece resource = std::string bundled_path_prefix(kChromeUIDevToolsBundledPath);
content::DevToolsFrontendHost::GetFrontendResource(filename); bundled_path_prefix += "/";
scoped_refptr<base::RefCountedStaticMemory> bytes( if (base::StartsWith(path, bundled_path_prefix,
new base::RefCountedStaticMemory(resource.data(), resource.length())); base::CompareCase::INSENSITIVE_ASCII)) {
callback.Run(bytes.get()); StartBundledDataRequest(path.substr(bundled_path_prefix.length()),
render_process_id, render_frame_id, callback);
return;
}
callback.Run(nullptr);
} }
std::string GetMimeType(const std::string& path) const override { std::string GetMimeType(const std::string& path) const override {
@ -84,6 +89,24 @@ class BundledDataSource : public content::URLDataSource {
return true; return true;
} }
void StartBundledDataRequest(
const std::string& path,
int render_process_id,
int render_frame_id,
const content::URLDataSource::GotDataCallback& callback) {
std::string filename = PathWithoutParams(path);
base::StringPiece resource =
content::DevToolsFrontendHost::GetFrontendResource(filename);
DLOG_IF(WARNING, resource.empty())
<< "Unable to find dev tool resource: " << filename
<< ". If you compiled with debug_devtools=1, try running with "
"--debug-devtools.";
scoped_refptr<base::RefCountedStaticMemory> bytes(
new base::RefCountedStaticMemory(resource.data(), resource.length()));
callback.Run(bytes.get());
}
private: private:
virtual ~BundledDataSource() {} virtual ~BundledDataSource() {}
DISALLOW_COPY_AND_ASSIGN(BundledDataSource); DISALLOW_COPY_AND_ASSIGN(BundledDataSource);

View file

@ -38,11 +38,13 @@ const double kPresetZoomFactors[] = { 0.25, 0.333, 0.5, 0.666, 0.75, 0.9, 1.0,
1.1, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0, 1.1, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0,
5.0 }; 5.0 };
const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?" const char kChromeUIDevToolsURL[] =
"can_dock=%s&" "chrome-devtools://devtools/bundled/inspector.html?"
"toolbarColor=rgba(223,223,223,1)&" "can_dock=%s&"
"textColor=rgba(0,0,0,1)&" "toolbarColor=rgba(223,223,223,1)&"
"experiments=true"; "textColor=rgba(0,0,0,1)&"
"experiments=true";
const char kDevToolsBoundsPref[] = "brightray.devtools.bounds"; const char kDevToolsBoundsPref[] = "brightray.devtools.bounds";
const char kDevToolsZoomPref[] = "brightray.devtools.zoom"; const char kDevToolsZoomPref[] = "brightray.devtools.zoom";
const char kDevToolsPreferences[] = "brightray.devtools.preferences"; const char kDevToolsPreferences[] = "brightray.devtools.preferences";