diff options
author | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-16 10:20:01 +0000 |
---|---|---|
committer | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-16 10:20:01 +0000 |
commit | c7c401dd5f78685f7ce4a1e1ba0b38f64702c73e (patch) | |
tree | 14fea4d07b6b4375da8bc4bf65f27268409b2034 /chrome | |
parent | cdefa460b361c452c20249b672afeda499886f60 (diff) | |
download | chromium_src-c7c401dd5f78685f7ce4a1e1ba0b38f64702c73e.zip chromium_src-c7c401dd5f78685f7ce4a1e1ba0b38f64702c73e.tar.gz chromium_src-c7c401dd5f78685f7ce4a1e1ba0b38f64702c73e.tar.bz2 |
Exposing extension preferences via the `chrome.extension` API.
`chrome.extension.isAllowedIncognitoAccess` gives access to `chrome://extension`'s "Allowed in Incognito" checkbox's state, and `chrome.extension.isAllowedFileSchemeAccess` does the same for "Allow access to File URLs".
Patch by Mike West <mkwst@google.com>.
BUG=74694
TEST=Create an extension that checks whether 'Allow in Incognito' or 'Allow access to File URLs' is checked. It should work correctly.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78347 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
24 files changed, 672 insertions, 25 deletions
diff --git a/chrome/browser/extensions/extension_apitest.cc b/chrome/browser/extensions/extension_apitest.cc index 463851c..bebf457 100644 --- a/chrome/browser/extensions/extension_apitest.cc +++ b/chrome/browser/extensions/extension_apitest.cc @@ -100,17 +100,26 @@ void ExtensionApiTest::TearDownInProcessBrowserTestFixture() { } bool ExtensionApiTest::RunExtensionTest(const char* extension_name) { - return RunExtensionTestImpl(extension_name, "", false); + return RunExtensionTestImpl(extension_name, "", false, true); } bool ExtensionApiTest::RunExtensionTestIncognito(const char* extension_name) { - return RunExtensionTestImpl(extension_name, "", true); + return RunExtensionTestImpl(extension_name, "", true, true); } +bool ExtensionApiTest::RunExtensionTestNoFileAccess( + const char* extension_name) { + return RunExtensionTestImpl(extension_name, "", false, false); +} + +bool ExtensionApiTest::RunExtensionTestIncognitoNoFileAccess( + const char* extension_name) { + return RunExtensionTestImpl(extension_name, "", true, false); +} bool ExtensionApiTest::RunExtensionSubtest(const char* extension_name, const std::string& page_url) { DCHECK(!page_url.empty()) << "Argument page_url is required."; - return RunExtensionTestImpl(extension_name, page_url, false); + return RunExtensionTestImpl(extension_name, page_url, false, true); } bool ExtensionApiTest::RunPageTest(const std::string& page_url) { @@ -121,15 +130,24 @@ bool ExtensionApiTest::RunPageTest(const std::string& page_url) { // PASSED or FAILED notification. bool ExtensionApiTest::RunExtensionTestImpl(const char* extension_name, const std::string& page_url, - bool enable_incognito) { + bool enable_incognito, + bool enable_fileaccess) { ResultCatcher catcher; DCHECK(!std::string(extension_name).empty() || !page_url.empty()) << "extension_name and page_url cannot both be empty"; if (!std::string(extension_name).empty()) { - bool loaded = enable_incognito ? + bool loaded; + if (enable_incognito) { + loaded = enable_fileaccess ? LoadExtensionIncognito(test_data_dir_.AppendASCII(extension_name)) : - LoadExtension(test_data_dir_.AppendASCII(extension_name)); + LoadExtensionIncognitoNoFileAccess( + test_data_dir_.AppendASCII(extension_name)); + } else { + loaded = enable_fileaccess ? + LoadExtension(test_data_dir_.AppendASCII(extension_name)) : + LoadExtensionNoFileAccess(test_data_dir_.AppendASCII(extension_name)); + } if (!loaded) { message_ = "Failed to load extension."; return false; diff --git a/chrome/browser/extensions/extension_apitest.h b/chrome/browser/extensions/extension_apitest.h index d56441e..5ab3748 100644 --- a/chrome/browser/extensions/extension_apitest.h +++ b/chrome/browser/extensions/extension_apitest.h @@ -80,6 +80,12 @@ class ExtensionApiTest : public ExtensionBrowserTest { // Same as RunExtensionTest, but enables the extension for incognito mode. bool RunExtensionTestIncognito(const char* extension_name); + // Same as RunExtensionTest, but disables file access. + bool RunExtensionTestNoFileAccess(const char* extension_name); + + // Same as RunExtensionTestIncognito, but disables file access. + bool RunExtensionTestIncognitoNoFileAccess(const char* extension_name); + // If not empty, Load |extension_name|, load |page_url| and wait for pass / // fail notification from the extension API on the page. Note that if // |page_url| is not a valid url, it will be treated as a resource within @@ -109,7 +115,8 @@ class ExtensionApiTest : public ExtensionBrowserTest { private: bool RunExtensionTestImpl(const char* extension_name, const std::string& test_page, - bool enable_incogntio); + bool enable_incogntio, + bool enable_fileaccess); // Hold details of the test, set in C++, which can be accessed by // javascript using chrome.test.getConfig(). diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc index 33876d9..b487dbc 100644 --- a/chrome/browser/extensions/extension_browsertest.cc +++ b/chrome/browser/extensions/extension_browsertest.cc @@ -58,7 +58,8 @@ void ExtensionBrowserTest::SetUpCommandLine(CommandLine* command_line) { } bool ExtensionBrowserTest::LoadExtensionImpl(const FilePath& path, - bool incognito_enabled) { + bool incognito_enabled, + bool fileaccess_enabled) { ExtensionService* service = browser()->profile()->GetExtensionService(); { NotificationRegistrar registrar; @@ -83,24 +84,31 @@ bool ExtensionBrowserTest::LoadExtensionImpl(const FilePath& path, if (!extension) return false; - if (incognito_enabled) { - // Enable the incognito bit in the extension prefs. The call to - // OnExtensionInstalled ensures the other extension prefs are set up with - // the defaults. - service->extension_prefs()->OnExtensionInstalled( - extension, Extension::ENABLED, false); - service->SetIsIncognitoEnabled(extension, true); - } + // The call to OnExtensionInstalled ensures the other extension prefs + // are set up with the defaults. + service->extension_prefs()->OnExtensionInstalled( + extension, Extension::ENABLED, false); + service->SetIsIncognitoEnabled(extension, incognito_enabled); + service->SetAllowFileAccess(extension, fileaccess_enabled); return WaitForExtensionHostsToLoad(); } bool ExtensionBrowserTest::LoadExtension(const FilePath& path) { - return LoadExtensionImpl(path, false); + return LoadExtensionImpl(path, false, true); } bool ExtensionBrowserTest::LoadExtensionIncognito(const FilePath& path) { - return LoadExtensionImpl(path, true); + return LoadExtensionImpl(path, true, true); +} + +bool ExtensionBrowserTest::LoadExtensionNoFileAccess(const FilePath& path) { + return LoadExtensionImpl(path, false, false); +} + +bool ExtensionBrowserTest::LoadExtensionIncognitoNoFileAccess( + const FilePath& path) { + return LoadExtensionImpl(path, true, false); } FilePath ExtensionBrowserTest::PackExtension(const FilePath& dir_path) { @@ -163,7 +171,7 @@ class MockAbortExtensionInstallUI : public ExtensionInstallUI { class MockAutoConfirmExtensionInstallUI : public ExtensionInstallUI { public: - MockAutoConfirmExtensionInstallUI(Profile* profile) : + explicit MockAutoConfirmExtensionInstallUI(Profile* profile) : ExtensionInstallUI(profile) {} // Proceed without confirmation prompt. diff --git a/chrome/browser/extensions/extension_browsertest.h b/chrome/browser/extensions/extension_browsertest.h index b3bd018..c5c150a 100644 --- a/chrome/browser/extensions/extension_browsertest.h +++ b/chrome/browser/extensions/extension_browsertest.h @@ -28,6 +28,13 @@ class ExtensionBrowserTest // Same as above, but enables the extension in incognito mode first. bool LoadExtensionIncognito(const FilePath& path); + // By default, unpacked extensions have file access: this loads them with + // that permission removed. + bool LoadExtensionNoFileAccess(const FilePath& path); + + // Same as above, but enables the extension in incognito mode first. + bool LoadExtensionIncognitoNoFileAccess(const FilePath& path); + // Pack the extension in |dir_path| into a crx file and return its path. // Return an empty FilePath if there were errors. FilePath PackExtension(const FilePath& dir_path); @@ -128,7 +135,8 @@ class ExtensionBrowserTest InstallUIType ui_type, int expected_change, Profile* profile); - bool LoadExtensionImpl(const FilePath& path, bool incognito_enabled); + bool LoadExtensionImpl(const FilePath& path, bool incognito_enabled, + bool fileaccess_enabled); bool WaitForExtensionHostsToLoad(); diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc index 1d58b498..f3c805d 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.cc +++ b/chrome/browser/extensions/extension_function_dispatcher.cc @@ -283,6 +283,8 @@ void FactoryRegistry::ResetFunctions() { // Extension module. RegisterFunction<SetUpdateUrlDataFunction>(); + RegisterFunction<IsAllowedIncognitoAccessFunction>(); + RegisterFunction<IsAllowedFileSchemeAccessFunction>(); // WebstorePrivate. RegisterFunction<GetBrowserLoginFunction>(); diff --git a/chrome/browser/extensions/extension_module.cc b/chrome/browser/extensions/extension_module.cc index 1ef27a9..bb13067 100644 --- a/chrome/browser/extensions/extension_module.cc +++ b/chrome/browser/extensions/extension_module.cc @@ -21,3 +21,21 @@ bool SetUpdateUrlDataFunction::RunImpl() { extension_prefs()->SetUpdateUrlData(extension_id(), data); return true; } + +bool IsAllowedIncognitoAccessFunction::RunImpl() { + ExtensionService* ext_service = profile()->GetExtensionService(); + const Extension* extension = GetExtension(); + + result_.reset(Value::CreateBooleanValue( + ext_service->IsIncognitoEnabled(extension))); + return true; +} + +bool IsAllowedFileSchemeAccessFunction::RunImpl() { + ExtensionService* ext_service = profile()->GetExtensionService(); + const Extension* extension = GetExtension(); + + result_.reset(Value::CreateBooleanValue( + ext_service->AllowFileAccess(extension))); + return true; +} diff --git a/chrome/browser/extensions/extension_module.h b/chrome/browser/extensions/extension_module.h index 21227a2..a7471e3 100644 --- a/chrome/browser/extensions/extension_module.h +++ b/chrome/browser/extensions/extension_module.h @@ -12,9 +12,22 @@ class ExtensionPrefs; class SetUpdateUrlDataFunction : public SyncExtensionFunction { protected: - ExtensionPrefs* extension_prefs(); virtual bool RunImpl(); DECLARE_EXTENSION_FUNCTION_NAME("extension.setUpdateUrlData"); + + private: + ExtensionPrefs* extension_prefs(); +}; + +class IsAllowedIncognitoAccessFunction : public SyncExtensionFunction { + protected: + virtual bool RunImpl(); + DECLARE_EXTENSION_FUNCTION_NAME("extension.isAllowedIncognitoAccess"); }; +class IsAllowedFileSchemeAccessFunction : public SyncExtensionFunction { + protected: + virtual bool RunImpl(); + DECLARE_EXTENSION_FUNCTION_NAME("extension.isAllowedFileSchemeAccess"); +}; #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MODULE_H__ diff --git a/chrome/browser/extensions/extension_module_apitest.cc b/chrome/browser/extensions/extension_module_apitest.cc index 718c422..748b132 100644 --- a/chrome/browser/extensions/extension_module_apitest.cc +++ b/chrome/browser/extensions/extension_module_apitest.cc @@ -7,6 +7,21 @@ class ExtensionModuleApiTest : public ExtensionApiTest { }; -IN_PROC_BROWSER_TEST_F(ExtensionModuleApiTest, Basics) { - ASSERT_TRUE(RunExtensionTest("extension_module")) << message_; +IN_PROC_BROWSER_TEST_F(ExtensionModuleApiTest, CognitoFile) { + ASSERT_TRUE(RunExtensionTest("extension_module/cognito_file")) << message_; +} + +IN_PROC_BROWSER_TEST_F(ExtensionModuleApiTest, IncognitoFile) { + ASSERT_TRUE(RunExtensionTestIncognito( + "extension_module/incognito_file")) << message_; +} + +IN_PROC_BROWSER_TEST_F(ExtensionModuleApiTest, CognitoNoFile) { + ASSERT_TRUE(RunExtensionTestNoFileAccess( + "extension_module/cognito_nofile")) << message_; +} + +IN_PROC_BROWSER_TEST_F(ExtensionModuleApiTest, IncognitoNoFile) { + ASSERT_TRUE(RunExtensionTestIncognitoNoFileAccess( + "extension_module/incognito_nofile")) << message_; } diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json index 88c566d..ffe741d 100644 --- a/chrome/common/extensions/api/extension_api.json +++ b/chrome/common/extensions/api/extension_api.json @@ -191,6 +191,42 @@ } }, { + "name": "isAllowedIncognitoAccess", + "type": "function", + "description": "Retrieves the state of the extension's access to Incognito-mode (as determined by the user-controlled 'Allowed in Incognito' checkbox.", + "parameters": [ + { + "type": "function", + "name": "callback", + "parameters": [ + { + "name": "isAllowedAccess", + "type": "boolean", + "description": "True if the extension has access to Incognito mode, false otherwise." + } + ] + } + ] + }, + { + "name": "isAllowedFileSchemeAccess", + "type": "function", + "description": "Retrieves the state of the extension's access to the 'file://' scheme (as determined by the user-controlled 'Allow access to File URLs' checkbox.", + "parameters": [ + { + "type": "function", + "name": "callback", + "parameters": [ + { + "name": "isAllowedAccess", + "type": "boolean", + "description": "True if the extension can access the 'file://' scheme, false otherwise." + } + ] + } + ] + }, + { "name": "setUpdateUrlData", "type": "function", "description": "Sets the value of the ap CGI parameter used in the extension's update URL. This value is ignored for extensions that are hosted in the Chrome Extension Gallery.", diff --git a/chrome/common/extensions/docs/extension.html b/chrome/common/extensions/docs/extension.html index 9e99f0e..149f08f 100644 --- a/chrome/common/extensions/docs/extension.html +++ b/chrome/common/extensions/docs/extension.html @@ -294,6 +294,10 @@ </li><li> <a href="#method-getViews">getViews</a> </li><li> + <a href="#method-isAllowedFileSchemeAccess">isAllowedFileSchemeAccess</a> + </li><li> + <a href="#method-isAllowedIncognitoAccess">isAllowedIncognitoAccess</a> + </li><li> <a href="#method-sendRequest">sendRequest</a> </li><li> <a href="#method-setUpdateUrlData">setUpdateUrlData</a> @@ -1813,6 +1817,398 @@ For details, see </div> <!-- /description --> </div><div class="apiItem"> + <a name="method-isAllowedFileSchemeAccess"></a> <!-- method-anchor --> + <h4>isAllowedFileSchemeAccess</h4> + + <div class="summary"><span style="display: none; ">void</span> + <!-- Note: intentionally longer 80 columns --> + <span>chrome.extension.isAllowedFileSchemeAccess</span>(<span class="null"><span style="display: none; ">, </span><span>function</span> + <var><span>callback</span></var></span>)</div> + + <div class="description"> + <p class="todo" style="display: none; ">Undocumented.</p> + <p>Retrieves the state of the extension's access to the 'file://' scheme (as determined by the user-controlled 'Allow access to File URLs' checkbox.</p> + + <!-- PARAMETERS --> + <h4>Parameters</h4> + <dl> + <div> + <div> + <dt> + <var>callback</var> + <em> + + <!-- TYPE --> + <div style="display:inline"> + ( + <span class="optional" style="display: none; ">optional</span> + <span class="enum" style="display: none; ">enumerated</span> + <span id="typeTemplate"> + <span style="display: none; "> + <a> Type</a> + </span> + <span> + <span style="display: none; "> + array of <span><span></span></span> + </span> + <span>function</span> + <span style="display: none; "></span> + </span> + </span> + ) + </div> + + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <dd style="display: none; "> + Description of this parameter from the json schema. + </dd> + <dd style="display: none; "> + This parameter was added in version + <b><span></span></b>. + You must omit this parameter in earlier versions, + and you may omit it in any version. If you require this + parameter, the manifest key + <a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a> + can ensure that your extension won't be run in an earlier browser version. + </dd> + + <!-- OBJECT PROPERTIES --> + <dd style="display: none; "> + <dl> + <div> + <div> + </div> + </div> + </dl> + </dd> + + <!-- OBJECT METHODS --> + <dd style="display: none; "> + <div></div> + </dd> + + <!-- OBJECT EVENT FIELDS --> + <dd style="display: none; "> + <div></div> + </dd> + + <!-- FUNCTION PARAMETERS --> + <dd style="display: none; "> + <div></div> + </dd> + + </div> + </div> + </dl> + + <!-- RETURNS --> + <h4 style="display: none; ">Returns</h4> + <dl> + <div style="display: none; "> + <div> + </div> + </div> + </dl> + + <!-- CALLBACK --> + <div> + <div> + <h4>Callback function</h4> + <p> + The callback <em>parameter</em> should specify a function + that looks like this: + </p> + <p style="display: none; "> + If you specify the <em>callback</em> parameter, it should + specify a function that looks like this: + </p> + + <!-- Note: intentionally longer 80 columns --> + <pre>function(<span>boolean isAllowedAccess</span>) <span class="subdued">{...}</span>;</pre> + <dl> + <div> + <div> + <dt> + <var>isAllowedAccess</var> + <em> + + <!-- TYPE --> + <div style="display:inline"> + ( + <span class="optional" style="display: none; ">optional</span> + <span class="enum" style="display: none; ">enumerated</span> + <span id="typeTemplate"> + <span style="display: none; "> + <a> Type</a> + </span> + <span> + <span style="display: none; "> + array of <span><span></span></span> + </span> + <span>boolean</span> + <span style="display: none; "></span> + </span> + </span> + ) + </div> + + </em> + </dt> + <dd class="todo" style="display: none; "> + Undocumented. + </dd> + <dd>True if the extension can access the 'file://' scheme, false otherwise.</dd> + <dd style="display: none; "> + This parameter was added in version + <b><span></span></b>. + You must omit this parameter in earlier versions, + and you may omit it in any version. If you require this + parameter, the manifest key + <a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a> + can ensure that your extension won't be run in an earlier browser version. + </dd> + + <!-- OBJECT PROPERTIES --> + <dd style="display: none; "> + <dl> + <div> + <div> + </div> + </div> + </dl> + </dd> + + <!-- OBJECT METHODS --> + <dd style="display: none; "> + <div></div> + </dd> + + <!-- OBJECT EVENT FIELDS --> + <dd style="display: none; "> + <div></div> + </dd> + + <!-- FUNCTION PARAMETERS --> + <dd style="display: none; "> + <div></div> + </dd> + + </div> + </div> + </dl> + </div> + </div> + + <!-- MIN_VERSION --> + <p style="display: none; "> + This function was added in version <b><span></span></b>. + If you require this function, the manifest key + <a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a> + can ensure that your extension won't be run in an earlier browser version. + </p> + </div> <!-- /description --> + + </div><div class="apiItem"> + <a name="method-isAllowedIncognitoAccess"></a> <!-- method-anchor --> + <h4>isAllowedIncognitoAccess</h4> + + <div class="summary"><span style="display: none; ">void</span> + <!-- Note: intentionally longer 80 columns --> + <span>chrome.extension.isAllowedIncognitoAccess</span>(<span class="null"><span style="display: none; ">, </span><span>function</span> + <var><span>callback</span></var></span>)</div> + + <div class="description"> + <p class="todo" style="display: none; ">Undocumented.</p> + <p>Retrieves the state of the extension's access to Incognito-mode (as determined by the user-controlled 'Allowed in Incognito' checkbox.</p> + + <!-- PARAMETERS --> + <h4>Parameters</h4> + <dl> + <div> + <div> + <dt> + <var>callback</var> + <em> + + <!-- TYPE --> + <div style="display:inline"> + ( + <span class="optional" style="display: none; ">optional</span> + <span class="enum" style="display: none; ">enumerated</span> + <span id="typeTemplate"> + <span style="display: none; "> + <a> Type</a> + </span> + <span> + <span style="display: none; "> + array of <span><span></span></span> + </span> + <span>function</span> + <span style="display: none; "></span> + </span> + </span> + ) + </div> + + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <dd style="display: none; "> + Description of this parameter from the json schema. + </dd> + <dd style="display: none; "> + This parameter was added in version + <b><span></span></b>. + You must omit this parameter in earlier versions, + and you may omit it in any version. If you require this + parameter, the manifest key + <a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a> + can ensure that your extension won't be run in an earlier browser version. + </dd> + + <!-- OBJECT PROPERTIES --> + <dd style="display: none; "> + <dl> + <div> + <div> + </div> + </div> + </dl> + </dd> + + <!-- OBJECT METHODS --> + <dd style="display: none; "> + <div></div> + </dd> + + <!-- OBJECT EVENT FIELDS --> + <dd style="display: none; "> + <div></div> + </dd> + + <!-- FUNCTION PARAMETERS --> + <dd style="display: none; "> + <div></div> + </dd> + + </div> + </div> + </dl> + + <!-- RETURNS --> + <h4 style="display: none; ">Returns</h4> + <dl> + <div style="display: none; "> + <div> + </div> + </div> + </dl> + + <!-- CALLBACK --> + <div> + <div> + <h4>Callback function</h4> + <p> + The callback <em>parameter</em> should specify a function + that looks like this: + </p> + <p style="display: none; "> + If you specify the <em>callback</em> parameter, it should + specify a function that looks like this: + </p> + + <!-- Note: intentionally longer 80 columns --> + <pre>function(<span>boolean isAllowedAccess</span>) <span class="subdued">{...}</span>;</pre> + <dl> + <div> + <div> + <dt> + <var>isAllowedAccess</var> + <em> + + <!-- TYPE --> + <div style="display:inline"> + ( + <span class="optional" style="display: none; ">optional</span> + <span class="enum" style="display: none; ">enumerated</span> + <span id="typeTemplate"> + <span style="display: none; "> + <a> Type</a> + </span> + <span> + <span style="display: none; "> + array of <span><span></span></span> + </span> + <span>boolean</span> + <span style="display: none; "></span> + </span> + </span> + ) + </div> + + </em> + </dt> + <dd class="todo" style="display: none; "> + Undocumented. + </dd> + <dd>True if the extension has access to Incognito mode, false otherwise.</dd> + <dd style="display: none; "> + This parameter was added in version + <b><span></span></b>. + You must omit this parameter in earlier versions, + and you may omit it in any version. If you require this + parameter, the manifest key + <a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a> + can ensure that your extension won't be run in an earlier browser version. + </dd> + + <!-- OBJECT PROPERTIES --> + <dd style="display: none; "> + <dl> + <div> + <div> + </div> + </div> + </dl> + </dd> + + <!-- OBJECT METHODS --> + <dd style="display: none; "> + <div></div> + </dd> + + <!-- OBJECT EVENT FIELDS --> + <dd style="display: none; "> + <div></div> + </dd> + + <!-- FUNCTION PARAMETERS --> + <dd style="display: none; "> + <div></div> + </dd> + + </div> + </div> + </dl> + </div> + </div> + + <!-- MIN_VERSION --> + <p style="display: none; "> + This function was added in version <b><span></span></b>. + If you require this function, the manifest key + <a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a> + can ensure that your extension won't be run in an earlier browser version. + </p> + </div> <!-- /description --> + + </div><div class="apiItem"> <a name="method-sendRequest"></a> <!-- method-anchor --> <h4>sendRequest</h4> diff --git a/chrome/common/extensions/docs/samples.json b/chrome/common/extensions/docs/samples.json index e293a2e..4a9d46b 100644 --- a/chrome/common/extensions/docs/samples.json +++ b/chrome/common/extensions/docs/samples.json @@ -78,6 +78,8 @@ "chrome.extension.getToolstrips": "extension.html#method-getToolstrips", "chrome.extension.getURL": "extension.html#method-getURL", "chrome.extension.getViews": "extension.html#method-getViews", + "chrome.extension.isAllowedFileSchemeAccess": "extension.html#method-isAllowedFileSchemeAccess", + "chrome.extension.isAllowedIncognitoAccess": "extension.html#method-isAllowedIncognitoAccess", "chrome.extension.onConnect": "extension.html#event-onConnect", "chrome.extension.onConnectExternal": "extension.html#event-onConnectExternal", "chrome.extension.onRequest": "extension.html#event-onRequest", diff --git a/chrome/renderer/resources/renderer_extension_bindings.js b/chrome/renderer/resources/renderer_extension_bindings.js index 422b794..82795e7 100644 --- a/chrome/renderer/resources/renderer_extension_bindings.js +++ b/chrome/renderer/resources/renderer_extension_bindings.js @@ -331,6 +331,8 @@ var chrome = chrome || {}; "extension.getExtensionTabs", "extension.getToolstrips", "extension.getViews", + "extension.isAllowedIncognitoAccess", + "extension.isAllowedFileSchemeAccess", "extension.onConnectExternal", "extension.onRequestExternal", "extension.setUpdateUrlData", diff --git a/chrome/test/data/extensions/api_test/extension_module/manifest.json b/chrome/test/data/extensions/api_test/extension_module/cognito_file/manifest.json index 4b3caa8..cfc99c0 100644 --- a/chrome/test/data/extensions/api_test/extension_module/manifest.json +++ b/chrome/test/data/extensions/api_test/extension_module/cognito_file/manifest.json @@ -1,6 +1,6 @@ { "name": "chrome.extension", "version": "0.1", - "description": "end-to-end browser test for some chrome.extension API", + "description": "end-to-end browser test for some chrome.extension API: cognito mode.", "background_page": "test.html" } diff --git a/chrome/test/data/extensions/api_test/extension_module/test.html b/chrome/test/data/extensions/api_test/extension_module/cognito_file/test.html index 46f4d74..46f4d74 100644 --- a/chrome/test/data/extensions/api_test/extension_module/test.html +++ b/chrome/test/data/extensions/api_test/extension_module/cognito_file/test.html diff --git a/chrome/test/data/extensions/api_test/extension_module/test.js b/chrome/test/data/extensions/api_test/extension_module/cognito_file/test.js index 762ba45..2829fde 100644 --- a/chrome/test/data/extensions/api_test/extension_module/test.js +++ b/chrome/test/data/extensions/api_test/extension_module/cognito_file/test.js @@ -3,7 +3,7 @@ // found in the LICENSE file. // extension api test -// browser_tests.exe --gtest_filter=ExtensionModuleApiTest.Basics +// browser_tests.exe --gtest_filter=ExtensionModuleApiTest.CognitoFile chrome.test.runTests([ function testUpdateUrlData() { @@ -39,5 +39,15 @@ chrome.test.runTests([ chrome.extension.setUpdateUrlData('a=1&b=2&foo'); chrome.test.succeed(); + }, + function testPermissions() { + chrome.extension.isAllowedIncognitoAccess( + chrome.test.callbackPass(function(hasAccess) { + chrome.test.assertFalse(hasAccess); + })); + chrome.extension.isAllowedFileSchemeAccess( + chrome.test.callbackPass(function(hasAccess) { + chrome.test.assertTrue(hasAccess); + })); } ]); diff --git a/chrome/test/data/extensions/api_test/extension_module/cognito_nofile/manifest.json b/chrome/test/data/extensions/api_test/extension_module/cognito_nofile/manifest.json new file mode 100644 index 0000000..cfc99c0 --- /dev/null +++ b/chrome/test/data/extensions/api_test/extension_module/cognito_nofile/manifest.json @@ -0,0 +1,6 @@ +{ + "name": "chrome.extension", + "version": "0.1", + "description": "end-to-end browser test for some chrome.extension API: cognito mode.", + "background_page": "test.html" +} diff --git a/chrome/test/data/extensions/api_test/extension_module/cognito_nofile/test.html b/chrome/test/data/extensions/api_test/extension_module/cognito_nofile/test.html new file mode 100644 index 0000000..46f4d74 --- /dev/null +++ b/chrome/test/data/extensions/api_test/extension_module/cognito_nofile/test.html @@ -0,0 +1 @@ +<script src="test.js"></script> diff --git a/chrome/test/data/extensions/api_test/extension_module/cognito_nofile/test.js b/chrome/test/data/extensions/api_test/extension_module/cognito_nofile/test.js new file mode 100644 index 0000000..3dd027a --- /dev/null +++ b/chrome/test/data/extensions/api_test/extension_module/cognito_nofile/test.js @@ -0,0 +1,53 @@ +// Copyright (c) 2010 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. + +// extension api test +// browser_tests.exe --gtest_filter=ExtensionModuleApiTest.CognitoNofile + +chrome.test.runTests([ + function testUpdateUrlData() { + // Data string must not be too long. + try { + var data = + '01234567890123456789012345678901234567890123456789' + + '01234567890123456789012345678901234567890123456789' + // 100 + '01234567890123456789012345678901234567890123456789' + + '01234567890123456789012345678901234567890123456789' + // 200 + '01234567890123456789012345678901234567890123456789' + + '01234567890123456789012345678901234567890123456789' + // 300 + '01234567890123456789012345678901234567890123456789' + + '01234567890123456789012345678901234567890123456789' + // 400 + '01234567890123456789012345678901234567890123456789' + + '01234567890123456789012345678901234567890123456789' + // 500 + '01234567890123456789012345678901234567890123456789' + + '01234567890123456789012345678901234567890123456789' + // 600 + '01234567890123456789012345678901234567890123456789' + + '01234567890123456789012345678901234567890123456789' + // 700 + '01234567890123456789012345678901234567890123456789' + + '01234567890123456789012345678901234567890123456789' + // 800 + '01234567890123456789012345678901234567890123456789' + + '01234567890123456789012345678901234567890123456789' + // 900 + '01234567890123456789012345678901234567890123456789' + + '01234567890123456789012345678901234567890123456789' + // 1000 + '01234567890123456789012345678901234567890123456789'; + chrome.extension.setUpdateUrlData(data); + // Should not reach this line since the above call throws. + chrome.test.fail(); + } catch(ex) { + } + + chrome.extension.setUpdateUrlData('a=1&b=2&foo'); + chrome.test.succeed(); + }, + function testPermissions() { + chrome.extension.isAllowedIncognitoAccess( + chrome.test.callbackPass(function(hasAccess) { + chrome.test.assertFalse(hasAccess); + })); + chrome.extension.isAllowedFileSchemeAccess( + chrome.test.callbackPass(function(hasAccess) { + chrome.test.assertFalse(hasAccess); + })); + } +]); diff --git a/chrome/test/data/extensions/api_test/extension_module/incognito_file/manifest.json b/chrome/test/data/extensions/api_test/extension_module/incognito_file/manifest.json new file mode 100644 index 0000000..b491fa8 --- /dev/null +++ b/chrome/test/data/extensions/api_test/extension_module/incognito_file/manifest.json @@ -0,0 +1,6 @@ +{ + "name": "chrome.extension", + "version": "0.1", + "description": "end-to-end browser test for some chrome.extension API: incognito mode", + "background_page": "test.html" +} diff --git a/chrome/test/data/extensions/api_test/extension_module/incognito_file/test.html b/chrome/test/data/extensions/api_test/extension_module/incognito_file/test.html new file mode 100644 index 0000000..46f4d74 --- /dev/null +++ b/chrome/test/data/extensions/api_test/extension_module/incognito_file/test.html @@ -0,0 +1 @@ +<script src="test.js"></script> diff --git a/chrome/test/data/extensions/api_test/extension_module/incognito_file/test.js b/chrome/test/data/extensions/api_test/extension_module/incognito_file/test.js new file mode 100644 index 0000000..5003fe3 --- /dev/null +++ b/chrome/test/data/extensions/api_test/extension_module/incognito_file/test.js @@ -0,0 +1,19 @@ +// Copyright (c) 2010 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. + +// extension api test +// browser_tests.exe --gtest_filter=ExtensionModuleApiTest.IncognitoFile + +chrome.test.runTests([ + function testPermissions() { + chrome.extension.isAllowedIncognitoAccess( + chrome.test.callbackPass(function(hasAccess) { + chrome.test.assertTrue(hasAccess); + })); + chrome.extension.isAllowedFileSchemeAccess( + chrome.test.callbackPass(function(hasAccess) { + chrome.test.assertTrue(hasAccess); + })); + } +]); diff --git a/chrome/test/data/extensions/api_test/extension_module/incognito_nofile/manifest.json b/chrome/test/data/extensions/api_test/extension_module/incognito_nofile/manifest.json new file mode 100644 index 0000000..b491fa8 --- /dev/null +++ b/chrome/test/data/extensions/api_test/extension_module/incognito_nofile/manifest.json @@ -0,0 +1,6 @@ +{ + "name": "chrome.extension", + "version": "0.1", + "description": "end-to-end browser test for some chrome.extension API: incognito mode", + "background_page": "test.html" +} diff --git a/chrome/test/data/extensions/api_test/extension_module/incognito_nofile/test.html b/chrome/test/data/extensions/api_test/extension_module/incognito_nofile/test.html new file mode 100644 index 0000000..46f4d74 --- /dev/null +++ b/chrome/test/data/extensions/api_test/extension_module/incognito_nofile/test.html @@ -0,0 +1 @@ +<script src="test.js"></script> diff --git a/chrome/test/data/extensions/api_test/extension_module/incognito_nofile/test.js b/chrome/test/data/extensions/api_test/extension_module/incognito_nofile/test.js new file mode 100644 index 0000000..9d56c24 --- /dev/null +++ b/chrome/test/data/extensions/api_test/extension_module/incognito_nofile/test.js @@ -0,0 +1,19 @@ +// Copyright (c) 2010 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. + +// extension api test +// browser_tests.exe --gtest_filter=ExtensionModuleApiTest.IncognitoNofile + +chrome.test.runTests([ + function testPermissions() { + chrome.extension.isAllowedIncognitoAccess( + chrome.test.callbackPass(function(hasAccess) { + chrome.test.assertTrue(hasAccess); + })); + chrome.extension.isAllowedFileSchemeAccess( + chrome.test.callbackPass(function(hasAccess) { + chrome.test.assertFalse(hasAccess); + })); + } +]); |