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

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

Issue 10909256: Always send the full tab object in ExtensionAction click event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: kalments Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
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/tab_helper.h" 8 #include "chrome/browser/extensions/tab_helper.h"
9 #include "chrome/browser/extensions/window_controller.h" 9 #include "chrome/browser/extensions/window_controller.h"
10 #include "chrome/browser/net/url_fixer_upper.h" 10 #include "chrome/browser/net/url_fixer_upper.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 std::string ExtensionTabUtil::GetTabStatusText(bool is_loading) { 55 std::string ExtensionTabUtil::GetTabStatusText(bool is_loading) {
56 return is_loading ? keys::kStatusValueLoading : keys::kStatusValueComplete; 56 return is_loading ? keys::kStatusValueLoading : keys::kStatusValueComplete;
57 } 57 }
58 58
59 int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) { 59 int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) {
60 return SessionID::IdForWindowContainingTab(web_contents); 60 return SessionID::IdForWindowContainingTab(web_contents);
61 } 61 }
62 62
63 DictionaryValue* ExtensionTabUtil::CreateTabValue( 63 DictionaryValue* ExtensionTabUtil::CreateTabValue(
64 const WebContents* contents, 64 const WebContents* contents,
65 TabStripModel* tab_strip,
66 int tab_index,
65 const Extension* extension) { 67 const Extension* extension) {
66 // Find the tab strip and index of this guy. 68 // Only add privacy-sensitive data if the requesting extension has the tabs
67 TabStripModel* tab_strip = NULL; 69 // permission.
68 int tab_index; 70 bool has_permission = extension && extension->HasAPIPermissionForTab(
69 if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index)) { 71 GetTabId(contents), APIPermission::kTab);
70 return ExtensionTabUtil::CreateTabValue(contents,
71 tab_strip,
72 tab_index,
73 extension);
74 }
75 72
76 // Couldn't find it. This can happen if the tab is being dragged. 73 return CreateTabValue(contents, tab_strip, tab_index,
77 return ExtensionTabUtil::CreateTabValue(contents, NULL, -1, extension); 74 has_permission ? INCLUDE_PRIVACY_SENSITIVE_FIELDS :
75 OMIT_PRIVACY_SENSITIVE_FIELDS);
78 } 76 }
79 77
80 ListValue* ExtensionTabUtil::CreateTabList( 78 ListValue* ExtensionTabUtil::CreateTabList(
81 const Browser* browser, 79 const Browser* browser,
82 const Extension* extension) { 80 const Extension* extension) {
83 ListValue* tab_list = new ListValue(); 81 ListValue* tab_list = new ListValue();
84 TabStripModel* tab_strip = browser->tab_strip_model(); 82 TabStripModel* tab_strip = browser->tab_strip_model();
85 for (int i = 0; i < tab_strip->count(); ++i) { 83 for (int i = 0; i < tab_strip->count(); ++i) {
86 tab_list->Append(CreateTabValue( 84 tab_list->Append(CreateTabValue(
87 tab_strip->GetTabContentsAt(i)->web_contents(), 85 tab_strip->GetTabContentsAt(i)->web_contents(),
88 tab_strip, 86 tab_strip,
89 i, 87 i,
90 extension)); 88 extension));
91 } 89 }
92 90
93 return tab_list; 91 return tab_list;
94 } 92 }
95 93
96 DictionaryValue* ExtensionTabUtil::CreateTabValue( 94 DictionaryValue* ExtensionTabUtil::CreateTabValue(
97 const WebContents* contents, 95 const WebContents* contents,
98 TabStripModel* tab_strip, 96 TabStripModel* tab_strip,
99 int tab_index, 97 int tab_index,
100 const Extension* extension) { 98 IncludePrivacySensitiveFields include_privacy_sensitive_fields) {
99 if (!tab_strip)
100 ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index);
101
101 DictionaryValue* result = new DictionaryValue(); 102 DictionaryValue* result = new DictionaryValue();
102 bool is_loading = contents->IsLoading(); 103 bool is_loading = contents->IsLoading();
103 result->SetInteger(keys::kIdKey, GetTabId(contents)); 104 result->SetInteger(keys::kIdKey, GetTabId(contents));
104 result->SetInteger(keys::kIndexKey, tab_index); 105 result->SetInteger(keys::kIndexKey, tab_index);
105 result->SetInteger(keys::kWindowIdKey, GetWindowIdOfTab(contents)); 106 result->SetInteger(keys::kWindowIdKey, GetWindowIdOfTab(contents));
106 result->SetString(keys::kStatusKey, GetTabStatusText(is_loading)); 107 result->SetString(keys::kStatusKey, GetTabStatusText(is_loading));
107 result->SetBoolean(keys::kActiveKey, 108 result->SetBoolean(keys::kActiveKey,
108 tab_strip && tab_index == tab_strip->active_index()); 109 tab_strip && tab_index == tab_strip->active_index());
109 result->SetBoolean(keys::kSelectedKey, 110 result->SetBoolean(keys::kSelectedKey,
110 tab_strip && tab_index == tab_strip->active_index()); 111 tab_strip && tab_index == tab_strip->active_index());
111 result->SetBoolean(keys::kHighlightedKey, 112 result->SetBoolean(keys::kHighlightedKey,
112 tab_strip && tab_strip->IsTabSelected(tab_index)); 113 tab_strip && tab_strip->IsTabSelected(tab_index));
113 result->SetBoolean(keys::kPinnedKey, 114 result->SetBoolean(keys::kPinnedKey,
114 tab_strip && tab_strip->IsTabPinned(tab_index)); 115 tab_strip && tab_strip->IsTabPinned(tab_index));
115 result->SetBoolean(keys::kIncognitoKey, 116 result->SetBoolean(keys::kIncognitoKey,
116 contents->GetBrowserContext()->IsOffTheRecord()); 117 contents->GetBrowserContext()->IsOffTheRecord());
117 118
118 // Only add privacy-sensitive data if the requesting extension has the tabs 119 if (include_privacy_sensitive_fields == INCLUDE_PRIVACY_SENSITIVE_FIELDS) {
119 // permission.
120 bool has_permission = false;
121 if (extension) {
122 if (tab_index >= 0) {
123 has_permission =
124 extension->HasAPIPermissionForTab(
125 tab_index, APIPermission::kTab) ||
126 extension->HasAPIPermissionForTab(
127 tab_index, APIPermission::kWebNavigation);
128 } else {
129 has_permission =
130 extension->HasAPIPermission(APIPermission::kTab) ||
131 extension->HasAPIPermission(APIPermission::kWebNavigation);
132 }
133 }
134
135 if (has_permission) {
136 result->SetString(keys::kUrlKey, contents->GetURL().spec()); 120 result->SetString(keys::kUrlKey, contents->GetURL().spec());
137 result->SetString(keys::kTitleKey, contents->GetTitle()); 121 result->SetString(keys::kTitleKey, contents->GetTitle());
138 if (!is_loading) { 122 if (!is_loading) {
139 NavigationEntry* entry = contents->GetController().GetActiveEntry(); 123 NavigationEntry* entry = contents->GetController().GetActiveEntry();
140 if (entry && entry->GetFavicon().valid) 124 if (entry && entry->GetFavicon().valid)
141 result->SetString(keys::kFaviconUrlKey, entry->GetFavicon().url.spec()); 125 result->SetString(keys::kFaviconUrlKey, entry->GetFavicon().url.spec());
142 } 126 }
143 } 127 }
144 128
145 if (tab_strip) { 129 if (tab_strip) {
146 content::NavigationController* opener = 130 content::NavigationController* opener =
147 tab_strip->GetOpenerOfTabContentsAt(tab_index); 131 tab_strip->GetOpenerOfTabContentsAt(tab_index);
148 if (opener) { 132 if (opener) {
149 result->SetInteger(keys::kOpenerTabIdKey, 133 result->SetInteger(keys::kOpenerTabIdKey,
150 GetTabId(opener->GetWebContents())); 134 GetTabId(opener->GetWebContents()));
151 } 135 }
152 } 136 }
153 137
154 return result; 138 return result;
155 } 139 }
156 140
157 DictionaryValue* ExtensionTabUtil::CreateTabValueActive(
158 const WebContents* contents,
159 bool active,
160 const extensions::Extension* extension) {
161 DictionaryValue* result = CreateTabValue(contents, extension);
162 result->SetBoolean(keys::kSelectedKey, active);
163 return result;
164 }
165
166 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents, 141 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents,
167 TabStripModel** tab_strip_model, 142 TabStripModel** tab_strip_model,
168 int* tab_index) { 143 int* tab_index) {
169 DCHECK(web_contents); 144 DCHECK(web_contents);
170 DCHECK(tab_strip_model); 145 DCHECK(tab_strip_model);
171 DCHECK(tab_index); 146 DCHECK(tab_index);
172 147
173 for (BrowserList::const_iterator it = BrowserList::begin(); 148 for (BrowserList::const_iterator it = BrowserList::begin();
174 it != BrowserList::end(); ++it) { 149 it != BrowserList::end(); ++it) {
175 TabStripModel* tab_strip = (*it)->tab_strip_model(); 150 TabStripModel* tab_strip = (*it)->tab_strip_model();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 271
297 // static 272 // static
298 extensions::WindowController* ExtensionTabUtil::GetWindowControllerOfTab( 273 extensions::WindowController* ExtensionTabUtil::GetWindowControllerOfTab(
299 const WebContents* web_contents) { 274 const WebContents* web_contents) {
300 Browser* browser = browser::FindBrowserWithWebContents(web_contents); 275 Browser* browser = browser::FindBrowserWithWebContents(web_contents);
301 if (browser != NULL) 276 if (browser != NULL)
302 return browser->extension_window_controller(); 277 return browser->extension_window_controller();
303 278
304 return NULL; 279 return NULL;
305 } 280 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_tab_util.h ('k') | chrome/browser/extensions/extension_tab_util_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698