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
9 changed files with 41 additions and 1 deletions

View File

@@ -679,6 +679,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())
@@ -722,6 +733,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
.SetMethod("hasServiceWorker", &WebContents::HasServiceWorker)
.SetMethod("unregisterServiceWorker",
&WebContents::UnregisterServiceWorker)
.SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker)
.Build());
return mate::ObjectTemplateBuilder(

View File

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

View File

@@ -371,6 +371,10 @@ void Window::InspectElement(int x, int y) {
window_->InspectElement(x, y);
}
void Window::InspectServiceWorker() {
window_->InspectServiceWorker();
}
void Window::FocusOnWebView() {
window_->FocusOnWebView();
}
@@ -544,7 +548,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

View File

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

View File

@@ -314,6 +314,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();
}

View File

@@ -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();

View File

@@ -270,6 +270,7 @@ registerWebViewElement = ->
"replaceMisspelling"
"send"
"getId"
"inspectServiceWorker"
]
# 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`).
### BrowserWindow.inspectServiceWorker()
Opens the developer tools for the service worker context present in the web contents.
### BrowserWindow.focusOnWebView()
### 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.
### `<webview>`.inspectServiceWorker()
Opens the devtools for the service worker context present in the guest page.
### `<webview>`.undo()
Executes editing command `undo` in page.