Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / chromecast / browser / service / cast_service_simple.cc
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
5 #include "chromecast/browser/service/cast_service_simple.h"
6
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"
14
15 namespace chromecast {
16
17 namespace {
18
19 GURL GetStartupURL() {
20   base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
21   const base::CommandLine::StringVector& args = command_line->GetArgs();
22
23   if (args.empty())
24     return GURL("http://www.google.com/");
25
26   GURL url(args[0]);
27   if (url.is_valid() && url.has_scheme())
28     return url;
29
30   return net::FilePathToFileURL(base::FilePath(args[0]));
31 }
32
33 }  // namespace
34
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);
41 }
42
43 CastServiceSimple::CastServiceSimple(
44     content::BrowserContext* browser_context,
45     const OptInStatsChangedCallback& opt_in_stats_callback)
46     : CastService(browser_context, opt_in_stats_callback) {
47 }
48
49 CastServiceSimple::~CastServiceSimple() {
50 }
51
52 void CastServiceSimple::Initialize() {
53 }
54
55 void CastServiceSimple::StartInternal() {
56   // This is the simple version that hard-codes the size.
57   gfx::Size initial_size(1280, 720);
58
59   window_.reset(new CastContentWindow);
60   web_contents_ = window_->Create(initial_size, browser_context());
61
62   web_contents_->GetController().LoadURL(GetStartupURL(),
63                                          content::Referrer(),
64                                          ui::PAGE_TRANSITION_TYPED,
65                                          std::string());
66 }
67
68 void CastServiceSimple::StopInternal() {
69   web_contents_->GetRenderViewHost()->ClosePage();
70   web_contents_.reset();
71   window_.reset();
72 }
73
74 }  // namespace chromecast