Commit bea0cd59 authored by nyquist@chromium.org's avatar nyquist@chromium.org

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
parent 0dac68b4
...@@ -9,4 +9,8 @@ include_rules = [ ...@@ -9,4 +9,8 @@ include_rules = [
"+device/bluetooth", "+device/bluetooth",
"+third_party/angle", # For ANGLE version. "+third_party/angle", # For ANGLE version.
"+third_party/zlib/zlib.h", # For compression level constants. "+third_party/zlib/zlib.h", # For compression level constants.
# DOM Distiller.
"+components/dom_distiller/core",
"+components/dom_distiller/webui",
] ]
...@@ -55,6 +55,8 @@ ...@@ -55,6 +55,8 @@
#include "chrome/common/extensions/feature_switch.h" #include "chrome/common/extensions/feature_switch.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "components/dom_distiller/core/dom_distiller_constants.h"
#include "components/dom_distiller/webui/dom_distiller_ui.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui.h"
#include "content/public/common/content_client.h" #include "content/public/common/content_client.h"
...@@ -237,6 +239,11 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, ...@@ -237,6 +239,11 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
return &NewWebUI<LocalDiscoveryUI>; return &NewWebUI<LocalDiscoveryUI>;
} }
#endif #endif
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableDomDistiller) &&
url.host() == dom_distiller::kChromeUIDomDistillerHost) {
return &NewWebUI<dom_distiller::DomDistillerUI>;
}
if (url.host() == chrome::kChromeUIFlagsHost) if (url.host() == chrome::kChromeUIFlagsHost)
return &NewWebUI<FlagsUI>; return &NewWebUI<FlagsUI>;
if (url.host() == chrome::kChromeUIHistoryFrameHost) if (url.host() == chrome::kChromeUIHistoryFrameHost)
......
...@@ -2460,6 +2460,8 @@ ...@@ -2460,6 +2460,8 @@
'installer_util', 'installer_util',
'../components/components.gyp:autofill_content_risk_proto', '../components/components.gyp:autofill_content_risk_proto',
'../components/component_strings.gyp:component_strings', '../components/component_strings.gyp:component_strings',
'../components/components.gyp:dom_distiller_core',
'../components/components.gyp:dom_distiller_webui',
'../device/bluetooth/bluetooth.gyp:device_bluetooth', '../device/bluetooth/bluetooth.gyp:device_bluetooth',
'../media/media.gyp:media', '../media/media.gyp:media',
'../net/net.gyp:net_with_v8', '../net/net.gyp:net_with_v8',
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
'conditions': [ 'conditions': [
['OS != "ios"', { ['OS != "ios"', {
'pak_inputs': [ 'pak_inputs': [
'<(SHARED_INTERMEDIATE_DIR)/components/dom_distiller_resources.pak',
'<(SHARED_INTERMEDIATE_DIR)/content/browser/tracing/tracing_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/content/browser/tracing/tracing_resources.pak',
'<(SHARED_INTERMEDIATE_DIR)/content/content_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/content/content_resources.pak',
'<(SHARED_INTERMEDIATE_DIR)/webkit/blink_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/webkit/blink_resources.pak',
......
...@@ -573,6 +573,9 @@ const char kEnableDevToolsExperiments[] = "enable-devtools-experiments"; ...@@ -573,6 +573,9 @@ const char kEnableDevToolsExperiments[] = "enable-devtools-experiments";
// opt in to "Use web service to resolve navigation errors".) // opt in to "Use web service to resolve navigation errors".)
const char kEnableDnsProbes[] = "enable-dns-probes"; const char kEnableDnsProbes[] = "enable-dns-probes";
// Enables the DOM distiller.
const char kEnableDomDistiller[] = "enable-dom-distiller";
// Enables extensions to be easily installed from sites other than the web // Enables extensions to be easily installed from sites other than the web
// store. Without this flag, they can still be installed, but must be manually // store. Without this flag, they can still be installed, but must be manually
// dragged onto chrome://extensions/. // dragged onto chrome://extensions/.
......
...@@ -171,6 +171,7 @@ extern const char kEnableComponentCloudPolicy[]; ...@@ -171,6 +171,7 @@ extern const char kEnableComponentCloudPolicy[];
extern const char kEnableContacts[]; extern const char kEnableContacts[];
extern const char kEnableDevToolsExperiments[]; extern const char kEnableDevToolsExperiments[];
extern const char kEnableDnsProbes[]; extern const char kEnableDnsProbes[];
extern const char kEnableDomDistiller[];
extern const char kEnableExtensionActivityLogging[]; extern const char kEnableExtensionActivityLogging[];
extern const char kEnableExtensionActivityLogTesting[]; extern const char kEnableExtensionActivityLogTesting[];
extern const char kEnableFastUnload[]; extern const char kEnableFastUnload[];
......
...@@ -8,6 +8,10 @@ per-file breakpad.gypi=jochen@chromium.org ...@@ -8,6 +8,10 @@ per-file breakpad.gypi=jochen@chromium.org
per-file breakpad.gypi=rsesek@chromium.org per-file breakpad.gypi=rsesek@chromium.org
per-file breakpad.gypi=thestig@chromium.org per-file breakpad.gypi=thestig@chromium.org
per-file dom_distiller*=bengr@chromium.org
per-file dom_distiller*=cjhopman@chromium.org
per-file dom_distiller*=nyquist@chromium.org
per-file json_schema.gypi=asargent@chromium.org per-file json_schema.gypi=asargent@chromium.org
per-file json_schema.gypi=calamity@chromium.org per-file json_schema.gypi=calamity@chromium.org
per-file json_schema.gypi=kalman@chromium.org per-file json_schema.gypi=kalman@chromium.org
......
...@@ -168,6 +168,7 @@ ...@@ -168,6 +168,7 @@
<release seq="1" allow_pseudo="false"> <release seq="1" allow_pseudo="false">
<messages fallback_to_english="true"> <messages fallback_to_english="true">
<part file="autofill_strings.grdp" /> <part file="autofill_strings.grdp" />
<part file="dom_distiller_strings.grdp" />
</messages> </messages>
</release> </release>
</grit> </grit>
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
'breakpad.gypi', 'breakpad.gypi',
'browser_context_keyed_service.gypi', 'browser_context_keyed_service.gypi',
'components_tests.gypi', 'components_tests.gypi',
'dom_distiller.gypi',
'json_schema.gypi', 'json_schema.gypi',
'navigation_interception.gypi', 'navigation_interception.gypi',
'policy.gypi', 'policy.gypi',
......
# 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.
{
'targets': [
{
'target_name': 'dom_distiller_core',
'type': 'static_library',
'include_dirs': [
'..',
],
'sources': [
'dom_distiller/core/dom_distiller_constants.cc',
'dom_distiller/core/dom_distiller_constants.h',
],
},
{
'target_name': 'dom_distiller_webui',
'type': 'static_library',
'dependencies': [
'component_strings.gyp:component_strings',
'dom_distiller_core',
'dom_distiller_resources',
'../base/base.gyp:base',
'../base/base.gyp:base',
'../content/content.gyp:content_browser',
'../skia/skia.gyp:skia',
],
'include_dirs': [
'..',
],
'sources': [
'dom_distiller/webui/dom_distiller_ui.cc',
'dom_distiller/webui/dom_distiller_ui.h',
'dom_distiller/webui/dom_distiller_handler.cc',
'dom_distiller/webui/dom_distiller_handler.h',
],
},
{
'target_name': 'dom_distiller_resources',
'type': 'none',
'variables': {
'grit_out_dir': '<(SHARED_INTERMEDIATE_DIR)/components',
},
'actions': [
{
'action_name': 'dom_distiller_resources',
'variables': {
'grit_grd_file': 'dom_distiller_resources.grd',
},
'includes': [ '../build/grit_action.gypi' ],
},
],
'includes': [ '../build/grit_target.gypi' ],
},
],
}
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
bengr@chromium.org
cjhopman@chromium.org
nyquist@chromium.org
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.
// 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
// 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_
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
// 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
// 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_
// 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
// 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_
/* 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;
}
<!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>
// 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);
<?xml version="1.0" encoding="UTF-8"?>
<grit latest_public_release="0" current_release="1">
<outputs>
<output filename="grit/dom_distiller_resources.h" type="rc_header">
<emit emit_type='prepend'></emit>
</output>
<output filename="dom_distiller_resources.pak" type="data_package" />
<output filename="dom_distiller_resources.rc" type="rc_all" />
</outputs>
<release seq="1">
<includes>
<include name="IDR_ABOUT_DOM_DISTILLER_HTML" file="dom_distiller/webui/resources/about_dom_distiller.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" />
<include name="IDR_ABOUT_DOM_DISTILLER_CSS" file="dom_distiller/webui/resources/about_dom_distiller.css" type="BINDATA" />
<include name="IDR_ABOUT_DOM_DISTILLER_JS" file="dom_distiller/webui/resources/about_dom_distiller.js" type="BINDATA" />
</includes>
</release>
</grit>
<?xml version="1.0" encoding="utf-8"?>
<grit-part>
<message name="IDS_DOM_DISTILLER_TITLE" desc="The title to show on the DOM Distiller debug page.">
DOM Distiller
</message>
</grit-part>
...@@ -214,6 +214,9 @@ ...@@ -214,6 +214,9 @@
"components/component_strings.grd": { "components/component_strings.grd": {
"messages": [30000], "messages": [30000],
}, },
"components/dom_distiller_resources.grd": {
"includes": [30250],
},
"third_party/WebKit/public/blink_resources.grd": { "third_party/WebKit/public/blink_resources.grd": {
"includes": [30500], "includes": [30500],
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment