OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <shellapi.h> | 8 #include <shellapi.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 #endif // OS_WIN | 10 #endif // OS_WIN |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 url = extension->GetFullLaunchURL(); | 548 url = extension->GetFullLaunchURL(); |
549 } | 549 } |
550 | 550 |
551 std::string app_name; | 551 std::string app_name; |
552 if (extension) | 552 if (extension) |
553 app_name = | 553 app_name = |
554 web_app::GenerateApplicationNameFromExtensionId(extension->id()); | 554 web_app::GenerateApplicationNameFromExtensionId(extension->id()); |
555 else | 555 else |
556 app_name = web_app::GenerateApplicationNameFromURL(url); | 556 app_name = web_app::GenerateApplicationNameFromURL(url); |
557 | 557 |
558 RegisterAppPrefs(app_name); | 558 RegisterAppPrefs(app_name, profile); |
559 | 559 |
560 bool as_panel = extension && (container == extension_misc::LAUNCH_PANEL); | 560 bool as_panel = extension && (container == extension_misc::LAUNCH_PANEL); |
561 | 561 |
562 gfx::Size window_size; | 562 gfx::Size window_size; |
563 if (extension) | 563 if (extension) |
564 window_size.SetSize(extension->launch_width(), | 564 window_size.SetSize(extension->launch_width(), |
565 extension->launch_height()); | 565 extension->launch_height()); |
566 | 566 |
567 Browser* browser = Browser::CreateForApp(app_name, window_size, profile, | 567 Browser* browser = Browser::CreateForApp(app_name, window_size, profile, |
568 as_panel); | 568 as_panel); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 // In playback/record mode we always fix the size of the browser and | 766 // In playback/record mode we always fix the size of the browser and |
767 // move it to (0,0). The reason for this is two reasons: First we want | 767 // move it to (0,0). The reason for this is two reasons: First we want |
768 // resize/moves in the playback to still work, and Second we want | 768 // resize/moves in the playback to still work, and Second we want |
769 // playbacks to work (as much as possible) on machines w/ different | 769 // playbacks to work (as much as possible) on machines w/ different |
770 // screen sizes. | 770 // screen sizes. |
771 return gfx::Rect(0, 0, 800, 600); | 771 return gfx::Rect(0, 0, 800, 600); |
772 } | 772 } |
773 | 773 |
774 gfx::Rect restored_bounds = override_bounds_; | 774 gfx::Rect restored_bounds = override_bounds_; |
775 bool maximized; | 775 bool maximized; |
776 WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, NULL, | 776 WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, this, |
777 &restored_bounds, &maximized); | 777 &restored_bounds, &maximized); |
778 return restored_bounds; | 778 return restored_bounds; |
779 } | 779 } |
780 | 780 |
781 // TODO(beng): obtain maximized state some other way so we don't need to go | 781 // TODO(beng): obtain maximized state some other way so we don't need to go |
782 // through all this hassle. | 782 // through all this hassle. |
783 bool Browser::GetSavedMaximizedState() const { | 783 bool Browser::GetSavedMaximizedState() const { |
784 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kStartMaximized)) | 784 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kStartMaximized)) |
785 return true; | 785 return true; |
786 | 786 |
787 if (maximized_state_ == MAXIMIZED_STATE_MAXIMIZED) | 787 if (maximized_state_ == MAXIMIZED_STATE_MAXIMIZED) |
788 return true; | 788 return true; |
789 if (maximized_state_ == MAXIMIZED_STATE_UNMAXIMIZED) | 789 if (maximized_state_ == MAXIMIZED_STATE_UNMAXIMIZED) |
790 return false; | 790 return false; |
791 | 791 |
792 // An explicit maximized state was not set. Query the window sizer. | 792 // An explicit maximized state was not set. Query the window sizer. |
793 gfx::Rect restored_bounds; | 793 gfx::Rect restored_bounds; |
794 bool maximized = false; | 794 bool maximized = false; |
795 WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, NULL, | 795 WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, this, |
796 &restored_bounds, &maximized); | 796 &restored_bounds, &maximized); |
797 return maximized; | 797 return maximized; |
798 } | 798 } |
799 | 799 |
800 SkBitmap Browser::GetCurrentPageIcon() const { | 800 SkBitmap Browser::GetCurrentPageIcon() const { |
801 TabContents* contents = GetSelectedTabContents(); | 801 TabContents* contents = GetSelectedTabContents(); |
802 // |contents| can be NULL since GetCurrentPageIcon() is called by the window | 802 // |contents| can be NULL since GetCurrentPageIcon() is called by the window |
803 // during the window's creation (before tabs have been added). | 803 // during the window's creation (before tabs have been added). |
804 return contents ? contents->GetFavIcon() : SkBitmap(); | 804 return contents ? contents->GetFavIcon() : SkBitmap(); |
805 } | 805 } |
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2002 const PrefService::Preference* home_page_is_new_tab_page_pref = | 2002 const PrefService::Preference* home_page_is_new_tab_page_pref = |
2003 prefs->FindPreference(prefs::kHomePageIsNewTabPage); | 2003 prefs->FindPreference(prefs::kHomePageIsNewTabPage); |
2004 if (home_page_is_new_tab_page_pref && | 2004 if (home_page_is_new_tab_page_pref && |
2005 !home_page_is_new_tab_page_pref->IsManaged() && | 2005 !home_page_is_new_tab_page_pref->IsManaged() && |
2006 !prefs->HasPrefPath(prefs::kHomePageIsNewTabPage)) | 2006 !prefs->HasPrefPath(prefs::kHomePageIsNewTabPage)) |
2007 prefs->SetBoolean(prefs::kHomePageIsNewTabPage, false); | 2007 prefs->SetBoolean(prefs::kHomePageIsNewTabPage, false); |
2008 } | 2008 } |
2009 | 2009 |
2010 // static | 2010 // static |
2011 void Browser::RegisterPrefs(PrefService* prefs) { | 2011 void Browser::RegisterPrefs(PrefService* prefs) { |
2012 prefs->RegisterDictionaryPref(prefs::kBrowserWindowPlacement); | |
2013 prefs->RegisterIntegerPref(prefs::kOptionsWindowLastTabIndex, 0); | 2012 prefs->RegisterIntegerPref(prefs::kOptionsWindowLastTabIndex, 0); |
2014 prefs->RegisterIntegerPref(prefs::kDevToolsSplitLocation, -1); | |
2015 prefs->RegisterDictionaryPref(prefs::kPreferencesWindowPlacement); | 2013 prefs->RegisterDictionaryPref(prefs::kPreferencesWindowPlacement); |
2016 prefs->RegisterIntegerPref(prefs::kExtensionSidebarWidth, -1); | 2014 prefs->RegisterIntegerPref(prefs::kExtensionSidebarWidth, -1); |
| 2015 prefs->RegisterIntegerPref(prefs::kMultipleProfilePrefMigration, 0); |
2017 // Educated guess: Chrome has a bundled Flash version supporting | 2016 // Educated guess: Chrome has a bundled Flash version supporting |
2018 // clearing LSO data, Chromium hasn't. | 2017 // clearing LSO data, Chromium hasn't. |
2019 #if defined(GOOGLE_CHROME_BUILD) | 2018 #if defined(GOOGLE_CHROME_BUILD) |
2020 prefs->RegisterBooleanPref(prefs::kClearPluginLSODataEnabled, true); | 2019 prefs->RegisterBooleanPref(prefs::kClearPluginLSODataEnabled, true); |
2021 #else | 2020 #else |
2022 prefs->RegisterBooleanPref(prefs::kClearPluginLSODataEnabled, false); | 2021 prefs->RegisterBooleanPref(prefs::kClearPluginLSODataEnabled, false); |
2023 #endif | 2022 #endif |
2024 } | 2023 } |
2025 | 2024 |
2026 // static | 2025 // static |
(...skipping 28 matching lines...) Expand all Loading... |
2055 prefs->RegisterBooleanPref(prefs::kWebAppCreateOnDesktop, true); | 2054 prefs->RegisterBooleanPref(prefs::kWebAppCreateOnDesktop, true); |
2056 prefs->RegisterBooleanPref(prefs::kWebAppCreateInAppsMenu, true); | 2055 prefs->RegisterBooleanPref(prefs::kWebAppCreateInAppsMenu, true); |
2057 prefs->RegisterBooleanPref(prefs::kWebAppCreateInQuickLaunchBar, true); | 2056 prefs->RegisterBooleanPref(prefs::kWebAppCreateInQuickLaunchBar, true); |
2058 prefs->RegisterBooleanPref(prefs::kUseVerticalTabs, false); | 2057 prefs->RegisterBooleanPref(prefs::kUseVerticalTabs, false); |
2059 prefs->RegisterBooleanPref(prefs::kEnableTranslate, true); | 2058 prefs->RegisterBooleanPref(prefs::kEnableTranslate, true); |
2060 prefs->RegisterBooleanPref(prefs::kRemotingHasSetupCompleted, false); | 2059 prefs->RegisterBooleanPref(prefs::kRemotingHasSetupCompleted, false); |
2061 prefs->RegisterStringPref(prefs::kCloudPrintEmail, std::string()); | 2060 prefs->RegisterStringPref(prefs::kCloudPrintEmail, std::string()); |
2062 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, false); | 2061 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, false); |
2063 prefs->RegisterBooleanPref(prefs::kIncognitoEnabled, true); | 2062 prefs->RegisterBooleanPref(prefs::kIncognitoEnabled, true); |
2064 prefs->RegisterDoublePref(prefs::kDefaultZoomLevel, 0.0); | 2063 prefs->RegisterDoublePref(prefs::kDefaultZoomLevel, 0.0); |
2065 prefs->RegisterIntegerPref(prefs::kMultipleProfilePrefMigration, 0); | 2064 prefs->RegisterIntegerPref(prefs::kDevToolsSplitLocation, -1); |
| 2065 prefs->RegisterDictionaryPref(prefs::kBrowserWindowPlacement); |
2066 // We need to register the type of this preference in order to query | 2066 // We need to register the type of this preference in order to query |
2067 // it even though it's only typically controlled via policy. | 2067 // it even though it's only typically controlled via policy. |
2068 prefs->RegisterBooleanPref(prefs::kDisable3DAPIs, false); | 2068 prefs->RegisterBooleanPref(prefs::kDisable3DAPIs, false); |
2069 } | 2069 } |
2070 | 2070 |
2071 // static | 2071 // static |
2072 bool Browser::RunUnloadEventsHelper(TabContents* contents) { | 2072 bool Browser::RunUnloadEventsHelper(TabContents* contents) { |
2073 // If the TabContents is not connected yet, then there's no unload | 2073 // If the TabContents is not connected yet, then there's no unload |
2074 // handler we can fire even if the TabContents has an unload listener. | 2074 // handler we can fire even if the TabContents has an unload listener. |
2075 // One case where we hit this is in a tab that has an infinite loop | 2075 // One case where we hit this is in a tab that has an infinite loop |
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2997 return false; | 2997 return false; |
2998 } | 2998 } |
2999 | 2999 |
3000 bool Browser::IsApplication() const { | 3000 bool Browser::IsApplication() const { |
3001 return (type_ & TYPE_APP) != 0; | 3001 return (type_ & TYPE_APP) != 0; |
3002 } | 3002 } |
3003 | 3003 |
3004 void Browser::ConvertContentsToApplication(TabContents* contents) { | 3004 void Browser::ConvertContentsToApplication(TabContents* contents) { |
3005 const GURL& url = contents->controller().GetActiveEntry()->url(); | 3005 const GURL& url = contents->controller().GetActiveEntry()->url(); |
3006 std::string app_name = web_app::GenerateApplicationNameFromURL(url); | 3006 std::string app_name = web_app::GenerateApplicationNameFromURL(url); |
3007 RegisterAppPrefs(app_name); | 3007 RegisterAppPrefs(app_name, contents->profile()); |
3008 | 3008 |
3009 DetachContents(contents); | 3009 DetachContents(contents); |
3010 Browser* app_browser = Browser::CreateForApp( | 3010 Browser* app_browser = Browser::CreateForApp( |
3011 app_name, gfx::Size(), profile_, false); | 3011 app_name, gfx::Size(), profile_, false); |
3012 TabContentsWrapper* wrapper = new TabContentsWrapper(contents); | 3012 TabContentsWrapper* wrapper = new TabContentsWrapper(contents); |
3013 app_browser->tabstrip_model()->AppendTabContents(wrapper, true); | 3013 app_browser->tabstrip_model()->AppendTabContents(wrapper, true); |
3014 | 3014 |
3015 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 3015 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
3016 contents->render_view_host()->SyncRendererPrefs(); | 3016 contents->render_view_host()->SyncRendererPrefs(); |
3017 app_browser->window()->Show(); | 3017 app_browser->window()->Show(); |
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4152 // us). Avoid that by passing in false so that the call to | 4152 // us). Avoid that by passing in false so that the call to |
4153 // ProcessPendingTabs is delayed. | 4153 // ProcessPendingTabs is delayed. |
4154 ClearUnloadState(contents->tab_contents(), false); | 4154 ClearUnloadState(contents->tab_contents(), false); |
4155 } | 4155 } |
4156 | 4156 |
4157 registrar_.Remove(this, NotificationType::TAB_CONTENTS_DISCONNECTED, | 4157 registrar_.Remove(this, NotificationType::TAB_CONTENTS_DISCONNECTED, |
4158 Source<TabContentsWrapper>(contents)); | 4158 Source<TabContentsWrapper>(contents)); |
4159 } | 4159 } |
4160 | 4160 |
4161 // static | 4161 // static |
4162 void Browser::RegisterAppPrefs(const std::string& app_name) { | 4162 void Browser::RegisterAppPrefs(const std::string& app_name, Profile* profile) { |
4163 // A set of apps that we've already started. | 4163 // A set of apps that we've already started. |
4164 static std::set<std::string>* g_app_names = NULL; | 4164 static std::set<std::string>* g_app_names = NULL; |
4165 | 4165 |
4166 if (!g_app_names) | 4166 if (!g_app_names) |
4167 g_app_names = new std::set<std::string>; | 4167 g_app_names = new std::set<std::string>; |
4168 | 4168 |
4169 // Only register once for each app name. | 4169 // Only register once for each app name. |
4170 if (g_app_names->find(app_name) != g_app_names->end()) | 4170 if (g_app_names->find(app_name) != g_app_names->end()) |
4171 return; | 4171 return; |
4172 g_app_names->insert(app_name); | 4172 g_app_names->insert(app_name); |
4173 | 4173 |
4174 // We need to register the window position pref. | 4174 // We need to register the window position pref. |
4175 std::string window_pref(prefs::kBrowserWindowPlacement); | 4175 std::string window_pref(prefs::kBrowserWindowPlacement); |
4176 window_pref.append("_"); | 4176 window_pref.append("_"); |
4177 window_pref.append(app_name); | 4177 window_pref.append(app_name); |
4178 PrefService* prefs = g_browser_process->local_state(); | 4178 profile->GetPrefs()->RegisterDictionaryPref(window_pref.c_str()); |
4179 DCHECK(prefs); | |
4180 | |
4181 prefs->RegisterDictionaryPref(window_pref.c_str()); | |
4182 } | 4179 } |
4183 | 4180 |
4184 void Browser::TabRestoreServiceChanged(TabRestoreService* service) { | 4181 void Browser::TabRestoreServiceChanged(TabRestoreService* service) { |
4185 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, | 4182 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, |
4186 !service->entries().empty()); | 4183 !service->entries().empty()); |
4187 } | 4184 } |
4188 | 4185 |
4189 void Browser::TabRestoreServiceDestroyed(TabRestoreService* service) { | 4186 void Browser::TabRestoreServiceDestroyed(TabRestoreService* service) { |
4190 if (!tab_restore_service_) | 4187 if (!tab_restore_service_) |
4191 return; | 4188 return; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4303 // The page transition below is only for the purpose of inserting the tab. | 4300 // The page transition below is only for the purpose of inserting the tab. |
4304 browser->AddTab(view_source_contents, PageTransition::LINK); | 4301 browser->AddTab(view_source_contents, PageTransition::LINK); |
4305 } | 4302 } |
4306 | 4303 |
4307 if (profile_->HasSessionService()) { | 4304 if (profile_->HasSessionService()) { |
4308 SessionService* session_service = profile_->GetSessionService(); | 4305 SessionService* session_service = profile_->GetSessionService(); |
4309 if (session_service) | 4306 if (session_service) |
4310 session_service->TabRestored(&view_source_contents->controller(), false); | 4307 session_service->TabRestored(&view_source_contents->controller(), false); |
4311 } | 4308 } |
4312 } | 4309 } |
OLD | NEW |