// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "android_webview/browser/aw_devtools_delegate.h" #include "android_webview/browser/browser_view_renderer_impl.h" #include "base/bind.h" #include "base/json/json_writer.h" #include "base/stringprintf.h" #include "base/values.h" #include "content/public/browser/android/devtools_auth.h" #include "content/public/browser/devtools_http_handler.h" #include "content/public/browser/web_contents.h" #include "content/public/common/url_constants.h" #include "net/socket/unix_domain_socket_posix.h" #include "ui/base/resource/resource_bundle.h" namespace { const char kSocketNameFormat[] = "webview_devtools_remote_%d"; } namespace android_webview { AwDevToolsDelegate::AwDevToolsDelegate(content::BrowserContext* browser_context) : browser_context_(browser_context) { devtools_http_handler_ = content::DevToolsHttpHandler::Start( new net::UnixDomainSocketWithAbstractNamespaceFactory( base::StringPrintf(kSocketNameFormat, getpid()), base::Bind(&content::CanUserConnectToDevTools)), "", this); } AwDevToolsDelegate::~AwDevToolsDelegate() { } void AwDevToolsDelegate::Stop() { devtools_http_handler_->Stop(); // WARNING: |this| has now been deleted by the method above. } std::string AwDevToolsDelegate::GetDiscoveryPageHTML() { // This is a temporary way of providing the list of inspectable WebViews. // Since WebView doesn't have its own resources now, it doesn't seem // reasonable to create a dedicated .pak file just for this temporary page. const char html[] = "" "" "WebView remote debugging" "" "" "" "" "
Inspectable WebViews
" "

Only show:

" "
" " " " Attached
" " " " Visible
" " " " Non-empty
" " " " Auto refresh every " " seconds
" "
" "
" " " " " " " " " " " " " " " "
TitleAttachedVisibleEmptyPositionSize
" "" ""; return html; } bool AwDevToolsDelegate::BundlesFrontendResources() { return true; } base::FilePath AwDevToolsDelegate::GetDebugFrontendDir() { return base::FilePath(); } std::string AwDevToolsDelegate::GetPageThumbnailData(const GURL& url) { return ""; } content::RenderViewHost* AwDevToolsDelegate::CreateNewTarget() { return NULL; } content::DevToolsHttpHandlerDelegate::TargetType AwDevToolsDelegate::GetTargetType(content::RenderViewHost*) { return kTargetTypeTab; } std::string AwDevToolsDelegate::GetViewDescription( content::RenderViewHost* rvh) { content::WebContents* web_contents = content::WebContents::FromRenderViewHost(rvh); if (!web_contents) return ""; BrowserViewRenderer* bvr = BrowserViewRendererImpl::FromWebContents(web_contents); if (!bvr) return ""; base::DictionaryValue description; description.SetBoolean("attached", bvr->IsAttachedToWindow()); description.SetBoolean("visible", bvr->IsViewVisible()); gfx::Rect screen_rect = bvr->GetScreenRect(); description.SetInteger("screenX", screen_rect.x()); description.SetInteger("screenY", screen_rect.y()); description.SetBoolean("empty", screen_rect.size().IsEmpty()); if (!screen_rect.size().IsEmpty()) { description.SetInteger("width", screen_rect.width()); description.SetInteger("height", screen_rect.height()); } std::string json; base::JSONWriter::Write(&description, &json); return json; } } // namespace android_webview