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

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

Issue 7714007: Apply content-security-policy directive to chrome://workers page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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_number_conversions.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 16 matching lines...) Expand all
27 static const char kOpenDevToolsCommand[] = "openDevTools"; 27 static const char kOpenDevToolsCommand[] = "openDevTools";
28 28
29 static const char kWorkerProcessHostIdField[] = "workerProcessHostId"; 29 static const char kWorkerProcessHostIdField[] = "workerProcessHostId";
30 static const char kWorkerRouteIdField[] = "workerRouteId"; 30 static const char kWorkerRouteIdField[] = "workerRouteId";
31 static const char kUrlField[] = "url"; 31 static const char kUrlField[] = "url";
32 static const char kNameField[] = "name"; 32 static const char kNameField[] = "name";
33 static const char kPidField[] = "pid"; 33 static const char kPidField[] = "pid";
34 34
35 namespace { 35 namespace {
36 36
37 class WorkersUIHTMLSource : public ChromeURLDataManager::DataSource { 37 class WorkersUIHTMLSource : public ChromeWebUIDataSource {
38 public: 38 public:
39 WorkersUIHTMLSource(); 39 WorkersUIHTMLSource();
40 40
41 virtual void StartDataRequest(const std::string& path, 41 virtual void StartDataRequest(const std::string& path,
42 bool is_incognito, 42 bool is_incognito,
43 int request_id); 43 int request_id);
44
45 virtual std::string GetMimeType(const std::string&) const;
46
47 private: 44 private:
48 ~WorkersUIHTMLSource() {} 45 ~WorkersUIHTMLSource() {}
49
50 void SendSharedWorkersData(int request_id); 46 void SendSharedWorkersData(int request_id);
51
52 DISALLOW_COPY_AND_ASSIGN(WorkersUIHTMLSource); 47 DISALLOW_COPY_AND_ASSIGN(WorkersUIHTMLSource);
53 }; 48 };
54 49
55 WorkersUIHTMLSource::WorkersUIHTMLSource() 50 WorkersUIHTMLSource::WorkersUIHTMLSource()
56 : DataSource(chrome::kChromeUIWorkersHost, NULL) { 51 : ChromeWebUIDataSource(chrome::kChromeUIWorkersHost, NULL) {
52 add_resource_path("workers.js", IDR_WORKERS_INDEX_JS);
53 set_default_resource(IDR_WORKERS_INDEX_HTML);
57 } 54 }
58 55
59 void WorkersUIHTMLSource::StartDataRequest(const std::string& path, 56 void WorkersUIHTMLSource::StartDataRequest(const std::string& path,
60 bool is_incognito, 57 bool is_incognito,
61 int request_id) { 58 int request_id) {
62 if (path == kWorkersDataFile) { 59 if (path == kWorkersDataFile) {
63 SendSharedWorkersData(request_id); 60 SendSharedWorkersData(request_id);
64 } else { 61 } else {
65 int idr = IDR_WORKERS_INDEX_HTML; 62 ChromeWebUIDataSource::StartDataRequest(path, is_incognito, request_id);
66 scoped_refptr<RefCountedStaticMemory> response(
67 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(idr));
68 SendResponse(request_id, response);
69 } 63 }
70 } 64 }
71 65
72 std::string WorkersUIHTMLSource::GetMimeType(const std::string& path) const {
73 if (EndsWith(path, ".css", false))
74 return "text/css";
75 if (EndsWith(path, ".js", false))
76 return "application/javascript";
77 if (EndsWith(path, ".json", false))
78 return "plain/text";
79 return "text/html";
80 }
81
82 void WorkersUIHTMLSource::SendSharedWorkersData(int request_id) { 66 void WorkersUIHTMLSource::SendSharedWorkersData(int request_id) {
83 ListValue workers_list; 67 ListValue workers_list;
84 BrowserChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS); 68 BrowserChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS);
85 for (; !iter.Done(); ++iter) { 69 for (; !iter.Done(); ++iter) {
86 WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); 70 WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter);
87 const WorkerProcessHost::Instances& instances = worker->instances(); 71 const WorkerProcessHost::Instances& instances = worker->instances();
88 for (WorkerProcessHost::Instances::const_iterator i = instances.begin(); 72 for (WorkerProcessHost::Instances::const_iterator i = instances.begin();
89 i != instances.end(); ++i) { 73 i != instances.end(); ++i) {
90 if (!i->shared()) 74 if (!i->shared())
91 continue; 75 continue;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 WorkersDOMHandler* handler = new WorkersDOMHandler(); 142 WorkersDOMHandler* handler = new WorkersDOMHandler();
159 AddMessageHandler(handler); 143 AddMessageHandler(handler);
160 handler->Attach(this); 144 handler->Attach(this);
161 145
162 WorkersUIHTMLSource* html_source = new WorkersUIHTMLSource(); 146 WorkersUIHTMLSource* html_source = new WorkersUIHTMLSource();
163 147
164 // Set up the chrome://workers/ source. 148 // Set up the chrome://workers/ source.
165 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); 149 Profile* profile = Profile::FromBrowserContext(contents->browser_context());
166 profile->GetChromeURLDataManager()->AddDataSource(html_source); 150 profile->GetChromeURLDataManager()->AddDataSource(html_source);
167 } 151 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698