| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/webui/web_ui_data_source_impl.h" | 5 #include "content/browser/webui/web_ui_data_source_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "content/public/common/content_client.h" | 12 #include "content/public/common/content_client.h" |
| 13 #include "grit/content_resources.h" | |
| 14 #include "ui/base/webui/jstemplate_builder.h" | 13 #include "ui/base/webui/jstemplate_builder.h" |
| 15 #include "ui/base/webui/web_ui_util.h" | 14 #include "ui/base/webui/web_ui_util.h" |
| 16 | 15 |
| 17 #if defined(USE_MOJO) | |
| 18 #include "mojo/public/bindings/js/constants.h" | |
| 19 #endif | |
| 20 | |
| 21 namespace content { | 16 namespace content { |
| 22 | 17 |
| 23 // static | |
| 24 WebUIDataSource* WebUIDataSource::Create(const std::string& source_name) { | 18 WebUIDataSource* WebUIDataSource::Create(const std::string& source_name) { |
| 25 return new WebUIDataSourceImpl(source_name); | 19 return new WebUIDataSourceImpl(source_name); |
| 26 } | 20 } |
| 27 | 21 |
| 28 #if defined(USE_MOJO) | |
| 29 // static | |
| 30 WebUIDataSource* WebUIDataSource::AddMojoDataSource( | |
| 31 BrowserContext* browser_context) { | |
| 32 WebUIDataSource* mojo_source = Create("mojo"); | |
| 33 mojo_source->AddResourcePath(mojo::kCodecModuleName, IDR_MOJO_CODEC_JS); | |
| 34 mojo_source->AddResourcePath(mojo::kConnectorModuleName, | |
| 35 IDR_MOJO_CONNECTOR_JS); | |
| 36 URLDataManager::AddWebUIDataSource(browser_context, mojo_source); | |
| 37 return mojo_source; | |
| 38 } | |
| 39 #endif | |
| 40 | |
| 41 // static | |
| 42 void WebUIDataSource::Add(BrowserContext* browser_context, | 22 void WebUIDataSource::Add(BrowserContext* browser_context, |
| 43 WebUIDataSource* source) { | 23 WebUIDataSource* source) { |
| 44 URLDataManager::AddWebUIDataSource(browser_context, source); | 24 URLDataManager::AddWebUIDataSource(browser_context, source); |
| 45 } | 25 } |
| 46 | 26 |
| 47 // Internal class to hide the fact that WebUIDataSourceImpl implements | 27 // Internal class to hide the fact that WebUIDataSourceImpl implements |
| 48 // URLDataSource. | 28 // URLDataSource. |
| 49 class WebUIDataSourceImpl::InternalDataSource : public URLDataSource { | 29 class WebUIDataSourceImpl::InternalDataSource : public URLDataSource { |
| 50 public: | 30 public: |
| 51 InternalDataSource(WebUIDataSourceImpl* parent) : parent_(parent) { | 31 InternalDataSource(WebUIDataSourceImpl* parent) : parent_(parent) { |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 224 } |
| 245 | 225 |
| 246 void WebUIDataSourceImpl::SendFromResourceBundle( | 226 void WebUIDataSourceImpl::SendFromResourceBundle( |
| 247 const URLDataSource::GotDataCallback& callback, int idr) { | 227 const URLDataSource::GotDataCallback& callback, int idr) { |
| 248 scoped_refptr<base::RefCountedStaticMemory> response( | 228 scoped_refptr<base::RefCountedStaticMemory> response( |
| 249 GetContentClient()->GetDataResourceBytes(idr)); | 229 GetContentClient()->GetDataResourceBytes(idr)); |
| 250 callback.Run(response.get()); | 230 callback.Run(response.get()); |
| 251 } | 231 } |
| 252 | 232 |
| 253 } // namespace content | 233 } // namespace content |
| OLD | NEW |