Chromium Code Reviews| Index: components/wug/web_ui_view.h |
| diff --git a/components/wug/web_ui_view.h b/components/wug/web_ui_view.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fd9300ef97e9ee53e1104ced549b3f20a6c433ac |
| --- /dev/null |
| +++ b/components/wug/web_ui_view.h |
| @@ -0,0 +1,100 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_UI_WEBUI_WUG_WEB_UI_VIEW_H_ |
| +#define CHROME_BROWSER_UI_WEBUI_WUG_WEB_UI_VIEW_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/bind.h" |
| +#include "base/containers/hash_tables.h" |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted_memory.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "components/login/base_screen_handler_utils.h" |
| +#include "components/login/screens/screen_context.h" |
| +#include "components/wug/export.h" |
| +#include "components/wug/view.h" |
| +#include "content/public/browser/web_ui.h" |
| +#include "content/public/browser/web_ui_data_source.h" |
| + |
| +namespace base { |
| +class DictionaryValue; |
| +} |
| + |
| +namespace content { |
| +class WebUI; |
| +} |
| + |
| +namespace login { |
| +class LocalizedValuesBuilder; |
| +} |
| + |
| +namespace wug { |
| + |
| +using Context = login::ScreenContext; |
| + |
|
Nikita (slow)
2015/02/24 15:22:44
nit: Add comment
dzhioev (left Google)
2015/02/26 14:01:39
Done.
|
| +class WUG_EXPORT WebUIView : public View { |
| + public: |
| + WebUIView(content::WebUI* web_ui, const std::string& id); |
| + ~WebUIView() override; |
| + |
| + void SetUpDataSource(content::WebUIDataSource* data_source); |
| + |
| + // Overridden from View: |
| + void Init() override; |
| + |
| + protected: |
| + 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
|
| + base::hash_map<std::string, scoped_refptr<base::RefCountedMemory>>; |
| + |
| + content::WebUI* web_ui() { return web_ui_; } |
| + |
| + template <typename T> |
| + void AddCallback(const std::string& name, void (T::*method)()) { |
| + base::Callback<void()> callback = |
| + base::Bind(method, base::Unretained(static_cast<T*>(this))); |
| + web_ui_->RegisterMessageCallback( |
| + name, base::Bind(&::login::CallbackWrapper0, callback)); |
| + } |
| + |
| + template <typename T, typename A1> |
| + void AddCallback(const std::string& name, void (T::*method)(A1 arg1)) { |
| + base::Callback<void(A1)> callback = |
| + base::Bind(method, base::Unretained(static_cast<T*>(this))); |
| + web_ui_->RegisterMessageCallback( |
| + name, base::Bind(&::login::CallbackWrapper1<A1>, callback)); |
| + } |
| + |
| + // Overridden from View: |
| + void OnReady() override; |
| + void OnContextChanged(const base::DictionaryValue& diff) override; |
| + |
| + virtual void AddLocalizedValues(::login::LocalizedValuesBuilder* builder) = 0; |
| + virtual void AddResources(ResourcesMap* resources_map) = 0; |
| + |
| + 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.
|
| + void SetUpDataSourceInternal(content::WebUIDataSource* data_source, |
| + ResourcesMap* resources_map); |
| + void HandleHTMLReady(); |
| + void HandleContextChanged(const base::DictionaryValue* diff); |
| + void Bind(); |
| + |
| + bool HandleDataRequest( |
| + const ResourcesMap* resources, |
| + const std::string& path, |
| + const content::WebUIDataSource::GotDataCallback& got_data_callback); |
| + |
| + private: |
| + content::WebUI* web_ui_; |
| + bool html_ready_; |
| + bool view_bound_; |
| + scoped_ptr<Context> pending_context_changes_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WebUIView); |
| +}; |
| + |
| +} // namespace wug |
| + |
| +#endif // CHROME_BROWSER_UI_WEBUI_WUG_WEB_UI_VIEW_H_ |