Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: chrome/browser/ui/webui/workers_ui.cc

Issue 7248076: DevTools: add initial support for shared workers debugging (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed some debug printing Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/workers_ui.h" 5 #include "chrome/browser/ui/webui/workers_ui.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/memory/ref_counted_memory.h" 8 #include "base/memory/ref_counted_memory.h"
9 #include "base/string_number_conversions.h"
9 #include "base/string_util.h" 10 #include "base/string_util.h"
10 #include "base/values.h" 11 #include "base/values.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" 13 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h"
13 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 14 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
14 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
16 #include "content/browser/debugger/worker_devtools_manager.h"
15 #include "content/browser/tab_contents/tab_contents.h" 17 #include "content/browser/tab_contents/tab_contents.h"
16 #include "content/browser/worker_host/worker_process_host.h" 18 #include "content/browser/worker_host/worker_process_host.h"
19 #include "content/common/devtools_messages.h"
17 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
18 #include "grit/workers_resources.h" 21 #include "grit/workers_resources.h"
19 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
20 23
21 static const char kWorkersDataFile[] = "workers_data.json"; 24 static const char kWorkersDataFile[] = "workers_data.json";
22 static const char kIndexHtmlFile[] = "index.html"; 25 static const char kIndexHtmlFile[] = "index.html";
23 26
24 namespace { 27 namespace {
25 28
26 class WorkersUIHTMLSource : public ChromeURLDataManager::DataSource { 29 class WorkersUIHTMLSource : public ChromeURLDataManager::DataSource {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 ListValue workers_list; 75 ListValue workers_list;
73 BrowserChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS); 76 BrowserChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS);
74 for (; !iter.Done(); ++iter) { 77 for (; !iter.Done(); ++iter) {
75 WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); 78 WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter);
76 const WorkerProcessHost::Instances& instances = worker->instances(); 79 const WorkerProcessHost::Instances& instances = worker->instances();
77 for (WorkerProcessHost::Instances::const_iterator i = instances.begin(); 80 for (WorkerProcessHost::Instances::const_iterator i = instances.begin();
78 i != instances.end(); ++i) { 81 i != instances.end(); ++i) {
79 if (!i->shared()) 82 if (!i->shared())
80 continue; 83 continue;
81 DictionaryValue* worker_data = new DictionaryValue(); 84 DictionaryValue* worker_data = new DictionaryValue();
82 worker_data->SetInteger("id", i->worker_route_id()); 85 worker_data->SetInteger("workerProcessHostId", worker->id());
86 worker_data->SetInteger("workerRouteId", i->worker_route_id());
83 worker_data->SetString("url", i->url().spec()); 87 worker_data->SetString("url", i->url().spec());
84 worker_data->SetString("name", i->name()); 88 worker_data->SetString("name", i->name());
85 worker_data->SetInteger("pid", worker->pid()); 89 worker_data->SetInteger("pid", worker->pid());
86 workers_list.Append(worker_data); 90 workers_list.Append(worker_data);
87 } 91 }
88 } 92 }
89 93
90 std::string json_string; 94 std::string json_string;
91 base::JSONWriter::Write(&workers_list, false, &json_string); 95 base::JSONWriter::Write(&workers_list, false, &json_string);
92 96
93 scoped_refptr<RefCountedBytes> json_bytes(new RefCountedBytes()); 97 scoped_refptr<RefCountedBytes> json_bytes(new RefCountedBytes());
94 json_bytes->data.resize(json_string.size()); 98 json_bytes->data.resize(json_string.size());
95 std::copy(json_string.begin(), json_string.end(), json_bytes->data.begin()); 99 std::copy(json_string.begin(), json_string.end(), json_bytes->data.begin());
96 100
97 SendResponse(request_id, json_bytes); 101 SendResponse(request_id, json_bytes);
98 } 102 }
99 103
104 class WorkersDOMHandler : public WebUIMessageHandler {
105 public:
106 WorkersDOMHandler() {}
107 virtual ~WorkersDOMHandler() {}
108
109 private:
110 // WebUIMessageHandler implementation.
111 virtual void RegisterMessages();
112
113 // Callback for "openDevTools" message.
114 void HandleOpenDevTools(const ListValue* args);
115
116 DISALLOW_COPY_AND_ASSIGN(WorkersDOMHandler);
117 };
118
119 void WorkersDOMHandler::RegisterMessages() {
120 web_ui_->RegisterMessageCallback("openDevTools",
121 NewCallback(this, &WorkersDOMHandler::HandleOpenDevTools));
122 }
123
124 static void OpenDevToolsOnIOThread(int worker_process_host_id,
125 int worker_route_id) {
126 WorkerDevToolsManager::GetInstance()->OpenDevToolsForWorker(
127 worker_process_host_id, worker_route_id);
128 }
129
130 void WorkersDOMHandler::HandleOpenDevTools(const ListValue* args) {
131 std::string worker_process_host_id_str;
132 std::string worker_route_id_str;
133 int worker_process_host_id;
134 int worker_route_id;
135 CHECK(args->GetSize() == 2);
136 CHECK(args->GetString(0, &worker_process_host_id_str));
137 CHECK(args->GetString(1, &worker_route_id_str));
138 CHECK(base::StringToInt(worker_process_host_id_str,
139 &worker_process_host_id));
140 CHECK(base::StringToInt(worker_route_id_str, &worker_route_id));
141 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, NewRunnableFunction(
142 &OpenDevToolsOnIOThread, worker_process_host_id, worker_route_id));
143 }
144
100 } // namespace 145 } // namespace
101 146
102 WorkersUI::WorkersUI(TabContents* contents) : ChromeWebUI(contents) { 147 WorkersUI::WorkersUI(TabContents* contents) : ChromeWebUI(contents) {
148 WorkersDOMHandler* handler = new WorkersDOMHandler();
149 AddMessageHandler(handler);
150 handler->Attach(this);
151
103 WorkersUIHTMLSource* html_source = new WorkersUIHTMLSource(); 152 WorkersUIHTMLSource* html_source = new WorkersUIHTMLSource();
104 153
105 // Set up the chrome://workers/ source. 154 // Set up the chrome://workers/ source.
106 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); 155 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source);
107 } 156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698