Commit 71142d76 authored by beaudoin@chromium.org's avatar beaudoin@chromium.org

Discovery API supports specifying a tile in a URL.

BUG=none
TEST=none


Review URL: https://chromiumcodereview.appspot.com/10647003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149243 0039d316-1c4b-4281-b951-d872f2087c98
parent faf4c9bd
...@@ -34,11 +34,18 @@ bool DiscoverySuggestFunction::RunImpl() { ...@@ -34,11 +34,18 @@ bool DiscoverySuggestFunction::RunImpl() {
} }
} }
std::string empty;
const std::string* url_image = ∅
if (params->details.url_image != NULL)
url_image = params->details.url_image.get();
extensions::SuggestedLinksRegistry* registry = extensions::SuggestedLinksRegistry* registry =
extensions::SuggestedLinksRegistryFactory::GetForProfile(profile()); extensions::SuggestedLinksRegistryFactory::GetForProfile(profile());
scoped_ptr<extensions::SuggestedLink> suggested_link( scoped_ptr<extensions::SuggestedLink> suggested_link(
new extensions::SuggestedLink(params->details.link_url, new extensions::SuggestedLink(params->details.link_url,
params->details.link_text, score)); params->details.link_text,
*url_image,
score));
registry->Add(extension_id(), suggested_link.Pass()); registry->Add(extension_id(), suggested_link.Pass());
return true; return true;
} }
......
...@@ -8,9 +8,11 @@ namespace extensions { ...@@ -8,9 +8,11 @@ namespace extensions {
SuggestedLink::SuggestedLink(const std::string& link_url, SuggestedLink::SuggestedLink(const std::string& link_url,
const std::string& link_text, const std::string& link_text,
const std::string& url_image,
double score) double score)
: link_url_(link_url), : link_url_(link_url),
link_text_(link_text), link_text_(link_text),
url_image_(url_image),
score_(score) {} score_(score) {}
SuggestedLink::~SuggestedLink() {} SuggestedLink::~SuggestedLink() {}
......
...@@ -16,17 +16,19 @@ namespace extensions { ...@@ -16,17 +16,19 @@ namespace extensions {
// wants to inject in the NTP's recommended pane. // wants to inject in the NTP's recommended pane.
class SuggestedLink { class SuggestedLink {
public: public:
SuggestedLink(const std::string& link_url_, const std::string& link_text_, SuggestedLink(const std::string& link_url, const std::string& link_text,
double score); const std::string& url_image, double score);
~SuggestedLink(); ~SuggestedLink();
const std::string& link_url() const { return link_url_; } const std::string& link_url() const { return link_url_; }
const std::string& link_text() const { return link_text_; } const std::string& link_text() const { return link_text_; }
const std::string& url_image() const { return url_image_; }
double score() const { return score_; } double score() const { return score_; }
private: private:
std::string link_url_; std::string link_url_;
std::string link_text_; std::string link_text_;
std::string url_image_;
// |score_| is a value between 0 and 1 indicating the relative importance of // |score_| is a value between 0 and 1 indicating the relative importance of
// this suggested link. A link with score 1 is twice as likely to be presented // this suggested link. A link with score 1 is twice as likely to be presented
......
...@@ -109,7 +109,10 @@ cr.define('ntp', function() { ...@@ -109,7 +109,10 @@ cr.define('ntp', function() {
// Sets the tooltip. // Sets the tooltip.
this.title = data.title; this.title = data.title;
var thumbnailUrl = 'chrome://thumb/' + data.url; var thumbnailUrl;
thumbnailUrl = data.urlImage ? data.urlImage :
'chrome://thumb/' + data.url;
this.querySelector('.thumbnail').style.backgroundImage = this.querySelector('.thumbnail').style.backgroundImage =
url(thumbnailUrl); url(thumbnailUrl);
......
...@@ -76,6 +76,9 @@ void SuggestionsSourceDiscovery::FetchItems(Profile* profile) { ...@@ -76,6 +76,9 @@ void SuggestionsSourceDiscovery::FetchItems(Profile* profile) {
ASCIIToUTF16((*it)->link_text()), ASCIIToUTF16((*it)->link_text()),
GURL((*it)->link_url())); GURL((*it)->link_url()));
page_value->SetDouble("score", (*it)->score()); page_value->SetDouble("score", (*it)->score());
const std::string& url_image = (*it)->url_image();
if (url_image.length() > 0)
page_value->SetString("urlImage", url_image);
items_.push_back(page_value); items_.push_back(page_value);
} }
combiner_->OnItemsReady(); combiner_->OnItemsReady();
......
...@@ -14,6 +14,9 @@ namespace experimental.discovery { ...@@ -14,6 +14,9 @@ namespace experimental.discovery {
// The linkified text. It should be relatively short. // The linkified text. It should be relatively short.
DOMString linkText; DOMString linkText;
// The url of the image to use as a tile.
DOMString? urlImage;
// A score indicating how interesting that suggestion is. The value must be // A score indicating how interesting that suggestion is. The value must be
// between 0 and 1. A suggestion with score 1 is twice as likely to be // between 0 and 1. A suggestion with score 1 is twice as likely to be
// displayed than one with a score of 0.5. Defaults to 1. // displayed than one with a score of 0.5. Defaults to 1.
......
...@@ -445,6 +445,30 @@ ...@@ -445,6 +445,30 @@
<!-- OBJECT METHODS --> <!-- OBJECT METHODS -->
<!-- OBJECT EVENT FIELDS --> <!-- OBJECT EVENT FIELDS -->
<!-- FUNCTION PARAMETERS --> <!-- FUNCTION PARAMETERS -->
</div>
</div><div>
<div>
<dt>
<var>urlImage</var>
<em>
<!-- TYPE -->
<div style="display:inline">
(
<span class="optional">optional</span>
<span id="typeTemplate">
<span>
<span>string</span>
</span>
</span>
)
</div>
</em>
</dt>
<dd>The url of the image to use as a tile.</dd>
<!-- OBJECT PROPERTIES -->
<!-- OBJECT METHODS -->
<!-- OBJECT EVENT FIELDS -->
<!-- FUNCTION PARAMETERS -->
</div> </div>
</div> </div>
</dl> </dl>
......
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