OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/webui/media_internals_ui.h" | |
6 | |
7 #include "base/memory/ref_counted_memory.h" | |
8 #include "base/values.h" | |
9 #include "chrome/browser/profiles/profile.h" | |
10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | |
11 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | |
12 #include "chrome/common/jstemplate_builder.h" | |
13 #include "chrome/common/url_constants.h" | |
14 #include "grit/browser_resources.h" | |
15 #include "ui/base/resource/resource_bundle.h" | |
16 | |
17 namespace { | |
18 | |
19 class MediaInternalsHTMLSource : public ChromeURLDataManager::DataSource { | |
20 public: | |
21 MediaInternalsHTMLSource(); | |
22 | |
23 // Called when the network layer has requested a resource underneath | |
24 // the path we registered. | |
25 virtual void StartDataRequest(const std::string& path, | |
26 bool is_incognito, | |
27 int request_id); | |
28 virtual std::string GetMimeType(const std::string& path) const; | |
29 | |
30 private: | |
31 virtual ~MediaInternalsHTMLSource() {} | |
32 DISALLOW_COPY_AND_ASSIGN(MediaInternalsHTMLSource); | |
33 }; | |
34 | |
35 //////////////////////////////////////////////////////////////////////////////// | |
36 // | |
37 // MediaInternalsHTMLSource | |
38 // | |
39 //////////////////////////////////////////////////////////////////////////////// | |
40 | |
41 MediaInternalsHTMLSource::MediaInternalsHTMLSource() | |
42 : DataSource(chrome::kChromeUIMediaInternalsHost, MessageLoop::current()) { | |
43 } | |
44 | |
45 void MediaInternalsHTMLSource::StartDataRequest(const std::string& path, | |
46 bool is_incognito, | |
47 int request_id) { | |
48 DictionaryValue localized_strings; | |
49 SetFontAndTextDirection(&localized_strings); | |
50 | |
51 base::StringPiece html_template( | |
52 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
53 IDR_MEDIA_INTERNALS_HTML)); | |
54 std::string html(html_template.data(), html_template.size()); | |
55 jstemplate_builder::AppendI18nTemplateSourceHtml(&html); | |
56 jstemplate_builder::AppendJsTemplateSourceHtml(&html); | |
57 jstemplate_builder::AppendJsonHtml(&localized_strings, &html); | |
58 jstemplate_builder::AppendI18nTemplateProcessHtml(&html); | |
59 | |
60 scoped_refptr<RefCountedBytes> bytes(new RefCountedBytes()); | |
61 bytes->data.resize(html.size()); | |
62 std::copy(html.begin(), html.end(), bytes->data.begin()); | |
63 | |
64 SendResponse(request_id, bytes); | |
65 } | |
66 | |
67 std::string MediaInternalsHTMLSource::GetMimeType( | |
68 const std::string& path) const { | |
69 return "text/html"; | |
70 } | |
71 | |
72 } // namespace | |
73 | |
74 | |
75 //////////////////////////////////////////////////////////////////////////////// | |
76 // | |
77 // MediaInternalsUI | |
78 // | |
79 //////////////////////////////////////////////////////////////////////////////// | |
80 | |
81 MediaInternalsUI::MediaInternalsUI(TabContents* contents) | |
82 : ChromeWebUI(contents) { | |
83 contents->profile()->GetChromeURLDataManager()->AddDataSource( | |
84 new MediaInternalsHTMLSource()); | |
85 } | |
86 | |
OLD | NEW |