| Index: extensions/browser/renderer_startup_helper.cc
|
| diff --git a/extensions/browser/renderer_startup_helper.cc b/extensions/browser/renderer_startup_helper.cc
|
| index bd2d0fb2360e634fd85a41c8dfb3c67ef715ce82..cff496b4a276e003affb24e1f87649aa3b7ca7e0 100644
|
| --- a/extensions/browser/renderer_startup_helper.cc
|
| +++ b/extensions/browser/renderer_startup_helper.cc
|
| @@ -6,14 +6,17 @@
|
|
|
| #include "base/debug/alias.h"
|
| #include "base/debug/dump_without_crashing.h"
|
| +#include "base/stl_util.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/values.h"
|
| #include "components/keyed_service/content/browser_context_dependency_manager.h"
|
| +#include "content/public/browser/browser_context.h"
|
| #include "content/public/browser/notification_service.h"
|
| #include "content/public/browser/notification_types.h"
|
| #include "content/public/browser/render_process_host.h"
|
| #include "extensions/browser/extension_function_dispatcher.h"
|
| #include "extensions/browser/extension_registry.h"
|
| +#include "extensions/browser/extension_util.h"
|
| #include "extensions/browser/extensions_browser_client.h"
|
| #include "extensions/browser/guest_view/web_view/web_view_guest.h"
|
| #include "extensions/common/extension_messages.h"
|
| @@ -27,6 +30,27 @@ using content::BrowserContext;
|
|
|
| namespace extensions {
|
|
|
| +namespace {
|
| +
|
| +// Returns whether the |extension| should be loaded in the given
|
| +// |browser_context|.
|
| +bool IsExtensionVisibleToContext(const Extension& extension,
|
| + content::BrowserContext* browser_context) {
|
| + // Renderers don't need to know about themes.
|
| + if (extension.is_theme())
|
| + return false;
|
| +
|
| + // Only extensions enabled in incognito mode should be loaded in an incognito
|
| + // renderer. However extensions which can't be loaded in the incognito mode
|
| + // (e.g. platform apps) should also be loaded in an incognito renderer to
|
| + // ensure connections from incognito tabs to such extensions work.
|
| + return !browser_context->IsOffTheRecord() ||
|
| + !util::CanBeIncognitoEnabled(&extension) ||
|
| + util::IsIncognitoEnabled(extension.id(), browser_context);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| RendererStartupHelper::RendererStartupHelper(BrowserContext* browser_context)
|
| : browser_context_(browser_context) {
|
| DCHECK(browser_context);
|
| @@ -98,8 +122,9 @@ void RendererStartupHelper::InitializeProcess(
|
| WebViewGuest::GetPartitionID(process)));
|
| }
|
|
|
| - // Loaded extensions.
|
| + // Load extensions.
|
| std::vector<ExtensionMsg_Loaded_Params> loaded_extensions;
|
| + BrowserContext* renderer_context = process->GetBrowserContext();
|
| const ExtensionSet& extensions =
|
| ExtensionRegistry::Get(browser_context_)->enabled_extensions();
|
| for (const auto& ext : extensions) {
|
| @@ -107,18 +132,20 @@ void RendererStartupHelper::InitializeProcess(
|
| DCHECK(base::ContainsKey(extension_process_map_, ext->id()));
|
| DCHECK(!base::ContainsKey(extension_process_map_[ext->id()], process));
|
|
|
| - // Renderers don't need to know about themes.
|
| - if (!ext->is_theme()) {
|
| - // TODO(kalman): Only include tab specific permissions for extension
|
| - // processes, no other process needs it, so it's mildly wasteful.
|
| - // I am not sure this is possible to know this here, at such a low
|
| - // level of the stack. Perhaps site isolation can help.
|
| - bool include_tab_permissions = true;
|
| - loaded_extensions.push_back(
|
| - ExtensionMsg_Loaded_Params(ext.get(), include_tab_permissions));
|
| - extension_process_map_[ext->id()].insert(process);
|
| - }
|
| + if (!IsExtensionVisibleToContext(*ext, renderer_context))
|
| + continue;
|
| +
|
| + // TODO(kalman): Only include tab specific permissions for extension
|
| + // processes, no other process needs it, so it's mildly wasteful.
|
| + // I am not sure this is possible to know this here, at such a low
|
| + // level of the stack. Perhaps site isolation can help.
|
| + bool include_tab_permissions = true;
|
| + loaded_extensions.push_back(
|
| + ExtensionMsg_Loaded_Params(ext.get(), include_tab_permissions));
|
| + extension_process_map_[ext->id()].insert(process);
|
| }
|
| +
|
| + // Activate pending extensions.
|
| process->Send(new ExtensionMsg_Loaded(loaded_extensions));
|
| auto iter = pending_active_extensions_.find(process);
|
| if (iter != pending_active_extensions_.end()) {
|
| @@ -167,10 +194,7 @@ void RendererStartupHelper::ActivateExtensionInProcess(
|
| #endif
|
| }
|
|
|
| - // Renderers don't need to know about themes. We also don't normally
|
| - // "activate" themes, but this could happen if someone tries to open a tab
|
| - // to the e.g. theme's manifest.
|
| - if (extension.is_theme())
|
| + if (!IsExtensionVisibleToContext(extension, process->GetBrowserContext()))
|
| return;
|
|
|
| if (base::ContainsKey(initialized_processes_, process)) {
|
| @@ -190,10 +214,6 @@ void RendererStartupHelper::OnExtensionLoaded(const Extension& extension) {
|
| std::set<content::RenderProcessHost*>& loaded_process_set =
|
| extension_process_map_[extension.id()];
|
|
|
| - // Renderers don't need to know about themes.
|
| - if (extension.is_theme())
|
| - return;
|
| -
|
| // We don't need to include tab permisisons here, since the extension
|
| // was just loaded.
|
| // Uninitialized renderers will be informed of the extension load during the
|
| @@ -202,6 +222,8 @@ void RendererStartupHelper::OnExtensionLoaded(const Extension& extension) {
|
| 1,
|
| ExtensionMsg_Loaded_Params(&extension, false /* no tab permissions */));
|
| for (content::RenderProcessHost* process : initialized_processes_) {
|
| + if (!IsExtensionVisibleToContext(extension, process->GetBrowserContext()))
|
| + continue;
|
| process->Send(new ExtensionMsg_Loaded(params));
|
| loaded_process_set.insert(process);
|
| }
|
|
|