Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chromecast / browser / service / cast_service_simple.cc
blob95a497f892f0d97e73524f95563a2fc7796622ff
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 "base/files/file_util.h"
9 #include "chromecast/browser/cast_content_window.h"
10 #include "content/public/browser/render_view_host.h"
11 #include "content/public/browser/web_contents.h"
12 #include "net/base/filename_util.h"
13 #include "net/url_request/url_request_context_getter.h"
15 namespace chromecast {
16 namespace shell {
18 namespace {
20 GURL GetStartupURL() {
21 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
22 const base::CommandLine::StringVector& args = command_line->GetArgs();
24 if (args.empty())
25 return GURL("http://www.google.com/");
27 GURL url(args[0]);
28 if (url.is_valid() && url.has_scheme())
29 return url;
31 return net::FilePathToFileURL(
32 base::MakeAbsoluteFilePath(base::FilePath(args[0])));
35 } // namespace
37 CastServiceSimple::CastServiceSimple(
38 content::BrowserContext* browser_context,
39 PrefService* pref_service)
40 : CastService(browser_context, pref_service) {
43 CastServiceSimple::~CastServiceSimple() {
46 void CastServiceSimple::InitializeInternal() {
47 startup_url_ = GetStartupURL();
50 void CastServiceSimple::FinalizeInternal() {
53 void CastServiceSimple::StartInternal() {
54 // This is the simple version that hard-codes the size.
55 gfx::Size initial_size(1280, 720);
57 window_.reset(new CastContentWindow);
58 web_contents_ = window_->CreateWebContents(initial_size, browser_context());
59 window_->CreateWindowTree(initial_size, web_contents_.get());
61 web_contents_->GetController().LoadURL(startup_url_, content::Referrer(),
62 ui::PAGE_TRANSITION_TYPED,
63 std::string());
66 void CastServiceSimple::StopInternal() {
67 web_contents_->ClosePage();
68 web_contents_.reset();
69 window_.reset();
72 } // namespace shell
73 } // namespace chromecast