OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/webui/cast/cast_ui.h" | |
6 | |
7 #include "chrome/browser/media/router/media_router_factory.h" | |
8 #include "chrome/browser/media/router/mojo/media_router_mojo_impl.h" | |
9 #include "chrome/browser/profiles/profile.h" | |
10 #include "chrome/common/url_constants.h" | |
11 #include "content/public/browser/web_contents.h" | |
12 #include "content/public/browser/web_ui.h" | |
13 #include "content/public/browser/web_ui_data_source.h" | |
14 #include "grit/browser_resources.h" | |
15 #include "grit/generated_resources.h" | |
16 | |
17 namespace { | |
18 const char kRequestExtensionId[] = "requestExtensionId"; | |
19 const char kSetExtensionId[] = "setExtensionId"; | |
20 } | |
21 | |
22 CastUI::CastUI(content::WebUI* web_ui) | |
23 : content::WebUIController(web_ui) { | |
24 // Retrieve the ID of the component extension. | |
25 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
| |
26 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.
| |
27 // TODO(crbug.com/597778): remove reference to MediaRouterMojoImpl. | |
28 auto router = static_cast<media_router::MediaRouterMojoImpl*>( | |
29 media_router::MediaRouterFactory::GetApiForBrowserContext( | |
30 wc->GetBrowserContext())); | |
31 DCHECK(router); | |
Bernhard Bauer
2016/05/19 14:34:07
Same here.
sheretov
2016/05/19 16:16:45
Done.
| |
32 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.
| |
33 | |
34 web_ui->RegisterMessageCallback( | |
35 kRequestExtensionId, | |
36 base::Bind(&CastUI::OnRequestExtensionId, base::Unretained(this))); | |
37 | |
38 // Set up the chrome://cast source. | |
39 content::WebUIDataSource* html_source = | |
40 content::WebUIDataSource::Create(chrome::kChromeUICastHost); | |
41 | |
42 // Add required resources. | |
43 html_source->AddResourcePath("cast.css", IDR_CAST_CSS); | |
44 html_source->AddResourcePath("cast.js", IDR_CAST_JS); | |
45 html_source->AddResourcePath("cast_favicon.ico", IDR_CAST_FAVICON); | |
46 html_source->SetDefaultResource(IDR_CAST_HTML); | |
47 html_source->OverrideContentSecurityPolicyObjectSrc("object-src *;"); | |
48 | |
49 Profile* profile = Profile::FromWebUI(web_ui); | |
50 content::WebUIDataSource::Add(profile, html_source); | |
51 } | |
52 | |
53 CastUI::~CastUI() { | |
54 } | |
55 | |
56 void CastUI::OnRequestExtensionId(const base::ListValue* args) { | |
57 base::StringValue result(component_extension_id_); | |
58 web_ui()->CallJavascriptFunction(kSetExtensionId, result); | |
59 } | |
OLD | NEW |