blob: e1eeae9454a7087277900171e9cf529f6b8344fa [file] [log] [blame]
Avi Drissmand878a5012022-09-12 19:13:301// Copyright 2014 The Chromium Authors
[email protected]791733d2014-07-17 17:56:292// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
gunschf44ffcb2014-10-13 23:01:455#include "chromecast/browser/service/cast_service_simple.h"
[email protected]791733d2014-07-17 17:56:296
derekjchow504caf22017-01-12 21:04:277#include <string>
8
[email protected]791733d2014-07-17 17:56:299#include "base/command_line.h"
eugenebngb9400dc2015-04-28 11:18:0610#include "base/files/file_util.h"
Sean Toppingf3a1642f2017-08-31 00:22:5111#include "base/time/time.h"
Zhiheng Vincent Li180905f52018-03-14 21:36:3512#include "chromecast/browser/cast_content_window.h"
Sean Toppingeda675e2019-11-07 22:29:0413#include "chromecast/browser/cast_web_service.h"
[email protected]791733d2014-07-17 17:56:2914#include "content/public/browser/web_contents.h"
jlevasseur4681757a2017-02-08 22:09:0315#include "content/public/common/content_switches.h"
[email protected]791733d2014-07-17 17:56:2916#include "net/base/filename_util.h"
[email protected]791733d2014-07-17 17:56:2917
18namespace chromecast {
gunsch68c183a2015-09-08 18:12:3119namespace shell {
[email protected]791733d2014-07-17 17:56:2920
21namespace {
22
23GURL GetStartupURL() {
24 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
25 const base::CommandLine::StringVector& args = command_line->GetArgs();
26
27 if (args.empty())
Sean Toppingcd917c012021-12-03 21:19:3528 return GURL();
[email protected]791733d2014-07-17 17:56:2929
30 GURL url(args[0]);
31 if (url.is_valid() && url.has_scheme())
32 return url;
33
eugenebngb9400dc2015-04-28 11:18:0634 return net::FilePathToFileURL(
35 base::MakeAbsoluteFilePath(base::FilePath(args[0])));
[email protected]791733d2014-07-17 17:56:2936}
37
[email protected]791733d2014-07-17 17:56:2938} // namespace
39
Sean Toppingd23e5722021-11-22 20:48:4940CastServiceSimple::CastServiceSimple(CastWebService* web_service)
41 : web_service_(web_service) {
42 DCHECK(web_service_);
[email protected]791733d2014-07-17 17:56:2943}
44
45CastServiceSimple::~CastServiceSimple() {
46}
47
byungchul70f384aa2014-12-16 19:14:1148void CastServiceSimple::InitializeInternal() {
halliwella9d2cb92015-01-23 17:44:0249 startup_url_ = GetStartupURL();
byungchul70f384aa2014-12-16 19:14:1150}
51
52void CastServiceSimple::FinalizeInternal() {
[email protected]791733d2014-07-17 17:56:2953}
54
55void CastServiceSimple::StartInternal() {
jlevasseur4681757a2017-02-08 22:09:0356 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
57 return;
58 }
59
Sean Toppingcd917c012021-12-03 21:19:3560 if (startup_url_.is_empty()) {
61 return;
62 }
63
Sean Topping92d0465b2021-07-16 01:11:3364 ::chromecast::mojom::CastWebViewParamsPtr params =
65 ::chromecast::mojom::CastWebViewParams::New();
66 params->enabled_for_dev = true;
67
Sean Topping077ba6d82021-11-02 22:48:4268 cast_web_view_ = web_service_->CreateWebViewInternal(std::move(params));
Sean Toppinga0a0f5e2020-03-19 00:22:3069 cast_web_view_->cast_web_contents()->LoadUrl(startup_url_);
70 cast_web_view_->window()->GrantScreenAccess();
Sean Topping805f50e2021-05-21 00:55:4771 cast_web_view_->window()->CreateWindow(
Sean Topping49d1cf7f2019-10-23 18:59:5372 ::chromecast::mojom::ZOrder::APP,
73 chromecast::VisibilityPriority::STICKY_ACTIVITY);
[email protected]791733d2014-07-17 17:56:2974}
75
76void CastServiceSimple::StopInternal() {
derekjchow7348f002017-02-22 16:46:1177 if (cast_web_view_) {
Sean Toppinga0a0f5e2020-03-19 00:22:3078 cast_web_view_->cast_web_contents()->ClosePage();
jlevasseur4681757a2017-02-08 22:09:0379 }
derekjchow7348f002017-02-22 16:46:1180 cast_web_view_.reset();
[email protected]791733d2014-07-17 17:56:2981}
82
gunsch68c183a2015-09-08 18:12:3183} // namespace shell
[email protected]791733d2014-07-17 17:56:2984} // namespace chromecast