blob: 9c7ca6d3fc6b8182ced4d8826b70b78cb0e804d1 [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
7#include "base/command_line.h"
gunschf898f9912014-10-20 22:39:598#include "chromecast/browser/cast_content_window.h"
[email protected]791733d2014-07-17 17:56:299#include "content/public/browser/render_view_host.h"
10#include "content/public/browser/web_contents.h"
11#include "net/base/filename_util.h"
lcwu5b07d9f2014-09-25 18:39:0612#include "net/url_request/url_request_context_getter.h"
[email protected]791733d2014-07-17 17:56:2913
14namespace chromecast {
15
16namespace {
17
18GURL 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]791733d2014-07-17 17:56:2932} // namespace
33
34// static
byungchulba8252562014-12-05 21:01:2735scoped_ptr<CastService> CastService::Create(
lcwu5b07d9f2014-09-25 18:39:0636 content::BrowserContext* browser_context,
byungchulba8252562014-12-05 21:01:2737 PrefService* pref_service,
byungchul70f384aa2014-12-16 19:14:1138 metrics::CastMetricsServiceClient* metrics_service_client,
39 net::URLRequestContextGetter* request_context_getter) {
byungchulba8252562014-12-05 21:01:2740 return scoped_ptr<CastService>(new CastServiceSimple(browser_context,
41 pref_service,
byungchul70f384aa2014-12-16 19:14:1142 metrics_service_client));
[email protected]791733d2014-07-17 17:56:2943}
44
gunsch7b23fd172014-09-29 20:06:1645CastServiceSimple::CastServiceSimple(
46 content::BrowserContext* browser_context,
byungchulba8252562014-12-05 21:01:2747 PrefService* pref_service,
byungchul70f384aa2014-12-16 19:14:1148 metrics::CastMetricsServiceClient* metrics_service_client)
49 : CastService(browser_context, pref_service, metrics_service_client) {
[email protected]791733d2014-07-17 17:56:2950}
51
52CastServiceSimple::~CastServiceSimple() {
53}
54
byungchul70f384aa2014-12-16 19:14:1155void CastServiceSimple::InitializeInternal() {
halliwella9d2cb92015-01-23 17:44:0256 startup_url_ = GetStartupURL();
byungchul70f384aa2014-12-16 19:14:1157}
58
59void CastServiceSimple::FinalizeInternal() {
[email protected]791733d2014-07-17 17:56:2960}
61
62void CastServiceSimple::StartInternal() {
gunschf898f9912014-10-20 22:39:5963 // This is the simple version that hard-codes the size.
64 gfx::Size initial_size(1280, 720);
[email protected]791733d2014-07-17 17:56:2965
gunschf898f9912014-10-20 22:39:5966 window_.reset(new CastContentWindow);
derekjchow482c153d2014-12-23 19:47:0667 web_contents_ = window_->CreateWebContents(initial_size, browser_context());
68 window_->CreateWindowTree(initial_size, web_contents_.get());
[email protected]791733d2014-07-17 17:56:2969
halliwella9d2cb92015-01-23 17:44:0270 web_contents_->GetController().LoadURL(startup_url_, content::Referrer(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:3571 ui::PAGE_TRANSITION_TYPED,
[email protected]791733d2014-07-17 17:56:2972 std::string());
73}
74
75void CastServiceSimple::StopInternal() {
76 web_contents_->GetRenderViewHost()->ClosePage();
[email protected]791733d2014-07-17 17:56:2977 web_contents_.reset();
gunschf898f9912014-10-20 22:39:5978 window_.reset();
[email protected]791733d2014-07-17 17:56:2979}
80
81} // namespace chromecast