Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1058)

Unified Diff: chrome/browser/ui/webui/offline_internals_ui.cc

Issue 2172443004: [Offline Pages] Add network status, save request textbox, and offline url link to offline internals… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolve code review comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/offline_pages/offline_internals_browser_proxy.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/offline_internals_ui.cc
diff --git a/chrome/browser/ui/webui/offline_internals_ui.cc b/chrome/browser/ui/webui/offline_internals_ui.cc
index 93ed44994e32922e0c036e5ce4402044ad82cd50..3092a8e360d3465902290006a6f837b50d6fa871 100644
--- a/chrome/browser/ui/webui/offline_internals_ui.cc
+++ b/chrome/browser/ui/webui/offline_internals_ui.cc
@@ -19,16 +19,19 @@
#include "chrome/common/url_constants.h"
#include "components/offline_pages/background/request_coordinator.h"
#include "components/offline_pages/background/save_page_request.h"
+#include "components/offline_pages/client_namespace_constants.h"
#include "components/offline_pages/offline_page_model.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_controller.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "grit/browser_resources.h"
+#include "net/base/network_change_notifier.h"
namespace {
// Class acting as a controller of the chrome://offline-internals WebUI.
+// TODO(chili): Should split this file and move to webui/offline_internals/
class OfflineInternalsUIMessageHandler : public content::WebUIMessageHandler {
public:
OfflineInternalsUIMessageHandler();
@@ -62,6 +65,12 @@ class OfflineInternalsUIMessageHandler : public content::WebUIMessageHandler {
// Load whether logs are being recorded.
void HandleGetLoggingState(const base::ListValue* args);
+ // Adds a url to the background loader queue.
+ void HandleAddToRequestQueue(const base::ListValue* args);
+
+ // Load whether device is currently offline.
+ void HandleGetNetworkStatus(const base::ListValue* args);
+
// Callback for async GetAllPages calls.
void HandleStoredPagesCallback(
std::string callback_id,
@@ -197,7 +206,7 @@ void OfflineInternalsUIMessageHandler::HandleStoredPagesCallback(
offline_page->SetString("namespace", page.client_id.name_space);
offline_page->SetDouble("size", page.file_size);
offline_page->SetString("id", std::to_string(page.offline_id));
- offline_page->SetString("filePath", page.file_path.value());
+ offline_page->SetString("filePath", page.GetOfflineURL().spec());
offline_page->SetDouble("creationTime", page.creation_time.ToJsTime());
offline_page->SetDouble("lastAccessTime",
page.last_access_time.ToJsTime());
@@ -270,6 +279,17 @@ void OfflineInternalsUIMessageHandler::HandleSetRecordPageModel(
offline_page_model_->GetLogger()->SetIsLogging(should_record);
}
+void OfflineInternalsUIMessageHandler::HandleGetNetworkStatus(
+ const base::ListValue* args) {
+ const base::Value* callback_id;
+ CHECK(args->Get(0, &callback_id));
+
+ ResolveJavascriptCallback(
+ *callback_id,
+ base::StringValue(
+ net::NetworkChangeNotifier::IsOffline() ? "Offline" : "Online"));
+}
+
void OfflineInternalsUIMessageHandler::HandleSetRecordRequestQueue(
const base::ListValue* args) {
bool should_record;
@@ -308,6 +328,23 @@ void OfflineInternalsUIMessageHandler::HandleGetEventLogs(
ResolveJavascriptCallback(*callback_id, result);
}
+void OfflineInternalsUIMessageHandler::HandleAddToRequestQueue(
+ const base::ListValue* args) {
+ const base::Value* callback_id;
+ CHECK(args->Get(0, &callback_id));
+
+ std::string url;
+ CHECK(args->GetString(1, &url));
+
+ ResolveJavascriptCallback(
+ *callback_id,
+ base::FundamentalValue(
+ request_coordinator_->SavePageLater(
+ GURL(url),
+ offline_pages::ClientId(offline_pages::kAsyncNamespace,
+ std::to_string(std::rand())))));
dpapad 2016/07/22 01:24:49 std::to_string() is not currently allowed in the C
+}
+
void OfflineInternalsUIMessageHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"deleteAllPages",
@@ -341,6 +378,14 @@ void OfflineInternalsUIMessageHandler::RegisterMessages() {
"getLoggingState",
base::Bind(&OfflineInternalsUIMessageHandler::HandleGetLoggingState,
weak_ptr_factory_.GetWeakPtr()));
+ web_ui()->RegisterMessageCallback(
+ "addToRequestQueue",
+ base::Bind(&OfflineInternalsUIMessageHandler::HandleAddToRequestQueue,
+ weak_ptr_factory_.GetWeakPtr()));
+ web_ui()->RegisterMessageCallback(
+ "getNetworkStatus",
+ base::Bind(&OfflineInternalsUIMessageHandler::HandleGetNetworkStatus,
+ weak_ptr_factory_.GetWeakPtr()));
// Get the offline page model associated with this web ui.
Profile* profile = Profile::FromWebUI(web_ui());
« no previous file with comments | « chrome/browser/resources/offline_pages/offline_internals_browser_proxy.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698