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 22 matching lines...) Expand all Loading... | |
139 #include "content/browser/debugger/devtools_manager.h" | 140 #include "content/browser/debugger/devtools_manager.h" |
140 #include "content/browser/download/download_item.h" | 141 #include "content/browser/download/download_item.h" |
141 #include "content/browser/download/download_manager.h" | 142 #include "content/browser/download/download_manager.h" |
142 #include "content/browser/download/save_package.h" | 143 #include "content/browser/download/save_package.h" |
143 #include "content/browser/host_zoom_map.h" | 144 #include "content/browser/host_zoom_map.h" |
144 #include "content/browser/plugin_service.h" | 145 #include "content/browser/plugin_service.h" |
145 #include "content/browser/renderer_host/render_view_host.h" | 146 #include "content/browser/renderer_host/render_view_host.h" |
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" |
150 #include "content/browser/tab_contents/navigation_details.h" | |
yzshen1
2011/11/04 01:56:32
Why this is needed?
koz (OOO until 15th September)
2011/11/06 23:30:20
Hm, turns out it's not. I'm not sure how that got
| |
149 #include "content/browser/tab_contents/navigation_entry.h" | 151 #include "content/browser/tab_contents/navigation_entry.h" |
150 #include "content/browser/tab_contents/tab_contents_view.h" | 152 #include "content/browser/tab_contents/tab_contents_view.h" |
151 #include "content/browser/user_metrics.h" | 153 #include "content/browser/user_metrics.h" |
152 #include "content/public/browser/notification_service.h" | 154 #include "content/public/browser/notification_service.h" |
153 #include "content/public/browser/notification_details.h" | 155 #include "content/public/browser/notification_details.h" |
154 #include "content/public/common/content_restriction.h" | 156 #include "content/public/common/content_restriction.h" |
155 #include "content/public/common/content_switches.h" | 157 #include "content/public/common/content_switches.h" |
156 #include "grit/chromium_strings.h" | |
157 #include "grit/generated_resources.h" | 158 #include "grit/generated_resources.h" |
158 #include "grit/locale_settings.h" | 159 #include "grit/locale_settings.h" |
159 #include "grit/theme_resources_standard.h" | 160 #include "grit/theme_resources_standard.h" |
160 #include "net/base/cookie_monster.h" | 161 #include "net/base/cookie_monster.h" |
161 #include "net/base/net_util.h" | 162 #include "net/base/net_util.h" |
162 #include "net/base/registry_controlled_domain.h" | 163 #include "net/base/registry_controlled_domain.h" |
163 #include "net/url_request/url_request_context.h" | 164 #include "net/url_request/url_request_context.h" |
164 #include "ui/base/animation/animation.h" | 165 #include "ui/base/animation/animation.h" |
165 #include "ui/base/l10n/l10n_util.h" | 166 #include "ui/base/l10n/l10n_util.h" |
166 #include "ui/gfx/point.h" | 167 #include "ui/gfx/point.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 last_blocked_command_id_(-1), | 282 last_blocked_command_id_(-1), |
282 last_blocked_command_disposition_(CURRENT_TAB), | 283 last_blocked_command_disposition_(CURRENT_TAB), |
283 pending_web_app_action_(NONE), | 284 pending_web_app_action_(NONE), |
284 ALLOW_THIS_IN_INITIALIZER_LIST( | 285 ALLOW_THIS_IN_INITIALIZER_LIST( |
285 tab_restore_service_delegate_( | 286 tab_restore_service_delegate_( |
286 new BrowserTabRestoreServiceDelegate(this))), | 287 new BrowserTabRestoreServiceDelegate(this))), |
287 ALLOW_THIS_IN_INITIALIZER_LIST( | 288 ALLOW_THIS_IN_INITIALIZER_LIST( |
288 synced_window_delegate_( | 289 synced_window_delegate_( |
289 new BrowserSyncedWindowDelegate(this))), | 290 new BrowserSyncedWindowDelegate(this))), |
290 bookmark_bar_state_(BookmarkBar::HIDDEN), | 291 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) { | 292 window_has_shown_(false) { |
296 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, | 293 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, |
297 content::NotificationService::AllSources()); | 294 content::NotificationService::AllSources()); |
298 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, | 295 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
299 content::Source<Profile>(profile_)); | 296 content::Source<Profile>(profile_)); |
300 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 297 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
301 content::Source<Profile>(profile_)); | 298 content::Source<Profile>(profile_)); |
302 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 299 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
303 content::Source<Profile>(profile_)); | 300 content::Source<Profile>(profile_)); |
304 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 301 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 } | 396 } |
400 | 397 |
401 // There may be pending file dialogs, we need to tell them that we've gone | 398 // 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. | 399 // away so they don't try and call back to us. |
403 if (select_file_dialog_.get()) | 400 if (select_file_dialog_.get()) |
404 select_file_dialog_->ListenerDestroyed(); | 401 select_file_dialog_->ListenerDestroyed(); |
405 | 402 |
406 TabRestoreServiceDestroyed(tab_restore_service_); | 403 TabRestoreServiceDestroyed(tab_restore_service_); |
407 } | 404 } |
408 | 405 |
406 bool Browser::IsFullscreenForTab() const { | |
yzshen1
2011/11/04 01:56:32
Please try to keep the method definition the same
koz (OOO until 15th September)
2011/11/06 23:30:20
Done.
| |
407 return fullscreen_controller_->IsFullscreenForTab(); | |
408 } | |
409 | |
409 // static | 410 // static |
410 Browser* Browser::Create(Profile* profile) { | 411 Browser* Browser::Create(Profile* profile) { |
411 Browser* browser = new Browser(TYPE_TABBED, profile); | 412 Browser* browser = new Browser(TYPE_TABBED, profile); |
412 browser->InitBrowserWindow(); | 413 browser->InitBrowserWindow(); |
413 return browser; | 414 return browser; |
414 } | 415 } |
415 | 416 |
416 // static | 417 // static |
417 Browser* Browser::CreateWithParams(const CreateParams& params) { | 418 Browser* Browser::CreateWithParams(const CreateParams& params) { |
418 Browser* browser = new Browser(params.type, params.profile); | 419 Browser* browser = new Browser(params.type, params.profile); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
510 #if defined(OS_WIN) | 511 #if defined(OS_WIN) |
511 ImportAutofillDataWin(PersonalDataManagerFactory::GetForProfile(profile_)); | 512 ImportAutofillDataWin(PersonalDataManagerFactory::GetForProfile(profile_)); |
512 #endif // defined(OS_WIN) | 513 #endif // defined(OS_WIN) |
513 // Reset the preference so we don't call it again for subsequent windows. | 514 // Reset the preference so we don't call it again for subsequent windows. |
514 local_state->ClearPref(prefs::kAutofillPersonalDataManagerFirstRun); | 515 local_state->ClearPref(prefs::kAutofillPersonalDataManagerFirstRun); |
515 } | 516 } |
516 | 517 |
517 // Permanently dismiss ntp4 bubble for new users. | 518 // Permanently dismiss ntp4 bubble for new users. |
518 if (FirstRun::IsChromeFirstRun()) | 519 if (FirstRun::IsChromeFirstRun()) |
519 NewTabPageHandler::DismissIntroMessage(local_state); | 520 NewTabPageHandler::DismissIntroMessage(local_state); |
521 fullscreen_controller_ = new FullscreenController(window_, profile_, this); | |
Peter Kasting
2011/11/03 18:24:56
Nit: Seems like this might be better just below th
koz (OOO until 15th September)
2011/11/06 23:30:20
Done.
| |
520 } | 522 } |
521 | 523 |
522 /////////////////////////////////////////////////////////////////////////////// | 524 /////////////////////////////////////////////////////////////////////////////// |
523 // Getters & Setters | 525 // Getters & Setters |
524 | 526 |
525 FindBarController* Browser::GetFindBarController() { | 527 FindBarController* Browser::GetFindBarController() { |
526 if (!find_bar_controller_.get()) { | 528 if (!find_bar_controller_.get()) { |
527 FindBar* find_bar = window_->CreateFindBar(); | 529 FindBar* find_bar = window_->CreateFindBar(); |
528 find_bar_controller_.reset(new FindBarController(find_bar)); | 530 find_bar_controller_.reset(new FindBarController(find_bar)); |
529 find_bar->SetFindBarController(find_bar_controller_.get()); | 531 find_bar->SetFindBarController(find_bar_controller_.get()); |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1353 contents_url == GURL(chrome::kAboutBlankURL)) && | 1355 contents_url == GURL(chrome::kAboutBlankURL)) && |
1354 browser::GetIndexOfSingletonTab(&local_params) < 0) { | 1356 browser::GetIndexOfSingletonTab(&local_params) < 0) { |
1355 local_params.disposition = CURRENT_TAB; | 1357 local_params.disposition = CURRENT_TAB; |
1356 } | 1358 } |
1357 } | 1359 } |
1358 | 1360 |
1359 browser::Navigate(&local_params); | 1361 browser::Navigate(&local_params); |
1360 } | 1362 } |
1361 | 1363 |
1362 void Browser::WindowFullscreenStateChanged() { | 1364 void Browser::WindowFullscreenStateChanged() { |
1363 UpdateCommandsForFullscreenMode(window_->IsFullscreen()); | 1365 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 } | 1366 } |
1384 | 1367 |
1385 /////////////////////////////////////////////////////////////////////////////// | 1368 /////////////////////////////////////////////////////////////////////////////// |
1386 // Browser, Assorted browser commands: | 1369 // Browser, Assorted browser commands: |
1387 | 1370 |
1388 TabContents* Browser::GetOrCloneTabForDisposition( | 1371 TabContents* Browser::GetOrCloneTabForDisposition( |
1389 WindowOpenDisposition disposition) { | 1372 WindowOpenDisposition disposition) { |
1390 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); | 1373 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); |
1391 switch (disposition) { | 1374 switch (disposition) { |
1392 case NEW_FOREGROUND_TAB: | 1375 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(); | 1696 int tab_strip_index = tab_handler_->GetTabStripModel()->active_index(); |
1714 TabContentsWrapper* contents = | 1697 TabContentsWrapper* contents = |
1715 tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); | 1698 tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); |
1716 Browser* browser = Browser::Create(profile_); | 1699 Browser* browser = Browser::Create(profile_); |
1717 browser->tabstrip_model()->AppendTabContents(contents, true); | 1700 browser->tabstrip_model()->AppendTabContents(contents, true); |
1718 browser->window()->Show(); | 1701 browser->window()->Show(); |
1719 } | 1702 } |
1720 | 1703 |
1721 // TODO(koz): Change |for_tab| to an enum. | 1704 // TODO(koz): Change |for_tab| to an enum. |
1722 void Browser::ToggleFullscreenMode(bool for_tab) { | 1705 void Browser::ToggleFullscreenMode(bool for_tab) { |
1723 bool entering_fullscreen = !window_->IsFullscreen(); | 1706 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 } | 1707 } |
1771 | 1708 |
1772 #if defined(OS_MACOSX) | 1709 #if defined(OS_MACOSX) |
1773 void Browser::TogglePresentationMode(bool for_tab) { | 1710 void Browser::TogglePresentationMode(bool for_tab) { |
1774 bool entering_fullscreen = !window_->InPresentationMode(); | 1711 fullscreen_controller_->TogglePresentationMode(for_tab); |
yzshen1
2011/11/04 01:56:32
FYI, jeremy is changing the content of this method
koz (OOO until 15th September)
2011/11/06 23:30:20
Yep, I will. Thanks for the tip.
| |
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 } | 1712 } |
1794 #endif | 1713 #endif |
1795 | 1714 |
1796 #if defined(OS_CHROMEOS) | 1715 #if defined(OS_CHROMEOS) |
1797 void Browser::Search() { | 1716 void Browser::Search() { |
1798 // Exit fullscreen to show omnibox. | 1717 // Exit fullscreen to show omnibox. |
1799 if (window_->IsFullscreen()) { | 1718 if (window_->IsFullscreen()) { |
1800 ToggleFullscreenMode(false); | 1719 ToggleFullscreenMode(false); |
1801 // ToggleFullscreenMode is asynchronous, so we don't have omnibox | 1720 // ToggleFullscreenMode is asynchronous, so we don't have omnibox |
1802 // visible at this point. Wait for next event cycle which toggles | 1721 // 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, | 3147 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, |
3229 content::Source<TabContents>(contents->tab_contents())); | 3148 content::Source<TabContents>(contents->tab_contents())); |
3230 | 3149 |
3231 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, | 3150 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
3232 content::Source<TabContents>(contents->tab_contents())); | 3151 content::Source<TabContents>(contents->tab_contents())); |
3233 } | 3152 } |
3234 | 3153 |
3235 void Browser::TabClosingAt(TabStripModel* tab_strip_model, | 3154 void Browser::TabClosingAt(TabStripModel* tab_strip_model, |
3236 TabContentsWrapper* contents, | 3155 TabContentsWrapper* contents, |
3237 int index) { | 3156 int index) { |
3238 if (fullscreened_tab_ == contents) { | 3157 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( | 3158 content::NotificationService::current()->Notify( |
3248 content::NOTIFICATION_TAB_CLOSING, | 3159 content::NOTIFICATION_TAB_CLOSING, |
3249 content::Source<NavigationController>(&contents->controller()), | 3160 content::Source<NavigationController>(&contents->controller()), |
3250 content::NotificationService::NoDetails()); | 3161 content::NotificationService::NoDetails()); |
3251 | 3162 |
3252 // Sever the TabContents' connection back to us. | 3163 // Sever the TabContents' connection back to us. |
3253 SetAsDelegate(contents, NULL); | 3164 SetAsDelegate(contents, NULL); |
3254 } | 3165 } |
3255 | 3166 |
3256 void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { | 3167 void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { |
3257 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); | 3168 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); |
3258 } | 3169 } |
3259 | 3170 |
3260 void Browser::TabDeactivated(TabContentsWrapper* contents) { | 3171 void Browser::TabDeactivated(TabContentsWrapper* contents) { |
3261 if (contents == fullscreened_tab_) | 3172 fullscreen_controller_->OnTabDeactivated(contents); |
3262 ExitTabbedFullscreenModeIfNecessary(); | |
3263 if (instant()) | 3173 if (instant()) |
3264 instant()->Hide(); | 3174 instant()->Hide(); |
3265 | 3175 |
3266 // Save what the user's currently typing, so it can be restored when we | 3176 // Save what the user's currently typing, so it can be restored when we |
3267 // switch back to this tab. | 3177 // switch back to this tab. |
3268 window_->GetLocationBar()->SaveStateToContents(contents->tab_contents()); | 3178 window_->GetLocationBar()->SaveStateToContents(contents->tab_contents()); |
3269 } | 3179 } |
3270 | 3180 |
3271 void Browser::ActiveTabChanged(TabContentsWrapper* old_contents, | 3181 void Browser::ActiveTabChanged(TabContentsWrapper* old_contents, |
3272 TabContentsWrapper* new_contents, | 3182 TabContentsWrapper* new_contents, |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3790 DCHECK(source); | 3700 DCHECK(source); |
3791 int index = tabstrip_model()->GetWrapperIndex(source); | 3701 int index = tabstrip_model()->GetWrapperIndex(source); |
3792 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); | 3702 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); |
3793 ViewSource(wrapper, frame_url, frame_content_state); | 3703 ViewSource(wrapper, frame_url, frame_content_state); |
3794 } | 3704 } |
3795 | 3705 |
3796 bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | 3706 bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
3797 bool* is_keyboard_shortcut) { | 3707 bool* is_keyboard_shortcut) { |
3798 // Escape exits tabbed fullscreen mode. | 3708 // Escape exits tabbed fullscreen mode. |
3799 // TODO(koz): Write a test for this http://crbug.com/100441. | 3709 // TODO(koz): Write a test for this http://crbug.com/100441. |
3800 if (event.windowsKeyCode == 27 && fullscreened_tab_) { | 3710 if (event.windowsKeyCode == 27 && |
3801 ExitTabbedFullscreenModeIfNecessary(); | 3711 fullscreen_controller_->HandleUserPressedEscape()) { |
3802 return true; | 3712 return true; |
3803 } | 3713 } |
3804 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); | 3714 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); |
3805 } | 3715 } |
3806 | 3716 |
3807 void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { | 3717 void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
3808 window()->HandleKeyboardEvent(event); | 3718 window()->HandleKeyboardEvent(event); |
3809 } | 3719 } |
3810 | 3720 |
3811 void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) { | 3721 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) { | 3789 const ViewHostMsg_RunFileChooser_Params& params) { |
3880 RunFileChooserHelper(tab, params); | 3790 RunFileChooserHelper(tab, params); |
3881 } | 3791 } |
3882 | 3792 |
3883 void Browser::EnumerateDirectory(TabContents* tab, int request_id, | 3793 void Browser::EnumerateDirectory(TabContents* tab, int request_id, |
3884 const FilePath& path) { | 3794 const FilePath& path) { |
3885 EnumerateDirectoryHelper(tab, request_id, path); | 3795 EnumerateDirectoryHelper(tab, request_id, path); |
3886 } | 3796 } |
3887 | 3797 |
3888 void Browser::ToggleFullscreenModeForTab(TabContents* tab, | 3798 void Browser::ToggleFullscreenModeForTab(TabContents* tab, |
3889 bool enter_fullscreen) { | 3799 bool enter_fullscreen) { |
Peter Kasting
2011/11/03 18:24:56
Nit: While here, indent this arg even with the oth
koz (OOO until 15th September)
2011/11/06 23:30:20
Done.
| |
3890 if (tab != GetSelectedTabContents()) | 3800 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 } | 3801 } |
3938 | 3802 |
3939 bool Browser::IsFullscreenForTab(const TabContents* tab) const { | 3803 bool Browser::IsFullscreenForTab(const TabContents* tab) const { |
3940 const TabContentsWrapper* wrapper = | 3804 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 } | 3805 } |
3948 | 3806 |
3949 void Browser::JSOutOfMemory(TabContents* tab) { | 3807 void Browser::JSOutOfMemory(TabContents* tab) { |
3950 JSOutOfMemoryHelper(tab); | 3808 JSOutOfMemoryHelper(tab); |
3951 } | 3809 } |
3952 | 3810 |
3953 void Browser::RegisterProtocolHandler(TabContents* tab, | 3811 void Browser::RegisterProtocolHandler(TabContents* tab, |
3954 const std::string& protocol, | 3812 const std::string& protocol, |
3955 const GURL& url, | 3813 const GURL& url, |
3956 const string16& title) { | 3814 const string16& title) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3989 int active_match_ordinal, | 3847 int active_match_ordinal, |
3990 bool final_update) { | 3848 bool final_update) { |
3991 FindReplyHelper(tab, request_id, number_of_matches, selection_rect, | 3849 FindReplyHelper(tab, request_id, number_of_matches, selection_rect, |
3992 active_match_ordinal, final_update); | 3850 active_match_ordinal, final_update); |
3993 } | 3851 } |
3994 | 3852 |
3995 void Browser::CrashedPlugin(TabContents* tab, const FilePath& plugin_path) { | 3853 void Browser::CrashedPlugin(TabContents* tab, const FilePath& plugin_path) { |
3996 CrashedPluginHelper(tab, plugin_path); | 3854 CrashedPluginHelper(tab, plugin_path); |
3997 } | 3855 } |
3998 | 3856 |
3999 void Browser::ExitTabbedFullscreenModeIfNecessary() { | |
4000 if (tab_caused_fullscreen_) | |
4001 ToggleFullscreenMode(false); | |
4002 else | |
4003 NotifyTabOfFullscreenExitIfNecessary(); | |
4004 } | |
4005 | |
4006 void Browser::UpdatePreferredSize(TabContents* source, | 3857 void Browser::UpdatePreferredSize(TabContents* source, |
4007 const gfx::Size& pref_size) { | 3858 const gfx::Size& pref_size) { |
4008 window_->UpdatePreferredSize(source, pref_size); | 3859 window_->UpdatePreferredSize(source, pref_size); |
4009 } | 3860 } |
4010 | 3861 |
4011 void Browser::RequestToLockMouse(TabContents* tab) { | 3862 void Browser::RequestToLockMouse(TabContents* tab) { |
4012 // Mouse Lock is only permitted when browser is in tab fullscreen. | 3863 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 } | 3864 } |
4040 | 3865 |
4041 void Browser::LostMouseLock() { | 3866 void Browser::LostMouseLock() { |
4042 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 3867 fullscreen_controller_->LostMouseLock(); |
4043 UpdateFullscreenExitBubbleContent(); | |
4044 } | 3868 } |
4045 | 3869 |
4046 void Browser::OnAcceptFullscreenPermission( | 3870 void Browser::OnAcceptFullscreenPermission( |
4047 const GURL& url, | 3871 const GURL& url, |
4048 FullscreenExitBubbleType bubble_type) { | 3872 FullscreenExitBubbleType bubble_type) { |
4049 bool mouse_lock = false; | 3873 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 } | 3874 } |
4077 | 3875 |
4078 void Browser::OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type) { | 3876 void Browser::OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type) { |
4079 bool mouse_lock = false; | 3877 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 } | 3878 } |
4097 | 3879 |
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 | 3880 |
4116 /////////////////////////////////////////////////////////////////////////////// | 3881 /////////////////////////////////////////////////////////////////////////////// |
4117 // Browser, TabContentsWrapperDelegate implementation: | 3882 // Browser, TabContentsWrapperDelegate implementation: |
4118 | 3883 |
4119 void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, | 3884 void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, |
4120 int32 page_id) { | 3885 int32 page_id) { |
4121 if (GetSelectedTabContentsWrapper() != source) | 3886 if (GetSelectedTabContentsWrapper() != source) |
4122 return; | 3887 return; |
4123 | 3888 |
4124 NavigationEntry* entry = source->controller().GetLastCommittedEntry(); | 3889 NavigationEntry* entry = source->controller().GetLastCommittedEntry(); |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4347 if (location_bar) | 4112 if (location_bar) |
4348 location_bar->UpdateContentSettingsIcons(); | 4113 location_bar->UpdateContentSettingsIcons(); |
4349 } | 4114 } |
4350 break; | 4115 break; |
4351 } | 4116 } |
4352 | 4117 |
4353 case content::NOTIFICATION_INTERSTITIAL_ATTACHED: | 4118 case content::NOTIFICATION_INTERSTITIAL_ATTACHED: |
4354 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); | 4119 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
4355 break; | 4120 break; |
4356 | 4121 |
4122 case chrome::NOTIFICATION_FULLSCREEN_CHANGED: | |
yzshen1
2011/11/04 01:56:32
[Not sure whether it affects anything, just want t
koz (OOO until 15th September)
2011/11/06 23:30:20
I did consider this. I tested the UpdateCommands..
| |
4123 UpdateCommandsForFullscreenMode(window_->IsFullscreen()); | |
4124 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN); | |
4125 break; | |
4126 | |
4357 default: | 4127 default: |
4358 NOTREACHED() << "Got a notification we didn't register for."; | 4128 NOTREACHED() << "Got a notification we didn't register for."; |
4359 } | 4129 } |
4360 } | 4130 } |
4361 | 4131 |
4362 /////////////////////////////////////////////////////////////////////////////// | 4132 /////////////////////////////////////////////////////////////////////////////// |
4363 // Browser, ProfileSyncServiceObserver implementation: | 4133 // Browser, ProfileSyncServiceObserver implementation: |
4364 | 4134 |
4365 void Browser::OnStateChanged() { | 4135 void Browser::OnStateChanged() { |
4366 DCHECK(profile_->GetProfileSyncService()); | 4136 DCHECK(profile_->GetProfileSyncService()); |
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5474 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); | 5244 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); |
5475 } else if (is_type_tabbed()) { | 5245 } else if (is_type_tabbed()) { |
5476 GlobalErrorService* service = | 5246 GlobalErrorService* service = |
5477 GlobalErrorServiceFactory::GetForProfile(profile()); | 5247 GlobalErrorServiceFactory::GetForProfile(profile()); |
5478 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); | 5248 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); |
5479 if (error) { | 5249 if (error) { |
5480 error->ShowBubbleView(this); | 5250 error->ShowBubbleView(this); |
5481 } | 5251 } |
5482 } | 5252 } |
5483 } | 5253 } |
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 |