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.
5 #include "chromecast/browser/service/cast_service_simple.h"
7 #include "base/command_line.h"
8 #include "chromecast/browser/cast_content_window.h"
9 #include "content/public/browser/render_view_host.h"
10 #include "content/public/browser/web_contents.h"
11 #include "net/base/filename_util.h"
12 #include "net/url_request/url_request_context_getter.h"
14 namespace chromecast
{
18 GURL
GetStartupURL() {
19 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
20 const base::CommandLine::StringVector
& args
= command_line
->GetArgs();
23 return GURL("http://www.google.com/");
26 if (url
.is_valid() && url
.has_scheme())
29 return net::FilePathToFileURL(base::FilePath(args
[0]));
35 scoped_ptr
<CastService
> CastService::Create(
36 content::BrowserContext
* browser_context
,
37 PrefService
* pref_service
,
38 metrics::CastMetricsServiceClient
* metrics_service_client
,
39 net::URLRequestContextGetter
* request_context_getter
) {
40 return scoped_ptr
<CastService
>(new CastServiceSimple(browser_context
,
42 metrics_service_client
));
45 CastServiceSimple::CastServiceSimple(
46 content::BrowserContext
* browser_context
,
47 PrefService
* pref_service
,
48 metrics::CastMetricsServiceClient
* metrics_service_client
)
49 : CastService(browser_context
, pref_service
, metrics_service_client
) {
52 CastServiceSimple::~CastServiceSimple() {
55 void CastServiceSimple::InitializeInternal() {
56 startup_url_
= GetStartupURL();
59 void CastServiceSimple::FinalizeInternal() {
62 void CastServiceSimple::StartInternal() {
63 // This is the simple version that hard-codes the size.
64 gfx::Size
initial_size(1280, 720);
66 window_
.reset(new CastContentWindow
);
67 web_contents_
= window_
->CreateWebContents(initial_size
, browser_context());
68 window_
->CreateWindowTree(initial_size
, web_contents_
.get());
70 web_contents_
->GetController().LoadURL(startup_url_
, content::Referrer(),
71 ui::PAGE_TRANSITION_TYPED
,
75 void CastServiceSimple::StopInternal() {
76 web_contents_
->GetRenderViewHost()->ClosePage();
77 web_contents_
.reset();
81 } // namespace chromecast