[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 | |
| 7 | #include "base/command_line.h" |
gunsch | f898f991 | 2014-10-20 22:39:59 | [diff] [blame] | 8 | #include "chromecast/browser/cast_content_window.h" |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 9 | #include "content/public/browser/render_view_host.h" |
| 10 | #include "content/public/browser/web_contents.h" |
| 11 | #include "net/base/filename_util.h" |
lcwu | 5b07d9f | 2014-09-25 18:39:06 | [diff] [blame] | 12 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 13 | |
| 14 | namespace chromecast { |
| 15 | |
| 16 | namespace { |
| 17 | |
| 18 | GURL GetStartupURL() { |
| 19 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 20 | const base::CommandLine::StringVector& args = command_line->GetArgs(); |
| 21 | |
| 22 | if (args.empty()) |
| 23 | return GURL("http://www.google.com/"); |
| 24 | |
| 25 | GURL url(args[0]); |
| 26 | if (url.is_valid() && url.has_scheme()) |
| 27 | return url; |
| 28 | |
| 29 | return net::FilePathToFileURL(base::FilePath(args[0])); |
| 30 | } |
| 31 | |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 32 | } // namespace |
| 33 | |
| 34 | // static |
byungchul | ba825256 | 2014-12-05 21:01:27 | [diff] [blame] | 35 | scoped_ptr<CastService> CastService::Create( |
lcwu | 5b07d9f | 2014-09-25 18:39:06 | [diff] [blame] | 36 | content::BrowserContext* browser_context, |
byungchul | ba825256 | 2014-12-05 21:01:27 | [diff] [blame] | 37 | PrefService* pref_service, |
byungchul | 70f384aa | 2014-12-16 19:14:11 | [diff] [blame] | 38 | metrics::CastMetricsServiceClient* metrics_service_client, |
| 39 | net::URLRequestContextGetter* request_context_getter) { |
byungchul | ba825256 | 2014-12-05 21:01:27 | [diff] [blame] | 40 | return scoped_ptr<CastService>(new CastServiceSimple(browser_context, |
| 41 | pref_service, |
byungchul | 70f384aa | 2014-12-16 19:14:11 | [diff] [blame] | 42 | metrics_service_client)); |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 43 | } |
| 44 | |
gunsch | 7b23fd17 | 2014-09-29 20:06:16 | [diff] [blame] | 45 | CastServiceSimple::CastServiceSimple( |
| 46 | content::BrowserContext* browser_context, |
byungchul | ba825256 | 2014-12-05 21:01:27 | [diff] [blame] | 47 | PrefService* pref_service, |
byungchul | 70f384aa | 2014-12-16 19:14:11 | [diff] [blame] | 48 | metrics::CastMetricsServiceClient* metrics_service_client) |
| 49 | : CastService(browser_context, pref_service, metrics_service_client) { |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | CastServiceSimple::~CastServiceSimple() { |
| 53 | } |
| 54 | |
byungchul | 70f384aa | 2014-12-16 19:14:11 | [diff] [blame] | 55 | void CastServiceSimple::InitializeInternal() { |
halliwell | a9d2cb9 | 2015-01-23 17:44:02 | [diff] [blame^] | 56 | startup_url_ = GetStartupURL(); |
byungchul | 70f384aa | 2014-12-16 19:14:11 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | void CastServiceSimple::FinalizeInternal() { |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void CastServiceSimple::StartInternal() { |
gunsch | f898f991 | 2014-10-20 22:39:59 | [diff] [blame] | 63 | // This is the simple version that hard-codes the size. |
| 64 | gfx::Size initial_size(1280, 720); |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 65 | |
gunsch | f898f991 | 2014-10-20 22:39:59 | [diff] [blame] | 66 | window_.reset(new CastContentWindow); |
derekjchow | 482c153d | 2014-12-23 19:47:06 | [diff] [blame] | 67 | web_contents_ = window_->CreateWebContents(initial_size, browser_context()); |
| 68 | window_->CreateWindowTree(initial_size, web_contents_.get()); |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 69 | |
halliwell | a9d2cb9 | 2015-01-23 17:44:02 | [diff] [blame^] | 70 | web_contents_->GetController().LoadURL(startup_url_, content::Referrer(), |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 71 | ui::PAGE_TRANSITION_TYPED, |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 72 | std::string()); |
| 73 | } |
| 74 | |
| 75 | void CastServiceSimple::StopInternal() { |
| 76 | web_contents_->GetRenderViewHost()->ClosePage(); |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 77 | web_contents_.reset(); |
gunsch | f898f991 | 2014-10-20 22:39:59 | [diff] [blame] | 78 | window_.reset(); |
[email protected] | 791733d | 2014-07-17 17:56:29 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | } // namespace chromecast |