diff options
-rw-r--r-- | build/ios/grit_whitelist.txt | 6 | ||||
-rw-r--r-- | chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc | 26 | ||||
-rw-r--r-- | components/dom_distiller.gypi | 6 | ||||
-rw-r--r-- | components/dom_distiller/core/distiller.cc | 4 | ||||
-rw-r--r-- | components/dom_distiller/core/task_tracker.cc | 2 | ||||
-rw-r--r-- | components/dom_distiller/webui/dom_distiller_handler.cc | 61 | ||||
-rw-r--r-- | components/dom_distiller/webui/dom_distiller_handler.h | 32 | ||||
-rw-r--r-- | components/dom_distiller/webui/dom_distiller_ui.cc | 23 | ||||
-rw-r--r-- | components/dom_distiller/webui/dom_distiller_ui.h | 18 | ||||
-rw-r--r-- | components/dom_distiller/webui/resources/about_dom_distiller.css | 4 | ||||
-rw-r--r-- | components/dom_distiller/webui/resources/about_dom_distiller.html | 33 | ||||
-rw-r--r-- | components/dom_distiller/webui/resources/about_dom_distiller.js | 81 | ||||
-rw-r--r-- | components/dom_distiller_strings.grdp | 20 |
13 files changed, 252 insertions, 64 deletions
diff --git a/build/ios/grit_whitelist.txt b/build/ios/grit_whitelist.txt index 1eb4eac..b374986 100644 --- a/build/ios/grit_whitelist.txt +++ b/build/ios/grit_whitelist.txt @@ -246,6 +246,12 @@ IDS_DELETE IDS_DISABLE_TOUCH_ADJUSTMENT_DESCRIPTION IDS_DISABLE_TOUCH_ADJUSTMENT_NAME IDS_DOM_DISTILLER_TITLE +IDS_DOM_DISTILLER_WEBUI_ENTRY_ADD +IDS_DOM_DISTILLER_WEBUI_ENTRY_ADD_FAILED +IDS_DOM_DISTILLER_WEBUI_ENTRY_URL +IDS_DOM_DISTILLER_WEBUI_FETCHING_ENTRIES +IDS_DOM_DISTILLER_WEBUI_REFRESH +IDS_DOM_DISTILLER_WEBUI_TITLE IDS_DONE IDS_EDIT_FIND_MAC IDS_EMPTY_KEYWORD_VALUE 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 c20609c..fa712adb 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc @@ -11,6 +11,7 @@ #include "base/prefs/pref_service.h" #include "chrome/browser/about_flags.h" #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h" +#include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_web_ui.h" #include "chrome/browser/history/history_types.h" @@ -56,6 +57,7 @@ #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/core/dom_distiller_service.h" #include "components/dom_distiller/webui/dom_distiller_ui.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_ui.h" @@ -187,6 +189,21 @@ WebUIController* NewWebUI<chromeos::OobeUI>(WebUI* web_ui, const GURL& url) { } #endif +// Special cases for DOM distiller. +template<> +WebUIController* NewWebUI<dom_distiller::DomDistillerUi>(WebUI* web_ui, + const GURL& url) { + // The DomDistillerUi can not depend on components/dom_distiller/content, + // so inject the correct DomDistillerService from chrome/. + content::BrowserContext* browser_context = + web_ui->GetWebContents()->GetBrowserContext(); + dom_distiller::DomDistillerService* service = + dom_distiller::DomDistillerServiceFactory::GetForBrowserContext( + browser_context); + // TODO(nyquist): Add real scheme. + return new dom_distiller::DomDistillerUi(web_ui, service, "dummy"); +} + // Only create ExtensionWebUI for URLs that are allowed extension bindings, // hosted by actual tabs. bool NeedsExtensionWebUI(Profile* profile, const GURL& url) { @@ -246,10 +263,6 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, return &NewWebUI<LocalDiscoveryUI>; } #endif - if (IsEnableDomDistillerSet() && - url.host() == dom_distiller::kChromeUIDomDistillerHost) { - return &NewWebUI<dom_distiller::DomDistillerUI>; - } if (url.host() == chrome::kChromeUIFlagsHost) return &NewWebUI<FlagsUI>; if (url.host() == chrome::kChromeUIHistoryFrameHost) @@ -480,6 +493,11 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, return &NewWebUI<PrintPreviewUI>; #endif + if (IsEnableDomDistillerSet() && + url.host() == dom_distiller::kChromeUIDomDistillerHost) { + return &NewWebUI<dom_distiller::DomDistillerUi>; + } + return NULL; } diff --git a/components/dom_distiller.gypi b/components/dom_distiller.gypi index f3c695a..ddc7b2e 100644 --- a/components/dom_distiller.gypi +++ b/components/dom_distiller.gypi @@ -11,20 +11,22 @@ 'type': 'static_library', 'dependencies': [ 'component_strings.gyp:component_strings', + 'distilled_page_proto', 'dom_distiller_core', 'dom_distiller_resources', '../base/base.gyp:base', '../content/content.gyp:content_browser', '../skia/skia.gyp:skia', + '../sync/sync.gyp:sync', ], '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', + 'dom_distiller/webui/dom_distiller_ui.cc', + 'dom_distiller/webui/dom_distiller_ui.h', ], }, { diff --git a/components/dom_distiller/core/distiller.cc b/components/dom_distiller/core/distiller.cc index 7d044eb..84b8a05 100644 --- a/components/dom_distiller/core/distiller.cc +++ b/components/dom_distiller/core/distiller.cc @@ -30,8 +30,10 @@ DistillerFactoryImpl::DistillerFactoryImpl( DistillerFactoryImpl::~DistillerFactoryImpl() {} scoped_ptr<Distiller> DistillerFactoryImpl::CreateDistiller() { - return scoped_ptr<Distiller>(new DistillerImpl( + scoped_ptr<DistillerImpl> distiller(new DistillerImpl( *distiller_page_factory_, *distiller_url_fetcher_factory_)); + distiller->Init(); + return distiller.PassAs<Distiller>(); } DistillerImpl::DistillerImpl( diff --git a/components/dom_distiller/core/task_tracker.cc b/components/dom_distiller/core/task_tracker.cc index 5a6cd7c..ac06407 100644 --- a/components/dom_distiller/core/task_tracker.cc +++ b/components/dom_distiller/core/task_tracker.cc @@ -36,7 +36,7 @@ void TaskTracker::StartDistiller(DistillerFactory* factory) { GURL url(entry_.pages(0).url()); DCHECK(url.is_valid()); - distiller_ = factory->CreateDistiller().Pass(); + distiller_ = factory->CreateDistiller(); distiller_->DistillPage(url, base::Bind(&TaskTracker::OnDistilledDataReady, weak_ptr_factory_.GetWeakPtr())); diff --git a/components/dom_distiller/webui/dom_distiller_handler.cc b/components/dom_distiller/webui/dom_distiller_handler.cc index c05cc0d..6202de7 100644 --- a/components/dom_distiller/webui/dom_distiller_handler.cc +++ b/components/dom_distiller/webui/dom_distiller_handler.cc @@ -6,12 +6,18 @@ #include "base/bind.h" #include "base/values.h" +#include "components/dom_distiller/core/dom_distiller_service.h" +#include "components/dom_distiller/core/proto/distilled_page.pb.h" #include "content/public/browser/web_ui.h" +#include "url/gurl.h" namespace dom_distiller { -DomDistillerHandler::DomDistillerHandler() - : weak_ptr_factory_(this) { +DomDistillerHandler::DomDistillerHandler(DomDistillerService* service, + const std::string& scheme) + : weak_ptr_factory_(this), + service_(service) { + article_scheme_ = scheme; } DomDistillerHandler::~DomDistillerHandler() {} @@ -21,22 +27,49 @@ void DomDistillerHandler::RegisterMessages() { "requestEntries", base::Bind(&DomDistillerHandler::HandleRequestEntries, base::Unretained(this))); + web_ui()->RegisterMessageCallback( + "addArticle", + base::Bind(&DomDistillerHandler::HandleAddArticle, + base::Unretained(this))); + web_ui()->RegisterMessageCallback( + "selectArticle", + base::Bind(&DomDistillerHandler::HandleSelectArticle, + base::Unretained(this))); +} + +void DomDistillerHandler::HandleAddArticle(const ListValue* args) { + std::string url; + args->GetString(0, &url); + GURL gurl(url); + if (gurl.is_valid()) + service_->AddToList(gurl); + else + web_ui()->CallJavascriptFunction("domDistiller.onArticleAddFailed"); +} + +void DomDistillerHandler::HandleSelectArticle(const ListValue* args) { + std::string entry_id; + args->GetString(0, &entry_id); + + // TODO(nyquist): Do something here. } 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); + const std::vector<ArticleEntry>& entries_specifics = service_->GetEntries(); + for (std::vector<ArticleEntry>::const_iterator it = entries_specifics.begin(); + it != entries_specifics.end(); + ++it) { + const ArticleEntry& article = *it; + DCHECK(IsEntryValid(article)); + scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue()); + entry->SetString("entry_id", article.entry_id()); + std::string title = (!article.has_title() || article.title().empty()) ? + article.entry_id() : article.title(); + entry->SetString("title", title); + entries.Append(entry.release()); + } + web_ui()->CallJavascriptFunction("domDistiller.onReceivedEntries", entries); } } // namespace dom_distiller diff --git a/components/dom_distiller/webui/dom_distiller_handler.h b/components/dom_distiller/webui/dom_distiller_handler.h index 2af6d34..faf251c 100644 --- a/components/dom_distiller/webui/dom_distiller_handler.h +++ b/components/dom_distiller/webui/dom_distiller_handler.h @@ -5,31 +5,49 @@ #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 DomDistillerService; + +// Handler class for DOM Distiller list operations. class DomDistillerHandler : public content::WebUIMessageHandler { public: - DomDistillerHandler(); + // The lifetime of |service| has to outlive this handler. + DomDistillerHandler(DomDistillerService* service, + const std::string& scheme); 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); + // Callback from JavaScript for the "requestEntries" message. This + // requests the list of entries and returns it to the front end by calling + // "onReceivedEntries". There are no JavaScript arguments to this method. + void HandleRequestEntries(const ListValue* args); + + // Callback from JavaScript for when an article should be added. The first + // element in |args| should be a string representing the URL to be added. + void HandleAddArticle(const ListValue* args); + + // Callback from JavaScript for when an article is selected. The first element + // in |args| should be a string representing the ID of the entry to be + // selected. + void HandleSelectArticle(const ListValue* args); private: // Factory for the creating refs in callbacks. base::WeakPtrFactory<DomDistillerHandler> weak_ptr_factory_; + // The DomDistillerService. + DomDistillerService* service_; + + // The scheme for DOM distiller articles. + std::string article_scheme_; + DISALLOW_COPY_AND_ASSIGN(DomDistillerHandler); }; diff --git a/components/dom_distiller/webui/dom_distiller_ui.cc b/components/dom_distiller/webui/dom_distiller_ui.cc index e141843..807a6b3 100644 --- a/components/dom_distiller/webui/dom_distiller_ui.cc +++ b/components/dom_distiller/webui/dom_distiller_ui.cc @@ -5,6 +5,7 @@ #include "components/dom_distiller/webui/dom_distiller_ui.h" #include "components/dom_distiller/core/dom_distiller_constants.h" +#include "components/dom_distiller/core/dom_distiller_service.h" #include "components/dom_distiller/webui/dom_distiller_handler.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/web_contents.h" @@ -15,7 +16,9 @@ namespace dom_distiller { -DomDistillerUI::DomDistillerUI(content::WebUI* web_ui) +DomDistillerUi::DomDistillerUi(content::WebUI* web_ui, + DomDistillerService* service, + const std::string& scheme) : content::WebUIController(web_ui) { // Set up WebUIDataSource. content::WebUIDataSource* source = @@ -27,16 +30,28 @@ DomDistillerUI::DomDistillerUI(content::WebUI* web_ui) IDR_ABOUT_DOM_DISTILLER_JS); source->SetUseJsonJSFormatV2(); - source->AddLocalizedString("domDistillerTitle", IDS_DOM_DISTILLER_TITLE); + source->AddLocalizedString("domDistillerTitle", + IDS_DOM_DISTILLER_WEBUI_TITLE); + source->AddLocalizedString("addArticleUrl", + IDS_DOM_DISTILLER_WEBUI_ENTRY_URL); + source->AddLocalizedString("addArticleAddButtonLabel", + IDS_DOM_DISTILLER_WEBUI_ENTRY_ADD); + source->AddLocalizedString("addArticleFailedLabel", + IDS_DOM_DISTILLER_WEBUI_ENTRY_ADD_FAILED); + source->AddLocalizedString("loadingEntries", + IDS_DOM_DISTILLER_WEBUI_FETCHING_ENTRIES); + source->AddLocalizedString("refreshButtonLabel", + IDS_DOM_DISTILLER_WEBUI_REFRESH); + 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()); + web_ui->AddMessageHandler(new DomDistillerHandler(service, scheme)); } -DomDistillerUI::~DomDistillerUI() {} +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 index 1b9f1c2..12b14bf 100644 --- a/components/dom_distiller/webui/dom_distiller_ui.h +++ b/components/dom_distiller/webui/dom_distiller_ui.h @@ -2,21 +2,25 @@ // 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_H_ -#define COMPONENTS_DOM_DISTILLER_WEBUI_DOM_DISTILLER_H_ +#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 { +class DomDistillerService; + +// The WebUI controller for chrome://dom-distiller. +class DomDistillerUi : public content::WebUIController { public: - explicit DomDistillerUI(content::WebUI* web_ui); - virtual ~DomDistillerUI(); + DomDistillerUi(content::WebUI* web_ui, + DomDistillerService* service, + const std::string& scheme); + virtual ~DomDistillerUi(); private: - DISALLOW_COPY_AND_ASSIGN(DomDistillerUI); + DISALLOW_COPY_AND_ASSIGN(DomDistillerUi); }; } // namespace dom_distiller diff --git a/components/dom_distiller/webui/resources/about_dom_distiller.css b/components/dom_distiller/webui/resources/about_dom_distiller.css index 088136a..065ad72 100644 --- a/components/dom_distiller/webui/resources/about_dom_distiller.css +++ b/components/dom_distiller/webui/resources/about_dom_distiller.css @@ -6,3 +6,7 @@ a:visited { color: orange; } + +.hidden { + visibility: hidden; +} diff --git a/components/dom_distiller/webui/resources/about_dom_distiller.html b/components/dom_distiller/webui/resources/about_dom_distiller.html index 5674036..474868e 100644 --- a/components/dom_distiller/webui/resources/about_dom_distiller.html +++ b/components/dom_distiller/webui/resources/about_dom_distiller.html @@ -1,4 +1,9 @@ <!DOCTYPE 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. +--> <html> <head> <meta charset="utf-8"> @@ -18,11 +23,29 @@ <script src="strings.js"></script> </head> <body> - <header> - <h1 i18n-content="domDistillerTitle"></h1> - </header> - <div id="entries-section"> - <div id="entries-list"></div> + <div id="mainContent"> + <div id="list-section"> + <header> + <h1 id="listTitle" i18n-content="domDistillerTitle"></h1> + </header> + <div id="add-entry"> + <form> + <label for="article_url" i18n-content="addArticleUrl"></label> + <input type="text" id="article_url" /> + <br/> + <button id="addbutton" i18n-content="addArticleAddButtonLabel"></button> + </form> + <span id="add-entry-error" i18n-content="addArticleFailedLabel"></span> + </div> + <div id="update-list"> + <form> + <button id="refreshbutton" i18n-content="refreshButtonLabel"></button> + <span id="entries-list-loading" i18n-content="loadingEntries"></span> + </form> + </div> + <ul id="entries-list"> + </ul> + </div> </div> <script src="chrome://resources/js/i18n_template2.js"></script> <script src="chrome://resources/js/jstemplate_compiled.js"></script> diff --git a/components/dom_distiller/webui/resources/about_dom_distiller.js b/components/dom_distiller/webui/resources/about_dom_distiller.js index f558d7f..4a401a9 100644 --- a/components/dom_distiller/webui/resources/about_dom_distiller.js +++ b/components/dom_distiller/webui/resources/about_dom_distiller.js @@ -2,31 +2,76 @@ // 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'); +var domDistiller = { + /** + * 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. + */ + onReceivedEntries: function(entries) { + $('entries-list-loading').classList.add('hidden'); + if (!entries.length) $('entries-list').classList.add('hidden'); + + var list = $('entries-list'); + domDistiller.removeAllChildren(list); for (var i = 0; i < entries.length; i++) { var listItem = document.createElement('li'); var link = document.createElement('a'); + var entry_id = entries[i].entry_id; + link.setAttribute('id', 'entry-' + entry_id); + link.setAttribute('href', '#'); link.innerText = entries[i].title; - link.setAttribute('href', entries[i].url); + link.addEventListener('click', function(event) { + domDistiller.onSelectArticle(event.target.id.substr("entry-".length)); + }, true); listItem.appendChild(link); list.appendChild(listItem); } - $('entries-list').appendChild(list); - } -} + }, + + /** + * Callback from the backend when adding an article failed. + */ + onArticleAddFailed: function() { + $('add-entry-error').classList.remove('hidden'); + }, + + removeAllChildren: function(root) { + while(root.firstChild) { + root.removeChild(root.firstChild); + } + }, + + onAddArticle: function() { + $('add-entry-error').classList.add('hidden'); + var url = $('article_url').value; + chrome.send('addArticle', [url]); + }, + + onSelectArticle: function(articleId) { + chrome.send('selectArticle', [articleId]); + }, + + /* All the work we do on load. */ + onLoadWork: function() { + $('list-section').classList.remove('hidden'); + $('entries-list-loading').classList.add('hidden'); + $('add-entry-error').classList.add('hidden'); + + $('refreshbutton').addEventListener('click', function(event) { + domDistiller.onRequestEntries(); + }, false); + $('addbutton').addEventListener('click', function(event) { + domDistiller.onAddArticle(); + }, false); + domDistiller.onRequestEntries(); + }, -/* All the work we do on load. */ -function onLoadWork() { - chrome.send('requestEntries'); + onRequestEntries: function() { + $('entries-list-loading').classList.remove('hidden'); + chrome.send('requestEntries'); + }, } -document.addEventListener('DOMContentLoaded', onLoadWork); +document.addEventListener('DOMContentLoaded', domDistiller.onLoadWork); diff --git a/components/dom_distiller_strings.grdp b/components/dom_distiller_strings.grdp index 3d81fae..3c9dca7 100644 --- a/components/dom_distiller_strings.grdp +++ b/components/dom_distiller_strings.grdp @@ -1,8 +1,26 @@ <?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."> + <message name="IDS_DOM_DISTILLER_WEBUI_TITLE" desc="The title to show on the DOM Distiller debug page."> DOM Distiller </message> + <message name="IDS_DOM_DISTILLER_WEBUI_ENTRY_TITLE" desc="The label for the title of an entry on the DOM Distiller debug page."> + Title + </message> + <message name="IDS_DOM_DISTILLER_WEBUI_ENTRY_URL" desc="The label for the URL of an entry on the DOM Distiller debug page."> + URL + </message> + <message name="IDS_DOM_DISTILLER_WEBUI_ENTRY_ADD" desc="The label for for the button for adding a new entry on the DOM Distiller debug page."> + Add + </message> + <message name="IDS_DOM_DISTILLER_WEBUI_ENTRY_ADD_FAILED" desc="The label to show when adding an article failed on the DOM Distiller debug page."> + Failed to add article. + </message> + <message name="IDS_DOM_DISTILLER_WEBUI_REFRESH" desc="The label for the button for refreshing the list of entries on the DOM Distiller debug page."> + Refresh + </message> + <message name="IDS_DOM_DISTILLER_WEBUI_FETCHING_ENTRIES" desc="The text to show while fetching the list of entries on the DOM Distiller debug page."> + Fetching entries... + </message> </grit-part> |