Index: chrome/browser/ui/webui/media_internals_ui.cc |
diff --git a/chrome/browser/ui/webui/media_internals_ui.cc b/chrome/browser/ui/webui/media_internals_ui.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8195ee77cb08902d09f474b79abce35c67573950 |
--- /dev/null |
+++ b/chrome/browser/ui/webui/media_internals_ui.cc |
@@ -0,0 +1,91 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/webui/media_internals_ui.h" |
+ |
+#include <algorithm> |
+ |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/ref_counted_memory.h" |
+#include "base/message_loop.h" |
+#include "base/string_piece.h" |
+#include "base/values.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
+#include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
+#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.
|
+#include "chrome/common/url_constants.h" |
+#include "grit/browser_resources.h" |
+#include "ui/base/resource/resource_bundle.h" |
+ |
+namespace { |
+ |
+class MediaInternalsHTMLSource : public ChromeURLDataManager::DataSource { |
+ public: |
+ MediaInternalsHTMLSource(); |
+ |
+ // Called when the network layer has requested a resource underneath |
+ // the path we registered. |
+ virtual void StartDataRequest(const std::string& path, |
+ bool is_incognito, |
+ int request_id); |
+ 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.
|
+ |
+ private: |
+ ~MediaInternalsHTMLSource() {} |
scherkus (not reviewing)
2011/06/14 02:21:34
should be virtual
Scott Franklin
2011/06/14 17:16:50
Done.
|
+ DISALLOW_COPY_AND_ASSIGN(MediaInternalsHTMLSource); |
+}; |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// |
+// MediaInternalsHTMLSource |
+// |
+//////////////////////////////////////////////////////////////////////////////// |
+ |
+MediaInternalsHTMLSource::MediaInternalsHTMLSource() |
+ : DataSource(chrome::kChromeUIMediaInternalsHost, MessageLoop::current()) { |
+} |
+ |
+void MediaInternalsHTMLSource::StartDataRequest(const std::string& path, |
+ bool is_incognito, |
+ int request_id) { |
+ DictionaryValue localized_strings; |
+ SetFontAndTextDirection(&localized_strings); |
+ |
+ base::StringPiece html_template( |
+ ResourceBundle::GetSharedInstance().GetRawDataResource( |
+ IDR_MEDIA_INTERNALS_HTML)); |
+ std::string html(html_template.data(), html_template.size()); |
+ jstemplate_builder::AppendI18nTemplateSourceHtml(&html); |
+ jstemplate_builder::AppendJsTemplateSourceHtml(&html); |
+ jstemplate_builder::AppendJsonHtml(&localized_strings, &html); |
+ jstemplate_builder::AppendI18nTemplateProcessHtml(&html); |
+ |
+ scoped_refptr<RefCountedBytes> bytes(new RefCountedBytes()); |
+ bytes->data.resize(html.size()); |
+ std::copy(html.begin(), html.end(), bytes->data.begin()); |
+ |
+ SendResponse(request_id, bytes); |
+} |
+ |
+std::string MediaInternalsHTMLSource::GetMimeType( |
+ const std::string& path) const { |
+ return "text/html"; |
+} |
+ |
+} // namespace |
+ |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// |
+// MediaInternalsUI |
+// |
+//////////////////////////////////////////////////////////////////////////////// |
+ |
+MediaInternalsUI::MediaInternalsUI(TabContents* contents) |
+ : ChromeWebUI(contents) { |
+ contents->profile()->GetChromeURLDataManager()->AddDataSource( |
+ new MediaInternalsHTMLSource()); |
+} |
+ |