| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/browser.h" | 5 #include "chrome/browser/browser.h" |
| 6 | 6 |
| 7 #include "app/animation.h" | 7 #include "app/animation.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 : type_(type), | 133 : type_(type), |
| 134 profile_(profile), | 134 profile_(profile), |
| 135 window_(NULL), | 135 window_(NULL), |
| 136 tabstrip_model_(this, profile), | 136 tabstrip_model_(this, profile), |
| 137 command_updater_(this), | 137 command_updater_(this), |
| 138 toolbar_model_(this), | 138 toolbar_model_(this), |
| 139 chrome_updater_factory_(this), | 139 chrome_updater_factory_(this), |
| 140 is_attempting_to_close_browser_(false), | 140 is_attempting_to_close_browser_(false), |
| 141 cancel_download_confirmation_state_(NOT_PROMPTED), | 141 cancel_download_confirmation_state_(NOT_PROMPTED), |
| 142 maximized_state_(MAXIMIZED_STATE_DEFAULT), | 142 maximized_state_(MAXIMIZED_STATE_DEFAULT), |
| 143 method_factory_(this) { | 143 method_factory_(this), |
| 144 pending_web_app_action_(NONE) { |
| 144 tabstrip_model_.AddObserver(this); | 145 tabstrip_model_.AddObserver(this); |
| 145 | 146 |
| 146 registrar_.Add(this, NotificationType::SSL_VISIBLE_STATE_CHANGED, | 147 registrar_.Add(this, NotificationType::SSL_VISIBLE_STATE_CHANGED, |
| 147 NotificationService::AllSources()); | 148 NotificationService::AllSources()); |
| 148 registrar_.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, | 149 registrar_.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, |
| 149 NotificationService::AllSources()); | 150 NotificationService::AllSources()); |
| 150 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 151 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
| 151 NotificationService::AllSources()); | 152 NotificationService::AllSources()); |
| 152 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED, | 153 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED, |
| 153 NotificationService::AllSources()); | 154 NotificationService::AllSources()); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 browser->AddTabWithURL(url, GURL(), PageTransition::START_PAGE, true, -1, | 339 browser->AddTabWithURL(url, GURL(), PageTransition::START_PAGE, true, -1, |
| 339 false, NULL); | 340 false, NULL); |
| 340 | 341 |
| 341 TabContents* tab_contents = browser->GetSelectedTabContents(); | 342 TabContents* tab_contents = browser->GetSelectedTabContents(); |
| 342 tab_contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 343 tab_contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
| 343 tab_contents->render_view_host()->SyncRendererPrefs(); | 344 tab_contents->render_view_host()->SyncRendererPrefs(); |
| 344 browser->window()->Show(); | 345 browser->window()->Show(); |
| 345 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial | 346 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial |
| 346 // focus explicitly. | 347 // focus explicitly. |
| 347 tab_contents->view()->SetInitialFocus(); | 348 tab_contents->view()->SetInitialFocus(); |
| 349 |
| 350 // Set UPDATE_SHORTCUT as the pending web app action. This action is picked |
| 351 // up in LoadingStateChanged to schedule a GetApplicationInfo. And when |
| 352 // the web app info is available, TabContents notifies Browser via |
| 353 // OnDidGetApplicationInfo, which calls web_app::UpdateShortcutForTabContents |
| 354 // when it sees UPDATE_SHORTCUT as pending web app action. |
| 355 browser->pending_web_app_action_ = UPDATE_SHORTCUT; |
| 348 } | 356 } |
| 349 | 357 |
| 350 #if defined(OS_MACOSX) | 358 #if defined(OS_MACOSX) |
| 351 // static | 359 // static |
| 352 void Browser::OpenHistoryWindow(Profile* profile) { | 360 void Browser::OpenHistoryWindow(Profile* profile) { |
| 353 Browser* browser = Browser::Create(profile); | 361 Browser* browser = Browser::Create(profile); |
| 354 browser->ShowHistoryTab(); | 362 browser->ShowHistoryTab(); |
| 355 browser->window()->Show(); | 363 browser->window()->Show(); |
| 356 } | 364 } |
| 357 | 365 |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1167 UserMetrics::RecordAction("CreateShortcut", profile_); | 1175 UserMetrics::RecordAction("CreateShortcut", profile_); |
| 1168 #if defined(OS_WIN) || defined(OS_LINUX) | 1176 #if defined(OS_WIN) || defined(OS_LINUX) |
| 1169 TabContents* current_tab = GetSelectedTabContents(); | 1177 TabContents* current_tab = GetSelectedTabContents(); |
| 1170 DCHECK(current_tab && web_app::IsValidUrl(current_tab->GetURL())) << | 1178 DCHECK(current_tab && web_app::IsValidUrl(current_tab->GetURL())) << |
| 1171 "Menu item should be disabled."; | 1179 "Menu item should be disabled."; |
| 1172 | 1180 |
| 1173 NavigationEntry* entry = current_tab->controller().GetLastCommittedEntry(); | 1181 NavigationEntry* entry = current_tab->controller().GetLastCommittedEntry(); |
| 1174 if (!entry) | 1182 if (!entry) |
| 1175 return; | 1183 return; |
| 1176 | 1184 |
| 1185 // RVH's GetApplicationInfo should not be called before it returns. |
| 1186 DCHECK(pending_web_app_action_ == NONE); |
| 1187 pending_web_app_action_ = CREATE_SHORTCUT; |
| 1188 |
| 1177 // Start fetching web app info for CreateApplicatoinShortcut dialog and | 1189 // Start fetching web app info for CreateApplicatoinShortcut dialog and |
| 1178 // show the dialog when the data is available in OnDidGetApplicationInfo. | 1190 // show the dialog when the data is available in OnDidGetApplicationInfo. |
| 1179 current_tab->render_view_host()->GetApplicationInfo(entry->page_id()); | 1191 current_tab->render_view_host()->GetApplicationInfo(entry->page_id()); |
| 1180 #else | 1192 #else |
| 1181 NOTIMPLEMENTED(); | 1193 NOTIMPLEMENTED(); |
| 1182 #endif | 1194 #endif |
| 1183 } | 1195 } |
| 1184 | 1196 |
| 1185 void Browser::ToggleDevToolsWindow(bool open_console) { | 1197 void Browser::ToggleDevToolsWindow(bool open_console) { |
| 1186 if (open_console) | 1198 if (open_console) |
| (...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1983 } | 1995 } |
| 1984 | 1996 |
| 1985 void Browser::LoadingStateChanged(TabContents* source) { | 1997 void Browser::LoadingStateChanged(TabContents* source) { |
| 1986 window_->UpdateLoadingAnimations(tabstrip_model_.TabsAreLoading()); | 1998 window_->UpdateLoadingAnimations(tabstrip_model_.TabsAreLoading()); |
| 1987 window_->UpdateTitleBar(); | 1999 window_->UpdateTitleBar(); |
| 1988 | 2000 |
| 1989 if (source == GetSelectedTabContents()) { | 2001 if (source == GetSelectedTabContents()) { |
| 1990 UpdateStopGoState(source->is_loading(), false); | 2002 UpdateStopGoState(source->is_loading(), false); |
| 1991 if (GetStatusBubble()) | 2003 if (GetStatusBubble()) |
| 1992 GetStatusBubble()->SetStatus(GetSelectedTabContents()->GetStatusText()); | 2004 GetStatusBubble()->SetStatus(GetSelectedTabContents()->GetStatusText()); |
| 2005 |
| 2006 if (!source->is_loading() && |
| 2007 pending_web_app_action_ == UPDATE_SHORTCUT) { |
| 2008 // Schedule a shortcut update when web application info is available. |
| 2009 NavigationEntry* entry = source->controller().GetLastCommittedEntry(); |
| 2010 if (entry) { |
| 2011 source->render_view_host()->GetApplicationInfo(entry->page_id()); |
| 2012 } else { |
| 2013 pending_web_app_action_ = NONE; |
| 2014 NOTREACHED(); |
| 2015 } |
| 2016 } |
| 1993 } | 2017 } |
| 1994 } | 2018 } |
| 1995 | 2019 |
| 1996 void Browser::CloseContents(TabContents* source) { | 2020 void Browser::CloseContents(TabContents* source) { |
| 1997 if (is_attempting_to_close_browser_) { | 2021 if (is_attempting_to_close_browser_) { |
| 1998 // If we're trying to close the browser, just clear the state related to | 2022 // If we're trying to close the browser, just clear the state related to |
| 1999 // waiting for unload to fire. Don't actually try to close the tab as it | 2023 // waiting for unload to fire. Don't actually try to close the tab as it |
| 2000 // will go down the slow shutdown path instead of the fast path of killing | 2024 // will go down the slow shutdown path instead of the fast path of killing |
| 2001 // all the renderer processes. | 2025 // all the renderer processes. |
| 2002 ClearUnloadState(source); | 2026 ClearUnloadState(source); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2230 void Browser::OnDidGetApplicationInfo(TabContents* tab_contents, | 2254 void Browser::OnDidGetApplicationInfo(TabContents* tab_contents, |
| 2231 int32 page_id) { | 2255 int32 page_id) { |
| 2232 TabContents* current_tab = GetSelectedTabContents(); | 2256 TabContents* current_tab = GetSelectedTabContents(); |
| 2233 if (current_tab != tab_contents) | 2257 if (current_tab != tab_contents) |
| 2234 return; | 2258 return; |
| 2235 | 2259 |
| 2236 NavigationEntry* entry = current_tab->controller().GetLastCommittedEntry(); | 2260 NavigationEntry* entry = current_tab->controller().GetLastCommittedEntry(); |
| 2237 if (!entry || (entry->page_id() != page_id)) | 2261 if (!entry || (entry->page_id() != page_id)) |
| 2238 return; | 2262 return; |
| 2239 | 2263 |
| 2240 window()->ShowCreateShortcutsDialog(current_tab); | 2264 switch (pending_web_app_action_) { |
| 2265 case CREATE_SHORTCUT: { |
| 2266 window()->ShowCreateShortcutsDialog(current_tab); |
| 2267 break; |
| 2268 } |
| 2269 case UPDATE_SHORTCUT: { |
| 2270 web_app::UpdateShortcutForTabContents(current_tab); |
| 2271 break; |
| 2272 } |
| 2273 default: |
| 2274 NOTREACHED(); |
| 2275 break; |
| 2276 } |
| 2277 |
| 2278 pending_web_app_action_ = NONE; |
| 2241 } | 2279 } |
| 2242 | 2280 |
| 2243 /////////////////////////////////////////////////////////////////////////////// | 2281 /////////////////////////////////////////////////////////////////////////////// |
| 2244 // Browser, SelectFileDialog::Listener implementation: | 2282 // Browser, SelectFileDialog::Listener implementation: |
| 2245 | 2283 |
| 2246 void Browser::FileSelected(const FilePath& path, int index, void* params) { | 2284 void Browser::FileSelected(const FilePath& path, int index, void* params) { |
| 2247 GURL file_url = net::FilePathToFileURL(path); | 2285 GURL file_url = net::FilePathToFileURL(path); |
| 2248 if (!file_url.is_empty()) | 2286 if (!file_url.is_empty()) |
| 2249 OpenURL(file_url, GURL(), CURRENT_TAB, PageTransition::TYPED); | 2287 OpenURL(file_url, GURL(), CURRENT_TAB, PageTransition::TYPED); |
| 2250 } | 2288 } |
| (...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3071 /////////////////////////////////////////////////////////////////////////////// | 3109 /////////////////////////////////////////////////////////////////////////////// |
| 3072 // BrowserToolbarModel (private): | 3110 // BrowserToolbarModel (private): |
| 3073 | 3111 |
| 3074 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { | 3112 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { |
| 3075 // This |current_tab| can be NULL during the initialization of the | 3113 // This |current_tab| can be NULL during the initialization of the |
| 3076 // toolbar during window creation (i.e. before any tabs have been added | 3114 // toolbar during window creation (i.e. before any tabs have been added |
| 3077 // to the window). | 3115 // to the window). |
| 3078 TabContents* current_tab = browser_->GetSelectedTabContents(); | 3116 TabContents* current_tab = browser_->GetSelectedTabContents(); |
| 3079 return current_tab ? ¤t_tab->controller() : NULL; | 3117 return current_tab ? ¤t_tab->controller() : NULL; |
| 3080 } | 3118 } |
| OLD | NEW |