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 CHROME_BROWSER_UI_WEBUI_WUG_WEB_UI_VIEW_H_ | |
6 #define CHROME_BROWSER_UI_WEBUI_WUG_WEB_UI_VIEW_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/bind.h" | |
11 #include "base/containers/hash_tables.h" | |
12 #include "base/macros.h" | |
13 #include "base/memory/ref_counted_memory.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "components/login/base_screen_handler_utils.h" | |
16 #include "components/login/screens/screen_context.h" | |
17 #include "components/wug/export.h" | |
18 #include "components/wug/view.h" | |
19 #include "content/public/browser/web_ui.h" | |
20 #include "content/public/browser/web_ui_data_source.h" | |
21 | |
22 namespace base { | |
23 class DictionaryValue; | |
24 } | |
25 | |
26 namespace content { | |
27 class WebUI; | |
28 } | |
29 | |
30 namespace login { | |
31 class LocalizedValuesBuilder; | |
32 } | |
33 | |
34 namespace wug { | |
35 | |
36 using Context = login::ScreenContext; | |
37 | |
Nikita (slow)
2015/02/24 15:22:44
nit: Add comment
dzhioev (left Google)
2015/02/26 14:01:39
Done.
| |
38 class WUG_EXPORT WebUIView : public View { | |
39 public: | |
40 WebUIView(content::WebUI* web_ui, const std::string& id); | |
41 ~WebUIView() override; | |
42 | |
43 void SetUpDataSource(content::WebUIDataSource* data_source); | |
44 | |
45 // Overridden from View: | |
46 void Init() override; | |
47 | |
48 protected: | |
49 using ResourcesMap = | |
Nikita (slow)
2015/02/24 15:22:44
typedef?
dzhioev (left Google)
2015/02/26 14:01:39
'using' is a preferred way for making type definit
| |
50 base::hash_map<std::string, scoped_refptr<base::RefCountedMemory>>; | |
51 | |
52 content::WebUI* web_ui() { return web_ui_; } | |
53 | |
54 template <typename T> | |
55 void AddCallback(const std::string& name, void (T::*method)()) { | |
56 base::Callback<void()> callback = | |
57 base::Bind(method, base::Unretained(static_cast<T*>(this))); | |
58 web_ui_->RegisterMessageCallback( | |
59 name, base::Bind(&::login::CallbackWrapper0, callback)); | |
60 } | |
61 | |
62 template <typename T, typename A1> | |
63 void AddCallback(const std::string& name, void (T::*method)(A1 arg1)) { | |
64 base::Callback<void(A1)> callback = | |
65 base::Bind(method, base::Unretained(static_cast<T*>(this))); | |
66 web_ui_->RegisterMessageCallback( | |
67 name, base::Bind(&::login::CallbackWrapper1<A1>, callback)); | |
68 } | |
69 | |
70 // Overridden from View: | |
71 void OnReady() override; | |
72 void OnContextChanged(const base::DictionaryValue& diff) override; | |
73 | |
74 virtual void AddLocalizedValues(::login::LocalizedValuesBuilder* builder) = 0; | |
75 virtual void AddResources(ResourcesMap* resources_map) = 0; | |
76 | |
77 private: | |
Nikita (slow)
2015/02/24 15:22:44
nit: Please add comments for methods
dzhioev (left Google)
2015/02/26 14:01:39
Done.
| |
78 void SetUpDataSourceInternal(content::WebUIDataSource* data_source, | |
79 ResourcesMap* resources_map); | |
80 void HandleHTMLReady(); | |
81 void HandleContextChanged(const base::DictionaryValue* diff); | |
82 void Bind(); | |
83 | |
84 bool HandleDataRequest( | |
85 const ResourcesMap* resources, | |
86 const std::string& path, | |
87 const content::WebUIDataSource::GotDataCallback& got_data_callback); | |
88 | |
89 private: | |
90 content::WebUI* web_ui_; | |
91 bool html_ready_; | |
92 bool view_bound_; | |
93 scoped_ptr<Context> pending_context_changes_; | |
94 | |
95 DISALLOW_COPY_AND_ASSIGN(WebUIView); | |
96 }; | |
97 | |
98 } // namespace wug | |
99 | |
100 #endif // CHROME_BROWSER_UI_WEBUI_WUG_WEB_UI_VIEW_H_ | |
OLD | NEW |