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 <windows.h> | 5 #include <windows.h> |
6 #include <shellapi.h> | 6 #include <shellapi.h> |
7 | 7 |
8 #include "chrome/browser/browser.h" | 8 #include "chrome/browser/browser.h" |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 : type_(type), | 143 : type_(type), |
144 profile_(profile), | 144 profile_(profile), |
145 window_(NULL), | 145 window_(NULL), |
146 tabstrip_model_(this, profile), | 146 tabstrip_model_(this, profile), |
147 controller_(this), | 147 controller_(this), |
148 toolbar_model_(this), | 148 toolbar_model_(this), |
149 chrome_updater_factory_(this), | 149 chrome_updater_factory_(this), |
150 is_attempting_to_close_browser_(false), | 150 is_attempting_to_close_browser_(false), |
151 override_maximized_(false), | 151 override_maximized_(false), |
152 method_factory_(this), | 152 method_factory_(this), |
153 idle_task_(new BrowserIdleTimer) { | 153 idle_task_(new BrowserIdleTimer), |
| 154 parent_hwnd_(NULL) { |
154 tabstrip_model_.AddObserver(this); | 155 tabstrip_model_.AddObserver(this); |
155 | 156 |
156 NotificationService::current()->AddObserver( | 157 NotificationService::current()->AddObserver( |
157 this, NOTIFY_SSL_STATE_CHANGED, NotificationService::AllSources()); | 158 this, NOTIFY_SSL_STATE_CHANGED, NotificationService::AllSources()); |
158 | 159 |
159 InitCommandState(); | 160 InitCommandState(); |
160 BrowserList::AddBrowser(this); | 161 BrowserList::AddBrowser(this); |
161 | 162 |
162 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, | 163 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, |
163 profile_->GetPrefs(), NULL); | 164 profile_->GetPrefs(), NULL); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 225 |
225 // static | 226 // static |
226 Browser* Browser::CreateForApp(const std::wstring& app_name, | 227 Browser* Browser::CreateForApp(const std::wstring& app_name, |
227 Profile* profile) { | 228 Profile* profile) { |
228 Browser* browser = new Browser(BrowserType::APPLICATION, profile); | 229 Browser* browser = new Browser(BrowserType::APPLICATION, profile); |
229 browser->app_name_ = app_name; | 230 browser->app_name_ = app_name; |
230 browser->CreateBrowserWindow(); | 231 browser->CreateBrowserWindow(); |
231 return browser; | 232 return browser; |
232 } | 233 } |
233 | 234 |
| 235 // static |
| 236 Browser* Browser::CreateForEmbedded(HWND parent_hwnd, |
| 237 gfx::Rect& rect, |
| 238 Profile* profile) { |
| 239 Browser* browser = new Browser(BrowserType::EMBEDDED, profile); |
| 240 browser->set_parent_hwnd(parent_hwnd); |
| 241 browser->set_override_bounds(rect); |
| 242 browser->CreateBrowserWindow(); |
| 243 return browser; |
| 244 } |
| 245 |
234 void Browser::CreateBrowserWindow() { | 246 void Browser::CreateBrowserWindow() { |
235 DCHECK(!window_); | 247 DCHECK(!window_); |
236 window_ = BrowserWindow::CreateBrowserWindow(this); | 248 window_ = BrowserWindow::CreateBrowserWindow(this); |
237 | 249 |
238 // Show the First Run information bubble if we've been told to. | 250 // Show the First Run information bubble if we've been told to. |
239 PrefService* local_state = g_browser_process->local_state(); | 251 PrefService* local_state = g_browser_process->local_state(); |
240 if (local_state->IsPrefRegistered(prefs::kShouldShowFirstRunBubble) && | 252 if (local_state->IsPrefRegistered(prefs::kShouldShowFirstRunBubble) && |
241 local_state->GetBoolean(prefs::kShouldShowFirstRunBubble)) { | 253 local_state->GetBoolean(prefs::kShouldShowFirstRunBubble)) { |
242 // Reset the preference so we don't show the bubble for subsequent windows. | 254 // Reset the preference so we don't show the bubble for subsequent windows. |
243 local_state->ClearPref(prefs::kShouldShowFirstRunBubble); | 255 local_state->ClearPref(prefs::kShouldShowFirstRunBubble); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 std::wstring Browser::GetWindowPlacementKey() const { | 319 std::wstring Browser::GetWindowPlacementKey() const { |
308 std::wstring name(prefs::kBrowserWindowPlacement); | 320 std::wstring name(prefs::kBrowserWindowPlacement); |
309 if (!app_name_.empty()) { | 321 if (!app_name_.empty()) { |
310 name.append(L"_"); | 322 name.append(L"_"); |
311 name.append(app_name_); | 323 name.append(app_name_); |
312 } | 324 } |
313 return name; | 325 return name; |
314 } | 326 } |
315 | 327 |
316 bool Browser::ShouldSaveWindowPlacement() const { | 328 bool Browser::ShouldSaveWindowPlacement() const { |
317 // We don't save window position for popups. | 329 // We don't save window position for popups for embedded windows. |
318 return type() != BrowserType::BROWSER; | 330 return type() != BrowserType::BROWSER && type() != BrowserType::EMBEDDED; |
319 } | 331 } |
320 | 332 |
321 void Browser::SaveWindowPlacement(const gfx::Rect& bounds, bool maximized) { | 333 void Browser::SaveWindowPlacement(const gfx::Rect& bounds, bool maximized) { |
322 // Save to the session storage service, used when reloading a past session. | 334 // Save to the session storage service, used when reloading a past session. |
323 // Note that we don't want to be the ones who cause lazy initialization of | 335 // Note that we don't want to be the ones who cause lazy initialization of |
324 // the session service. This function gets called during initial window | 336 // the session service. This function gets called during initial window |
325 // showing, and we don't want to bring in the session service this early. | 337 // showing, and we don't want to bring in the session service this early. |
326 if (profile()->HasSessionService()) { | 338 if (profile()->HasSessionService()) { |
327 SessionService* session_service = profile()->GetSessionService(); | 339 SessionService* session_service = profile()->GetSessionService(); |
328 if (session_service) | 340 if (session_service) |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 | 702 |
691 const TabRestoreService::HistoricalTab& tab = tabs.front(); | 703 const TabRestoreService::HistoricalTab& tab = tabs.front(); |
692 AddRestoredTab(tab.navigations, tab_count(), tab.current_navigation_index, | 704 AddRestoredTab(tab.navigations, tab_count(), tab.current_navigation_index, |
693 true); | 705 true); |
694 service->RemoveHistoricalTabById(tab.id); | 706 service->RemoveHistoricalTabById(tab.id); |
695 } | 707 } |
696 | 708 |
697 void Browser::ConvertPopupToTabbedBrowser() { | 709 void Browser::ConvertPopupToTabbedBrowser() { |
698 UserMetrics::RecordAction(L"ShowAsTab", profile_); | 710 UserMetrics::RecordAction(L"ShowAsTab", profile_); |
699 | 711 |
700 if (type() != BrowserType::BROWSER) { | 712 if (type() != BrowserType::BROWSER && type() != BrowserType::EMBEDDED) { |
701 NOTREACHED(); | 713 NOTREACHED(); |
702 return; | 714 return; |
703 } | 715 } |
704 | 716 |
705 int tab_strip_index = tabstrip_model_.selected_index(); | 717 int tab_strip_index = tabstrip_model_.selected_index(); |
706 TabContents* contents = tabstrip_model_.DetachTabContentsAt(tab_strip_index); | 718 TabContents* contents = tabstrip_model_.DetachTabContentsAt(tab_strip_index); |
707 Browser* browser = Browser::Create(profile_); | 719 Browser* browser = Browser::Create(profile_); |
708 browser->tabstrip_model()->AppendTabContents(contents, true); | 720 browser->tabstrip_model()->AppendTabContents(contents, true); |
709 browser->window()->Show(); | 721 browser->window()->Show(); |
710 } | 722 } |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 // the right index (if tab 5 is selected and we right-click tab 1 we want | 1281 // the right index (if tab 5 is selected and we right-click tab 1 we want |
1270 // the new tab to appear in index position 2, not 6). | 1282 // the new tab to appear in index position 2, not 6). |
1271 if (tabstrip_model_.selected_index() != index) | 1283 if (tabstrip_model_.selected_index() != index) |
1272 tabstrip_model_.SelectTabContentsAt(index, true); | 1284 tabstrip_model_.SelectTabContentsAt(index, true); |
1273 tabstrip_model_.AddTabContents(new_contents, index + 1, | 1285 tabstrip_model_.AddTabContents(new_contents, index + 1, |
1274 PageTransition::LINK, true); | 1286 PageTransition::LINK, true); |
1275 } else { | 1287 } else { |
1276 Browser* browser = NULL; | 1288 Browser* browser = NULL; |
1277 if (type_ == BrowserType::APPLICATION) { | 1289 if (type_ == BrowserType::APPLICATION) { |
1278 browser = Browser::CreateForApp(app_name_, profile_); | 1290 browser = Browser::CreateForApp(app_name_, profile_); |
1279 } else if (type_ == BrowserType::BROWSER) { | 1291 } else if (type_ == BrowserType::BROWSER || type_ == BrowserType::EMBEDDED)
{ |
1280 browser = Browser::CreateForPopup(profile_); | 1292 browser = Browser::CreateForPopup(profile_); |
1281 } | 1293 } |
1282 | 1294 |
1283 // We need to show the browser now. Otherwise ContainerWin assumes the | 1295 // We need to show the browser now. Otherwise ContainerWin assumes the |
1284 // TabContents is invisible and won't size it. | 1296 // TabContents is invisible and won't size it. |
1285 browser->window()->Show(); | 1297 browser->window()->Show(); |
1286 | 1298 |
1287 // The page transition below is only for the purpose of inserting the tab. | 1299 // The page transition below is only for the purpose of inserting the tab. |
1288 HWND parent_hwnd = reinterpret_cast<HWND>(window_->GetNativeHandle()); | 1300 HWND parent_hwnd = reinterpret_cast<HWND>(window_->GetNativeHandle()); |
1289 new_contents = browser->AddTabWithNavigationController( | 1301 new_contents = browser->AddTabWithNavigationController( |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1661 | 1673 |
1662 int index = tabstrip_model_.GetIndexOfTabContents(source); | 1674 int index = tabstrip_model_.GetIndexOfTabContents(source); |
1663 if (index == TabStripModel::kNoTab) { | 1675 if (index == TabStripModel::kNoTab) { |
1664 NOTREACHED() << "CloseContents called for tab not in our strip"; | 1676 NOTREACHED() << "CloseContents called for tab not in our strip"; |
1665 return; | 1677 return; |
1666 } | 1678 } |
1667 tabstrip_model_.CloseTabContentsAt(index); | 1679 tabstrip_model_.CloseTabContentsAt(index); |
1668 } | 1680 } |
1669 | 1681 |
1670 void Browser::MoveContents(TabContents* source, const gfx::Rect& pos) { | 1682 void Browser::MoveContents(TabContents* source, const gfx::Rect& pos) { |
1671 if (type() != BrowserType::BROWSER) { | 1683 if (type() != BrowserType::BROWSER && type() != BrowserType::EMBEDDED) { |
1672 NOTREACHED() << "moving invalid browser type"; | 1684 NOTREACHED() << "moving invalid browser type"; |
1673 return; | 1685 return; |
1674 } | 1686 } |
1675 window_->SetBounds(pos); | 1687 window_->SetBounds(pos); |
1676 } | 1688 } |
1677 | 1689 |
1678 bool Browser::IsPopup(TabContents* source) { | 1690 bool Browser::IsPopup(TabContents* source) { |
1679 // A non-tabbed BROWSER is an unconstrained popup. | 1691 // A non-tabbed BROWSER is an unconstrained popup. |
1680 return (type() == BrowserType::BROWSER); | 1692 return (type() == BrowserType::BROWSER); |
1681 } | 1693 } |
1682 | 1694 |
| 1695 bool Browser::IsEmbedded(TabContents* source) { |
| 1696 return (type() == BrowserType::EMBEDDED); |
| 1697 } |
| 1698 |
1683 void Browser::ToolbarSizeChanged(TabContents* source, bool is_animating) { | 1699 void Browser::ToolbarSizeChanged(TabContents* source, bool is_animating) { |
1684 if (source == GetSelectedTabContents() || source == NULL) { | 1700 if (source == GetSelectedTabContents() || source == NULL) { |
1685 // This will refresh the shelf if needed. | 1701 // This will refresh the shelf if needed. |
1686 window_->SelectedTabToolbarSizeChanged(is_animating); | 1702 window_->SelectedTabToolbarSizeChanged(is_animating); |
1687 } | 1703 } |
1688 } | 1704 } |
1689 | 1705 |
1690 void Browser::URLStarredChanged(TabContents* source, bool starred) { | 1706 void Browser::URLStarredChanged(TabContents* source, bool starred) { |
1691 if (source == GetSelectedTabContents()) | 1707 if (source == GetSelectedTabContents()) |
1692 SetStarredButtonToggled(starred); | 1708 SetStarredButtonToggled(starred); |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2345 | 2361 |
2346 // We need to register the window position pref. | 2362 // We need to register the window position pref. |
2347 std::wstring window_pref(prefs::kBrowserWindowPlacement); | 2363 std::wstring window_pref(prefs::kBrowserWindowPlacement); |
2348 window_pref.append(L"_"); | 2364 window_pref.append(L"_"); |
2349 window_pref.append(app_name); | 2365 window_pref.append(app_name); |
2350 PrefService* prefs = g_browser_process->local_state(); | 2366 PrefService* prefs = g_browser_process->local_state(); |
2351 DCHECK(prefs); | 2367 DCHECK(prefs); |
2352 | 2368 |
2353 prefs->RegisterDictionaryPref(window_pref.c_str()); | 2369 prefs->RegisterDictionaryPref(window_pref.c_str()); |
2354 } | 2370 } |
OLD | NEW |