| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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" | |
| 6 | |
| 7 #include <windows.h> | 5 #include <windows.h> |
| 8 #include <shellapi.h> | 6 #include <shellapi.h> |
| 9 | 7 |
| 8 #include "chrome/browser/browser.h" |
| 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/file_version_info.h" | 11 #include "base/file_version_info.h" |
| 12 #include "base/idle_timer.h" | 12 #include "base/idle_timer.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "chrome/app/chrome_dll_resource.h" | 15 #include "chrome/app/chrome_dll_resource.h" |
| 16 #include "chrome/app/locales/locale_settings.h" | 16 #include "chrome/app/locales/locale_settings.h" |
| 17 #include "chrome/browser/automation/ui_controls.h" | 17 #include "chrome/browser/automation/ui_controls.h" |
| 18 #include "chrome/browser/browser_list.h" | 18 #include "chrome/browser/browser_list.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // The source of the update. | 145 // The source of the update. |
| 146 const TabContents* source; | 146 const TabContents* source; |
| 147 | 147 |
| 148 // What changed in the UI. | 148 // What changed in the UI. |
| 149 unsigned changed_flags; | 149 unsigned changed_flags; |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 /////////////////////////////////////////////////////////////////////////////// | 152 /////////////////////////////////////////////////////////////////////////////// |
| 153 // Browser, Constructors, Creation, Showing: | 153 // Browser, Constructors, Creation, Showing: |
| 154 | 154 |
| 155 Browser::Browser(const gfx::Rect& initial_bounds, | 155 Browser::Browser(BrowserType::Type type, Profile* profile) |
| 156 int show_command, | 156 : type_(type), |
| 157 Profile* profile, | 157 profile_(profile), |
| 158 BrowserType::Type type, | |
| 159 const std::wstring& app_name) | |
| 160 : profile_(profile), | |
| 161 window_(NULL), | 158 window_(NULL), |
| 162 initial_show_command_(show_command), | 159 tabstrip_model_(this, profile), |
| 160 controller_(this), |
| 161 toolbar_model_(this), |
| 162 chrome_updater_factory_(this), |
| 163 is_attempting_to_close_browser_(false), | 163 is_attempting_to_close_browser_(false), |
| 164 controller_(this), | 164 override_maximized_(false), |
| 165 chrome_updater_factory_(this), | |
| 166 method_factory_(this), | 165 method_factory_(this), |
| 167 tabstrip_model_(this, profile), | 166 idle_task_(new BrowserIdleTimer) { |
| 168 toolbar_model_(this), | |
| 169 type_(type), | |
| 170 app_name_(app_name), | |
| 171 idle_task_(new BrowserIdleTimer()) { | |
| 172 tabstrip_model_.AddObserver(this); | 167 tabstrip_model_.AddObserver(this); |
| 173 | 168 |
| 174 CommandLine parsed_command_line; | |
| 175 | |
| 176 gfx::Rect create_bounds; | |
| 177 bool maximized = false; | |
| 178 WindowSizer::GetBrowserWindowBounds(app_name_, initial_bounds, | |
| 179 &create_bounds, &maximized); | |
| 180 if (parsed_command_line.HasSwitch(switches::kStartMaximized)) | |
| 181 maximized = true; | |
| 182 if (maximized) | |
| 183 initial_show_command_ = SW_SHOWMAXIMIZED; | |
| 184 window_ = BrowserWindow::CreateBrowserWindow(this, create_bounds, | |
| 185 show_command); | |
| 186 | |
| 187 NotificationService::current()->AddObserver( | 169 NotificationService::current()->AddObserver( |
| 188 this, NOTIFY_SSL_STATE_CHANGED, NotificationService::AllSources()); | 170 this, NOTIFY_SSL_STATE_CHANGED, NotificationService::AllSources()); |
| 189 | 171 |
| 190 InitCommandState(); | 172 InitCommandState(); |
| 191 BrowserList::AddBrowser(this); | 173 BrowserList::AddBrowser(this); |
| 192 | 174 |
| 193 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, | 175 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, |
| 194 profile_->GetPrefs(), NULL); | 176 profile_->GetPrefs(), NULL); |
| 195 | 177 |
| 196 // Trim browser memory on idle for low & medium memory models. | 178 // Trim browser memory on idle for low & medium memory models. |
| 197 if (g_browser_process->memory_model() < BrowserProcess::HIGH_MEMORY_MODEL) | 179 if (g_browser_process->memory_model() < BrowserProcess::HIGH_MEMORY_MODEL) |
| 198 idle_task_->Start(); | 180 idle_task_->Start(); |
| 199 | |
| 200 // Show the First Run information bubble if we've been told to. | |
| 201 PrefService* local_state = g_browser_process->local_state(); | |
| 202 if (local_state->IsPrefRegistered(prefs::kShouldShowFirstRunBubble) && | |
| 203 local_state->GetBoolean(prefs::kShouldShowFirstRunBubble)) { | |
| 204 // Reset the preference so we don't show the bubble for subsequent windows. | |
| 205 local_state->ClearPref(prefs::kShouldShowFirstRunBubble); | |
| 206 GetLocationBarView()->ShowFirstRunBubble(); | |
| 207 } | |
| 208 } | 181 } |
| 209 | 182 |
| 210 Browser::~Browser() { | 183 Browser::~Browser() { |
| 211 // The tab strip should be empty at this point. | 184 // The tab strip should be empty at this point. |
| 212 DCHECK(tabstrip_model_.empty()); | 185 DCHECK(tabstrip_model_.empty()); |
| 213 tabstrip_model_.RemoveObserver(this); | 186 tabstrip_model_.RemoveObserver(this); |
| 214 | 187 |
| 215 BrowserList::RemoveBrowser(this); | 188 BrowserList::RemoveBrowser(this); |
| 216 | 189 |
| 217 if (!BrowserList::HasBrowserWithProfile(profile_)) { | 190 if (!BrowserList::HasBrowserWithProfile(profile_)) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 241 // can just delete all of the cookies in the store. | 214 // can just delete all of the cookies in the store. |
| 242 profile_->GetRequestContext()->cookie_store()->DeleteAll(false); | 215 profile_->GetRequestContext()->cookie_store()->DeleteAll(false); |
| 243 } | 216 } |
| 244 | 217 |
| 245 // There may be pending file dialogs, we need to tell them that we've gone | 218 // There may be pending file dialogs, we need to tell them that we've gone |
| 246 // away so they don't try and call back to us. | 219 // away so they don't try and call back to us. |
| 247 if (select_file_dialog_.get()) | 220 if (select_file_dialog_.get()) |
| 248 select_file_dialog_->ListenerDestroyed(); | 221 select_file_dialog_->ListenerDestroyed(); |
| 249 } | 222 } |
| 250 | 223 |
| 251 void Browser::Show() { | 224 // static |
| 252 // TODO(beng): this entire function should move to BrowserWindow. | 225 Browser* Browser::Create(Profile* profile) { |
| 226 Browser* browser = new Browser(BrowserType::TABBED_BROWSER, profile); |
| 227 browser->CreateBrowserWindow(); |
| 228 return browser; |
| 229 } |
| 253 | 230 |
| 254 // Only allow one call after the browser is created. | 231 // static |
| 255 if (initial_show_command_ < 0) { | 232 Browser* Browser::CreateForPopup(Profile* profile) { |
| 256 // The frame is already visible, we're being invoked again either by the | 233 Browser* browser = new Browser(BrowserType::BROWSER, profile); |
| 257 // user clicking a link in another app or from a desktop shortcut. | 234 browser->CreateBrowserWindow(); |
| 258 window_->Activate(); | 235 return browser; |
| 259 return; | 236 } |
| 237 |
| 238 // static |
| 239 Browser* Browser::CreateForApp(const std::wstring& app_name, |
| 240 Profile* profile) { |
| 241 Browser* browser = new Browser(BrowserType::APPLICATION, profile); |
| 242 browser->app_name_ = app_name; |
| 243 browser->CreateBrowserWindow(); |
| 244 return browser; |
| 245 } |
| 246 |
| 247 void Browser::CreateBrowserWindow() { |
| 248 DCHECK(!window_); |
| 249 window_ = BrowserWindow::CreateBrowserWindow(this); |
| 250 |
| 251 // Show the First Run information bubble if we've been told to. |
| 252 PrefService* local_state = g_browser_process->local_state(); |
| 253 if (local_state->IsPrefRegistered(prefs::kShouldShowFirstRunBubble) && |
| 254 local_state->GetBoolean(prefs::kShouldShowFirstRunBubble)) { |
| 255 // Reset the preference so we don't show the bubble for subsequent windows. |
| 256 local_state->ClearPref(prefs::kShouldShowFirstRunBubble); |
| 257 GetLocationBarView()->ShowFirstRunBubble(); |
| 260 } | 258 } |
| 261 window_->Show(initial_show_command_, false); | |
| 262 if ((initial_show_command_ == SW_SHOWNORMAL) || | |
| 263 (initial_show_command_ == SW_SHOWMAXIMIZED)) | |
| 264 window_->Activate(); | |
| 265 initial_show_command_ = -1; | |
| 266 | |
| 267 // Setting the focus doesn't work when the window is invisible, so any focus | |
| 268 // initialization that happened before this will be lost. | |
| 269 // | |
| 270 // We really "should" restore the focus whenever the window becomes unhidden, | |
| 271 // but I think initializing is the only time where this can happen where there | |
| 272 // is some focus change we need to pick up, and this is easier than plumbing | |
| 273 // through an unhide message all the way from the frame. | |
| 274 // | |
| 275 // If we do find there are cases where we need to restore the focus on show, | |
| 276 // that should be added and this should be removed. | |
| 277 TabContents* selected_tab_contents = GetSelectedTabContents(); | |
| 278 if (selected_tab_contents) | |
| 279 selected_tab_contents->RestoreFocus(); | |
| 280 } | 259 } |
| 281 | 260 |
| 282 /////////////////////////////////////////////////////////////////////////////// | 261 /////////////////////////////////////////////////////////////////////////////// |
| 283 // Browser, Creation Helpers: | 262 // Browser, Creation Helpers: |
| 284 | 263 |
| 285 // static | 264 // static |
| 286 void Browser::OpenNewBrowserWindow(Profile* profile, int show_command) { | 265 void Browser::OpenEmptyWindow(Profile* profile) { |
| 287 Browser* browser = new Browser(gfx::Rect(), show_command, profile, | 266 Browser* browser = Browser::Create(profile); |
| 288 BrowserType::TABBED_BROWSER, L""); | |
| 289 browser->AddBlankTab(true); | 267 browser->AddBlankTab(true); |
| 290 browser->Show(); | 268 browser->window()->Show(); |
| 291 } | 269 } |
| 292 | 270 |
| 293 // static | 271 // static |
| 294 void Browser::OpenURLOffTheRecord(Profile* profile, const GURL& url) { | 272 void Browser::OpenURLOffTheRecord(Profile* profile, const GURL& url) { |
| 295 Profile* off_the_record_profile = profile->GetOffTheRecordProfile(); | 273 Profile* off_the_record_profile = profile->GetOffTheRecordProfile(); |
| 296 Browser* browser = BrowserList::FindBrowserWithType( | 274 Browser* browser = BrowserList::FindBrowserWithType( |
| 297 off_the_record_profile, BrowserType::TABBED_BROWSER); | 275 off_the_record_profile, |
| 298 if (browser == NULL) { | 276 BrowserType::TABBED_BROWSER); |
| 299 browser = new Browser(gfx::Rect(), SW_SHOWNORMAL, off_the_record_profile, | 277 if (!browser) |
| 300 BrowserType::TABBED_BROWSER, L""); | 278 browser = Browser::Create(off_the_record_profile); |
| 301 } | |
| 302 // TODO(eroman): should we have referrer here? | 279 // TODO(eroman): should we have referrer here? |
| 303 browser->AddTabWithURL(url, GURL(), PageTransition::LINK, true, NULL); | 280 browser->AddTabWithURL(url, GURL(), PageTransition::LINK, true, NULL); |
| 304 browser->Show(); | 281 browser->window()->Show(); |
| 305 browser->window()->Activate(); | |
| 306 } | 282 } |
| 307 | 283 |
| 308 // static | 284 // static |
| 309 void Browser::OpenWebApplication(Profile* profile, | 285 void Browser::OpenWebApplication(Profile* profile, WebApp* app) { |
| 310 WebApp* app, | |
| 311 int show_command) { | |
| 312 const std::wstring& app_name = | 286 const std::wstring& app_name = |
| 313 app->name().empty() ? ComputeApplicationNameFromURL(app->url()) : | 287 app->name().empty() ? ComputeApplicationNameFromURL(app->url()) : |
| 314 app->name(); | 288 app->name(); |
| 289 RegisterAppPrefs(app_name); |
| 315 | 290 |
| 316 RegisterAppPrefs(app_name); | 291 Browser* browser = Browser::CreateForApp(app_name, profile); |
| 317 Browser* browser = new Browser(gfx::Rect(), show_command, profile, | |
| 318 BrowserType::APPLICATION, app_name); | |
| 319 browser->AddWebApplicationTab(profile, app, false); | 292 browser->AddWebApplicationTab(profile, app, false); |
| 320 browser->Show(); | 293 browser->window()->Show(); |
| 321 } | 294 } |
| 322 | 295 |
| 323 /////////////////////////////////////////////////////////////////////////////// | 296 /////////////////////////////////////////////////////////////////////////////// |
| 324 // Browser, Command API: | 297 // Browser, Command API: |
| 325 | 298 |
| 326 bool Browser::SupportsCommand(int id) const { | 299 bool Browser::SupportsCommand(int id) const { |
| 327 return controller_.SupportsCommand(id); | 300 return controller_.SupportsCommand(id); |
| 328 } | 301 } |
| 329 | 302 |
| 330 bool Browser::IsCommandEnabled(int id) const { | 303 bool Browser::IsCommandEnabled(int id) const { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 349 /////////////////////////////////////////////////////////////////////////////// | 322 /////////////////////////////////////////////////////////////////////////////// |
| 350 // Browser, DEPRECATED DEPRECATED DEPRECATED: | 323 // Browser, DEPRECATED DEPRECATED DEPRECATED: |
| 351 | 324 |
| 352 HWND Browser::GetTopLevelHWND() const { | 325 HWND Browser::GetTopLevelHWND() const { |
| 353 return window_ ? reinterpret_cast<HWND>(window_->GetNativeHandle()) : NULL; | 326 return window_ ? reinterpret_cast<HWND>(window_->GetNativeHandle()) : NULL; |
| 354 } | 327 } |
| 355 | 328 |
| 356 /////////////////////////////////////////////////////////////////////////////// | 329 /////////////////////////////////////////////////////////////////////////////// |
| 357 // Browser, State Storage and Retrieval for UI: | 330 // Browser, State Storage and Retrieval for UI: |
| 358 | 331 |
| 359 void Browser::SaveWindowPosition(const gfx::Rect& bounds, bool maximized) { | 332 void Browser::SaveWindowPlacement(const gfx::Rect& bounds, bool maximized) { |
| 360 // We don't save window position for popups. | 333 // We don't save window position for popups. |
| 361 if (type() == BrowserType::BROWSER) | 334 if (type() == BrowserType::BROWSER) |
| 362 return; | 335 return; |
| 363 | 336 |
| 364 // First save to local state, this is for remembering on subsequent starts. | 337 // First save to local state, this is for remembering on subsequent starts. |
| 365 PrefService* prefs = g_browser_process->local_state(); | 338 PrefService* prefs = g_browser_process->local_state(); |
| 366 DCHECK(prefs); | 339 DCHECK(prefs); |
| 367 std::wstring name(prefs::kBrowserWindowPlacement); | 340 std::wstring name(prefs::kBrowserWindowPlacement); |
| 368 if (!app_name_.empty()) { | 341 if (!app_name_.empty()) { |
| 369 name.append(L"_"); | 342 name.append(L"_"); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 383 // initialization of the session service. This function gets called during | 356 // initialization of the session service. This function gets called during |
| 384 // initial window showing, and we don't want to bring in the session service | 357 // initial window showing, and we don't want to bring in the session service |
| 385 // this early. | 358 // this early. |
| 386 if (profile()->HasSessionService()) { | 359 if (profile()->HasSessionService()) { |
| 387 SessionService* session_service = profile()->GetSessionService(); | 360 SessionService* session_service = profile()->GetSessionService(); |
| 388 if (session_service) | 361 if (session_service) |
| 389 session_service->SetWindowBounds(session_id_, bounds, maximized); | 362 session_service->SetWindowBounds(session_id_, bounds, maximized); |
| 390 } | 363 } |
| 391 } | 364 } |
| 392 | 365 |
| 393 void Browser::RestoreWindowPosition(gfx::Rect* bounds, bool* maximized) { | 366 gfx::Rect Browser::GetSavedWindowBounds() const { |
| 394 DCHECK(bounds && maximized); | 367 CommandLine parsed_command_line; |
| 395 WindowSizer::GetBrowserWindowBounds(app_name_, *bounds, bounds, maximized); | 368 bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode); |
| 369 bool playback_mode = parsed_command_line.HasSwitch(switches::kPlaybackMode); |
| 370 if (record_mode || playback_mode) { |
| 371 // In playback/record mode we always fix the size of the browser and |
| 372 // move it to (0,0). The reason for this is two reasons: First we want |
| 373 // resize/moves in the playback to still work, and Second we want |
| 374 // playbacks to work (as much as possible) on machines w/ different |
| 375 // screen sizes. |
| 376 return gfx::Rect(0, 0, 800, 600); |
| 377 } |
| 378 |
| 379 gfx::Rect restored_bounds = override_bounds_; |
| 380 bool maximized; |
| 381 WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, |
| 382 &restored_bounds, &maximized); |
| 383 return restored_bounds; |
| 384 } |
| 385 |
| 386 // TODO(beng): obtain maximized state some other way so we don't need to go |
| 387 // through all this hassle. |
| 388 bool Browser::GetSavedMaximizedState() const { |
| 389 if (CommandLine().HasSwitch(switches::kStartMaximized)) |
| 390 return true; |
| 391 |
| 392 gfx::Rect restored_bounds; |
| 393 bool maximized = override_maximized_; |
| 394 WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, |
| 395 &restored_bounds, &maximized); |
| 396 return maximized; |
| 396 } | 397 } |
| 397 | 398 |
| 398 SkBitmap Browser::GetCurrentPageIcon() const { | 399 SkBitmap Browser::GetCurrentPageIcon() const { |
| 399 TabContents* contents = tabstrip_model_.GetSelectedTabContents(); | 400 TabContents* contents = tabstrip_model_.GetSelectedTabContents(); |
| 400 return contents ? contents->GetFavIcon() : SkBitmap(); | 401 return contents ? contents->GetFavIcon() : SkBitmap(); |
| 401 } | 402 } |
| 402 | 403 |
| 403 std::wstring Browser::GetCurrentPageTitle() const { | 404 std::wstring Browser::GetCurrentPageTitle() const { |
| 404 TabContents* contents = tabstrip_model_.GetSelectedTabContents(); | 405 TabContents* contents = tabstrip_model_.GetSelectedTabContents(); |
| 405 std::wstring title; | 406 std::wstring title; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 OpenURL(GURL(), GURL(), CURRENT_TAB, PageTransition::TYPED); | 655 OpenURL(GURL(), GURL(), CURRENT_TAB, PageTransition::TYPED); |
| 655 } | 656 } |
| 656 } | 657 } |
| 657 | 658 |
| 658 void Browser::NewTab() { | 659 void Browser::NewTab() { |
| 659 UserMetrics::RecordAction(L"NewTab", profile_); | 660 UserMetrics::RecordAction(L"NewTab", profile_); |
| 660 if (type() == BrowserType::TABBED_BROWSER) { | 661 if (type() == BrowserType::TABBED_BROWSER) { |
| 661 AddBlankTab(true); | 662 AddBlankTab(true); |
| 662 } else { | 663 } else { |
| 663 Browser* b = GetOrCreateTabbedBrowser(); | 664 Browser* b = GetOrCreateTabbedBrowser(); |
| 664 DCHECK(b); | |
| 665 b->Show(); | |
| 666 b->window()->Activate(); | |
| 667 b->AddBlankTab(true); | 665 b->AddBlankTab(true); |
| 666 b->window()->Show(); |
| 668 } | 667 } |
| 669 } | 668 } |
| 670 | 669 |
| 671 void Browser::CloseTab() { | 670 void Browser::CloseTab() { |
| 672 UserMetrics::RecordAction(L"CloseTab_Accelerator", profile_); | 671 UserMetrics::RecordAction(L"CloseTab_Accelerator", profile_); |
| 673 tabstrip_model_.CloseTabContentsAt(tabstrip_model_.selected_index()); | 672 tabstrip_model_.CloseTabContentsAt(tabstrip_model_.selected_index()); |
| 674 } | 673 } |
| 675 | 674 |
| 676 void Browser::CloseApp() { | 675 void Browser::CloseApp() { |
| 677 UserMetrics::RecordAction(L"CloseWebApp", profile_); | 676 UserMetrics::RecordAction(L"CloseWebApp", profile_); |
| 678 tabstrip_model_.CloseTabContentsAt(tabstrip_model_.selected_index()); | 677 tabstrip_model_.CloseTabContentsAt(tabstrip_model_.selected_index()); |
| 679 } | 678 } |
| 680 | 679 |
| 681 void Browser::NewWindow() { | 680 void Browser::NewWindow() { |
| 682 UserMetrics::RecordAction(L"NewWindow", profile_); | 681 UserMetrics::RecordAction(L"NewWindow", profile_); |
| 683 Browser::OpenNewBrowserWindow(profile_->GetOriginalProfile(), | 682 Browser::OpenEmptyWindow(profile_->GetOriginalProfile()); |
| 684 SW_SHOWNORMAL); | |
| 685 } | 683 } |
| 686 | 684 |
| 687 void Browser::NewIncognitoWindow() { | 685 void Browser::NewIncognitoWindow() { |
| 688 UserMetrics::RecordAction(L"NewIncognitoWindow", profile_); | 686 UserMetrics::RecordAction(L"NewIncognitoWindow", profile_); |
| 689 Browser::OpenNewBrowserWindow(profile_->GetOffTheRecordProfile(), | 687 Browser::OpenEmptyWindow(profile_->GetOffTheRecordProfile()); |
| 690 SW_SHOWNORMAL); | |
| 691 } | 688 } |
| 692 | 689 |
| 693 void Browser::CloseWindow() { | 690 void Browser::CloseWindow() { |
| 694 UserMetrics::RecordAction(L"CloseWindow", profile_); | 691 UserMetrics::RecordAction(L"CloseWindow", profile_); |
| 695 window_->Close(); | 692 window_->Close(); |
| 696 } | 693 } |
| 697 | 694 |
| 698 void Browser::SelectNextTab() { | 695 void Browser::SelectNextTab() { |
| 699 UserMetrics::RecordAction(L"SelectNextTab", profile_); | 696 UserMetrics::RecordAction(L"SelectNextTab", profile_); |
| 700 tabstrip_model_.SelectNextTab(); | 697 tabstrip_model_.SelectNextTab(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 void Browser::ConvertPopupToTabbedBrowser() { | 738 void Browser::ConvertPopupToTabbedBrowser() { |
| 742 UserMetrics::RecordAction(L"ShowAsTab", profile_); | 739 UserMetrics::RecordAction(L"ShowAsTab", profile_); |
| 743 | 740 |
| 744 if (type() != BrowserType::BROWSER) { | 741 if (type() != BrowserType::BROWSER) { |
| 745 NOTREACHED(); | 742 NOTREACHED(); |
| 746 return; | 743 return; |
| 747 } | 744 } |
| 748 | 745 |
| 749 int tab_strip_index = tabstrip_model_.selected_index(); | 746 int tab_strip_index = tabstrip_model_.selected_index(); |
| 750 TabContents* contents = tabstrip_model_.DetachTabContentsAt(tab_strip_index); | 747 TabContents* contents = tabstrip_model_.DetachTabContentsAt(tab_strip_index); |
| 751 Browser* browser = new Browser(gfx::Rect(), SW_SHOWNORMAL, profile_, | 748 Browser* browser = Browser::Create(profile_); |
| 752 BrowserType::TABBED_BROWSER, L""); | 749 browser->tabstrip_model()->AppendTabContents(contents, true); |
| 753 browser->AddNewContents(NULL, contents, NEW_FOREGROUND_TAB, gfx::Rect(), | 750 browser->window()->Show(); |
| 754 true); | |
| 755 browser->Show(); | |
| 756 } | 751 } |
| 757 | 752 |
| 758 void Browser::Exit() { | 753 void Browser::Exit() { |
| 759 UserMetrics::RecordAction(L"Exit", profile_); | 754 UserMetrics::RecordAction(L"Exit", profile_); |
| 760 BrowserList::CloseAllBrowsers(true); | 755 BrowserList::CloseAllBrowsers(true); |
| 761 } | 756 } |
| 762 | 757 |
| 763 // TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always | 758 // TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always |
| 764 // enabled in the page menu regardless of whether the command will do | 759 // enabled in the page menu regardless of whether the command will do |
| 765 // anything. When someone selects the menu item, we just act as if they hit | 760 // anything. When someone selects the menu item, we just act as if they hit |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 | 1274 |
| 1280 default: | 1275 default: |
| 1281 LOG(WARNING) << "Received Unimplemented Command: " << id; | 1276 LOG(WARNING) << "Received Unimplemented Command: " << id; |
| 1282 break; | 1277 break; |
| 1283 } | 1278 } |
| 1284 } | 1279 } |
| 1285 | 1280 |
| 1286 /////////////////////////////////////////////////////////////////////////////// | 1281 /////////////////////////////////////////////////////////////////////////////// |
| 1287 // Browser, TabStripModelDelegate implementation: | 1282 // Browser, TabStripModelDelegate implementation: |
| 1288 | 1283 |
| 1284 GURL Browser::GetBlankTabURL() const { |
| 1285 return NewTabUIURL(); |
| 1286 } |
| 1287 |
| 1289 void Browser::CreateNewStripWithContents(TabContents* detached_contents, | 1288 void Browser::CreateNewStripWithContents(TabContents* detached_contents, |
| 1290 const gfx::Point& drop_point) { | 1289 const gfx::Point& drop_point) { |
| 1291 DCHECK(type_ == BrowserType::TABBED_BROWSER); | 1290 DCHECK(type_ == BrowserType::TABBED_BROWSER); |
| 1292 | 1291 |
| 1293 // Create an empty new browser window the same size as the old one. | 1292 // Create an empty new browser window the same size as the old one. |
| 1294 // TODO(beng): move elsewhere | 1293 // TODO(beng): move elsewhere |
| 1295 CRect browser_rect; | 1294 CRect browser_rect; |
| 1296 GetWindowRect(reinterpret_cast<HWND>(window_->GetNativeHandle()), | 1295 GetWindowRect(reinterpret_cast<HWND>(window_->GetNativeHandle()), |
| 1297 &browser_rect); | 1296 &browser_rect); |
| 1298 gfx::Rect rect(0, 0); | 1297 gfx::Rect rect(0, 0); |
| 1299 if (drop_point.x() != 0 || drop_point.y() != 0) { | 1298 if (drop_point.x() != 0 || drop_point.y() != 0) { |
| 1300 rect.SetRect(drop_point.x(), drop_point.y(), browser_rect.Width(), | 1299 rect.SetRect(drop_point.x(), drop_point.y(), browser_rect.Width(), |
| 1301 browser_rect.Height()); | 1300 browser_rect.Height()); |
| 1302 } | 1301 } |
| 1303 Browser* new_window = | 1302 Browser* browser = new Browser(BrowserType::TABBED_BROWSER, profile_); |
| 1304 new Browser(rect, SW_SHOWNORMAL, profile_, BrowserType::TABBED_BROWSER, | 1303 browser->set_override_bounds(rect); |
| 1305 std::wstring()); | 1304 browser->CreateBrowserWindow(); |
| 1306 // Append the TabContents before showing it so the window doesn't flash | 1305 browser->tabstrip_model()->AppendTabContents(detached_contents, true); |
| 1307 // black. | 1306 browser->window()->Show(); |
| 1308 new_window->tabstrip_model()->AppendTabContents(detached_contents, true); | |
| 1309 new_window->Show(); | |
| 1310 | 1307 |
| 1311 // When we detach a tab we need to make sure any associated Find window moves | 1308 // When we detach a tab we need to make sure any associated Find window moves |
| 1312 // along with it to its new home (basically we just make new_window the parent | 1309 // along with it to its new home (basically we just make new_window the parent |
| 1313 // of the Find window). | 1310 // of the Find window). |
| 1314 // TODO(brettw) this could probably be improved, see | 1311 // TODO(brettw) this could probably be improved, see |
| 1315 // WebContentsView::ReparentFindWindow for more. | 1312 // WebContentsView::ReparentFindWindow for more. |
| 1316 if (detached_contents->AsWebContents()) | 1313 if (detached_contents->AsWebContents()) |
| 1317 detached_contents->AsWebContents()->view()->ReparentFindWindow(new_window); | 1314 detached_contents->AsWebContents()->view()->ReparentFindWindow(browser); |
| 1318 } | 1315 } |
| 1319 | 1316 |
| 1320 int Browser::GetDragActions() const { | 1317 int Browser::GetDragActions() const { |
| 1321 int result = 0; | 1318 int result = 0; |
| 1322 if (BrowserList::GetBrowserCountForType(profile_, | 1319 if (BrowserList::GetBrowserCountForType(profile_, |
| 1323 BrowserType::TABBED_BROWSER) > 1 || | 1320 BrowserType::TABBED_BROWSER) > 1 || |
| 1324 tab_count() > 1) | 1321 tab_count() > 1) |
| 1325 result |= TAB_TEAROFF_ACTION; | 1322 result |= TAB_TEAROFF_ACTION; |
| 1326 if (tab_count() > 1) | 1323 if (tab_count() > 1) |
| 1327 result |= TAB_MOVE_ACTION; | 1324 result |= TAB_MOVE_ACTION; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1370 GetTopLevelHWND())->active_contents(); | 1367 GetTopLevelHWND())->active_contents(); |
| 1371 // If you duplicate a tab that is not selected, we need to make sure to | 1368 // If you duplicate a tab that is not selected, we need to make sure to |
| 1372 // select the tab being duplicated so that DetermineInsertionIndex returns | 1369 // select the tab being duplicated so that DetermineInsertionIndex returns |
| 1373 // the right index (if tab 5 is selected and we right-click tab 1 we want | 1370 // the right index (if tab 5 is selected and we right-click tab 1 we want |
| 1374 // the new tab to appear in index position 2, not 6). | 1371 // the new tab to appear in index position 2, not 6). |
| 1375 if (tabstrip_model_.selected_index() != index) | 1372 if (tabstrip_model_.selected_index() != index) |
| 1376 tabstrip_model_.SelectTabContentsAt(index, true); | 1373 tabstrip_model_.SelectTabContentsAt(index, true); |
| 1377 tabstrip_model_.AddTabContents(new_contents, index + 1, | 1374 tabstrip_model_.AddTabContents(new_contents, index + 1, |
| 1378 PageTransition::LINK, true); | 1375 PageTransition::LINK, true); |
| 1379 } else { | 1376 } else { |
| 1380 Browser* new_browser = new Browser(gfx::Rect(), SW_SHOWNORMAL, profile(), | 1377 Browser* browser = NULL; |
| 1381 BrowserType::APPLICATION, app_name_); | 1378 if (type_ == BrowserType::APPLICATION) { |
| 1379 browser = Browser::CreateForApp(app_name_, profile_); |
| 1380 } else if (type_ == BrowserType::BROWSER) { |
| 1381 browser = Browser::CreateForPopup(profile_); |
| 1382 } |
| 1382 | 1383 |
| 1383 // We need to show the browser now. Otherwise ContainerWin assumes the | 1384 // We need to show the browser now. Otherwise ContainerWin assumes the |
| 1384 // TabContents is invisible and won't size it. | 1385 // TabContents is invisible and won't size it. |
| 1385 new_browser->Show(); | 1386 browser->window()->Show(); |
| 1386 | 1387 |
| 1387 // The page transition below is only for the purpose of inserting the tab. | 1388 // The page transition below is only for the purpose of inserting the tab. |
| 1388 new_contents = new_browser->AddTabWithNavigationController( | 1389 new_contents = browser->AddTabWithNavigationController( |
| 1389 contents->controller()->Clone(new_browser->GetTopLevelHWND()), | 1390 contents->controller()->Clone(browser->GetTopLevelHWND()), |
| 1390 PageTransition::LINK); | 1391 PageTransition::LINK); |
| 1391 | |
| 1392 new_browser->window()->Activate(); | |
| 1393 } | 1392 } |
| 1394 | 1393 |
| 1395 if (profile_->HasSessionService()) { | 1394 if (profile_->HasSessionService()) { |
| 1396 SessionService* session_service = profile_->GetSessionService(); | 1395 SessionService* session_service = profile_->GetSessionService(); |
| 1397 if (session_service) | 1396 if (session_service) |
| 1398 session_service->TabRestored(new_contents->controller()); | 1397 session_service->TabRestored(new_contents->controller()); |
| 1399 } | 1398 } |
| 1400 } | 1399 } |
| 1401 | 1400 |
| 1402 void Browser::ValidateLoadingAnimations() { | 1401 void Browser::ValidateLoadingAnimations() { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1581 | 1580 |
| 1582 Browser* b = GetOrCreateTabbedBrowser(); | 1581 Browser* b = GetOrCreateTabbedBrowser(); |
| 1583 DCHECK(b); | 1582 DCHECK(b); |
| 1584 | 1583 |
| 1585 // If we have just created a new browser window, make sure we select the | 1584 // If we have just created a new browser window, make sure we select the |
| 1586 // tab. | 1585 // tab. |
| 1587 if (b->tab_count() == 0 && disposition == NEW_BACKGROUND_TAB) | 1586 if (b->tab_count() == 0 && disposition == NEW_BACKGROUND_TAB) |
| 1588 disposition = NEW_FOREGROUND_TAB; | 1587 disposition = NEW_FOREGROUND_TAB; |
| 1589 | 1588 |
| 1590 b->OpenURL(url, referrer, disposition, transition); | 1589 b->OpenURL(url, referrer, disposition, transition); |
| 1591 b->Show(); | 1590 b->window()->Show(); |
| 1592 b->window()->Activate(); | |
| 1593 return; | 1591 return; |
| 1594 } | 1592 } |
| 1595 | 1593 |
| 1596 if (profile_->IsOffTheRecord() && disposition == OFF_THE_RECORD) | 1594 if (profile_->IsOffTheRecord() && disposition == OFF_THE_RECORD) |
| 1597 disposition = NEW_FOREGROUND_TAB; | 1595 disposition = NEW_FOREGROUND_TAB; |
| 1598 | 1596 |
| 1599 if (disposition == NEW_WINDOW) { | 1597 if (disposition == NEW_WINDOW) { |
| 1600 Browser* new_browser = new Browser(gfx::Rect(), SW_SHOWNORMAL, profile_, | 1598 Browser* browser = Browser::Create(profile_); |
| 1601 BrowserType::TABBED_BROWSER, L""); | 1599 new_contents = browser->AddTabWithURL(url, referrer, transition, true, |
| 1602 new_contents = new_browser->AddTabWithURL(url, referrer, transition, true, | 1600 instance); |
| 1603 instance); | 1601 browser->window()->Show(); |
| 1604 new_browser->Show(); | |
| 1605 } else if ((disposition == CURRENT_TAB) && current_tab) { | 1602 } else if ((disposition == CURRENT_TAB) && current_tab) { |
| 1606 if (transition == PageTransition::TYPED || | 1603 if (transition == PageTransition::TYPED || |
| 1607 transition == PageTransition::AUTO_BOOKMARK || | 1604 transition == PageTransition::AUTO_BOOKMARK || |
| 1608 transition == PageTransition::GENERATED || | 1605 transition == PageTransition::GENERATED || |
| 1609 transition == PageTransition::START_PAGE) { | 1606 transition == PageTransition::START_PAGE) { |
| 1610 // Don't forget the openers if this tab is a New Tab page opened at the | 1607 // Don't forget the openers if this tab is a New Tab page opened at the |
| 1611 // end of the TabStrip (e.g. by pressing Ctrl+T). Give the user one | 1608 // end of the TabStrip (e.g. by pressing Ctrl+T). Give the user one |
| 1612 // navigation of one of these transition types before resetting the | 1609 // navigation of one of these transition types before resetting the |
| 1613 // opener relationships (this allows for the use case of opening a new | 1610 // opener relationships (this allows for the use case of opening a new |
| 1614 // tab to do a quick look-up of something while viewing a tab earlier in | 1611 // tab to do a quick look-up of something while viewing a tab earlier in |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1639 GetStatusBubble()->Hide(); | 1636 GetStatusBubble()->Hide(); |
| 1640 | 1637 |
| 1641 // Synchronously update the location bar. This allows us to immediately | 1638 // Synchronously update the location bar. This allows us to immediately |
| 1642 // have the URL bar update when the user types something, rather than | 1639 // have the URL bar update when the user types something, rather than |
| 1643 // going through the normal system of ScheduleUIUpdate which has a delay. | 1640 // going through the normal system of ScheduleUIUpdate which has a delay. |
| 1644 UpdateToolbar(false); | 1641 UpdateToolbar(false); |
| 1645 } else if (disposition == OFF_THE_RECORD) { | 1642 } else if (disposition == OFF_THE_RECORD) { |
| 1646 OpenURLOffTheRecord(profile_, url); | 1643 OpenURLOffTheRecord(profile_, url); |
| 1647 return; | 1644 return; |
| 1648 } else if (disposition != SUPPRESS_OPEN) { | 1645 } else if (disposition != SUPPRESS_OPEN) { |
| 1649 new_contents = | 1646 new_contents = AddTabWithURL(url, referrer, transition, |
| 1650 AddTabWithURL(url, referrer, transition, | 1647 disposition != NEW_BACKGROUND_TAB, instance); |
| 1651 disposition != NEW_BACKGROUND_TAB, instance); | |
| 1652 } | 1648 } |
| 1653 | 1649 |
| 1654 if (disposition != NEW_BACKGROUND_TAB && source_tab_was_frontmost) { | 1650 if (disposition != NEW_BACKGROUND_TAB && source_tab_was_frontmost) { |
| 1655 // Give the focus to the newly navigated tab, if the source tab was | 1651 // Give the focus to the newly navigated tab, if the source tab was |
| 1656 // front-most. | 1652 // front-most. |
| 1657 new_contents->Focus(); | 1653 new_contents->Focus(); |
| 1658 } | 1654 } |
| 1659 } | 1655 } |
| 1660 | 1656 |
| 1661 void Browser::NavigationStateChanged(const TabContents* source, | 1657 void Browser::NavigationStateChanged(const TabContents* source, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1720 DCHECK(b); | 1716 DCHECK(b); |
| 1721 PageTransition::Type transition = PageTransition::LINK; | 1717 PageTransition::Type transition = PageTransition::LINK; |
| 1722 // If we were called from an "installed webapp" we want to emulate the code | 1718 // If we were called from an "installed webapp" we want to emulate the code |
| 1723 // that is run from browser_init.cc for links from external applications. | 1719 // that is run from browser_init.cc for links from external applications. |
| 1724 // This means we need to open the tab with the START PAGE transition. | 1720 // This means we need to open the tab with the START PAGE transition. |
| 1725 // AddNewContents doesn't support this but the TabStripModel's | 1721 // AddNewContents doesn't support this but the TabStripModel's |
| 1726 // AddTabContents method does. | 1722 // AddTabContents method does. |
| 1727 if (type_ == BrowserType::APPLICATION) | 1723 if (type_ == BrowserType::APPLICATION) |
| 1728 transition = PageTransition::START_PAGE; | 1724 transition = PageTransition::START_PAGE; |
| 1729 b->tabstrip_model()->AddTabContents(new_contents, -1, transition, true); | 1725 b->tabstrip_model()->AddTabContents(new_contents, -1, transition, true); |
| 1730 b->Show(); | 1726 b->window()->Show(); |
| 1731 b->window()->Activate(); | |
| 1732 return; | 1727 return; |
| 1733 } | 1728 } |
| 1734 | 1729 |
| 1735 if (disposition == NEW_POPUP) { | 1730 if (disposition == NEW_POPUP) { |
| 1736 BuildPopupWindow(source, new_contents, initial_pos); | 1731 BuildPopupWindow(source, new_contents, initial_pos); |
| 1737 } else if (disposition == NEW_WINDOW) { | 1732 } else if (disposition == NEW_WINDOW) { |
| 1738 Browser* new_browser = new Browser(gfx::Rect(), SW_SHOWNORMAL, profile_, | 1733 Browser* browser = Browser::Create(profile_); |
| 1739 BrowserType::TABBED_BROWSER, L""); | 1734 browser->AddNewContents(source, new_contents, NEW_FOREGROUND_TAB, |
| 1740 new_browser->AddNewContents(source, new_contents, NEW_FOREGROUND_TAB, | 1735 initial_pos, user_gesture); |
| 1741 initial_pos, user_gesture); | 1736 browser->window()->Show(); |
| 1742 new_browser->Show(); | |
| 1743 } else if (disposition == CURRENT_TAB) { | 1737 } else if (disposition == CURRENT_TAB) { |
| 1744 ReplaceContents(source, new_contents); | 1738 ReplaceContents(source, new_contents); |
| 1745 } else if (disposition != SUPPRESS_OPEN) { | 1739 } else if (disposition != SUPPRESS_OPEN) { |
| 1746 tabstrip_model_.AddTabContents(new_contents, -1, PageTransition::LINK, | 1740 tabstrip_model_.AddTabContents(new_contents, -1, PageTransition::LINK, |
| 1747 disposition == NEW_FOREGROUND_TAB); | 1741 disposition == NEW_FOREGROUND_TAB); |
| 1748 } | 1742 } |
| 1749 } | 1743 } |
| 1750 | 1744 |
| 1751 void Browser::ActivateContents(TabContents* contents) { | 1745 void Browser::ActivateContents(TabContents* contents) { |
| 1752 tabstrip_model_.SelectTabContentsAt( | 1746 tabstrip_model_.SelectTabContentsAt( |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1849 if (index < 0) | 1843 if (index < 0) |
| 1850 return; | 1844 return; |
| 1851 | 1845 |
| 1852 WebApp* app = contents->AsWebContents()->web_app(); | 1846 WebApp* app = contents->AsWebContents()->web_app(); |
| 1853 const std::wstring& app_name = | 1847 const std::wstring& app_name = |
| 1854 app->name().empty() ? ComputeApplicationNameFromURL(app->url()) : | 1848 app->name().empty() ? ComputeApplicationNameFromURL(app->url()) : |
| 1855 app->name(); | 1849 app->name(); |
| 1856 RegisterAppPrefs(app_name); | 1850 RegisterAppPrefs(app_name); |
| 1857 | 1851 |
| 1858 tabstrip_model_.DetachTabContentsAt(index); | 1852 tabstrip_model_.DetachTabContentsAt(index); |
| 1859 Browser* browser = new Browser(gfx::Rect(), SW_SHOWNORMAL, profile_, | 1853 Browser* browser = Browser::CreateForApp(app_name, profile_); |
| 1860 BrowserType::APPLICATION, app_name); | 1854 browser->tabstrip_model()->AppendTabContents(contents, true); |
| 1861 browser->AddNewContents( | 1855 browser->window()->Show(); |
| 1862 NULL, contents, NEW_FOREGROUND_TAB, gfx::Rect(), true); | |
| 1863 browser->Show(); | |
| 1864 } | 1856 } |
| 1865 | 1857 |
| 1866 void Browser::ContentsStateChanged(TabContents* source) { | 1858 void Browser::ContentsStateChanged(TabContents* source) { |
| 1867 int index = tabstrip_model_.GetIndexOfTabContents(source); | 1859 int index = tabstrip_model_.GetIndexOfTabContents(source); |
| 1868 if (index != TabStripModel::kNoTab) | 1860 if (index != TabStripModel::kNoTab) |
| 1869 tabstrip_model_.UpdateTabContentsStateAt(index); | 1861 tabstrip_model_.UpdateTabContentsStateAt(index); |
| 1870 } | 1862 } |
| 1871 | 1863 |
| 1872 bool Browser::ShouldDisplayURLField() { | 1864 bool Browser::ShouldDisplayURLField() { |
| 1873 return !IsApplication(); | 1865 return !IsApplication(); |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2399 RemoveFromVector(&tabs_needing_unload_fired_, tab); | 2391 RemoveFromVector(&tabs_needing_unload_fired_, tab); |
| 2400 ProcessPendingTabs(); | 2392 ProcessPendingTabs(); |
| 2401 } | 2393 } |
| 2402 | 2394 |
| 2403 /////////////////////////////////////////////////////////////////////////////// | 2395 /////////////////////////////////////////////////////////////////////////////// |
| 2404 // Browser, Assorted utility functions (private): | 2396 // Browser, Assorted utility functions (private): |
| 2405 | 2397 |
| 2406 Browser* Browser::GetOrCreateTabbedBrowser() { | 2398 Browser* Browser::GetOrCreateTabbedBrowser() { |
| 2407 Browser* browser = BrowserList::FindBrowserWithType( | 2399 Browser* browser = BrowserList::FindBrowserWithType( |
| 2408 profile_, BrowserType::TABBED_BROWSER); | 2400 profile_, BrowserType::TABBED_BROWSER); |
| 2409 if (!browser) { | 2401 if (!browser) |
| 2410 browser = new Browser(gfx::Rect(), SW_SHOWNORMAL, profile_, | 2402 browser = Browser::Create(profile_); |
| 2411 BrowserType::TABBED_BROWSER, std::wstring()); | |
| 2412 } | |
| 2413 return browser; | 2403 return browser; |
| 2414 } | 2404 } |
| 2415 | 2405 |
| 2416 void Browser::BuildPopupWindow(TabContents* source, | 2406 void Browser::BuildPopupWindow(TabContents* source, |
| 2417 TabContents* new_contents, | 2407 TabContents* new_contents, |
| 2418 const gfx::Rect& initial_pos) { | 2408 const gfx::Rect& initial_pos) { |
| 2419 BrowserType::Type type = | 2409 BrowserType::Type type = |
| 2420 type_ == BrowserType::APPLICATION ? type_ : BrowserType::BROWSER; | 2410 type_ == BrowserType::APPLICATION ? type_ : BrowserType::BROWSER; |
| 2421 Browser* browser = new Browser(initial_pos, SW_SHOWNORMAL, profile_, type, | 2411 Browser* browser = new Browser(type, profile_); |
| 2422 std::wstring()); | 2412 browser->set_override_bounds(initial_pos); |
| 2423 browser->AddNewContents(source, new_contents, | 2413 browser->CreateBrowserWindow(); |
| 2424 NEW_FOREGROUND_TAB, gfx::Rect(), true); | 2414 // TODO(beng): See if this can be made to use |
| 2425 browser->Show(); | 2415 // TabStripModel::AppendTabContents. |
| 2416 browser->AddNewContents(source, new_contents, NEW_FOREGROUND_TAB, |
| 2417 gfx::Rect(), true); |
| 2418 browser->window()->Show(); |
| 2426 } | 2419 } |
| 2427 | 2420 |
| 2428 GURL Browser::GetHomePage() { | 2421 GURL Browser::GetHomePage() { |
| 2429 if (profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) { | 2422 if (profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) |
| 2430 return NewTabUIURL(); | 2423 return NewTabUIURL(); |
| 2431 } else { | 2424 GURL home_page = GURL(URLFixerUpper::FixupURL( |
| 2432 GURL home_page = GURL(URLFixerUpper::FixupURL( | 2425 profile_->GetPrefs()->GetString(prefs::kHomePage), |
| 2433 profile_->GetPrefs()->GetString(prefs::kHomePage), | 2426 std::wstring())); |
| 2434 std::wstring())); | 2427 if (!home_page.is_valid()) |
| 2435 if (!home_page.is_valid()) | 2428 return NewTabUIURL(); |
| 2436 return NewTabUIURL(); | 2429 return home_page; |
| 2437 | |
| 2438 return home_page; | |
| 2439 } | |
| 2440 } | 2430 } |
| 2441 | 2431 |
| 2442 void Browser::AdvanceFindSelection(bool forward_direction) { | 2432 void Browser::AdvanceFindSelection(bool forward_direction) { |
| 2443 GetSelectedTabContents()->AsWebContents()->view()->FindInPage( | 2433 GetSelectedTabContents()->AsWebContents()->view()->FindInPage( |
| 2444 *this, true, forward_direction); | 2434 *this, true, forward_direction); |
| 2445 } | 2435 } |
| 2446 | 2436 |
| 2447 void Browser::CloseFrame() { | 2437 void Browser::CloseFrame() { |
| 2448 window_->Close(); | 2438 window_->Close(); |
| 2449 } | 2439 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2472 | 2462 |
| 2473 // We need to register the window position pref. | 2463 // We need to register the window position pref. |
| 2474 std::wstring window_pref(prefs::kBrowserWindowPlacement); | 2464 std::wstring window_pref(prefs::kBrowserWindowPlacement); |
| 2475 window_pref.append(L"_"); | 2465 window_pref.append(L"_"); |
| 2476 window_pref.append(app_name); | 2466 window_pref.append(app_name); |
| 2477 PrefService* prefs = g_browser_process->local_state(); | 2467 PrefService* prefs = g_browser_process->local_state(); |
| 2478 DCHECK(prefs); | 2468 DCHECK(prefs); |
| 2479 | 2469 |
| 2480 prefs->RegisterDictionaryPref(window_pref.c_str()); | 2470 prefs->RegisterDictionaryPref(window_pref.c_str()); |
| 2481 } | 2471 } |
| OLD | NEW |