Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_PHYSICAL_WEB_WEBUI_PHYSICAL_WEB_BASE_MESSAGE_HANDLER_H_ | 5 #ifndef COMPONENTS_PHYSICAL_WEB_WEBUI_PHYSICAL_WEB_BASE_MESSAGE_HANDLER_H_ |
| 6 #define COMPONENTS_PHYSICAL_WEB_WEBUI_PHYSICAL_WEB_BASE_MESSAGE_HANDLER_H_ | 6 #define COMPONENTS_PHYSICAL_WEB_WEBUI_PHYSICAL_WEB_BASE_MESSAGE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <unordered_map> | |
| 9 | |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "components/physical_web/data_source/physical_web_data_source.h" | |
| 14 #include "components/physical_web/data_source/physical_web_listener.h" | |
| 11 | 15 |
| 12 namespace physical_web { | 16 namespace physical_web { |
| 13 | 17 |
| 14 class PhysicalWebDataSource; | 18 class PhysicalWebDataSource; |
| 15 | 19 |
| 16 } // namespace physical_web | 20 } // namespace physical_web |
| 17 | 21 |
| 18 namespace physical_web_ui { | 22 namespace physical_web_ui { |
| 19 | 23 |
| 20 // This is the equivalent of content::WebUI::MessageCallback. | 24 // This is the equivalent of content::WebUI::MessageCallback. |
| 21 typedef base::Callback<void(const base::ListValue*)> MessageCallback; | 25 typedef base::Callback<void(const base::ListValue*)> MessageCallback; |
| 22 | 26 |
| 23 // The base handler for Javascript messages for the chrome://physical-web page. | 27 // The base handler for Javascript messages for the chrome://physical-web page. |
| 24 // This does not implement WebUIMessageHandler or register its methods. | 28 // This does not implement WebUIMessageHandler or register its methods. |
| 25 class PhysicalWebBaseMessageHandler { | 29 class PhysicalWebBaseMessageHandler : physical_web::PhysicalWebListener { |
| 26 public: | 30 public: |
| 27 PhysicalWebBaseMessageHandler(); | 31 PhysicalWebBaseMessageHandler(); |
| 28 virtual ~PhysicalWebBaseMessageHandler(); | 32 virtual ~PhysicalWebBaseMessageHandler(); |
| 29 | 33 |
| 30 // Handles the RequestNearbyURLs message, returning URLs that are currently | 34 // PhysicalWebListener |
| 31 // being broadcasted by Physical Web transports. | 35 void OnFound(const GURL& url) override; |
| 32 void HandleRequestNearbyURLs(const base::ListValue* args); | 36 void OnLost(const GURL& url) override; |
| 37 void OnDistanceChanged(const GURL& url, double distance_estimate) override; | |
| 38 | |
| 39 // Return URLs that are currently being broadcasted by Physical Web | |
| 40 // transports. | |
| 41 void ReturnNearbyURLs(const base::ListValue* args); | |
|
mmocny
2017/03/24 17:15:12
I think we don't need this ListValue* parameter an
Ran
2017/03/24 18:45:19
Done.
| |
| 33 | 42 |
| 34 // Handles a click on a Physical Web URL, recording the click and | 43 // Handles a click on a Physical Web URL, recording the click and |
| 35 // directing the user appropriately. | 44 // directing the user appropriately. |
| 36 void HandlePhysicalWebItemClicked(const base::ListValue* args); | 45 void HandlePhysicalWebItemClicked(const base::ListValue* args); |
| 37 | 46 |
| 38 // Registers the messages that this MessageHandler can handle. | 47 // Registers the messages that this MessageHandler can handle. |
| 39 void RegisterMessages(); | 48 void RegisterMessages(); |
| 40 | 49 |
| 41 protected: | 50 protected: |
| 42 // Subclasses should implement these protected methods as a pass through to | 51 // Subclasses should implement these protected methods as a pass through to |
| 43 // the similarly named methods of the appropriate WebUI object (the exact | 52 // the similarly named methods of the appropriate WebUI object (the exact |
| 44 // WebUI class differs per platform). | 53 // WebUI class differs per platform). |
| 45 virtual void RegisterMessageCallback( | 54 virtual void RegisterMessageCallback(const std::string& message, |
| 46 const std::string& message, | 55 const MessageCallback& callback) = 0; |
| 47 const MessageCallback& callback) = 0; | |
| 48 virtual void CallJavaScriptFunction(const std::string& function, | 56 virtual void CallJavaScriptFunction(const std::string& function, |
| 49 const base::Value& arg) = 0; | 57 const base::Value& arg) = 0; |
| 50 virtual physical_web::PhysicalWebDataSource* GetPhysicalWebDataSource() = 0; | 58 virtual physical_web::PhysicalWebDataSource* GetPhysicalWebDataSource() = 0; |
| 51 | 59 |
| 52 private: | 60 private: |
| 61 physical_web::PhysicalWebDataSource* data_source_; | |
| 62 std::vector<std::string> ordered_group_ids_; | |
| 63 std::unordered_map<std::string, physical_web::Metadata> metadata_map_; | |
| 64 | |
| 53 DISALLOW_COPY_AND_ASSIGN(PhysicalWebBaseMessageHandler); | 65 DISALLOW_COPY_AND_ASSIGN(PhysicalWebBaseMessageHandler); |
| 54 }; | 66 }; |
| 55 | 67 |
| 56 } // namespace physical_web_ui | 68 } // namespace physical_web_ui |
| 57 | 69 |
| 58 #endif // COMPONENTS_PHYSICAL_WEB_WEBUI_PHYSICAL_WEB_BASE_MESSAGE_HANDLER_H_ | 70 #endif // COMPONENTS_PHYSICAL_WEB_WEBUI_PHYSICAL_WEB_BASE_MESSAGE_HANDLER_H_ |
| OLD | NEW |