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_tabs_module.h" | 5 #include "chrome/browser/extensions/extension_tabs_module.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1187 } | 1187 } |
1188 | 1188 |
1189 tab_contents_ = contents; | 1189 tab_contents_ = contents; |
1190 | 1190 |
1191 // TODO(rafaelw): handle setting remaining tab properties: | 1191 // TODO(rafaelw): handle setting remaining tab properties: |
1192 // -title | 1192 // -title |
1193 // -favIconUrl | 1193 // -favIconUrl |
1194 | 1194 |
1195 // Navigate the tab to a new location if the url is different. | 1195 // Navigate the tab to a new location if the url is different. |
1196 bool is_async = false; | 1196 bool is_async = false; |
1197 if (!UpdateURLIfPresent(update_props, &is_async)) | 1197 if (!UpdateURLIfPresent(update_props, tab_id, &is_async)) |
1198 return false; | 1198 return false; |
1199 | 1199 |
1200 bool active = false; | 1200 bool active = false; |
1201 // TODO(rafaelw): Setting |active| from js doesn't make much sense. | 1201 // TODO(rafaelw): Setting |active| from js doesn't make much sense. |
1202 // Move tab selection management up to window. | 1202 // Move tab selection management up to window. |
1203 if (update_props->HasKey(keys::kSelectedKey)) | 1203 if (update_props->HasKey(keys::kSelectedKey)) |
1204 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( | 1204 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( |
1205 keys::kSelectedKey, &active)); | 1205 keys::kSelectedKey, &active)); |
1206 | 1206 |
1207 // The 'active' property has replaced 'selected'. | 1207 // The 'active' property has replaced 'selected'. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1251 } | 1251 } |
1252 | 1252 |
1253 if (!is_async) { | 1253 if (!is_async) { |
1254 PopulateResult(); | 1254 PopulateResult(); |
1255 SendResponse(true); | 1255 SendResponse(true); |
1256 } | 1256 } |
1257 return true; | 1257 return true; |
1258 } | 1258 } |
1259 | 1259 |
1260 bool UpdateTabFunction::UpdateURLIfPresent(DictionaryValue* update_props, | 1260 bool UpdateTabFunction::UpdateURLIfPresent(DictionaryValue* update_props, |
| 1261 int tab_id, |
1261 bool* is_async) { | 1262 bool* is_async) { |
1262 if (!update_props->HasKey(keys::kUrlKey)) | 1263 if (!update_props->HasKey(keys::kUrlKey)) |
1263 return true; | 1264 return true; |
1264 | 1265 |
1265 std::string url_string; | 1266 std::string url_string; |
1266 EXTENSION_FUNCTION_VALIDATE(update_props->GetString( | 1267 EXTENSION_FUNCTION_VALIDATE(update_props->GetString( |
1267 keys::kUrlKey, &url_string)); | 1268 keys::kUrlKey, &url_string)); |
1268 GURL url = ExtensionTabUtil::ResolvePossiblyRelativeURL( | 1269 GURL url = ExtensionTabUtil::ResolvePossiblyRelativeURL( |
1269 url_string, GetExtension()); | 1270 url_string, GetExtension()); |
1270 | 1271 |
1271 if (!url.is_valid()) { | 1272 if (!url.is_valid()) { |
1272 error_ = ExtensionErrorUtils::FormatErrorMessage( | 1273 error_ = ExtensionErrorUtils::FormatErrorMessage( |
1273 keys::kInvalidUrlError, url_string); | 1274 keys::kInvalidUrlError, url_string); |
1274 return false; | 1275 return false; |
1275 } | 1276 } |
1276 | 1277 |
1277 // Don't let the extension crash the browser or renderers. | 1278 // Don't let the extension crash the browser or renderers. |
1278 if (ExtensionTabUtil::IsCrashURL(url)) { | 1279 if (ExtensionTabUtil::IsCrashURL(url)) { |
1279 error_ = keys::kNoCrashBrowserError; | 1280 error_ = keys::kNoCrashBrowserError; |
1280 return false; | 1281 return false; |
1281 } | 1282 } |
1282 | 1283 |
1283 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so | 1284 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so |
1284 // we need to check host permissions before allowing them. | 1285 // we need to check host permissions before allowing them. |
1285 if (url.SchemeIs(chrome::kJavaScriptScheme)) { | 1286 if (url.SchemeIs(chrome::kJavaScriptScheme)) { |
1286 if (!GetExtension()->CanExecuteScriptOnPage( | 1287 if (!GetExtension()->CanExecuteScriptOnPage( |
1287 tab_contents_->web_contents()->GetURL(), NULL, &error_)) { | 1288 tab_contents_->web_contents()->GetURL(), tab_id, NULL, &error_)) { |
1288 return false; | 1289 return false; |
1289 } | 1290 } |
1290 | 1291 |
1291 tab_contents_->extension_tab_helper()->script_executor()->ExecuteScript( | 1292 tab_contents_->extension_tab_helper()->script_executor()->ExecuteScript( |
1292 extension_id(), | 1293 extension_id(), |
1293 ScriptExecutor::JAVASCRIPT, | 1294 ScriptExecutor::JAVASCRIPT, |
1294 url.path(), | 1295 url.path(), |
1295 ScriptExecutor::TOP_FRAME, | 1296 ScriptExecutor::TOP_FRAME, |
1296 UserScript::DOCUMENT_IDLE, | 1297 UserScript::DOCUMENT_IDLE, |
1297 ScriptExecutor::MAIN_WORLD, | 1298 ScriptExecutor::MAIN_WORLD, |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1590 | 1591 |
1591 if (options->HasKey(keys::kQualityKey)) { | 1592 if (options->HasKey(keys::kQualityKey)) { |
1592 EXTENSION_FUNCTION_VALIDATE( | 1593 EXTENSION_FUNCTION_VALIDATE( |
1593 options->GetInteger(keys::kQualityKey, &image_quality_)); | 1594 options->GetInteger(keys::kQualityKey, &image_quality_)); |
1594 } | 1595 } |
1595 } | 1596 } |
1596 | 1597 |
1597 // captureVisibleTab() can return an image containing sensitive information | 1598 // captureVisibleTab() can return an image containing sensitive information |
1598 // that the browser would otherwise protect. Ensure the extension has | 1599 // that the browser would otherwise protect. Ensure the extension has |
1599 // permission to do this. | 1600 // permission to do this. |
1600 if (!GetExtension()->CanCaptureVisiblePage(web_contents->GetURL(), &error_)) | 1601 if (!GetExtension()->CanCaptureVisiblePage( |
| 1602 web_contents->GetURL(), |
| 1603 wrapper->extension_tab_helper()->GetTabId(), |
| 1604 &error_)) { |
1601 return false; | 1605 return false; |
| 1606 } |
1602 | 1607 |
1603 RenderViewHost* render_view_host = web_contents->GetRenderViewHost(); | 1608 RenderViewHost* render_view_host = web_contents->GetRenderViewHost(); |
1604 content::RenderWidgetHostView* view = render_view_host->GetView(); | 1609 content::RenderWidgetHostView* view = render_view_host->GetView(); |
1605 if (!view) { | 1610 if (!view) { |
1606 error_ = keys::kInternalVisibleTabCaptureError; | 1611 error_ = keys::kInternalVisibleTabCaptureError; |
1607 return false; | 1612 return false; |
1608 } | 1613 } |
1609 skia::PlatformCanvas* temp_canvas = new skia::PlatformCanvas; | 1614 skia::PlatformCanvas* temp_canvas = new skia::PlatformCanvas; |
1610 render_view_host->CopyFromBackingStore( | 1615 render_view_host->CopyFromBackingStore( |
1611 gfx::Rect(), | 1616 gfx::Rect(), |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1784 // called for every API call the extension made. | 1789 // called for every API call the extension made. |
1785 GotLanguage(language); | 1790 GotLanguage(language); |
1786 } | 1791 } |
1787 | 1792 |
1788 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1793 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
1789 result_.reset(Value::CreateStringValue(language.c_str())); | 1794 result_.reset(Value::CreateStringValue(language.c_str())); |
1790 SendResponse(true); | 1795 SendResponse(true); |
1791 | 1796 |
1792 Release(); // Balanced in Run() | 1797 Release(); // Balanced in Run() |
1793 } | 1798 } |
OLD | NEW |