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

Side by Side Diff: components/ntp_tiles/webui/popular_sites_internals_message_handler.h

Issue 2457033003: Add chrome://popular-sites-internals/ to iOS. (Closed)
Patch Set: Minimize ios/content diff. Created 4 years, 1 month 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 #ifndef COMPONENTS_NTP_TILES_WEBUI_POPULAR_SITES_HANDLER_H_
6 #define COMPONENTS_NTP_TILES_WEBUI_POPULAR_SITES_HANDLER_H_
7
8 #include <memory>
9 #include <string>
10 #include <vector>
11
12 #include "base/callback_forward.h"
13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h"
15
16 class PrefService;
17
18 namespace base {
19 class Value;
20 class ListValue;
21 class SequencedWorkerPool;
22 } // namespace base
23
24 namespace ntp_tiles {
25
26 class PopularSites;
27 class PopularSitesInternalsMessageHandlerClient;
28
29 // Implements the WebUI message handler for chrome://popular-sites-internals/
30 //
31 // Because content and iOS use different implementations of WebUI, this class
32 // implements the generic portion and depends on the embedder to inject a bridge
33 // to the embedder's API. It cannot itself implement either API directly.
34 class PopularSitesInternalsMessageHandler {
35 public:
36 PopularSitesInternalsMessageHandler(
jochen (gone - plz use gerrit) 2016/11/02 10:53:34 explicit
sfiera 2016/11/02 13:30:19 Oops. Done, thanks.
37 PopularSitesInternalsMessageHandlerClient* web_ui);
38 ~PopularSitesInternalsMessageHandler();
39
40 // Called when the WebUI page's JavaScript has loaded and it is ready to
41 // receive RegisterMessageCallback() calls.
42 void RegisterMessages();
43
44 private:
45 // Callbacks registered in RegisterMessages().
46 void HandleRegisterForEvents(const base::ListValue* args);
47 void HandleUpdate(const base::ListValue* args);
48 void HandleViewJson(const base::ListValue* args);
49
50 void SendOverrides();
51 void SendDownloadResult(bool success);
52 void SendSites();
53 void SendJson(const std::string& json);
54
55 // Completion handler for popular_sites_->StartFetch().
56 void OnPopularSitesAvailable(bool explicit_request, bool success);
57
58 // Bridge to embedder's API.
59 PopularSitesInternalsMessageHandlerClient* web_ui_;
60
61 std::unique_ptr<PopularSites> popular_sites_;
62
63 base::WeakPtrFactory<PopularSitesInternalsMessageHandler> weak_ptr_factory_;
64
65 DISALLOW_COPY_AND_ASSIGN(PopularSitesInternalsMessageHandler);
66 };
67
68 // Implemented by embedders to hook up PopularSitesInternalsMessageHandler.
69 class PopularSitesInternalsMessageHandlerClient {
jochen (gone - plz use gerrit) 2016/11/02 10:53:34 can you move this into a separate header please?
sfiera 2016/11/02 13:30:19 Done.
70 public:
71 // Returns the blocking pool for hte embedder.
72 virtual base::SequencedWorkerPool* GetBlockingPool() = 0;
73
74 // Returns the PrefService for the embedder and containing WebUI page.
75 virtual PrefService* GetPrefs() = 0;
76
77 // Creates a new PopularSites based on the context pf the WebUI page.
78 virtual std::unique_ptr<ntp_tiles::PopularSites> MakePopularSites() = 0;
79
80 // Registers a callback in Javascript. See content::WebUI and web::WebUIIOS.
81 virtual void RegisterMessageCallback(
82 const std::string& message,
83 const base::Callback<void(const base::ListValue*)>& callback) = 0;
84
85 // Invokes a function in Javascript. See content::WebUI and web::WebUIIOS.
86 virtual void CallJavascriptFunctionVector(
87 const std::string& name,
88 const std::vector<const base::Value*>& values) = 0;
89
90 // Helper function for CallJavascriptFunctionVector().
91 template <typename... Arg>
92 void CallJavascriptFunction(const std::string& name, const Arg&... arg) {
93 CallJavascriptFunctionVector(name, {&arg...});
94 }
95
96 protected:
97 PopularSitesInternalsMessageHandlerClient();
98 virtual ~PopularSitesInternalsMessageHandlerClient();
99
100 private:
101 DISALLOW_COPY_AND_ASSIGN(PopularSitesInternalsMessageHandlerClient);
102 };
103
104 } // namespace ntp_tiles
105
106 #endif // COMPONENTS_NTP_TILES_WEBUI_POPULAR_SITES_HANDLER_H_
OLDNEW
« no previous file with comments | « components/ntp_tiles/DEPS ('k') | components/ntp_tiles/webui/popular_sites_internals_message_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698