| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/ui/webui/media_router/media_router_webui_message_handle
r.h" | 5 #include "chrome/browser/ui/webui/media_router/media_router_webui_message_handle
r.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 sink_val->SetString("description", sink.description()); | 58 sink_val->SetString("description", sink.description()); |
| 59 | 59 |
| 60 int cast_mode_bits = 0; | 60 int cast_mode_bits = 0; |
| 61 for (MediaCastMode cast_mode : sink_with_cast_modes.cast_modes) | 61 for (MediaCastMode cast_mode : sink_with_cast_modes.cast_modes) |
| 62 cast_mode_bits |= cast_mode; | 62 cast_mode_bits |= cast_mode; |
| 63 | 63 |
| 64 sink_val->SetInteger("castModes", cast_mode_bits); | 64 sink_val->SetInteger("castModes", cast_mode_bits); |
| 65 value->Append(sink_val.release()); | 65 value->Append(sink_val.release()); |
| 66 } | 66 } |
| 67 | 67 |
| 68 return value.Pass(); | 68 return value; |
| 69 } | 69 } |
| 70 | 70 |
| 71 scoped_ptr<base::DictionaryValue> RouteToValue( | 71 scoped_ptr<base::DictionaryValue> RouteToValue( |
| 72 const MediaRoute& route, const std::string& extension_id) { | 72 const MediaRoute& route, const std::string& extension_id) { |
| 73 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); | 73 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); |
| 74 dictionary->SetString("id", route.media_route_id()); | 74 dictionary->SetString("id", route.media_route_id()); |
| 75 dictionary->SetString("sinkId", route.media_sink_id()); | 75 dictionary->SetString("sinkId", route.media_sink_id()); |
| 76 dictionary->SetString("description", route.description()); | 76 dictionary->SetString("description", route.description()); |
| 77 dictionary->SetBoolean("isLocal", route.is_local()); | 77 dictionary->SetBoolean("isLocal", route.is_local()); |
| 78 | 78 |
| 79 const std::string& custom_path = route.custom_controller_path(); | 79 const std::string& custom_path = route.custom_controller_path(); |
| 80 if (!custom_path.empty()) { | 80 if (!custom_path.empty()) { |
| 81 std::string full_custom_controller_path = base::StringPrintf("%s://%s/%s", | 81 std::string full_custom_controller_path = base::StringPrintf("%s://%s/%s", |
| 82 extensions::kExtensionScheme, extension_id.c_str(), | 82 extensions::kExtensionScheme, extension_id.c_str(), |
| 83 custom_path.c_str()); | 83 custom_path.c_str()); |
| 84 DCHECK(GURL(full_custom_controller_path).is_valid()); | 84 DCHECK(GURL(full_custom_controller_path).is_valid()); |
| 85 dictionary->SetString("customControllerPath", | 85 dictionary->SetString("customControllerPath", |
| 86 full_custom_controller_path); | 86 full_custom_controller_path); |
| 87 } | 87 } |
| 88 | 88 |
| 89 return dictionary.Pass(); | 89 return dictionary; |
| 90 } | 90 } |
| 91 | 91 |
| 92 scoped_ptr<base::ListValue> RoutesToValue( | 92 scoped_ptr<base::ListValue> RoutesToValue( |
| 93 const std::vector<MediaRoute>& routes, const std::string& extension_id) { | 93 const std::vector<MediaRoute>& routes, const std::string& extension_id) { |
| 94 scoped_ptr<base::ListValue> value(new base::ListValue); | 94 scoped_ptr<base::ListValue> value(new base::ListValue); |
| 95 | 95 |
| 96 for (const MediaRoute& route : routes) { | 96 for (const MediaRoute& route : routes) { |
| 97 scoped_ptr<base::DictionaryValue> route_val(RouteToValue(route, | 97 scoped_ptr<base::DictionaryValue> route_val(RouteToValue(route, |
| 98 extension_id)); | 98 extension_id)); |
| 99 value->Append(route_val.release()); | 99 value->Append(route_val.release()); |
| 100 } | 100 } |
| 101 | 101 |
| 102 return value.Pass(); | 102 return value; |
| 103 } | 103 } |
| 104 | 104 |
| 105 scoped_ptr<base::ListValue> CastModesToValue(const CastModeSet& cast_modes, | 105 scoped_ptr<base::ListValue> CastModesToValue(const CastModeSet& cast_modes, |
| 106 const std::string& source_host) { | 106 const std::string& source_host) { |
| 107 scoped_ptr<base::ListValue> value(new base::ListValue); | 107 scoped_ptr<base::ListValue> value(new base::ListValue); |
| 108 | 108 |
| 109 for (const MediaCastMode& cast_mode : cast_modes) { | 109 for (const MediaCastMode& cast_mode : cast_modes) { |
| 110 scoped_ptr<base::DictionaryValue> cast_mode_val(new base::DictionaryValue); | 110 scoped_ptr<base::DictionaryValue> cast_mode_val(new base::DictionaryValue); |
| 111 cast_mode_val->SetInteger("type", cast_mode); | 111 cast_mode_val->SetInteger("type", cast_mode); |
| 112 cast_mode_val->SetString( | 112 cast_mode_val->SetString( |
| 113 "description", MediaCastModeToDescription(cast_mode, source_host)); | 113 "description", MediaCastModeToDescription(cast_mode, source_host)); |
| 114 cast_mode_val->SetString("host", source_host); | 114 cast_mode_val->SetString("host", source_host); |
| 115 value->Append(cast_mode_val.release()); | 115 value->Append(cast_mode_val.release()); |
| 116 } | 116 } |
| 117 | 117 |
| 118 return value.Pass(); | 118 return value; |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Returns an Issue dictionary created from |issue| that can be used in WebUI. | 121 // Returns an Issue dictionary created from |issue| that can be used in WebUI. |
| 122 scoped_ptr<base::DictionaryValue> IssueToValue(const Issue& issue) { | 122 scoped_ptr<base::DictionaryValue> IssueToValue(const Issue& issue) { |
| 123 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); | 123 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); |
| 124 dictionary->SetString("id", issue.id()); | 124 dictionary->SetString("id", issue.id()); |
| 125 dictionary->SetString("title", issue.title()); | 125 dictionary->SetString("title", issue.title()); |
| 126 dictionary->SetString("message", issue.message()); | 126 dictionary->SetString("message", issue.message()); |
| 127 dictionary->SetInteger("defaultActionType", issue.default_action().type()); | 127 dictionary->SetInteger("defaultActionType", issue.default_action().type()); |
| 128 if (!issue.secondary_actions().empty()) { | 128 if (!issue.secondary_actions().empty()) { |
| 129 dictionary->SetInteger("secondaryActionType", | 129 dictionary->SetInteger("secondaryActionType", |
| 130 issue.secondary_actions().begin()->type()); | 130 issue.secondary_actions().begin()->type()); |
| 131 } | 131 } |
| 132 if (!issue.route_id().empty()) | 132 if (!issue.route_id().empty()) |
| 133 dictionary->SetString("routeId", issue.route_id()); | 133 dictionary->SetString("routeId", issue.route_id()); |
| 134 dictionary->SetBoolean("isBlocking", issue.is_blocking()); | 134 dictionary->SetBoolean("isBlocking", issue.is_blocking()); |
| 135 | 135 |
| 136 return dictionary.Pass(); | 136 return dictionary; |
| 137 } | 137 } |
| 138 | 138 |
| 139 bool IsValidIssueActionTypeNum(int issue_action_type_num) { | 139 bool IsValidIssueActionTypeNum(int issue_action_type_num) { |
| 140 return issue_action_type_num >= 0 && | 140 return issue_action_type_num >= 0 && |
| 141 issue_action_type_num < IssueAction::TYPE_MAX; | 141 issue_action_type_num < IssueAction::TYPE_MAX; |
| 142 } | 142 } |
| 143 | 143 |
| 144 // Composes a "learn more" URL. The URL depends on template arguments in |args|. | 144 // Composes a "learn more" URL. The URL depends on template arguments in |args|. |
| 145 // Returns an empty string if |args| is invalid. | 145 // Returns an empty string if |args| is invalid. |
| 146 std::string GetLearnMoreUrl(const base::DictionaryValue* args) { | 146 std::string GetLearnMoreUrl(const base::DictionaryValue* args) { |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 open_args->AppendString(learn_more_url); | 410 open_args->AppendString(learn_more_url); |
| 411 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); | 411 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); |
| 412 return true; | 412 return true; |
| 413 } else { | 413 } else { |
| 414 // Do nothing; no other issue action types require any other action. | 414 // Do nothing; no other issue action types require any other action. |
| 415 return true; | 415 return true; |
| 416 } | 416 } |
| 417 } | 417 } |
| 418 | 418 |
| 419 } // namespace media_router | 419 } // namespace media_router |
| OLD | NEW |