| 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2"; | 178 "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2"; |
| 179 | 179 |
| 180 // The URL for the privacy dashboard. | 180 // The URL for the privacy dashboard. |
| 181 const char kPrivacyDashboardUrl[] = "https://www.google.com/dashboard"; | 181 const char kPrivacyDashboardUrl[] = "https://www.google.com/dashboard"; |
| 182 | 182 |
| 183 // How long we wait before updating the browser chrome while loading a page. | 183 // How long we wait before updating the browser chrome while loading a page. |
| 184 const int kUIUpdateCoalescingTimeMS = 200; | 184 const int kUIUpdateCoalescingTimeMS = 200; |
| 185 | 185 |
| 186 const char kHashMark[] = "#"; | 186 const char kHashMark[] = "#"; |
| 187 | 187 |
| 188 #if defined(OS_CHROMEOS) | |
| 189 // If a popup window is bigger than this fraction of the screen on chrome os, | |
| 190 // turn it into a tab | |
| 191 const float kPopupMaxWidthFactor = 0.5; | |
| 192 const float kPopupMaxHeightFactor = 0.6; | |
| 193 #endif | |
| 194 | |
| 195 } // namespace | 188 } // namespace |
| 196 | 189 |
| 197 extern bool g_log_bug53991; | 190 extern bool g_log_bug53991; |
| 198 | 191 |
| 199 /////////////////////////////////////////////////////////////////////////////// | 192 /////////////////////////////////////////////////////////////////////////////// |
| 200 // Browser, Constructors, Creation, Showing: | 193 // Browser, Constructors, Creation, Showing: |
| 201 | 194 |
| 202 Browser::Browser(Type type, Profile* profile) | 195 Browser::Browser(Type type, Profile* profile) |
| 203 : type_(type), | 196 : type_(type), |
| 204 profile_(profile), | 197 profile_(profile), |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 } | 330 } |
| 338 | 331 |
| 339 // static | 332 // static |
| 340 Browser* Browser::Create(Profile* profile) { | 333 Browser* Browser::Create(Profile* profile) { |
| 341 Browser* browser = new Browser(TYPE_NORMAL, profile); | 334 Browser* browser = new Browser(TYPE_NORMAL, profile); |
| 342 browser->InitBrowserWindow(); | 335 browser->InitBrowserWindow(); |
| 343 return browser; | 336 return browser; |
| 344 } | 337 } |
| 345 | 338 |
| 346 // static | 339 // static |
| 347 Browser* Browser::CreateForPopup(Type type, | |
| 348 Profile* profile, | |
| 349 TabContents* new_contents, | |
| 350 const gfx::Rect& initial_bounds) { | |
| 351 DCHECK(type & TYPE_POPUP); | |
| 352 Browser* browser = new Browser(type, profile); | |
| 353 browser->set_override_bounds(initial_bounds); | |
| 354 browser->InitBrowserWindow(); | |
| 355 TabContentsWrapper* wrapper = new TabContentsWrapper(new_contents); | |
| 356 browser->tabstrip_model()->AppendTabContents(wrapper, true); | |
| 357 return browser; | |
| 358 } | |
| 359 | |
| 360 // static | |
| 361 Browser* Browser::CreateForType(Type type, Profile* profile) { | 340 Browser* Browser::CreateForType(Type type, Profile* profile) { |
| 362 Browser* browser = new Browser(type, profile); | 341 Browser* browser = new Browser(type, profile); |
| 363 browser->InitBrowserWindow(); | 342 browser->InitBrowserWindow(); |
| 364 return browser; | 343 return browser; |
| 365 } | 344 } |
| 366 | 345 |
| 367 // static | 346 // static |
| 368 Browser* Browser::CreateForApp(const std::string& app_name, | 347 Browser* Browser::CreateForApp(const std::string& app_name, |
| 369 const gfx::Size& window_size, | 348 const gfx::Size& window_size, |
| 370 Profile* profile, | 349 Profile* profile, |
| (...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1128 return false; | 1107 return false; |
| 1129 controller.GoToIndex(index); | 1108 controller.GoToIndex(index); |
| 1130 return true; | 1109 return true; |
| 1131 } | 1110 } |
| 1132 | 1111 |
| 1133 browser::NavigateParams Browser::GetSingletonTabNavigateParams( | 1112 browser::NavigateParams Browser::GetSingletonTabNavigateParams( |
| 1134 const GURL& url) { | 1113 const GURL& url) { |
| 1135 browser::NavigateParams params(this, url, PageTransition::AUTO_BOOKMARK); | 1114 browser::NavigateParams params(this, url, PageTransition::AUTO_BOOKMARK); |
| 1136 params.disposition = SINGLETON_TAB; | 1115 params.disposition = SINGLETON_TAB; |
| 1137 params.window_action = browser::NavigateParams::SHOW_WINDOW; | 1116 params.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 1117 params.user_gesture = true; |
| 1138 return params; | 1118 return params; |
| 1139 } | 1119 } |
| 1140 | 1120 |
| 1141 void Browser::ShowSingletonTab(const GURL& url) { | 1121 void Browser::ShowSingletonTab(const GURL& url) { |
| 1142 browser::NavigateParams params(GetSingletonTabNavigateParams(url)); | 1122 browser::NavigateParams params(GetSingletonTabNavigateParams(url)); |
| 1143 browser::Navigate(¶ms); | 1123 browser::Navigate(¶ms); |
| 1144 } | 1124 } |
| 1145 | 1125 |
| 1146 void Browser::UpdateCommandsForFullscreenMode(bool is_fullscreen) { | 1126 void Browser::UpdateCommandsForFullscreenMode(bool is_fullscreen) { |
| 1147 #if !defined(OS_MACOSX) | 1127 #if !defined(OS_MACOSX) |
| (...skipping 1717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2865 WindowOpenDisposition disposition, | 2845 WindowOpenDisposition disposition, |
| 2866 PageTransition::Type transition) { | 2846 PageTransition::Type transition) { |
| 2867 browser::NavigateParams params(this, url, transition); | 2847 browser::NavigateParams params(this, url, transition); |
| 2868 params.source_contents = | 2848 params.source_contents = |
| 2869 tabstrip_model()->GetTabContentsAt( | 2849 tabstrip_model()->GetTabContentsAt( |
| 2870 tabstrip_model()->GetWrapperIndex(source)); | 2850 tabstrip_model()->GetWrapperIndex(source)); |
| 2871 params.referrer = referrer; | 2851 params.referrer = referrer; |
| 2872 params.disposition = disposition; | 2852 params.disposition = disposition; |
| 2873 params.tabstrip_add_types = TabStripModel::ADD_NONE; | 2853 params.tabstrip_add_types = TabStripModel::ADD_NONE; |
| 2874 params.window_action = browser::NavigateParams::SHOW_WINDOW; | 2854 params.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 2855 params.user_gesture = true; |
| 2875 browser::Navigate(¶ms); | 2856 browser::Navigate(¶ms); |
| 2876 } | 2857 } |
| 2877 | 2858 |
| 2878 void Browser::NavigationStateChanged(const TabContents* source, | 2859 void Browser::NavigationStateChanged(const TabContents* source, |
| 2879 unsigned changed_flags) { | 2860 unsigned changed_flags) { |
| 2880 // Only update the UI when something visible has changed. | 2861 // Only update the UI when something visible has changed. |
| 2881 if (changed_flags) | 2862 if (changed_flags) |
| 2882 ScheduleUIUpdate(source, changed_flags); | 2863 ScheduleUIUpdate(source, changed_flags); |
| 2883 | 2864 |
| 2884 // We don't schedule updates to commands since they will only change once per | 2865 // We don't schedule updates to commands since they will only change once per |
| 2885 // navigation, so we don't have to worry about flickering. | 2866 // navigation, so we don't have to worry about flickering. |
| 2886 if (changed_flags & TabContents::INVALIDATE_URL) | 2867 if (changed_flags & TabContents::INVALIDATE_URL) |
| 2887 UpdateCommandsForTabState(); | 2868 UpdateCommandsForTabState(); |
| 2888 } | 2869 } |
| 2889 | 2870 |
| 2890 void Browser::AddNewContents(TabContents* source, | 2871 void Browser::AddNewContents(TabContents* source, |
| 2891 TabContents* new_contents, | 2872 TabContents* new_contents, |
| 2892 WindowOpenDisposition disposition, | 2873 WindowOpenDisposition disposition, |
| 2893 const gfx::Rect& initial_pos, | 2874 const gfx::Rect& initial_pos, |
| 2894 bool user_gesture) { | 2875 bool user_gesture) { |
| 2895 // No code for this yet | 2876 // No code for this yet |
| 2896 DCHECK(disposition != SAVE_TO_DISK); | 2877 DCHECK(disposition != SAVE_TO_DISK); |
| 2897 // Can't create a new contents for the current tab - invalid case. | 2878 // Can't create a new contents for the current tab - invalid case. |
| 2898 DCHECK(disposition != CURRENT_TAB); | 2879 DCHECK(disposition != CURRENT_TAB); |
| 2899 | 2880 |
| 2900 // TODO(beng): This belongs behind the platform-specific View interface. | |
| 2901 // That's why it's there. http://crbug.com/78853 | |
| 2902 #if defined(OS_CHROMEOS) | |
| 2903 if (disposition == NEW_POPUP) { | |
| 2904 // If the popup is bigger than a given factor of the screen, then | |
| 2905 // turn it into a foreground tab (on chrome os only) | |
| 2906 // Also check for width or height == 0, which would otherwise indicate | |
| 2907 // a tab sized popup window. | |
| 2908 GdkScreen* screen = gdk_screen_get_default(); | |
| 2909 int max_width = gdk_screen_get_width(screen) * kPopupMaxWidthFactor; | |
| 2910 int max_height = gdk_screen_get_height(screen) * kPopupMaxHeightFactor; | |
| 2911 if (initial_pos.width() > max_width || initial_pos.width() == 0 || | |
| 2912 initial_pos.height() > max_height || initial_pos.height() == 0) { | |
| 2913 disposition = NEW_FOREGROUND_TAB; | |
| 2914 } | |
| 2915 } | |
| 2916 #endif | |
| 2917 | |
| 2918 TabContentsWrapper* wrapper = new TabContentsWrapper(new_contents); | 2881 TabContentsWrapper* wrapper = new TabContentsWrapper(new_contents); |
| 2919 browser::NavigateParams params(this, wrapper); | 2882 browser::NavigateParams params(this, wrapper); |
| 2920 params.source_contents = | 2883 params.source_contents = |
| 2921 tabstrip_model()->GetTabContentsAt( | 2884 tabstrip_model()->GetTabContentsAt( |
| 2922 tabstrip_model()->GetWrapperIndex(source)); | 2885 tabstrip_model()->GetWrapperIndex(source)); |
| 2923 params.disposition = disposition; | 2886 params.disposition = disposition; |
| 2924 params.window_bounds = initial_pos; | 2887 params.window_bounds = initial_pos; |
| 2925 // If we create a popup or panel from a non user-gesture, don't activate | 2888 params.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 2926 // the new window / panel. | 2889 params.user_gesture = user_gesture; |
| 2927 if (disposition == NEW_POPUP && !user_gesture) | |
| 2928 params.window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE; | |
| 2929 else | |
| 2930 params.window_action = browser::NavigateParams::SHOW_WINDOW; | |
| 2931 browser::Navigate(¶ms); | 2890 browser::Navigate(¶ms); |
| 2932 } | 2891 } |
| 2933 | 2892 |
| 2934 void Browser::ActivateContents(TabContents* contents) { | 2893 void Browser::ActivateContents(TabContents* contents) { |
| 2935 tab_handler_->GetTabStripModel()->ActivateTabAt( | 2894 tab_handler_->GetTabStripModel()->ActivateTabAt( |
| 2936 tab_handler_->GetTabStripModel()->GetWrapperIndex(contents), false); | 2895 tab_handler_->GetTabStripModel()->GetWrapperIndex(contents), false); |
| 2937 window_->Activate(); | 2896 window_->Activate(); |
| 2938 } | 2897 } |
| 2939 | 2898 |
| 2940 void Browser::DeactivateContents(TabContents* contents) { | 2899 void Browser::DeactivateContents(TabContents* contents) { |
| (...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4410 // The page transition below is only for the purpose of inserting the tab. | 4369 // The page transition below is only for the purpose of inserting the tab. |
| 4411 browser->AddTab(view_source_contents, PageTransition::LINK); | 4370 browser->AddTab(view_source_contents, PageTransition::LINK); |
| 4412 } | 4371 } |
| 4413 | 4372 |
| 4414 if (profile_->HasSessionService()) { | 4373 if (profile_->HasSessionService()) { |
| 4415 SessionService* session_service = profile_->GetSessionService(); | 4374 SessionService* session_service = profile_->GetSessionService(); |
| 4416 if (session_service) | 4375 if (session_service) |
| 4417 session_service->TabRestored(&view_source_contents->controller(), false); | 4376 session_service->TabRestored(&view_source_contents->controller(), false); |
| 4418 } | 4377 } |
| 4419 } | 4378 } |
| OLD | NEW |