| 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 <windows.h> | 8 #include <windows.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #endif // OS_WIN | 10 #endif // OS_WIN |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 #include "chrome/browser/ui/browser_dialogs.h" | 97 #include "chrome/browser/ui/browser_dialogs.h" |
| 98 #include "chrome/browser/ui/browser_list.h" | 98 #include "chrome/browser/ui/browser_list.h" |
| 99 #include "chrome/browser/ui/browser_navigator.h" | 99 #include "chrome/browser/ui/browser_navigator.h" |
| 100 #include "chrome/browser/ui/browser_synced_window_delegate.h" | 100 #include "chrome/browser/ui/browser_synced_window_delegate.h" |
| 101 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" | 101 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" |
| 102 #include "chrome/browser/ui/browser_window.h" | 102 #include "chrome/browser/ui/browser_window.h" |
| 103 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 103 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
| 104 #include "chrome/browser/ui/find_bar/find_bar.h" | 104 #include "chrome/browser/ui/find_bar/find_bar.h" |
| 105 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 105 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 106 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 106 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
| 107 #include "chrome/browser/ui/fullscreen_controller.h" |
| 107 #include "chrome/browser/ui/global_error.h" | 108 #include "chrome/browser/ui/global_error.h" |
| 108 #include "chrome/browser/ui/global_error_service.h" | 109 #include "chrome/browser/ui/global_error_service.h" |
| 109 #include "chrome/browser/ui/global_error_service_factory.h" | 110 #include "chrome/browser/ui/global_error_service_factory.h" |
| 110 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" | 111 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
| 111 #include "chrome/browser/ui/omnibox/location_bar.h" | 112 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 112 #include "chrome/browser/ui/panels/panel.h" | 113 #include "chrome/browser/ui/panels/panel.h" |
| 113 #include "chrome/browser/ui/panels/panel_manager.h" | 114 #include "chrome/browser/ui/panels/panel_manager.h" |
| 114 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" | 115 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" |
| 115 #include "chrome/browser/ui/status_bubble.h" | 116 #include "chrome/browser/ui/status_bubble.h" |
| 116 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 117 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 146 #include "content/browser/site_instance.h" | 147 #include "content/browser/site_instance.h" |
| 147 #include "content/browser/tab_contents/interstitial_page.h" | 148 #include "content/browser/tab_contents/interstitial_page.h" |
| 148 #include "content/browser/tab_contents/navigation_controller.h" | 149 #include "content/browser/tab_contents/navigation_controller.h" |
| 149 #include "content/browser/tab_contents/navigation_entry.h" | 150 #include "content/browser/tab_contents/navigation_entry.h" |
| 150 #include "content/browser/tab_contents/tab_contents_view.h" | 151 #include "content/browser/tab_contents/tab_contents_view.h" |
| 151 #include "content/browser/user_metrics.h" | 152 #include "content/browser/user_metrics.h" |
| 152 #include "content/public/browser/notification_service.h" | 153 #include "content/public/browser/notification_service.h" |
| 153 #include "content/public/browser/notification_details.h" | 154 #include "content/public/browser/notification_details.h" |
| 154 #include "content/public/common/content_restriction.h" | 155 #include "content/public/common/content_restriction.h" |
| 155 #include "content/public/common/content_switches.h" | 156 #include "content/public/common/content_switches.h" |
| 156 #include "grit/chromium_strings.h" | |
| 157 #include "grit/generated_resources.h" | 157 #include "grit/generated_resources.h" |
| 158 #include "grit/locale_settings.h" | 158 #include "grit/locale_settings.h" |
| 159 #include "grit/theme_resources_standard.h" | 159 #include "grit/theme_resources_standard.h" |
| 160 #include "net/base/cookie_monster.h" | 160 #include "net/base/cookie_monster.h" |
| 161 #include "net/base/net_util.h" | 161 #include "net/base/net_util.h" |
| 162 #include "net/base/registry_controlled_domain.h" | 162 #include "net/base/registry_controlled_domain.h" |
| 163 #include "net/url_request/url_request_context.h" | 163 #include "net/url_request/url_request_context.h" |
| 164 #include "ui/base/animation/animation.h" | 164 #include "ui/base/animation/animation.h" |
| 165 #include "ui/base/l10n/l10n_util.h" | 165 #include "ui/base/l10n/l10n_util.h" |
| 166 #include "ui/gfx/point.h" | 166 #include "ui/gfx/point.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 last_blocked_command_id_(-1), | 281 last_blocked_command_id_(-1), |
| 282 last_blocked_command_disposition_(CURRENT_TAB), | 282 last_blocked_command_disposition_(CURRENT_TAB), |
| 283 pending_web_app_action_(NONE), | 283 pending_web_app_action_(NONE), |
| 284 ALLOW_THIS_IN_INITIALIZER_LIST( | 284 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 285 tab_restore_service_delegate_( | 285 tab_restore_service_delegate_( |
| 286 new BrowserTabRestoreServiceDelegate(this))), | 286 new BrowserTabRestoreServiceDelegate(this))), |
| 287 ALLOW_THIS_IN_INITIALIZER_LIST( | 287 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 288 synced_window_delegate_( | 288 synced_window_delegate_( |
| 289 new BrowserSyncedWindowDelegate(this))), | 289 new BrowserSyncedWindowDelegate(this))), |
| 290 bookmark_bar_state_(BookmarkBar::HIDDEN), | 290 bookmark_bar_state_(BookmarkBar::HIDDEN), |
| 291 fullscreened_tab_(NULL), | |
| 292 tab_caused_fullscreen_(false), | |
| 293 tab_fullscreen_accepted_(false), | |
| 294 mouse_lock_state_(MOUSELOCK_NOT_REQUESTED), | |
| 295 window_has_shown_(false) { | 291 window_has_shown_(false) { |
| 296 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, | 292 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, |
| 297 content::NotificationService::AllSources()); | 293 content::NotificationService::AllSources()); |
| 298 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, | 294 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
| 299 content::Source<Profile>(profile_)); | 295 content::Source<Profile>(profile_)); |
| 300 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 296 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 301 content::Source<Profile>(profile_)); | 297 content::Source<Profile>(profile_)); |
| 302 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 298 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 303 content::Source<Profile>(profile_)); | 299 content::Source<Profile>(profile_)); |
| 304 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 300 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 395 } |
| 400 | 396 |
| 401 // There may be pending file dialogs, we need to tell them that we've gone | 397 // There may be pending file dialogs, we need to tell them that we've gone |
| 402 // away so they don't try and call back to us. | 398 // away so they don't try and call back to us. |
| 403 if (select_file_dialog_.get()) | 399 if (select_file_dialog_.get()) |
| 404 select_file_dialog_->ListenerDestroyed(); | 400 select_file_dialog_->ListenerDestroyed(); |
| 405 | 401 |
| 406 TabRestoreServiceDestroyed(tab_restore_service_); | 402 TabRestoreServiceDestroyed(tab_restore_service_); |
| 407 } | 403 } |
| 408 | 404 |
| 405 bool Browser::IsFullscreenForTab() const { |
| 406 return fullscreen_controller_->IsFullscreenForTab(); |
| 407 } |
| 408 |
| 409 // static | 409 // static |
| 410 Browser* Browser::Create(Profile* profile) { | 410 Browser* Browser::Create(Profile* profile) { |
| 411 Browser* browser = new Browser(TYPE_TABBED, profile); | 411 Browser* browser = new Browser(TYPE_TABBED, profile); |
| 412 browser->InitBrowserWindow(); | 412 browser->InitBrowserWindow(); |
| 413 return browser; | 413 return browser; |
| 414 } | 414 } |
| 415 | 415 |
| 416 // static | 416 // static |
| 417 Browser* Browser::CreateWithParams(const CreateParams& params) { | 417 Browser* Browser::CreateWithParams(const CreateParams& params) { |
| 418 Browser* browser = new Browser(params.type, params.profile); | 418 Browser* browser = new Browser(params.type, params.profile); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 CreateParams params(TYPE_POPUP, profile); | 467 CreateParams params(TYPE_POPUP, profile); |
| 468 #endif | 468 #endif |
| 469 params.app_name = DevToolsWindow::kDevToolsApp; | 469 params.app_name = DevToolsWindow::kDevToolsApp; |
| 470 return CreateWithParams(params); | 470 return CreateWithParams(params); |
| 471 } | 471 } |
| 472 | 472 |
| 473 void Browser::InitBrowserWindow() { | 473 void Browser::InitBrowserWindow() { |
| 474 DCHECK(!window_); | 474 DCHECK(!window_); |
| 475 | 475 |
| 476 window_ = CreateBrowserWindow(); | 476 window_ = CreateBrowserWindow(); |
| 477 fullscreen_controller_ = new FullscreenController(window_, profile_, this); |
| 477 | 478 |
| 478 #if defined(OS_WIN) && !defined(USE_AURA) | 479 #if defined(OS_WIN) && !defined(USE_AURA) |
| 479 { | 480 { |
| 480 // TODO: This might hit the disk | 481 // TODO: This might hit the disk |
| 481 // http://code.google.com/p/chromium/issues/detail?id=61638 | 482 // http://code.google.com/p/chromium/issues/detail?id=61638 |
| 482 base::ThreadRestrictions::ScopedAllowIO allow_io; | 483 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 483 | 484 |
| 484 // Set the app user model id for this application to that of the application | 485 // Set the app user model id for this application to that of the application |
| 485 // name. See http://crbug.com/7028. | 486 // name. See http://crbug.com/7028. |
| 486 ui::win::SetAppIdForWindow( | 487 ui::win::SetAppIdForWindow( |
| (...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 contents_url == GURL(chrome::kAboutBlankURL)) && | 1354 contents_url == GURL(chrome::kAboutBlankURL)) && |
| 1354 browser::GetIndexOfSingletonTab(&local_params) < 0) { | 1355 browser::GetIndexOfSingletonTab(&local_params) < 0) { |
| 1355 local_params.disposition = CURRENT_TAB; | 1356 local_params.disposition = CURRENT_TAB; |
| 1356 } | 1357 } |
| 1357 } | 1358 } |
| 1358 | 1359 |
| 1359 browser::Navigate(&local_params); | 1360 browser::Navigate(&local_params); |
| 1360 } | 1361 } |
| 1361 | 1362 |
| 1362 void Browser::WindowFullscreenStateChanged() { | 1363 void Browser::WindowFullscreenStateChanged() { |
| 1363 UpdateCommandsForFullscreenMode(window_->IsFullscreen()); | 1364 fullscreen_controller_->WindowFullscreenStateChanged(); |
| 1364 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN); | |
| 1365 MessageLoop::current()->PostTask( | |
| 1366 FROM_HERE, method_factory_.NewRunnableMethod( | |
| 1367 &Browser::NotifyFullscreenChange)); | |
| 1368 bool notify_tab_of_exit; | |
| 1369 #if defined(OS_MACOSX) | |
| 1370 notify_tab_of_exit = !window_->InPresentationMode(); | |
| 1371 #else | |
| 1372 notify_tab_of_exit = !window_->IsFullscreen(); | |
| 1373 #endif | |
| 1374 if (notify_tab_of_exit) | |
| 1375 NotifyTabOfFullscreenExitIfNecessary(); | |
| 1376 } | |
| 1377 | |
| 1378 void Browser::NotifyFullscreenChange() { | |
| 1379 content::NotificationService::current()->Notify( | |
| 1380 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | |
| 1381 content::Source<Browser>(this), | |
| 1382 content::NotificationService::NoDetails()); | |
| 1383 } | 1365 } |
| 1384 | 1366 |
| 1385 /////////////////////////////////////////////////////////////////////////////// | 1367 /////////////////////////////////////////////////////////////////////////////// |
| 1386 // Browser, Assorted browser commands: | 1368 // Browser, Assorted browser commands: |
| 1387 | 1369 |
| 1388 TabContents* Browser::GetOrCloneTabForDisposition( | 1370 TabContents* Browser::GetOrCloneTabForDisposition( |
| 1389 WindowOpenDisposition disposition) { | 1371 WindowOpenDisposition disposition) { |
| 1390 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); | 1372 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); |
| 1391 switch (disposition) { | 1373 switch (disposition) { |
| 1392 case NEW_FOREGROUND_TAB: | 1374 case NEW_FOREGROUND_TAB: |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1713 int tab_strip_index = tab_handler_->GetTabStripModel()->active_index(); | 1695 int tab_strip_index = tab_handler_->GetTabStripModel()->active_index(); |
| 1714 TabContentsWrapper* contents = | 1696 TabContentsWrapper* contents = |
| 1715 tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); | 1697 tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); |
| 1716 Browser* browser = Browser::Create(profile_); | 1698 Browser* browser = Browser::Create(profile_); |
| 1717 browser->tabstrip_model()->AppendTabContents(contents, true); | 1699 browser->tabstrip_model()->AppendTabContents(contents, true); |
| 1718 browser->window()->Show(); | 1700 browser->window()->Show(); |
| 1719 } | 1701 } |
| 1720 | 1702 |
| 1721 // TODO(koz): Change |for_tab| to an enum. | 1703 // TODO(koz): Change |for_tab| to an enum. |
| 1722 void Browser::ToggleFullscreenMode(bool for_tab) { | 1704 void Browser::ToggleFullscreenMode(bool for_tab) { |
| 1723 bool entering_fullscreen = !window_->IsFullscreen(); | 1705 fullscreen_controller_->ToggleFullscreenMode(for_tab); |
| 1724 | |
| 1725 #if !defined(OS_MACOSX) | |
| 1726 // In kiosk mode, we always want to be fullscreen. When the browser first | |
| 1727 // starts we're not yet fullscreen, so let the initial toggle go through. | |
| 1728 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && | |
| 1729 window_->IsFullscreen()) | |
| 1730 return; | |
| 1731 #endif | |
| 1732 | |
| 1733 GURL url; | |
| 1734 if (for_tab) { | |
| 1735 url = GetSelectedTabContents()->GetURL(); | |
| 1736 tab_fullscreen_accepted_ = entering_fullscreen && | |
| 1737 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | |
| 1738 } else { | |
| 1739 UserMetrics::RecordAction(UserMetricsAction("ToggleFullscreen")); | |
| 1740 } | |
| 1741 if (entering_fullscreen) | |
| 1742 window_->EnterFullscreen(url, GetFullscreenExitBubbleType()); | |
| 1743 else | |
| 1744 window_->ExitFullscreen(); | |
| 1745 | |
| 1746 // Once the window has become fullscreen it'll call back to | |
| 1747 // WindowFullscreenStateChanged(). We don't do this immediately as | |
| 1748 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let | |
| 1749 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | |
| 1750 | |
| 1751 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates | |
| 1752 // the necessary state of the frame. | |
| 1753 #if defined(OS_MACOSX) | |
| 1754 WindowFullscreenStateChanged(); | |
| 1755 #endif | |
| 1756 } | |
| 1757 | |
| 1758 void Browser::NotifyTabOfFullscreenExitIfNecessary() { | |
| 1759 if (fullscreened_tab_) | |
| 1760 fullscreened_tab_->ExitFullscreenMode(); | |
| 1761 else | |
| 1762 DCHECK_EQ(mouse_lock_state_, MOUSELOCK_NOT_REQUESTED); | |
| 1763 | |
| 1764 fullscreened_tab_ = NULL; | |
| 1765 tab_caused_fullscreen_ = false; | |
| 1766 tab_fullscreen_accepted_ = false; | |
| 1767 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
| 1768 | |
| 1769 UpdateFullscreenExitBubbleContent(); | |
| 1770 } | 1706 } |
| 1771 | 1707 |
| 1772 #if defined(OS_MACOSX) | 1708 #if defined(OS_MACOSX) |
| 1773 void Browser::TogglePresentationMode(bool for_tab) { | 1709 void Browser::TogglePresentationMode(bool for_tab) { |
| 1774 bool entering_fullscreen = !window_->InPresentationMode(); | 1710 fullscreen_controller_->TogglePresentationMode(for_tab); |
| 1775 GURL url; | |
| 1776 bool ask_permission = false; | |
| 1777 if (for_tab) { | |
| 1778 url = GetSelectedTabContents()->GetURL(); | |
| 1779 ask_permission = GetFullscreenSetting(url) != CONTENT_SETTING_ALLOW; | |
| 1780 } | |
| 1781 if (entering_fullscreen) { | |
| 1782 FullscreenExitBubbleType type = | |
| 1783 FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; | |
| 1784 if (for_tab) { | |
| 1785 type = ask_permission ? FEB_TYPE_FULLSCREEN_BUTTONS : | |
| 1786 FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION; | |
| 1787 } | |
| 1788 window_->EnterPresentationMode(url, type); | |
| 1789 } else { | |
| 1790 window_->ExitPresentationMode(); | |
| 1791 } | |
| 1792 WindowFullscreenStateChanged(); | |
| 1793 } | 1711 } |
| 1794 #endif | 1712 #endif |
| 1795 | 1713 |
| 1796 #if defined(OS_CHROMEOS) | 1714 #if defined(OS_CHROMEOS) |
| 1797 void Browser::Search() { | 1715 void Browser::Search() { |
| 1798 // Exit fullscreen to show omnibox. | 1716 // Exit fullscreen to show omnibox. |
| 1799 if (window_->IsFullscreen()) { | 1717 if (window_->IsFullscreen()) { |
| 1800 ToggleFullscreenMode(false); | 1718 ToggleFullscreenMode(false); |
| 1801 // ToggleFullscreenMode is asynchronous, so we don't have omnibox | 1719 // ToggleFullscreenMode is asynchronous, so we don't have omnibox |
| 1802 // visible at this point. Wait for next event cycle which toggles | 1720 // visible at this point. Wait for next event cycle which toggles |
| (...skipping 1425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3228 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, | 3146 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, |
| 3229 content::Source<TabContents>(contents->tab_contents())); | 3147 content::Source<TabContents>(contents->tab_contents())); |
| 3230 | 3148 |
| 3231 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, | 3149 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
| 3232 content::Source<TabContents>(contents->tab_contents())); | 3150 content::Source<TabContents>(contents->tab_contents())); |
| 3233 } | 3151 } |
| 3234 | 3152 |
| 3235 void Browser::TabClosingAt(TabStripModel* tab_strip_model, | 3153 void Browser::TabClosingAt(TabStripModel* tab_strip_model, |
| 3236 TabContentsWrapper* contents, | 3154 TabContentsWrapper* contents, |
| 3237 int index) { | 3155 int index) { |
| 3238 if (fullscreened_tab_ == contents) { | 3156 fullscreen_controller_->OnTabClosing(contents->tab_contents()); |
| 3239 ExitTabbedFullscreenModeIfNecessary(); | |
| 3240 // The call to exit fullscreen may result in asynchronous notification of | |
| 3241 // fullscreen state change (e.g., on Linux). We don't want to rely on it | |
| 3242 // to call NotifyTabOfFullscreenExitIfNecessary(), because at that point | |
| 3243 // |fullscreen_tab_| may not be valid. Instead, we call it here to clean up | |
| 3244 // tab fullscreen related state. | |
| 3245 NotifyTabOfFullscreenExitIfNecessary(); | |
| 3246 } | |
| 3247 content::NotificationService::current()->Notify( | 3157 content::NotificationService::current()->Notify( |
| 3248 content::NOTIFICATION_TAB_CLOSING, | 3158 content::NOTIFICATION_TAB_CLOSING, |
| 3249 content::Source<NavigationController>(&contents->controller()), | 3159 content::Source<NavigationController>(&contents->controller()), |
| 3250 content::NotificationService::NoDetails()); | 3160 content::NotificationService::NoDetails()); |
| 3251 | 3161 |
| 3252 // Sever the TabContents' connection back to us. | 3162 // Sever the TabContents' connection back to us. |
| 3253 SetAsDelegate(contents, NULL); | 3163 SetAsDelegate(contents, NULL); |
| 3254 } | 3164 } |
| 3255 | 3165 |
| 3256 void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { | 3166 void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { |
| 3257 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); | 3167 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); |
| 3258 } | 3168 } |
| 3259 | 3169 |
| 3260 void Browser::TabDeactivated(TabContentsWrapper* contents) { | 3170 void Browser::TabDeactivated(TabContentsWrapper* contents) { |
| 3261 if (contents == fullscreened_tab_) | 3171 fullscreen_controller_->OnTabDeactivated(contents); |
| 3262 ExitTabbedFullscreenModeIfNecessary(); | |
| 3263 if (instant()) | 3172 if (instant()) |
| 3264 instant()->Hide(); | 3173 instant()->Hide(); |
| 3265 | 3174 |
| 3266 // Save what the user's currently typing, so it can be restored when we | 3175 // Save what the user's currently typing, so it can be restored when we |
| 3267 // switch back to this tab. | 3176 // switch back to this tab. |
| 3268 window_->GetLocationBar()->SaveStateToContents(contents->tab_contents()); | 3177 window_->GetLocationBar()->SaveStateToContents(contents->tab_contents()); |
| 3269 } | 3178 } |
| 3270 | 3179 |
| 3271 void Browser::ActiveTabChanged(TabContentsWrapper* old_contents, | 3180 void Browser::ActiveTabChanged(TabContentsWrapper* old_contents, |
| 3272 TabContentsWrapper* new_contents, | 3181 TabContentsWrapper* new_contents, |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3790 DCHECK(source); | 3699 DCHECK(source); |
| 3791 int index = tabstrip_model()->GetWrapperIndex(source); | 3700 int index = tabstrip_model()->GetWrapperIndex(source); |
| 3792 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); | 3701 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); |
| 3793 ViewSource(wrapper, frame_url, frame_content_state); | 3702 ViewSource(wrapper, frame_url, frame_content_state); |
| 3794 } | 3703 } |
| 3795 | 3704 |
| 3796 bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | 3705 bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
| 3797 bool* is_keyboard_shortcut) { | 3706 bool* is_keyboard_shortcut) { |
| 3798 // Escape exits tabbed fullscreen mode. | 3707 // Escape exits tabbed fullscreen mode. |
| 3799 // TODO(koz): Write a test for this http://crbug.com/100441. | 3708 // TODO(koz): Write a test for this http://crbug.com/100441. |
| 3800 if (event.windowsKeyCode == 27 && fullscreened_tab_) { | 3709 if (event.windowsKeyCode == 27 && |
| 3801 ExitTabbedFullscreenModeIfNecessary(); | 3710 fullscreen_controller_->HandleUserPressedEscape()) { |
| 3802 return true; | 3711 return true; |
| 3803 } | 3712 } |
| 3804 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); | 3713 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); |
| 3805 } | 3714 } |
| 3806 | 3715 |
| 3807 void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { | 3716 void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
| 3808 window()->HandleKeyboardEvent(event); | 3717 window()->HandleKeyboardEvent(event); |
| 3809 } | 3718 } |
| 3810 | 3719 |
| 3811 void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) { | 3720 void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3879 const ViewHostMsg_RunFileChooser_Params& params) { | 3788 const ViewHostMsg_RunFileChooser_Params& params) { |
| 3880 RunFileChooserHelper(tab, params); | 3789 RunFileChooserHelper(tab, params); |
| 3881 } | 3790 } |
| 3882 | 3791 |
| 3883 void Browser::EnumerateDirectory(TabContents* tab, int request_id, | 3792 void Browser::EnumerateDirectory(TabContents* tab, int request_id, |
| 3884 const FilePath& path) { | 3793 const FilePath& path) { |
| 3885 EnumerateDirectoryHelper(tab, request_id, path); | 3794 EnumerateDirectoryHelper(tab, request_id, path); |
| 3886 } | 3795 } |
| 3887 | 3796 |
| 3888 void Browser::ToggleFullscreenModeForTab(TabContents* tab, | 3797 void Browser::ToggleFullscreenModeForTab(TabContents* tab, |
| 3889 bool enter_fullscreen) { | 3798 bool enter_fullscreen) { |
| 3890 if (tab != GetSelectedTabContents()) | 3799 fullscreen_controller_->ToggleFullscreenModeForTab(tab, enter_fullscreen); |
| 3891 return; | |
| 3892 | |
| 3893 bool in_browser_or_tab_fullscreen_mode; | |
| 3894 #if defined(OS_MACOSX) | |
| 3895 in_browser_or_tab_fullscreen_mode = window_->InPresentationMode(); | |
| 3896 #else | |
| 3897 in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); | |
| 3898 #endif | |
| 3899 | |
| 3900 if (enter_fullscreen) { | |
| 3901 fullscreened_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab); | |
| 3902 if (!in_browser_or_tab_fullscreen_mode) { | |
| 3903 tab_caused_fullscreen_ = true; | |
| 3904 #if defined(OS_MACOSX) | |
| 3905 TogglePresentationMode(true); | |
| 3906 #else | |
| 3907 ToggleFullscreenMode(true); | |
| 3908 #endif | |
| 3909 } else { | |
| 3910 // We need to update the fullscreen exit bubble, e.g., going from browser | |
| 3911 // fullscreen to tab fullscreen will need to show different content. | |
| 3912 const GURL& url = tab->GetURL(); | |
| 3913 if (!tab_fullscreen_accepted_) { | |
| 3914 tab_fullscreen_accepted_ = | |
| 3915 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | |
| 3916 } | |
| 3917 UpdateFullscreenExitBubbleContent(); | |
| 3918 } | |
| 3919 } else { | |
| 3920 if (in_browser_or_tab_fullscreen_mode) { | |
| 3921 if (tab_caused_fullscreen_) { | |
| 3922 #if defined(OS_MACOSX) | |
| 3923 TogglePresentationMode(true); | |
| 3924 #else | |
| 3925 ToggleFullscreenMode(true); | |
| 3926 #endif | |
| 3927 } else { | |
| 3928 // If currently there is a tab in "tab fullscreen" mode and fullscreen | |
| 3929 // was not caused by it (i.e., previously it was in "browser fullscreen" | |
| 3930 // mode), we need to switch back to "browser fullscreen" mode. In this | |
| 3931 // case, all we have to do is notifying the tab that it has exited "tab | |
| 3932 // fullscreen" mode. | |
| 3933 NotifyTabOfFullscreenExitIfNecessary(); | |
| 3934 } | |
| 3935 } | |
| 3936 } | |
| 3937 } | 3800 } |
| 3938 | 3801 |
| 3939 bool Browser::IsFullscreenForTab(const TabContents* tab) const { | 3802 bool Browser::IsFullscreenForTab(const TabContents* tab) const { |
| 3940 const TabContentsWrapper* wrapper = | 3803 return fullscreen_controller_->IsFullscreenForTab(tab); |
| 3941 TabContentsWrapper::GetCurrentWrapperForContents(tab); | |
| 3942 bool result = wrapper && wrapper == fullscreened_tab_; | |
| 3943 DCHECK(!result || tab == GetSelectedTabContents()); | |
| 3944 DCHECK(!result || window_->IsFullscreen()); | |
| 3945 | |
| 3946 return result; | |
| 3947 } | 3804 } |
| 3948 | 3805 |
| 3949 void Browser::JSOutOfMemory(TabContents* tab) { | 3806 void Browser::JSOutOfMemory(TabContents* tab) { |
| 3950 JSOutOfMemoryHelper(tab); | 3807 JSOutOfMemoryHelper(tab); |
| 3951 } | 3808 } |
| 3952 | 3809 |
| 3953 void Browser::RegisterProtocolHandler(TabContents* tab, | 3810 void Browser::RegisterProtocolHandler(TabContents* tab, |
| 3954 const std::string& protocol, | 3811 const std::string& protocol, |
| 3955 const GURL& url, | 3812 const GURL& url, |
| 3956 const string16& title) { | 3813 const string16& title) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3989 int active_match_ordinal, | 3846 int active_match_ordinal, |
| 3990 bool final_update) { | 3847 bool final_update) { |
| 3991 FindReplyHelper(tab, request_id, number_of_matches, selection_rect, | 3848 FindReplyHelper(tab, request_id, number_of_matches, selection_rect, |
| 3992 active_match_ordinal, final_update); | 3849 active_match_ordinal, final_update); |
| 3993 } | 3850 } |
| 3994 | 3851 |
| 3995 void Browser::CrashedPlugin(TabContents* tab, const FilePath& plugin_path) { | 3852 void Browser::CrashedPlugin(TabContents* tab, const FilePath& plugin_path) { |
| 3996 CrashedPluginHelper(tab, plugin_path); | 3853 CrashedPluginHelper(tab, plugin_path); |
| 3997 } | 3854 } |
| 3998 | 3855 |
| 3999 void Browser::ExitTabbedFullscreenModeIfNecessary() { | |
| 4000 if (tab_caused_fullscreen_) | |
| 4001 ToggleFullscreenMode(false); | |
| 4002 else | |
| 4003 NotifyTabOfFullscreenExitIfNecessary(); | |
| 4004 } | |
| 4005 | |
| 4006 void Browser::UpdatePreferredSize(TabContents* source, | 3856 void Browser::UpdatePreferredSize(TabContents* source, |
| 4007 const gfx::Size& pref_size) { | 3857 const gfx::Size& pref_size) { |
| 4008 window_->UpdatePreferredSize(source, pref_size); | 3858 window_->UpdatePreferredSize(source, pref_size); |
| 4009 } | 3859 } |
| 4010 | 3860 |
| 4011 void Browser::RequestToLockMouse(TabContents* tab) { | 3861 void Browser::RequestToLockMouse(TabContents* tab) { |
| 4012 // Mouse Lock is only permitted when browser is in tab fullscreen. | 3862 fullscreen_controller_->RequestToLockMouse(tab); |
| 4013 if (!IsFullscreenForTab(tab)) { | |
| 4014 tab->GotResponseToLockMouseRequest(false); | |
| 4015 return; | |
| 4016 } | |
| 4017 | |
| 4018 if (mouse_lock_state_ == MOUSELOCK_ACCEPTED) { | |
| 4019 tab->GotResponseToLockMouseRequest(true); | |
| 4020 return; | |
| 4021 } | |
| 4022 | |
| 4023 switch (GetMouseLockSetting(tab->GetURL())) { | |
| 4024 case CONTENT_SETTING_ALLOW: | |
| 4025 mouse_lock_state_ = MOUSELOCK_ACCEPTED; | |
| 4026 tab->GotResponseToLockMouseRequest(true); | |
| 4027 break; | |
| 4028 case CONTENT_SETTING_BLOCK: | |
| 4029 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
| 4030 tab->GotResponseToLockMouseRequest(false); | |
| 4031 break; | |
| 4032 case CONTENT_SETTING_ASK: | |
| 4033 mouse_lock_state_ = MOUSELOCK_REQUESTED; | |
| 4034 break; | |
| 4035 default: | |
| 4036 NOTREACHED(); | |
| 4037 } | |
| 4038 UpdateFullscreenExitBubbleContent(); | |
| 4039 } | 3863 } |
| 4040 | 3864 |
| 4041 void Browser::LostMouseLock() { | 3865 void Browser::LostMouseLock() { |
| 4042 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 3866 fullscreen_controller_->LostMouseLock(); |
| 4043 UpdateFullscreenExitBubbleContent(); | |
| 4044 } | 3867 } |
| 4045 | 3868 |
| 4046 void Browser::OnAcceptFullscreenPermission( | 3869 void Browser::OnAcceptFullscreenPermission( |
| 4047 const GURL& url, | 3870 const GURL& url, |
| 4048 FullscreenExitBubbleType bubble_type) { | 3871 FullscreenExitBubbleType bubble_type) { |
| 4049 bool mouse_lock = false; | 3872 fullscreen_controller_->OnAcceptFullscreenPermission(url, bubble_type); |
| 4050 bool fullscreen = false; | |
| 4051 fullscreen_bubble::PermissionRequestedByType(bubble_type, &fullscreen, | |
| 4052 &mouse_lock); | |
| 4053 DCHECK(fullscreened_tab_); | |
| 4054 DCHECK_NE(tab_fullscreen_accepted_, fullscreen); | |
| 4055 | |
| 4056 HostContentSettingsMap* settings_map = | |
| 4057 profile()->GetHostContentSettingsMap(); | |
| 4058 if (mouse_lock) { | |
| 4059 DCHECK_EQ(mouse_lock_state_, MOUSELOCK_REQUESTED); | |
| 4060 settings_map->SetContentSetting( | |
| 4061 ContentSettingsPattern::FromURL(url), | |
| 4062 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_MOUSELOCK, | |
| 4063 std::string(), CONTENT_SETTING_ALLOW); | |
| 4064 mouse_lock_state_ = | |
| 4065 fullscreened_tab_->tab_contents()->GotResponseToLockMouseRequest(true) ? | |
| 4066 MOUSELOCK_ACCEPTED : MOUSELOCK_NOT_REQUESTED; | |
| 4067 } | |
| 4068 if (!tab_fullscreen_accepted_) { | |
| 4069 settings_map->SetContentSetting( | |
| 4070 ContentSettingsPattern::FromURL(url), | |
| 4071 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_FULLSCREEN, | |
| 4072 std::string(), CONTENT_SETTING_ALLOW); | |
| 4073 tab_fullscreen_accepted_ = true; | |
| 4074 } | |
| 4075 UpdateFullscreenExitBubbleContent(); | |
| 4076 } | 3873 } |
| 4077 | 3874 |
| 4078 void Browser::OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type) { | 3875 void Browser::OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type) { |
| 4079 bool mouse_lock = false; | 3876 fullscreen_controller_->OnDenyFullscreenPermission(bubble_type); |
| 4080 bool fullscreen = false; | |
| 4081 fullscreen_bubble::PermissionRequestedByType(bubble_type, &fullscreen, | |
| 4082 &mouse_lock); | |
| 4083 DCHECK(fullscreened_tab_); | |
| 4084 DCHECK_NE(tab_fullscreen_accepted_, fullscreen); | |
| 4085 | |
| 4086 if (mouse_lock) { | |
| 4087 DCHECK_EQ(mouse_lock_state_, MOUSELOCK_REQUESTED); | |
| 4088 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
| 4089 fullscreened_tab_->tab_contents()->GotResponseToLockMouseRequest(false); | |
| 4090 if (!fullscreen) | |
| 4091 UpdateFullscreenExitBubbleContent(); | |
| 4092 } | |
| 4093 | |
| 4094 if (fullscreen) | |
| 4095 ExitTabbedFullscreenModeIfNecessary(); | |
| 4096 } | 3877 } |
| 4097 | 3878 |
| 4098 ContentSetting Browser::GetFullscreenSetting(const GURL& url) { | |
| 4099 if (url.SchemeIsFile()) | |
| 4100 return CONTENT_SETTING_ALLOW; | |
| 4101 | |
| 4102 HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); | |
| 4103 return settings_map->GetContentSetting(url, url, | |
| 4104 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()); | |
| 4105 } | |
| 4106 | |
| 4107 ContentSetting Browser::GetMouseLockSetting(const GURL& url) { | |
| 4108 if (url.SchemeIsFile()) | |
| 4109 return CONTENT_SETTING_ALLOW; | |
| 4110 | |
| 4111 HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); | |
| 4112 return settings_map->GetContentSetting(url, url, | |
| 4113 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); | |
| 4114 } | |
| 4115 | 3879 |
| 4116 /////////////////////////////////////////////////////////////////////////////// | 3880 /////////////////////////////////////////////////////////////////////////////// |
| 4117 // Browser, TabContentsWrapperDelegate implementation: | 3881 // Browser, TabContentsWrapperDelegate implementation: |
| 4118 | 3882 |
| 4119 void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, | 3883 void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, |
| 4120 int32 page_id) { | 3884 int32 page_id) { |
| 4121 if (GetSelectedTabContentsWrapper() != source) | 3885 if (GetSelectedTabContentsWrapper() != source) |
| 4122 return; | 3886 return; |
| 4123 | 3887 |
| 4124 NavigationEntry* entry = source->controller().GetLastCommittedEntry(); | 3888 NavigationEntry* entry = source->controller().GetLastCommittedEntry(); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4347 if (location_bar) | 4111 if (location_bar) |
| 4348 location_bar->UpdateContentSettingsIcons(); | 4112 location_bar->UpdateContentSettingsIcons(); |
| 4349 } | 4113 } |
| 4350 break; | 4114 break; |
| 4351 } | 4115 } |
| 4352 | 4116 |
| 4353 case content::NOTIFICATION_INTERSTITIAL_ATTACHED: | 4117 case content::NOTIFICATION_INTERSTITIAL_ATTACHED: |
| 4354 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); | 4118 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
| 4355 break; | 4119 break; |
| 4356 | 4120 |
| 4121 case chrome::NOTIFICATION_FULLSCREEN_CHANGED: |
| 4122 UpdateCommandsForFullscreenMode(window_->IsFullscreen()); |
| 4123 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN); |
| 4124 break; |
| 4125 |
| 4357 default: | 4126 default: |
| 4358 NOTREACHED() << "Got a notification we didn't register for."; | 4127 NOTREACHED() << "Got a notification we didn't register for."; |
| 4359 } | 4128 } |
| 4360 } | 4129 } |
| 4361 | 4130 |
| 4362 /////////////////////////////////////////////////////////////////////////////// | 4131 /////////////////////////////////////////////////////////////////////////////// |
| 4363 // Browser, ProfileSyncServiceObserver implementation: | 4132 // Browser, ProfileSyncServiceObserver implementation: |
| 4364 | 4133 |
| 4365 void Browser::OnStateChanged() { | 4134 void Browser::OnStateChanged() { |
| 4366 DCHECK(profile_->GetProfileSyncService()); | 4135 DCHECK(profile_->GetProfileSyncService()); |
| (...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5474 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); | 5243 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); |
| 5475 } else if (is_type_tabbed()) { | 5244 } else if (is_type_tabbed()) { |
| 5476 GlobalErrorService* service = | 5245 GlobalErrorService* service = |
| 5477 GlobalErrorServiceFactory::GetForProfile(profile()); | 5246 GlobalErrorServiceFactory::GetForProfile(profile()); |
| 5478 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); | 5247 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); |
| 5479 if (error) { | 5248 if (error) { |
| 5480 error->ShowBubbleView(this); | 5249 error->ShowBubbleView(this); |
| 5481 } | 5250 } |
| 5482 } | 5251 } |
| 5483 } | 5252 } |
| 5484 | |
| 5485 FullscreenExitBubbleType Browser::GetFullscreenExitBubbleType() const { | |
| 5486 bool tab_fullscreen_requested = | |
| 5487 fullscreened_tab_ && !tab_fullscreen_accepted_; | |
| 5488 if (!tab_fullscreen_requested && !tab_fullscreen_accepted_) { | |
| 5489 DCHECK_EQ(mouse_lock_state_, MOUSELOCK_NOT_REQUESTED); | |
| 5490 return FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; | |
| 5491 } | |
| 5492 if (tab_fullscreen_requested) { | |
| 5493 DCHECK_NE(mouse_lock_state_, MOUSELOCK_ACCEPTED); | |
| 5494 return mouse_lock_state_ == MOUSELOCK_REQUESTED ? | |
| 5495 FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS : FEB_TYPE_FULLSCREEN_BUTTONS; | |
| 5496 } | |
| 5497 if (mouse_lock_state_ == MOUSELOCK_REQUESTED) | |
| 5498 return FEB_TYPE_MOUSELOCK_BUTTONS; | |
| 5499 return mouse_lock_state_ == MOUSELOCK_ACCEPTED ? | |
| 5500 FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION : | |
| 5501 FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION; | |
| 5502 } | |
| 5503 | |
| 5504 void Browser::UpdateFullscreenExitBubbleContent() { | |
| 5505 GURL url; | |
| 5506 if (fullscreened_tab_) | |
| 5507 url = fullscreened_tab_->tab_contents()->GetURL(); | |
| 5508 | |
| 5509 window_->UpdateFullscreenExitBubbleContent( | |
| 5510 url, GetFullscreenExitBubbleType()); | |
| 5511 } | |
| OLD | NEW |