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 if (for_tab) { | |
1777 url = GetSelectedTabContents()->GetURL(); | |
1778 tab_fullscreen_accepted_ = entering_fullscreen && | |
1779 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | |
1780 } | |
1781 if (entering_fullscreen) | |
1782 window_->EnterPresentationMode(url, GetFullscreenExitBubbleType()); | |
1783 else | |
1784 window_->ExitPresentationMode(); | |
1785 WindowFullscreenStateChanged(); | |
1786 } | 1711 } |
1787 #endif | 1712 #endif |
1788 | 1713 |
1789 #if defined(OS_CHROMEOS) | 1714 #if defined(OS_CHROMEOS) |
1790 void Browser::Search() { | 1715 void Browser::Search() { |
1791 // Exit fullscreen to show omnibox. | 1716 // Exit fullscreen to show omnibox. |
1792 if (window_->IsFullscreen()) { | 1717 if (window_->IsFullscreen()) { |
1793 ToggleFullscreenMode(false); | 1718 ToggleFullscreenMode(false); |
1794 // ToggleFullscreenMode is asynchronous, so we don't have omnibox | 1719 // ToggleFullscreenMode is asynchronous, so we don't have omnibox |
1795 // visible at this point. Wait for next event cycle which toggles | 1720 // visible at this point. Wait for next event cycle which toggles |
(...skipping 1419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3215 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, | 3140 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, |
3216 content::Source<TabContents>(contents->tab_contents())); | 3141 content::Source<TabContents>(contents->tab_contents())); |
3217 | 3142 |
3218 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, | 3143 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
3219 content::Source<TabContents>(contents->tab_contents())); | 3144 content::Source<TabContents>(contents->tab_contents())); |
3220 } | 3145 } |
3221 | 3146 |
3222 void Browser::TabClosingAt(TabStripModel* tab_strip_model, | 3147 void Browser::TabClosingAt(TabStripModel* tab_strip_model, |
3223 TabContentsWrapper* contents, | 3148 TabContentsWrapper* contents, |
3224 int index) { | 3149 int index) { |
3225 if (fullscreened_tab_ == contents) { | 3150 fullscreen_controller_->OnTabClosing(contents->tab_contents()); |
3226 ExitTabbedFullscreenModeIfNecessary(); | |
3227 // The call to exit fullscreen may result in asynchronous notification of | |
3228 // fullscreen state change (e.g., on Linux). We don't want to rely on it | |
3229 // to call NotifyTabOfFullscreenExitIfNecessary(), because at that point | |
3230 // |fullscreen_tab_| may not be valid. Instead, we call it here to clean up | |
3231 // tab fullscreen related state. | |
3232 NotifyTabOfFullscreenExitIfNecessary(); | |
3233 } | |
3234 content::NotificationService::current()->Notify( | 3151 content::NotificationService::current()->Notify( |
3235 content::NOTIFICATION_TAB_CLOSING, | 3152 content::NOTIFICATION_TAB_CLOSING, |
3236 content::Source<NavigationController>(&contents->controller()), | 3153 content::Source<NavigationController>(&contents->controller()), |
3237 content::NotificationService::NoDetails()); | 3154 content::NotificationService::NoDetails()); |
3238 | 3155 |
3239 // Sever the TabContents' connection back to us. | 3156 // Sever the TabContents' connection back to us. |
3240 SetAsDelegate(contents, NULL); | 3157 SetAsDelegate(contents, NULL); |
3241 } | 3158 } |
3242 | 3159 |
3243 void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { | 3160 void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { |
3244 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); | 3161 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); |
3245 } | 3162 } |
3246 | 3163 |
3247 void Browser::TabDeactivated(TabContentsWrapper* contents) { | 3164 void Browser::TabDeactivated(TabContentsWrapper* contents) { |
3248 if (contents == fullscreened_tab_) | 3165 fullscreen_controller_->OnTabDeactivated(contents); |
3249 ExitTabbedFullscreenModeIfNecessary(); | |
3250 if (instant()) | 3166 if (instant()) |
3251 instant()->Hide(); | 3167 instant()->Hide(); |
3252 | 3168 |
3253 // Save what the user's currently typing, so it can be restored when we | 3169 // Save what the user's currently typing, so it can be restored when we |
3254 // switch back to this tab. | 3170 // switch back to this tab. |
3255 window_->GetLocationBar()->SaveStateToContents(contents->tab_contents()); | 3171 window_->GetLocationBar()->SaveStateToContents(contents->tab_contents()); |
3256 } | 3172 } |
3257 | 3173 |
3258 void Browser::ActiveTabChanged(TabContentsWrapper* old_contents, | 3174 void Browser::ActiveTabChanged(TabContentsWrapper* old_contents, |
3259 TabContentsWrapper* new_contents, | 3175 TabContentsWrapper* new_contents, |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3777 DCHECK(source); | 3693 DCHECK(source); |
3778 int index = tabstrip_model()->GetWrapperIndex(source); | 3694 int index = tabstrip_model()->GetWrapperIndex(source); |
3779 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); | 3695 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); |
3780 ViewSource(wrapper, frame_url, frame_content_state); | 3696 ViewSource(wrapper, frame_url, frame_content_state); |
3781 } | 3697 } |
3782 | 3698 |
3783 bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | 3699 bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
3784 bool* is_keyboard_shortcut) { | 3700 bool* is_keyboard_shortcut) { |
3785 // Escape exits tabbed fullscreen mode. | 3701 // Escape exits tabbed fullscreen mode. |
3786 // TODO(koz): Write a test for this http://crbug.com/100441. | 3702 // TODO(koz): Write a test for this http://crbug.com/100441. |
3787 if (event.windowsKeyCode == 27 && fullscreened_tab_) { | 3703 if (event.windowsKeyCode == 27 && |
3788 ExitTabbedFullscreenModeIfNecessary(); | 3704 fullscreen_controller_->HandleUserPressedEscape()) { |
3789 return true; | 3705 return true; |
3790 } | 3706 } |
3791 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); | 3707 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); |
3792 } | 3708 } |
3793 | 3709 |
3794 void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { | 3710 void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
3795 window()->HandleKeyboardEvent(event); | 3711 window()->HandleKeyboardEvent(event); |
3796 } | 3712 } |
3797 | 3713 |
3798 void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) { | 3714 void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3866 const ViewHostMsg_RunFileChooser_Params& params) { | 3782 const ViewHostMsg_RunFileChooser_Params& params) { |
3867 RunFileChooserHelper(tab, params); | 3783 RunFileChooserHelper(tab, params); |
3868 } | 3784 } |
3869 | 3785 |
3870 void Browser::EnumerateDirectory(TabContents* tab, int request_id, | 3786 void Browser::EnumerateDirectory(TabContents* tab, int request_id, |
3871 const FilePath& path) { | 3787 const FilePath& path) { |
3872 EnumerateDirectoryHelper(tab, request_id, path); | 3788 EnumerateDirectoryHelper(tab, request_id, path); |
3873 } | 3789 } |
3874 | 3790 |
3875 void Browser::ToggleFullscreenModeForTab(TabContents* tab, | 3791 void Browser::ToggleFullscreenModeForTab(TabContents* tab, |
3876 bool enter_fullscreen) { | 3792 bool enter_fullscreen) { |
3877 if (tab != GetSelectedTabContents()) | 3793 fullscreen_controller_->ToggleFullscreenModeForTab(tab, enter_fullscreen); |
3878 return; | |
3879 | |
3880 bool in_browser_or_tab_fullscreen_mode; | |
3881 #if defined(OS_MACOSX) | |
3882 in_browser_or_tab_fullscreen_mode = window_->InPresentationMode(); | |
3883 #else | |
3884 in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); | |
3885 #endif | |
3886 | |
3887 if (enter_fullscreen) { | |
3888 fullscreened_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab); | |
3889 if (!in_browser_or_tab_fullscreen_mode) { | |
3890 tab_caused_fullscreen_ = true; | |
3891 #if defined(OS_MACOSX) | |
3892 TogglePresentationMode(true); | |
3893 #else | |
3894 ToggleFullscreenMode(true); | |
3895 #endif | |
3896 } else { | |
3897 // We need to update the fullscreen exit bubble, e.g., going from browser | |
3898 // fullscreen to tab fullscreen will need to show different content. | |
3899 const GURL& url = tab->GetURL(); | |
3900 if (!tab_fullscreen_accepted_) { | |
3901 tab_fullscreen_accepted_ = | |
3902 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | |
3903 } | |
3904 UpdateFullscreenExitBubbleContent(); | |
3905 } | |
3906 } else { | |
3907 if (in_browser_or_tab_fullscreen_mode) { | |
3908 if (tab_caused_fullscreen_) { | |
3909 #if defined(OS_MACOSX) | |
3910 TogglePresentationMode(true); | |
3911 #else | |
3912 ToggleFullscreenMode(true); | |
3913 #endif | |
3914 } else { | |
3915 // If currently there is a tab in "tab fullscreen" mode and fullscreen | |
3916 // was not caused by it (i.e., previously it was in "browser fullscreen" | |
3917 // mode), we need to switch back to "browser fullscreen" mode. In this | |
3918 // case, all we have to do is notifying the tab that it has exited "tab | |
3919 // fullscreen" mode. | |
3920 NotifyTabOfFullscreenExitIfNecessary(); | |
3921 } | |
3922 } | |
3923 } | |
3924 } | 3794 } |
3925 | 3795 |
3926 bool Browser::IsFullscreenForTab(const TabContents* tab) const { | 3796 bool Browser::IsFullscreenForTab(const TabContents* tab) const { |
3927 const TabContentsWrapper* wrapper = | 3797 return fullscreen_controller_->IsFullscreenForTab(tab); |
3928 TabContentsWrapper::GetCurrentWrapperForContents(tab); | |
3929 bool result = wrapper && wrapper == fullscreened_tab_; | |
3930 DCHECK(!result || tab == GetSelectedTabContents()); | |
3931 DCHECK(!result || window_->IsFullscreen()); | |
3932 | |
3933 return result; | |
3934 } | 3798 } |
3935 | 3799 |
3936 void Browser::JSOutOfMemory(TabContents* tab) { | 3800 void Browser::JSOutOfMemory(TabContents* tab) { |
3937 JSOutOfMemoryHelper(tab); | 3801 JSOutOfMemoryHelper(tab); |
3938 } | 3802 } |
3939 | 3803 |
3940 void Browser::RegisterProtocolHandler(TabContents* tab, | 3804 void Browser::RegisterProtocolHandler(TabContents* tab, |
3941 const std::string& protocol, | 3805 const std::string& protocol, |
3942 const GURL& url, | 3806 const GURL& url, |
3943 const string16& title) { | 3807 const string16& title) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3976 int active_match_ordinal, | 3840 int active_match_ordinal, |
3977 bool final_update) { | 3841 bool final_update) { |
3978 FindReplyHelper(tab, request_id, number_of_matches, selection_rect, | 3842 FindReplyHelper(tab, request_id, number_of_matches, selection_rect, |
3979 active_match_ordinal, final_update); | 3843 active_match_ordinal, final_update); |
3980 } | 3844 } |
3981 | 3845 |
3982 void Browser::CrashedPlugin(TabContents* tab, const FilePath& plugin_path) { | 3846 void Browser::CrashedPlugin(TabContents* tab, const FilePath& plugin_path) { |
3983 CrashedPluginHelper(tab, plugin_path); | 3847 CrashedPluginHelper(tab, plugin_path); |
3984 } | 3848 } |
3985 | 3849 |
3986 void Browser::ExitTabbedFullscreenModeIfNecessary() { | |
3987 if (tab_caused_fullscreen_) | |
3988 ToggleFullscreenMode(false); | |
3989 else | |
3990 NotifyTabOfFullscreenExitIfNecessary(); | |
3991 } | |
3992 | |
3993 void Browser::UpdatePreferredSize(TabContents* source, | 3850 void Browser::UpdatePreferredSize(TabContents* source, |
3994 const gfx::Size& pref_size) { | 3851 const gfx::Size& pref_size) { |
3995 window_->UpdatePreferredSize(source, pref_size); | 3852 window_->UpdatePreferredSize(source, pref_size); |
3996 } | 3853 } |
3997 | 3854 |
3998 void Browser::RequestToLockMouse(TabContents* tab) { | 3855 void Browser::RequestToLockMouse(TabContents* tab) { |
3999 // Mouse Lock is only permitted when browser is in tab fullscreen. | 3856 fullscreen_controller_->RequestToLockMouse(tab); |
4000 if (!IsFullscreenForTab(tab)) { | |
4001 tab->GotResponseToLockMouseRequest(false); | |
4002 return; | |
4003 } | |
4004 | |
4005 if (mouse_lock_state_ == MOUSELOCK_ACCEPTED) { | |
4006 tab->GotResponseToLockMouseRequest(true); | |
4007 return; | |
4008 } | |
4009 | |
4010 switch (GetMouseLockSetting(tab->GetURL())) { | |
4011 case CONTENT_SETTING_ALLOW: | |
4012 mouse_lock_state_ = MOUSELOCK_ACCEPTED; | |
4013 tab->GotResponseToLockMouseRequest(true); | |
4014 break; | |
4015 case CONTENT_SETTING_BLOCK: | |
4016 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
4017 tab->GotResponseToLockMouseRequest(false); | |
4018 break; | |
4019 case CONTENT_SETTING_ASK: | |
4020 mouse_lock_state_ = MOUSELOCK_REQUESTED; | |
4021 break; | |
4022 default: | |
4023 NOTREACHED(); | |
4024 } | |
4025 UpdateFullscreenExitBubbleContent(); | |
4026 } | 3857 } |
4027 | 3858 |
4028 void Browser::LostMouseLock() { | 3859 void Browser::LostMouseLock() { |
4029 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 3860 fullscreen_controller_->LostMouseLock(); |
4030 UpdateFullscreenExitBubbleContent(); | |
4031 } | 3861 } |
4032 | 3862 |
4033 void Browser::OnAcceptFullscreenPermission( | 3863 void Browser::OnAcceptFullscreenPermission( |
4034 const GURL& url, | 3864 const GURL& url, |
4035 FullscreenExitBubbleType bubble_type) { | 3865 FullscreenExitBubbleType bubble_type) { |
4036 bool mouse_lock = false; | 3866 fullscreen_controller_->OnAcceptFullscreenPermission(url, bubble_type); |
4037 bool fullscreen = false; | |
4038 fullscreen_bubble::PermissionRequestedByType(bubble_type, &fullscreen, | |
4039 &mouse_lock); | |
4040 DCHECK(fullscreened_tab_); | |
4041 DCHECK_NE(tab_fullscreen_accepted_, fullscreen); | |
4042 | |
4043 HostContentSettingsMap* settings_map = | |
4044 profile()->GetHostContentSettingsMap(); | |
4045 if (mouse_lock) { | |
4046 DCHECK_EQ(mouse_lock_state_, MOUSELOCK_REQUESTED); | |
4047 settings_map->SetContentSetting( | |
4048 ContentSettingsPattern::FromURL(url), | |
4049 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_MOUSELOCK, | |
4050 std::string(), CONTENT_SETTING_ALLOW); | |
4051 mouse_lock_state_ = | |
4052 fullscreened_tab_->tab_contents()->GotResponseToLockMouseRequest(true) ? | |
4053 MOUSELOCK_ACCEPTED : MOUSELOCK_NOT_REQUESTED; | |
4054 } | |
4055 if (!tab_fullscreen_accepted_) { | |
4056 settings_map->SetContentSetting( | |
4057 ContentSettingsPattern::FromURL(url), | |
4058 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_FULLSCREEN, | |
4059 std::string(), CONTENT_SETTING_ALLOW); | |
4060 tab_fullscreen_accepted_ = true; | |
4061 } | |
4062 UpdateFullscreenExitBubbleContent(); | |
4063 } | 3867 } |
4064 | 3868 |
4065 void Browser::OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type) { | 3869 void Browser::OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type) { |
4066 bool mouse_lock = false; | 3870 fullscreen_controller_->OnDenyFullscreenPermission(bubble_type); |
4067 bool fullscreen = false; | |
4068 fullscreen_bubble::PermissionRequestedByType(bubble_type, &fullscreen, | |
4069 &mouse_lock); | |
4070 DCHECK(fullscreened_tab_); | |
4071 DCHECK_NE(tab_fullscreen_accepted_, fullscreen); | |
4072 | |
4073 if (mouse_lock) { | |
4074 DCHECK_EQ(mouse_lock_state_, MOUSELOCK_REQUESTED); | |
4075 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
4076 fullscreened_tab_->tab_contents()->GotResponseToLockMouseRequest(false); | |
4077 if (!fullscreen) | |
4078 UpdateFullscreenExitBubbleContent(); | |
4079 } | |
4080 | |
4081 if (fullscreen) | |
4082 ExitTabbedFullscreenModeIfNecessary(); | |
4083 } | 3871 } |
4084 | 3872 |
4085 ContentSetting Browser::GetFullscreenSetting(const GURL& url) { | |
4086 if (url.SchemeIsFile()) | |
4087 return CONTENT_SETTING_ALLOW; | |
4088 | |
4089 HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); | |
4090 return settings_map->GetContentSetting(url, url, | |
4091 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()); | |
4092 } | |
4093 | |
4094 ContentSetting Browser::GetMouseLockSetting(const GURL& url) { | |
4095 if (url.SchemeIsFile()) | |
4096 return CONTENT_SETTING_ALLOW; | |
4097 | |
4098 HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); | |
4099 return settings_map->GetContentSetting(url, url, | |
4100 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); | |
4101 } | |
4102 | 3873 |
4103 /////////////////////////////////////////////////////////////////////////////// | 3874 /////////////////////////////////////////////////////////////////////////////// |
4104 // Browser, TabContentsWrapperDelegate implementation: | 3875 // Browser, TabContentsWrapperDelegate implementation: |
4105 | 3876 |
4106 void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, | 3877 void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, |
4107 int32 page_id) { | 3878 int32 page_id) { |
4108 if (GetSelectedTabContentsWrapper() != source) | 3879 if (GetSelectedTabContentsWrapper() != source) |
4109 return; | 3880 return; |
4110 | 3881 |
4111 NavigationEntry* entry = source->controller().GetLastCommittedEntry(); | 3882 NavigationEntry* entry = source->controller().GetLastCommittedEntry(); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4339 if (location_bar) | 4110 if (location_bar) |
4340 location_bar->UpdateContentSettingsIcons(); | 4111 location_bar->UpdateContentSettingsIcons(); |
4341 } | 4112 } |
4342 break; | 4113 break; |
4343 } | 4114 } |
4344 | 4115 |
4345 case content::NOTIFICATION_INTERSTITIAL_ATTACHED: | 4116 case content::NOTIFICATION_INTERSTITIAL_ATTACHED: |
4346 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); | 4117 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
4347 break; | 4118 break; |
4348 | 4119 |
| 4120 case chrome::NOTIFICATION_FULLSCREEN_CHANGED: |
| 4121 UpdateCommandsForFullscreenMode(window_->IsFullscreen()); |
| 4122 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN); |
| 4123 break; |
| 4124 |
4349 default: | 4125 default: |
4350 NOTREACHED() << "Got a notification we didn't register for."; | 4126 NOTREACHED() << "Got a notification we didn't register for."; |
4351 } | 4127 } |
4352 } | 4128 } |
4353 | 4129 |
4354 /////////////////////////////////////////////////////////////////////////////// | 4130 /////////////////////////////////////////////////////////////////////////////// |
4355 // Browser, ProfileSyncServiceObserver implementation: | 4131 // Browser, ProfileSyncServiceObserver implementation: |
4356 | 4132 |
4357 void Browser::OnStateChanged() { | 4133 void Browser::OnStateChanged() { |
4358 DCHECK(profile_->GetProfileSyncService()); | 4134 DCHECK(profile_->GetProfileSyncService()); |
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5466 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); | 5242 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); |
5467 } else if (is_type_tabbed()) { | 5243 } else if (is_type_tabbed()) { |
5468 GlobalErrorService* service = | 5244 GlobalErrorService* service = |
5469 GlobalErrorServiceFactory::GetForProfile(profile()); | 5245 GlobalErrorServiceFactory::GetForProfile(profile()); |
5470 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); | 5246 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); |
5471 if (error) { | 5247 if (error) { |
5472 error->ShowBubbleView(this); | 5248 error->ShowBubbleView(this); |
5473 } | 5249 } |
5474 } | 5250 } |
5475 } | 5251 } |
5476 | |
5477 FullscreenExitBubbleType Browser::GetFullscreenExitBubbleType() const { | |
5478 bool tab_fullscreen_requested = | |
5479 fullscreened_tab_ && !tab_fullscreen_accepted_; | |
5480 if (!tab_fullscreen_requested && !tab_fullscreen_accepted_) { | |
5481 DCHECK_EQ(mouse_lock_state_, MOUSELOCK_NOT_REQUESTED); | |
5482 return FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; | |
5483 } | |
5484 if (tab_fullscreen_requested) { | |
5485 DCHECK_NE(mouse_lock_state_, MOUSELOCK_ACCEPTED); | |
5486 return mouse_lock_state_ == MOUSELOCK_REQUESTED ? | |
5487 FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS : FEB_TYPE_FULLSCREEN_BUTTONS; | |
5488 } | |
5489 if (mouse_lock_state_ == MOUSELOCK_REQUESTED) | |
5490 return FEB_TYPE_MOUSELOCK_BUTTONS; | |
5491 return mouse_lock_state_ == MOUSELOCK_ACCEPTED ? | |
5492 FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION : | |
5493 FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION; | |
5494 } | |
5495 | |
5496 void Browser::UpdateFullscreenExitBubbleContent() { | |
5497 GURL url; | |
5498 if (fullscreened_tab_) | |
5499 url = fullscreened_tab_->tab_contents()->GetURL(); | |
5500 | |
5501 window_->UpdateFullscreenExitBubbleContent( | |
5502 url, GetFullscreenExitBubbleType()); | |
5503 } | |
OLD | NEW |