Chromium Code Reviews| Index: chrome/browser/ui/webui/cast/cast_ui.cc |
| diff --git a/chrome/browser/ui/webui/cast/cast_ui.cc b/chrome/browser/ui/webui/cast/cast_ui.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c3ba8c34f7ad27f68a7d0ae769b779d4903f5698 |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/cast/cast_ui.cc |
| @@ -0,0 +1,59 @@ |
| +// Copyright 2016 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. |
| + |
| +#include "chrome/browser/ui/webui/cast/cast_ui.h" |
| + |
| +#include "chrome/browser/media/router/media_router_factory.h" |
| +#include "chrome/browser/media/router/mojo/media_router_mojo_impl.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/common/url_constants.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/public/browser/web_ui.h" |
| +#include "content/public/browser/web_ui_data_source.h" |
| +#include "grit/browser_resources.h" |
| +#include "grit/generated_resources.h" |
| + |
| +namespace { |
| +const char kRequestExtensionId[] = "requestExtensionId"; |
| +const char kSetExtensionId[] = "setExtensionId"; |
| +} |
| + |
| +CastUI::CastUI(content::WebUI* web_ui) |
| + : content::WebUIController(web_ui) { |
| + // Retrieve the ID of the component extension. |
| + auto wc = web_ui->GetWebContents(); |
|
Bernhard Bauer
2016/05/19 14:34:07
Use the full type. Also, don't use abbreviations i
sheretov
2016/05/19 16:16:45
Removed this temporary variable altogether. Still
|
| + DCHECK(wc); |
|
Bernhard Bauer
2016/05/19 14:34:07
If this is null, you'll crash below in any case. (
sheretov
2016/05/19 16:16:45
Done.
|
| + // TODO(crbug.com/597778): remove reference to MediaRouterMojoImpl. |
| + auto router = static_cast<media_router::MediaRouterMojoImpl*>( |
| + media_router::MediaRouterFactory::GetApiForBrowserContext( |
| + wc->GetBrowserContext())); |
| + DCHECK(router); |
|
Bernhard Bauer
2016/05/19 14:34:07
Same here.
sheretov
2016/05/19 16:16:45
Done.
|
| + component_extension_id_ = router->media_route_provider_extension_id(); |
|
Bernhard Bauer
2016/05/19 14:34:07
Is there a reason you're not just adding this as a
sheretov
2016/05/19 16:16:45
Done.
|
| + |
| + web_ui->RegisterMessageCallback( |
| + kRequestExtensionId, |
| + base::Bind(&CastUI::OnRequestExtensionId, base::Unretained(this))); |
| + |
| + // Set up the chrome://cast source. |
| + content::WebUIDataSource* html_source = |
| + content::WebUIDataSource::Create(chrome::kChromeUICastHost); |
| + |
| + // Add required resources. |
| + html_source->AddResourcePath("cast.css", IDR_CAST_CSS); |
| + html_source->AddResourcePath("cast.js", IDR_CAST_JS); |
| + html_source->AddResourcePath("cast_favicon.ico", IDR_CAST_FAVICON); |
| + html_source->SetDefaultResource(IDR_CAST_HTML); |
| + html_source->OverrideContentSecurityPolicyObjectSrc("object-src *;"); |
| + |
| + Profile* profile = Profile::FromWebUI(web_ui); |
| + content::WebUIDataSource::Add(profile, html_source); |
| +} |
| + |
| +CastUI::~CastUI() { |
| +} |
| + |
| +void CastUI::OnRequestExtensionId(const base::ListValue* args) { |
| + base::StringValue result(component_extension_id_); |
| + web_ui()->CallJavascriptFunction(kSetExtensionId, result); |
| +} |