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

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

Issue 10443105: Take 2 at implementing activeTab. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: many more tests Created 8 years, 6 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_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 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 } 1216 }
1217 1217
1218 tab_contents_ = contents; 1218 tab_contents_ = contents;
1219 1219
1220 // TODO(rafaelw): handle setting remaining tab properties: 1220 // TODO(rafaelw): handle setting remaining tab properties:
1221 // -title 1221 // -title
1222 // -favIconUrl 1222 // -favIconUrl
1223 1223
1224 // Navigate the tab to a new location if the url is different. 1224 // Navigate the tab to a new location if the url is different.
1225 bool is_async = false; 1225 bool is_async = false;
1226 if (!UpdateURLIfPresent(update_props, &is_async)) 1226 if (!UpdateURLIfPresent(update_props, tab_id, &is_async))
1227 return false; 1227 return false;
1228 1228
1229 bool active = false; 1229 bool active = false;
1230 // TODO(rafaelw): Setting |active| from js doesn't make much sense. 1230 // TODO(rafaelw): Setting |active| from js doesn't make much sense.
1231 // Move tab selection management up to window. 1231 // Move tab selection management up to window.
1232 if (update_props->HasKey(keys::kSelectedKey)) 1232 if (update_props->HasKey(keys::kSelectedKey))
1233 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( 1233 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(
1234 keys::kSelectedKey, &active)); 1234 keys::kSelectedKey, &active));
1235 1235
1236 // The 'active' property has replaced 'selected'. 1236 // The 'active' property has replaced 'selected'.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 } 1280 }
1281 1281
1282 if (!is_async) { 1282 if (!is_async) {
1283 PopulateResult(); 1283 PopulateResult();
1284 SendResponse(true); 1284 SendResponse(true);
1285 } 1285 }
1286 return true; 1286 return true;
1287 } 1287 }
1288 1288
1289 bool UpdateTabFunction::UpdateURLIfPresent(DictionaryValue* update_props, 1289 bool UpdateTabFunction::UpdateURLIfPresent(DictionaryValue* update_props,
1290 int tab_id,
1290 bool* is_async) { 1291 bool* is_async) {
1291 if (!update_props->HasKey(keys::kUrlKey)) 1292 if (!update_props->HasKey(keys::kUrlKey))
1292 return true; 1293 return true;
1293 1294
1294 std::string url_string; 1295 std::string url_string;
1295 EXTENSION_FUNCTION_VALIDATE(update_props->GetString( 1296 EXTENSION_FUNCTION_VALIDATE(update_props->GetString(
1296 keys::kUrlKey, &url_string)); 1297 keys::kUrlKey, &url_string));
1297 GURL url = ExtensionTabUtil::ResolvePossiblyRelativeURL( 1298 GURL url = ExtensionTabUtil::ResolvePossiblyRelativeURL(
1298 url_string, GetExtension()); 1299 url_string, GetExtension());
1299 1300
1300 if (!url.is_valid()) { 1301 if (!url.is_valid()) {
1301 error_ = ExtensionErrorUtils::FormatErrorMessage( 1302 error_ = ExtensionErrorUtils::FormatErrorMessage(
1302 keys::kInvalidUrlError, url_string); 1303 keys::kInvalidUrlError, url_string);
1303 return false; 1304 return false;
1304 } 1305 }
1305 1306
1306 // Don't let the extension crash the browser or renderers. 1307 // Don't let the extension crash the browser or renderers.
1307 if (ExtensionTabUtil::IsCrashURL(url)) { 1308 if (ExtensionTabUtil::IsCrashURL(url)) {
1308 error_ = keys::kNoCrashBrowserError; 1309 error_ = keys::kNoCrashBrowserError;
1309 return false; 1310 return false;
1310 } 1311 }
1311 1312
1312 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so 1313 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so
1313 // we need to check host permissions before allowing them. 1314 // we need to check host permissions before allowing them.
1314 if (url.SchemeIs(chrome::kJavaScriptScheme)) { 1315 if (url.SchemeIs(chrome::kJavaScriptScheme)) {
1315 if (!GetExtension()->CanExecuteScriptOnPage( 1316 if (!GetExtension()->CanExecuteScriptOnPage(
1316 tab_contents_->web_contents()->GetURL(), NULL, &error_)) { 1317 tab_contents_->web_contents()->GetURL(), tab_id, NULL, &error_)) {
1317 return false; 1318 return false;
1318 } 1319 }
1319 1320
1320 tab_contents_->extension_tab_helper()->script_executor()->ExecuteScript( 1321 tab_contents_->extension_tab_helper()->script_executor()->ExecuteScript(
1321 extension_id(), 1322 extension_id(),
1322 ScriptExecutor::JAVASCRIPT, 1323 ScriptExecutor::JAVASCRIPT,
1323 url.path(), 1324 url.path(),
1324 ScriptExecutor::TOP_FRAME, 1325 ScriptExecutor::TOP_FRAME,
1325 UserScript::DOCUMENT_IDLE, 1326 UserScript::DOCUMENT_IDLE,
1326 ScriptExecutor::MAIN_WORLD, 1327 ScriptExecutor::MAIN_WORLD,
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1619 1620
1620 if (options->HasKey(keys::kQualityKey)) { 1621 if (options->HasKey(keys::kQualityKey)) {
1621 EXTENSION_FUNCTION_VALIDATE( 1622 EXTENSION_FUNCTION_VALIDATE(
1622 options->GetInteger(keys::kQualityKey, &image_quality_)); 1623 options->GetInteger(keys::kQualityKey, &image_quality_));
1623 } 1624 }
1624 } 1625 }
1625 1626
1626 // captureVisibleTab() can return an image containing sensitive information 1627 // captureVisibleTab() can return an image containing sensitive information
1627 // that the browser would otherwise protect. Ensure the extension has 1628 // that the browser would otherwise protect. Ensure the extension has
1628 // permission to do this. 1629 // permission to do this.
1629 if (!GetExtension()->CanCaptureVisiblePage(web_contents->GetURL(), &error_)) 1630 if (!GetExtension()->CanCaptureVisiblePage(
1631 web_contents->GetURL(),
1632 wrapper->extension_tab_helper()->GetTabId(),
1633 &error_)) {
1630 return false; 1634 return false;
1635 }
1631 1636
1632 RenderViewHost* render_view_host = web_contents->GetRenderViewHost(); 1637 RenderViewHost* render_view_host = web_contents->GetRenderViewHost();
1633 content::RenderWidgetHostView* view = render_view_host->GetView(); 1638 content::RenderWidgetHostView* view = render_view_host->GetView();
1634 if (!view) { 1639 if (!view) {
1635 error_ = keys::kInternalVisibleTabCaptureError; 1640 error_ = keys::kInternalVisibleTabCaptureError;
1636 return false; 1641 return false;
1637 } 1642 }
1638 skia::PlatformCanvas* temp_canvas = new skia::PlatformCanvas; 1643 skia::PlatformCanvas* temp_canvas = new skia::PlatformCanvas;
1639 render_view_host->CopyFromBackingStore( 1644 render_view_host->CopyFromBackingStore(
1640 gfx::Rect(), 1645 gfx::Rect(),
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 // called for every API call the extension made. 1818 // called for every API call the extension made.
1814 GotLanguage(language); 1819 GotLanguage(language);
1815 } 1820 }
1816 1821
1817 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { 1822 void DetectTabLanguageFunction::GotLanguage(const std::string& language) {
1818 result_.reset(Value::CreateStringValue(language.c_str())); 1823 result_.reset(Value::CreateStringValue(language.c_str()));
1819 SendResponse(true); 1824 SendResponse(true);
1820 1825
1821 Release(); // Balanced in Run() 1826 Release(); // Balanced in Run()
1822 } 1827 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698