| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tab_contents/tab_contents.h" | 5 #include "chrome/browser/tab_contents/tab_contents.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 #include "chrome/browser/search_engines/template_url_fetcher_ui_callbacks.h" | 68 #include "chrome/browser/search_engines/template_url_fetcher_ui_callbacks.h" |
| 69 #include "chrome/browser/search_engines/template_url_model.h" | 69 #include "chrome/browser/search_engines/template_url_model.h" |
| 70 #include "chrome/browser/sessions/session_types.h" | 70 #include "chrome/browser/sessions/session_types.h" |
| 71 #include "chrome/browser/tab_contents/infobar_delegate.h" | 71 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 72 #include "chrome/browser/tab_contents/interstitial_page.h" | 72 #include "chrome/browser/tab_contents/interstitial_page.h" |
| 73 #include "chrome/browser/tab_contents/navigation_entry.h" | 73 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 74 #include "chrome/browser/tab_contents/provisional_load_details.h" | 74 #include "chrome/browser/tab_contents/provisional_load_details.h" |
| 75 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | 75 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
| 76 #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" | 76 #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" |
| 77 #include "chrome/browser/tab_contents/tab_contents_view.h" | 77 #include "chrome/browser/tab_contents/tab_contents_view.h" |
| 78 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
| 78 #include "chrome/browser/tab_contents/web_navigation_observer.h" | 79 #include "chrome/browser/tab_contents/web_navigation_observer.h" |
| 79 #include "chrome/browser/translate/page_translated_details.h" | 80 #include "chrome/browser/translate/page_translated_details.h" |
| 80 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" | 81 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" |
| 81 #include "chrome/browser/ui/find_bar/find_bar_state.h" | 82 #include "chrome/browser/ui/find_bar/find_bar_state.h" |
| 82 #include "chrome/common/bindings_policy.h" | 83 #include "chrome/common/bindings_policy.h" |
| 83 #include "chrome/common/chrome_switches.h" | 84 #include "chrome/common/chrome_switches.h" |
| 84 #include "chrome/common/content_restriction.h" | 85 #include "chrome/common/content_restriction.h" |
| 85 #include "chrome/common/extensions/extension.h" | 86 #include "chrome/common/extensions/extension.h" |
| 86 #include "chrome/common/extensions/extension_action.h" | 87 #include "chrome/common/extensions/extension_action.h" |
| 87 #include "chrome/common/extensions/extension_icon_set.h" | 88 #include "chrome/common/extensions/extension_icon_set.h" |
| 88 #include "chrome/common/extensions/extension_resource.h" | 89 #include "chrome/common/extensions/extension_resource.h" |
| 89 #include "chrome/common/extensions/url_pattern.h" | 90 #include "chrome/common/extensions/url_pattern.h" |
| 90 #include "chrome/common/navigation_types.h" | 91 #include "chrome/common/navigation_types.h" |
| 91 #include "chrome/common/net/url_request_context_getter.h" | 92 #include "chrome/common/net/url_request_context_getter.h" |
| 92 #include "chrome/common/notification_service.h" | 93 #include "chrome/common/notification_service.h" |
| 93 #include "chrome/common/pref_names.h" | 94 #include "chrome/common/pref_names.h" |
| 94 #include "chrome/common/render_messages.h" | 95 #include "chrome/common/render_messages.h" |
| 95 #include "chrome/common/render_messages_params.h" | 96 #include "chrome/common/render_messages_params.h" |
| 97 #include "chrome/common/thumbnail_score.h" |
| 96 #include "chrome/common/url_constants.h" | 98 #include "chrome/common/url_constants.h" |
| 97 #include "gfx/codec/png_codec.h" | 99 #include "gfx/codec/png_codec.h" |
| 98 #include "grit/chromium_strings.h" | 100 #include "grit/chromium_strings.h" |
| 99 #include "grit/generated_resources.h" | 101 #include "grit/generated_resources.h" |
| 100 #include "grit/locale_settings.h" | 102 #include "grit/locale_settings.h" |
| 101 #include "grit/platform_locale_settings.h" | 103 #include "grit/platform_locale_settings.h" |
| 102 #include "grit/theme_resources.h" | 104 #include "grit/theme_resources.h" |
| 103 #include "net/base/net_util.h" | 105 #include "net/base/net_util.h" |
| 104 #include "net/base/registry_controlled_domain.h" | 106 #include "net/base/registry_controlled_domain.h" |
| 105 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 107 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| (...skipping 2111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2217 // or the favicon url wasn't obtained before the load started. This assumes | 2219 // or the favicon url wasn't obtained before the load started. This assumes |
| 2218 // the later. | 2220 // the later. |
| 2219 // TODO(sky): Need a way to set the favicon that doesn't involve generating | 2221 // TODO(sky): Need a way to set the favicon that doesn't involve generating |
| 2220 // its url. | 2222 // its url. |
| 2221 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer)); | 2223 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer)); |
| 2222 } | 2224 } |
| 2223 new_url->set_safe_for_autoreplace(true); | 2225 new_url->set_safe_for_autoreplace(true); |
| 2224 url_model->Add(new_url); | 2226 url_model->Add(new_url); |
| 2225 } | 2227 } |
| 2226 | 2228 |
| 2229 void TabContents::UpdateThumbnailIfNecessary(const GURL& url) { |
| 2230 if (profile()->IsOffTheRecord() || |
| 2231 (url.SchemeIs("chrome") && url.host() == "newtab")) |
| 2232 return; |
| 2233 // TODO(satorux): Add more conditions here to avoid unnecessary |
| 2234 // thumbnail generation. |
| 2235 |
| 2236 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator(); |
| 2237 const int options = (ThumbnailGenerator::kClippedThumbnail | |
| 2238 ThumbnailGenerator::kBoringScore); |
| 2239 ThumbnailGenerator::ThumbnailResult result; |
| 2240 SkBitmap thumbnail = generator->GetThumbnailForRendererWithOptions( |
| 2241 render_view_host(), options, &result); |
| 2242 // Failed to generate a thumbnail. Maybe the tab is in the background? |
| 2243 if (thumbnail.isNull()) |
| 2244 return; |
| 2245 |
| 2246 ThumbnailScore score; |
| 2247 score.at_top = (render_view_host()->last_scroll_offset().height() == 0); |
| 2248 score.boring_score = result.boring_score; |
| 2249 score.good_clipping = |
| 2250 (result.clip_result == ThumbnailGenerator::kTallerThanWide || |
| 2251 result.clip_result == ThumbnailGenerator::kNotClipped); |
| 2252 |
| 2253 history::TopSites* top_sites = profile()->GetTopSites(); |
| 2254 top_sites->SetPageThumbnail(url, thumbnail, score); |
| 2255 VLOG(1) << "Thumbnail taken for " << url |
| 2256 << ", at_top: " << score.at_top |
| 2257 << ", boring_score: " << score.boring_score |
| 2258 << ", good_clipping: " << score.good_clipping; |
| 2259 } |
| 2260 |
| 2261 |
| 2262 |
| 2227 void TabContents::OnUserGesture() { | 2263 void TabContents::OnUserGesture() { |
| 2228 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this. | 2264 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this. |
| 2229 DownloadRequestLimiter* limiter = | 2265 DownloadRequestLimiter* limiter = |
| 2230 g_browser_process->download_request_limiter(); | 2266 g_browser_process->download_request_limiter(); |
| 2231 if (limiter) | 2267 if (limiter) |
| 2232 limiter->OnUserGesture(this); | 2268 limiter->OnUserGesture(this); |
| 2233 ExternalProtocolHandler::PermitLaunchUrl(); | 2269 ExternalProtocolHandler::PermitLaunchUrl(); |
| 2234 } | 2270 } |
| 2235 | 2271 |
| 2236 void TabContents::OnFindReply(int request_id, | 2272 void TabContents::OnFindReply(int request_id, |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2363 } | 2399 } |
| 2364 #endif | 2400 #endif |
| 2365 | 2401 |
| 2366 language_state_.LanguageDetermined(language, page_translatable); | 2402 language_state_.LanguageDetermined(language, page_translatable); |
| 2367 | 2403 |
| 2368 std::string lang = language; | 2404 std::string lang = language; |
| 2369 NotificationService::current()->Notify( | 2405 NotificationService::current()->Notify( |
| 2370 NotificationType::TAB_LANGUAGE_DETERMINED, | 2406 NotificationType::TAB_LANGUAGE_DETERMINED, |
| 2371 Source<TabContents>(this), | 2407 Source<TabContents>(this), |
| 2372 Details<std::string>(&lang)); | 2408 Details<std::string>(&lang)); |
| 2409 |
| 2410 UpdateThumbnailIfNecessary(url); |
| 2373 } | 2411 } |
| 2374 | 2412 |
| 2375 void TabContents::OnPageTranslated(int32 page_id, | 2413 void TabContents::OnPageTranslated(int32 page_id, |
| 2376 const std::string& original_lang, | 2414 const std::string& original_lang, |
| 2377 const std::string& translated_lang, | 2415 const std::string& translated_lang, |
| 2378 TranslateErrors::Type error_type) { | 2416 TranslateErrors::Type error_type) { |
| 2379 language_state_.set_current_language(translated_lang); | 2417 language_state_.set_current_language(translated_lang); |
| 2380 language_state_.set_translation_pending(false); | 2418 language_state_.set_translation_pending(false); |
| 2381 PageTranslatedDetails details(original_lang, translated_lang, error_type); | 2419 PageTranslatedDetails details(original_lang, translated_lang, error_type); |
| 2382 NotificationService::current()->Notify( | 2420 NotificationService::current()->Notify( |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2701 void TabContents::UpdateEncoding(RenderViewHost* render_view_host, | 2739 void TabContents::UpdateEncoding(RenderViewHost* render_view_host, |
| 2702 const std::string& encoding) { | 2740 const std::string& encoding) { |
| 2703 set_encoding(encoding); | 2741 set_encoding(encoding); |
| 2704 } | 2742 } |
| 2705 | 2743 |
| 2706 void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) { | 2744 void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) { |
| 2707 if (delegate()) | 2745 if (delegate()) |
| 2708 delegate()->UpdateTargetURL(this, url); | 2746 delegate()->UpdateTargetURL(this, url); |
| 2709 } | 2747 } |
| 2710 | 2748 |
| 2711 void TabContents::UpdateThumbnail(const GURL& url, | |
| 2712 const SkBitmap& bitmap, | |
| 2713 const ThumbnailScore& score) { | |
| 2714 if (profile()->IsOffTheRecord()) | |
| 2715 return; | |
| 2716 | |
| 2717 // Tell History about this thumbnail | |
| 2718 history::TopSites* ts = profile()->GetTopSites(); | |
| 2719 if (ts) | |
| 2720 ts->SetPageThumbnail(url, bitmap, score); | |
| 2721 } | |
| 2722 | |
| 2723 void TabContents::UpdateInspectorSetting(const std::string& key, | 2749 void TabContents::UpdateInspectorSetting(const std::string& key, |
| 2724 const std::string& value) { | 2750 const std::string& value) { |
| 2725 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value); | 2751 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value); |
| 2726 } | 2752 } |
| 2727 | 2753 |
| 2728 void TabContents::ClearInspectorSettings() { | 2754 void TabContents::ClearInspectorSettings() { |
| 2729 RenderViewHostDelegateHelper::ClearInspectorSettings(profile()); | 2755 RenderViewHostDelegateHelper::ClearInspectorSettings(profile()); |
| 2730 } | 2756 } |
| 2731 | 2757 |
| 2732 void TabContents::Close(RenderViewHost* rvh) { | 2758 void TabContents::Close(RenderViewHost* rvh) { |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3371 } | 3397 } |
| 3372 | 3398 |
| 3373 void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) { | 3399 void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) { |
| 3374 render_manager_.SwapInRenderViewHost(rvh); | 3400 render_manager_.SwapInRenderViewHost(rvh); |
| 3375 } | 3401 } |
| 3376 | 3402 |
| 3377 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 3403 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 3378 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 3404 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
| 3379 rwh_view->SetSize(view()->GetContainerSize()); | 3405 rwh_view->SetSize(view()->GetContainerSize()); |
| 3380 } | 3406 } |
| OLD | NEW |