Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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/settings_window_manager.h" | 5 #include "chrome/browser/ui/settings_window_manager.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/ui/browser_finder.h" | 8 #include "chrome/browser/ui/browser_finder.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/browser_navigator.h" | 10 #include "chrome/browser/ui/browser_navigator.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 } | 47 } |
| 48 NavigateParams params(browser, gurl, | 48 NavigateParams params(browser, gurl, |
| 49 ui::PAGE_TRANSITION_AUTO_BOOKMARK); | 49 ui::PAGE_TRANSITION_AUTO_BOOKMARK); |
| 50 params.window_action = NavigateParams::SHOW_WINDOW; | 50 params.window_action = NavigateParams::SHOW_WINDOW; |
| 51 params.user_gesture = true; | 51 params.user_gesture = true; |
| 52 chrome::Navigate(¶ms); | 52 chrome::Navigate(¶ms); |
| 53 return; | 53 return; |
| 54 } | 54 } |
| 55 | 55 |
| 56 // No existing browser window, create one. | 56 // No existing browser window, create one. |
| 57 NavigateParams params(profile, gurl, ui::PAGE_TRANSITION_AUTO_BOOKMARK); | 57 navigate_params_.reset( |
| 58 params.disposition = NEW_POPUP; | 58 new NavigateParams(profile, gurl, ui::PAGE_TRANSITION_AUTO_BOOKMARK)); |
| 59 params.trusted_source = true; | 59 navigate_params_->disposition = NEW_POPUP; |
| 60 params.window_action = NavigateParams::SHOW_WINDOW; | 60 navigate_params_->trusted_source = true; |
| 61 params.user_gesture = true; | 61 navigate_params_->window_action = NavigateParams::SHOW_WINDOW; |
| 62 params.path_behavior = NavigateParams::IGNORE_AND_NAVIGATE; | 62 navigate_params_->user_gesture = true; |
| 63 chrome::Navigate(¶ms); | 63 navigate_params_->path_behavior = NavigateParams::IGNORE_AND_NAVIGATE; |
| 64 settings_session_map_[profile] = params.browser->session_id().id(); | 64 chrome::Navigate(navigate_params_.get()); |
| 65 settings_session_map_[profile] = navigate_params_->browser->session_id().id(); | |
| 66 // Once we set settings_session_map_, reset |navigate_params_| so that we do | |
| 67 // not hold on to a structure with stale pointers. | |
| 68 navigate_params_.reset(); | |
| 65 | 69 |
| 66 FOR_EACH_OBSERVER(SettingsWindowManagerObserver, | 70 FOR_EACH_OBSERVER(SettingsWindowManagerObserver, |
| 67 observers_, OnNewSettingsWindow(params.browser)); | 71 observers_, OnNewSettingsWindow(navigate_params_->browser)); |
| 68 } | 72 } |
| 69 | 73 |
| 70 Browser* SettingsWindowManager::FindBrowserForProfile(Profile* profile) { | 74 Browser* SettingsWindowManager::FindBrowserForProfile(Profile* profile) { |
| 71 ProfileSessionMap::iterator iter = settings_session_map_.find(profile); | 75 ProfileSessionMap::iterator iter = settings_session_map_.find(profile); |
| 72 if (iter != settings_session_map_.end()) | 76 if (iter != settings_session_map_.end()) |
| 73 return chrome::FindBrowserWithID(iter->second); | 77 return chrome::FindBrowserWithID(iter->second); |
| 74 return NULL; | 78 return NULL; |
| 75 } | 79 } |
| 76 | 80 |
| 77 bool SettingsWindowManager::IsSettingsBrowser(Browser* browser) const { | 81 bool SettingsWindowManager::IsSettingsBrowser(Browser* browser) const { |
| 82 // This may get called from chrome::Navigate, so first test to see if this | |
| 83 // is the browser we are crrently navigating to. | |
| 84 if (navigate_params_ && navigate_params_->browser == browser) | |
|
sky
2014/09/25 23:36:52
Dependencies like this are fragile and result in N
| |
| 85 return true; | |
| 78 ProfileSessionMap::const_iterator iter = | 86 ProfileSessionMap::const_iterator iter = |
| 79 settings_session_map_.find(browser->profile()); | 87 settings_session_map_.find(browser->profile()); |
| 80 return (iter != settings_session_map_.end() && | 88 return (iter != settings_session_map_.end() && |
| 81 iter->second == browser->session_id().id()); | 89 iter->second == browser->session_id().id()); |
| 82 } | 90 } |
| 83 | 91 |
| 84 SettingsWindowManager::SettingsWindowManager() { | 92 SettingsWindowManager::SettingsWindowManager() { |
| 85 } | 93 } |
| 86 | 94 |
| 87 SettingsWindowManager::~SettingsWindowManager() { | 95 SettingsWindowManager::~SettingsWindowManager() { |
| 88 } | 96 } |
| 89 | 97 |
| 90 } // namespace chrome | 98 } // namespace chrome |
| OLD | NEW |