[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" |
derekjchow | 504caf2 | 2017-01-12 21:04:27 | [diff] [blame] | 11 | #include "base/memory/ptr_util.h" |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 12 | #include "content/public/browser/web_contents.h" |
jlevasseur | 4681757a | 2017-02-08 22:09:03 | [diff] [blame] | 13 | #include "content/public/common/content_switches.h" |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 14 | #include "net/base/filename_util.h" |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 15 | |
16 | namespace chromecast { | ||||
gunsch | 68c183a | 2015-09-08 18:12:31 | [diff] [blame] | 17 | namespace shell { |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 18 | |
19 | namespace { | ||||
20 | |||||
21 | GURL 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 | |||||
eugenebng | b9400dc | 2015-04-28 11:18:06 | [diff] [blame] | 32 | return net::FilePathToFileURL( |
33 | base::MakeAbsoluteFilePath(base::FilePath(args[0]))); | ||||
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 34 | } |
35 | |||||
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 36 | } // namespace |
37 | |||||
jlevasseur | bc99b5bd | 2017-01-23 19:01:33 | [diff] [blame] | 38 | CastServiceSimple::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] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 44 | } |
45 | |||||
46 | CastServiceSimple::~CastServiceSimple() { | ||||
47 | } | ||||
48 | |||||
byungchul | 70f384aa | 2014-12-16 19:14:11 | [diff] [blame] | 49 | void CastServiceSimple::InitializeInternal() { |
halliwell | a9d2cb9 | 2015-01-23 17:44:02 | [diff] [blame] | 50 | startup_url_ = GetStartupURL(); |
byungchul | 70f384aa | 2014-12-16 19:14:11 | [diff] [blame] | 51 | } |
52 | |||||
53 | void CastServiceSimple::FinalizeInternal() { | ||||
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 54 | } |
55 | |||||
56 | void CastServiceSimple::StartInternal() { | ||||
jlevasseur | 4681757a | 2017-02-08 22:09:03 | [diff] [blame] | 57 | if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { |
58 | return; | ||||
59 | } | ||||
60 | |||||
derekjchow | 7348f00 | 2017-02-22 16:46:11 | [diff] [blame^] | 61 | 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] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 66 | } |
67 | |||||
68 | void CastServiceSimple::StopInternal() { | ||||
derekjchow | 7348f00 | 2017-02-22 16:46:11 | [diff] [blame^] | 69 | if (cast_web_view_) { |
70 | cast_web_view_->ClosePage(); | ||||
jlevasseur | 4681757a | 2017-02-08 22:09:03 | [diff] [blame] | 71 | } |
derekjchow | 7348f00 | 2017-02-22 16:46:11 | [diff] [blame^] | 72 | cast_web_view_.reset(); |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 73 | } |
74 | |||||
derekjchow | 7348f00 | 2017-02-22 16:46:11 | [diff] [blame^] | 75 | void CastServiceSimple::OnPageStopped(int error_code) {} |
76 | |||||
77 | void CastServiceSimple::OnLoadingStateChanged(bool loading) {} | ||||
78 | |||||
derekjchow | 504caf2 | 2017-01-12 21:04:27 | [diff] [blame] | 79 | void CastServiceSimple::OnWindowDestroyed() {} |
80 | |||||
81 | void CastServiceSimple::OnKeyEvent(const ui::KeyEvent& key_event) {} | ||||
82 | |||||
gunsch | 68c183a | 2015-09-08 18:12:31 | [diff] [blame] | 83 | } // namespace shell |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 84 | } // namespace chromecast |