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/api/tabs/tabs.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1184 Browser* browser = GetCurrentBrowser(); | 1184 Browser* browser = GetCurrentBrowser(); |
1185 if (!browser) { | 1185 if (!browser) { |
1186 error_ = keys::kNoCurrentWindowError; | 1186 error_ = keys::kNoCurrentWindowError; |
1187 return false; | 1187 return false; |
1188 } | 1188 } |
1189 contents = browser->tab_strip_model()->GetActiveTabContents(); | 1189 contents = browser->tab_strip_model()->GetActiveTabContents(); |
1190 if (!contents) { | 1190 if (!contents) { |
1191 error_ = keys::kNoSelectedTabError; | 1191 error_ = keys::kNoSelectedTabError; |
1192 return false; | 1192 return false; |
1193 } | 1193 } |
1194 tab_id = ExtensionTabUtil::GetTabId(contents->web_contents()); | 1194 tab_id = contents->extension_tab_helper()->tab_id(); |
1195 } else { | 1195 } else { |
1196 EXTENSION_FUNCTION_VALIDATE(tab_value->GetAsInteger(&tab_id)); | 1196 EXTENSION_FUNCTION_VALIDATE(tab_value->GetAsInteger(&tab_id)); |
1197 } | 1197 } |
1198 | 1198 |
1199 int tab_index = -1; | 1199 int tab_index = -1; |
1200 TabStripModel* tab_strip = NULL; | 1200 TabStripModel* tab_strip = NULL; |
1201 if (!GetTabById(tab_id, profile(), include_incognito(), | 1201 if (!GetTabById(tab_id, profile(), include_incognito(), |
1202 NULL, &tab_strip, &contents, &tab_index, &error_)) { | 1202 NULL, &tab_strip, &contents, &tab_index, &error_)) { |
1203 return false; | 1203 return false; |
1204 } | 1204 } |
1205 | 1205 |
1206 tab_contents_ = contents; | 1206 tab_contents_ = contents; |
1207 | 1207 |
1208 // TODO(rafaelw): handle setting remaining tab properties: | 1208 // TODO(rafaelw): handle setting remaining tab properties: |
1209 // -title | 1209 // -title |
1210 // -favIconUrl | 1210 // -favIconUrl |
1211 | 1211 |
1212 // Navigate the tab to a new location if the url is different. | 1212 // Navigate the tab to a new location if the url is different. |
1213 bool is_async = false; | 1213 bool is_async = false; |
1214 if (!UpdateURLIfPresent(update_props, &is_async)) | 1214 if (!UpdateURLIfPresent(update_props, tab_id, &is_async)) |
1215 return false; | 1215 return false; |
1216 | 1216 |
1217 bool active = false; | 1217 bool active = false; |
1218 // TODO(rafaelw): Setting |active| from js doesn't make much sense. | 1218 // TODO(rafaelw): Setting |active| from js doesn't make much sense. |
1219 // Move tab selection management up to window. | 1219 // Move tab selection management up to window. |
1220 if (update_props->HasKey(keys::kSelectedKey)) | 1220 if (update_props->HasKey(keys::kSelectedKey)) |
1221 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( | 1221 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( |
1222 keys::kSelectedKey, &active)); | 1222 keys::kSelectedKey, &active)); |
1223 | 1223 |
1224 // The 'active' property has replaced 'selected'. | 1224 // The 'active' property has replaced 'selected'. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1268 } | 1268 } |
1269 | 1269 |
1270 if (!is_async) { | 1270 if (!is_async) { |
1271 PopulateResult(); | 1271 PopulateResult(); |
1272 SendResponse(true); | 1272 SendResponse(true); |
1273 } | 1273 } |
1274 return true; | 1274 return true; |
1275 } | 1275 } |
1276 | 1276 |
1277 bool UpdateTabFunction::UpdateURLIfPresent(DictionaryValue* update_props, | 1277 bool UpdateTabFunction::UpdateURLIfPresent(DictionaryValue* update_props, |
| 1278 int tab_id, |
1278 bool* is_async) { | 1279 bool* is_async) { |
1279 if (!update_props->HasKey(keys::kUrlKey)) | 1280 if (!update_props->HasKey(keys::kUrlKey)) |
1280 return true; | 1281 return true; |
1281 | 1282 |
1282 std::string url_string; | 1283 std::string url_string; |
1283 EXTENSION_FUNCTION_VALIDATE(update_props->GetString( | 1284 EXTENSION_FUNCTION_VALIDATE(update_props->GetString( |
1284 keys::kUrlKey, &url_string)); | 1285 keys::kUrlKey, &url_string)); |
1285 GURL url = ExtensionTabUtil::ResolvePossiblyRelativeURL( | 1286 GURL url = ExtensionTabUtil::ResolvePossiblyRelativeURL( |
1286 url_string, GetExtension()); | 1287 url_string, GetExtension()); |
1287 | 1288 |
1288 if (!url.is_valid()) { | 1289 if (!url.is_valid()) { |
1289 error_ = ExtensionErrorUtils::FormatErrorMessage( | 1290 error_ = ExtensionErrorUtils::FormatErrorMessage( |
1290 keys::kInvalidUrlError, url_string); | 1291 keys::kInvalidUrlError, url_string); |
1291 return false; | 1292 return false; |
1292 } | 1293 } |
1293 | 1294 |
1294 // Don't let the extension crash the browser or renderers. | 1295 // Don't let the extension crash the browser or renderers. |
1295 if (ExtensionTabUtil::IsCrashURL(url)) { | 1296 if (ExtensionTabUtil::IsCrashURL(url)) { |
1296 error_ = keys::kNoCrashBrowserError; | 1297 error_ = keys::kNoCrashBrowserError; |
1297 return false; | 1298 return false; |
1298 } | 1299 } |
1299 | 1300 |
1300 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so | 1301 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so |
1301 // we need to check host permissions before allowing them. | 1302 // we need to check host permissions before allowing them. |
1302 if (url.SchemeIs(chrome::kJavaScriptScheme)) { | 1303 if (url.SchemeIs(chrome::kJavaScriptScheme)) { |
1303 if (!GetExtension()->CanExecuteScriptOnPage( | 1304 if (!GetExtension()->CanExecuteScriptOnPage( |
1304 tab_contents_->web_contents()->GetURL(), NULL, &error_)) { | 1305 tab_contents_->web_contents()->GetURL(), tab_id, NULL, &error_)) { |
1305 return false; | 1306 return false; |
1306 } | 1307 } |
1307 | 1308 |
1308 tab_contents_->extension_tab_helper()->script_executor()->ExecuteScript( | 1309 tab_contents_->extension_tab_helper()->script_executor()->ExecuteScript( |
1309 extension_id(), | 1310 extension_id(), |
1310 ScriptExecutor::JAVASCRIPT, | 1311 ScriptExecutor::JAVASCRIPT, |
1311 url.path(), | 1312 url.path(), |
1312 ScriptExecutor::TOP_FRAME, | 1313 ScriptExecutor::TOP_FRAME, |
1313 UserScript::DOCUMENT_IDLE, | 1314 UserScript::DOCUMENT_IDLE, |
1314 ScriptExecutor::MAIN_WORLD, | 1315 ScriptExecutor::MAIN_WORLD, |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1607 | 1608 |
1608 if (options->HasKey(keys::kQualityKey)) { | 1609 if (options->HasKey(keys::kQualityKey)) { |
1609 EXTENSION_FUNCTION_VALIDATE( | 1610 EXTENSION_FUNCTION_VALIDATE( |
1610 options->GetInteger(keys::kQualityKey, &image_quality_)); | 1611 options->GetInteger(keys::kQualityKey, &image_quality_)); |
1611 } | 1612 } |
1612 } | 1613 } |
1613 | 1614 |
1614 // captureVisibleTab() can return an image containing sensitive information | 1615 // captureVisibleTab() can return an image containing sensitive information |
1615 // that the browser would otherwise protect. Ensure the extension has | 1616 // that the browser would otherwise protect. Ensure the extension has |
1616 // permission to do this. | 1617 // permission to do this. |
1617 if (!GetExtension()->CanCaptureVisiblePage(web_contents->GetURL(), &error_)) | 1618 if (!GetExtension()->CanCaptureVisiblePage( |
| 1619 web_contents->GetURL(), |
| 1620 tab_contents->extension_tab_helper()->tab_id(), |
| 1621 &error_)) { |
1618 return false; | 1622 return false; |
| 1623 } |
1619 | 1624 |
1620 RenderViewHost* render_view_host = web_contents->GetRenderViewHost(); | 1625 RenderViewHost* render_view_host = web_contents->GetRenderViewHost(); |
1621 content::RenderWidgetHostView* view = render_view_host->GetView(); | 1626 content::RenderWidgetHostView* view = render_view_host->GetView(); |
1622 if (!view) { | 1627 if (!view) { |
1623 error_ = keys::kInternalVisibleTabCaptureError; | 1628 error_ = keys::kInternalVisibleTabCaptureError; |
1624 return false; | 1629 return false; |
1625 } | 1630 } |
1626 skia::PlatformCanvas* temp_canvas = new skia::PlatformCanvas; | 1631 skia::PlatformCanvas* temp_canvas = new skia::PlatformCanvas; |
1627 render_view_host->CopyFromBackingStore( | 1632 render_view_host->CopyFromBackingStore( |
1628 gfx::Rect(), | 1633 gfx::Rect(), |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1801 // called for every API call the extension made. | 1806 // called for every API call the extension made. |
1802 GotLanguage(language); | 1807 GotLanguage(language); |
1803 } | 1808 } |
1804 | 1809 |
1805 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1810 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
1806 result_.reset(Value::CreateStringValue(language.c_str())); | 1811 result_.reset(Value::CreateStringValue(language.c_str())); |
1807 SendResponse(true); | 1812 SendResponse(true); |
1808 | 1813 |
1809 Release(); // Balanced in Run() | 1814 Release(); // Balanced in Run() |
1810 } | 1815 } |
OLD | NEW |