Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Side by Side Diff: chrome/browser/extensions/extension_tabs_module.cc

Issue 2111010: fix chrome.tabs.onUpdated bugs, add browsertest (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: more cr changes Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_tabs_module.h" 5 #include "chrome/browser/extensions/extension_tabs_module.h"
6 6
7 #include "base/histogram.h" 7 #include "base/histogram.h"
8 #include "base/base64.h" 8 #include "base/base64.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "chrome/browser/browser.h" 10 #include "chrome/browser/browser.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 static std::string GetWindowTypeText(Browser::Type type); 71 static std::string GetWindowTypeText(Browser::Type type);
72 72
73 int ExtensionTabUtil::GetWindowId(const Browser* browser) { 73 int ExtensionTabUtil::GetWindowId(const Browser* browser) {
74 return browser->session_id().id(); 74 return browser->session_id().id();
75 } 75 }
76 76
77 int ExtensionTabUtil::GetTabId(const TabContents* tab_contents) { 77 int ExtensionTabUtil::GetTabId(const TabContents* tab_contents) {
78 return tab_contents->controller().session_id().id(); 78 return tab_contents->controller().session_id().id();
79 } 79 }
80 80
81 ExtensionTabUtil::TabStatus ExtensionTabUtil::GetTabStatus( 81 std::string ExtensionTabUtil::GetTabStatusText(bool is_loading) {
82 const TabContents* tab_contents) { 82 return is_loading ? keys::kStatusValueLoading : keys::kStatusValueComplete;
83 return tab_contents->is_loading() ? TAB_LOADING : TAB_COMPLETE;
84 }
85
86 std::string ExtensionTabUtil::GetTabStatusText(TabStatus status) {
87 std::string text;
88 switch (status) {
89 case TAB_LOADING:
90 text = keys::kStatusValueLoading;
91 break;
92 case TAB_COMPLETE:
93 text = keys::kStatusValueComplete;
94 break;
95 }
96
97 return text;
98 } 83 }
99 84
100 int ExtensionTabUtil::GetWindowIdOfTab(const TabContents* tab_contents) { 85 int ExtensionTabUtil::GetWindowIdOfTab(const TabContents* tab_contents) {
101 return tab_contents->controller().window_id().id(); 86 return tab_contents->controller().window_id().id();
102 } 87 }
103 88
104 DictionaryValue* ExtensionTabUtil::CreateTabValue( 89 DictionaryValue* ExtensionTabUtil::CreateTabValue(
105 const TabContents* contents) { 90 const TabContents* contents) {
106 // Find the tab strip and index of this guy. 91 // Find the tab strip and index of this guy.
107 for (BrowserList::const_iterator it = BrowserList::begin(); 92 for (BrowserList::const_iterator it = BrowserList::begin();
(...skipping 15 matching lines...) Expand all
123 for (int i = 0; i < tab_strip->count(); ++i) { 108 for (int i = 0; i < tab_strip->count(); ++i) {
124 tab_list->Append(ExtensionTabUtil::CreateTabValue( 109 tab_list->Append(ExtensionTabUtil::CreateTabValue(
125 tab_strip->GetTabContentsAt(i), tab_strip, i)); 110 tab_strip->GetTabContentsAt(i), tab_strip, i));
126 } 111 }
127 112
128 return tab_list; 113 return tab_list;
129 } 114 }
130 115
131 DictionaryValue* ExtensionTabUtil::CreateTabValue( 116 DictionaryValue* ExtensionTabUtil::CreateTabValue(
132 const TabContents* contents, TabStripModel* tab_strip, int tab_index) { 117 const TabContents* contents, TabStripModel* tab_strip, int tab_index) {
133 TabStatus status = GetTabStatus(contents);
134
135 DictionaryValue* result = new DictionaryValue(); 118 DictionaryValue* result = new DictionaryValue();
136 result->SetInteger(keys::kIdKey, ExtensionTabUtil::GetTabId(contents)); 119 result->SetInteger(keys::kIdKey, ExtensionTabUtil::GetTabId(contents));
137 result->SetInteger(keys::kIndexKey, tab_index); 120 result->SetInteger(keys::kIndexKey, tab_index);
138 result->SetInteger(keys::kWindowIdKey, 121 result->SetInteger(keys::kWindowIdKey,
139 ExtensionTabUtil::GetWindowIdOfTab(contents)); 122 ExtensionTabUtil::GetWindowIdOfTab(contents));
140 result->SetString(keys::kUrlKey, contents->GetURL().spec()); 123 result->SetString(keys::kUrlKey, contents->GetURL().spec());
141 result->SetString(keys::kStatusKey, GetTabStatusText(status)); 124 result->SetString(keys::kStatusKey, GetTabStatusText(contents->is_loading()));
142 result->SetBoolean(keys::kSelectedKey, 125 result->SetBoolean(keys::kSelectedKey,
143 tab_strip && tab_index == tab_strip->selected_index()); 126 tab_strip && tab_index == tab_strip->selected_index());
144 result->SetString(keys::kTitleKey, UTF16ToWide(contents->GetTitle())); 127 result->SetString(keys::kTitleKey, UTF16ToWide(contents->GetTitle()));
145 result->SetBoolean(keys::kIncognitoKey, 128 result->SetBoolean(keys::kIncognitoKey,
146 contents->profile()->IsOffTheRecord()); 129 contents->profile()->IsOffTheRecord());
147 130
148 if (status != TAB_LOADING) { 131 if (!contents->is_loading()) {
149 NavigationEntry* entry = contents->controller().GetActiveEntry(); 132 NavigationEntry* entry = contents->controller().GetActiveEntry();
150 if (entry) { 133 if (entry) {
151 if (entry->favicon().is_valid()) 134 if (entry->favicon().is_valid())
152 result->SetString(keys::kFavIconUrlKey, entry->favicon().url().spec()); 135 result->SetString(keys::kFavIconUrlKey, entry->favicon().url().spec());
153 } 136 }
154 } 137 }
155 138
156 return result; 139 return result;
157 } 140 }
158 141
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 // caller. 1118 // caller.
1136 use_type = url.is_valid() && (url != resolved_url) ? 1119 use_type = url.is_valid() && (url != resolved_url) ?
1137 RELATIVE_URL_RESOLUTIONS_DIFFER : RELATIVE_URL_RESOLUTIONS_AGREE; 1120 RELATIVE_URL_RESOLUTIONS_DIFFER : RELATIVE_URL_RESOLUTIONS_AGREE;
1138 } 1121 }
1139 1122
1140 UMA_HISTOGRAM_ENUMERATION("Extensions.APIUse_RelativeURL", use_type, 1123 UMA_HISTOGRAM_ENUMERATION("Extensions.APIUse_RelativeURL", use_type,
1141 EXTENSION_API_RELATIVE_URL_USE_MAX_VALUE); 1124 EXTENSION_API_RELATIVE_URL_USE_MAX_VALUE);
1142 1125
1143 return url; 1126 return url;
1144 } 1127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698