Commit 23c9664f authored by ranj's avatar ranj Committed by Commit bot

Show a default URL icon instead of a broken image for urls with no icon.

BUG=682244

Review-Url: https://codereview.chromium.org/2717363003
Cr-Commit-Position: refs/heads/master@{#460648}
parent 528e9669
......@@ -20,8 +20,8 @@
namespace {
content::WebUIDataSource* CreatePhysicalWebHTMLSource() {
content::WebUIDataSource* source = content::WebUIDataSource::Create(
chrome::kChromeUIPhysicalWebHost);
content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUIPhysicalWebHost);
source->AddLocalizedString(physical_web_ui::kTitle,
IDS_PHYSICAL_WEB_UI_TITLE);
......@@ -33,6 +33,8 @@ content::WebUIDataSource* CreatePhysicalWebHTMLSource() {
source->AddResourcePath(physical_web_ui::kPhysicalWebCSS,
IDR_PHYSICAL_WEB_UI_CSS);
source->SetDefaultResource(IDR_PHYSICAL_WEB_UI_HTML);
source->AddResourcePath(physical_web_ui::kPhysicalWebLinkIcon,
IDR_PHYSICAL_WEB_UI_LINK_ICON);
return source;
}
......@@ -80,8 +82,7 @@ class PhysicalWebMessageHandler : public content::WebUIMessageHandler {
} // namespace
PhysicalWebUI::PhysicalWebUI(content::WebUI* web_ui)
: WebUIController(web_ui) {
PhysicalWebUI::PhysicalWebUI(content::WebUI* web_ui) : WebUIController(web_ui) {
content::WebUIDataSource::Add(Profile::FromWebUI(web_ui),
CreatePhysicalWebHTMLSource());
web_ui->AddMessageHandler(base::MakeUnique<PhysicalWebMessageHandler>());
......
......@@ -9,6 +9,7 @@ namespace physical_web_ui {
// Resource paths.
const char kPhysicalWebJS[] = "physical_web.js";
const char kPhysicalWebCSS[] = "physical_web.css";
const char kPhysicalWebLinkIcon[] = "ic_link_grey600_36dp.png";
// Message handlers.
const char kPhysicalWebPageLoaded[] = "physicalWebPageLoaded";
......
......@@ -11,6 +11,7 @@ namespace physical_web_ui {
// Must match the resource file names.
extern const char kPhysicalWebJS[];
extern const char kPhysicalWebCSS[];
extern const char kPhysicalWebLinkIcon[];
// Message handlers.
// Must match the constants used in the resource files.
......
......@@ -25,6 +25,8 @@ function renderTemplate(nearbyUrlsData) {
// This is the javascript code that processes the template:
jstProcess(new JsEvalContext(nearbyUrlsData), templateDiv);
assignImageLoadErrorHandlers();
let bodyContainer = $('body-container');
bodyContainer.hidden = false;
}
......@@ -41,4 +43,15 @@ function pushNearbyURLs(nearbyUrlsData) {
renderTemplate(nearbyUrlsData);
}
function assignImageLoadErrorHandlers() {
var pwIcons = document.querySelectorAll('.physicalWebIcon');
pwIcons.forEach(function(e) {
let img = e.getElementsByTagName('img')[0];
img.addEventListener('error', function() {
img.src =
'chrome://physical-web/ic_link_grey600_36dp.png';
});
});
}
document.addEventListener('DOMContentLoaded', physicalWebPageLoaded);
......@@ -3,4 +3,5 @@
<include name="IDR_PHYSICAL_WEB_UI_HTML" file="../physical_web/webui/resources/physical_web.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" />
<include name="IDR_PHYSICAL_WEB_UI_JS" file="../physical_web/webui/resources/physical_web.js" type="BINDATA" />
<include name="IDR_PHYSICAL_WEB_UI_CSS" file="../physical_web/webui/resources/physical_web.css" type="BINDATA" />
<include name="IDR_PHYSICAL_WEB_UI_LINK_ICON" file="../physical_web/resources/ic_link_grey600_36dp.png" type="BINDATA" />
</grit-part>
\ No newline at end of file
......@@ -35,6 +35,8 @@ web::WebUIIOSDataSource* CreatePhysicalWebUIDataSource() {
IDR_PHYSICAL_WEB_UI_JS);
html_source->AddResourcePath(physical_web_ui::kPhysicalWebCSS,
IDR_PHYSICAL_WEB_UI_CSS);
html_source->AddResourcePath(physical_web_ui::kPhysicalWebLinkIcon,
IDR_PHYSICAL_WEB_UI_LINK_ICON);
html_source->SetDefaultResource(IDR_PHYSICAL_WEB_UI_HTML);
return html_source;
}
......
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