diff options
26 files changed, 388 insertions, 0 deletions
diff --git a/chrome/browser/ui/webui/DEPS b/chrome/browser/ui/webui/DEPS index 6461fcc..7a5531e 100644 --- a/chrome/browser/ui/webui/DEPS +++ b/chrome/browser/ui/webui/DEPS @@ -9,4 +9,8 @@ include_rules = [ "+device/bluetooth", "+third_party/angle", # For ANGLE version. "+third_party/zlib/zlib.h", # For compression level constants. + + # DOM Distiller. + "+components/dom_distiller/core", + "+components/dom_distiller/webui", ] diff --git a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc index 6d2018e..cb3075c 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc @@ -55,6 +55,8 @@ #include "chrome/common/extensions/feature_switch.h" #include "chrome/common/pref_names.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_ui.h" #include "content/public/common/content_client.h" @@ -237,6 +239,11 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, return &NewWebUI<LocalDiscoveryUI>; } #endif + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableDomDistiller) && + url.host() == dom_distiller::kChromeUIDomDistillerHost) { + return &NewWebUI<dom_distiller::DomDistillerUI>; + } if (url.host() == chrome::kChromeUIFlagsHost) return &NewWebUI<FlagsUI>; if (url.host() == chrome::kChromeUIHistoryFrameHost) diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index 9d4593e..ebc4228 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -2460,6 +2460,8 @@ 'installer_util', '../components/components.gyp:autofill_content_risk_proto', '../components/component_strings.gyp:component_strings', + '../components/components.gyp:dom_distiller_core', + '../components/components.gyp:dom_distiller_webui', '../device/bluetooth/bluetooth.gyp:device_bluetooth', '../media/media.gyp:media', '../net/net.gyp:net_with_v8', diff --git a/chrome/chrome_repack_resources.gypi b/chrome/chrome_repack_resources.gypi index 7480c2d..f442cd2 100644 --- a/chrome/chrome_repack_resources.gypi +++ b/chrome/chrome_repack_resources.gypi @@ -19,6 +19,7 @@ 'conditions': [ ['OS != "ios"', { 'pak_inputs': [ + '<(SHARED_INTERMEDIATE_DIR)/components/dom_distiller_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/content/browser/tracing/tracing_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/content/content_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/webkit/blink_resources.pak', diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 4500f75..0c07489 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -573,6 +573,9 @@ const char kEnableDevToolsExperiments[] = "enable-devtools-experiments"; // opt in to "Use web service to resolve navigation errors".) 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 // store. Without this flag, they can still be installed, but must be manually // dragged onto chrome://extensions/. diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index fdb0d91..7ad8790 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -171,6 +171,7 @@ extern const char kEnableComponentCloudPolicy[]; extern const char kEnableContacts[]; extern const char kEnableDevToolsExperiments[]; extern const char kEnableDnsProbes[]; +extern const char kEnableDomDistiller[]; extern const char kEnableExtensionActivityLogging[]; extern const char kEnableExtensionActivityLogTesting[]; extern const char kEnableFastUnload[]; diff --git a/components/OWNERS b/components/OWNERS index 2c71d95..4c134eb 100644 --- a/components/OWNERS +++ b/components/OWNERS @@ -8,6 +8,10 @@ per-file breakpad.gypi=jochen@chromium.org per-file breakpad.gypi=rsesek@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=calamity@chromium.org per-file json_schema.gypi=kalman@chromium.org diff --git a/components/component_strings.grd b/components/component_strings.grd index 85b5d61..28e2a46 100644 --- a/components/component_strings.grd +++ b/components/component_strings.grd @@ -168,6 +168,7 @@ <release seq="1" allow_pseudo="false"> <messages fallback_to_english="true"> <part file="autofill_strings.grdp" /> + <part file="dom_distiller_strings.grdp" /> </messages> </release> </grit> diff --git a/components/components.gyp b/components/components.gyp index 02f190b..0bfe536 100644 --- a/components/components.gyp +++ b/components/components.gyp @@ -15,6 +15,7 @@ 'breakpad.gypi', 'browser_context_keyed_service.gypi', 'components_tests.gypi', + 'dom_distiller.gypi', 'json_schema.gypi', 'navigation_interception.gypi', 'policy.gypi', diff --git a/components/dom_distiller.gypi b/components/dom_distiller.gypi new file mode 100644 index 0000000..82d31af --- /dev/null +++ b/components/dom_distiller.gypi @@ -0,0 +1,58 @@ +# 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' ], + }, + ], +} 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); diff --git a/components/dom_distiller_resources.grd b/components/dom_distiller_resources.grd new file mode 100644 index 0000000..dd2a5f5 --- /dev/null +++ b/components/dom_distiller_resources.grd @@ -0,0 +1,17 @@ +<?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> diff --git a/components/dom_distiller_strings.grdp b/components/dom_distiller_strings.grdp new file mode 100644 index 0000000..3d81fae --- /dev/null +++ b/components/dom_distiller_strings.grdp @@ -0,0 +1,8 @@ +<?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> diff --git a/tools/gritsettings/resource_ids b/tools/gritsettings/resource_ids index 0e6b848..f02e9ec 100644 --- a/tools/gritsettings/resource_ids +++ b/tools/gritsettings/resource_ids @@ -214,6 +214,9 @@ "components/component_strings.grd": { "messages": [30000], }, + "components/dom_distiller_resources.grd": { + "includes": [30250], + }, "third_party/WebKit/public/blink_resources.grd": { "includes": [30500], }, |