| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/tab_contents/core_tab_helper.h" | 5 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/profiler/scoped_tracker.h" | 13 #include "base/profiler/scoped_tracker.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/search_engines/template_url_service_factory.h" | 17 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_command_controller.h" | 19 #include "chrome/browser/ui/browser_command_controller.h" |
| 20 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
| 21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/render_messages.h" | 22 #include "chrome/common/render_messages.h" |
| 23 #include "chrome/grit/generated_resources.h" | 23 #include "chrome/grit/generated_resources.h" |
| 24 #include "components/guest_view/browser/guest_view_manager.h" | 24 #include "components/guest_view/browser/guest_view_manager.h" |
| 25 #include "components/search_engines/template_url.h" | 25 #include "components/search_engines/template_url.h" |
| 26 #include "components/search_engines/template_url_service.h" | 26 #include "components/search_engines/template_url_service.h" |
| 27 #include "components/strings/grit/components_strings.h" | 27 #include "components/strings/grit/components_strings.h" |
| 28 #include "components/web_cache/browser/web_cache_manager.h" | 28 #include "components/web_cache/browser/web_cache_manager.h" |
| 29 #include "content/public/browser/navigation_controller.h" |
| 30 #include "content/public/browser/navigation_entry.h" |
| 29 #include "content/public/browser/render_frame_host.h" | 31 #include "content/public/browser/render_frame_host.h" |
| 30 #include "content/public/browser/render_process_host.h" | 32 #include "content/public/browser/render_process_host.h" |
| 31 #include "content/public/browser/render_view_host.h" | 33 #include "content/public/browser/render_view_host.h" |
| 32 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 33 #include "content/public/common/context_menu_params.h" | 35 #include "content/public/common/context_menu_params.h" |
| 36 #include "content/public/common/ssl_status.h" |
| 34 #include "net/base/load_states.h" | 37 #include "net/base/load_states.h" |
| 38 #include "net/base/url_util.h" |
| 35 #include "net/http/http_request_headers.h" | 39 #include "net/http/http_request_headers.h" |
| 36 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
| 37 | 41 |
| 38 using content::WebContents; | 42 using content::WebContents; |
| 39 | 43 |
| 40 namespace { | 44 namespace { |
| 41 | 45 |
| 42 const int kImageSearchThumbnailMinSize = 300 * 300; | 46 const int kImageSearchThumbnailMinSize = 300 * 300; |
| 43 const int kImageSearchThumbnailMaxWidth = 600; | 47 const int kImageSearchThumbnailMaxWidth = 600; |
| 44 const int kImageSearchThumbnailMaxHeight = 600; | 48 const int kImageSearchThumbnailMaxHeight = 600; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 status_text)); | 244 status_text)); |
| 241 } | 245 } |
| 242 | 246 |
| 243 //////////////////////////////////////////////////////////////////////////////// | 247 //////////////////////////////////////////////////////////////////////////////// |
| 244 // WebContentsObserver overrides | 248 // WebContentsObserver overrides |
| 245 | 249 |
| 246 void CoreTabHelper::DidStartLoading() { | 250 void CoreTabHelper::DidStartLoading() { |
| 247 UpdateContentRestrictions(0); | 251 UpdateContentRestrictions(0); |
| 248 } | 252 } |
| 249 | 253 |
| 254 void CoreTabHelper::DocumentOnLoadCompletedInMainFrame() { |
| 255 bool allow_localhost = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 256 switches::kAllowInsecureLocalhost); |
| 257 if (!allow_localhost) |
| 258 return; |
| 259 |
| 260 content::NavigationEntry* entry = |
| 261 web_contents()->GetController().GetLastCommittedEntry(); |
| 262 if (!net::IsLocalhost(entry->GetURL().host())) |
| 263 return; |
| 264 |
| 265 content::SSLStatus ssl_status = entry->GetSSL(); |
| 266 bool is_cert_error = net::IsCertStatusError(ssl_status.cert_status) && |
| 267 !net::IsCertStatusMinorError(ssl_status.cert_status); |
| 268 if (!is_cert_error) |
| 269 return; |
| 270 |
| 271 web_contents()->GetMainFrame()->AddMessageToConsole( |
| 272 content::CONSOLE_MESSAGE_LEVEL_WARNING, |
| 273 base::StringPrintf( |
| 274 "This site does not have a valid SSL " |
| 275 "certificate! Without SSL, your site's and " |
| 276 "visitors' data is vulnerable to theft and " |
| 277 "tampering. Get a valid SSL certificate before" |
| 278 " releasing your website to the public.")); |
| 279 } |
| 280 |
| 250 void CoreTabHelper::WasShown() { | 281 void CoreTabHelper::WasShown() { |
| 251 web_cache::WebCacheManager::GetInstance()->ObserveActivity( | 282 web_cache::WebCacheManager::GetInstance()->ObserveActivity( |
| 252 web_contents()->GetRenderProcessHost()->GetID()); | 283 web_contents()->GetRenderProcessHost()->GetID()); |
| 253 } | 284 } |
| 254 | 285 |
| 255 void CoreTabHelper::WebContentsDestroyed() { | 286 void CoreTabHelper::WebContentsDestroyed() { |
| 256 // OnCloseStarted isn't called in unit tests. | 287 // OnCloseStarted isn't called in unit tests. |
| 257 if (!close_start_time_.is_null()) { | 288 if (!close_start_time_.is_null()) { |
| 258 bool fast_tab_close_enabled = | 289 bool fast_tab_close_enabled = |
| 259 base::CommandLine::ForCurrentProcess()->HasSwitch( | 290 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 DCHECK(!content_type.empty()); | 386 DCHECK(!content_type.empty()); |
| 356 open_url_params.uses_post = true; | 387 open_url_params.uses_post = true; |
| 357 open_url_params.post_data = content::ResourceRequestBody::CreateFromBytes( | 388 open_url_params.post_data = content::ResourceRequestBody::CreateFromBytes( |
| 358 post_data.data(), post_data.size()); | 389 post_data.data(), post_data.size()); |
| 359 open_url_params.extra_headers += base::StringPrintf( | 390 open_url_params.extra_headers += base::StringPrintf( |
| 360 "%s: %s\r\n", net::HttpRequestHeaders::kContentType, | 391 "%s: %s\r\n", net::HttpRequestHeaders::kContentType, |
| 361 content_type.c_str()); | 392 content_type.c_str()); |
| 362 } | 393 } |
| 363 web_contents()->OpenURL(open_url_params); | 394 web_contents()->OpenURL(open_url_params); |
| 364 } | 395 } |
| OLD | NEW |