Chromium Code Reviews| Index: chrome/browser/extensions/extension_tab_util_athena.cc |
| diff --git a/chrome/browser/extensions/extension_tab_util_athena.cc b/chrome/browser/extensions/extension_tab_util_athena.cc |
| index cdfe7a1e0cea4db76774ae3898ed58a48d354856..2fcbb6b0d4365db70c3a6ca529a0df15363053cc 100644 |
| --- a/chrome/browser/extensions/extension_tab_util_athena.cc |
| +++ b/chrome/browser/extensions/extension_tab_util_athena.cc |
| @@ -7,14 +7,43 @@ |
| #include "base/logging.h" |
| #include "base/values.h" |
| #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| +#include "chrome/browser/extensions/window_controller.h" |
| +#include "chrome/browser/extensions/window_controller_list.h" |
| +#include "chrome/browser/sessions/session_tab_helper.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/browser_iterator.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "content/public/browser/browser_context.h" |
| +#include "content/public/browser/favicon_status.h" |
| +#include "content/public/browser/navigation_entry.h" |
| +#include "extensions/browser/app_window/app_window.h" |
| +#include "extensions/browser/app_window/app_window_registry.h" |
| #include "url/gurl.h" |
| +using content::NavigationEntry; |
| using content::WebContents; |
| namespace extensions { |
| namespace keys = tabs_constants; |
| +namespace { |
| + |
| +WindowController* GetAppWindowController(const WebContents* contents) { |
| + AppWindowRegistry* registry = |
| + AppWindowRegistry::Get(contents->GetBrowserContext()); |
| + if (!registry) |
| + return NULL; |
| + AppWindow* app_window = |
| + registry->GetAppWindowForRenderViewHost(contents->GetRenderViewHost()); |
| + if (!app_window) |
| + return NULL; |
| + return WindowControllerList::GetInstance()->FindWindowById( |
| + app_window->session_id().id()); |
| +} |
| + |
| +} // namespace |
| + |
| ExtensionTabUtil::OpenTabParams::OpenTabParams() |
| : create_browser_if_needed(false) { |
| } |
| @@ -60,18 +89,15 @@ int ExtensionTabUtil::GetWindowIdOfTabStripModel( |
| } |
| int ExtensionTabUtil::GetTabId(const WebContents* web_contents) { |
| - NOTIMPLEMENTED(); |
| - return -1; |
| + return SessionTabHelper::IdForTab(web_contents); |
| } |
| std::string ExtensionTabUtil::GetTabStatusText(bool is_loading) { |
| - NOTIMPLEMENTED(); |
| - return keys::kStatusValueComplete; |
| + return is_loading ? keys::kStatusValueLoading : keys::kStatusValueComplete; |
| } |
| int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) { |
| - NOTIMPLEMENTED(); |
| - return -1; |
| + return SessionTabHelper::IdForWindowContainingTab(web_contents); |
| } |
| base::DictionaryValue* ExtensionTabUtil::CreateTabValue( |
| @@ -79,8 +105,53 @@ base::DictionaryValue* ExtensionTabUtil::CreateTabValue( |
| TabStripModel* tab_strip, |
| int tab_index, |
| const Extension* extension) { |
| - NOTREACHED(); |
| - return NULL; |
| + // If we have a matching AppWindow with a controller, get the tab value |
| + // from its controller instead. |
| + WindowController* controller = GetAppWindowController(contents); |
|
Nikita (slow)
2014/10/27 10:56:50
I've removed impl for this method as well cause it
|
| + if (controller) |
| + return controller->CreateTabValue(NULL, tab_index); |
| + |
| + if (!tab_strip) |
| + ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index); |
| + |
| + base::DictionaryValue* result = new base::DictionaryValue(); |
| + bool is_loading = contents->IsLoading(); |
| + result->SetInteger(keys::kIdKey, GetTabId(contents)); |
| + result->SetInteger(keys::kIndexKey, tab_index); |
| + result->SetInteger(keys::kWindowIdKey, GetWindowIdOfTab(contents)); |
| + result->SetString(keys::kStatusKey, GetTabStatusText(is_loading)); |
| + result->SetBoolean(keys::kActiveKey, |
| + tab_strip && tab_index == tab_strip->active_index()); |
| + result->SetBoolean(keys::kSelectedKey, |
| + tab_strip && tab_index == tab_strip->active_index()); |
| + result->SetBoolean(keys::kHighlightedKey, |
| + tab_strip && tab_strip->IsTabSelected(tab_index)); |
| + result->SetBoolean(keys::kPinnedKey, |
| + tab_strip && tab_strip->IsTabPinned(tab_index)); |
| + result->SetBoolean(keys::kIncognitoKey, |
| + contents->GetBrowserContext()->IsOffTheRecord()); |
| + result->SetInteger(keys::kWidthKey, |
| + contents->GetContainerBounds().size().width()); |
| + result->SetInteger(keys::kHeightKey, |
| + contents->GetContainerBounds().size().height()); |
| + |
| + // Privacy-sensitive fields: these should be stripped off by |
| + // ScrubTabValueForExtension if the extension should not see them. |
| + result->SetString(keys::kUrlKey, contents->GetURL().spec()); |
| + result->SetString(keys::kTitleKey, contents->GetTitle()); |
| + if (!is_loading) { |
| + NavigationEntry* entry = contents->GetController().GetVisibleEntry(); |
| + if (entry && entry->GetFavicon().valid) |
| + result->SetString(keys::kFaviconUrlKey, entry->GetFavicon().url.spec()); |
| + } |
| + |
| + if (tab_strip) { |
| + WebContents* opener = tab_strip->GetOpenerOfWebContentsAt(tab_index); |
| + if (opener) |
| + result->SetInteger(keys::kOpenerTabIdKey, GetTabId(opener)); |
| + } |
| + |
| + return result; |
| } |
| base::ListValue* ExtensionTabUtil::CreateTabList( |
| @@ -93,8 +164,53 @@ base::DictionaryValue* ExtensionTabUtil::CreateTabValue( |
| WebContents* contents, |
| TabStripModel* tab_strip, |
| int tab_index) { |
| - NOTREACHED(); |
| - return NULL; |
| + // If we have a matching AppWindow with a controller, get the tab value |
| + // from its controller instead. |
| + WindowController* controller = GetAppWindowController(contents); |
| + if (controller) |
| + return controller->CreateTabValue(NULL, tab_index); |
| + |
| + if (!tab_strip) |
| + ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index); |
| + |
| + base::DictionaryValue* result = new base::DictionaryValue(); |
| + bool is_loading = contents->IsLoading(); |
| + result->SetInteger(keys::kIdKey, GetTabId(contents)); |
| + result->SetInteger(keys::kIndexKey, tab_index); |
| + result->SetInteger(keys::kWindowIdKey, GetWindowIdOfTab(contents)); |
| + result->SetString(keys::kStatusKey, GetTabStatusText(is_loading)); |
| + result->SetBoolean(keys::kActiveKey, |
| + tab_strip && tab_index == tab_strip->active_index()); |
| + result->SetBoolean(keys::kSelectedKey, |
| + tab_strip && tab_index == tab_strip->active_index()); |
| + result->SetBoolean(keys::kHighlightedKey, |
| + tab_strip && tab_strip->IsTabSelected(tab_index)); |
| + result->SetBoolean(keys::kPinnedKey, |
| + tab_strip && tab_strip->IsTabPinned(tab_index)); |
| + result->SetBoolean(keys::kIncognitoKey, |
| + contents->GetBrowserContext()->IsOffTheRecord()); |
| + result->SetInteger(keys::kWidthKey, |
| + contents->GetContainerBounds().size().width()); |
| + result->SetInteger(keys::kHeightKey, |
| + contents->GetContainerBounds().size().height()); |
| + |
| + // Privacy-sensitive fields: these should be stripped off by |
| + // ScrubTabValueForExtension if the extension should not see them. |
| + result->SetString(keys::kUrlKey, contents->GetURL().spec()); |
| + result->SetString(keys::kTitleKey, contents->GetTitle()); |
| + if (!is_loading) { |
| + NavigationEntry* entry = contents->GetController().GetVisibleEntry(); |
| + if (entry && entry->GetFavicon().valid) |
| + result->SetString(keys::kFaviconUrlKey, entry->GetFavicon().url.spec()); |
| + } |
| + |
| + if (tab_strip) { |
| + WebContents* opener = tab_strip->GetOpenerOfWebContentsAt(tab_index); |
| + if (opener) |
| + result->SetInteger(keys::kOpenerTabIdKey, GetTabId(opener)); |
| + } |
| + |
| + return result; |
| } |
| void ExtensionTabUtil::ScrubTabValueForExtension( |
| @@ -113,7 +229,20 @@ void ExtensionTabUtil::ScrubTabForExtension(const Extension* extension, |
| bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents, |
| TabStripModel** tab_strip_model, |
| int* tab_index) { |
| - NOTIMPLEMENTED(); |
| + DCHECK(web_contents); |
| + DCHECK(tab_strip_model); |
| + DCHECK(tab_index); |
| + |
| + for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
|
oshima
2014/10/24 14:41:26
there is no browser / tabstrip in athena. how doe
Nikita (slow)
2014/10/24 15:10:47
I need to double check, maybe this method is not n
Nikita (slow)
2014/10/27 10:56:50
This method is not really needed for a fix, remove
|
| + TabStripModel* tab_strip = it->tab_strip_model(); |
| + int index = tab_strip->GetIndexOfWebContents(web_contents); |
| + if (index != -1) { |
| + *tab_strip_model = tab_strip; |
| + *tab_index = index; |
| + return true; |
| + } |
| + } |
| + |
| return false; |
| } |
| @@ -168,7 +297,7 @@ WindowController* ExtensionTabUtil::GetWindowControllerOfTab( |
| void ExtensionTabUtil::OpenOptionsPage(const Extension* extension, |
| Browser* browser) { |
| - // NOTIMPLEMENTED(); |
| + NOTIMPLEMENTED(); |
| } |
| } // namespace extensions |