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/extensions/extension_tab_util.h" | 5 #include "chrome/browser/extensions/extension_tab_util.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 9 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
10 #include "chrome/browser/extensions/chrome_extension_function.h" | 10 #include "chrome/browser/extensions/chrome_extension_function.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 return NULL; | 164 return NULL; |
165 } | 165 } |
166 } | 166 } |
167 | 167 |
168 // TODO(rafaelw): handle setting remaining tab properties: | 168 // TODO(rafaelw): handle setting remaining tab properties: |
169 // -title | 169 // -title |
170 // -favIconUrl | 170 // -favIconUrl |
171 | 171 |
172 GURL url; | 172 GURL url; |
173 if (params.url.get()) { | 173 if (params.url.get()) { |
174 std::string url_string= *params.url; | 174 std::string url_string = *params.url; |
175 url = ExtensionTabUtil::ResolvePossiblyRelativeURL(url_string, | 175 url = ExtensionTabUtil::ResolvePossiblyRelativeURL(url_string, |
176 function->extension()); | 176 function->extension()); |
177 if (!url.is_valid()) { | 177 if (!url.is_valid()) { |
178 *error = | 178 *error = |
179 ErrorUtils::FormatErrorMessage(keys::kInvalidUrlError, url_string); | 179 ErrorUtils::FormatErrorMessage(keys::kInvalidUrlError, url_string); |
180 return NULL; | 180 return NULL; |
181 } | 181 } |
182 } else { | 182 } else { |
183 url = GURL(chrome::kChromeUINewTabURL); | 183 url = GURL(chrome::kChromeUINewTabURL); |
184 } | 184 } |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 GURL fixed_url = | 521 GURL fixed_url = |
522 url_fixer::FixupURL(url.possibly_invalid_spec(), std::string()); | 522 url_fixer::FixupURL(url.possibly_invalid_spec(), std::string()); |
523 return (fixed_url.SchemeIs(content::kChromeUIScheme) && | 523 return (fixed_url.SchemeIs(content::kChromeUIScheme) && |
524 (fixed_url.host() == content::kChromeUIBrowserCrashHost || | 524 (fixed_url.host() == content::kChromeUIBrowserCrashHost || |
525 fixed_url.host() == chrome::kChromeUICrashHost)); | 525 fixed_url.host() == chrome::kChromeUICrashHost)); |
526 } | 526 } |
527 | 527 |
528 void ExtensionTabUtil::CreateTab(WebContents* web_contents, | 528 void ExtensionTabUtil::CreateTab(WebContents* web_contents, |
529 const std::string& extension_id, | 529 const std::string& extension_id, |
530 WindowOpenDisposition disposition, | 530 WindowOpenDisposition disposition, |
531 const gfx::Rect& initial_pos, | 531 const gfx::Rect& initial_rect, |
532 bool user_gesture) { | 532 bool user_gesture) { |
533 Profile* profile = | 533 Profile* profile = |
534 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 534 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
535 chrome::HostDesktopType active_desktop = chrome::GetActiveDesktop(); | 535 chrome::HostDesktopType active_desktop = chrome::GetActiveDesktop(); |
536 Browser* browser = chrome::FindTabbedBrowser(profile, false, active_desktop); | 536 Browser* browser = chrome::FindTabbedBrowser(profile, false, active_desktop); |
537 const bool browser_created = !browser; | 537 const bool browser_created = !browser; |
538 if (!browser) | 538 if (!browser) |
539 browser = new Browser(Browser::CreateParams(profile, active_desktop)); | 539 browser = new Browser(Browser::CreateParams(profile, active_desktop)); |
540 chrome::NavigateParams params(browser, web_contents); | 540 chrome::NavigateParams params(browser, web_contents); |
541 | 541 |
542 // The extension_app_id parameter ends up as app_name in the Browser | 542 // The extension_app_id parameter ends up as app_name in the Browser |
543 // which causes the Browser to return true for is_app(). This affects | 543 // which causes the Browser to return true for is_app(). This affects |
544 // among other things, whether the location bar gets displayed. | 544 // among other things, whether the location bar gets displayed. |
545 // TODO(mpcomplete): This seems wrong. What if the extension content is hosted | 545 // TODO(mpcomplete): This seems wrong. What if the extension content is hosted |
546 // in a tab? | 546 // in a tab? |
547 if (disposition == NEW_POPUP) | 547 if (disposition == NEW_POPUP) |
548 params.extension_app_id = extension_id; | 548 params.extension_app_id = extension_id; |
549 | 549 |
550 params.disposition = disposition; | 550 params.disposition = disposition; |
551 params.window_bounds = initial_pos; | 551 params.window_bounds = initial_rect; |
552 params.window_action = chrome::NavigateParams::SHOW_WINDOW; | 552 params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
553 params.user_gesture = user_gesture; | 553 params.user_gesture = user_gesture; |
554 chrome::Navigate(¶ms); | 554 chrome::Navigate(¶ms); |
555 | 555 |
556 // Close the browser if chrome::Navigate created a new one. | 556 // Close the browser if chrome::Navigate created a new one. |
557 if (browser_created && (browser != params.browser)) | 557 if (browser_created && (browser != params.browser)) |
558 browser->window()->Close(); | 558 browser->window()->Close(); |
559 } | 559 } |
560 | 560 |
561 // static | 561 // static |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 false); | 613 false); |
614 browser->OpenURL(params); | 614 browser->OpenURL(params); |
615 browser->window()->Show(); | 615 browser->window()->Show(); |
616 WebContents* web_contents = | 616 WebContents* web_contents = |
617 browser->tab_strip_model()->GetActiveWebContents(); | 617 browser->tab_strip_model()->GetActiveWebContents(); |
618 web_contents->GetDelegate()->ActivateContents(web_contents); | 618 web_contents->GetDelegate()->ActivateContents(web_contents); |
619 } | 619 } |
620 } | 620 } |
621 | 621 |
622 } // namespace extensions | 622 } // namespace extensions |
OLD | NEW |