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