Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: chrome/browser/ui/browser_navigator.cc

Issue 7448012: Create the correct SiteInstance when restoring tabs that belong to apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix style. Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | content/browser/tab_contents/render_view_host_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/browser_about_handler.h" 10 #include "chrome/browser/browser_about_handler.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_tab_helper.h" 12 #include "chrome/browser/extensions/extension_tab_helper.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/tabs/tab_strip_model.h" 14 #include "chrome/browser/tabs/tab_strip_model.h"
15 #include "chrome/browser/tab_contents/tab_util.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_list.h" 17 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/browser/ui/browser_window.h" 18 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/browser/ui/omnibox/location_bar.h" 19 #include "chrome/browser/ui/omnibox/location_bar.h"
19 #include "chrome/browser/ui/status_bubble.h" 20 #include "chrome/browser/ui/status_bubble.h"
20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
21 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
22 #include "chrome/browser/web_applications/web_app.h" 22 #include "chrome/browser/web_applications/web_app.h"
23 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/extensions/extension.h" 23 #include "chrome/common/extensions/extension.h"
25 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
26 #include "content/browser/browser_url_handler.h" 25 #include "content/browser/browser_url_handler.h"
27 #include "content/browser/site_instance.h" 26 #include "content/browser/site_instance.h"
28 #include "content/browser/tab_contents/tab_contents.h" 27 #include "content/browser/tab_contents/tab_contents.h"
29 28
30 namespace { 29 namespace {
31 30
32 // Returns an appropriate SiteInstance for WebUI URLs, or the SiteInstance for
33 // |source_contents| if it represents the same website as |url|. Returns NULL
34 // otherwise.
35 SiteInstance* GetSiteInstance(TabContents* source_contents, Profile* profile,
36 const GURL& url) {
37 // If url is a WebUI or extension, we need to be sure to use the right type
38 // of renderer process up front. Otherwise, we create a normal SiteInstance
39 // as part of creating the tab.
40 ExtensionService* service = profile->GetExtensionService();
41 if (ChromeWebUIFactory::GetInstance()->UseWebUIForURL(profile, url) ||
42 (service && service->GetExtensionByWebExtent(url))) {
43 return SiteInstance::CreateSiteInstanceForURL(profile, url);
44 }
45
46 if (!source_contents)
47 return NULL;
48
49 // Don't use this logic when "--process-per-tab" is specified.
50 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab) &&
51 SiteInstance::IsSameWebSite(source_contents->profile(),
52 source_contents->GetURL(),
53 url)) {
54 return source_contents->GetSiteInstance();
55 }
56 return NULL;
57 }
58
59 // Returns true if the specified Browser can open tabs. Not all Browsers support 31 // Returns true if the specified Browser can open tabs. Not all Browsers support
60 // multiple tabs, such as app frames and popups. This function returns false for 32 // multiple tabs, such as app frames and popups. This function returns false for
61 // those types of Browser. 33 // those types of Browser.
62 bool WindowCanOpenTabs(Browser* browser) { 34 bool WindowCanOpenTabs(Browser* browser) {
63 return browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP) || 35 return browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP) ||
64 browser->tabstrip_model()->empty(); 36 browser->tabstrip_model()->empty();
65 } 37 }
66 38
67 // Finds an existing Browser compatible with |profile|, making a new one if no 39 // Finds an existing Browser compatible with |profile|, making a new one if no
68 // such Browser is located. 40 // such Browser is located.
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 // supposed to target a new tab; unless it's a singleton that already exists. 377 // supposed to target a new tab; unless it's a singleton that already exists.
406 if (!params->target_contents && singleton_index < 0) { 378 if (!params->target_contents && singleton_index < 0) {
407 GURL url = params->url.is_empty() ? params->browser->GetHomePage() 379 GURL url = params->url.is_empty() ? params->browser->GetHomePage()
408 : params->url; 380 : params->url;
409 if (params->disposition != CURRENT_TAB) { 381 if (params->disposition != CURRENT_TAB) {
410 TabContents* source_contents = params->source_contents ? 382 TabContents* source_contents = params->source_contents ?
411 params->source_contents->tab_contents() : NULL; 383 params->source_contents->tab_contents() : NULL;
412 params->target_contents = 384 params->target_contents =
413 Browser::TabContentsFactory( 385 Browser::TabContentsFactory(
414 params->browser->profile(), 386 params->browser->profile(),
415 GetSiteInstance(source_contents, params->browser->profile(), url), 387 tab_util::GetSiteInstanceForNewTab(
388 source_contents, params->browser->profile(), url),
416 MSG_ROUTING_NONE, 389 MSG_ROUTING_NONE,
417 source_contents, 390 source_contents,
418 NULL); 391 NULL);
419 // This function takes ownership of |params->target_contents| until it 392 // This function takes ownership of |params->target_contents| until it
420 // is added to a TabStripModel. 393 // is added to a TabStripModel.
421 target_contents_owner.TakeOwnership(); 394 target_contents_owner.TakeOwnership();
422 params->target_contents->extension_tab_helper()-> 395 params->target_contents->extension_tab_helper()->
423 SetExtensionAppById(params->extension_app_id); 396 SetExtensionAppById(params->extension_app_id);
424 // TODO(sky): figure out why this is needed. Without it we seem to get 397 // TODO(sky): figure out why this is needed. Without it we seem to get
425 // failures in startup tests. 398 // failures in startup tests.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 rewritten_url, replacements)) { 514 rewritten_url, replacements)) {
542 params->target_contents = tab; 515 params->target_contents = tab;
543 return tab_index; 516 return tab_index;
544 } 517 }
545 } 518 }
546 519
547 return -1; 520 return -1;
548 } 521 }
549 522
550 } // namespace browser 523 } // namespace browser
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | content/browser/tab_contents/render_view_host_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698