summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/common/extensions')
-rw-r--r--chrome/common/extensions/docs/content_scripts.html8
-rw-r--r--chrome/common/extensions/docs/examples/api/messaging/timer/page.js18
-rw-r--r--chrome/common/extensions/docs/static/content_scripts.html8
-rw-r--r--chrome/common/extensions/extension.cc15
-rw-r--r--chrome/common/extensions/extension_constants.cc3
-rw-r--r--chrome/common/extensions/extension_constants.h2
-rw-r--r--chrome/common/extensions/user_script.cc6
-rw-r--r--chrome/common/extensions/user_script.h11
8 files changed, 59 insertions, 12 deletions
diff --git a/chrome/common/extensions/docs/content_scripts.html b/chrome/common/extensions/docs/content_scripts.html
index 34b7d05..c3b720c 100644
--- a/chrome/common/extensions/docs/content_scripts.html
+++ b/chrome/common/extensions/docs/content_scripts.html
@@ -409,6 +409,14 @@ learn about the
<b>NOTE:</b> In <code>document_idle</code>, content scripts may not necessarily receive the window.onload event, because they may run after it has
already fired. In most cases, listening for the onload event is unnecessary for content scripts running at <code>document_idle</code> because they are guaranteed to run after the DOM is complete. If your script definitely needs to run after <code>window.onload</code> you can check if it has already fired by using the <code><a href="http://www.whatwg.org/specs/web-apps/current-work/#dom-document-readystate">document.readyState</a></code> property.</td>
</tr>
+ <tr>
+ <td>all_frames</td>
+ <td>boolean</td>
+ <td><em>Optional.</em>
+ Controls whether the content script runs in all frames of the matching page, or only the top frame.
+ <br><br>
+ Defaults to <code>false</code>, meaning that only the top frame is matched.</td>
+ </tr>
</tbody></table>
diff --git a/chrome/common/extensions/docs/examples/api/messaging/timer/page.js b/chrome/common/extensions/docs/examples/api/messaging/timer/page.js
index 4914aab..92f8df3 100644
--- a/chrome/common/extensions/docs/examples/api/messaging/timer/page.js
+++ b/chrome/common/extensions/docs/examples/api/messaging/timer/page.js
@@ -1,12 +1,10 @@
-if (window == top) {
- chrome.extension.onConnect.addListener(function(port) {
- port.onMessage.addListener(function(msg) {
- port.postMessage({counter: msg.counter+1});
- });
+chrome.extension.onConnect.addListener(function(port) {
+ port.onMessage.addListener(function(msg) {
+ port.postMessage({counter: msg.counter+1});
});
+});
- chrome.extension.onRequest.addListener(
- function(request, sender, sendResponse) {
- sendResponse({counter: request.counter+1});
- });
-}
+chrome.extension.onRequest.addListener(
+ function(request, sender, sendResponse) {
+ sendResponse({counter: request.counter+1});
+ });
diff --git a/chrome/common/extensions/docs/static/content_scripts.html b/chrome/common/extensions/docs/static/content_scripts.html
index ffd3c89..3e52078 100644
--- a/chrome/common/extensions/docs/static/content_scripts.html
+++ b/chrome/common/extensions/docs/static/content_scripts.html
@@ -127,6 +127,14 @@ learn about the
<b>NOTE:</b> In <code>document_idle</code>, content scripts may not necessarily receive the window.onload event, because they may run after it has
already fired. In most cases, listening for the onload event is unnecessary for content scripts running at <code>document_idle</code> because they are guaranteed to run after the DOM is complete. If your script definitely needs to run after <code>window.onload</code> you can check if it has already fired by using the <code><a href="http://www.whatwg.org/specs/web-apps/current-work/#dom-document-readystate">document.readyState</a></code> property.</td>
</tr>
+ <tr>
+ <td>all_frames</td>
+ <td>boolean</td>
+ <td><em>Optional.</em>
+ Controls whether the content script runs in all frames of the matching page, or only the top frame.
+ <br><br>
+ Defaults to <code>false</code>, meaning that only the top frame is matched.</td>
+ </tr>
</table>
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index 72ebe24..34975f9 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -217,6 +217,17 @@ bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script,
}
}
+ // all frames
+ if (content_script->HasKey(keys::kAllFrames)) {
+ bool all_frames = false;
+ if (!content_script->GetBoolean(keys::kAllFrames, &all_frames)) {
+ *error = ExtensionErrorUtils::FormatErrorMessage(
+ errors::kInvalidAllFrames, IntToString(definition_index));
+ return false;
+ }
+ result->set_match_all_frames(all_frames);
+ }
+
// matches
ListValue* matches = NULL;
if (!content_script->GetList(keys::kMatches, &matches)) {
@@ -991,8 +1002,10 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id,
if (!LoadUserScriptHelper(content_script, i, error, &script))
return false; // Failed to parse script context definition
script.set_extension_id(id());
- if (converted_from_user_script_)
+ if (converted_from_user_script_) {
script.set_emulate_greasemonkey(true);
+ script.set_match_all_frames(true); // greasemonkey matches all frames
+ }
content_scripts_.push_back(script);
}
}
diff --git a/chrome/common/extensions/extension_constants.cc b/chrome/common/extensions/extension_constants.cc
index f89e23f..54588e5a 100644
--- a/chrome/common/extensions/extension_constants.cc
+++ b/chrome/common/extensions/extension_constants.cc
@@ -6,6 +6,7 @@
namespace extension_manifest_keys {
+const wchar_t* kAllFrames = L"all_frames";
const wchar_t* kBackground = L"background_page";
const wchar_t* kBrowserAction = L"browser_action";
const wchar_t* kChromeURLOverrides = L"chrome_url_overrides";
@@ -65,6 +66,8 @@ const char* kPageActionTypePermanent = "permanent";
// printf because we want to unit test them and scanf is hard to make
// cross-platform.
namespace extension_manifest_errors {
+const char* kInvalidAllFrames =
+ "Invalid value for 'content_scripts[*].all_frames'.";
const char* kInvalidBrowserAction =
"Invalid value for 'browser_action'.";
const char* kInvalidChromeURLOverrides =
diff --git a/chrome/common/extensions/extension_constants.h b/chrome/common/extensions/extension_constants.h
index 17ca5cb..01d1ff4 100644
--- a/chrome/common/extensions/extension_constants.h
+++ b/chrome/common/extensions/extension_constants.h
@@ -7,6 +7,7 @@
// Keys used in JSON representation of extensions.
namespace extension_manifest_keys {
+ extern const wchar_t* kAllFrames;
extern const wchar_t* kBackground;
extern const wchar_t* kBrowserAction;
extern const wchar_t* kChromeURLOverrides;
@@ -89,6 +90,7 @@ namespace extension_manifest_errors {
extern const char* kInvalidPrivacyBlacklists;
extern const char* kInvalidPrivacyBlacklistsPath;
+ extern const char* kInvalidAllFrames;
extern const char* kInvalidBackground;
extern const char* kInvalidRunAt;
extern const char* kInvalidSignature;
diff --git a/chrome/common/extensions/user_script.cc b/chrome/common/extensions/user_script.cc
index 10d0b60..96f7dd4 100644
--- a/chrome/common/extensions/user_script.cc
+++ b/chrome/common/extensions/user_script.cc
@@ -84,6 +84,9 @@ void UserScript::Pickle(::Pickle* pickle) const {
// Write Greasemonkey emulation.
pickle->WriteBool(emulate_greasemonkey());
+ // Write match all frames
+ pickle->WriteBool(match_all_frames());
+
// Write globs.
std::vector<std::string>::const_iterator glob;
pickle->WriteSize(globs_.size());
@@ -130,6 +133,9 @@ void UserScript::Unpickle(const ::Pickle& pickle, void** iter) {
// Read Greasemonkey emulation.
CHECK(pickle.ReadBool(iter, &emulate_greasemonkey_));
+ // Read match all frames
+ CHECK(pickle.ReadBool(iter, &match_all_frames_));
+
// Read globs.
size_t num_globs = 0;
CHECK(pickle.ReadSize(iter, &num_globs));
diff --git a/chrome/common/extensions/user_script.h b/chrome/common/extensions/user_script.h
index adcfa3f..b7093c1 100644
--- a/chrome/common/extensions/user_script.h
+++ b/chrome/common/extensions/user_script.h
@@ -102,7 +102,8 @@ class UserScript {
// Constructor. Default the run location to document end, which is like
// Greasemonkey and probably more useful for typical scripts.
UserScript()
- : run_location_(DOCUMENT_IDLE), emulate_greasemonkey_(false) {
+ : run_location_(DOCUMENT_IDLE), emulate_greasemonkey_(false),
+ match_all_frames_(false) {
}
const std::string& name_space() const { return name_space_; }
@@ -126,6 +127,10 @@ class UserScript {
bool emulate_greasemonkey() const { return emulate_greasemonkey_; }
void set_emulate_greasemonkey(bool val) { emulate_greasemonkey_ = val; }
+ // Whether to match all frames, or only the top one.
+ bool match_all_frames() const { return match_all_frames_; }
+ void set_match_all_frames(bool val) { match_all_frames_ = val; }
+
// The globs, if any, that determine which pages this script runs against.
// These are only used with "standalone" Greasemonkey-like user scripts.
const std::vector<std::string>& globs() const { return globs_; }
@@ -209,6 +214,10 @@ class UserScript {
// Whether we should try to emulate Greasemonkey's APIs when running this
// script.
bool emulate_greasemonkey_;
+
+ // Whether the user script should run in all frames, or only just the top one.
+ // Defaults to false.
+ bool match_all_frames_;
};
typedef std::vector<UserScript> UserScriptList;