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 2119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2225 // or the favicon url wasn't obtained before the load started. This assumes | 2227 // or the favicon url wasn't obtained before the load started. This assumes |
| 2226 // the later. | 2228 // the later. |
| 2227 // TODO(sky): Need a way to set the favicon that doesn't involve generating | 2229 // TODO(sky): Need a way to set the favicon that doesn't involve generating |
| 2228 // its url. | 2230 // its url. |
| 2229 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer)); | 2231 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer)); |
| 2230 } | 2232 } |
| 2231 new_url->set_safe_for_autoreplace(true); | 2233 new_url->set_safe_for_autoreplace(true); |
| 2232 url_model->Add(new_url); | 2234 url_model->Add(new_url); |
| 2233 } | 2235 } |
| 2234 | 2236 |
| 2237 void TabContents::UpdateThumbnailIfNecessary(const GURL& url) { | |
|
brettw
2011/01/21 00:09:17
I'm always trying to get people to not add stuff t
satorux1
2011/01/21 04:53:43
That's a good idea. Moved accordingly.
| |
| 2238 if (profile()->IsOffTheRecord() || | |
| 2239 (url.SchemeIs("chrome") && url.host() == "newtab")) | |
| 2240 return; | |
| 2241 // TODO(satorux): Add more conditions here to avoid unnecessary | |
| 2242 // thumbnail generation. | |
| 2243 | |
| 2244 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator(); | |
| 2245 const int options = ThumbnailGenerator::kClippedThumbnail; | |
| 2246 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; | |
| 2247 SkBitmap thumbnail = generator->GetThumbnailForRendererWithOptions( | |
| 2248 render_view_host(), options, &clip_result); | |
| 2249 // Failed to generate a thumbnail. Maybe the tab is in the background? | |
| 2250 if (thumbnail.isNull()) | |
| 2251 return; | |
| 2252 | |
| 2253 // Compute the thumbnail score. | |
| 2254 ThumbnailScore score; | |
| 2255 score.at_top = (render_view_host()->last_scroll_offset().height() == 0); | |
| 2256 score.boring_score = ThumbnailGenerator::CalculateBoringScore(&thumbnail); | |
| 2257 score.good_clipping = | |
| 2258 (clip_result == ThumbnailGenerator::kTallerThanWide || | |
| 2259 clip_result == ThumbnailGenerator::kNotClipped); | |
| 2260 | |
| 2261 history::TopSites* top_sites = profile()->GetTopSites(); | |
| 2262 top_sites->SetPageThumbnail(url, thumbnail, score); | |
| 2263 VLOG(1) << "Thumbnail taken for " << url | |
| 2264 << ", at_top: " << score.at_top | |
| 2265 << ", boring_score: " << score.boring_score | |
| 2266 << ", good_clipping: " << score.good_clipping; | |
| 2267 } | |
| 2268 | |
| 2235 void TabContents::OnUserGesture() { | 2269 void TabContents::OnUserGesture() { |
| 2236 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this. | 2270 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this. |
| 2237 DownloadRequestLimiter* limiter = | 2271 DownloadRequestLimiter* limiter = |
| 2238 g_browser_process->download_request_limiter(); | 2272 g_browser_process->download_request_limiter(); |
| 2239 if (limiter) | 2273 if (limiter) |
| 2240 limiter->OnUserGesture(this); | 2274 limiter->OnUserGesture(this); |
| 2241 ExternalProtocolHandler::PermitLaunchUrl(); | 2275 ExternalProtocolHandler::PermitLaunchUrl(); |
| 2242 } | 2276 } |
| 2243 | 2277 |
| 2244 void TabContents::OnFindReply(int request_id, | 2278 void TabContents::OnFindReply(int request_id, |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2371 } | 2405 } |
| 2372 #endif | 2406 #endif |
| 2373 | 2407 |
| 2374 language_state_.LanguageDetermined(language, page_translatable); | 2408 language_state_.LanguageDetermined(language, page_translatable); |
| 2375 | 2409 |
| 2376 std::string lang = language; | 2410 std::string lang = language; |
| 2377 NotificationService::current()->Notify( | 2411 NotificationService::current()->Notify( |
| 2378 NotificationType::TAB_LANGUAGE_DETERMINED, | 2412 NotificationType::TAB_LANGUAGE_DETERMINED, |
| 2379 Source<TabContents>(this), | 2413 Source<TabContents>(this), |
| 2380 Details<std::string>(&lang)); | 2414 Details<std::string>(&lang)); |
| 2415 | |
| 2416 // Generate the thumbnail here if the in-browser thumbnailing is enabled. | |
| 2417 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 2418 switches::kEnableInBrowserThumbnailing)) { | |
| 2419 UpdateThumbnailIfNecessary(url); | |
| 2420 } | |
| 2381 } | 2421 } |
| 2382 | 2422 |
| 2383 void TabContents::OnPageTranslated(int32 page_id, | 2423 void TabContents::OnPageTranslated(int32 page_id, |
| 2384 const std::string& original_lang, | 2424 const std::string& original_lang, |
| 2385 const std::string& translated_lang, | 2425 const std::string& translated_lang, |
| 2386 TranslateErrors::Type error_type) { | 2426 TranslateErrors::Type error_type) { |
| 2387 language_state_.set_current_language(translated_lang); | 2427 language_state_.set_current_language(translated_lang); |
| 2388 language_state_.set_translation_pending(false); | 2428 language_state_.set_translation_pending(false); |
| 2389 PageTranslatedDetails details(original_lang, translated_lang, error_type); | 2429 PageTranslatedDetails details(original_lang, translated_lang, error_type); |
| 2390 NotificationService::current()->Notify( | 2430 NotificationService::current()->Notify( |
| (...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3386 if (pm != NULL) { | 3426 if (pm != NULL) { |
| 3387 if (pm->MaybeUsePreloadedPage(this, url)) { | 3427 if (pm->MaybeUsePreloadedPage(this, url)) { |
| 3388 // TODO(tburkard): If the preloaded page has not finished preloading | 3428 // TODO(tburkard): If the preloaded page has not finished preloading |
| 3389 // yet, we should not do this. | 3429 // yet, we should not do this. |
| 3390 DidStopLoading(); | 3430 DidStopLoading(); |
| 3391 return true; | 3431 return true; |
| 3392 } | 3432 } |
| 3393 } | 3433 } |
| 3394 return false; | 3434 return false; |
| 3395 } | 3435 } |
| OLD | NEW |