Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 // Deletes all the pages in the store. | |
| 33 void DeleteAllPages(const base::ListValue* args); | |
| 34 | |
| 35 // Delete selected list of page ids from the store. | |
| 36 void DeleteSelectPages(const base::ListValue* args); | |
|
jianli
2016/05/25 00:17:17
nit: DeleteSelectedPages
chili
2016/05/25 02:14:48
Done.
| |
| 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::DeleteAllPages( | |
| 53 const base::ListValue* args) { | |
| 54 web_ui()->CallJavascriptFunction("offlineInternals.pagesDeleted"); | |
| 55 } | |
| 56 | |
| 57 void OfflineInternalsUIMessageHandler::DeleteSelectPages( | |
| 58 const base::ListValue* args) { | |
| 59 web_ui()->CallJavascriptFunction("offlineInternals.pagesDeleted"); | |
| 60 } | |
| 61 | |
| 62 void OfflineInternalsUIMessageHandler:: | |
| 63 | |
| 64 void | |
|
jianli
2016/05/25 00:17:17
Will this get compiled?
chili
2016/05/25 02:14:47
I just did a git cl format... seemed to have messe
| |
| 65 OfflineInternalsUIMessageHandler::GetOfflineInternalsInfo( | |
| 66 const base::ListValue* args) { | |
| 67 base::DictionaryValue results; | |
| 68 base::ListValue* pages = new base::ListValue(); | |
| 69 base::ListValue* queueItems = new base::ListValue(); | |
| 70 results.Set("AllPages", pages); | |
| 71 results.Set("Queue", queueItems); | |
| 72 | |
| 73 // Fake page | |
| 74 base::DictionaryValue* samplePage = new base::DictionaryValue(); | |
|
jianli
2016/05/25 00:17:17
Try not to land the CL with dummy code. You could
chili
2016/05/25 02:14:48
Acknowledged.
| |
| 75 pages->Append(samplePage); | |
| 76 samplePage->SetString("onlineUrl", "http://www.test.com"); | |
| 77 samplePage->SetString("internalUrl", "128438sdjklre"); | |
| 78 samplePage->SetString("namespace", "bookmark"); | |
| 79 samplePage->SetInteger("size", 300); | |
| 80 | |
| 81 // Fake queue | |
| 82 base::DictionaryValue* sampleQueueItem = new base::DictionaryValue(); | |
| 83 queueItems->Append(sampleQueueItem); | |
| 84 sampleQueueItem->SetString("onlineUrl", "http://www.google.com"); | |
| 85 sampleQueueItem->SetString("status", "pending"); | |
| 86 sampleQueueItem->SetString("creation time", "5:00:32AM"); | |
| 87 | |
| 88 web_ui()->CallJavascriptFunction("offlineInternals.setOfflineInternalsInfo", | |
| 89 results); | |
| 90 } | |
| 91 | |
| 92 void OfflineInternalsUIMessageHandler::RegisterMessages() { | |
| 93 web_ui()->RegisterMessageCallback( | |
| 94 "deleteAllPages", | |
| 95 base::Bind(&OfflineInternalsUIMessageHandler::DeleteAllPages, | |
| 96 weak_ptr_factory_.GetWeakPtr())); | |
| 97 web_ui()->RegisterMessageCallback( | |
| 98 "deleteSelectPages", | |
| 99 base::Bind(&OfflineInternalsUIMessageHandler::DeleteSelectPages, | |
| 100 weak_ptr_factory_.GetWeakPtr())); | |
| 101 web_ui()->RegisterMessageCallback( | |
| 102 "getOfflineInternalsInfo", | |
| 103 base::Bind(&OfflineInternalsUIMessageHandler::GetOfflineInternalsInfo, | |
| 104 weak_ptr_factory_.GetWeakPtr())); | |
| 105 } | |
| 106 | |
| 107 } // namespace | |
| 108 | |
| 109 OfflineInternalsUI::OfflineInternalsUI(content::WebUI* web_ui) | |
| 110 : content::WebUIController(web_ui) { | |
| 111 // chrome://offline-internals source. | |
| 112 content::WebUIDataSource* html_source = | |
| 113 content::WebUIDataSource::Create(chrome::kChromeUIOfflineInternalsHost); | |
| 114 | |
| 115 // Required resources | |
|
jianli
2016/05/25 00:17:17
nit: end with period
chili
2016/05/25 02:14:48
Done.
| |
| 116 html_source->SetJsonPath("strings.js"); | |
| 117 html_source->AddResourcePath("offline_internals.css", | |
| 118 IDR_OFFLINE_INTERNALS_CSS); | |
| 119 html_source->AddResourcePath("offline_internals.js", | |
| 120 IDR_OFFLINE_INTERNALS_JS); | |
| 121 html_source->SetDefaultResource(IDR_OFFLINE_INTERNALS_HTML); | |
| 122 | |
| 123 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); | |
| 124 | |
| 125 web_ui->AddMessageHandler(new OfflineInternalsUIMessageHandler()); | |
| 126 } | |
| 127 | |
| 128 OfflineInternalsUI::~OfflineInternalsUI() {} | |
| OLD | NEW |