diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-29 22:23:49 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-29 22:23:49 +0000 |
commit | f7c80ac89d54f43a43a1fad19a5b4e919927d263 (patch) | |
tree | bff16aef806ed0e727a7e78ab6c08ecc5640d90e | |
parent | 52a26894a92e0d8b756bcce2bc96cd741f135329 (diff) | |
download | chromium_src-f7c80ac89d54f43a43a1fad19a5b4e919927d263.zip chromium_src-f7c80ac89d54f43a43a1fad19a5b4e919927d263.tar.gz chromium_src-f7c80ac89d54f43a43a1fad19a5b4e919927d263.tar.bz2 |
Remove support for some deprecated APIs in manifest version 2.
TBR=kalman@chromium.org
Review URL: http://codereview.chromium.org/9295042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119647 0039d316-1c4b-4281-b951-d872f2087c98
17 files changed, 95 insertions, 64 deletions
diff --git a/chrome/browser/extensions/extension_browsertests_misc.cc b/chrome/browser/extensions/extension_browsertests_misc.cc index a92ccd6..ef915de 100644 --- a/chrome/browser/extensions/extension_browsertests_misc.cc +++ b/chrome/browser/extensions/extension_browsertests_misc.cc @@ -133,8 +133,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WebKitPrefsBackgroundPage) { ASSERT_FALSE(prefs.accelerated_2d_canvas_enabled); } -// Tests that we can load page actions in the Omnibox. -IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageAction) { +IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionCrash25562) { ASSERT_TRUE(test_server()->Start()); CommandLine::ForCurrentProcess()->AppendSwitch( @@ -146,6 +145,20 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageAction) { test_data_dir_.AppendASCII("browsertest") .AppendASCII("crash_25562"))); + // Navigate to the feed page. + GURL feed_url = test_server()->GetURL(kFeedPage); + ui_test_utils::NavigateToURL(browser(), feed_url); + // We should now have one page action ready to go in the LocationBar. + ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); +} + +// Tests that we can load page actions in the Omnibox. +IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageAction) { + ASSERT_TRUE(test_server()->Start()); + + CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kAllowLegacyExtensionManifests); + ASSERT_TRUE(LoadExtension( test_data_dir_.AppendASCII("subscribe_page_action"))); diff --git a/chrome/browser/extensions/extension_page_actions_module.cc b/chrome/browser/extensions/extension_page_actions_module.cc index 203c87d..1e97ad7 100644 --- a/chrome/browser/extensions/extension_page_actions_module.cc +++ b/chrome/browser/extensions/extension_page_actions_module.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -35,7 +35,6 @@ const char kIconIndexOutOfBounds[] = "Page action icon index out of bounds."; const char kNoIconSpecified[] = "Page action has no icons to show."; } -// TODO(EXTENSIONS_DEPRECATED): obsolete API. bool PageActionFunction::SetPageActionEnabled(bool enable) { std::string page_action_id; EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &page_action_id)); diff --git a/chrome/common/extensions/api/extension.json b/chrome/common/extensions/api/extension.json index 0b10faa..4b139f8 100644 --- a/chrome/common/extensions/api/extension.json +++ b/chrome/common/extensions/api/extension.json @@ -163,6 +163,7 @@ "name": "getExtensionTabs", "nodoc": true, "type": "function", + "maximumManifestVersion": 1, "description": "Deprecated. Please use getViews({type: 'TAB'}). Returns an array of the JavaScript 'window' objects for each of the tabs running inside the current extension. If windowId is specified, returns only the 'window' objects of tabs attached to the specified window.", "parameters": [ {"type": "integer", "name": "windowId", "optional": true} diff --git a/chrome/common/extensions/api/pageActions.json b/chrome/common/extensions/api/pageActions.json index 57531d4..69e5078 100644 --- a/chrome/common/extensions/api/pageActions.json +++ b/chrome/common/extensions/api/pageActions.json @@ -2,6 +2,7 @@ { "namespace": "pageActions", "nodoc": true, + "maximumManifestVersion": 1, "types": [], "functions": [ { diff --git a/chrome/renderer/extensions/chrome_v8_context.cc b/chrome/renderer/extensions/chrome_v8_context.cc index 174b4ad..98b0c07 100644 --- a/chrome/renderer/extensions/chrome_v8_context.cc +++ b/chrome/renderer/extensions/chrome_v8_context.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -112,12 +112,14 @@ bool ChromeV8Context::CallChromeHiddenMethod( } void ChromeV8Context::DispatchOnLoadEvent(bool is_extension_process, - bool is_incognito_process) const { + bool is_incognito_process, + int manifest_version) const { v8::HandleScope handle_scope; - v8::Handle<v8::Value> argv[3]; + v8::Handle<v8::Value> argv[4]; argv[0] = v8::String::New(extension_id_.c_str()); argv[1] = v8::Boolean::New(is_extension_process); argv[2] = v8::Boolean::New(is_incognito_process); + argv[3] = v8::Integer::New(manifest_version); CallChromeHiddenMethod("dispatchOnLoad", arraysize(argv), argv, NULL); } diff --git a/chrome/renderer/extensions/chrome_v8_context.h b/chrome/renderer/extensions/chrome_v8_context.h index bbacfd1..19165ab 100644 --- a/chrome/renderer/extensions/chrome_v8_context.h +++ b/chrome/renderer/extensions/chrome_v8_context.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -65,7 +65,8 @@ class ChromeV8Context { // Fires the onload and onunload events on the chromeHidden object. // TODO(aa): Move this to EventBindings. void DispatchOnLoadEvent(bool is_extension_process, - bool is_incognito_process) const; + bool is_incognito_process, + int manifest_version) const; void DispatchOnUnloadEvent() const; // Call the named method of the chromeHidden object in this context. diff --git a/chrome/renderer/extensions/extension_dispatcher.cc b/chrome/renderer/extensions/extension_dispatcher.cc index 1acc9af..8fd6b50 100644 --- a/chrome/renderer/extensions/extension_dispatcher.cc +++ b/chrome/renderer/extensions/extension_dispatcher.cc @@ -319,9 +319,15 @@ void ExtensionDispatcher::DidCreateScriptContext( new ChromeV8Context(v8_context, frame, GetExtensionID(frame, world_id)); v8_context_set_.Add(context); + const Extension* extension = extensions_.GetByID(context->extension_id()); + int manifest_version = 1; + if (extension) + manifest_version = extension->manifest_version(); + context->DispatchOnLoadEvent( is_extension_process_, - ChromeRenderProcessObserver::is_incognito_process()); + ChromeRenderProcessObserver::is_incognito_process(), + manifest_version); VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); } diff --git a/chrome/renderer/resources/extensions/event.js b/chrome/renderer/resources/extensions/event.js index 45d7080..dffe201 100644 --- a/chrome/renderer/resources/extensions/event.js +++ b/chrome/renderer/resources/extensions/event.js @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -233,11 +233,8 @@ var chrome = chrome || {}; chromeHidden.onLoad = new chrome.Event(); chromeHidden.onUnload = new chrome.Event(); - chromeHidden.dispatchOnLoad = function(extensionId, isExtensionProcess, - isIncognitoContext) { - chromeHidden.onLoad.dispatch(extensionId, isExtensionProcess, - isIncognitoContext); - }; + chromeHidden.dispatchOnLoad = + chromeHidden.onLoad.dispatch.bind(chromeHidden.onLoad); chromeHidden.dispatchOnUnload = function() { chromeHidden.onUnload.dispatch(); diff --git a/chrome/renderer/resources/extensions/extension_custom_bindings.js b/chrome/renderer/resources/extensions/extension_custom_bindings.js index 22a7f96..6444ef3 100644 --- a/chrome/renderer/resources/extensions/extension_custom_bindings.js +++ b/chrome/renderer/resources/extensions/extension_custom_bindings.js @@ -19,7 +19,8 @@ var WINDOW_ID_NONE = -1; GetChromeHidden().registerCustomHook('extension', function(bindingsAPI) { // getTabContentses is retained for backwards compatibility. // See http://crbug.com/21433 - chrome.extension.getTabContentses = chrome.extension.getExtensionTabs; + if (chrome.extension.getExtensionTabs) + chrome.extension.getTabContentses = chrome.extension.getExtensionTabs; var apiFunctions = bindingsAPI.apiFunctions; diff --git a/chrome/renderer/resources/extensions/miscellaneous_bindings.js b/chrome/renderer/resources/extensions/miscellaneous_bindings.js index 5a65a02..37ce11d 100644 --- a/chrome/renderer/resources/extensions/miscellaneous_bindings.js +++ b/chrome/renderer/resources/extensions/miscellaneous_bindings.js @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -20,6 +20,7 @@ var chrome = chrome || {}; native function Print(); var chromeHidden = GetChromeHidden(); + var manifestVersion; // The reserved channel name for the sendRequest API. chromeHidden.kRequestChannel = "chrome.extension.sendRequest"; @@ -125,8 +126,8 @@ var chrome = chrome || {}; if (connectEvent.hasListeners()) { var port = chromeHidden.Port.createPort(portId, channelName); port.sender = sender; - // TODO(EXTENSIONS_DEPRECATED): port.tab is obsolete. - port.tab = port.sender.tab; + if (manifestVersion < 2) + port.tab = port.sender.tab; connectEvent.dispatch(port); } @@ -195,14 +196,19 @@ var chrome = chrome || {}; // This function is called on context initialization for both content scripts // and extension contexts. - chromeHidden.onLoad.addListener(function(extensionId, isExtensionProcess, - inIncognitoContext) { + chromeHidden.onLoad.addListener(function(extensionId, + isExtensionProcess, + inIncognitoContext, + tempManifestVersion) { chromeHidden.extensionId = extensionId; + manifestVersion = tempManifestVersion; chrome.extension = chrome.extension || {}; chrome.self = chrome.extension; - chrome.extension.inIncognitoTab = inIncognitoContext; // deprecated + if (manifestVersion < 2) + chrome.extension.inIncognitoTab = inIncognitoContext; + chrome.extension.inIncognitoContext = inIncognitoContext; // Events for when a message channel is opened to our extension. diff --git a/chrome/renderer/resources/extensions/page_actions_custom_bindings.js b/chrome/renderer/resources/extensions/page_actions_custom_bindings.js index 515beb8..e9077ba 100644 --- a/chrome/renderer/resources/extensions/page_actions_custom_bindings.js +++ b/chrome/renderer/resources/extensions/page_actions_custom_bindings.js @@ -13,7 +13,6 @@ GetChromeHidden().registerCustomHook( 'pageActions', function(bindingsAPI, extensionId) { var pageActions = GetCurrentPageActions(extensionId); var oldStyleEventName = "pageActions"; - // TODO(EXTENSIONS_DEPRECATED): only one page action for (var i = 0; i < pageActions.length; ++i) { // Setup events for each extension_id/page_action_id string we find. chrome.pageActions[pageActions[i]] = new chrome.Event(oldStyleEventName); diff --git a/chrome/renderer/resources/extensions/schema_generated_bindings.js b/chrome/renderer/resources/extensions/schema_generated_bindings.js index 32c7701..a935ff9 100644 --- a/chrome/renderer/resources/extensions/schema_generated_bindings.js +++ b/chrome/renderer/resources/extensions/schema_generated_bindings.js @@ -352,8 +352,25 @@ var chrome = chrome || {}; return "unknown"; } - chromeHidden.onLoad.addListener(function(extensionId, isExtensionProcess, - isIncognitoProcess) { + function isPlatformSupported(schemaNode, platform) { + return !schemaNode.platforms || + schemaNode.platforms.indexOf(platform) > -1; + } + + function isManifestVersionSupported(schemaNode, manifestVersion) { + return !schemaNode.maximumManifestVersion || + manifestVersion <= schemaNode.maximumManifestVersion; + } + + function isSchemaNodeSupported(schemaNode, platform, manifestVersion) { + return isPlatformSupported(schemaNode, platform) && + isManifestVersionSupported(schemaNode, manifestVersion); + } + + chromeHidden.onLoad.addListener(function(extensionId, + isExtensionProcess, + isIncognitoProcess, + manifestVersion) { var apiDefinitions = GetExtensionAPIDefinition(); // Read api definitions and setup api functions in the chrome namespace. @@ -365,10 +382,8 @@ var chrome = chrome || {}; var platform = getPlatform(); apiDefinitions.forEach(function(apiDef) { - // Only generate bindings if supported by this platform. - if (apiDef.platforms && apiDef.platforms.indexOf(platform) == -1) { + if (!isSchemaNodeSupported(apiDef, platform, manifestVersion)) return; - } var module = chrome; var namespaces = apiDef.namespace.split('.'); @@ -380,6 +395,9 @@ var chrome = chrome || {}; // Add types to global validationTypes if (apiDef.types) { apiDef.types.forEach(function(t) { + if (!isSchemaNodeSupported(t, platform, manifestVersion)) + return; + chromeHidden.validationTypes.push(t); if (t.type == 'object' && customTypes[t.id]) { customTypes[t.id].prototype.setSchema(t); @@ -407,6 +425,9 @@ var chrome = chrome || {}; // Setup Functions. if (apiDef.functions) { apiDef.functions.forEach(function(functionDef) { + if (!isSchemaNodeSupported(functionDef, platform, manifestVersion)) + return; + if (functionDef.name in module || addUnprivilegedAccessGetter(module, functionDef.name, functionDef.unprivileged)) { @@ -449,6 +470,9 @@ var chrome = chrome || {}; // Setup Events if (apiDef.events) { apiDef.events.forEach(function(eventDef) { + if (!isSchemaNodeSupported(eventDef, platform, manifestVersion)) + return; + if (eventDef.name in module || addUnprivilegedAccessGetter(module, eventDef.name, eventDef.unprivileged)) { @@ -471,6 +495,9 @@ var chrome = chrome || {}; // Parse any values defined for properties. if (def.properties) { forEach(def.properties, function(prop, property) { + if (!isSchemaNodeSupported(property, platform, manifestVersion)) + return; + if (prop in m || addUnprivilegedAccessGetter(m, prop, property.unprivileged)) { return; @@ -525,8 +552,7 @@ var chrome = chrome || {}; // custom hooks in extension processes, to maintain current behaviour. We // should fix this this with a smaller hammer. apiDefinitions.forEach(function(apiDef) { - // Only generate bindings if supported by this platform. - if (apiDef.platforms && apiDef.platforms.indexOf(platform) == -1) + if (!isSchemaNodeSupported(apiDef, platform, manifestVersion)) return; var hook = customHooks[apiDef.namespace]; diff --git a/chrome/test/data/extensions/api_test/stubs/background.js b/chrome/test/data/extensions/api_test/stubs/background.html index c0fcc45..f1d207d 100644 --- a/chrome/test/data/extensions/api_test/stubs/background.js +++ b/chrome/test/data/extensions/api_test/stubs/background.html @@ -1,4 +1,5 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +<script> +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -16,3 +17,4 @@ chrome.extension.onRequest.addListener(function(msg, sender, responseFunc) { // On first install, send a success message so the test can continue. chrome.test.notifyPass(); +</script> diff --git a/chrome/test/data/extensions/api_test/stubs/manifest.json b/chrome/test/data/extensions/api_test/stubs/manifest.json index af8bbbb..6909f1e 100644 --- a/chrome/test/data/extensions/api_test/stubs/manifest.json +++ b/chrome/test/data/extensions/api_test/stubs/manifest.json @@ -1,10 +1,7 @@ { "name": "Content Script Extension API Stubs Test", "version": "1.0", - "manifest_version": 2, - "background": { - "scripts": ["background.js"] - }, + "background_page": "background.html", "content_scripts": [ { "matches": ["http://*/*"], diff --git a/chrome/test/data/extensions/browsertest/crash_25562/background.js b/chrome/test/data/extensions/browsertest/crash_25562/background.js index 8ff4dc0..0264428 100644 --- a/chrome/test/data/extensions/browsertest/crash_25562/background.js +++ b/chrome/test/data/extensions/browsertest/crash_25562/background.js @@ -1,28 +1,11 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// The Page Action ID. -var pageActionId = "TestId"; - -// The window this Page Action is associated with. -var windowId = -1; - -// The TabId this Page Action is associated with. -var tabId = -1; - -// The URL of the page on build.chromium.org. -var pageUrl = ""; - chrome.self.onConnect.addListener(function(port) { - windowId = port.tab.windowId; - tabId = port.tab.id; - pageUrl = port.tab.url; - - port.onMessage.addListener(function(mybool) { + port.onMessage.addListener(function() { // Let Chrome know that the PageAction needs to be enabled for this tabId // and for the url of this page. - chrome.pageActions.enableForTab(pageActionId, - {tabId: tabId, url: pageUrl}); + chrome.pageAction.show(port.sender.tab.id); }); }); diff --git a/chrome/test/data/extensions/browsertest/crash_25562/manifest.json b/chrome/test/data/extensions/browsertest/crash_25562/manifest.json index 4783f04..5c3c5a8 100644 --- a/chrome/test/data/extensions/browsertest/crash_25562/manifest.json +++ b/chrome/test/data/extensions/browsertest/crash_25562/manifest.json @@ -8,12 +8,9 @@ } ], "description": "A page action with incorrect icon specification", "name": "Test extension", - "page_actions": [ { - "icon": "chrome-16.png", - "id": "TestId", - "name": "Page action name", - "tooltip": "Page action tooltip" - } ], + "page_action": { + "icon": "chrome-16.png" + }, "permissions": [ "http://*/*" ], "manifest_version": 2, "version": "1.0" diff --git a/chrome/test/data/extensions/browsertest/title_localized_pa/background.js b/chrome/test/data/extensions/browsertest/title_localized_pa/background.js index 82daf0b..0031ace 100644 --- a/chrome/test/data/extensions/browsertest/title_localized_pa/background.js +++ b/chrome/test/data/extensions/browsertest/title_localized_pa/background.js @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,6 +6,6 @@ chrome.self.onConnect.addListener(function(port) { port.onMessage.addListener(function(mybool) { // Let Chrome know that the PageAction needs to be enabled for this tabId // and for the url of this page. - chrome.pageAction.show(port.tab.id); + chrome.pageAction.show(port.sender.tab.id); }); }); |