| 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 "apps/app_window.h" | 7 #include "apps/app_window.h" |
| 8 #include "apps/app_window_registry.h" | 8 #include "apps/app_window_registry.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 if (error_message) | 83 if (error_message) |
| 84 *error_message = ErrorUtils::FormatErrorMessage( | 84 *error_message = ErrorUtils::FormatErrorMessage( |
| 85 keys::kWindowNotFoundError, base::IntToString(window_id)); | 85 keys::kWindowNotFoundError, base::IntToString(window_id)); |
| 86 | 86 |
| 87 return NULL; | 87 return NULL; |
| 88 } | 88 } |
| 89 | 89 |
| 90 Browser* CreateBrowser(ChromeAsyncExtensionFunction* function, | 90 Browser* CreateBrowser(ChromeUIThreadExtensionFunction* function, |
| 91 int window_id, | 91 int window_id, |
| 92 std::string* error) { | 92 std::string* error) { |
| 93 content::WebContents* web_contents = function->GetAssociatedWebContents(); | 93 content::WebContents* web_contents = function->GetAssociatedWebContents(); |
| 94 DCHECK(web_contents); | 94 DCHECK(web_contents); |
| 95 DCHECK(web_contents->GetView()); | 95 DCHECK(web_contents->GetView()); |
| 96 DCHECK(web_contents->GetView()->GetNativeView()); | 96 DCHECK(web_contents->GetView()->GetNativeView()); |
| 97 DCHECK(!chrome::FindBrowserWithWebContents(web_contents)); | 97 DCHECK(!chrome::FindBrowserWithWebContents(web_contents)); |
| 98 | 98 |
| 99 chrome::HostDesktopType desktop_type = | 99 chrome::HostDesktopType desktop_type = |
| 100 chrome::GetHostDesktopTypeForNativeView( | 100 chrome::GetHostDesktopTypeForNativeView( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 111 ExtensionTabUtil::OpenTabParams::OpenTabParams() | 111 ExtensionTabUtil::OpenTabParams::OpenTabParams() |
| 112 : create_browser_if_needed(false) { | 112 : create_browser_if_needed(false) { |
| 113 } | 113 } |
| 114 | 114 |
| 115 ExtensionTabUtil::OpenTabParams::~OpenTabParams() { | 115 ExtensionTabUtil::OpenTabParams::~OpenTabParams() { |
| 116 } | 116 } |
| 117 | 117 |
| 118 // Opens a new tab for a given extension. Returns NULL and sets |error| if an | 118 // Opens a new tab for a given extension. Returns NULL and sets |error| if an |
| 119 // error occurs. | 119 // error occurs. |
| 120 base::DictionaryValue* ExtensionTabUtil::OpenTab( | 120 base::DictionaryValue* ExtensionTabUtil::OpenTab( |
| 121 ChromeAsyncExtensionFunction* function, | 121 ChromeUIThreadExtensionFunction* function, |
| 122 const OpenTabParams& params, | 122 const OpenTabParams& params, |
| 123 std::string* error) { | 123 std::string* error) { |
| 124 // windowId defaults to "current" window. | 124 // windowId defaults to "current" window. |
| 125 int window_id = extension_misc::kCurrentWindowId; | 125 int window_id = extension_misc::kCurrentWindowId; |
| 126 if (params.window_id.get()) | 126 if (params.window_id.get()) |
| 127 window_id = *params.window_id; | 127 window_id = *params.window_id; |
| 128 | 128 |
| 129 Browser* browser = GetBrowserFromWindowID(function, window_id, error); | 129 Browser* browser = GetBrowserFromWindowID(function, window_id, error); |
| 130 if (!browser) { | 130 if (!browser) { |
| 131 if (!params.create_browser_if_needed) { | 131 if (!params.create_browser_if_needed) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 navigate_params.target_contents->GetView()->SetInitialFocus(); | 250 navigate_params.target_contents->GetView()->SetInitialFocus(); |
| 251 | 251 |
| 252 // Return data about the newly created tab. | 252 // Return data about the newly created tab. |
| 253 return ExtensionTabUtil::CreateTabValue(navigate_params.target_contents, | 253 return ExtensionTabUtil::CreateTabValue(navigate_params.target_contents, |
| 254 tab_strip, | 254 tab_strip, |
| 255 new_index, | 255 new_index, |
| 256 function->GetExtension()); | 256 function->GetExtension()); |
| 257 } | 257 } |
| 258 | 258 |
| 259 Browser* ExtensionTabUtil::GetBrowserFromWindowID( | 259 Browser* ExtensionTabUtil::GetBrowserFromWindowID( |
| 260 ChromeAsyncExtensionFunction* function, | 260 ChromeUIThreadExtensionFunction* function, |
| 261 int window_id, | 261 int window_id, |
| 262 std::string* error) { | 262 std::string* error) { |
| 263 if (window_id == extension_misc::kCurrentWindowId) { | 263 if (window_id == extension_misc::kCurrentWindowId) { |
| 264 Browser* result = function->GetCurrentBrowser(); | 264 Browser* result = function->GetCurrentBrowser(); |
| 265 if (!result || !result->window()) { | 265 if (!result || !result->window()) { |
| 266 if (error) | 266 if (error) |
| 267 *error = keys::kNoCurrentWindowError; | 267 *error = keys::kNoCurrentWindowError; |
| 268 return NULL; | 268 return NULL; |
| 269 } | 269 } |
| 270 return result; | 270 return result; |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 content::PAGE_TRANSITION_LINK, | 573 content::PAGE_TRANSITION_LINK, |
| 574 false); | 574 false); |
| 575 browser->OpenURL(params); | 575 browser->OpenURL(params); |
| 576 browser->window()->Show(); | 576 browser->window()->Show(); |
| 577 WebContents* web_contents = | 577 WebContents* web_contents = |
| 578 browser->tab_strip_model()->GetActiveWebContents(); | 578 browser->tab_strip_model()->GetActiveWebContents(); |
| 579 web_contents->GetDelegate()->ActivateContents(web_contents); | 579 web_contents->GetDelegate()->ActivateContents(web_contents); |
| 580 } | 580 } |
| 581 | 581 |
| 582 } // namespace extensions | 582 } // namespace extensions |
| OLD | NEW |