| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromecast/browser/service/cast_service_simple.h" | 5 #include "chromecast/browser/service/cast_service_simple.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "chromecast/browser/cast_content_window.h" | 9 #include "chromecast/browser/cast_content_window.h" |
| 10 #include "chromecast/browser/cast_window_manager.h" |
| 10 #include "content/public/browser/render_view_host.h" | 11 #include "content/public/browser/render_view_host.h" |
| 11 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 12 #include "net/base/filename_util.h" | 13 #include "net/base/filename_util.h" |
| 13 #include "net/url_request/url_request_context_getter.h" | 14 #include "net/url_request/url_request_context_getter.h" |
| 14 | 15 |
| 15 namespace chromecast { | 16 namespace chromecast { |
| 16 namespace shell { | 17 namespace shell { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 GURL GetStartupURL() { | 21 GURL GetStartupURL() { |
| 21 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 22 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 22 const base::CommandLine::StringVector& args = command_line->GetArgs(); | 23 const base::CommandLine::StringVector& args = command_line->GetArgs(); |
| 23 | 24 |
| 24 if (args.empty()) | 25 if (args.empty()) |
| 25 return GURL("http://www.google.com/"); | 26 return GURL("http://www.google.com/"); |
| 26 | 27 |
| 27 GURL url(args[0]); | 28 GURL url(args[0]); |
| 28 if (url.is_valid() && url.has_scheme()) | 29 if (url.is_valid() && url.has_scheme()) |
| 29 return url; | 30 return url; |
| 30 | 31 |
| 31 return net::FilePathToFileURL( | 32 return net::FilePathToFileURL( |
| 32 base::MakeAbsoluteFilePath(base::FilePath(args[0]))); | 33 base::MakeAbsoluteFilePath(base::FilePath(args[0]))); |
| 33 } | 34 } |
| 34 | 35 |
| 35 } // namespace | 36 } // namespace |
| 36 | 37 |
| 37 CastServiceSimple::CastServiceSimple( | 38 CastServiceSimple::CastServiceSimple( |
| 38 content::BrowserContext* browser_context, | 39 content::BrowserContext* browser_context, |
| 39 PrefService* pref_service) | 40 PrefService* pref_service, |
| 40 : CastService(browser_context, pref_service) { | 41 CastWindowManager* cast_window_manager) |
| 42 : CastService(browser_context, pref_service), |
| 43 cast_window_manager_(cast_window_manager) { |
| 41 } | 44 } |
| 42 | 45 |
| 43 CastServiceSimple::~CastServiceSimple() { | 46 CastServiceSimple::~CastServiceSimple() { |
| 44 } | 47 } |
| 45 | 48 |
| 46 void CastServiceSimple::InitializeInternal() { | 49 void CastServiceSimple::InitializeInternal() { |
| 47 startup_url_ = GetStartupURL(); | 50 startup_url_ = GetStartupURL(); |
| 48 } | 51 } |
| 49 | 52 |
| 50 void CastServiceSimple::FinalizeInternal() { | 53 void CastServiceSimple::FinalizeInternal() { |
| 51 } | 54 } |
| 52 | 55 |
| 53 void CastServiceSimple::StartInternal() { | 56 void CastServiceSimple::StartInternal() { |
| 54 window_.reset(new CastContentWindow); | 57 window_.reset(new CastContentWindow); |
| 55 web_contents_ = window_->CreateWebContents(browser_context()); | 58 web_contents_ = window_->CreateWebContents(browser_context()); |
| 56 window_->CreateWindowTree(web_contents_.get()); | 59 cast_window_manager_->AddWebContents(web_contents_.get(), false, false); |
| 57 | 60 |
| 58 web_contents_->GetController().LoadURL(startup_url_, content::Referrer(), | 61 web_contents_->GetController().LoadURL(startup_url_, content::Referrer(), |
| 59 ui::PAGE_TRANSITION_TYPED, | 62 ui::PAGE_TRANSITION_TYPED, |
| 60 std::string()); | 63 std::string()); |
| 61 } | 64 } |
| 62 | 65 |
| 63 void CastServiceSimple::StopInternal() { | 66 void CastServiceSimple::StopInternal() { |
| 64 web_contents_->ClosePage(); | 67 web_contents_->ClosePage(); |
| 65 web_contents_.reset(); | 68 web_contents_.reset(); |
| 66 window_.reset(); | 69 window_.reset(); |
| 67 } | 70 } |
| 68 | 71 |
| 69 } // namespace shell | 72 } // namespace shell |
| 70 } // namespace chromecast | 73 } // namespace chromecast |
| OLD | NEW |