Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: chrome/browser/ui/browser.cc

Issue 6854035: Move blocked content from TabContents to TabContentsWrapper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/ui/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <shellapi.h> 8 #include <shellapi.h>
9 #include <windows.h> 9 #include <windows.h>
10 #endif // OS_WIN 10 #endif // OS_WIN
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 #include "chrome/browser/sync/profile_sync_service.h" 68 #include "chrome/browser/sync/profile_sync_service.h"
69 #include "chrome/browser/sync/sync_ui_util.h" 69 #include "chrome/browser/sync/sync_ui_util.h"
70 #include "chrome/browser/tab_closeable_state_watcher.h" 70 #include "chrome/browser/tab_closeable_state_watcher.h"
71 #include "chrome/browser/tab_contents/background_contents.h" 71 #include "chrome/browser/tab_contents/background_contents.h"
72 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" 72 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h"
73 #include "chrome/browser/tabs/tab_finder.h" 73 #include "chrome/browser/tabs/tab_finder.h"
74 #include "chrome/browser/tabs/tab_strip_model.h" 74 #include "chrome/browser/tabs/tab_strip_model.h"
75 #include "chrome/browser/ui/browser_list.h" 75 #include "chrome/browser/ui/browser_list.h"
76 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" 76 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h"
77 #include "chrome/browser/ui/browser_window.h" 77 #include "chrome/browser/ui/browser_window.h"
78 #include "chrome/browser/ui/content_settings/content_settings_tab_helper.h"
78 #include "chrome/browser/ui/download/download_tab_helper.h" 79 #include "chrome/browser/ui/download/download_tab_helper.h"
79 #include "chrome/browser/ui/find_bar/find_bar.h" 80 #include "chrome/browser/ui/find_bar/find_bar.h"
80 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 81 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
81 #include "chrome/browser/ui/find_bar/find_tab_helper.h" 82 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
82 #include "chrome/browser/ui/omnibox/location_bar.h" 83 #include "chrome/browser/ui/omnibox/location_bar.h"
83 #include "chrome/browser/ui/options/options_window.h" 84 #include "chrome/browser/ui/options/options_window.h"
84 #include "chrome/browser/ui/panels/panel.h" 85 #include "chrome/browser/ui/panels/panel.h"
85 #include "chrome/browser/ui/panels/panel_manager.h" 86 #include "chrome/browser/ui/panels/panel_manager.h"
86 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" 87 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
87 #include "chrome/browser/ui/status_bubble.h" 88 #include "chrome/browser/ui/status_bubble.h"
(...skipping 2798 matching lines...) Expand 10 before | Expand all | Expand 10 after
2886 // navigation, so we don't have to worry about flickering. 2887 // navigation, so we don't have to worry about flickering.
2887 if (changed_flags & TabContents::INVALIDATE_URL) 2888 if (changed_flags & TabContents::INVALIDATE_URL)
2888 UpdateCommandsForTabState(); 2889 UpdateCommandsForTabState();
2889 } 2890 }
2890 2891
2891 void Browser::AddNewContents(TabContents* source, 2892 void Browser::AddNewContents(TabContents* source,
2892 TabContents* new_contents, 2893 TabContents* new_contents,
2893 WindowOpenDisposition disposition, 2894 WindowOpenDisposition disposition,
2894 const gfx::Rect& initial_pos, 2895 const gfx::Rect& initial_pos,
2895 bool user_gesture) { 2896 bool user_gesture) {
2896 // No code for this yet 2897 // No code for this yet.
2897 DCHECK(disposition != SAVE_TO_DISK); 2898 DCHECK(disposition != SAVE_TO_DISK);
2898 // Can't create a new contents for the current tab - invalid case. 2899 // Can't create a new contents for the current tab - invalid case.
2899 DCHECK(disposition != CURRENT_TAB); 2900 DCHECK(disposition != CURRENT_TAB);
2900 2901
2902 TabContentsWrapper* source_wrapper = NULL;
2903 ContentSettingsTabHelper* source_content_settings = NULL;
2904 TabContentsWrapper* new_wrapper = new TabContentsWrapper(new_contents);
2905 if (source) {
2906 source_wrapper = TabContentsWrapper::GetCurrentWrapperForContents(source);
2907 source_content_settings = source_wrapper->content_settings_tab_helper();
2908 }
2909
2910 if (source_wrapper) {
2911 // Handle blocking of all contents.
2912 if (source_content_settings->all_contents_blocked()) {
2913 source_content_settings->AddTabContents(new_wrapper,
2914 disposition,
2915 initial_pos,
2916 user_gesture);
2917 return;
2918 }
2919
2920 // Handle blocking of popups.
2921 if ((disposition == NEW_POPUP) && !user_gesture &&
2922 !CommandLine::ForCurrentProcess()->HasSwitch(
2923 switches::kDisablePopupBlocking)) {
2924 // Unrequested popups from normal pages are constrained unless they're in
2925 // the whitelist. The popup owner will handle checking this.
2926 GetConstrainingContents(source_wrapper)->content_settings_tab_helper()->
2927 AddPopup(new_wrapper, initial_pos);
2928 return;
2929 }
2930
2931 new_contents->DisassociateFromPopupCount();
2932 }
2933
2901 // TODO(beng): This belongs behind the platform-specific View interface. 2934 // TODO(beng): This belongs behind the platform-specific View interface.
2902 // That's why it's there. http://crbug.com/78853 2935 // That's why it's there. http://crbug.com/78853
2903 #if defined(OS_CHROMEOS) 2936 #if defined(OS_CHROMEOS)
2904 if (disposition == NEW_POPUP) { 2937 if (disposition == NEW_POPUP) {
2905 // If the popup is bigger than a given factor of the screen, then 2938 // If the popup is bigger than a given factor of the screen, then
2906 // turn it into a foreground tab (on chrome os only) 2939 // turn it into a foreground tab (on chrome os only)
2907 // Also check for width or height == 0, which would otherwise indicate 2940 // Also check for width or height == 0, which would otherwise indicate
2908 // a tab sized popup window. 2941 // a tab sized popup window.
2909 GdkScreen* screen = gdk_screen_get_default(); 2942 GdkScreen* screen = gdk_screen_get_default();
2910 int max_width = gdk_screen_get_width(screen) * kPopupMaxWidthFactor; 2943 int max_width = gdk_screen_get_width(screen) * kPopupMaxWidthFactor;
2911 int max_height = gdk_screen_get_height(screen) * kPopupMaxHeightFactor; 2944 int max_height = gdk_screen_get_height(screen) * kPopupMaxHeightFactor;
2912 if (initial_pos.width() > max_width || initial_pos.width() == 0 || 2945 if (initial_pos.width() > max_width || initial_pos.width() == 0 ||
2913 initial_pos.height() > max_height || initial_pos.height() == 0) { 2946 initial_pos.height() > max_height || initial_pos.height() == 0) {
2914 disposition = NEW_FOREGROUND_TAB; 2947 disposition = NEW_FOREGROUND_TAB;
2915 } 2948 }
2916 } 2949 }
2917 #endif 2950 #endif
2918 2951
2919 TabContentsWrapper* wrapper = new TabContentsWrapper(new_contents); 2952 browser::NavigateParams params(this, new_wrapper);
2920 browser::NavigateParams params(this, wrapper);
2921 params.source_contents = 2953 params.source_contents =
2922 tabstrip_model()->GetTabContentsAt( 2954 source ? tabstrip_model()->GetTabContentsAt(
2923 tabstrip_model()->GetWrapperIndex(source)); 2955 tabstrip_model()->GetWrapperIndex(source))
2956 : NULL;
2924 params.disposition = disposition; 2957 params.disposition = disposition;
2925 params.window_bounds = initial_pos; 2958 params.window_bounds = initial_pos;
2926 params.show_window = true; 2959 params.show_window = true;
2927 browser::Navigate(&params); 2960 browser::Navigate(&params);
2961
2962 if (source) {
2963 NotificationService::current()->Notify(
2964 NotificationType::TAB_ADDED,
2965 Source<TabContentsDelegate>(source->delegate()),
2966 Details<TabContents>(source));
2967 }
2928 } 2968 }
2929 2969
2930 void Browser::ActivateContents(TabContents* contents) { 2970 void Browser::ActivateContents(TabContents* contents) {
2931 tab_handler_->GetTabStripModel()->SelectTabContentsAt( 2971 tab_handler_->GetTabStripModel()->SelectTabContentsAt(
2932 tab_handler_->GetTabStripModel()->GetWrapperIndex(contents), false); 2972 tab_handler_->GetTabStripModel()->GetWrapperIndex(contents), false);
2933 window_->Activate(); 2973 window_->Activate();
2934 } 2974 }
2935 2975
2936 void Browser::DeactivateContents(TabContents* contents) { 2976 void Browser::DeactivateContents(TabContents* contents) {
2937 window_->Deactivate(); 2977 window_->Deactivate();
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
3193 return; 3233 return;
3194 3234
3195 TabContents* current_tab = GetSelectedTabContents(); 3235 TabContents* current_tab = GetSelectedTabContents();
3196 // We make this check for the case of minimized windows, unit tests, etc. 3236 // We make this check for the case of minimized windows, unit tests, etc.
3197 if (platform_util::IsVisible(current_tab->GetNativeView()) && 3237 if (platform_util::IsVisible(current_tab->GetNativeView()) &&
3198 ui::Animation::ShouldRenderRichAnimation()) { 3238 ui::Animation::ShouldRenderRichAnimation()) {
3199 DownloadStartedAnimation::Show(current_tab); 3239 DownloadStartedAnimation::Show(current_tab);
3200 } 3240 }
3201 #endif 3241 #endif
3202 3242
3203 // If the download occurs in a new tab, close it 3243 // If the download occurs in a new tab, close it.
3244 TabContentsWrapper* wrapper =
3245 TabContentsWrapper::GetCurrentWrapperForContents(tab);
3204 if (tab->controller().IsInitialNavigation() && 3246 if (tab->controller().IsInitialNavigation() &&
3205 GetConstrainingContents(tab) == tab && tab_count() > 1) { 3247 GetConstrainingContents(wrapper) == wrapper && tab_count() > 1) {
3206 CloseContents(tab); 3248 CloseContents(tab);
3207 } 3249 }
3208 } 3250 }
3209 3251
3210 void Browser::ShowPageInfo(Profile* profile, 3252 void Browser::ShowPageInfo(Profile* profile,
3211 const GURL& url, 3253 const GURL& url,
3212 const NavigationEntry::SSLStatus& ssl, 3254 const NavigationEntry::SSLStatus& ssl,
3213 bool show_history) { 3255 bool show_history) {
3214 window()->ShowPageInfo(profile, url, ssl, show_history); 3256 window()->ShowPageInfo(profile, url, ssl, show_history);
3215 } 3257 }
(...skipping 20 matching lines...) Expand all
3236 } 3278 }
3237 3279
3238 void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { 3280 void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
3239 window()->HandleKeyboardEvent(event); 3281 window()->HandleKeyboardEvent(event);
3240 } 3282 }
3241 3283
3242 void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) { 3284 void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) {
3243 window()->ShowRepostFormWarningDialog(tab_contents); 3285 window()->ShowRepostFormWarningDialog(tab_contents);
3244 } 3286 }
3245 3287
3246 void Browser::ShowContentSettingsPage(ContentSettingsType content_type) {
3247 ShowOptionsTab(
3248 chrome::kContentSettingsExceptionsSubPage + std::string(kHashMark) +
3249 ContentSettingsHandler::ContentSettingsTypeToGroupName(content_type));
3250 }
3251
3252 void Browser::ShowCollectedCookiesDialog(TabContents *tab_contents) {
3253 window()->ShowCollectedCookiesDialog(tab_contents);
3254 }
3255
3256 bool Browser::ShouldAddNavigationToHistory( 3288 bool Browser::ShouldAddNavigationToHistory(
3257 const history::HistoryAddPageArgs& add_page_args, 3289 const history::HistoryAddPageArgs& add_page_args,
3258 NavigationType::Type navigation_type) { 3290 NavigationType::Type navigation_type) {
3259 // Don't update history if running as app. 3291 // Don't update history if running as app.
3260 return !IsApplication(); 3292 return !IsApplication();
3261 } 3293 }
3262 3294
3263 void Browser::ContentRestrictionsChanged(TabContents* source) { 3295 void Browser::ContentRestrictionsChanged(TabContents* source) {
3264 UpdateCommandsForContentRestrictionState(); 3296 UpdateCommandsForContentRestrictionState();
3265 } 3297 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
3329 window()->ConfirmSetDefaultSearchProvider(tab_contents, template_url, 3361 window()->ConfirmSetDefaultSearchProvider(tab_contents, template_url,
3330 template_url_model); 3362 template_url_model);
3331 } 3363 }
3332 3364
3333 void Browser::ConfirmAddSearchProvider(const TemplateURL* template_url, 3365 void Browser::ConfirmAddSearchProvider(const TemplateURL* template_url,
3334 Profile* profile) { 3366 Profile* profile) {
3335 window()->ConfirmAddSearchProvider(template_url, profile); 3367 window()->ConfirmAddSearchProvider(template_url, profile);
3336 } 3368 }
3337 3369
3338 /////////////////////////////////////////////////////////////////////////////// 3370 ///////////////////////////////////////////////////////////////////////////////
3371 // Browser, ContentSettingsTabHelperDelegate implementation:
3372
3373 TabContentsWrapper* Browser::GetConstrainingContents(
3374 TabContentsWrapper* source) {
3375 return source;
3376 }
3377
3378 void Browser::ShowContentSettingsPage(ContentSettingsType content_type) {
3379 ShowOptionsTab(
3380 chrome::kContentSettingsExceptionsSubPage + std::string(kHashMark) +
3381 ContentSettingsHandler::ContentSettingsTypeToGroupName(content_type));
3382 }
3383
3384 void Browser::ShowCollectedCookiesDialog(TabContents *tab_contents) {
3385 window()->ShowCollectedCookiesDialog(tab_contents);
3386 }
3387
3388 ///////////////////////////////////////////////////////////////////////////////
3339 // Browser, SelectFileDialog::Listener implementation: 3389 // Browser, SelectFileDialog::Listener implementation:
3340 3390
3341 void Browser::FileSelected(const FilePath& path, int index, void* params) { 3391 void Browser::FileSelected(const FilePath& path, int index, void* params) {
3342 profile_->set_last_selected_directory(path.DirName()); 3392 profile_->set_last_selected_directory(path.DirName());
3343 GURL file_url = net::FilePathToFileURL(path); 3393 GURL file_url = net::FilePathToFileURL(path);
3344 if (!file_url.is_empty()) 3394 if (!file_url.is_empty())
3345 OpenURL(file_url, GURL(), CURRENT_TAB, PageTransition::TYPED); 3395 OpenURL(file_url, GURL(), CURRENT_TAB, PageTransition::TYPED);
3346 } 3396 }
3347 3397
3348 /////////////////////////////////////////////////////////////////////////////// 3398 ///////////////////////////////////////////////////////////////////////////////
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after
4207 4257
4208 // static 4258 // static
4209 Browser* Browser::GetOrCreateTabbedBrowser(Profile* profile) { 4259 Browser* Browser::GetOrCreateTabbedBrowser(Profile* profile) {
4210 Browser* browser = GetTabbedBrowser(profile, false); 4260 Browser* browser = GetTabbedBrowser(profile, false);
4211 if (!browser) 4261 if (!browser)
4212 browser = Browser::Create(profile); 4262 browser = Browser::Create(profile);
4213 return browser; 4263 return browser;
4214 } 4264 }
4215 4265
4216 void Browser::SetAsDelegate(TabContentsWrapper* tab, Browser* delegate) { 4266 void Browser::SetAsDelegate(TabContentsWrapper* tab, Browser* delegate) {
4267 // TabContents...
4217 tab->tab_contents()->set_delegate(delegate); 4268 tab->tab_contents()->set_delegate(delegate);
4218 tab->set_delegate(delegate); 4269 tab->set_delegate(delegate);
4270
4271 // ...and all the helpers.
4272 tab->content_settings_tab_helper()->set_delegate(delegate);
4219 tab->search_engine_tab_helper()->set_delegate(delegate); 4273 tab->search_engine_tab_helper()->set_delegate(delegate);
4220 } 4274 }
4221 4275
4222 void Browser::FindInPage(bool find_next, bool forward_direction) { 4276 void Browser::FindInPage(bool find_next, bool forward_direction) {
4223 ShowFindBar(); 4277 ShowFindBar();
4224 if (find_next) { 4278 if (find_next) {
4225 string16 find_text; 4279 string16 find_text;
4226 #if defined(OS_MACOSX) 4280 #if defined(OS_MACOSX)
4227 // We always want to search for the contents of the find pasteboard on OS X. 4281 // We always want to search for the contents of the find pasteboard on OS X.
4228 find_text = GetFindPboardText(); 4282 find_text = GetFindPboardText();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
4341 INSTANT_COMMIT_PRESSED_ENTER); 4395 INSTANT_COMMIT_PRESSED_ENTER);
4342 // HideInstant is invoked after release so that InstantController is not 4396 // HideInstant is invoked after release so that InstantController is not
4343 // active when HideInstant asks it for its state. 4397 // active when HideInstant asks it for its state.
4344 HideInstant(); 4398 HideInstant();
4345 preview_contents->controller().PruneAllButActive(); 4399 preview_contents->controller().PruneAllButActive();
4346 tab_handler_->GetTabStripModel()->AddTabContents( 4400 tab_handler_->GetTabStripModel()->AddTabContents(
4347 preview_contents, 4401 preview_contents,
4348 -1, 4402 -1,
4349 instant()->last_transition_type(), 4403 instant()->last_transition_type(),
4350 TabStripModel::ADD_SELECTED); 4404 TabStripModel::ADD_SELECTED);
4351 instant()->CompleteRelease(preview_contents->tab_contents()); 4405 instant()->CompleteRelease(preview_contents);
4352 return true; 4406 return true;
4353 } 4407 }
4354 // The omnibox currently doesn't use other dispositions, so we don't attempt 4408 // The omnibox currently doesn't use other dispositions, so we don't attempt
4355 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add 4409 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add
4356 // support for the new disposition. 4410 // support for the new disposition.
4357 NOTREACHED(); 4411 NOTREACHED();
4358 return false; 4412 return false;
4359 } 4413 }
4360 4414
4361 void Browser::CreateInstantIfNecessary() { 4415 void Browser::CreateInstantIfNecessary() {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
4427 // The page transition below is only for the purpose of inserting the tab. 4481 // The page transition below is only for the purpose of inserting the tab.
4428 browser->AddTab(view_source_contents, PageTransition::LINK); 4482 browser->AddTab(view_source_contents, PageTransition::LINK);
4429 } 4483 }
4430 4484
4431 if (profile_->HasSessionService()) { 4485 if (profile_->HasSessionService()) {
4432 SessionService* session_service = profile_->GetSessionService(); 4486 SessionService* session_service = profile_->GetSessionService();
4433 if (session_service) 4487 if (session_service)
4434 session_service->TabRestored(&view_source_contents->controller(), false); 4488 session_service->TabRestored(&view_source_contents->controller(), false);
4435 } 4489 }
4436 } 4490 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698