| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 if (error_message) | 88 if (error_message) |
| 89 *error_message = ErrorUtils::FormatErrorMessage( | 89 *error_message = ErrorUtils::FormatErrorMessage( |
| 90 keys::kWindowNotFoundError, base::IntToString(window_id)); | 90 keys::kWindowNotFoundError, base::IntToString(window_id)); |
| 91 | 91 |
| 92 return NULL; | 92 return NULL; |
| 93 } | 93 } |
| 94 | 94 |
| 95 Browser* CreateBrowser(ChromeUIThreadExtensionFunction* function, | 95 Browser* CreateBrowser(ChromeUIThreadExtensionFunction* function, |
| 96 int window_id, | 96 int window_id, |
| 97 std::string* error) { | 97 std::string* error) { |
| 98 content::WebContents* web_contents = function->GetAssociatedWebContents(); | 98 Browser::CreateParams params(Browser::TYPE_TABBED, function->GetProfile()); |
| 99 chrome::HostDesktopType desktop_type = | |
| 100 web_contents && web_contents->GetNativeView() | |
| 101 ? chrome::GetHostDesktopTypeForNativeView( | |
| 102 web_contents->GetNativeView()) | |
| 103 : chrome::GetHostDesktopTypeForNativeView(NULL); | |
| 104 Browser::CreateParams params( | |
| 105 Browser::TYPE_TABBED, function->GetProfile(), desktop_type); | |
| 106 Browser* browser = new Browser(params); | 99 Browser* browser = new Browser(params); |
| 107 browser->window()->Show(); | 100 browser->window()->Show(); |
| 108 return browser; | 101 return browser; |
| 109 } | 102 } |
| 110 | 103 |
| 111 // Use this function for reporting a tab id to an extension. It will | 104 // Use this function for reporting a tab id to an extension. It will |
| 112 // take care of setting the id to TAB_ID_NONE if necessary (for | 105 // take care of setting the id to TAB_ID_NONE if necessary (for |
| 113 // example with devtools). | 106 // example with devtools). |
| 114 int GetTabIdForExtensions(const WebContents* web_contents) { | 107 int GetTabIdForExtensions(const WebContents* web_contents) { |
| 115 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 108 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 bool pinned = false; | 207 bool pinned = false; |
| 215 if (params.pinned.get()) | 208 if (params.pinned.get()) |
| 216 pinned = *params.pinned; | 209 pinned = *params.pinned; |
| 217 | 210 |
| 218 // We can't load extension URLs into incognito windows unless the extension | 211 // We can't load extension URLs into incognito windows unless the extension |
| 219 // uses split mode. Special case to fall back to a tabbed window. | 212 // uses split mode. Special case to fall back to a tabbed window. |
| 220 if (url.SchemeIs(kExtensionScheme) && | 213 if (url.SchemeIs(kExtensionScheme) && |
| 221 !IncognitoInfo::IsSplitMode(function->extension()) && | 214 !IncognitoInfo::IsSplitMode(function->extension()) && |
| 222 browser->profile()->IsOffTheRecord()) { | 215 browser->profile()->IsOffTheRecord()) { |
| 223 Profile* profile = browser->profile()->GetOriginalProfile(); | 216 Profile* profile = browser->profile()->GetOriginalProfile(); |
| 224 chrome::HostDesktopType desktop_type = browser->host_desktop_type(); | |
| 225 | 217 |
| 226 browser = chrome::FindTabbedBrowser(profile, false); | 218 browser = chrome::FindTabbedBrowser(profile, false); |
| 227 if (!browser) { | 219 if (!browser) { |
| 228 browser = new Browser( | 220 browser = |
| 229 Browser::CreateParams(Browser::TYPE_TABBED, profile, desktop_type)); | 221 new Browser(Browser::CreateParams(Browser::TYPE_TABBED, profile)); |
| 230 browser->window()->Show(); | 222 browser->window()->Show(); |
| 231 } | 223 } |
| 232 } | 224 } |
| 233 | 225 |
| 234 // If index is specified, honor the value, but keep it bound to | 226 // If index is specified, honor the value, but keep it bound to |
| 235 // -1 <= index <= tab_strip->count() where -1 invokes the default behavior. | 227 // -1 <= index <= tab_strip->count() where -1 invokes the default behavior. |
| 236 int index = -1; | 228 int index = -1; |
| 237 if (params.index.get()) | 229 if (params.index.get()) |
| 238 index = *params.index; | 230 index = *params.index; |
| 239 | 231 |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 return false; | 577 return false; |
| 586 } | 578 } |
| 587 | 579 |
| 588 void ExtensionTabUtil::CreateTab(WebContents* web_contents, | 580 void ExtensionTabUtil::CreateTab(WebContents* web_contents, |
| 589 const std::string& extension_id, | 581 const std::string& extension_id, |
| 590 WindowOpenDisposition disposition, | 582 WindowOpenDisposition disposition, |
| 591 const gfx::Rect& initial_rect, | 583 const gfx::Rect& initial_rect, |
| 592 bool user_gesture) { | 584 bool user_gesture) { |
| 593 Profile* profile = | 585 Profile* profile = |
| 594 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 586 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 595 chrome::HostDesktopType active_desktop = chrome::GetActiveDesktop(); | |
| 596 Browser* browser = chrome::FindTabbedBrowser(profile, false); | 587 Browser* browser = chrome::FindTabbedBrowser(profile, false); |
| 597 const bool browser_created = !browser; | 588 const bool browser_created = !browser; |
| 598 if (!browser) | 589 if (!browser) |
| 599 browser = new Browser(Browser::CreateParams(profile, active_desktop)); | 590 browser = new Browser(Browser::CreateParams(profile)); |
| 600 chrome::NavigateParams params(browser, web_contents); | 591 chrome::NavigateParams params(browser, web_contents); |
| 601 | 592 |
| 602 // The extension_app_id parameter ends up as app_name in the Browser | 593 // The extension_app_id parameter ends up as app_name in the Browser |
| 603 // which causes the Browser to return true for is_app(). This affects | 594 // which causes the Browser to return true for is_app(). This affects |
| 604 // among other things, whether the location bar gets displayed. | 595 // among other things, whether the location bar gets displayed. |
| 605 // TODO(mpcomplete): This seems wrong. What if the extension content is hosted | 596 // TODO(mpcomplete): This seems wrong. What if the extension content is hosted |
| 606 // in a tab? | 597 // in a tab? |
| 607 if (disposition == NEW_POPUP) | 598 if (disposition == NEW_POPUP) |
| 608 params.extension_app_id = extension_id; | 599 params.extension_app_id = extension_id; |
| 609 | 600 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 638 bool ExtensionTabUtil::OpenOptionsPage(const Extension* extension, | 629 bool ExtensionTabUtil::OpenOptionsPage(const Extension* extension, |
| 639 Browser* browser) { | 630 Browser* browser) { |
| 640 if (!OptionsPageInfo::HasOptionsPage(extension)) | 631 if (!OptionsPageInfo::HasOptionsPage(extension)) |
| 641 return false; | 632 return false; |
| 642 | 633 |
| 643 // Force the options page to open in non-OTR window, because it won't be | 634 // Force the options page to open in non-OTR window, because it won't be |
| 644 // able to save settings from OTR. | 635 // able to save settings from OTR. |
| 645 scoped_ptr<chrome::ScopedTabbedBrowserDisplayer> displayer; | 636 scoped_ptr<chrome::ScopedTabbedBrowserDisplayer> displayer; |
| 646 if (browser->profile()->IsOffTheRecord()) { | 637 if (browser->profile()->IsOffTheRecord()) { |
| 647 displayer.reset(new chrome::ScopedTabbedBrowserDisplayer( | 638 displayer.reset(new chrome::ScopedTabbedBrowserDisplayer( |
| 648 browser->profile()->GetOriginalProfile(), | 639 browser->profile()->GetOriginalProfile())); |
| 649 browser->host_desktop_type())); | |
| 650 browser = displayer->browser(); | 640 browser = displayer->browser(); |
| 651 } | 641 } |
| 652 | 642 |
| 653 GURL url_to_navigate; | 643 GURL url_to_navigate; |
| 654 if (OptionsPageInfo::ShouldOpenInTab(extension)) { | 644 if (OptionsPageInfo::ShouldOpenInTab(extension)) { |
| 655 // Options page tab is simply e.g. chrome-extension://.../options.html. | 645 // Options page tab is simply e.g. chrome-extension://.../options.html. |
| 656 url_to_navigate = OptionsPageInfo::GetOptionsPage(extension); | 646 url_to_navigate = OptionsPageInfo::GetOptionsPage(extension); |
| 657 } else { | 647 } else { |
| 658 // Options page tab is Extension settings pointed at that Extension's ID, | 648 // Options page tab is Extension settings pointed at that Extension's ID, |
| 659 // e.g. chrome://extensions?options=... | 649 // e.g. chrome://extensions?options=... |
| (...skipping 12 matching lines...) Expand all Loading... |
| 672 chrome::ShowSingletonTabOverwritingNTP(browser, params); | 662 chrome::ShowSingletonTabOverwritingNTP(browser, params); |
| 673 return true; | 663 return true; |
| 674 } | 664 } |
| 675 | 665 |
| 676 // static | 666 // static |
| 677 bool ExtensionTabUtil::BrowserSupportsTabs(Browser* browser) { | 667 bool ExtensionTabUtil::BrowserSupportsTabs(Browser* browser) { |
| 678 return browser && browser->tab_strip_model() && !browser->is_devtools(); | 668 return browser && browser->tab_strip_model() && !browser->is_devtools(); |
| 679 } | 669 } |
| 680 | 670 |
| 681 } // namespace extensions | 671 } // namespace extensions |
| OLD | NEW |