| 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/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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 #include "chrome/browser/sessions/session_service.h" | 65 #include "chrome/browser/sessions/session_service.h" |
| 66 #include "chrome/browser/sessions/session_types.h" | 66 #include "chrome/browser/sessions/session_types.h" |
| 67 #include "chrome/browser/sessions/tab_restore_service.h" | 67 #include "chrome/browser/sessions/tab_restore_service.h" |
| 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/blocked_content/blocked_content_tab_helper.h" |
| 75 #include "chrome/browser/ui/browser_list.h" | 76 #include "chrome/browser/ui/browser_list.h" |
| 76 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" | 77 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" |
| 77 #include "chrome/browser/ui/browser_window.h" | 78 #include "chrome/browser/ui/browser_window.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" |
| (...skipping 2800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2885 // navigation, so we don't have to worry about flickering. | 2886 // navigation, so we don't have to worry about flickering. |
| 2886 if (changed_flags & TabContents::INVALIDATE_URL) | 2887 if (changed_flags & TabContents::INVALIDATE_URL) |
| 2887 UpdateCommandsForTabState(); | 2888 UpdateCommandsForTabState(); |
| 2888 } | 2889 } |
| 2889 | 2890 |
| 2890 void Browser::AddNewContents(TabContents* source, | 2891 void Browser::AddNewContents(TabContents* source, |
| 2891 TabContents* new_contents, | 2892 TabContents* new_contents, |
| 2892 WindowOpenDisposition disposition, | 2893 WindowOpenDisposition disposition, |
| 2893 const gfx::Rect& initial_pos, | 2894 const gfx::Rect& initial_pos, |
| 2894 bool user_gesture) { | 2895 bool user_gesture) { |
| 2895 // No code for this yet | 2896 // No code for this yet. |
| 2896 DCHECK(disposition != SAVE_TO_DISK); | 2897 DCHECK(disposition != SAVE_TO_DISK); |
| 2897 // Can't create a new contents for the current tab - invalid case. | 2898 // Can't create a new contents for the current tab - invalid case. |
| 2898 DCHECK(disposition != CURRENT_TAB); | 2899 DCHECK(disposition != CURRENT_TAB); |
| 2899 | 2900 |
| 2901 TabContentsWrapper* source_wrapper = NULL; |
| 2902 BlockedContentTabHelper* source_blocked_content = NULL; |
| 2903 TabContentsWrapper* new_wrapper = new TabContentsWrapper(new_contents); |
| 2904 if (source) { |
| 2905 source_wrapper = TabContentsWrapper::GetCurrentWrapperForContents(source); |
| 2906 source_blocked_content = source_wrapper->blocked_content_tab_helper(); |
| 2907 } |
| 2908 |
| 2909 if (source_wrapper) { |
| 2910 // Handle blocking of all contents. |
| 2911 if (source_blocked_content->all_contents_blocked()) { |
| 2912 source_blocked_content->AddTabContents(new_wrapper, |
| 2913 disposition, |
| 2914 initial_pos, |
| 2915 user_gesture); |
| 2916 return; |
| 2917 } |
| 2918 |
| 2919 // Handle blocking of popups. |
| 2920 if ((disposition == NEW_POPUP) && !user_gesture && |
| 2921 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 2922 switches::kDisablePopupBlocking)) { |
| 2923 // Unrequested popups from normal pages are constrained unless they're in |
| 2924 // the whitelist. The popup owner will handle checking this. |
| 2925 GetConstrainingContents(source_wrapper)->blocked_content_tab_helper()-> |
| 2926 AddPopup(new_wrapper, initial_pos, user_gesture); |
| 2927 return; |
| 2928 } |
| 2929 |
| 2930 new_contents->DisassociateFromPopupCount(); |
| 2931 } |
| 2932 |
| 2900 // TODO(beng): This belongs behind the platform-specific View interface. | 2933 // TODO(beng): This belongs behind the platform-specific View interface. |
| 2901 // That's why it's there. http://crbug.com/78853 | 2934 // That's why it's there. http://crbug.com/78853 |
| 2902 #if defined(OS_CHROMEOS) | 2935 #if defined(OS_CHROMEOS) |
| 2903 if (disposition == NEW_POPUP) { | 2936 if (disposition == NEW_POPUP) { |
| 2904 // If the popup is bigger than a given factor of the screen, then | 2937 // If the popup is bigger than a given factor of the screen, then |
| 2905 // turn it into a foreground tab (on chrome os only) | 2938 // turn it into a foreground tab (on chrome os only) |
| 2906 // Also check for width or height == 0, which would otherwise indicate | 2939 // Also check for width or height == 0, which would otherwise indicate |
| 2907 // a tab sized popup window. | 2940 // a tab sized popup window. |
| 2908 GdkScreen* screen = gdk_screen_get_default(); | 2941 GdkScreen* screen = gdk_screen_get_default(); |
| 2909 int max_width = gdk_screen_get_width(screen) * kPopupMaxWidthFactor; | 2942 int max_width = gdk_screen_get_width(screen) * kPopupMaxWidthFactor; |
| 2910 int max_height = gdk_screen_get_height(screen) * kPopupMaxHeightFactor; | 2943 int max_height = gdk_screen_get_height(screen) * kPopupMaxHeightFactor; |
| 2911 if (initial_pos.width() > max_width || initial_pos.width() == 0 || | 2944 if (initial_pos.width() > max_width || initial_pos.width() == 0 || |
| 2912 initial_pos.height() > max_height || initial_pos.height() == 0) { | 2945 initial_pos.height() > max_height || initial_pos.height() == 0) { |
| 2913 disposition = NEW_FOREGROUND_TAB; | 2946 disposition = NEW_FOREGROUND_TAB; |
| 2914 } | 2947 } |
| 2915 } | 2948 } |
| 2916 #endif | 2949 #endif |
| 2917 | 2950 |
| 2918 TabContentsWrapper* wrapper = new TabContentsWrapper(new_contents); | 2951 browser::NavigateParams params(this, new_wrapper); |
| 2919 browser::NavigateParams params(this, wrapper); | |
| 2920 params.source_contents = | 2952 params.source_contents = |
| 2921 tabstrip_model()->GetTabContentsAt( | 2953 source ? tabstrip_model()->GetTabContentsAt( |
| 2922 tabstrip_model()->GetWrapperIndex(source)); | 2954 tabstrip_model()->GetWrapperIndex(source)) |
| 2955 : NULL; |
| 2923 params.disposition = disposition; | 2956 params.disposition = disposition; |
| 2924 params.window_bounds = initial_pos; | 2957 params.window_bounds = initial_pos; |
| 2925 // If we create a popup or panel from a non user-gesture, don't activate | 2958 // If we create a popup or panel from a non user-gesture, don't activate |
| 2926 // the new window / panel. | 2959 // the new window / panel. |
| 2927 if (disposition == NEW_POPUP && !user_gesture) | 2960 if (disposition == NEW_POPUP && !user_gesture) |
| 2928 params.window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE; | 2961 params.window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE; |
| 2929 else | 2962 else |
| 2930 params.window_action = browser::NavigateParams::SHOW_WINDOW; | 2963 params.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 2931 browser::Navigate(¶ms); | 2964 browser::Navigate(¶ms); |
| 2965 |
| 2966 if (source) { |
| 2967 NotificationService::current()->Notify( |
| 2968 NotificationType::TAB_ADDED, |
| 2969 Source<TabContentsDelegate>(source->delegate()), |
| 2970 Details<TabContents>(source)); |
| 2971 } |
| 2932 } | 2972 } |
| 2933 | 2973 |
| 2934 void Browser::ActivateContents(TabContents* contents) { | 2974 void Browser::ActivateContents(TabContents* contents) { |
| 2935 tab_handler_->GetTabStripModel()->ActivateTabAt( | 2975 tab_handler_->GetTabStripModel()->ActivateTabAt( |
| 2936 tab_handler_->GetTabStripModel()->GetWrapperIndex(contents), false); | 2976 tab_handler_->GetTabStripModel()->GetWrapperIndex(contents), false); |
| 2937 window_->Activate(); | 2977 window_->Activate(); |
| 2938 } | 2978 } |
| 2939 | 2979 |
| 2940 void Browser::DeactivateContents(TabContents* contents) { | 2980 void Browser::DeactivateContents(TabContents* contents) { |
| 2941 window_->Deactivate(); | 2981 window_->Deactivate(); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3184 return; | 3224 return; |
| 3185 | 3225 |
| 3186 TabContents* current_tab = GetSelectedTabContents(); | 3226 TabContents* current_tab = GetSelectedTabContents(); |
| 3187 // We make this check for the case of minimized windows, unit tests, etc. | 3227 // We make this check for the case of minimized windows, unit tests, etc. |
| 3188 if (platform_util::IsVisible(current_tab->GetNativeView()) && | 3228 if (platform_util::IsVisible(current_tab->GetNativeView()) && |
| 3189 ui::Animation::ShouldRenderRichAnimation()) { | 3229 ui::Animation::ShouldRenderRichAnimation()) { |
| 3190 DownloadStartedAnimation::Show(current_tab); | 3230 DownloadStartedAnimation::Show(current_tab); |
| 3191 } | 3231 } |
| 3192 #endif | 3232 #endif |
| 3193 | 3233 |
| 3194 // If the download occurs in a new tab, close it | 3234 // If the download occurs in a new tab, close it. |
| 3235 TabContentsWrapper* wrapper = |
| 3236 TabContentsWrapper::GetCurrentWrapperForContents(tab); |
| 3195 if (tab->controller().IsInitialNavigation() && | 3237 if (tab->controller().IsInitialNavigation() && |
| 3196 GetConstrainingContents(tab) == tab && tab_count() > 1) { | 3238 GetConstrainingContents(wrapper) == wrapper && tab_count() > 1) { |
| 3197 CloseContents(tab); | 3239 CloseContents(tab); |
| 3198 } | 3240 } |
| 3199 } | 3241 } |
| 3200 | 3242 |
| 3201 void Browser::ShowPageInfo(Profile* profile, | 3243 void Browser::ShowPageInfo(Profile* profile, |
| 3202 const GURL& url, | 3244 const GURL& url, |
| 3203 const NavigationEntry::SSLStatus& ssl, | 3245 const NavigationEntry::SSLStatus& ssl, |
| 3204 bool show_history) { | 3246 bool show_history) { |
| 3205 window()->ShowPageInfo(profile, url, ssl, show_history); | 3247 window()->ShowPageInfo(profile, url, ssl, show_history); |
| 3206 } | 3248 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3319 window()->ConfirmSetDefaultSearchProvider(tab_contents, template_url, | 3361 window()->ConfirmSetDefaultSearchProvider(tab_contents, template_url, |
| 3320 template_url_model); | 3362 template_url_model); |
| 3321 } | 3363 } |
| 3322 | 3364 |
| 3323 void Browser::ConfirmAddSearchProvider(const TemplateURL* template_url, | 3365 void Browser::ConfirmAddSearchProvider(const TemplateURL* template_url, |
| 3324 Profile* profile) { | 3366 Profile* profile) { |
| 3325 window()->ConfirmAddSearchProvider(template_url, profile); | 3367 window()->ConfirmAddSearchProvider(template_url, profile); |
| 3326 } | 3368 } |
| 3327 | 3369 |
| 3328 /////////////////////////////////////////////////////////////////////////////// | 3370 /////////////////////////////////////////////////////////////////////////////// |
| 3371 // Browser, BlockedContentTabHelperDelegate implementation: |
| 3372 |
| 3373 TabContentsWrapper* Browser::GetConstrainingContents( |
| 3374 TabContentsWrapper* source) { |
| 3375 return source; |
| 3376 } |
| 3377 |
| 3378 /////////////////////////////////////////////////////////////////////////////// |
| 3329 // Browser, SelectFileDialog::Listener implementation: | 3379 // Browser, SelectFileDialog::Listener implementation: |
| 3330 | 3380 |
| 3331 void Browser::FileSelected(const FilePath& path, int index, void* params) { | 3381 void Browser::FileSelected(const FilePath& path, int index, void* params) { |
| 3332 profile_->set_last_selected_directory(path.DirName()); | 3382 profile_->set_last_selected_directory(path.DirName()); |
| 3333 GURL file_url = net::FilePathToFileURL(path); | 3383 GURL file_url = net::FilePathToFileURL(path); |
| 3334 if (!file_url.is_empty()) | 3384 if (!file_url.is_empty()) |
| 3335 OpenURL(file_url, GURL(), CURRENT_TAB, PageTransition::TYPED); | 3385 OpenURL(file_url, GURL(), CURRENT_TAB, PageTransition::TYPED); |
| 3336 } | 3386 } |
| 3337 | 3387 |
| 3338 /////////////////////////////////////////////////////////////////////////////// | 3388 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4181 | 4231 |
| 4182 // static | 4232 // static |
| 4183 Browser* Browser::GetOrCreateTabbedBrowser(Profile* profile) { | 4233 Browser* Browser::GetOrCreateTabbedBrowser(Profile* profile) { |
| 4184 Browser* browser = GetTabbedBrowser(profile, false); | 4234 Browser* browser = GetTabbedBrowser(profile, false); |
| 4185 if (!browser) | 4235 if (!browser) |
| 4186 browser = Browser::Create(profile); | 4236 browser = Browser::Create(profile); |
| 4187 return browser; | 4237 return browser; |
| 4188 } | 4238 } |
| 4189 | 4239 |
| 4190 void Browser::SetAsDelegate(TabContentsWrapper* tab, Browser* delegate) { | 4240 void Browser::SetAsDelegate(TabContentsWrapper* tab, Browser* delegate) { |
| 4241 // TabContents... |
| 4191 tab->tab_contents()->set_delegate(delegate); | 4242 tab->tab_contents()->set_delegate(delegate); |
| 4192 tab->set_delegate(delegate); | 4243 tab->set_delegate(delegate); |
| 4244 |
| 4245 // ...and all the helpers. |
| 4246 tab->blocked_content_tab_helper()->set_delegate(delegate); |
| 4193 tab->search_engine_tab_helper()->set_delegate(delegate); | 4247 tab->search_engine_tab_helper()->set_delegate(delegate); |
| 4194 } | 4248 } |
| 4195 | 4249 |
| 4196 void Browser::FindInPage(bool find_next, bool forward_direction) { | 4250 void Browser::FindInPage(bool find_next, bool forward_direction) { |
| 4197 ShowFindBar(); | 4251 ShowFindBar(); |
| 4198 if (find_next) { | 4252 if (find_next) { |
| 4199 string16 find_text; | 4253 string16 find_text; |
| 4200 #if defined(OS_MACOSX) | 4254 #if defined(OS_MACOSX) |
| 4201 // We always want to search for the contents of the find pasteboard on OS X. | 4255 // We always want to search for the contents of the find pasteboard on OS X. |
| 4202 find_text = GetFindPboardText(); | 4256 find_text = GetFindPboardText(); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4315 INSTANT_COMMIT_PRESSED_ENTER); | 4369 INSTANT_COMMIT_PRESSED_ENTER); |
| 4316 // HideInstant is invoked after release so that InstantController is not | 4370 // HideInstant is invoked after release so that InstantController is not |
| 4317 // active when HideInstant asks it for its state. | 4371 // active when HideInstant asks it for its state. |
| 4318 HideInstant(); | 4372 HideInstant(); |
| 4319 preview_contents->controller().PruneAllButActive(); | 4373 preview_contents->controller().PruneAllButActive(); |
| 4320 tab_handler_->GetTabStripModel()->AddTabContents( | 4374 tab_handler_->GetTabStripModel()->AddTabContents( |
| 4321 preview_contents, | 4375 preview_contents, |
| 4322 -1, | 4376 -1, |
| 4323 instant()->last_transition_type(), | 4377 instant()->last_transition_type(), |
| 4324 TabStripModel::ADD_ACTIVE); | 4378 TabStripModel::ADD_ACTIVE); |
| 4325 instant()->CompleteRelease(preview_contents->tab_contents()); | 4379 instant()->CompleteRelease(preview_contents); |
| 4326 return true; | 4380 return true; |
| 4327 } | 4381 } |
| 4328 // The omnibox currently doesn't use other dispositions, so we don't attempt | 4382 // The omnibox currently doesn't use other dispositions, so we don't attempt |
| 4329 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add | 4383 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add |
| 4330 // support for the new disposition. | 4384 // support for the new disposition. |
| 4331 NOTREACHED(); | 4385 NOTREACHED(); |
| 4332 return false; | 4386 return false; |
| 4333 } | 4387 } |
| 4334 | 4388 |
| 4335 void Browser::CreateInstantIfNecessary() { | 4389 void Browser::CreateInstantIfNecessary() { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4414 TabContents* current_tab = GetSelectedTabContents(); | 4468 TabContents* current_tab = GetSelectedTabContents(); |
| 4415 if (current_tab) { | 4469 if (current_tab) { |
| 4416 content_restrictions = current_tab->content_restrictions(); | 4470 content_restrictions = current_tab->content_restrictions(); |
| 4417 NavigationEntry* active_entry = current_tab->controller().GetActiveEntry(); | 4471 NavigationEntry* active_entry = current_tab->controller().GetActiveEntry(); |
| 4418 // See comment in UpdateCommandsForTabState about why we call url(). | 4472 // See comment in UpdateCommandsForTabState about why we call url(). |
| 4419 if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL())) | 4473 if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL())) |
| 4420 content_restrictions |= CONTENT_RESTRICTION_SAVE; | 4474 content_restrictions |= CONTENT_RESTRICTION_SAVE; |
| 4421 } | 4475 } |
| 4422 return content_restrictions; | 4476 return content_restrictions; |
| 4423 } | 4477 } |
| OLD | NEW |