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 CHROME_BROWSER_UI_WEBUI_PLUGINS_PLUGINS_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_PLUGINS_PLUGINS_HANDLER_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_PLUGINS_PLUGINS_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_PLUGINS_PLUGINS_HANDLER_H_ |
7 | 7 |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/prefs/pref_member.h" | 9 #include "base/prefs/pref_member.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/ui/webui/mojo_web_ui_handler.h" | |
12 #include "chrome/browser/ui/webui/plugins/plugins.mojom.h" | |
11 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
12 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
13 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
14 #include "content/public/browser/web_ui_message_handler.h" | 16 #include "content/public/browser/web_ui_message_handler.h" |
15 #include "content/public/common/webplugininfo.h" | 17 #include "content/public/common/webplugininfo.h" |
18 #include "mojo/public/cpp/bindings/binding.h" | |
16 | 19 |
17 class PluginsHandler : public content::WebUIMessageHandler, | 20 class PluginsHandler : |
18 public content::NotificationObserver { | 21 public MojoWebUIHandler, public PluginsHandlerMojo, |
22 public content::NotificationObserver { | |
Dan Beam
2016/01/26 20:10:43
wrong indent
dpapad
2016/01/26 22:34:48
Fixed (along with other style issues, just run cla
| |
19 public: | 23 public: |
20 PluginsHandler(); | 24 PluginsHandler(content::WebUI* web_ui, |
25 mojo::InterfaceRequest<PluginsHandlerMojo> request); | |
21 ~PluginsHandler() override; | 26 ~PluginsHandler() override; |
22 | 27 |
23 // content::WebUIMessageHandler implementation. | 28 // PluginsHandlerMojo overrides: |
24 void RegisterMessages() override; | 29 void GetPluginsData(const GetPluginsDataCallback& callback) override; |
30 void GetShowDetails(const GetShowDetailsCallback& callback) override; | |
31 void SaveShowDetailsToPrefs(bool details_mode) override; | |
32 void SetPluginAlwaysAllowed( | |
33 const mojo::String& plugin, bool allowed) override; | |
34 void SetPluginEnabled(const mojo::String& plugin_path, bool enable) override; | |
35 void SetPluginGroupEnabled(const mojo::String& group_name, bool enable) | |
36 override; | |
37 void SetClientPage(PluginsPageMojoPtr page) override; | |
25 | 38 |
26 // content::NotificationObserver implementation. | 39 // content::NotificationObserver implementation. |
27 void Observe(int type, | 40 void Observe(int type, |
28 const content::NotificationSource& source, | 41 const content::NotificationSource& source, |
29 const content::NotificationDetails& details) override; | 42 const content::NotificationDetails& details) override; |
30 | 43 |
31 private: | 44 private: |
32 // Callback for the "requestPluginsData" message. | 45 mojo::Array<PluginDataPtr> GeneratePluginsData( |
33 void HandleRequestPluginsData(const base::ListValue* args); | 46 const std::vector<content::WebPluginInfo>& plugins); |
34 | 47 |
35 // Callback for the "enablePlugin" message. | 48 PluginFilePtr GeneratePluginFile(const content::WebPluginInfo& plugin, |
36 void HandleEnablePluginMessage(const base::ListValue* args); | 49 const base::string16& group_name, |
37 | 50 bool plugin_enabled) const; |
38 // Callback for the "saveShowDetailsToPrefs" message. | |
39 void HandleSaveShowDetailsToPrefs(const base::ListValue* args); | |
40 | |
41 // Calback for the "getShowDetails" message. | |
42 void HandleGetShowDetails(const base::ListValue* args); | |
43 | |
44 // Callback for the "setPluginAlwaysAllowed" message. | |
45 void HandleSetPluginAlwaysAllowed(const base::ListValue* args); | |
46 | |
47 void LoadPlugins(); | |
48 | |
49 // Called on the UI thread when the plugin information is ready. | |
50 void PluginsLoaded(const std::vector<content::WebPluginInfo>& plugins); | |
51 | 51 |
52 // Detect a plugin's enabled mode (one of enabledByUser, disabledByUser, | 52 // Detect a plugin's enabled mode (one of enabledByUser, disabledByUser, |
53 // enabledByPolicy, disabledByPolicy). | 53 // enabledByPolicy, disabledByPolicy). |
54 std::string GetPluginEnabledMode(const base::string16& plugin_name, | 54 std::string GetPluginEnabledMode(const base::string16& plugin_name, |
55 const base::string16& group_name, | 55 const base::string16& group_name, |
56 bool plugin_enabled) const; | 56 bool plugin_enabled) const; |
57 | 57 |
58 // Detect a plugin group's enabled mode (one of enabledByUser, disabledByUser, | 58 // Detect a plugin group's enabled mode (one of enabledByUser, disabledByUser, |
59 // enabledByPolicy, disabledByPolicy, managedByPolicy). | 59 // enabledByPolicy, disabledByPolicy, managedByPolicy). |
60 std::string GetPluginGroupEnabledMode(const base::ListValue& plugin_files, | 60 std::string GetPluginGroupEnabledMode( |
61 bool group_enabled) const; | 61 const mojo::Array<PluginFilePtr>& plugin_files, |
62 bool group_enabled) const; | |
63 | |
64 // Called on the UI thread when the plugin info requested fom GetPluginsData | |
65 // is ready. | |
66 void RespondWithPluginsData( | |
67 const GetPluginsDataCallback& callback, | |
68 const std::vector<content::WebPluginInfo>& plugins); | |
69 | |
70 // Called on the UI thread when the plugin info has changed and calls the page | |
71 // to update it. | |
72 void NotifyWithPluginsData( | |
73 const std::vector<content::WebPluginInfo>& plugins); | |
62 | 74 |
63 content::NotificationRegistrar registrar_; | 75 content::NotificationRegistrar registrar_; |
64 | 76 |
65 // This pref guards the value whether about:plugins is in the details mode or | 77 // This pref guards the value whether about:plugins is in the details mode or |
66 // not. | 78 // not. |
67 BooleanPrefMember show_details_; | 79 BooleanPrefMember show_details_; |
68 | 80 |
81 content::WebUI* web_ui_; | |
Dan Beam
2016/01/26 20:10:43
nit: document ownership
dpapad
2016/01/26 22:34:48
Done.
| |
82 mojo::Binding<PluginsHandlerMojo> binding_; | |
83 | |
84 // Handle back to the page by which JS methods can be called. | |
85 PluginsPageMojoPtr page_; | |
86 | |
69 base::WeakPtrFactory<PluginsHandler> weak_ptr_factory_; | 87 base::WeakPtrFactory<PluginsHandler> weak_ptr_factory_; |
70 | 88 |
71 DISALLOW_COPY_AND_ASSIGN(PluginsHandler); | 89 DISALLOW_COPY_AND_ASSIGN(PluginsHandler); |
72 }; | 90 }; |
73 | 91 |
74 #endif // CHROME_BROWSER_UI_WEBUI_PLUGINS_PLUGINS_HANDLER_H_ | 92 #endif // CHROME_BROWSER_UI_WEBUI_PLUGINS_PLUGINS_HANDLER_H_ |
OLD | NEW |