Chromium Code Reviews| 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::ClipResult clip_result = ThumbnailGenerator::kNotClipped; | |
| 2239 SkBitmap thumbnail = generator->GetThumbnailForRendererWithOptions( | |
| 2240 render_view_host(), options, &clip_result); | |
| 2241 // Failed to generate a thumbnail. Maybe the tab is in the background? | |
| 2242 if (thumbnail.isNull()) | |
| 2243 return; | |
| 2244 | |
| 2245 // Compute the thumbnail score. | |
| 2246 ThumbnailScore score; | |
| 2247 score.at_top = (render_view_host()->last_scroll_offset().height() == 0); | |
| 2248 score.boring_score = ThumbnailGenerator::CalculateBoringScore(&thumbnail); | |
| 2249 score.good_clipping = | |
| 2250 (clip_result == ThumbnailGenerator::kTallerThanWide || | |
| 2251 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 | |
|
brettw
2011/01/20 00:30:51
Style nit: probably don't need these extra lines h
satorux1
2011/01/20 05:43:39
Done.
| |
| 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 // Generate the thumbnail here if the in-browser thumbnailing is enabled. | |
| 2411 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 2412 switches::kEnableInBrowserThumbnailing)) { | |
| 2413 UpdateThumbnailIfNecessary(url); | |
| 2414 } | |
| 2373 } | 2415 } |
| 2374 | 2416 |
| 2375 void TabContents::OnPageTranslated(int32 page_id, | 2417 void TabContents::OnPageTranslated(int32 page_id, |
| 2376 const std::string& original_lang, | 2418 const std::string& original_lang, |
| 2377 const std::string& translated_lang, | 2419 const std::string& translated_lang, |
| 2378 TranslateErrors::Type error_type) { | 2420 TranslateErrors::Type error_type) { |
| 2379 language_state_.set_current_language(translated_lang); | 2421 language_state_.set_current_language(translated_lang); |
| 2380 language_state_.set_translation_pending(false); | 2422 language_state_.set_translation_pending(false); |
| 2381 PageTranslatedDetails details(original_lang, translated_lang, error_type); | 2423 PageTranslatedDetails details(original_lang, translated_lang, error_type); |
| 2382 NotificationService::current()->Notify( | 2424 NotificationService::current()->Notify( |
| (...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3371 } | 3413 } |
| 3372 | 3414 |
| 3373 void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) { | 3415 void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) { |
| 3374 render_manager_.SwapInRenderViewHost(rvh); | 3416 render_manager_.SwapInRenderViewHost(rvh); |
| 3375 } | 3417 } |
| 3376 | 3418 |
| 3377 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 3419 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 3378 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 3420 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
| 3379 rwh_view->SetSize(view()->GetContainerSize()); | 3421 rwh_view->SetSize(view()->GetContainerSize()); |
| 3380 } | 3422 } |
| OLD | NEW |