• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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 "components/dom_distiller/webui/dom_distiller_ui.h"
6 
7 #include "components/dom_distiller/core/dom_distiller_constants.h"
8 #include "components/dom_distiller/core/dom_distiller_service.h"
9 #include "components/dom_distiller/webui/dom_distiller_handler.h"
10 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/web_contents.h"
12 #include "content/public/browser/web_ui.h"
13 #include "content/public/browser/web_ui_data_source.h"
14 #include "grit/component_strings.h"
15 #include "grit/dom_distiller_resources.h"
16 
17 namespace dom_distiller {
18 
DomDistillerUi(content::WebUI * web_ui,DomDistillerService * service,const std::string & scheme)19 DomDistillerUi::DomDistillerUi(content::WebUI* web_ui,
20                                DomDistillerService* service,
21                                const std::string& scheme)
22     : content::WebUIController(web_ui) {
23   // Set up WebUIDataSource.
24   content::WebUIDataSource* source =
25       content::WebUIDataSource::Create(kChromeUIDomDistillerHost);
26   source->SetDefaultResource(IDR_ABOUT_DOM_DISTILLER_HTML);
27   source->AddResourcePath("about_dom_distiller.css",
28                           IDR_ABOUT_DOM_DISTILLER_CSS);
29   source->AddResourcePath("about_dom_distiller.js",
30                           IDR_ABOUT_DOM_DISTILLER_JS);
31 
32   source->SetUseJsonJSFormatV2();
33   source->AddLocalizedString("domDistillerTitle",
34       IDS_DOM_DISTILLER_WEBUI_TITLE);
35   source->AddLocalizedString("addArticleUrl",
36       IDS_DOM_DISTILLER_WEBUI_ENTRY_URL);
37   source->AddLocalizedString("addArticleAddButtonLabel",
38       IDS_DOM_DISTILLER_WEBUI_ENTRY_ADD);
39   source->AddLocalizedString("addArticleFailedLabel",
40       IDS_DOM_DISTILLER_WEBUI_ENTRY_ADD_FAILED);
41   source->AddLocalizedString("loadingEntries",
42       IDS_DOM_DISTILLER_WEBUI_FETCHING_ENTRIES);
43   source->AddLocalizedString("refreshButtonLabel",
44       IDS_DOM_DISTILLER_WEBUI_REFRESH);
45 
46   content::BrowserContext* browser_context =
47       web_ui->GetWebContents()->GetBrowserContext();
48   content::WebUIDataSource::Add(browser_context, source);
49   source->SetJsonPath("strings.js");
50 
51   // Add message handler.
52   web_ui->AddMessageHandler(new DomDistillerHandler(service, scheme));
53 }
54 
~DomDistillerUi()55 DomDistillerUi::~DomDistillerUi() {}
56 
57 }  // namespace dom_distiller
58