Chromecast: extracts Linux window creation code to a common place.
[chromium-blink-merge.git] / chromecast / browser / service / cast_service_simple.cc
blob9ac90b040e79bd3e974e284a897f1f04a28cf32e
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"
13 #include "url/gurl.h"
15 namespace chromecast {
17 namespace {
19 GURL GetStartupURL() {
20 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
21 const base::CommandLine::StringVector& args = command_line->GetArgs();
23 if (args.empty())
24 return GURL("http://www.google.com/");
26 GURL url(args[0]);
27 if (url.is_valid() && url.has_scheme())
28 return url;
30 return net::FilePathToFileURL(base::FilePath(args[0]));
33 } // namespace
35 // static
36 CastService* CastService::Create(
37 content::BrowserContext* browser_context,
38 net::URLRequestContextGetter* request_context_getter,
39 const OptInStatsChangedCallback& opt_in_stats_callback) {
40 return new CastServiceSimple(browser_context, opt_in_stats_callback);
43 CastServiceSimple::CastServiceSimple(
44 content::BrowserContext* browser_context,
45 const OptInStatsChangedCallback& opt_in_stats_callback)
46 : CastService(browser_context, opt_in_stats_callback) {
49 CastServiceSimple::~CastServiceSimple() {
52 void CastServiceSimple::Initialize() {
55 void CastServiceSimple::StartInternal() {
56 // This is the simple version that hard-codes the size.
57 gfx::Size initial_size(1280, 720);
59 window_.reset(new CastContentWindow);
60 web_contents_ = window_->Create(initial_size, browser_context());
62 web_contents_->GetController().LoadURL(GetStartupURL(),
63 content::Referrer(),
64 ui::PAGE_TRANSITION_TYPED,
65 std::string());
68 void CastServiceSimple::StopInternal() {
69 web_contents_->GetRenderViewHost()->ClosePage();
70 web_contents_.reset();
71 window_.reset();
74 } // namespace chromecast