From 46d80e8f05391f24fbe9d48d0f5b69728131f400 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Mon, 18 May 2015 19:19:33 +0530 Subject: [PATCH 1/2] devtools: api to inspect service worker for current webcontents --- atom/browser/api/atom_api_web_contents.cc | 12 ++++++++++++ atom/browser/api/atom_api_web_contents.h | 1 + atom/renderer/lib/web-view/web-view.coffee | 1 + docs/api/web-view-tag.md | 4 ++++ 4 files changed, 18 insertions(+) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index e228a064f413..c61a124e4810 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -615,6 +615,17 @@ void WebContents::UnregisterServiceWorker( callback); } +void WebContents::InspectServiceWorker() { + for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) { + if (agent_host->GetType() == + content::DevToolsAgentHost::TYPE_SERVICE_WORKER) { + OpenDevTools(); + storage_->AttachTo(agent_host); + break; + } + } +} + mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( v8::Isolate* isolate) { if (template_.IsEmpty()) @@ -657,6 +668,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( .SetMethod("hasServiceWorker", &WebContents::HasServiceWorker) .SetMethod("unregisterServiceWorker", &WebContents::UnregisterServiceWorker) + .SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker) .Build()); return mate::ObjectTemplateBuilder( diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index e75cfb0267f0..1b22a2cbc61d 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -68,6 +68,7 @@ class WebContents : public mate::EventEmitter, void InspectElement(int x, int y); void HasServiceWorker(const base::Callback&); void UnregisterServiceWorker(const base::Callback&); + void InspectServiceWorker(); // Editing commands. void Undo(); diff --git a/atom/renderer/lib/web-view/web-view.coffee b/atom/renderer/lib/web-view/web-view.coffee index bf163c0cfb5c..c450f753060c 100644 --- a/atom/renderer/lib/web-view/web-view.coffee +++ b/atom/renderer/lib/web-view/web-view.coffee @@ -268,6 +268,7 @@ registerWebViewElement = -> "replaceMisspelling" "send" "getId" + "inspectServiceWorker" ] # Forward proto.foo* method calls to WebViewImpl.foo*. diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index 89ae678b3c46..13bd32d41d79 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -226,6 +226,10 @@ Returns whether guest page has a devtools window attached. Starts inspecting element at position (`x`, `y`) of guest page. +### ``.inspectServiceWorker() + +Opens the devtools for the service worker context present in the guest page. + ### ``.undo() Executes editing command `undo` in page. From 9963ddc4856e3712adb004e03568b6506bdf9583 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Mon, 18 May 2015 20:08:08 +0530 Subject: [PATCH 2/2] implement method on browser window --- atom/browser/api/atom_api_window.cc | 7 ++++++- atom/browser/api/atom_api_window.h | 1 + atom/browser/native_window.cc | 11 +++++++++++ atom/browser/native_window.h | 1 + docs/api/browser-window.md | 4 ++++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index b71499d3699c..74f0ba69ca45 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -351,6 +351,10 @@ void Window::InspectElement(int x, int y) { window_->InspectElement(x, y); } +void Window::InspectServiceWorker() { + window_->InspectServiceWorker(); +} + void Window::FocusOnWebView() { window_->FocusOnWebView(); } @@ -524,7 +528,8 @@ void Window::BuildPrototype(v8::Isolate* isolate, &Window::ShowDefinitionForSelection) #endif .SetMethod("_getWebContents", &Window::GetWebContents) - .SetMethod("_getDevToolsWebContents", &Window::GetDevToolsWebContents); + .SetMethod("_getDevToolsWebContents", &Window::GetDevToolsWebContents) + .SetMethod("inspectServiceWorker", &Window::InspectServiceWorker); } } // namespace api diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index d5c3ceedd2eb..d0d7b2621c56 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -116,6 +116,7 @@ class Window : public mate::EventEmitter, void CloseDevTools(); bool IsDevToolsOpened(); void InspectElement(int x, int y); + void InspectServiceWorker(); void FocusOnWebView(); void BlurWebView(); bool IsWebViewFocused(); diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 5bef1acfb872..9d24e68c8f42 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -317,6 +317,17 @@ void NativeWindow::InspectElement(int x, int y) { agent->InspectElement(x, y); } +void NativeWindow::InspectServiceWorker() { + for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) { + if (agent_host->GetType() == + content::DevToolsAgentHost::TYPE_SERVICE_WORKER) { + OpenDevTools(true); + inspectable_web_contents()->AttachTo(agent_host); + break; + } + } +} + void NativeWindow::FocusOnWebView() { GetWebContents()->GetRenderViewHost()->Focus(); } diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 32c3493cdbf8..05742a3880da 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -153,6 +153,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, virtual void CloseDevTools(); virtual bool IsDevToolsOpened(); virtual void InspectElement(int x, int y); + virtual void InspectServiceWorker(); virtual void FocusOnWebView(); virtual void BlurWebView(); diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index f8ff8e7b9e0c..e20d809a5e7b 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -500,6 +500,10 @@ Toggle the developer tools. Starts inspecting element at position (`x`, `y`). +### BrowserWindow.inspectServiceWorker() + +Opens the developer tools for the service worker context present in the web contents. + ### BrowserWindow.focusOnWebView() ### BrowserWindow.blurWebView()