Home | History | Annotate | Download | only in webui
      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/components_resources.h"
     15 #include "grit/components_strings.h"
     16 
     17 namespace dom_distiller {
     18 
     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", IDR_ABOUT_DOM_DISTILLER_JS);
     30 
     31   source->SetUseJsonJSFormatV2();
     32   source->AddLocalizedString("domDistillerTitle",
     33                              IDS_DOM_DISTILLER_WEBUI_TITLE);
     34   source->AddLocalizedString("addArticleUrl",
     35                              IDS_DOM_DISTILLER_WEBUI_ENTRY_URL);
     36   source->AddLocalizedString("addArticleAddButtonLabel",
     37                              IDS_DOM_DISTILLER_WEBUI_ENTRY_ADD);
     38   source->AddLocalizedString("addArticleFailedLabel",
     39                              IDS_DOM_DISTILLER_WEBUI_ENTRY_ADD_FAILED);
     40   source->AddLocalizedString("viewUrlButtonLabel",
     41                              IDS_DOM_DISTILLER_WEBUI_VIEW_URL);
     42   source->AddLocalizedString("viewUrlFailedLabel",
     43                              IDS_DOM_DISTILLER_WEBUI_VIEW_URL_FAILED);
     44   source->AddLocalizedString("loadingEntries",
     45                              IDS_DOM_DISTILLER_WEBUI_FETCHING_ENTRIES);
     46   source->AddLocalizedString("refreshButtonLabel",
     47                              IDS_DOM_DISTILLER_WEBUI_REFRESH);
     48 
     49   content::BrowserContext* browser_context =
     50       web_ui->GetWebContents()->GetBrowserContext();
     51   content::WebUIDataSource::Add(browser_context, source);
     52   source->SetJsonPath("strings.js");
     53 
     54   // Add message handler.
     55   web_ui->AddMessageHandler(new DomDistillerHandler(service, scheme));
     56 }
     57 
     58 DomDistillerUi::~DomDistillerUi() {}
     59 
     60 }  // namespace dom_distiller
     61