OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser_navigator.h" | 5 #include "chrome/browser/ui/browser_navigator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/browser_about_handler.h" | 12 #include "chrome/browser/browser_about_handler.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/extension_tab_helper.h" | 14 #include "chrome/browser/extensions/extension_tab_helper.h" |
15 #include "chrome/browser/google/google_url_tracker.h" | 15 #include "chrome/browser/google/google_url_tracker.h" |
16 #include "chrome/browser/google/google_util.h" | 16 #include "chrome/browser/google/google_util.h" |
17 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 17 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/browser/prerender/prerender_manager.h" | 19 #include "chrome/browser/prerender/prerender_manager.h" |
20 #include "chrome/browser/prerender/prerender_manager_factory.h" | 20 #include "chrome/browser/prerender/prerender_manager_factory.h" |
21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/rlz/rlz.h" | 22 #include "chrome/browser/rlz/rlz.h" |
23 #include "chrome/browser/tab_contents/tab_util.h" | 23 #include "chrome/browser/tab_contents/tab_util.h" |
24 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
25 #include "chrome/browser/ui/browser_list.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
26 #include "chrome/browser/ui/browser_window.h" | 26 #include "chrome/browser/ui/browser_window.h" |
27 #include "chrome/browser/ui/omnibox/location_bar.h" | 27 #include "chrome/browser/ui/omnibox/location_bar.h" |
28 #include "chrome/browser/ui/status_bubble.h" | 28 #include "chrome/browser/ui/status_bubble.h" |
29 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 29 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
30 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 30 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
31 #include "chrome/browser/web_applications/web_app.h" | 31 #include "chrome/browser/web_applications/web_app.h" |
32 #include "chrome/common/chrome_notification_types.h" | 32 #include "chrome/common/chrome_notification_types.h" |
33 #include "chrome/common/extensions/extension.h" | 33 #include "chrome/common/extensions/extension.h" |
34 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
35 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
(...skipping 13 matching lines...) Expand all Loading... |
49 // multiple tabs, such as app frames and popups. This function returns false for | 49 // multiple tabs, such as app frames and popups. This function returns false for |
50 // those types of Browser. | 50 // those types of Browser. |
51 bool WindowCanOpenTabs(Browser* browser) { | 51 bool WindowCanOpenTabs(Browser* browser) { |
52 return browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP) || | 52 return browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP) || |
53 browser->tab_strip_model()->empty(); | 53 browser->tab_strip_model()->empty(); |
54 } | 54 } |
55 | 55 |
56 // Finds an existing Browser compatible with |profile|, making a new one if no | 56 // Finds an existing Browser compatible with |profile|, making a new one if no |
57 // such Browser is located. | 57 // such Browser is located. |
58 Browser* GetOrCreateBrowser(Profile* profile) { | 58 Browser* GetOrCreateBrowser(Profile* profile) { |
59 Browser* browser = BrowserList::FindTabbedBrowser(profile, false); | 59 Browser* browser = browser::FindTabbedBrowser(profile, false); |
60 return browser ? browser : Browser::Create(profile); | 60 return browser ? browser : Browser::Create(profile); |
61 } | 61 } |
62 | 62 |
63 // Returns true if two URLs are equal after taking |replacements| into account. | 63 // Returns true if two URLs are equal after taking |replacements| into account. |
64 bool CompareURLsWithReplacements( | 64 bool CompareURLsWithReplacements( |
65 const GURL& url, | 65 const GURL& url, |
66 const GURL& other, | 66 const GURL& other, |
67 const url_canon::Replacements<char>& replacements) { | 67 const url_canon::Replacements<char>& replacements) { |
68 if (url == other) | 68 if (url == other) |
69 return true; | 69 return true; |
(...skipping 24 matching lines...) Expand all Loading... |
94 | 94 |
95 // If incognito is forced, we punt. | 95 // If incognito is forced, we punt. |
96 PrefService* prefs = profile->GetPrefs(); | 96 PrefService* prefs = profile->GetPrefs(); |
97 if (prefs && IncognitoModePrefs::GetAvailability(prefs) == | 97 if (prefs && IncognitoModePrefs::GetAvailability(prefs) == |
98 IncognitoModePrefs::FORCED) { | 98 IncognitoModePrefs::FORCED) { |
99 return false; | 99 return false; |
100 } | 100 } |
101 | 101 |
102 params->disposition = SINGLETON_TAB; | 102 params->disposition = SINGLETON_TAB; |
103 params->profile = profile; | 103 params->profile = profile; |
104 params->browser = Browser::GetOrCreateTabbedBrowser(profile); | 104 params->browser = browser::FindOrCreateTabbedBrowser(profile); |
105 params->window_action = browser::NavigateParams::SHOW_WINDOW; | 105 params->window_action = browser::NavigateParams::SHOW_WINDOW; |
106 } | 106 } |
107 | 107 |
108 return true; | 108 return true; |
109 } | 109 } |
110 | 110 |
111 // Returns a Browser that can host the navigation or tab addition specified in | 111 // Returns a Browser that can host the navigation or tab addition specified in |
112 // |params|. This might just return the same Browser specified in |params|, or | 112 // |params|. This might just return the same Browser specified in |params|, or |
113 // some other if that Browser is deemed incompatible. | 113 // some other if that Browser is deemed incompatible. |
114 Browser* GetBrowserForDisposition(browser::NavigateParams* params) { | 114 Browser* GetBrowserForDisposition(browser::NavigateParams* params) { |
115 // If no source TabContentsWrapper was specified, we use the selected one from | 115 // If no source TabContentsWrapper was specified, we use the selected one from |
116 // the target browser. This must happen first, before | 116 // the target browser. This must happen first, before |
117 // GetBrowserForDisposition() has a chance to replace |params->browser| with | 117 // GetBrowserForDisposition() has a chance to replace |params->browser| with |
118 // another one. | 118 // another one. |
119 if (!params->source_contents && params->browser) | 119 if (!params->source_contents && params->browser) |
120 params->source_contents = | 120 params->source_contents = |
121 params->browser->GetSelectedTabContentsWrapper(); | 121 params->browser->GetSelectedTabContentsWrapper(); |
122 | 122 |
123 Profile* profile = | 123 Profile* profile = |
124 params->browser ? params->browser->profile() : params->profile; | 124 params->browser ? params->browser->profile() : params->profile; |
125 | 125 |
126 switch (params->disposition) { | 126 switch (params->disposition) { |
127 case CURRENT_TAB: | 127 case CURRENT_TAB: |
128 if (!params->browser && profile) { | 128 if (!params->browser && profile) { |
129 // We specified a profile instead of a browser; find or create one. | 129 // We specified a profile instead of a browser; find or create one. |
130 params->browser = Browser::GetOrCreateTabbedBrowser(profile); | 130 params->browser = browser::FindOrCreateTabbedBrowser(profile); |
131 } | 131 } |
132 return params->browser; | 132 return params->browser; |
133 case SINGLETON_TAB: | 133 case SINGLETON_TAB: |
134 case NEW_FOREGROUND_TAB: | 134 case NEW_FOREGROUND_TAB: |
135 case NEW_BACKGROUND_TAB: | 135 case NEW_BACKGROUND_TAB: |
136 // See if we can open the tab in the window this navigator is bound to. | 136 // See if we can open the tab in the window this navigator is bound to. |
137 if (params->browser && WindowCanOpenTabs(params->browser)) | 137 if (params->browser && WindowCanOpenTabs(params->browser)) |
138 return params->browser; | 138 return params->browser; |
139 // Find a compatible window and re-execute this command in it. Otherwise | 139 // Find a compatible window and re-execute this command in it. Otherwise |
140 // re-run with NEW_WINDOW. | 140 // re-run with NEW_WINDOW. |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 return !(url.scheme() == chrome::kChromeUIScheme && | 677 return !(url.scheme() == chrome::kChromeUIScheme && |
678 (url.host() == chrome::kChromeUISettingsHost || | 678 (url.host() == chrome::kChromeUISettingsHost || |
679 url.host() == chrome::kChromeUISettingsFrameHost || | 679 url.host() == chrome::kChromeUISettingsFrameHost || |
680 url.host() == chrome::kChromeUIExtensionsHost || | 680 url.host() == chrome::kChromeUIExtensionsHost || |
681 url.host() == chrome::kChromeUIBookmarksHost || | 681 url.host() == chrome::kChromeUIBookmarksHost || |
682 url.host() == chrome::kChromeUISyncPromoHost || | 682 url.host() == chrome::kChromeUISyncPromoHost || |
683 url.host() == chrome::kChromeUIUberHost)); | 683 url.host() == chrome::kChromeUIUberHost)); |
684 } | 684 } |
685 | 685 |
686 } // namespace browser | 686 } // namespace browser |
OLD | NEW |