| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2"; | 180 "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2"; |
| 181 | 181 |
| 182 // The URL for the privacy dashboard. | 182 // The URL for the privacy dashboard. |
| 183 const char kPrivacyDashboardUrl[] = "https://www.google.com/dashboard"; | 183 const char kPrivacyDashboardUrl[] = "https://www.google.com/dashboard"; |
| 184 | 184 |
| 185 // How long we wait before updating the browser chrome while loading a page. | 185 // How long we wait before updating the browser chrome while loading a page. |
| 186 const int kUIUpdateCoalescingTimeMS = 200; | 186 const int kUIUpdateCoalescingTimeMS = 200; |
| 187 | 187 |
| 188 const char kHashMark[] = "#"; | 188 const char kHashMark[] = "#"; |
| 189 | 189 |
| 190 #if defined(OS_CHROMEOS) | |
| 191 // If a popup window is bigger than this fraction of the screen on chrome os, | |
| 192 // turn it into a tab | |
| 193 const float kPopupMaxWidthFactor = 0.5; | |
| 194 const float kPopupMaxHeightFactor = 0.6; | |
| 195 #endif | |
| 196 | |
| 197 } // namespace | 190 } // namespace |
| 198 | 191 |
| 199 extern bool g_log_bug53991; | 192 extern bool g_log_bug53991; |
| 200 | 193 |
| 201 /////////////////////////////////////////////////////////////////////////////// | 194 /////////////////////////////////////////////////////////////////////////////// |
| 202 // Browser, Constructors, Creation, Showing: | 195 // Browser, Constructors, Creation, Showing: |
| 203 | 196 |
| 204 Browser::Browser(Type type, Profile* profile) | 197 Browser::Browser(Type type, Profile* profile) |
| 205 : type_(type), | 198 : type_(type), |
| 206 profile_(profile), | 199 profile_(profile), |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 } | 334 } |
| 342 | 335 |
| 343 // static | 336 // static |
| 344 Browser* Browser::Create(Profile* profile) { | 337 Browser* Browser::Create(Profile* profile) { |
| 345 Browser* browser = new Browser(TYPE_NORMAL, profile); | 338 Browser* browser = new Browser(TYPE_NORMAL, profile); |
| 346 browser->InitBrowserWindow(); | 339 browser->InitBrowserWindow(); |
| 347 return browser; | 340 return browser; |
| 348 } | 341 } |
| 349 | 342 |
| 350 // static | 343 // static |
| 351 Browser* Browser::CreateForPopup(Type type, | |
| 352 Profile* profile, | |
| 353 TabContents* new_contents, | |
| 354 const gfx::Rect& initial_bounds) { | |
| 355 DCHECK(type & TYPE_POPUP); | |
| 356 Browser* browser = new Browser(type, profile); | |
| 357 browser->set_override_bounds(initial_bounds); | |
| 358 browser->InitBrowserWindow(); | |
| 359 TabContentsWrapper* wrapper = new TabContentsWrapper(new_contents); | |
| 360 browser->tabstrip_model()->AppendTabContents(wrapper, true); | |
| 361 return browser; | |
| 362 } | |
| 363 | |
| 364 // static | |
| 365 Browser* Browser::CreateForType(Type type, Profile* profile) { | 344 Browser* Browser::CreateForType(Type type, Profile* profile) { |
| 366 Browser* browser = new Browser(type, profile); | 345 Browser* browser = new Browser(type, profile); |
| 367 browser->InitBrowserWindow(); | 346 browser->InitBrowserWindow(); |
| 368 return browser; | 347 return browser; |
| 369 } | 348 } |
| 370 | 349 |
| 371 // static | 350 // static |
| 372 Browser* Browser::CreateForApp(const std::string& app_name, | 351 Browser* Browser::CreateForApp(const std::string& app_name, |
| 373 const gfx::Size& window_size, | 352 const gfx::Size& window_size, |
| 374 Profile* profile, | 353 Profile* profile, |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 return false; | 1121 return false; |
| 1143 controller.GoToIndex(index); | 1122 controller.GoToIndex(index); |
| 1144 return true; | 1123 return true; |
| 1145 } | 1124 } |
| 1146 | 1125 |
| 1147 browser::NavigateParams Browser::GetSingletonTabNavigateParams( | 1126 browser::NavigateParams Browser::GetSingletonTabNavigateParams( |
| 1148 const GURL& url) { | 1127 const GURL& url) { |
| 1149 browser::NavigateParams params(this, url, PageTransition::AUTO_BOOKMARK); | 1128 browser::NavigateParams params(this, url, PageTransition::AUTO_BOOKMARK); |
| 1150 params.disposition = SINGLETON_TAB; | 1129 params.disposition = SINGLETON_TAB; |
| 1151 params.window_action = browser::NavigateParams::SHOW_WINDOW; | 1130 params.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 1131 params.user_gesture = true; |
| 1152 return params; | 1132 return params; |
| 1153 } | 1133 } |
| 1154 | 1134 |
| 1155 void Browser::ShowSingletonTab(const GURL& url) { | 1135 void Browser::ShowSingletonTab(const GURL& url) { |
| 1156 browser::NavigateParams params(GetSingletonTabNavigateParams(url)); | 1136 browser::NavigateParams params(GetSingletonTabNavigateParams(url)); |
| 1157 browser::Navigate(¶ms); | 1137 browser::Navigate(¶ms); |
| 1158 } | 1138 } |
| 1159 | 1139 |
| 1160 void Browser::UpdateCommandsForFullscreenMode(bool is_fullscreen) { | 1140 void Browser::UpdateCommandsForFullscreenMode(bool is_fullscreen) { |
| 1161 #if !defined(OS_MACOSX) | 1141 #if !defined(OS_MACOSX) |
| (...skipping 1716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2878 WindowOpenDisposition disposition, | 2858 WindowOpenDisposition disposition, |
| 2879 PageTransition::Type transition) { | 2859 PageTransition::Type transition) { |
| 2880 browser::NavigateParams params(this, url, transition); | 2860 browser::NavigateParams params(this, url, transition); |
| 2881 params.source_contents = | 2861 params.source_contents = |
| 2882 tabstrip_model()->GetTabContentsAt( | 2862 tabstrip_model()->GetTabContentsAt( |
| 2883 tabstrip_model()->GetWrapperIndex(source)); | 2863 tabstrip_model()->GetWrapperIndex(source)); |
| 2884 params.referrer = referrer; | 2864 params.referrer = referrer; |
| 2885 params.disposition = disposition; | 2865 params.disposition = disposition; |
| 2886 params.tabstrip_add_types = TabStripModel::ADD_NONE; | 2866 params.tabstrip_add_types = TabStripModel::ADD_NONE; |
| 2887 params.window_action = browser::NavigateParams::SHOW_WINDOW; | 2867 params.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 2868 params.user_gesture = true; |
| 2888 browser::Navigate(¶ms); | 2869 browser::Navigate(¶ms); |
| 2889 } | 2870 } |
| 2890 | 2871 |
| 2891 void Browser::NavigationStateChanged(const TabContents* source, | 2872 void Browser::NavigationStateChanged(const TabContents* source, |
| 2892 unsigned changed_flags) { | 2873 unsigned changed_flags) { |
| 2893 // Only update the UI when something visible has changed. | 2874 // Only update the UI when something visible has changed. |
| 2894 if (changed_flags) | 2875 if (changed_flags) |
| 2895 ScheduleUIUpdate(source, changed_flags); | 2876 ScheduleUIUpdate(source, changed_flags); |
| 2896 | 2877 |
| 2897 // We don't schedule updates to commands since they will only change once per | 2878 // We don't schedule updates to commands since they will only change once per |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2939 // the whitelist. The popup owner will handle checking this. | 2920 // the whitelist. The popup owner will handle checking this. |
| 2940 GetConstrainingContentsWrapper(source_wrapper)-> | 2921 GetConstrainingContentsWrapper(source_wrapper)-> |
| 2941 blocked_content_tab_helper()-> | 2922 blocked_content_tab_helper()-> |
| 2942 AddPopup(new_wrapper, initial_pos, user_gesture); | 2923 AddPopup(new_wrapper, initial_pos, user_gesture); |
| 2943 return; | 2924 return; |
| 2944 } | 2925 } |
| 2945 | 2926 |
| 2946 new_contents->DisassociateFromPopupCount(); | 2927 new_contents->DisassociateFromPopupCount(); |
| 2947 } | 2928 } |
| 2948 | 2929 |
| 2949 // TODO(beng): This belongs behind the platform-specific View interface. | |
| 2950 // That's why it's there. http://crbug.com/78853 | |
| 2951 #if defined(OS_CHROMEOS) | |
| 2952 if (disposition == NEW_POPUP) { | |
| 2953 // If the popup is bigger than a given factor of the screen, then | |
| 2954 // turn it into a foreground tab (on chrome os only) | |
| 2955 // Also check for width or height == 0, which would otherwise indicate | |
| 2956 // a tab sized popup window. | |
| 2957 GdkScreen* screen = gdk_screen_get_default(); | |
| 2958 int max_width = gdk_screen_get_width(screen) * kPopupMaxWidthFactor; | |
| 2959 int max_height = gdk_screen_get_height(screen) * kPopupMaxHeightFactor; | |
| 2960 if (initial_pos.width() > max_width || initial_pos.width() == 0 || | |
| 2961 initial_pos.height() > max_height || initial_pos.height() == 0) { | |
| 2962 disposition = NEW_FOREGROUND_TAB; | |
| 2963 } | |
| 2964 } | |
| 2965 #endif | |
| 2966 | |
| 2967 browser::NavigateParams params(this, new_wrapper); | 2930 browser::NavigateParams params(this, new_wrapper); |
| 2968 params.source_contents = | 2931 params.source_contents = |
| 2969 source ? tabstrip_model()->GetTabContentsAt( | 2932 source ? tabstrip_model()->GetTabContentsAt( |
| 2970 tabstrip_model()->GetWrapperIndex(source)) | 2933 tabstrip_model()->GetWrapperIndex(source)) |
| 2971 : NULL; | 2934 : NULL; |
| 2972 params.disposition = disposition; | 2935 params.disposition = disposition; |
| 2973 params.window_bounds = initial_pos; | 2936 params.window_bounds = initial_pos; |
| 2974 // If we create a popup or panel from a non user-gesture, don't activate | 2937 params.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 2975 // the new window / panel. | 2938 params.user_gesture = user_gesture; |
| 2976 if (disposition == NEW_POPUP && !user_gesture) | |
| 2977 params.window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE; | |
| 2978 else | |
| 2979 params.window_action = browser::NavigateParams::SHOW_WINDOW; | |
| 2980 browser::Navigate(¶ms); | 2939 browser::Navigate(¶ms); |
| 2981 | 2940 |
| 2982 if (source) { | 2941 if (source) { |
| 2983 NotificationService::current()->Notify( | 2942 NotificationService::current()->Notify( |
| 2984 NotificationType::TAB_ADDED, | 2943 NotificationType::TAB_ADDED, |
| 2985 Source<TabContentsDelegate>(source->delegate()), | 2944 Source<TabContentsDelegate>(source->delegate()), |
| 2986 Details<TabContents>(source)); | 2945 Details<TabContents>(source)); |
| 2987 } | 2946 } |
| 2988 } | 2947 } |
| 2989 | 2948 |
| (...skipping 1492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4482 TabContents* current_tab = GetSelectedTabContents(); | 4441 TabContents* current_tab = GetSelectedTabContents(); |
| 4483 if (current_tab) { | 4442 if (current_tab) { |
| 4484 content_restrictions = current_tab->content_restrictions(); | 4443 content_restrictions = current_tab->content_restrictions(); |
| 4485 NavigationEntry* active_entry = current_tab->controller().GetActiveEntry(); | 4444 NavigationEntry* active_entry = current_tab->controller().GetActiveEntry(); |
| 4486 // See comment in UpdateCommandsForTabState about why we call url(). | 4445 // See comment in UpdateCommandsForTabState about why we call url(). |
| 4487 if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL())) | 4446 if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL())) |
| 4488 content_restrictions |= CONTENT_RESTRICTION_SAVE; | 4447 content_restrictions |= CONTENT_RESTRICTION_SAVE; |
| 4489 } | 4448 } |
| 4490 return content_restrictions; | 4449 return content_restrictions; |
| 4491 } | 4450 } |
| OLD | NEW |