diff options
author | nyquist@chromium.org <nyquist@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-17 04:01:11 +0000 |
---|---|---|
committer | nyquist@chromium.org <nyquist@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-17 04:01:11 +0000 |
commit | bea0cd590e37917a3252b4a54bd07178130862e5 (patch) | |
tree | d9fbd037ca6c49693cef7027cc9fa3b9d3219dcc /components/dom_distiller | |
parent | 0dac68b42cf4742c6e3d03dfaa14d2aa1ada0ea1 (diff) | |
download | chromium_src-bea0cd590e37917a3252b4a54bd07178130862e5.zip chromium_src-bea0cd590e37917a3252b4a54bd07178130862e5.tar.gz chromium_src-bea0cd590e37917a3252b4a54bd07178130862e5.tar.bz2 |
Initial WebUI for DOM Distiller.
The DOM Distiller component will contain code for an experimental
prototype for distilling the core part of a web page.
To enable this feature, use the command line flag --enable-distiller.
The webui/ folder depends on content, but given iOS at the time being
supports the usage of WebUI, it is kept a a top level folder in the
component instead of in content/.
BUG=288015
Review URL: https://chromiumcodereview.appspot.com/23503042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223528 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/dom_distiller')
-rw-r--r-- | components/dom_distiller/DEPS | 10 | ||||
-rw-r--r-- | components/dom_distiller/OWNERS | 3 | ||||
-rw-r--r-- | components/dom_distiller/README | 12 | ||||
-rw-r--r-- | components/dom_distiller/core/dom_distiller_constants.cc | 12 | ||||
-rw-r--r-- | components/dom_distiller/core/dom_distiller_constants.h | 15 | ||||
-rw-r--r-- | components/dom_distiller/webui/DEPS | 13 | ||||
-rw-r--r-- | components/dom_distiller/webui/dom_distiller_handler.cc | 42 | ||||
-rw-r--r-- | components/dom_distiller/webui/dom_distiller_handler.h | 38 | ||||
-rw-r--r-- | components/dom_distiller/webui/dom_distiller_ui.cc | 42 | ||||
-rw-r--r-- | components/dom_distiller/webui/dom_distiller_ui.h | 24 | ||||
-rw-r--r-- | components/dom_distiller/webui/resources/about_dom_distiller.css | 8 | ||||
-rw-r--r-- | components/dom_distiller/webui/resources/about_dom_distiller.html | 27 | ||||
-rw-r--r-- | components/dom_distiller/webui/resources/about_dom_distiller.js | 32 |
13 files changed, 278 insertions, 0 deletions
diff --git a/components/dom_distiller/DEPS b/components/dom_distiller/DEPS new file mode 100644 index 0000000..66f3cb1 --- /dev/null +++ b/components/dom_distiller/DEPS @@ -0,0 +1,10 @@ +include_rules = [ + "+grit", # For generated headers. + + # The dom distiller is a layered component; subdirectories must explicitly + # introduce the ability to use the content layer as appropriate. + # http://www.chromium.org/developers/design-documents/layered-components-design + "-components/dom_distiller", + "+components/dom_distiller/core", + "-content/public", +]
\ No newline at end of file diff --git a/components/dom_distiller/OWNERS b/components/dom_distiller/OWNERS new file mode 100644 index 0000000..f2ce81c --- /dev/null +++ b/components/dom_distiller/OWNERS @@ -0,0 +1,3 @@ +bengr@chromium.org +cjhopman@chromium.org +nyquist@chromium.org diff --git a/components/dom_distiller/README b/components/dom_distiller/README new file mode 100644 index 0000000..e8d7bb3 --- /dev/null +++ b/components/dom_distiller/README @@ -0,0 +1,12 @@ +The DOM Distiller component contains code for an experimental prototype for +distilling the core part of a web page. + +To enable this feature, use the command line flag --enable-distiller. + +The DOM Distiller is a layered component. See: +http://www.chromium.org/developers/design-documents/layered-components-design + +Folder structure: + + core/ contains the business logic of the component. + webui/ contains the WebUI code and resources for the debug page. diff --git a/components/dom_distiller/core/dom_distiller_constants.cc b/components/dom_distiller/core/dom_distiller_constants.cc new file mode 100644 index 0000000..5dea000 --- /dev/null +++ b/components/dom_distiller/core/dom_distiller_constants.cc @@ -0,0 +1,12 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/dom_distiller/core/dom_distiller_constants.h" + +namespace dom_distiller { + +const char kChromeUIDomDistillerURL[] = "chrome://dom-distiller/"; +const char kChromeUIDomDistillerHost[] = "dom-distiller"; + +} // namespace dom_distiller diff --git a/components/dom_distiller/core/dom_distiller_constants.h b/components/dom_distiller/core/dom_distiller_constants.h new file mode 100644 index 0000000..c39c88e --- /dev/null +++ b/components/dom_distiller/core/dom_distiller_constants.h @@ -0,0 +1,15 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_CONSTANTS_H_ +#define COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_CONSTANTS_H_ + +namespace dom_distiller { + +extern const char kChromeUIDomDistillerURL[]; +extern const char kChromeUIDomDistillerHost[]; + +} // namespace dom_distiller + +#endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_CONSTANTS_H_ diff --git a/components/dom_distiller/webui/DEPS b/components/dom_distiller/webui/DEPS new file mode 100644 index 0000000..2c43d7a --- /dev/null +++ b/components/dom_distiller/webui/DEPS @@ -0,0 +1,13 @@ +include_rules = [ + "+components/dom_distiller/webui", + "+ui/webui/resources", + # The webui of this component needs to depend on content, but since it is + # also supposed to be working on iOS, and there is currently no concrete plan + # yet for extracting webui as something that is reusable across iOS and other + # platforms, this DEPS rule is kept instead. + # To ensure this DEPS rule is not a nuisance to engineers refactoring the + # content layer, it is currently quite broad instead of the more strict + # approach directly allowing the header files that are currently included from + # content. + "+content/public/browser", +]
\ No newline at end of file diff --git a/components/dom_distiller/webui/dom_distiller_handler.cc b/components/dom_distiller/webui/dom_distiller_handler.cc new file mode 100644 index 0000000..c05cc0d --- /dev/null +++ b/components/dom_distiller/webui/dom_distiller_handler.cc @@ -0,0 +1,42 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/dom_distiller/webui/dom_distiller_handler.h" + +#include "base/bind.h" +#include "base/values.h" +#include "content/public/browser/web_ui.h" + +namespace dom_distiller { + +DomDistillerHandler::DomDistillerHandler() + : weak_ptr_factory_(this) { +} + +DomDistillerHandler::~DomDistillerHandler() {} + +void DomDistillerHandler::RegisterMessages() { + web_ui()->RegisterMessageCallback( + "requestEntries", + base::Bind(&DomDistillerHandler::HandleRequestEntries, + base::Unretained(this))); +} + +void DomDistillerHandler::HandleRequestEntries(const ListValue* args) { + base::ListValue entries; + + // Add some temporary placeholder entries. + scoped_ptr<base::DictionaryValue> entry1(new base::DictionaryValue()); + entry1->SetString("title", "Google"); + entry1->SetString("url", "http://www.google.com/"); + entries.Append(entry1.release()); + scoped_ptr<base::DictionaryValue> entry2(new base::DictionaryValue()); + entry2->SetString("title", "Chrome"); + entry2->SetString("url", "http://www.chrome.com/"); + entries.Append(entry2.release()); + + web_ui()->CallJavascriptFunction("onGotEntries", entries); +} + +} // namespace dom_distiller diff --git a/components/dom_distiller/webui/dom_distiller_handler.h b/components/dom_distiller/webui/dom_distiller_handler.h new file mode 100644 index 0000000..2af6d34 --- /dev/null +++ b/components/dom_distiller/webui/dom_distiller_handler.h @@ -0,0 +1,38 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_DOM_DISTILLER_WEBUI_DOM_DISTILLER_HANDLER_H_ +#define COMPONENTS_DOM_DISTILLER_WEBUI_DOM_DISTILLER_HANDLER_H_ + +#include <vector> + +#include "base/memory/weak_ptr.h" +#include "base/values.h" +#include "content/public/browser/web_ui_message_handler.h" + +namespace dom_distiller { + +// Handler class for DOM Distiller page operations. +class DomDistillerHandler : public content::WebUIMessageHandler { + public: + DomDistillerHandler(); + virtual ~DomDistillerHandler(); + + // content::WebUIMessageHandler implementation. + virtual void RegisterMessages() OVERRIDE; + + // Callback for the "requestEntries" message. This synchronously requests the + // list of entries and returns it to the front end. + virtual void HandleRequestEntries(const ListValue* args); + + private: + // Factory for the creating refs in callbacks. + base::WeakPtrFactory<DomDistillerHandler> weak_ptr_factory_; + + DISALLOW_COPY_AND_ASSIGN(DomDistillerHandler); +}; + +} // namespace dom_distiller + +#endif // COMPONENTS_DOM_DISTILLER_WEBUI_DOM_DISTILLER_HANDLER_H_ diff --git a/components/dom_distiller/webui/dom_distiller_ui.cc b/components/dom_distiller/webui/dom_distiller_ui.cc new file mode 100644 index 0000000..e141843 --- /dev/null +++ b/components/dom_distiller/webui/dom_distiller_ui.cc @@ -0,0 +1,42 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/dom_distiller/webui/dom_distiller_ui.h" + +#include "components/dom_distiller/core/dom_distiller_constants.h" +#include "components/dom_distiller/webui/dom_distiller_handler.h" +#include "content/public/browser/browser_context.h" +#include "content/public/browser/web_contents.h" +#include "content/public/browser/web_ui.h" +#include "content/public/browser/web_ui_data_source.h" +#include "grit/component_strings.h" +#include "grit/dom_distiller_resources.h" + +namespace dom_distiller { + +DomDistillerUI::DomDistillerUI(content::WebUI* web_ui) + : content::WebUIController(web_ui) { + // Set up WebUIDataSource. + content::WebUIDataSource* source = + content::WebUIDataSource::Create(kChromeUIDomDistillerHost); + source->SetDefaultResource(IDR_ABOUT_DOM_DISTILLER_HTML); + source->AddResourcePath("about_dom_distiller.css", + IDR_ABOUT_DOM_DISTILLER_CSS); + source->AddResourcePath("about_dom_distiller.js", + IDR_ABOUT_DOM_DISTILLER_JS); + + source->SetUseJsonJSFormatV2(); + source->AddLocalizedString("domDistillerTitle", IDS_DOM_DISTILLER_TITLE); + content::BrowserContext* browser_context = + web_ui->GetWebContents()->GetBrowserContext(); + content::WebUIDataSource::Add(browser_context, source); + source->SetJsonPath("strings.js"); + + // Add message handler. + web_ui->AddMessageHandler(new DomDistillerHandler()); +} + +DomDistillerUI::~DomDistillerUI() {} + +} // namespace dom_distiller diff --git a/components/dom_distiller/webui/dom_distiller_ui.h b/components/dom_distiller/webui/dom_distiller_ui.h new file mode 100644 index 0000000..762b236 --- /dev/null +++ b/components/dom_distiller/webui/dom_distiller_ui.h @@ -0,0 +1,24 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_DOM_DISTILLER_WEBUI_DOM_DISTILLER_UI_H_ +#define COMPONENTS_DOM_DISTILLER_WEBUI_DOM_DISTILLER_UI_H_ + +#include "content/public/browser/web_ui_controller.h" + +namespace dom_distiller { + +// The WebUI handler for chrome://dom-distiller. +class DomDistillerUI : public content::WebUIController { + public: + explicit DomDistillerUI(content::WebUI* web_ui); + virtual ~DomDistillerUI(); + + private: + DISALLOW_COPY_AND_ASSIGN(DomDistillerUI); +}; + +} // namespace dom_distiller + +#endif // COMPONENTS_DOM_DISTILLER_WEBUI_DOM_DISTILLER_UI_H_ diff --git a/components/dom_distiller/webui/resources/about_dom_distiller.css b/components/dom_distiller/webui/resources/about_dom_distiller.css new file mode 100644 index 0000000..088136a --- /dev/null +++ b/components/dom_distiller/webui/resources/about_dom_distiller.css @@ -0,0 +1,8 @@ +/* Copyright 2013 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +a:visited { + color: orange; +} diff --git a/components/dom_distiller/webui/resources/about_dom_distiller.html b/components/dom_distiller/webui/resources/about_dom_distiller.html new file mode 100644 index 0000000..1e3b537 --- /dev/null +++ b/components/dom_distiller/webui/resources/about_dom_distiller.html @@ -0,0 +1,27 @@ +<!DOCTYPE HTML> +<html> +<head> + <meta charset="utf-8"> + <title i18n-content="domDistillerTitle"></title> + <link rel="stylesheet" href="chrome://resources/css/chrome_shared.css"> + <link rel="stylesheet" href="chrome://resources/css/overlay.css"> + <link rel="stylesheet" href="about_dom_distiller.css"> + + <script src="chrome://resources/js/cr.js"></script> + <script src="chrome://resources/js/util.js"></script> + <script src="chrome://resources/js/load_time_data.js"></script> + <script src="chrome://resources/js/cr/ui/overlay.js"></script> + <script src="about_dom_distiller.js"></script> + <script src="strings.js"></script> +</head> +<body> + <header> + <h1 i18n-content="domDistillerTitle"></h1> + </header> + <div id="entries-section"> + <div id="entries-list"></div> + </div> + <script src="chrome://resources/js/i18n_template2.js"></script> + <script src="chrome://resources/js/jstemplate_compiled.js"></script> +</body> +</html> diff --git a/components/dom_distiller/webui/resources/about_dom_distiller.js b/components/dom_distiller/webui/resources/about_dom_distiller.js new file mode 100644 index 0000000..f558d7f --- /dev/null +++ b/components/dom_distiller/webui/resources/about_dom_distiller.js @@ -0,0 +1,32 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * Callback from the backend with the list of entries to display. + * This call will build the entries section of the DOM distiller page, or hide + * that section if there are none to display. + * @param {!Array.<string>} entries The entries. + */ +function onGotEntries(entries) { + $('entries-section').hidden = !entries.length; + if (entries.length > 0) { + var list = document.createElement('ul'); + for (var i = 0; i < entries.length; i++) { + var listItem = document.createElement('li'); + var link = document.createElement('a'); + link.innerText = entries[i].title; + link.setAttribute('href', entries[i].url); + listItem.appendChild(link); + list.appendChild(listItem); + } + $('entries-list').appendChild(list); + } +} + +/* All the work we do on load. */ +function onLoadWork() { + chrome.send('requestEntries'); +} + +document.addEventListener('DOMContentLoaded', onLoadWork); |