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

Side by Side Diff: chrome/browser/ui/webui/offline_internals_ui.cc

Issue 2003883002: [Offline pages] Create offline internals page for Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/offline_internals_ui.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/macros.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/values.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/url_constants.h"
14 #include "content/public/browser/web_ui.h"
15 #include "content/public/browser/web_ui_controller.h"
16 #include "content/public/browser/web_ui_data_source.h"
17 #include "content/public/browser/web_ui_message_handler.h"
18 #include "grit/components_resources.h"
19
20 namespace {
21
22 // Class acting as a controller of the chrome://offline-internals WebUI.
23 class OfflineInternalsUIMessageHandler : public content::WebUIMessageHandler {
24 public:
25 OfflineInternalsUIMessageHandler();
26 ~OfflineInternalsUIMessageHandler() override;
27
28 // WebUIMessageHandler implementation.
29 void RegisterMessages() override;
30
31 private:
32 // Clears all the pages in the store.
33 void ClearPages(const base::ListValue* args);
34
35 // Clear selected list of page ids from the store.
36 void ClearSelectPages(const base::ListValue* args);
37
38 // Load all information.
39 void GetOfflineInternalsInfo(const base::ListValue* args);
40
41 // Factory for creating references in callbacks.
42 base::WeakPtrFactory<OfflineInternalsUIMessageHandler> weak_ptr_factory_;
43
44 DISALLOW_COPY_AND_ASSIGN(OfflineInternalsUIMessageHandler);
45 };
46
47 OfflineInternalsUIMessageHandler::OfflineInternalsUIMessageHandler()
48 : weak_ptr_factory_(this) {}
49
50 OfflineInternalsUIMessageHandler::~OfflineInternalsUIMessageHandler() {}
51
52 void OfflineInternalsUIMessageHandler::ClearPages(const base::ListValue* args) {
53 web_ui()->CallJavascriptFunction("offlineInternals.pagesCleared");
dewittj 2016/05/24 18:13:08 I don't know enough about WebUIMessageHandler to k
chili 2016/05/24 22:52:30 From what I gather, when the javascript says "call
54 }
55
56 void OfflineInternalsUIMessageHandler::ClearSelectPages(
57 const base::ListValue* args) {
58 web_ui()->CallJavascriptFunction("offlineInternals.pagesCleared");
59 }
60
61 void OfflineInternalsUIMessageHandler::GetOfflineInternalsInfo(
62 const base::ListValue* args) {
63 base::DictionaryValue results;
64 base::ListValue* pages = new base::ListValue();
65 base::ListValue* queueItems = new base::ListValue();
66 results.Set("AllPages", pages);
67 results.Set("Queue", queueItems);
68
69 // Fake page
70 base::DictionaryValue* samplePage = new base::DictionaryValue();
71 pages->Append(samplePage);
72 samplePage->SetString("onlineUrl", "http://www.test.com");
73 samplePage->SetString("internalUrl", "128438sdjklre");
74 samplePage->SetString("namespace", "bookmark");
75 samplePage->SetInteger("size", 300);
76
77 // Fake queue
78 base::DictionaryValue* sampleQueueItem = new base::DictionaryValue();
79 queueItems->Append(sampleQueueItem);
80 sampleQueueItem->SetString("onlineUrl", "http://www.google.com");
81 sampleQueueItem->SetString("status", "pending");
82 sampleQueueItem->SetString("creation time", "5:00:32AM");
83
84 web_ui()->CallJavascriptFunction("offlineInternals.setOfflineInternalsInfo",
85 results);
86 }
87
88 void OfflineInternalsUIMessageHandler::RegisterMessages() {
89 web_ui()->RegisterMessageCallback(
90 "clearPages", base::Bind(&OfflineInternalsUIMessageHandler::ClearPages,
91 weak_ptr_factory_.GetWeakPtr()));
92 web_ui()->RegisterMessageCallback(
93 "clearSelectPages",
94 base::Bind(&OfflineInternalsUIMessageHandler::ClearSelectPages,
95 weak_ptr_factory_.GetWeakPtr()));
96 web_ui()->RegisterMessageCallback(
97 "getOfflineInternalsInfo",
98 base::Bind(&OfflineInternalsUIMessageHandler::GetOfflineInternalsInfo,
99 weak_ptr_factory_.GetWeakPtr()));
100 }
101
102 } // namespace
103
104 OfflineInternalsUI::OfflineInternalsUI(content::WebUI* web_ui)
105 : content::WebUIController(web_ui) {
106 // chrome://offline-internals source.
107 content::WebUIDataSource* html_source =
108 content::WebUIDataSource::Create(chrome::kChromeUIOfflineInternalsHost);
109
110 // Required resources
111 html_source->SetJsonPath("strings.js");
112 html_source->AddResourcePath("offline_internals.css",
113 IDR_OFFLINE_INTERNALS_CSS);
114 html_source->AddResourcePath("offline_internals.js",
115 IDR_OFFLINE_INTERNALS_JS);
116 html_source->SetDefaultResource(IDR_OFFLINE_INTERNALS_HTML);
117
118 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source);
119
120 web_ui->AddMessageHandler(new OfflineInternalsUIMessageHandler());
121 }
122
123 OfflineInternalsUI::~OfflineInternalsUI() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698