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" |
13 #include "ui/base/webui/jstemplate_builder.h" | 14 #include "ui/base/webui/jstemplate_builder.h" |
14 #include "ui/base/webui/web_ui_util.h" | 15 #include "ui/base/webui/web_ui_util.h" |
15 | 16 |
| 17 #if defined(USE_MOJO) |
| 18 #include "mojo/public/bindings/js/constants.h" |
| 19 #endif |
| 20 |
16 namespace content { | 21 namespace content { |
17 | 22 |
| 23 // static |
18 WebUIDataSource* WebUIDataSource::Create(const std::string& source_name) { | 24 WebUIDataSource* WebUIDataSource::Create(const std::string& source_name) { |
19 return new WebUIDataSourceImpl(source_name); | 25 return new WebUIDataSourceImpl(source_name); |
20 } | 26 } |
21 | 27 |
| 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 |
22 void WebUIDataSource::Add(BrowserContext* browser_context, | 42 void WebUIDataSource::Add(BrowserContext* browser_context, |
23 WebUIDataSource* source) { | 43 WebUIDataSource* source) { |
24 URLDataManager::AddWebUIDataSource(browser_context, source); | 44 URLDataManager::AddWebUIDataSource(browser_context, source); |
25 } | 45 } |
26 | 46 |
27 // Internal class to hide the fact that WebUIDataSourceImpl implements | 47 // Internal class to hide the fact that WebUIDataSourceImpl implements |
28 // URLDataSource. | 48 // URLDataSource. |
29 class WebUIDataSourceImpl::InternalDataSource : public URLDataSource { | 49 class WebUIDataSourceImpl::InternalDataSource : public URLDataSource { |
30 public: | 50 public: |
31 InternalDataSource(WebUIDataSourceImpl* parent) : parent_(parent) { | 51 InternalDataSource(WebUIDataSourceImpl* parent) : parent_(parent) { |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 } | 244 } |
225 | 245 |
226 void WebUIDataSourceImpl::SendFromResourceBundle( | 246 void WebUIDataSourceImpl::SendFromResourceBundle( |
227 const URLDataSource::GotDataCallback& callback, int idr) { | 247 const URLDataSource::GotDataCallback& callback, int idr) { |
228 scoped_refptr<base::RefCountedStaticMemory> response( | 248 scoped_refptr<base::RefCountedStaticMemory> response( |
229 GetContentClient()->GetDataResourceBytes(idr)); | 249 GetContentClient()->GetDataResourceBytes(idr)); |
230 callback.Run(response.get()); | 250 callback.Run(response.get()); |
231 } | 251 } |
232 | 252 |
233 } // namespace content | 253 } // namespace content |
OLD | NEW |