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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_WEBUI_MESSAGE_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_WEBUI_MESSAGE_HANDLER_H_
10 #include "base/macros.h"
11 #include "chrome/browser/media/router/issue.h"
12 #include "chrome/browser/ui/webui/media_router/media_cast_mode.h"
13 #include "chrome/browser/ui/webui/media_router/media_sink_with_cast_modes.h"
14 #include "content/public/browser/web_ui_message_handler.h"
17 class DictionaryValue
;
21 namespace media_router
{
27 // The handler for Javascript messages related to the media router dialog.
28 class MediaRouterWebUIMessageHandler
: public content::WebUIMessageHandler
{
30 explicit MediaRouterWebUIMessageHandler(MediaRouterUI
* media_router_ui
);
31 ~MediaRouterWebUIMessageHandler() override
;
33 // Methods to update the status displayed by the dialog.
34 void UpdateSinks(const std::vector
<MediaSinkWithCastModes
>& sinks
);
35 void UpdateRoutes(const std::vector
<MediaRoute
>& routes
);
36 void UpdateCastModes(const CastModeSet
& cast_modes
,
37 const std::string
& source_host
);
38 void OnCreateRouteResponseReceived(const MediaSink::Id
& sink_id
,
39 const MediaRoute
* route
);
41 // Does not take ownership of |issue|. Note that |issue| can be nullptr, when
42 // there are no more issues.
43 void UpdateIssue(const Issue
* issue
);
46 // WebUIMessageHandler implementation.
47 void RegisterMessages() override
;
49 // Handlers for JavaScript messages.
50 // In all cases, |args| consists of a single DictionaryValue containing the
52 // See media_router_ui_interface.js for documentation on parameters.
53 void OnRequestInitialData(const base::ListValue
* args
);
54 void OnCreateRoute(const base::ListValue
* args
);
55 void OnActOnIssue(const base::ListValue
* args
);
56 void OnCloseRoute(const base::ListValue
* args
);
57 void OnCloseDialog(const base::ListValue
* args
);
59 // Performs an action for an Issue of |type|.
60 // |args| contains additional parameter that varies based on |type|.
61 // Returns |true| if the action was successfully performed.
62 bool ActOnIssueType(const IssueAction::Type
& type
,
63 const base::DictionaryValue
* args
);
65 // Keeps track of whether a command to close the dialog has been issued.
68 MediaRouterUI
* media_router_ui_
;
70 DISALLOW_COPY_AND_ASSIGN(MediaRouterWebUIMessageHandler
);
73 } // namespace media_router
75 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_WEBUI_MESSAGE_HANDLER_H_