Merge pull request #1719 from deepak1556/service_worker_patch

devtools: api to inspect service worker
This commit is contained in:
Cheng Zhao 2015-05-27 15:47:41 +08:00
commit 4a376694b4
9 changed files with 41 additions and 1 deletions

View file

@ -679,6 +679,17 @@ void WebContents::UnregisterServiceWorker(
callback); 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( mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
v8::Isolate* isolate) { v8::Isolate* isolate) {
if (template_.IsEmpty()) if (template_.IsEmpty())
@ -722,6 +733,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
.SetMethod("hasServiceWorker", &WebContents::HasServiceWorker) .SetMethod("hasServiceWorker", &WebContents::HasServiceWorker)
.SetMethod("unregisterServiceWorker", .SetMethod("unregisterServiceWorker",
&WebContents::UnregisterServiceWorker) &WebContents::UnregisterServiceWorker)
.SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker)
.Build()); .Build());
return mate::ObjectTemplateBuilder( return mate::ObjectTemplateBuilder(

View file

@ -70,6 +70,7 @@ class WebContents : public mate::EventEmitter,
void InspectElement(int x, int y); void InspectElement(int x, int y);
void HasServiceWorker(const base::Callback<void(bool)>&); void HasServiceWorker(const base::Callback<void(bool)>&);
void UnregisterServiceWorker(const base::Callback<void(bool)>&); void UnregisterServiceWorker(const base::Callback<void(bool)>&);
void InspectServiceWorker();
// Editing commands. // Editing commands.
void Undo(); void Undo();

View file

@ -371,6 +371,10 @@ void Window::InspectElement(int x, int y) {
window_->InspectElement(x, y); window_->InspectElement(x, y);
} }
void Window::InspectServiceWorker() {
window_->InspectServiceWorker();
}
void Window::FocusOnWebView() { void Window::FocusOnWebView() {
window_->FocusOnWebView(); window_->FocusOnWebView();
} }
@ -544,7 +548,8 @@ void Window::BuildPrototype(v8::Isolate* isolate,
&Window::ShowDefinitionForSelection) &Window::ShowDefinitionForSelection)
#endif #endif
.SetMethod("_getWebContents", &Window::GetWebContents) .SetMethod("_getWebContents", &Window::GetWebContents)
.SetMethod("_getDevToolsWebContents", &Window::GetDevToolsWebContents); .SetMethod("_getDevToolsWebContents", &Window::GetDevToolsWebContents)
.SetMethod("inspectServiceWorker", &Window::InspectServiceWorker);
} }
} // namespace api } // namespace api

View file

@ -121,6 +121,7 @@ class Window : public mate::EventEmitter,
void CloseDevTools(); void CloseDevTools();
bool IsDevToolsOpened(); bool IsDevToolsOpened();
void InspectElement(int x, int y); void InspectElement(int x, int y);
void InspectServiceWorker();
void FocusOnWebView(); void FocusOnWebView();
void BlurWebView(); void BlurWebView();
bool IsWebViewFocused(); bool IsWebViewFocused();

View file

@ -314,6 +314,17 @@ void NativeWindow::InspectElement(int x, int y) {
agent->InspectElement(x, 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() { void NativeWindow::FocusOnWebView() {
GetWebContents()->GetRenderViewHost()->Focus(); GetWebContents()->GetRenderViewHost()->Focus();
} }

View file

@ -153,6 +153,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
virtual void CloseDevTools(); virtual void CloseDevTools();
virtual bool IsDevToolsOpened(); virtual bool IsDevToolsOpened();
virtual void InspectElement(int x, int y); virtual void InspectElement(int x, int y);
virtual void InspectServiceWorker();
virtual void FocusOnWebView(); virtual void FocusOnWebView();
virtual void BlurWebView(); virtual void BlurWebView();

View file

@ -270,6 +270,7 @@ registerWebViewElement = ->
"replaceMisspelling" "replaceMisspelling"
"send" "send"
"getId" "getId"
"inspectServiceWorker"
] ]
# Forward proto.foo* method calls to WebViewImpl.foo*. # Forward proto.foo* method calls to WebViewImpl.foo*.

View file

@ -524,6 +524,10 @@ Toggle the developer tools.
Starts inspecting element at position (`x`, `y`). 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.focusOnWebView()
### BrowserWindow.blurWebView() ### BrowserWindow.blurWebView()

View file

@ -238,6 +238,10 @@ Returns whether guest page has a devtools window attached.
Starts inspecting element at position (`x`, `y`) of guest page. Starts inspecting element at position (`x`, `y`) of guest page.
### `<webview>`.inspectServiceWorker()
Opens the devtools for the service worker context present in the guest page.
### `<webview>`.undo() ### `<webview>`.undo()
Executes editing command `undo` in page. Executes editing command `undo` in page.