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 #ifndef COMPONENTS_NTP_TILES_WEBUI_SITE_TILES_HANDLER_H_ | |
6 #define COMPONENTS_NTP_TILES_WEBUI_SITE_TILES_HANDLER_H_ | |
7 | |
8 #include <memory> | |
9 #include <string> | |
10 | |
11 #include "base/macros.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "components/ntp_tiles/most_visited_sites.h" | |
14 | |
15 namespace base { | |
16 class ListValue; | |
17 } // namespace base | |
18 | |
19 namespace ntp_tiles { | |
20 | |
21 class MostVisitedSites; | |
22 class SiteTilesInternalsMessageHandlerClient; | |
23 | |
24 // Implements the WebUI message handler for chrome://site-tiles-internals/ | |
25 // | |
26 // Because content and iOS use different implementations of WebUI, this class | |
27 // implements the generic portion and depends on the embedder to inject a bridge | |
28 // to the embedder's API. It cannot itself implement either API directly. | |
29 class SiteTilesInternalsMessageHandler : public MostVisitedSites::Observer { | |
Marc Treib
2016/12/08 15:41:50
I'm not entirely happy with the name, since it's n
sfiera
2016/12/08 16:44:35
If you were looking for the message handler for ch
| |
30 public: | |
31 explicit SiteTilesInternalsMessageHandler( | |
32 SiteTilesInternalsMessageHandlerClient* web_ui); | |
33 ~SiteTilesInternalsMessageHandler() override; | |
34 | |
35 // Called when the WebUI page's JavaScript has loaded and it is ready to | |
36 // receive RegisterMessageCallback() calls. | |
37 void RegisterMessages(); | |
38 | |
39 private: | |
40 // Callbacks registered in RegisterMessages(). | |
41 void HandleRegisterForEvents(const base::ListValue* args); | |
42 void HandleUpdate(const base::ListValue* args); | |
43 void HandleViewPopularSitesJson(const base::ListValue* args); | |
44 void HandleGetFavicon(const base::ListValue* args); | |
45 | |
46 void SendSourceInfo(); | |
47 void SendTiles(const NTPTilesVector& tiles); | |
48 void SendPopularSitesJson(const std::string& json); | |
49 | |
50 // MostVisitedSites::Observer. | |
51 void OnMostVisitedURLsAvailable(const NTPTilesVector& tiles) override; | |
52 void OnIconMadeAvailable(const GURL& site_url) override; | |
53 | |
54 // Bridge to embedder's API. | |
55 SiteTilesInternalsMessageHandlerClient* web_ui_; | |
Marc Treib
2016/12/08 15:41:50
|client_|? IMO web_ui_ is a bit confusing.
sfiera
2016/12/08 16:44:35
Done.
| |
56 | |
57 int site_count_; | |
58 std::unique_ptr<MostVisitedSites> most_visited_sites_; | |
59 | |
60 base::WeakPtrFactory<SiteTilesInternalsMessageHandler> weak_ptr_factory_; | |
61 | |
62 DISALLOW_COPY_AND_ASSIGN(SiteTilesInternalsMessageHandler); | |
63 }; | |
64 | |
65 } // namespace ntp_tiles | |
66 | |
67 #endif // COMPONENTS_NTP_TILES_WEBUI_SITE_TILES_HANDLER_H_ | |
OLD | NEW |