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