| 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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 | 326 |
| 327 int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) { | 327 int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) { |
| 328 return SessionTabHelper::IdForWindowContainingTab(web_contents); | 328 return SessionTabHelper::IdForWindowContainingTab(web_contents); |
| 329 } | 329 } |
| 330 | 330 |
| 331 // static | 331 // static |
| 332 std::unique_ptr<api::tabs::Tab> ExtensionTabUtil::CreateTabObject( | 332 std::unique_ptr<api::tabs::Tab> ExtensionTabUtil::CreateTabObject( |
| 333 WebContents* contents, | 333 WebContents* contents, |
| 334 TabStripModel* tab_strip, | 334 TabStripModel* tab_strip, |
| 335 int tab_index, | 335 int tab_index, |
| 336 const Extension* extension) { | 336 const Extension* extension, |
| 337 UrlType url_type) { |
| 337 // If we have a matching AppWindow with a controller, get the tab value | 338 // If we have a matching AppWindow with a controller, get the tab value |
| 338 // from its controller instead. | 339 // from its controller instead. |
| 339 WindowController* controller = GetAppWindowController(contents); | 340 WindowController* controller = GetAppWindowController(contents); |
| 340 if (controller && | 341 if (controller && |
| 341 (!extension || controller->IsVisibleToExtension(extension))) { | 342 (!extension || controller->IsVisibleToExtension(extension))) { |
| 342 return controller->CreateTabObject(extension, tab_index); | 343 return controller->CreateTabObject(extension, tab_index); |
| 343 } | 344 } |
| 344 std::unique_ptr<api::tabs::Tab> result = | 345 std::unique_ptr<api::tabs::Tab> result = |
| 345 CreateTabObject(contents, tab_strip, tab_index); | 346 CreateTabObject(contents, tab_strip, tab_index, url_type); |
| 346 ScrubTabForExtension(extension, contents, result.get()); | 347 ScrubTabForExtension(extension, contents, result.get()); |
| 347 return result; | 348 return result; |
| 348 } | 349 } |
| 349 | 350 |
| 350 std::unique_ptr<base::ListValue> ExtensionTabUtil::CreateTabList( | 351 std::unique_ptr<base::ListValue> ExtensionTabUtil::CreateTabList( |
| 351 const Browser* browser, | 352 const Browser* browser, |
| 352 const Extension* extension) { | 353 const Extension* extension) { |
| 353 std::unique_ptr<base::ListValue> tab_list(new base::ListValue()); | 354 std::unique_ptr<base::ListValue> tab_list(new base::ListValue()); |
| 354 TabStripModel* tab_strip = browser->tab_strip_model(); | 355 TabStripModel* tab_strip = browser->tab_strip_model(); |
| 355 for (int i = 0; i < tab_strip->count(); ++i) { | 356 for (int i = 0; i < tab_strip->count(); ++i) { |
| 356 tab_list->Append( | 357 tab_list->Append( |
| 357 CreateTabObject(tab_strip->GetWebContentsAt(i), tab_strip, i, extension) | 358 CreateTabObject(tab_strip->GetWebContentsAt(i), tab_strip, i, extension) |
| 358 ->ToValue()); | 359 ->ToValue()); |
| 359 } | 360 } |
| 360 | 361 |
| 361 return tab_list; | 362 return tab_list; |
| 362 } | 363 } |
| 363 | 364 |
| 364 // static | 365 // static |
| 365 std::unique_ptr<api::tabs::Tab> ExtensionTabUtil::CreateTabObject( | 366 std::unique_ptr<api::tabs::Tab> ExtensionTabUtil::CreateTabObject( |
| 366 content::WebContents* contents, | 367 content::WebContents* contents, |
| 367 TabStripModel* tab_strip, | 368 TabStripModel* tab_strip, |
| 368 int tab_index) { | 369 int tab_index, |
| 370 UrlType url_type) { |
| 369 // If we have a matching AppWindow with a controller, get the tab value | 371 // If we have a matching AppWindow with a controller, get the tab value |
| 370 // from its controller instead. | 372 // from its controller instead. |
| 371 WindowController* controller = GetAppWindowController(contents); | 373 WindowController* controller = GetAppWindowController(contents); |
| 372 if (controller) | 374 if (controller) |
| 373 return controller->CreateTabObject(nullptr, tab_index); | 375 return controller->CreateTabObject(nullptr, tab_index); |
| 374 | 376 |
| 375 if (!tab_strip) | 377 if (!tab_strip) |
| 376 ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index); | 378 ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index); |
| 377 bool is_loading = contents->IsLoading(); | 379 bool is_loading = contents->IsLoading(); |
| 378 std::unique_ptr<api::tabs::Tab> tab_object(new api::tabs::Tab); | 380 std::unique_ptr<api::tabs::Tab> tab_object(new api::tabs::Tab); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 389 g_browser_process->GetTabManager()->IsTabDiscarded(contents); | 391 g_browser_process->GetTabManager()->IsTabDiscarded(contents); |
| 390 tab_object->auto_discardable = | 392 tab_object->auto_discardable = |
| 391 g_browser_process->GetTabManager()->IsTabAutoDiscardable(contents); | 393 g_browser_process->GetTabManager()->IsTabAutoDiscardable(contents); |
| 392 tab_object->muted_info = CreateMutedInfo(contents); | 394 tab_object->muted_info = CreateMutedInfo(contents); |
| 393 tab_object->incognito = contents->GetBrowserContext()->IsOffTheRecord(); | 395 tab_object->incognito = contents->GetBrowserContext()->IsOffTheRecord(); |
| 394 tab_object->width.reset( | 396 tab_object->width.reset( |
| 395 new int(contents->GetContainerBounds().size().width())); | 397 new int(contents->GetContainerBounds().size().width())); |
| 396 tab_object->height.reset( | 398 tab_object->height.reset( |
| 397 new int(contents->GetContainerBounds().size().height())); | 399 new int(contents->GetContainerBounds().size().height())); |
| 398 | 400 |
| 399 tab_object->url.reset(new std::string(contents->GetURL().spec())); | 401 GURL url; |
| 402 switch (url_type) { |
| 403 case LastCommitted: |
| 404 url = contents->GetLastCommittedURL(); |
| 405 case Visible: |
| 406 url = contents->GetVisibleURL(); |
| 407 } |
| 408 tab_object->url.reset(new std::string(url.spec())); |
| 400 tab_object->title.reset( | 409 tab_object->title.reset( |
| 401 new std::string(base::UTF16ToUTF8(contents->GetTitle()))); | 410 new std::string(base::UTF16ToUTF8(contents->GetTitle()))); |
| 402 NavigationEntry* entry = contents->GetController().GetVisibleEntry(); | 411 NavigationEntry* entry = contents->GetController().GetVisibleEntry(); |
| 403 if (entry && entry->GetFavicon().valid) | 412 if (entry && entry->GetFavicon().valid) |
| 404 tab_object->fav_icon_url.reset( | 413 tab_object->fav_icon_url.reset( |
| 405 new std::string(entry->GetFavicon().url.spec())); | 414 new std::string(entry->GetFavicon().url.spec())); |
| 406 if (tab_strip) { | 415 if (tab_strip) { |
| 407 WebContents* opener = tab_strip->GetOpenerOfWebContentsAt(tab_index); | 416 WebContents* opener = tab_strip->GetOpenerOfWebContentsAt(tab_index); |
| 408 if (opener) | 417 if (opener) |
| 409 tab_object->opener_tab_id.reset(new int(GetTabIdForExtensions(opener))); | 418 tab_object->opener_tab_id.reset(new int(GetTabIdForExtensions(opener))); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 chrome::ShowSingletonTabOverwritingNTP(browser, params); | 675 chrome::ShowSingletonTabOverwritingNTP(browser, params); |
| 667 return true; | 676 return true; |
| 668 } | 677 } |
| 669 | 678 |
| 670 // static | 679 // static |
| 671 bool ExtensionTabUtil::BrowserSupportsTabs(Browser* browser) { | 680 bool ExtensionTabUtil::BrowserSupportsTabs(Browser* browser) { |
| 672 return browser && browser->tab_strip_model() && !browser->is_devtools(); | 681 return browser && browser->tab_strip_model() && !browser->is_devtools(); |
| 673 } | 682 } |
| 674 | 683 |
| 675 } // namespace extensions | 684 } // namespace extensions |
| OLD | NEW |