namespace internal {
-Status ParseWebViewsInfo(const std::string& data,
- WebViewsInfo* views_info) {
+Status ParseWebViewsInfo(const std::string& data, WebViewsInfo* views_info) {
scoped_ptr<base::Value> value(base::JSONReader::Read(data));
if (!value.get())
return Status(kUnknownError, "DevTools returned invalid JSON");
std::string debugger_url;
info->GetString("webSocketDebuggerUrl", &debugger_url);
WebViewInfo::Type type;
- if (type_as_string == "app")
- type = WebViewInfo::kApp;
- else if (type_as_string == "background_page")
- type = WebViewInfo::kBackgroundPage;
- else if (type_as_string == "page")
- type = WebViewInfo::kPage;
- else if (type_as_string == "worker")
- type = WebViewInfo::kWorker;
- else if (type_as_string == "other")
- type = WebViewInfo::kOther;
- else
- return Status(kUnknownError,
- "DevTools returned unknown type:" + type_as_string);
+ Status status = ParseType(type_as_string, &type);
+ if (status.IsError())
+ return status;
temp_views_info.push_back(WebViewInfo(id, debugger_url, url, type));
}
*views_info = WebViewsInfo(temp_views_info);
return Status(kOk);
}
+Status ParseType(const std::string& type_as_string, WebViewInfo::Type* type) {
+ if (type_as_string == "app")
+ *type = WebViewInfo::kApp;
+ else if (type_as_string == "background_page")
+ *type = WebViewInfo::kBackgroundPage;
+ else if (type_as_string == "page")
+ *type = WebViewInfo::kPage;
+ else if (type_as_string == "worker")
+ *type = WebViewInfo::kWorker;
+ else if (type_as_string == "webview")
+ *type = WebViewInfo::kWebView;
+ else if (type_as_string == "iframe")
+ *type = WebViewInfo::kIFrame;
+ else if (type_as_string == "other")
+ *type = WebViewInfo::kOther;
+ else if (type_as_string == "service_worker")
+ *type = WebViewInfo::kServiceWorker;
+ else
+ return Status(kUnknownError,
+ "DevTools returned unknown type:" + type_as_string);
+ return Status(kOk);
+}
+
} // namespace internal