[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 1 | // Copyright 2014 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 | |||||
gunsch | f44ffcb | 2014-10-13 23:01:45 | [diff] [blame] | 5 | #include "chromecast/browser/service/cast_service_simple.h" |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 6 | |
derekjchow | 504caf2 | 2017-01-12 21:04:27 | [diff] [blame] | 7 | #include <string> |
8 | |||||
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 9 | #include "base/command_line.h" |
eugenebng | b9400dc | 2015-04-28 11:18:06 | [diff] [blame] | 10 | #include "base/files/file_util.h" |
Sean Topping | f3a1642f | 2017-08-31 00:22:51 | [diff] [blame] | 11 | #include "base/time/time.h" |
Albert Chaulk | 7f637c7 | 2018-06-11 21:46:25 | [diff] [blame] | 12 | #include "chromecast/browser/cast_browser_process.h" |
Zhiheng Vincent Li | 180905f5 | 2018-03-14 21:36:35 | [diff] [blame] | 13 | #include "chromecast/browser/cast_content_window.h" |
Sean Topping | eda675e | 2019-11-07 22:29:04 | [diff] [blame] | 14 | #include "chromecast/browser/cast_web_service.h" |
Sean Topping | 95c063b | 2018-02-21 01:01:38 | [diff] [blame] | 15 | #include "chromecast/browser/cast_web_view_factory.h" |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 16 | #include "content/public/browser/web_contents.h" |
jlevasseur | 4681757a | 2017-02-08 22:09:03 | [diff] [blame] | 17 | #include "content/public/common/content_switches.h" |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 18 | #include "net/base/filename_util.h" |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 19 | |
20 | namespace chromecast { | ||||
gunsch | 68c183a | 2015-09-08 18:12:31 | [diff] [blame] | 21 | namespace shell { |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 22 | |
23 | namespace { | ||||
24 | |||||
25 | GURL GetStartupURL() { | ||||
26 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | ||||
27 | const base::CommandLine::StringVector& args = command_line->GetArgs(); | ||||
28 | |||||
29 | if (args.empty()) | ||||
30 | return GURL("http://www.google.com/"); | ||||
31 | |||||
32 | GURL url(args[0]); | ||||
33 | if (url.is_valid() && url.has_scheme()) | ||||
34 | return url; | ||||
35 | |||||
eugenebng | b9400dc | 2015-04-28 11:18:06 | [diff] [blame] | 36 | return net::FilePathToFileURL( |
37 | base::MakeAbsoluteFilePath(base::FilePath(args[0]))); | ||||
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 38 | } |
39 | |||||
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 40 | } // namespace |
41 | |||||
jlevasseur | bc99b5bd | 2017-01-23 19:01:33 | [diff] [blame] | 42 | CastServiceSimple::CastServiceSimple(content::BrowserContext* browser_context, |
43 | PrefService* pref_service, | ||||
44 | CastWindowManager* window_manager) | ||||
45 | : CastService(browser_context, pref_service), | ||||
Sean Topping | 95c063b | 2018-02-21 01:01:38 | [diff] [blame] | 46 | web_view_factory_(std::make_unique<CastWebViewFactory>(browser_context)), |
Sean Topping | eda675e | 2019-11-07 22:29:04 | [diff] [blame] | 47 | web_service_(std::make_unique<CastWebService>(browser_context, |
48 | web_view_factory_.get(), | ||||
49 | window_manager)) { | ||||
Albert Chaulk | 7f637c7 | 2018-06-11 21:46:25 | [diff] [blame] | 50 | shell::CastBrowserProcess::GetInstance()->SetWebViewFactory( |
51 | web_view_factory_.get()); | ||||
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 52 | } |
53 | |||||
54 | CastServiceSimple::~CastServiceSimple() { | ||||
55 | } | ||||
56 | |||||
byungchul | 70f384aa | 2014-12-16 19:14:11 | [diff] [blame] | 57 | void CastServiceSimple::InitializeInternal() { |
halliwell | a9d2cb9 | 2015-01-23 17:44:02 | [diff] [blame] | 58 | startup_url_ = GetStartupURL(); |
byungchul | 70f384aa | 2014-12-16 19:14:11 | [diff] [blame] | 59 | } |
60 | |||||
61 | void CastServiceSimple::FinalizeInternal() { | ||||
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 62 | } |
63 | |||||
64 | void CastServiceSimple::StartInternal() { | ||||
jlevasseur | 4681757a | 2017-02-08 22:09:03 | [diff] [blame] | 65 | if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { |
66 | return; | ||||
67 | } | ||||
68 | |||||
Stephen Lanham | 90e82f0 | 2018-02-07 23:59:10 | [diff] [blame] | 69 | CastWebView::CreateParams params; |
Sean Topping | eda675e | 2019-11-07 22:29:04 | [diff] [blame] | 70 | params.delegate = weak_factory_.GetWeakPtr(); |
71 | params.web_contents_params.delegate = weak_factory_.GetWeakPtr(); | ||||
Sean Topping | 8a34386 | 2019-05-09 22:19:14 | [diff] [blame] | 72 | params.web_contents_params.enabled_for_dev = true; |
Sean Topping | eda675e | 2019-11-07 22:29:04 | [diff] [blame] | 73 | params.window_params.delegate = weak_factory_.GetWeakPtr(); |
Stephen Lanham | 90e82f0 | 2018-02-07 23:59:10 | [diff] [blame] | 74 | cast_web_view_ = |
Sean Topping | a0a0f5e | 2020-03-19 00:22:30 | [diff] [blame^] | 75 | web_service_->CreateWebView(params, GURL() /* initial_url */); |
76 | cast_web_view_->cast_web_contents()->LoadUrl(startup_url_); | ||||
77 | cast_web_view_->window()->GrantScreenAccess(); | ||||
Sean Topping | df9fb29 | 2018-03-27 23:44:40 | [diff] [blame] | 78 | cast_web_view_->InitializeWindow( |
Sean Topping | 49d1cf7f | 2019-10-23 18:59:53 | [diff] [blame] | 79 | ::chromecast::mojom::ZOrder::APP, |
80 | chromecast::VisibilityPriority::STICKY_ACTIVITY); | ||||
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 81 | } |
82 | |||||
83 | void CastServiceSimple::StopInternal() { | ||||
derekjchow | 7348f00 | 2017-02-22 16:46:11 | [diff] [blame] | 84 | if (cast_web_view_) { |
Sean Topping | a0a0f5e | 2020-03-19 00:22:30 | [diff] [blame^] | 85 | cast_web_view_->cast_web_contents()->ClosePage(); |
jlevasseur | 4681757a | 2017-02-08 22:09:03 | [diff] [blame] | 86 | } |
derekjchow | 7348f00 | 2017-02-22 16:46:11 | [diff] [blame] | 87 | cast_web_view_.reset(); |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 88 | } |
89 | |||||
derekjchow | 504caf2 | 2017-01-12 21:04:27 | [diff] [blame] | 90 | void CastServiceSimple::OnWindowDestroyed() {} |
91 | |||||
Sean Topping | df9fb29 | 2018-03-27 23:44:40 | [diff] [blame] | 92 | bool CastServiceSimple::CanHandleGesture(GestureType gesture_type) { |
93 | return false; | ||||
94 | } | ||||
95 | |||||
Zhiheng Vincent Li | 180905f5 | 2018-03-14 21:36:35 | [diff] [blame] | 96 | bool CastServiceSimple::ConsumeGesture(GestureType gesture_type) { |
97 | return false; | ||||
Sean Topping | df9fb29 | 2018-03-27 23:44:40 | [diff] [blame] | 98 | } |
Zhiheng Vincent Li | 180905f5 | 2018-03-14 21:36:35 | [diff] [blame] | 99 | |
100 | void CastServiceSimple::OnVisibilityChange(VisibilityType visibility_type) {} | ||||
101 | |||||
102 | std::string CastServiceSimple::GetId() { | ||||
103 | return ""; | ||||
104 | } | ||||
105 | |||||
gunsch | 68c183a | 2015-09-08 18:12:31 | [diff] [blame] | 106 | } // namespace shell |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 107 | } // namespace chromecast |