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

Unified Diff: extensions/renderer/user_script_set_manager.cc

Issue 404613006: Declarative content scripts: Renderer-side: per-extension shared memory regions (lazily loaded) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix use of scoped and linked ptrs, better documentation Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: extensions/renderer/user_script_set_manager.cc
diff --git a/extensions/renderer/user_script_set_manager.cc b/extensions/renderer/user_script_set_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6db6e67cb5566f139020c7ad4d4fc5a69af304d9
--- /dev/null
+++ b/extensions/renderer/user_script_set_manager.cc
@@ -0,0 +1,102 @@
+// Copyright 2014 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.
+
+#include "extensions/renderer/user_script_set_manager.h"
+
+#include "content/public/renderer/render_thread.h"
+#include "extensions/common/extension_messages.h"
+#include "extensions/renderer/dispatcher.h"
+#include "extensions/renderer/user_script_set.h"
+#include "ipc/ipc_message.h"
+#include "ipc/ipc_message_macros.h"
+#include "third_party/WebKit/public/web/WebFrame.h"
+
+namespace extensions {
+
+UserScriptSetManager::UserScriptSetManager(const ExtensionSet* extensions)
+ : static_scripts_(extensions), extensions_(extensions) {
+ content::RenderThread::Get()->AddObserver(this);
+}
+
+UserScriptSetManager::~UserScriptSetManager() {
+}
+
+void UserScriptSetManager::AddObserver(Observer* observer) {
+ observers_.AddObserver(observer);
+}
+
+void UserScriptSetManager::RemoveObserver(Observer* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+bool UserScriptSetManager::OnControlMessageReceived(
+ const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(UserScriptSetManager, message)
+ IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts)
Devlin 2014/07/28 18:15:27 nit: Even though git cl format doesn't like it, we
Mark Dittmer 2014/07/29 16:59:31 Done.
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+const UserScriptSet* UserScriptSetManager::ProgrammaticScripts(
+ const ExtensionId& extension_id) {
+ UserScriptSetMap::const_iterator it =
+ programmatic_scripts_.find(extension_id);
+ if (it == programmatic_scripts_.end()) {
Devlin 2014/07/28 18:15:28 nit: no brackets - although I'd probably opt for a
Mark Dittmer 2014/07/29 16:59:31 Done.
+ return NULL;
+ }
+
+ return it->second.get();
+}
+
+void UserScriptSetManager::GetAllInjections(
+ ScopedVector<ScriptInjection>* injections,
+ blink::WebFrame* web_frame,
+ int tab_id,
+ UserScript::RunLocation run_location) {
+ static_scripts_.GetInjections(injections, web_frame, tab_id, run_location);
+ for (UserScriptSetMap::iterator it = programmatic_scripts_.begin();
+ it != programmatic_scripts_.end();
+ ++it) {
+ it->second->GetInjections(injections, web_frame, tab_id, run_location);
+ }
+}
+
+void UserScriptSetManager::GetAllActiveExtensionIds(
+ std::set<std::string>* ids) const {
Devlin 2014/07/28 18:15:28 Just for safety, let's throw in a DCHECK(ids) here
Mark Dittmer 2014/07/29 16:59:31 Done.
+ static_scripts_.GetActiveExtensionIds(ids);
+ for (UserScriptSetMap::const_iterator it = programmatic_scripts_.begin();
+ it != programmatic_scripts_.end();
+ ++it) {
+ it->second->GetActiveExtensionIds(ids);
+ }
+}
+
+void UserScriptSetManager::OnUpdateUserScripts(
+ base::SharedMemoryHandle shared_memory,
+ const ExtensionId& extension_id,
+ const std::set<std::string>& changed_extensions) {
+ UserScriptSet* scripts = NULL;
+ if (extension_id != "") {
Devlin 2014/07/28 18:15:27 nit: if (!extension_id.empty())
Mark Dittmer 2014/07/29 16:59:30 Done.
+ if (programmatic_scripts_.find(extension_id) !=
Devlin 2014/07/28 18:15:27 This strikes me as wrong. if there IS an entry, re
Mark Dittmer 2014/07/29 16:59:30 Done.
+ programmatic_scripts_.end()) {
+ scripts = new UserScriptSet(extensions_);
+ programmatic_scripts_[extension_id] = make_linked_ptr(scripts);
+ } else {
+ scripts = programmatic_scripts_[extension_id].get();
+ }
+ } else {
+ scripts = &static_scripts_;
+ }
+ if (scripts &&
Devlin 2014/07/28 18:15:27 sanity check: Can |scripts| ever be NULL? It look
Mark Dittmer 2014/07/29 16:59:30 Done.
+ scripts->OnUpdateUserScripts(shared_memory, changed_extensions)) {
+ FOR_EACH_OBSERVER(
+ Observer,
+ observers_,
+ OnUserScriptsUpdated(changed_extensions, scripts->scripts_.get()));
+ }
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698