blob: 96c4a48f2ace5f7c737479cc7a31665ccf05a7e4 [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"
derekjchow504caf22017-01-12 21:04:2711#include "base/memory/ptr_util.h"
[email protected]791733d2014-07-17 17:56:2912#include "content/public/browser/web_contents.h"
jlevasseur4681757a2017-02-08 22:09:0313#include "content/public/common/content_switches.h"
[email protected]791733d2014-07-17 17:56:2914#include "net/base/filename_util.h"
[email protected]791733d2014-07-17 17:56:2915
16namespace chromecast {
gunsch68c183a2015-09-08 18:12:3117namespace shell {
[email protected]791733d2014-07-17 17:56:2918
19namespace {
20
21GURL GetStartupURL() {
22 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
23 const base::CommandLine::StringVector& args = command_line->GetArgs();
24
25 if (args.empty())
26 return GURL("http://www.google.com/");
27
28 GURL url(args[0]);
29 if (url.is_valid() && url.has_scheme())
30 return url;
31
eugenebngb9400dc2015-04-28 11:18:0632 return net::FilePathToFileURL(
33 base::MakeAbsoluteFilePath(base::FilePath(args[0])));
[email protected]791733d2014-07-17 17:56:2934}
35
[email protected]791733d2014-07-17 17:56:2936} // namespace
37
jlevasseurbc99b5bd2017-01-23 19:01:3338CastServiceSimple::CastServiceSimple(content::BrowserContext* browser_context,
39 PrefService* pref_service,
40 CastWindowManager* window_manager)
41 : CastService(browser_context, pref_service),
42 window_manager_(window_manager) {
43 DCHECK(window_manager_);
[email protected]791733d2014-07-17 17:56:2944}
45
46CastServiceSimple::~CastServiceSimple() {
47}
48
byungchul70f384aa2014-12-16 19:14:1149void CastServiceSimple::InitializeInternal() {
halliwella9d2cb92015-01-23 17:44:0250 startup_url_ = GetStartupURL();
byungchul70f384aa2014-12-16 19:14:1151}
52
53void CastServiceSimple::FinalizeInternal() {
[email protected]791733d2014-07-17 17:56:2954}
55
56void CastServiceSimple::StartInternal() {
jlevasseur4681757a2017-02-08 22:09:0357 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
58 return;
59 }
60
derekjchow7348f002017-02-22 16:46:1161 cast_web_view_ = base::MakeUnique<CastWebView>(this, browser_context(),
62 /*site_instance*/ nullptr,
63 /*transparent*/ false);
64 cast_web_view_->Show(window_manager_);
65 cast_web_view_->LoadUrl(startup_url_);
[email protected]791733d2014-07-17 17:56:2966}
67
68void CastServiceSimple::StopInternal() {
derekjchow7348f002017-02-22 16:46:1169 if (cast_web_view_) {
70 cast_web_view_->ClosePage();
jlevasseur4681757a2017-02-08 22:09:0371 }
derekjchow7348f002017-02-22 16:46:1172 cast_web_view_.reset();
[email protected]791733d2014-07-17 17:56:2973}
74
derekjchow7348f002017-02-22 16:46:1175void CastServiceSimple::OnPageStopped(int error_code) {}
76
77void CastServiceSimple::OnLoadingStateChanged(bool loading) {}
78
derekjchow504caf22017-01-12 21:04:2779void CastServiceSimple::OnWindowDestroyed() {}
80
81void CastServiceSimple::OnKeyEvent(const ui::KeyEvent& key_event) {}
82
gunsch68c183a2015-09-08 18:12:3183} // namespace shell
[email protected]791733d2014-07-17 17:56:2984} // namespace chromecast