OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 BLIMP_CLIENT_CORE_CONTENTS_NAVIGATION_FEATURE_H_ | |
6 #define BLIMP_CLIENT_CORE_CONTENTS_NAVIGATION_FEATURE_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 | |
11 #include "base/containers/small_map.h" | |
12 #include "base/macros.h" | |
13 #include "blimp/net/blimp_message_processor.h" | |
14 | |
15 class GURL; | |
16 class SkBitmap; | |
17 | |
18 namespace blimp { | |
19 namespace client { | |
20 | |
21 // Handles all incoming and outgoing protobuf messages of type | |
22 // RenderWidget::NAVIGATION. Delegates can be added to be notified of incoming | |
23 // messages. | |
24 class NavigationFeature : public BlimpMessageProcessor { | |
25 public: | |
26 // A delegate to be notified of specific navigation events related to a | |
27 // a particular tab. | |
28 class NavigationFeatureDelegate { | |
29 public: | |
30 virtual ~NavigationFeatureDelegate() {} | |
31 virtual void OnUrlChanged(int tab_id, const GURL& url) = 0; | |
32 virtual void OnFaviconChanged(int tab_id, const SkBitmap& favicon) = 0; | |
33 virtual void OnTitleChanged(int tab_id, const std::string& title) = 0; | |
34 virtual void OnLoadingChanged(int tab_id, bool loading) = 0; | |
35 virtual void OnPageLoadStatusUpdate(int tab_id, bool completed) = 0; | |
36 }; | |
37 | |
38 NavigationFeature(); | |
39 ~NavigationFeature() override; | |
40 | |
41 // Set the BlimpMessageProcessor that will be used to send | |
42 // BlimpMessage::NAVIGATION messages to the engine. | |
43 void set_outgoing_message_processor( | |
44 std::unique_ptr<BlimpMessageProcessor> processor); | |
45 | |
46 // Sets a NavigationMessageDelegate to be notified of all navigation messages | |
47 // for |tab_id| from the engine. | |
48 void SetDelegate(int tab_id, NavigationFeatureDelegate* delegate); | |
49 void RemoveDelegate(int tab_id); | |
50 | |
51 // Virtual for testing. | |
52 virtual void NavigateToUrlText(int tab_id, const std::string& url_text); | |
53 virtual void Reload(int tab_id); | |
54 virtual void GoForward(int tab_id); | |
55 virtual void GoBack(int tab_id); | |
56 | |
57 // BlimpMessageProcessor implementation. | |
58 void ProcessMessage(std::unique_ptr<BlimpMessage> message, | |
59 const net::CompletionCallback& callback) override; | |
60 | |
61 protected: | |
62 // Finds the NavigationFeatureDelegate for a |tab_id|, protected for unit | |
63 // tests. | |
64 NavigationFeatureDelegate* FindDelegate(const int tab_id); | |
65 | |
66 private: | |
67 base::SmallMap<std::map<int, NavigationFeatureDelegate*>> delegates_; | |
68 | |
69 // Used to send BlimpMessage::NAVIGATION messages to the engine. | |
70 std::unique_ptr<BlimpMessageProcessor> outgoing_message_processor_; | |
71 | |
72 DISALLOW_COPY_AND_ASSIGN(NavigationFeature); | |
73 }; | |
74 | |
75 } // namespace client | |
76 } // namespace blimp | |
77 | |
78 #endif // BLIMP_CLIENT_CORE_CONTENTS_NAVIGATION_FEATURE_H_ | |
OLD | NEW |