blob: a961d1a567ffdfa81ecb2d701a2c37a4d40027de [file] [log] [blame]
[email protected]791733d2014-07-17 17:56:291// 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
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"
Albert Chaulk7f637c72018-06-11 21:46:2512#include "chromecast/browser/cast_browser_process.h"
Zhiheng Vincent Li180905f52018-03-14 21:36:3513#include "chromecast/browser/cast_content_window.h"
Sean Toppingeda675e2019-11-07 22:29:0414#include "chromecast/browser/cast_web_service.h"
Sean Topping95c063b2018-02-21 01:01:3815#include "chromecast/browser/cast_web_view_factory.h"
[email protected]791733d2014-07-17 17:56:2916#include "content/public/browser/web_contents.h"
jlevasseur4681757a2017-02-08 22:09:0317#include "content/public/common/content_switches.h"
[email protected]791733d2014-07-17 17:56:2918#include "net/base/filename_util.h"
[email protected]791733d2014-07-17 17:56:2919
20namespace chromecast {
gunsch68c183a2015-09-08 18:12:3121namespace shell {
[email protected]791733d2014-07-17 17:56:2922
23namespace {
24
25GURL 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
eugenebngb9400dc2015-04-28 11:18:0636 return net::FilePathToFileURL(
37 base::MakeAbsoluteFilePath(base::FilePath(args[0])));
[email protected]791733d2014-07-17 17:56:2938}
39
[email protected]791733d2014-07-17 17:56:2940} // namespace
41
jlevasseurbc99b5bd2017-01-23 19:01:3342CastServiceSimple::CastServiceSimple(content::BrowserContext* browser_context,
43 PrefService* pref_service,
44 CastWindowManager* window_manager)
45 : CastService(browser_context, pref_service),
Sean Topping95c063b2018-02-21 01:01:3846 web_view_factory_(std::make_unique<CastWebViewFactory>(browser_context)),
Sean Toppingeda675e2019-11-07 22:29:0447 web_service_(std::make_unique<CastWebService>(browser_context,
48 web_view_factory_.get(),
49 window_manager)) {
Albert Chaulk7f637c72018-06-11 21:46:2550 shell::CastBrowserProcess::GetInstance()->SetWebViewFactory(
51 web_view_factory_.get());
[email protected]791733d2014-07-17 17:56:2952}
53
54CastServiceSimple::~CastServiceSimple() {
55}
56
byungchul70f384aa2014-12-16 19:14:1157void CastServiceSimple::InitializeInternal() {
halliwella9d2cb92015-01-23 17:44:0258 startup_url_ = GetStartupURL();
byungchul70f384aa2014-12-16 19:14:1159}
60
61void CastServiceSimple::FinalizeInternal() {
[email protected]791733d2014-07-17 17:56:2962}
63
64void CastServiceSimple::StartInternal() {
jlevasseur4681757a2017-02-08 22:09:0365 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
66 return;
67 }
68
Stephen Lanham90e82f02018-02-07 23:59:1069 CastWebView::CreateParams params;
Sean Toppingeda675e2019-11-07 22:29:0470 params.delegate = weak_factory_.GetWeakPtr();
71 params.web_contents_params.delegate = weak_factory_.GetWeakPtr();
Sean Topping8a343862019-05-09 22:19:1472 params.web_contents_params.enabled_for_dev = true;
Sean Toppingeda675e2019-11-07 22:29:0473 params.window_params.delegate = weak_factory_.GetWeakPtr();
Stephen Lanham90e82f02018-02-07 23:59:1074 cast_web_view_ =
Sean Toppinga0a0f5e2020-03-19 00:22:3075 web_service_->CreateWebView(params, GURL() /* initial_url */);
76 cast_web_view_->cast_web_contents()->LoadUrl(startup_url_);
77 cast_web_view_->window()->GrantScreenAccess();
Sean Toppingdf9fb292018-03-27 23:44:4078 cast_web_view_->InitializeWindow(
Sean Topping49d1cf7f2019-10-23 18:59:5379 ::chromecast::mojom::ZOrder::APP,
80 chromecast::VisibilityPriority::STICKY_ACTIVITY);
[email protected]791733d2014-07-17 17:56:2981}
82
83void CastServiceSimple::StopInternal() {
derekjchow7348f002017-02-22 16:46:1184 if (cast_web_view_) {
Sean Toppinga0a0f5e2020-03-19 00:22:3085 cast_web_view_->cast_web_contents()->ClosePage();
jlevasseur4681757a2017-02-08 22:09:0386 }
derekjchow7348f002017-02-22 16:46:1187 cast_web_view_.reset();
[email protected]791733d2014-07-17 17:56:2988}
89
derekjchow504caf22017-01-12 21:04:2790void CastServiceSimple::OnWindowDestroyed() {}
91
Sean Toppingdf9fb292018-03-27 23:44:4092bool CastServiceSimple::CanHandleGesture(GestureType gesture_type) {
93 return false;
94}
95
Zhiheng Vincent Li180905f52018-03-14 21:36:3596bool CastServiceSimple::ConsumeGesture(GestureType gesture_type) {
97 return false;
Sean Toppingdf9fb292018-03-27 23:44:4098}
Zhiheng Vincent Li180905f52018-03-14 21:36:3599
100void CastServiceSimple::OnVisibilityChange(VisibilityType visibility_type) {}
101
102std::string CastServiceSimple::GetId() {
103 return "";
104}
105
gunsch68c183a2015-09-08 18:12:31106} // namespace shell
[email protected]791733d2014-07-17 17:56:29107} // namespace chromecast