OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
benm (inactive)
2013/02/28 14:54:12
2013
mnaganov (inactive)
2013/02/28 16:33:04
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "android_webview/browser/aw_devtools_delegate.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/stringprintf.h" | |
9 #include "content/public/browser/android/devtools_auth.h" | |
10 #include "content/public/browser/devtools_http_handler.h" | |
11 #include "content/public/browser/web_contents.h" | |
12 #include "content/public/common/url_constants.h" | |
13 #include "net/base/unix_domain_socket_posix.h" | |
14 #include "ui/base/resource/resource_bundle.h" | |
15 | |
16 namespace { | |
17 const char kSocketNameFormat[] = "webview_devtools_remote_%d"; | |
18 } | |
19 | |
20 namespace android_webview { | |
21 | |
22 AwDevToolsDelegate::AwDevToolsDelegate(content::BrowserContext* browser_context) | |
23 : browser_context_(browser_context) { | |
24 devtools_http_handler_ = content::DevToolsHttpHandler::Start( | |
25 new net::UnixDomainSocketWithAbstractNamespaceFactory( | |
26 StringPrintf(kSocketNameFormat, getpid()), | |
27 base::Bind(&content::CanUserConnectToDevTools)), | |
28 "", | |
29 this); | |
30 } | |
31 | |
32 AwDevToolsDelegate::~AwDevToolsDelegate() { | |
33 } | |
34 | |
35 void AwDevToolsDelegate::Stop() { | |
36 // The call below destroys this. | |
37 devtools_http_handler_->Stop(); | |
38 } | |
39 | |
40 std::string AwDevToolsDelegate::GetDiscoveryPageHTML() { | |
41 // This is a temporary way of providing the list of inspectable WebViews. | |
42 // Since WebView doesn't have its own resources now, it doesn't seem | |
43 // reasonable to create a dedicated .pak file just for this temporary page. | |
44 const char html[] = | |
45 "<html>" | |
46 "<head>" | |
47 "<title>WebView remote debugging</title>" | |
48 "<style>" | |
49 "</style>" | |
50 "<script>" | |
51 "function onLoad() {" | |
52 " var tabs_list_request = new XMLHttpRequest();" | |
53 " tabs_list_request.open(" | |
54 "\"GET\", \"/json/list?t=\" + new Date().getTime(), true);" | |
55 " tabs_list_request.onreadystatechange = onReady;" | |
56 " tabs_list_request.send();" | |
57 "}" | |
58 "function onReady() {" | |
59 " if(this.readyState == 4 && this.status == 200) {" | |
60 " if(this.response != null)" | |
61 " var responseJSON = JSON.parse(this.response);" | |
62 " for (var i = 0; i < responseJSON.length; ++i)" | |
63 " appendItem(responseJSON[i]);" | |
64 " }" | |
65 "}" | |
66 "function appendItem(item_object) {" | |
67 " var frontend_ref;" | |
68 " if (item_object.devtoolsFrontendUrl) {" | |
69 " frontend_ref = document.createElement(\"a\");" | |
70 " frontend_ref.href = item_object.devtoolsFrontendUrl;" | |
71 " frontend_ref.title = item_object.title;" | |
72 " } else {" | |
73 " frontend_ref = document.createElement(\"div\");" | |
74 " frontend_ref.title = " | |
75 "\"The view already has active debugging session\";" | |
76 " }" | |
77 " var text = document.createElement(\"div\");" | |
78 " if (item_object.title)" | |
79 " text.innerText = item_object.title;" | |
80 " else" | |
81 " text.innerText = \"(untitled tab)\";" | |
82 " text.style.cssText = " | |
83 "\"background-image:url(\" + item_object.faviconUrl + \")\";" | |
84 " frontend_ref.appendChild(text);" | |
85 " var item = document.createElement(\"p\");" | |
86 " item.appendChild(frontend_ref);" | |
87 " document.getElementById(\"items\").appendChild(item);" | |
88 "}" | |
89 "</script>" | |
90 "</head>" | |
91 "<body onload='onLoad()'>" | |
92 " <div id='caption'>Inspectable WebViews</div>" | |
93 " <div id='items'></div>" | |
94 "</body>" | |
95 "</html>"; | |
96 return html; | |
97 } | |
98 | |
99 bool AwDevToolsDelegate::BundlesFrontendResources() { | |
100 return true; | |
101 } | |
102 | |
103 base::FilePath AwDevToolsDelegate::GetDebugFrontendDir() { | |
104 return base::FilePath(); | |
105 } | |
106 | |
107 std::string AwDevToolsDelegate::GetPageThumbnailData(const GURL& url) { | |
108 return ""; | |
109 } | |
110 | |
111 content::RenderViewHost* AwDevToolsDelegate::CreateNewTarget() { | |
112 return NULL; | |
113 } | |
114 | |
115 content::DevToolsHttpHandlerDelegate::TargetType | |
116 AwDevToolsDelegate::GetTargetType(content::RenderViewHost*) { | |
117 return kTargetTypeTab; | |
118 } | |
119 | |
120 } // namespace android_webview | |
OLD | NEW |