OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/settings_window_manager.h" |
| 6 |
| 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/ui/browser_finder.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/browser_navigator.h" |
| 11 #include "chrome/browser/ui/browser_window.h" |
| 12 #include "chrome/browser/ui/chrome_pages.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "content/public/browser/user_metrics.h" |
| 15 #include "content/public/browser/web_contents.h" |
| 16 |
| 17 namespace chrome { |
| 18 |
| 19 // static |
| 20 SettingsWindowManager* SettingsWindowManager::GetInstance() { |
| 21 return Singleton<SettingsWindowManager>::get(); |
| 22 } |
| 23 |
| 24 void SettingsWindowManager::ShowForProfile(Profile* profile, |
| 25 const std::string& sub_page) { |
| 26 content::RecordAction(base::UserMetricsAction("ShowOptions")); |
| 27 GURL gurl = chrome::GetSettingsUrl(sub_page); |
| 28 // Look for an existing browser window. |
| 29 ProfileSessionMap::iterator iter = settings_session_map_.find(profile); |
| 30 if (iter != settings_session_map_.end()) { |
| 31 Browser* browser = chrome::FindBrowserWithID(iter->second); |
| 32 if (browser) { |
| 33 DCHECK(browser->profile() == profile); |
| 34 const content::WebContents* web_contents = |
| 35 browser->tab_strip_model()->GetWebContentsAt(0); |
| 36 if (web_contents && web_contents->GetURL() == gurl) { |
| 37 browser->window()->Show(); |
| 38 return; |
| 39 } |
| 40 NavigateParams params(browser, gurl, |
| 41 content::PAGE_TRANSITION_AUTO_BOOKMARK); |
| 42 params.window_action = NavigateParams::SHOW_WINDOW; |
| 43 params.user_gesture = true; |
| 44 chrome::Navigate(¶ms); |
| 45 return; |
| 46 } |
| 47 } |
| 48 // No existing browser window, create one. |
| 49 NavigateParams params(profile, gurl, content::PAGE_TRANSITION_AUTO_BOOKMARK); |
| 50 params.disposition = NEW_POPUP; |
| 51 params.window_action = NavigateParams::SHOW_WINDOW; |
| 52 params.user_gesture = true; |
| 53 params.path_behavior = NavigateParams::IGNORE_AND_NAVIGATE; |
| 54 chrome::Navigate(¶ms); |
| 55 settings_session_map_[profile] = params.browser->session_id().id(); |
| 56 } |
| 57 |
| 58 SettingsWindowManager::SettingsWindowManager() { |
| 59 } |
| 60 |
| 61 SettingsWindowManager::~SettingsWindowManager() { |
| 62 } |
| 63 |
| 64 } // namespace chrome |
OLD | NEW |