1d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// found in the LICENSE file.
4d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
5d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "components/dom_distiller/webui/dom_distiller_ui.h"
6d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
7d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "components/dom_distiller/core/dom_distiller_constants.h"
8a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/dom_distiller/core/dom_distiller_service.h"
9d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "components/dom_distiller/webui/dom_distiller_handler.h"
10d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "content/public/browser/browser_context.h"
11d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "content/public/browser/web_contents.h"
12d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "content/public/browser/web_ui.h"
13d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "content/public/browser/web_ui_data_source.h"
141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "grit/components_resources.h"
15cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "grit/components_strings.h"
16d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
17d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)namespace dom_distiller {
18d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)DomDistillerUi::DomDistillerUi(content::WebUI* web_ui,
20a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                               DomDistillerService* service,
21a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                               const std::string& scheme)
22d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    : content::WebUIController(web_ui) {
23d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Set up WebUIDataSource.
24d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  content::WebUIDataSource* source =
25d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      content::WebUIDataSource::Create(kChromeUIDomDistillerHost);
26d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  source->SetDefaultResource(IDR_ABOUT_DOM_DISTILLER_HTML);
27d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  source->AddResourcePath("about_dom_distiller.css",
28d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                          IDR_ABOUT_DOM_DISTILLER_CSS);
29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  source->AddResourcePath("about_dom_distiller.js", IDR_ABOUT_DOM_DISTILLER_JS);
30d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
31d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  source->SetUseJsonJSFormatV2();
32a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  source->AddLocalizedString("domDistillerTitle",
33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                             IDS_DOM_DISTILLER_WEBUI_TITLE);
34a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  source->AddLocalizedString("addArticleUrl",
35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                             IDS_DOM_DISTILLER_WEBUI_ENTRY_URL);
36a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  source->AddLocalizedString("addArticleAddButtonLabel",
37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                             IDS_DOM_DISTILLER_WEBUI_ENTRY_ADD);
38a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  source->AddLocalizedString("addArticleFailedLabel",
39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                             IDS_DOM_DISTILLER_WEBUI_ENTRY_ADD_FAILED);
40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  source->AddLocalizedString("viewUrlButtonLabel",
41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                             IDS_DOM_DISTILLER_WEBUI_VIEW_URL);
42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  source->AddLocalizedString("viewUrlFailedLabel",
43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                             IDS_DOM_DISTILLER_WEBUI_VIEW_URL_FAILED);
44a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  source->AddLocalizedString("loadingEntries",
45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                             IDS_DOM_DISTILLER_WEBUI_FETCHING_ENTRIES);
46a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  source->AddLocalizedString("refreshButtonLabel",
47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                             IDS_DOM_DISTILLER_WEBUI_REFRESH);
48a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
49d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  content::BrowserContext* browser_context =
50d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      web_ui->GetWebContents()->GetBrowserContext();
51d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  content::WebUIDataSource::Add(browser_context, source);
52d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  source->SetJsonPath("strings.js");
53d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
54d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Add message handler.
55a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  web_ui->AddMessageHandler(new DomDistillerHandler(service, scheme));
56d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
57d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
58a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)DomDistillerUi::~DomDistillerUi() {}
59d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
60d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}  // namespace dom_distiller
61