| 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 "chrome/browser/extensions/api/tabs/tabs_constants.h" | 7 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 8 #include "chrome/browser/extensions/extension_tab_helper.h" | 8 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 9 #include "chrome/browser/net/url_fixer_upper.h" | 9 #include "chrome/browser/net/url_fixer_upper.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 tab_list->Append(ExtensionTabUtil::CreateTabValue( | 74 tab_list->Append(ExtensionTabUtil::CreateTabValue( |
| 75 tab_strip->GetTabContentsAt(i)->web_contents(), tab_strip, i)); | 75 tab_strip->GetTabContentsAt(i)->web_contents(), tab_strip, i)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 return tab_list; | 78 return tab_list; |
| 79 } | 79 } |
| 80 | 80 |
| 81 DictionaryValue* ExtensionTabUtil::CreateTabValue(const WebContents* contents, | 81 DictionaryValue* ExtensionTabUtil::CreateTabValue(const WebContents* contents, |
| 82 TabStripModel* tab_strip, | 82 TabStripModel* tab_strip, |
| 83 int tab_index) { | 83 int tab_index) { |
| 84 return ExtensionTabUtil::CreateTabValue(contents, tab_strip, tab_index, true); |
| 85 } |
| 86 |
| 87 DictionaryValue* ExtensionTabUtil::CreateTabValue(const WebContents* contents, |
| 88 TabStripModel* tab_strip, |
| 89 int tab_index, |
| 90 bool has_permission) { |
| 84 DictionaryValue* result = new DictionaryValue(); | 91 DictionaryValue* result = new DictionaryValue(); |
| 85 bool is_loading = contents->IsLoading(); | 92 bool is_loading = contents->IsLoading(); |
| 86 result->SetInteger(keys::kIdKey, ExtensionTabUtil::GetTabId(contents)); | 93 result->SetInteger(keys::kIdKey, ExtensionTabUtil::GetTabId(contents)); |
| 87 result->SetInteger(keys::kIndexKey, tab_index); | 94 result->SetInteger(keys::kIndexKey, tab_index); |
| 88 result->SetInteger(keys::kWindowIdKey, | 95 result->SetInteger(keys::kWindowIdKey, |
| 89 ExtensionTabUtil::GetWindowIdOfTab(contents)); | 96 ExtensionTabUtil::GetWindowIdOfTab(contents)); |
| 90 result->SetString(keys::kUrlKey, contents->GetURL().spec()); | |
| 91 result->SetString(keys::kStatusKey, GetTabStatusText(is_loading)); | 97 result->SetString(keys::kStatusKey, GetTabStatusText(is_loading)); |
| 92 result->SetBoolean(keys::kActiveKey, | 98 result->SetBoolean(keys::kActiveKey, |
| 93 tab_strip && tab_index == tab_strip->active_index()); | 99 tab_strip && tab_index == tab_strip->active_index()); |
| 94 result->SetBoolean(keys::kSelectedKey, | 100 result->SetBoolean(keys::kSelectedKey, |
| 95 tab_strip && tab_index == tab_strip->active_index()); | 101 tab_strip && tab_index == tab_strip->active_index()); |
| 96 result->SetBoolean(keys::kHighlightedKey, | 102 result->SetBoolean(keys::kHighlightedKey, |
| 97 tab_strip && tab_strip->IsTabSelected(tab_index)); | 103 tab_strip && tab_strip->IsTabSelected(tab_index)); |
| 98 result->SetBoolean(keys::kPinnedKey, | 104 result->SetBoolean(keys::kPinnedKey, |
| 99 tab_strip && tab_strip->IsTabPinned(tab_index)); | 105 tab_strip && tab_strip->IsTabPinned(tab_index)); |
| 100 result->SetString(keys::kTitleKey, contents->GetTitle()); | |
| 101 result->SetBoolean(keys::kIncognitoKey, | 106 result->SetBoolean(keys::kIncognitoKey, |
| 102 contents->GetBrowserContext()->IsOffTheRecord()); | 107 contents->GetBrowserContext()->IsOffTheRecord()); |
| 103 | 108 |
| 104 if (tab_strip) { | 109 if (tab_strip) { |
| 105 content::NavigationController* opener = | 110 content::NavigationController* opener = |
| 106 tab_strip->GetOpenerOfTabContentsAt(tab_index); | 111 tab_strip->GetOpenerOfTabContentsAt(tab_index); |
| 107 if (opener) { | 112 if (opener) { |
| 108 result->SetInteger(keys::kOpenerTabIdKey, | 113 result->SetInteger(keys::kOpenerTabIdKey, |
| 109 ExtensionTabUtil::GetTabId(opener->GetWebContents())); | 114 ExtensionTabUtil::GetTabId(opener->GetWebContents())); |
| 110 } | 115 } |
| 111 } | 116 } |
| 112 | 117 if (has_permission) { |
| 113 if (!is_loading) { | 118 result->SetString(keys::kUrlKey, contents->GetURL().spec()); |
| 114 NavigationEntry* entry = contents->GetController().GetActiveEntry(); | 119 result->SetString(keys::kTitleKey, contents->GetTitle()); |
| 115 if (entry) { | 120 if (!is_loading) { |
| 116 if (entry->GetFavicon().valid) | 121 NavigationEntry* entry = contents->GetController().GetActiveEntry(); |
| 117 result->SetString(keys::kFaviconUrlKey, entry->GetFavicon().url.spec()); | 122 if (entry) { |
| 123 if (entry->GetFavicon().valid) |
| 124 result->SetString(keys::kFaviconUrlKey, |
| 125 entry->GetFavicon().url.spec()); |
| 126 } |
| 118 } | 127 } |
| 119 } | 128 } |
| 120 | 129 |
| 121 return result; | 130 return result; |
| 122 } | 131 } |
| 123 | 132 |
| 124 DictionaryValue* ExtensionTabUtil::CreateTabValueActive( | 133 DictionaryValue* ExtensionTabUtil::CreateTabValueActive( |
| 125 const WebContents* contents, | 134 const WebContents* contents, |
| 126 bool active) { | 135 bool active) { |
| 127 DictionaryValue* result = ExtensionTabUtil::CreateTabValue(contents); | 136 DictionaryValue* result = ExtensionTabUtil::CreateTabValue(contents); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 } | 221 } |
| 213 | 222 |
| 214 bool ExtensionTabUtil::IsCrashURL(const GURL& url) { | 223 bool ExtensionTabUtil::IsCrashURL(const GURL& url) { |
| 215 // Check a fixed-up URL, to normalize the scheme and parse hosts correctly. | 224 // Check a fixed-up URL, to normalize the scheme and parse hosts correctly. |
| 216 GURL fixed_url = | 225 GURL fixed_url = |
| 217 URLFixerUpper::FixupURL(url.possibly_invalid_spec(), std::string()); | 226 URLFixerUpper::FixupURL(url.possibly_invalid_spec(), std::string()); |
| 218 return (fixed_url.SchemeIs(chrome::kChromeUIScheme) && | 227 return (fixed_url.SchemeIs(chrome::kChromeUIScheme) && |
| 219 (fixed_url.host() == chrome::kChromeUIBrowserCrashHost || | 228 (fixed_url.host() == chrome::kChromeUIBrowserCrashHost || |
| 220 fixed_url.host() == chrome::kChromeUICrashHost)); | 229 fixed_url.host() == chrome::kChromeUICrashHost)); |
| 221 } | 230 } |
| OLD | NEW |