Commit fb88d32c authored by Dan Harrington's avatar Dan Harrington Committed by Commit Bot

Remove zine internals page

Bug: 1069183
Change-Id: I6bbcb5857c798faabd164e7b08523d05ec7aecdf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2414916
Commit-Queue: Dan H <harringtond@chromium.org>
Reviewed-by: default avatarEsmael Elmoslimany <aee@chromium.org>
Reviewed-by: default avatarCarlos Knippschild <carlosk@chromium.org>
Reviewed-by: default avatarMike West <mkwst@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809436}
parent c4fc2bb1
...@@ -1423,8 +1423,6 @@ ...@@ -1423,8 +1423,6 @@
'chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/|'\ 'chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/|'\
'chrome/browser/android/ntp/ntp_snippets|'\ 'chrome/browser/android/ntp/ntp_snippets|'\
'chrome/browser/ntp_snippets/|'\ 'chrome/browser/ntp_snippets/|'\
'chrome/browser/resources/snippets_internals|'\
'chrome/browser/ui/webui/snippets_internals|'\
'components/ntp_snippets/|'\ 'components/ntp_snippets/|'\
'chrome/android/java/res/layout/new_tab_page|'\ 'chrome/android/java/res/layout/new_tab_page|'\
'chrome/android/java/res/layout/most_visited|'\ 'chrome/android/java/res/layout/most_visited|'\
......
...@@ -3118,7 +3118,6 @@ static_library("browser") { ...@@ -3118,7 +3118,6 @@ static_library("browser") {
"//chrome/browser/share/android:jni_headers", "//chrome/browser/share/android:jni_headers",
"//chrome/browser/tab:jni_headers", "//chrome/browser/tab:jni_headers",
"//chrome/browser/ui/webui/explore_sites_internals:mojo_bindings", "//chrome/browser/ui/webui/explore_sites_internals:mojo_bindings",
"//chrome/browser/ui/webui/snippets_internals:mojo_bindings",
"//chrome/browser/updates", "//chrome/browser/updates",
"//chrome/browser/updates:factory", "//chrome/browser/updates:factory",
"//chrome/browser/video_tutorials/internal", "//chrome/browser/video_tutorials/internal",
...@@ -6319,10 +6318,7 @@ grit("dev_ui_browser_resources") { ...@@ -6319,10 +6318,7 @@ grit("dev_ui_browser_resources") {
"//chrome/browser/ui/webui/interventions_internals:mojo_bindings_js", "//chrome/browser/ui/webui/interventions_internals:mojo_bindings_js",
] ]
if (is_android) { if (is_android) {
deps += [ deps += [ "//chrome/browser/ui/webui/feed_internals:mojo_bindings_js" ]
"//chrome/browser/ui/webui/feed_internals:mojo_bindings_js",
"//chrome/browser/ui/webui/snippets_internals:mojo_bindings_js",
]
} }
} }
......
...@@ -95,8 +95,6 @@ ...@@ -95,8 +95,6 @@
#include "chrome/browser/offline_pages/android/offline_page_auto_fetcher.h" #include "chrome/browser/offline_pages/android/offline_page_auto_fetcher.h"
#include "chrome/browser/ui/webui/explore_sites_internals/explore_sites_internals.mojom.h" #include "chrome/browser/ui/webui/explore_sites_internals/explore_sites_internals.mojom.h"
#include "chrome/browser/ui/webui/explore_sites_internals/explore_sites_internals_ui.h" #include "chrome/browser/ui/webui/explore_sites_internals/explore_sites_internals_ui.h"
#include "chrome/browser/ui/webui/snippets_internals/snippets_internals.mojom.h"
#include "chrome/browser/ui/webui/snippets_internals/snippets_internals_ui.h"
#include "chrome/common/offline_page_auto_fetcher.mojom.h" #include "chrome/common/offline_page_auto_fetcher.mojom.h"
#include "components/contextual_search/content/browser/contextual_search_js_api_service_impl.h" #include "components/contextual_search/content/browser/contextual_search_js_api_service_impl.h"
#include "components/contextual_search/content/common/mojom/contextual_search_js_api_service.mojom.h" #include "components/contextual_search/content/common/mojom/contextual_search_js_api_service.mojom.h"
...@@ -597,9 +595,6 @@ void PopulateChromeWebUIFrameBinders( ...@@ -597,9 +595,6 @@ void PopulateChromeWebUIFrameBinders(
RegisterWebUIControllerInterfaceBinder< RegisterWebUIControllerInterfaceBinder<
explore_sites_internals::mojom::PageHandler, explore_sites_internals::mojom::PageHandler,
explore_sites::ExploreSitesInternalsUI>(map); explore_sites::ExploreSitesInternalsUI>(map);
RegisterWebUIControllerInterfaceBinder<
snippets_internals::mojom::PageHandlerFactory, SnippetsInternalsUI>(map);
#else #else
RegisterWebUIControllerInterfaceBinder<downloads::mojom::PageHandlerFactory, RegisterWebUIControllerInterfaceBinder<downloads::mojom::PageHandlerFactory,
DownloadsUI>(map); DownloadsUI>(map);
......
...@@ -81,10 +81,6 @@ This file specifies browser resources for developer-facing chrome:// pages ...@@ -81,10 +81,6 @@ This file specifies browser resources for developer-facing chrome:// pages
<include name="IDR_QUERY_TILES_INTERNALS_HTML" file="resources\internals\query_tiles\query_tiles_internals.html" type="BINDATA" /> <include name="IDR_QUERY_TILES_INTERNALS_HTML" file="resources\internals\query_tiles\query_tiles_internals.html" type="BINDATA" />
<include name="IDR_QUERY_TILES_INTERNALS_JS" file="resources\internals\query_tiles\query_tiles_internals.js" type="BINDATA" /> <include name="IDR_QUERY_TILES_INTERNALS_JS" file="resources\internals\query_tiles\query_tiles_internals.js" type="BINDATA" />
<include name="IDR_QUERY_TILES_INTERNALS_BROWSER_PROXY_JS" file="resources\internals\query_tiles\query_tiles_internals_browser_proxy.js" type="BINDATA" /> <include name="IDR_QUERY_TILES_INTERNALS_BROWSER_PROXY_JS" file="resources\internals\query_tiles\query_tiles_internals_browser_proxy.js" type="BINDATA" />
<include name="IDR_SNIPPETS_INTERNALS_HTML" file="resources\snippets_internals\snippets_internals.html" allowexternalscript="true" type="BINDATA" />
<include name="IDR_SNIPPETS_INTERNALS_CSS" file="resources\snippets_internals\snippets_internals.css" type="BINDATA" />
<include name="IDR_SNIPPETS_INTERNALS_JS" file="resources\snippets_internals\snippets_internals.js" type="BINDATA" />
<include name="IDR_SNIPPETS_INTERNALS_MOJOM_LITE_JS" file="${root_gen_dir}\chrome\browser\ui\webui\snippets_internals\snippets_internals.mojom-lite.js" use_base_dir="false" type="BINDATA" />
</if> </if>
<if expr="enable_supervised_users"> <if expr="enable_supervised_users">
......
...@@ -87,7 +87,6 @@ if (enable_js_type_check) { ...@@ -87,7 +87,6 @@ if (enable_js_type_check) {
"internals/notifications:closure_compile", "internals/notifications:closure_compile",
"internals/query_tiles:closure_compile", "internals/query_tiles:closure_compile",
"offline_pages:closure_compile", "offline_pages:closure_compile",
"snippets_internals:closure_compile",
"video_tutorials:closure_compile", "video_tutorials:closure_compile",
"webapks:closure_compile", "webapks:closure_compile",
] ]
......
...@@ -2,6 +2,5 @@ file://ui/webui/PLATFORM_OWNERS ...@@ -2,6 +2,5 @@ file://ui/webui/PLATFORM_OWNERS
per-file component_extension_resources.grd=dgozman@chromium.org per-file component_extension_resources.grd=dgozman@chromium.org
per-file profile_signin_confirmation*=achuith@chromium.org per-file profile_signin_confirmation*=achuith@chromium.org
per-file snippets_internals*=file://components/ntp_snippets/OWNERS
# COMPONENT: UI # COMPONENT: UI
# Copyright 2018 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.
import("//third_party/closure_compiler/compile_js.gni")
js_type_check("closure_compile") {
deps = [ ":snippets_internals" ]
}
js_library("snippets_internals") {
deps = [
"//chrome/browser/ui/webui/snippets_internals:mojo_bindings_js_library_for_compile",
"//third_party/jstemplate:jstemplate",
"//ui/webui/resources/js:util",
]
}
file://components/ntp_snippets/OWNERS
\ No newline at end of file
/* Copyright 2016 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 {
font-size: 20px;
}
#info > div {
width: 100%;
}
#info h2 {
color: rgb(74, 142, 230);
font-size: 100%;
margin-bottom: 0.3em;
margin-top: 1em;
}
.section-details {
width: 100%;
}
.section-details > tbody > tr:nth-child(odd) {
background: rgb(239, 243, 255);
}
.section-details .detail,
.section-details .value {
width: 50%;
}
td.title-link {
padding-bottom: 0.5em;
padding-top: 0.5em;
}
.expiry {
color: gray;
font-size: 80%;
}
.date {
white-space: nowrap;
}
.url {
display: inline-block;
font-size: 80%;
word-break: break-all;
}
.snippet-detail {
font-size: 90%;
}
.hidden {
display: none;
}
.detail {
color: gray;
font-weight: normal;
}
.forms {
margin-top: 0.3em;
}
#submit-clear {
margin-bottom: 0.5em;
}
#last-json-text {
border: 1px solid black;
color: gray;
font-size: 90%;
padding: 4px;
word-break: break-all;
}
button {
display: block;
min-height: 30px;
}
.vertical-buttons > button {
display: inline-block;
float: left;
margin-right: 5px;
max-width: 100px;
min-height: 40px;
}
#contextual-suggestions-section input {
box-sizing: border-box;
display: block;
width: 100%;
}
<!--
Copyright 2016 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.
-->
<!doctype html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Snippets Internals</title>
<link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
<link rel="stylesheet" href="snippets_internals.css">
<script src="chrome://resources/js/cr.js"></script>
<script src="chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js"></script>
<script src="chrome://resources/js/jstemplate_compiled.js"></script>
<script src="chrome://resources/js/util.js"></script>
<script src="snippets_internals.mojom-lite.js"></script>
<script src="snippets_internals.js"></script>
</head>
<body id="info">
<!-- Top level properties table. -->
<div>
<h2>Properties</h2>
<table class="section-details">
<tr>
<td class="name">Article Suggestions enabled</td>
<td id="flag-article-suggestions" class="value"></td>
</tr>
<tr>
<td class="name">Offlining Recent Tabs enabled</td>
<td id="flag-offlining-recent-pages-feature" class="value"></td>
</tr>
<tr>
<td class="name">Snippets fetch URL</td>
<td id="switch-fetch-url" class="value"></td>
</tr>
<tr>
<td class="name">Server-provided experiment IDs</td>
<td id="experiment-ids" class="value"></td>
</tr>
</table>
</div>
<!-- User classifier table with clear classification button.-->
<div>
<h2>User Classifier</h2>
<table class="section-details">
<tr>
<td class="name">User class</td>
<td id="user-class" class="value"></td>
</tr>
<tr>
<td class="name">Estimated average time to open NTP</td>
<td id="avg-time-to-open-ntp" class="value"></td>
</tr>
<tr>
<td class="name">Estimated average time to show suggestions</td>
<td id="avg-time-to-show" class="value"></td>
</tr>
<tr>
<td class="name">Estimated average time to use suggestions</td>
<td id="avg-time-to-use" class="value"></td>
</tr>
</table>
<button id="clear-classification">
Clear my classification
</button>
</div>
<!-- Category ranker table, populated dynamically. -->
<div>
<!-- Template cloned and populated by js. -->
<template id="category-ranker-row">
<tr>
<td class="name"></td>
<td class="value"></td>
</tr>
</template>
<h2>Category Ranker</h2>
<table class="section-details">
<tbody id="category-ranker-table"></tbody>
</table>
</div>
<div>
<h2>Content Suggestions Service Actions</h2>
<div class="forms">
<button id="reload-suggestions">Reload suggestions</button>
<button id="clear-cached-suggestions">
Clear cached suggestions
</button>
</div>
</div>
<div id="remote-content-suggestions">
<h2>Remote content suggestions</h2>
<table class="section-details">
<tr>
<td class="name">Last Fetch Status</td>
<td id="remote-status" class="value"></td>
</tr>
<tr>
<td class="name">Last Fetch Type</td>
<td id="remote-authenticated" class="value"></td>
</tr>
<tr>
<td class="name">Last Background Fetch Time:</td>
<td id="last-background-fetch-time" class="value"></td>
</tr>
</table>
<button id="background-fetch-button">
Fetch remote suggestions in the background in 2 seconds
</button>
<button id="last-json-button">Show the last JSON</button>
<div id="last-json-container" class="hidden">
<div id="last-json-text"></div>
<button id="last-json-dump">Dump the last JSON</button>
</div>
</div>
<div id="content-suggestions">
<h2>Content suggestions by category
<span class="detail">(click for details)</span>
<button id="submit-dump">Dump the list</button>
</h2>
<div jsselect="categories" style="display:none">
<div>
<h3 style="margin-bottom: 0px; padding-bottom: 0px;">
<span jscontent="categoryTitle"></span>
<span class="detail">
(id = <span jscontent="categoryId"></span>,
<span jscontent="status"></span>)
</span>
</h3>
</div>
<div class="vertical-buttons">
<button jsvalues="data-category-id:categoryId"
class="toggle-dismissed-suggestions">
Show dismissed suggestions
</button>
<button jsvalues="data-category-id:categoryId"
class="submit-clear-dismissed-suggestions">
Clear dismissed suggestions
</button>
</div>
<!-- Suggestions -->
<table class="section-details">
<tr jsselect="suggestions" style="display:none">
<td class="title-link">
<span class="hidden-toggler content-suggestion-title"
jsvalues="hidden-id:suggestionId">
<span jscontent="suggestionTitle"></span>&gt;&gt;
</span>
<div jsvalues="id:suggestionId" class="content-suggestion-detail hidden">
<table>
<tr>
<td>ID</td>
<td jscontent="suggestionIdWithinCategory"></td>
</tr>
<tr>
<td>URL</td>
<td><a class="url" jsvalues="href:url" jscontent="url"></a></td>
</tr>
<tr>
<td>URL with favicon</td>
<td>
<a class="url" jsvalues="href:faviconUrl"
jscontent="faviconUrl"></a>
</td>
</tr>
<tr>
<td>Snippet text</td>
<td jscontent="snippet"></td>
</tr>
<tr>
<td>Publish date</td>
<td class="expiry"></td>
<span class="date" jscontent="publishDate"></span>
</td>
</tr>
<tr>
<td>Publisher name</td>
<td jscontent="publisherName"></td>
</tr>
<tr>
<td>Score</td>
<td jscontent="score"></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<!-- Dismissed suggestions -->
<table jsvalues="id: 'dismissed-category-' + categoryId"
class="section-details hidden">
<thead>
<tr>
<th style="text-align:left">Dismissed suggestions
</thead>
<tr jsselect="dismissedSuggestions" style="display:none">
<td class="title-link">
<span class="hidden-toggler content-suggestion-title"
jsvalues="hidden-id:suggestionId">
<span jscontent="suggestionTitle"></span> (dismissed)&gt;&gt;
</span>
<div jsvalues="id:suggestionId" class="content-suggestion-detail hidden">
<table>
<tr>
<td>ID</td>
<td jscontent="suggestionIdWithinCategory"></td>
</tr>
<tr>
<td>URL</td>
<td><a class="url" jsvalues="href:url" jscontent="url"></a></td>
</tr>
<tr>
<td>Snippet text</td>
<td jscontent="snippet"></td>
</tr>
<tr>
<td>Publish date</td>
<td class="expiry">
<span class="date" jscontent="publishDate"></span>
</td>
</tr>
<tr>
<td>Publisher name</td>
<td jscontent="publisherName"></td>
</tr>
<tr>
<td>Score</td>
<td jscontent="score"></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
<div class="detail" id="content-suggestions-empty"></div>
</div>
</body>
// Copyright 2018 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.
'use strict';
/** @type {snippetsInternals.mojom.PageHandlerRemote} */
let pageHandler = null;
/** @type {snippetsInternals.mojom.PageInterface} */
let page = null;
/* Javascript module for chrome://snippets-internals. */
(function() {
/* Utility functions*/
/**
* Sets all the properties contained in the mapping in the page.
* property map {id -> value}.
* @param {!Object<string,string>} propertyMap Property name to value mapping.
*/
function setPropertiesInPage(propertyMap) {
Object.keys(propertyMap).forEach(function(field) {
setPropertyInPage(field, propertyMap[field]);
});
}
/**
* Sets the given value as textContent for the given field.
* @param {string} field Id of the element to set the property on.
* @param {string} value Property to be set in the page.
*/
function setPropertyInPage(field, value) {
$(field).textContent = value;
}
/**
* Downloads the given data under filename with the given datatype.
* Acceptable values for data type include: text/plain, application/json, etc.
* @param {string} fileName Name of the file to download.
* @param {string} dataType The content-type to download.
* @param {string} data The data to download.
*/
function downloadData(fileName, dataType, data) {
let dataToReport = data;
if (data === '') {
dataToReport = 'None';
}
const link = document.createElement('a');
link.download = fileName;
link.href = 'data:' + dataType + ',' + encodeURI(dataToReport);
link.click();
}
/**
* Wrapper funciton for downloadData that stringifies json.
* @param {string} fileName Name of file to download.
* @param {string} data JSON data to download.
*/
function downloadJson(fileName, data) {
downloadData(fileName, 'application/json', data);
}
/**
* Clears children of the given domId.
* @param {string} domId Id of the DOM element to be cleared.
*/
function clearChildrenForId(domId) {
const parent = $(domId);
while (parent.firstChild) {
parent.removeChild(parent.firstChild);
}
}
/* Page functions, as the elements appear of the page. */
function updateGeneralProperties() {
pageHandler.getGeneralProperties().then(
response => setPropertiesInPage(response.properties));
}
function getUserClassifierProperties() {
pageHandler.getUserClassifierProperties().then(
response => setPropertiesInPage(response.properties));
}
function getCategoryRankerProperties() {
pageHandler.getCategoryRankerProperties().then(function(response) {
const domId = 'category-ranker-table';
clearChildrenForId(domId);
const table = $(domId);
const rowTemplate = $('category-ranker-row');
Object.keys(response.properties).forEach(function(field) {
const row = document.importNode(rowTemplate.content, true);
const td = row.querySelectorAll('td');
td[0].textContent = field;
td[1].textContent = response.properties[field];
table.appendChild(row);
});
});
}
/* Retrieve the remote content suggestions properties. */
function getRemoteContentSuggestionsProperties() {
pageHandler.getRemoteContentSuggestionsProperties().then(function(response) {
setPropertiesInPage(response.properties);
});
}
/* Retrieve suggestions, ordered by category. */
function getSuggestionsByCategory() {
pageHandler.getSuggestionsByCategory().then(function(response) {
const domId = 'content-suggestions';
const toggleClass = 'hidden-toggler';
jstProcess(new JsEvalContext(response), $(domId));
let text;
let display;
if (response.categories.length > 0) {
text = '';
display = 'inline';
} else {
text = 'The list is empty.';
display = 'none';
}
const emptyNode = $(`${domId}-empty`);
if (emptyNode) {
emptyNode.textContent = text;
}
const clearNode = $(`${domId}-clear`);
if (clearNode) {
clearNode.style.display = display;
}
// Toggle visibility for suggestions.
const links = document.getElementsByClassName(toggleClass);
for (const link of links) {
link.onclick = function(event) {
const id = event.currentTarget.getAttribute('hidden-id');
$(id).classList.toggle('hidden');
};
}
// Clear dismissed suggestions.
const clearDismissedButtons =
document.getElementsByClassName('submit-clear-dismissed-suggestions');
for (const button of clearDismissedButtons) {
button.onclick = function(event) {
// This is an attribute set on the elements.
const id = parseInt(event.currentTarget.dataset.categoryId, 10);
// Clear the suggestions and hide the table.
pageHandler.clearDismissedSuggestions(id);
const table = $('dismissed-category-' + id);
table.classList.add('hidden');
// Reload the data.
getSuggestionsByCategory();
};
}
// Toggle viewing dismissed suggestions.
const toggleDismissedButtons =
document.getElementsByClassName('toggle-dismissed-suggestions');
for (const button of toggleDismissedButtons) {
button.onclick = function(event) {
// This is an attribute set on the elements.
const id = parseInt(event.currentTarget.dataset.categoryId, 10);
const table = $('dismissed-category-' + id);
table.classList.toggle('hidden');
};
}
});
}
/* Wrapper functions for setting up page. */
/* Refresh data. */
function refreshContent() {
updateGeneralProperties();
getUserClassifierProperties();
getCategoryRankerProperties();
getRemoteContentSuggestionsProperties();
}
/* Setup buttons and other event listeners. */
function setupEventListeners() {
$('clear-classification').addEventListener('click', function(event) {
pageHandler.clearUserClassifierProperties();
});
$('reload-suggestions').addEventListener('click', function(event) {
pageHandler.reloadSuggestions();
});
$('clear-cached-suggestions').addEventListener('click', function(event) {
pageHandler.clearCachedSuggestions();
});
$('background-fetch-button').addEventListener('click', function(event) {
$('background-fetch-button').disabled = true;
pageHandler.fetchSuggestionsInBackground(2).then(function(response) {
$('background-fetch-button').disabled = false;
$('last-json-container').classList.add('hidden');
$('last-json-button').textContent = 'Show the last JSON';
// After we've fetched, update the page.
getRemoteContentSuggestionsProperties();
});
});
$('last-json-button').addEventListener('click', function(event) {
pageHandler.getLastJson().then(function(response) {
const container = $('last-json-container');
container.classList.toggle('hidden');
$('last-json-text').textContent = response.json;
$('last-json-button').textContent =
container.classList.contains('hidden') ? 'Show the last JSON' :
'Hide the last JSON';
});
});
$('last-json-dump').addEventListener('click', function(event) {
pageHandler.getLastJson().then(function(response) {
downloadJson('last_snippets.json', response.json);
});
});
$('submit-dump').addEventListener('click', function(event) {
pageHandler.getSuggestionsByCategory().then(function(response) {
downloadJson('snippets.json', JSON.stringify(response.categories));
});
});
window.addEventListener('focus', getSuggestionsByCategory);
}
/* Represents the js-side of the IPC link. Backend talks to this. */
/** @implements {snippetsInternals.mojom.PageInterface} */
class SnippetsInternalsPageImpl {
constructor() {
this.receiver_ = new snippetsInternals.mojom.PageReceiver(this);
}
/**
* @return {!snippetsInternals.mojom.PageRemote}
*/
bindNewPipeAndPassRemote() {
return this.receiver_.$.bindNewPipeAndPassRemote();
}
/* Callback for when suggestions change on the backend. */
onSuggestionsChanged() {
getSuggestionsByCategory();
}
}
/* Main entry point. */
document.addEventListener('DOMContentLoaded', function() {
// Setup frontend mojo.
page = new SnippetsInternalsPageImpl();
// Setup backend mojo.
const pageHandlerFactory =
snippetsInternals.mojom.PageHandlerFactory.getRemote();
// Give backend mojo a reference to frontend mojo.
pageHandlerFactory.createPageHandler(page.bindNewPipeAndPassRemote())
.then((response) => {
pageHandler = response.handler;
// Populate value fields.
refreshContent();
getSuggestionsByCategory();
setInterval(refreshContent, 2000);
// Setup events.
setupEventListeners();
});
});
}());
...@@ -608,7 +608,6 @@ static_library("ui") { ...@@ -608,7 +608,6 @@ static_library("ui") {
"//chrome/app:chromium_strings", "//chrome/app:chromium_strings",
"//chrome/browser/notifications/scheduler/public", "//chrome/browser/notifications/scheduler/public",
"//chrome/browser/ui/webui/explore_sites_internals:mojo_bindings", "//chrome/browser/ui/webui/explore_sites_internals:mojo_bindings",
"//chrome/browser/ui/webui/snippets_internals:mojo_bindings",
"//components/browser_ui/util/android", "//components/browser_ui/util/android",
"//components/query_tiles", "//components/query_tiles",
"//components/security_state/content/android", "//components/security_state/content/android",
...@@ -781,10 +780,6 @@ static_library("ui") { ...@@ -781,10 +780,6 @@ static_library("ui") {
"webui/offline/offline_internals_ui.h", "webui/offline/offline_internals_ui.h",
"webui/offline/offline_internals_ui_message_handler.cc", "webui/offline/offline_internals_ui_message_handler.cc",
"webui/offline/offline_internals_ui_message_handler.h", "webui/offline/offline_internals_ui_message_handler.h",
"webui/snippets_internals/snippets_internals_page_handler.cc",
"webui/snippets_internals/snippets_internals_page_handler.h",
"webui/snippets_internals/snippets_internals_ui.cc",
"webui/snippets_internals/snippets_internals_ui.h",
"webui/video_tutorials/video_player_source.cc", "webui/video_tutorials/video_player_source.cc",
"webui/video_tutorials/video_player_source.h", "webui/video_tutorials/video_player_source.h",
"webui/webapks_handler.cc", "webui/webapks_handler.cc",
......
...@@ -20,8 +20,6 @@ per-file ntp_tiles_internals_ui.*=file://components/ntp_tiles/OWNERS ...@@ -20,8 +20,6 @@ per-file ntp_tiles_internals_ui.*=file://components/ntp_tiles/OWNERS
per-file signin_internals_ui*=achuith@chromium.org per-file signin_internals_ui*=achuith@chromium.org
per-file snippets_internals*=file://components/ntp_snippets/OWNERS
per-file sync_internals*=file://components/sync/OWNERS per-file sync_internals*=file://components/sync/OWNERS
per-file invalidations_message_handler.*=file://components/invalidation/OWNERS per-file invalidations_message_handler.*=file://components/invalidation/OWNERS
......
...@@ -120,7 +120,6 @@ ...@@ -120,7 +120,6 @@
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "chrome/browser/ui/webui/explore_sites_internals/explore_sites_internals_ui.h" #include "chrome/browser/ui/webui/explore_sites_internals/explore_sites_internals_ui.h"
#include "chrome/browser/ui/webui/offline/offline_internals_ui.h" #include "chrome/browser/ui/webui/offline/offline_internals_ui.h"
#include "chrome/browser/ui/webui/snippets_internals/snippets_internals_ui.h"
#include "chrome/browser/ui/webui/webapks_ui.h" #include "chrome/browser/ui/webui/webapks_ui.h"
#include "components/feed/buildflags.h" #include "components/feed/buildflags.h"
#include "components/feed/feed_feature_list.h" #include "components/feed/feed_feature_list.h"
...@@ -755,13 +754,9 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, ...@@ -755,13 +754,9 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
return &NewWebUI<OfflineInternalsUI>; return &NewWebUI<OfflineInternalsUI>;
if (url.host_piece() == chrome::kChromeUISnippetsInternalsHost && if (url.host_piece() == chrome::kChromeUISnippetsInternalsHost &&
!profile->IsOffTheRecord()) { !profile->IsOffTheRecord()) {
if (!base::FeatureList::IsEnabled(feed::kInterestFeedContentSuggestions)) { if (base::FeatureList::IsEnabled(feed::kInterestFeedContentSuggestions)) {
return &NewWebUI<SnippetsInternalsUI>;
} else {
#if BUILDFLAG(ENABLE_FEED_IN_CHROME) #if BUILDFLAG(ENABLE_FEED_IN_CHROME)
return &NewWebUI<FeedInternalsUI>; return &NewWebUI<FeedInternalsUI>;
#else
return nullptr;
#endif // BUILDFLAG(ENABLE_FEED_IN_CHROME) #endif // BUILDFLAG(ENABLE_FEED_IN_CHROME)
} }
} }
......
# Copyright 2018 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.
import("//mojo/public/tools/bindings/mojom.gni")
mojom("mojo_bindings") {
sources = [ "snippets_internals.mojom" ]
}
file://components/ntp_snippets/OWNERS
per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS
\ No newline at end of file
// Copyright 2018 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.
module snippets_internals.mojom;
struct SuggestionCategory {
int64 categoryId;
string categoryTitle;
string status;
array<SuggestionItem> suggestions;
array<SuggestionItem> dismissedSuggestions;
};
struct SuggestionItem {
string suggestionTitle;
string suggestionId;
string suggestionIdWithinCategory;
string url;
string faviconUrl;
string snippet;
string publishDate;
string publisherName;
float score;
};
interface PageHandlerFactory {
CreatePageHandler(pending_remote<Page> page) =>
(pending_remote<PageHandler> handler);
};
// Browser interface.
interface PageHandler {
// Populate properties about preferences/flags.
GetGeneralProperties() => (map<string, string> properties);
// Populate the properties for the user classifier.
GetUserClassifierProperties() => (map<string, string> properties);
// Clear stored properties for the user classifier.
ClearUserClassifierProperties();
// Get category ranker tuples (abritrary field/values).
GetCategoryRankerProperties() => (map<string, string> properties);
// Reload the current suggestions.
ReloadSuggestions();
// Clear cached suggestions.
ClearCachedSuggestions();
// Get the remote content suggestions.
GetRemoteContentSuggestionsProperties() => (map<string, string> properties);
// Fetch suggestions in background after the given delay.
FetchSuggestionsInBackground(int64 delaySeconds) => ();
// Download the last suggestions in json form.
GetLastJson() => (string json);
// Get the suggestions by category.
GetSuggestionsByCategory() => (array<SuggestionCategory> categories);
// Clear the dismissed suggestions.
ClearDismissedSuggestions(int64 category);
};
// Frontend interface.
interface Page {
OnSuggestionsChanged();
};
// Copyright 2018 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 CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_SNIPPETS_INTERNALS_PAGE_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_SNIPPETS_INTERNALS_PAGE_HANDLER_H_
#include <map>
#include <vector>
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "base/timer/timer.h"
#include "chrome/browser/ui/webui/snippets_internals/snippets_internals.mojom.h"
#include "components/ntp_snippets/content_suggestions_service.h"
#include "components/ntp_snippets/remote/remote_suggestions_provider.h"
#include "components/prefs/pref_service.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
// TODO: Write tests for this.
class SnippetsInternalsPageHandler
: public snippets_internals::mojom::PageHandler,
public ntp_snippets::ContentSuggestionsService::Observer {
public:
explicit SnippetsInternalsPageHandler(
mojo::PendingReceiver<snippets_internals::mojom::PageHandler> receiver,
mojo::PendingRemote<snippets_internals::mojom::Page> page,
ntp_snippets::ContentSuggestionsService* content_suggestions_service,
PrefService* pref_service);
~SnippetsInternalsPageHandler() override;
// snippets_internals::mojom::PageHandler
void GetGeneralProperties(GetGeneralPropertiesCallback) override;
void GetUserClassifierProperties(
GetUserClassifierPropertiesCallback) override;
void ClearUserClassifierProperties() override;
void GetCategoryRankerProperties(
GetCategoryRankerPropertiesCallback) override;
void ReloadSuggestions() override;
void ClearCachedSuggestions() override;
void GetRemoteContentSuggestionsProperties(
GetRemoteContentSuggestionsPropertiesCallback) override;
void FetchSuggestionsInBackground(
int64_t,
FetchSuggestionsInBackgroundCallback) override;
void GetLastJson(GetLastJsonCallback) override;
void GetSuggestionsByCategory(GetSuggestionsByCategoryCallback) override;
void ClearDismissedSuggestions(int64_t) override;
private:
// ntp_snippets::ContentSuggestionsService::Observer:
void OnNewSuggestions(ntp_snippets::Category category) override;
void OnCategoryStatusChanged(
ntp_snippets::Category category,
ntp_snippets::CategoryStatus new_status) override;
void OnSuggestionInvalidated(
const ntp_snippets::ContentSuggestion::ID& suggestion_id) override;
void OnFullRefreshRequired() override;
void ContentSuggestionsServiceShutdown() override;
void FetchSuggestionsInBackgroundImpl(FetchSuggestionsInBackgroundCallback);
void GetSuggestionsByCategoryImpl(GetSuggestionsByCategoryCallback);
// Misc. methods.
void CollectDismissedSuggestions(
int last_index,
GetSuggestionsByCategoryCallback callback,
std::vector<ntp_snippets::ContentSuggestion> suggestions);
// Receiver from the mojo interface to concrete impl.
mojo::Receiver<snippets_internals::mojom::PageHandler> receiver_;
// Observer to notify frontend of dirty data.
ScopedObserver<ntp_snippets::ContentSuggestionsService,
ntp_snippets::ContentSuggestionsService::Observer>
content_suggestions_service_observer_;
// Services that provide the data & functionality.
ntp_snippets::ContentSuggestionsService* content_suggestions_service_;
ntp_snippets::RemoteSuggestionsProvider* remote_suggestions_provider_;
PrefService* pref_service_;
// Store dismissed suggestions in an instance variable during aggregation
std::map<ntp_snippets::Category,
std::vector<ntp_snippets::ContentSuggestion>,
ntp_snippets::Category::CompareByID>
dismissed_suggestions_;
// Timers to delay actions.
base::OneShotTimer suggestion_fetch_timer_;
// Handle back to the page by which we can update.
mojo::Remote<snippets_internals::mojom::Page> page_;
base::WeakPtrFactory<SnippetsInternalsPageHandler> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(SnippetsInternalsPageHandler);
};
#endif // CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_SNIPPETS_INTERNALS_PAGE_HANDLER_H_
// Copyright 2016 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 "chrome/browser/ui/webui/snippets_internals/snippets_internals_ui.h"
#include <memory>
#include <utility>
#include "base/bind.h"
#include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/snippets_internals/snippets_internals.mojom.h"
#include "chrome/browser/ui/webui/snippets_internals/snippets_internals_page_handler.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/dev_ui_browser_resources.h"
#include "content/public/browser/web_ui_data_source.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/network/public/mojom/content_security_policy.mojom.h"
#if defined(OS_ANDROID)
#include "chrome/browser/flags/android/chrome_feature_list.h"
#endif
SnippetsInternalsUI::SnippetsInternalsUI(content::WebUI* web_ui)
: ui::MojoWebUIController(web_ui) {
content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUISnippetsInternalsHost);
source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ScriptSrc,
"script-src chrome://resources 'self' 'unsafe-eval';");
source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::TrustedTypes,
"trusted-types jstemplate;");
source->AddResourcePath("snippets_internals.css", IDR_SNIPPETS_INTERNALS_CSS);
source->AddResourcePath("snippets_internals.js", IDR_SNIPPETS_INTERNALS_JS);
source->AddResourcePath("snippets_internals.mojom-lite.js",
IDR_SNIPPETS_INTERNALS_MOJOM_LITE_JS);
source->SetDefaultResource(IDR_SNIPPETS_INTERNALS_HTML);
Profile* profile = Profile::FromWebUI(web_ui);
content_suggestions_service_ =
ContentSuggestionsServiceFactory::GetInstance()->GetForProfile(profile);
pref_service_ = profile->GetPrefs();
content::WebUIDataSource::Add(profile, source);
}
WEB_UI_CONTROLLER_TYPE_IMPL(SnippetsInternalsUI)
SnippetsInternalsUI::~SnippetsInternalsUI() {}
void SnippetsInternalsUI::BindInterface(
mojo::PendingReceiver<snippets_internals::mojom::PageHandlerFactory>
receiver) {
receiver_.reset();
receiver_.Bind(std::move(receiver));
}
void SnippetsInternalsUI::CreatePageHandler(
mojo::PendingRemote<snippets_internals::mojom::Page> page,
CreatePageHandlerCallback callback) {
DCHECK(page);
mojo::PendingRemote<snippets_internals::mojom::PageHandler> handler;
page_handler_ = std::make_unique<SnippetsInternalsPageHandler>(
handler.InitWithNewPipeAndPassReceiver(), std::move(page),
content_suggestions_service_, pref_service_);
std::move(callback).Run(std::move(handler));
}
// Copyright 2016 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 CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_SNIPPETS_INTERNALS_UI_H_
#define CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_SNIPPETS_INTERNALS_UI_H_
#include "base/macros.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/snippets_internals/snippets_internals.mojom.h"
#include "components/ntp_snippets/content_suggestions_service.h"
#include "components/prefs/pref_service.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "ui/webui/mojo_web_ui_controller.h"
class SnippetsInternalsPageHandler;
// The implementation for the chrome://snippets-internals page.
class SnippetsInternalsUI
: public snippets_internals::mojom::PageHandlerFactory,
public ui::MojoWebUIController {
public:
explicit SnippetsInternalsUI(content::WebUI* web_ui);
~SnippetsInternalsUI() override;
void CreatePageHandler(
mojo::PendingRemote<snippets_internals::mojom::Page> page,
CreatePageHandlerCallback callback) override;
// Instantiates the implementor of the mojom::PageHandlerFactory mojo
// interface passing the pending receiver that will be internally bound.
void BindInterface(
mojo::PendingReceiver<snippets_internals::mojom::PageHandlerFactory>
receiver);
private:
std::unique_ptr<SnippetsInternalsPageHandler> page_handler_;
ntp_snippets::ContentSuggestionsService* content_suggestions_service_;
PrefService* pref_service_;
// Receiver from the mojo interface to concrete impl.
mojo::Receiver<snippets_internals::mojom::PageHandlerFactory> receiver_{this};
WEB_UI_CONTROLLER_TYPE_DECL();
DISALLOW_COPY_AND_ASSIGN(SnippetsInternalsUI);
};
#endif // CHROME_BROWSER_UI_WEBUI_SNIPPETS_INTERNALS_SNIPPETS_INTERNALS_UI_H_
...@@ -238,7 +238,14 @@ void FeedOfflineHost::OnGetKnownContentDone( ...@@ -238,7 +238,14 @@ void FeedOfflineHost::OnGetKnownContentDone(
void FeedOfflineHost::GetCurrentArticleSuggestions( void FeedOfflineHost::GetCurrentArticleSuggestions(
SuggestionsProvider::SuggestionCallback suggestions_callback) { SuggestionsProvider::SuggestionCallback suggestions_callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!trigger_get_known_content_.is_null());
// This function is used by the internals page, which doesn't wait for
// initialization to complete. Just give up in this exceptional case.
if (!trigger_get_known_content_) {
std::move(suggestions_callback).Run({});
return;
}
pending_known_content_callbacks_.emplace_back( pending_known_content_callbacks_.emplace_back(
std::move(suggestions_callback)); std::move(suggestions_callback));
// Trigger after push_back() in case triggering results in a synchronous // Trigger after push_back() in case triggering results in a synchronous
......
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