cast_content_browser_client.cc revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
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/shell/browser/cast_content_browser_client.h"
6
7#include "base/command_line.h"
8#include "chromecast/shell/browser/cast_browser_context.h"
9#include "chromecast/shell/browser/cast_browser_main_parts.h"
10#include "chromecast/shell/browser/geolocation/cast_access_token_store.h"
11#include "chromecast/shell/browser/url_request_context_factory.h"
12#include "content/public/browser/certificate_request_result_type.h"
13#include "content/public/browser/render_process_host.h"
14#include "content/public/common/content_descriptors.h"
15#include "content/public/common/content_switches.h"
16#include "content/public/common/url_constants.h"
17#include "content/public/common/web_preferences.h"
18
19namespace chromecast {
20namespace shell {
21
22CastContentBrowserClient::CastContentBrowserClient()
23    : url_request_context_factory_(new URLRequestContextFactory()) {
24}
25
26CastContentBrowserClient::~CastContentBrowserClient() {
27}
28
29content::BrowserMainParts* CastContentBrowserClient::CreateBrowserMainParts(
30    const content::MainFunctionParams& parameters) {
31  shell_browser_main_parts_ =
32      new CastBrowserMainParts(parameters, url_request_context_factory_.get());
33  return shell_browser_main_parts_;
34}
35
36void CastContentBrowserClient::RenderProcessWillLaunch(
37    content::RenderProcessHost* host) {
38}
39
40net::URLRequestContextGetter* CastContentBrowserClient::CreateRequestContext(
41    content::BrowserContext* browser_context,
42    content::ProtocolHandlerMap* protocol_handlers,
43    content::URLRequestInterceptorScopedVector request_interceptors) {
44  return url_request_context_factory_->CreateMainGetter(
45      browser_context,
46      protocol_handlers,
47      request_interceptors.Pass());
48}
49
50bool CastContentBrowserClient::IsHandledURL(const GURL& url) {
51  if (!url.is_valid())
52    return false;
53
54  static const char* const kProtocolList[] = {
55      url::kBlobScheme,
56      url::kFileSystemScheme,
57      content::kChromeUIScheme,
58      content::kChromeDevToolsScheme,
59      url::kDataScheme,
60  };
61
62  const std::string& scheme = url.scheme();
63  for (size_t i = 0; i < arraysize(kProtocolList); ++i) {
64    if (scheme == kProtocolList[i])
65      return true;
66  }
67  return false;
68}
69
70void CastContentBrowserClient::AppendExtraCommandLineSwitches(
71    base::CommandLine* command_line,
72    int child_process_id) {
73
74  std::string process_type =
75      command_line->GetSwitchValueNative(switches::kProcessType);
76  // Renderer process comamndline
77  if (process_type == switches::kRendererProcess) {
78    // Any browser command-line switches that should be propagated to
79    // the renderer go here.
80  }
81}
82
83content::AccessTokenStore* CastContentBrowserClient::CreateAccessTokenStore() {
84  return new CastAccessTokenStore(shell_browser_main_parts_->browser_context());
85}
86
87void CastContentBrowserClient::OverrideWebkitPrefs(
88    content::RenderViewHost* render_view_host,
89    const GURL& url,
90    content::WebPreferences* prefs) {
91  prefs->allow_scripts_to_close_windows = true;
92  // TODO(lcwu): http://crbug.com/391089. This pref is set to true by default
93  // because some content providers such as YouTube use plain http requests
94  // to retrieve media data chunks while running in a https page. This pref
95  // should be disabled once all the content providers are no longer doing that.
96  prefs->allow_running_insecure_content = true;
97}
98
99std::string CastContentBrowserClient::GetApplicationLocale() {
100  return "en-US";
101}
102
103void CastContentBrowserClient::AllowCertificateError(
104    int render_process_id,
105    int render_view_id,
106    int cert_error,
107    const net::SSLInfo& ssl_info,
108    const GURL& request_url,
109    content::ResourceType resource_type,
110    bool overridable,
111    bool strict_enforcement,
112    bool expired_previous_decision,
113    const base::Callback<void(bool)>& callback,
114    content::CertificateRequestResultType* result) {
115  // Allow developers to override certificate errors.
116  // Otherwise, any fatal certificate errors will cause an abort.
117  *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
118  return;
119}
120
121bool CastContentBrowserClient::CanCreateWindow(
122    const GURL& opener_url,
123    const GURL& opener_top_level_frame_url,
124    const GURL& source_origin,
125    WindowContainerType container_type,
126    const GURL& target_url,
127    const content::Referrer& referrer,
128    WindowOpenDisposition disposition,
129    const blink::WebWindowFeatures& features,
130    bool user_gesture,
131    bool opener_suppressed,
132    content::ResourceContext* context,
133    int render_process_id,
134    int opener_id,
135    bool* no_javascript_access) {
136  *no_javascript_access = true;
137  return false;
138}
139
140void CastContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
141    const base::CommandLine& command_line,
142    int child_process_id,
143    std::vector<content::FileDescriptorInfo>* mappings) {
144}
145
146}  // namespace shell
147}  // namespace chromecast
148