| // Copyright 2014 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "chromecast/browser/service/cast_service_simple.h" |
| |
| #include <string> |
| |
| #include "base/command_line.h" |
| #include "base/files/file_util.h" |
| #include "base/time/time.h" |
| #include "chromecast/browser/cast_browser_process.h" |
| #include "chromecast/browser/cast_content_window.h" |
| #include "chromecast/browser/cast_web_service.h" |
| #include "chromecast/browser/cast_web_view_factory.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/common/content_switches.h" |
| #include "net/base/filename_util.h" |
| |
| namespace chromecast { |
| namespace shell { |
| |
| namespace { |
| |
| GURL GetStartupURL() { |
| base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| const base::CommandLine::StringVector& args = command_line->GetArgs(); |
| |
| if (args.empty()) |
| return GURL("http://www.google.com/"); |
| |
| GURL url(args[0]); |
| if (url.is_valid() && url.has_scheme()) |
| return url; |
| |
| return net::FilePathToFileURL( |
| base::MakeAbsoluteFilePath(base::FilePath(args[0]))); |
| } |
| |
| } // namespace |
| |
| CastServiceSimple::CastServiceSimple(content::BrowserContext* browser_context, |
| CastWindowManager* window_manager) |
| : web_view_factory_(std::make_unique<CastWebViewFactory>(browser_context)), |
| web_service_(std::make_unique<CastWebService>(browser_context, |
| web_view_factory_.get(), |
| window_manager)) { |
| shell::CastBrowserProcess::GetInstance()->SetWebViewFactory( |
| web_view_factory_.get()); |
| } |
| |
| CastServiceSimple::~CastServiceSimple() { |
| } |
| |
| void CastServiceSimple::InitializeInternal() { |
| startup_url_ = GetStartupURL(); |
| } |
| |
| void CastServiceSimple::FinalizeInternal() { |
| } |
| |
| void CastServiceSimple::StartInternal() { |
| if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { |
| return; |
| } |
| |
| CastWebView::CreateParams create_params; |
| create_params.delegate = weak_factory_.GetWeakPtr(); |
| create_params.window_delegate = weak_factory_.GetWeakPtr(); |
| |
| ::chromecast::mojom::CastWebViewParamsPtr params = |
| ::chromecast::mojom::CastWebViewParams::New(); |
| params->enabled_for_dev = true; |
| |
| cast_web_view_ = |
| web_service_->CreateWebViewInternal(create_params, std::move(params)); |
| cast_web_view_->cast_web_contents()->LoadUrl(startup_url_); |
| cast_web_view_->window()->GrantScreenAccess(); |
| cast_web_view_->window()->CreateWindow( |
| ::chromecast::mojom::ZOrder::APP, |
| chromecast::VisibilityPriority::STICKY_ACTIVITY); |
| } |
| |
| void CastServiceSimple::StopInternal() { |
| if (cast_web_view_) { |
| cast_web_view_->cast_web_contents()->ClosePage(); |
| } |
| cast_web_view_.reset(); |
| } |
| |
| void CastServiceSimple::OnWindowDestroyed() {} |
| |
| bool CastServiceSimple::CanHandleGesture(GestureType gesture_type) { |
| return false; |
| } |
| |
| void CastServiceSimple::ConsumeGesture( |
| GestureType gesture_type, |
| GestureHandledCallback handled_callback) { |
| std::move(handled_callback).Run(false); |
| } |
| |
| void CastServiceSimple::OnVisibilityChange(VisibilityType visibility_type) {} |
| |
| } // namespace shell |
| } // namespace chromecast |