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/webui/chrome_web_contents_handler.h" | 5 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" |
6 | 6 |
7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.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" |
11 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
| 12 #include "chrome/browser/ui/host_desktop.h" |
12 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 13 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
15 | 16 |
16 using content::BrowserContext; | 17 using content::BrowserContext; |
17 using content::OpenURLParams; | 18 using content::OpenURLParams; |
18 using content::WebContents; | 19 using content::WebContents; |
19 | 20 |
20 ChromeWebContentsHandler::ChromeWebContentsHandler() { | 21 ChromeWebContentsHandler::ChromeWebContentsHandler() { |
21 } | 22 } |
22 | 23 |
23 ChromeWebContentsHandler::~ChromeWebContentsHandler() { | 24 ChromeWebContentsHandler::~ChromeWebContentsHandler() { |
24 } | 25 } |
25 | 26 |
26 // Opens a new URL inside |source|. |context| is the browser context that the | 27 // Opens a new URL inside |source|. |context| is the browser context that the |
27 // browser should be owned by. |params| contains the URL to open and various | 28 // browser should be owned by. |params| contains the URL to open and various |
28 // attributes such as disposition. On return |out_new_contents| contains the | 29 // attributes such as disposition. On return |out_new_contents| contains the |
29 // WebContents the URL is opened in. Returns the web contents opened by the | 30 // WebContents the URL is opened in. Returns the web contents opened by the |
30 // browser. | 31 // browser. |
31 WebContents* ChromeWebContentsHandler::OpenURLFromTab( | 32 WebContents* ChromeWebContentsHandler::OpenURLFromTab( |
32 content::BrowserContext* context, | 33 content::BrowserContext* context, |
33 WebContents* source, | 34 WebContents* source, |
34 const OpenURLParams& params) { | 35 const OpenURLParams& params) { |
35 if (!context) | 36 if (!context) |
36 return NULL; | 37 return NULL; |
37 | 38 |
38 Profile* profile = Profile::FromBrowserContext(context); | 39 Profile* profile = Profile::FromBrowserContext(context); |
39 Browser* browser = browser::FindTabbedBrowser(profile, false); | 40 |
| 41 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; |
| 42 if (source) { |
| 43 Browser* source_browser = browser::FindBrowserWithWebContents(source); |
| 44 if (source_browser) |
| 45 desktop_type = source_browser->host_desktop_type(); |
| 46 } |
| 47 |
| 48 Browser* browser = browser::FindTabbedBrowser(profile, false, desktop_type); |
40 const bool browser_created = !browser; | 49 const bool browser_created = !browser; |
41 if (!browser) | 50 if (!browser) |
42 browser = new Browser(Browser::CreateParams(profile)); | 51 browser = new Browser( |
| 52 Browser::CreateParams(Browser::TYPE_TABBED, profile, desktop_type)); |
43 chrome::NavigateParams nav_params(browser, params.url, params.transition); | 53 chrome::NavigateParams nav_params(browser, params.url, params.transition); |
44 nav_params.referrer = params.referrer; | 54 nav_params.referrer = params.referrer; |
45 if (source && source->IsCrashed() && | 55 if (source && source->IsCrashed() && |
46 params.disposition == CURRENT_TAB && | 56 params.disposition == CURRENT_TAB && |
47 params.transition == content::PAGE_TRANSITION_LINK) { | 57 params.transition == content::PAGE_TRANSITION_LINK) { |
48 nav_params.disposition = NEW_FOREGROUND_TAB; | 58 nav_params.disposition = NEW_FOREGROUND_TAB; |
49 } else { | 59 } else { |
50 nav_params.disposition = params.disposition; | 60 nav_params.disposition = params.disposition; |
51 } | 61 } |
52 nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW; | 62 nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
(...skipping 18 matching lines...) Expand all Loading... |
71 content::BrowserContext* context, | 81 content::BrowserContext* context, |
72 WebContents* source, | 82 WebContents* source, |
73 WebContents* new_contents, | 83 WebContents* new_contents, |
74 WindowOpenDisposition disposition, | 84 WindowOpenDisposition disposition, |
75 const gfx::Rect& initial_pos, | 85 const gfx::Rect& initial_pos, |
76 bool user_gesture) { | 86 bool user_gesture) { |
77 if (!context) | 87 if (!context) |
78 return; | 88 return; |
79 | 89 |
80 Profile* profile = Profile::FromBrowserContext(context); | 90 Profile* profile = Profile::FromBrowserContext(context); |
81 Browser* browser = browser::FindTabbedBrowser(profile, false); | 91 |
| 92 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; |
| 93 if (source) { |
| 94 Browser* source_browser = browser::FindBrowserWithWebContents(source); |
| 95 if (source_browser) |
| 96 desktop_type = source_browser->host_desktop_type(); |
| 97 } |
| 98 |
| 99 Browser* browser = browser::FindTabbedBrowser(profile, false, desktop_type); |
82 const bool browser_created = !browser; | 100 const bool browser_created = !browser; |
83 if (!browser) | 101 if (!browser) |
84 browser = new Browser(Browser::CreateParams(profile)); | 102 browser = new Browser( |
| 103 Browser::CreateParams(Browser::TYPE_TABBED, profile, desktop_type)); |
85 TabContents* tab_contents = | 104 TabContents* tab_contents = |
86 TabContents::Factory::CreateTabContents(new_contents); | 105 TabContents::Factory::CreateTabContents(new_contents); |
87 chrome::NavigateParams params(browser, tab_contents); | 106 chrome::NavigateParams params(browser, tab_contents); |
88 // TODO(pinkerton): no way to get a TabContents for this. | 107 // TODO(pinkerton): no way to get a TabContents for this. |
89 // params.source_contents = source; | 108 // params.source_contents = source; |
90 params.disposition = disposition; | 109 params.disposition = disposition; |
91 params.window_bounds = initial_pos; | 110 params.window_bounds = initial_pos; |
92 params.window_action = chrome::NavigateParams::SHOW_WINDOW; | 111 params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
93 params.user_gesture = true; | 112 params.user_gesture = true; |
94 chrome::Navigate(¶ms); | 113 chrome::Navigate(¶ms); |
95 | 114 |
96 // Close the browser if chrome::Navigate created a new one. | 115 // Close the browser if chrome::Navigate created a new one. |
97 if (browser_created && (browser != params.browser)) | 116 if (browser_created && (browser != params.browser)) |
98 browser->window()->Close(); | 117 browser->window()->Close(); |
99 } | 118 } |
OLD | NEW |